fix(sub): show the MTProto inbound's remark in the sub page Configs tab (#7206)

tg://proxy links carry no #remark on purpose, so the Configs tab of the subscription page had nothing to title an MTProto row with and fell back to "Link N" on the raw, JSON and Clash pages.

While the page data is built, record each MTProto link's remark and send it to the page as linkRemarks, aligned with links; the tab uses it when the link itself has no name. The link, the subscription bodies and the ?format=info JSON are unchanged.

Closes #7198
This commit is contained in:
Бат-Орших
2026-11-25 19:41:44 +08:00
committed by GitHub
parent c12a4f72c7
commit 64ca67706f
7 changed files with 106 additions and 5 deletions
+1
View File
@@ -20,6 +20,7 @@ interface SubPageData {
subUpdates?: number;
links?: string[];
emails?: string[];
linkRemarks?: string[];
datepicker?: 'gregorian' | 'jalalian';
announce?: string;
downloadByte?: string | number;
+3 -2
View File
@@ -14,10 +14,11 @@ import SubQrButton from './SubQrButton';
interface SubConfigsTabProps {
links: string[];
linkRemarks?: string[];
onCopy: (value: string, toast?: string) => void;
}
export default function SubConfigsTab({ links, onCopy }: SubConfigsTabProps) {
export default function SubConfigsTab({ links, linkRemarks = [], onCopy }: SubConfigsTabProps) {
const { t } = useTranslation();
return (
@@ -32,7 +33,7 @@ export default function SubConfigsTab({ links, onCopy }: SubConfigsTabProps) {
</div>
{links.map((link, idx) => {
const parts = parseLinkParts(link);
const rowTitle = parts?.remark || `Link ${idx + 1}`;
const rowTitle = parts?.remark || linkRemarks[idx] || `Link ${idx + 1}`;
const isWireguardLink = link.startsWith('wireguard://') || link.startsWith('wg://');
const wireguardConfig = isWireguardLink ? wireguardConfigFromLink(link, rowTitle) : '';
const amneziawgConfig = link.startsWith('vpn://') ? amneziawgConfigFromLink(link) : '';
+2 -1
View File
@@ -34,6 +34,7 @@ const updateHours = Number(subData.subUpdates || 0);
const announce = subData.announce || '';
const links: string[] = Array.isArray(subData.links) ? subData.links : [];
const linkEmails: string[] = Array.isArray(subData.emails) ? subData.emails : [];
const linkRemarks: string[] = Array.isArray(subData.linkRemarks) ? subData.linkRemarks : [];
const totalByte = Number(subData.totalByte || 0);
const usedByte =
Number(subData.usedByte || 0) ||
@@ -124,7 +125,7 @@ export default function SubPage() {
<span className="sub-tab-count">{links.length}</span>
</>
),
children: <SubConfigsTab links={links} onCopy={copy} />,
children: <SubConfigsTab links={links} linkRemarks={linkRemarks} onCopy={copy} />,
});
}
return items;
+19
View File
@@ -2,6 +2,7 @@ import { fireEvent, render, within } from '@testing-library/react';
import { QRCode } from 'antd';
import { describe, expect, it, vi } from 'vitest';
import SubConfigsTab from '@/pages/sub/SubConfigsTab';
import SubLinksTab from '@/pages/sub/SubLinksTab';
import { renderWithProviders } from './test-utils';
@@ -79,3 +80,21 @@ describe('SubLinksTab inline QR card', () => {
expect(card.querySelector('.ant-segmented')).toBeNull();
});
});
describe('SubConfigsTab row titles (#7198)', () => {
it('names a remark-less tg://proxy row from linkRemarks at its own index', () => {
const links = [
'vless://11111111-1111-4111-8111-111111111111@h.example.com:443?type=tcp#DE-alice',
'tg://proxy?server=203.0.113.7&port=8443&secret=ee00',
'tg://proxy?server=203.0.113.8&port=8443&secret=ee11',
];
const view = renderWithProviders(
<SubConfigsTab links={links} linkRemarks={['', 'mt-sub-user', '']} onCopy={vi.fn()} />,
);
const titles = [...view.container.querySelectorAll('.sub-row-title')].map(
(el) => el.textContent,
);
expect(titles).toEqual(['DE-alice', 'mt-sub-user', 'Link 3']);
});
});
+3
View File
@@ -450,6 +450,7 @@ func (a *SUBController) maybeServeSubInfo(c *gin.Context) bool {
}
info := a.subPageContext(page)
delete(info, "links")
delete(info, "linkRemarks")
delete(info, "subFormat")
info["emails"] = dedupeEmails(page.Emails)
c.JSON(http.StatusOK, info)
@@ -462,6 +463,7 @@ func (a *SUBController) buildSubPageData(c *gin.Context) (PageData, bool) {
subReq := a.subService.ForRequest(host)
subReq.wireguardDevice = c.Query("wgDevice")
subReq.subscriptionBody = false
subReq.linkRemarks = map[string]string{}
subs, emails, lastOnline, traffic, err := subReq.getSubs(subId)
if err != nil || subs == nil {
writeSubError(c, err)
@@ -746,6 +748,7 @@ func (a *SUBController) subPageContext(page PageData) map[string]any {
"subUpdates": updateHours,
"links": page.Result,
"emails": page.Emails,
"linkRemarks": page.LinkRemarks,
"datepicker": datepicker,
"announce": page.SubAnnounce,
}
+65
View File
@@ -175,3 +175,68 @@ func TestSubPageDataNamesTheFormatOfTheVisitedRoute(t *testing.T) {
})
}
}
// tg://proxy links carry no #remark, so the page data must name the MTProto row
// at the link's own index and leave self-named links empty (#7198).
func TestSubPage_MtprotoRowCarriesInboundRemark(t *testing.T) {
gin.SetMode(gin.TestMode)
initSubDB(t)
seedInfoEndpointSub(t, "mt-page", "user")
db := database.GetDB()
inbound := &model.Inbound{
Listen: "203.0.113.7", Port: 8443, Protocol: model.MTProto, Enable: true,
Tag: "mt-page", Remark: "mt-sub",
Settings: `{"fakeTlsDomain":"www.cloudflare.com","clients":[{"email":"user","enable":true,"subId":"mt-page","secret":"` + mtprotoTestSecret + `"}]}`,
}
if err := db.Create(inbound).Error; err != nil {
t.Fatalf("create inbound: %v", err)
}
var client model.ClientRecord
if err := db.Where("email = ?", "user").First(&client).Error; err != nil {
t.Fatalf("load client: %v", err)
}
if err := db.Model(&client).Update("secret", mtprotoTestSecret).Error; err != nil {
t.Fatalf("set secret: %v", err)
}
if err := db.Create(&model.ClientInbound{ClientId: client.Id, InboundId: inbound.Id}).Error; err != nil {
t.Fatalf("attach client: %v", err)
}
oldDistFS := distFS
distFS = testDistFS
t.Cleanup(func() { distFS = oldDistFS })
router := gin.New()
NewSUBController(router.Group("/"))
req := httptest.NewRequest(http.MethodGet, "/sub/mt-page", nil)
req.Host = "sub.example.com"
req.Header.Set("Accept", "text/html")
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
_, rest, found := strings.Cut(w.Body.String(), "window.__SUB_PAGE_DATA__=")
raw, _, closed := strings.Cut(rest, ";</script>")
if w.Code != http.StatusOK || !found || !closed {
t.Fatalf("status = %d, page data not found; body=%s", w.Code, w.Body.String())
}
var page struct {
Links []string `json:"links"`
LinkRemarks []string `json:"linkRemarks"`
}
if err := json.Unmarshal([]byte(raw), &page); err != nil {
t.Fatalf("page data is not valid JSON: %v; data=%s", err, raw)
}
want := make([]string, len(page.Links))
mtproto := 0
for i, link := range page.Links {
if strings.HasPrefix(link, "tg://proxy") {
want[i] = "mt-sub-user"
mtproto++
}
}
if mtproto != 1 || len(page.Links) != 2 {
t.Fatalf("links = %q, want one tg://proxy link and one external link", page.Links)
}
if len(page.LinkRemarks) != len(want) || page.LinkRemarks[0] != want[0] || page.LinkRemarks[1] != want[1] {
t.Fatalf("linkRemarks = %q, want %q for links %q", page.LinkRemarks, want, page.Links)
}
}
+13 -2
View File
@@ -103,6 +103,9 @@ type SubService struct {
// settingsByInbound: one decode per request, not one per link of a subId.
tuicByInbound map[int]*tuicLinkInstance
amneziaWGServerByInbound map[int]*amneziawg.ServerSettings
// linkRemarks maps a remark-less link (mtproto) to its remark; only the sub page
// sets it, so the Configs tab can name the row.
linkRemarks map[string]string
}
// tuicLinkInstance indexes a decoded TUIC inbound's clients by email
@@ -1313,11 +1316,15 @@ func (s *SubService) genMtprotoLink(inbound *model.Inbound, email string) string
endpoints := s.advertisedEndpoints(inbound)
links := make([]string, 0, len(endpoints))
for _, endpoint := range endpoints {
links = append(links, buildLinkWithParams("tg://proxy", map[string]string{
link := buildLinkWithParams("tg://proxy", map[string]string{
"server": endpoint.Address,
"port": fmt.Sprintf("%d", endpoint.Port),
"secret": resolved.Secret,
}, ""))
}, "")
if s.linkRemarks != nil {
s.linkRemarks[link] = s.endpointRemark(inbound, email, endpoint.ep, "")
}
links = append(links, link)
}
return strings.Join(links, "\n")
}
@@ -3400,6 +3407,7 @@ type PageData struct {
SubAnnounce string
Result []string
Emails []string
LinkRemarks []string
}
// ResolveRequest extracts scheme, host, and header information from an HTTP request.
@@ -3548,6 +3556,7 @@ func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray
pageLinks := make([]string, 0, len(subs))
pageEmails := make([]string, 0, len(subs))
pageRemarks := make([]string, 0, len(subs))
for i, sub := range subs {
email := ""
if i < len(emails) {
@@ -3556,6 +3565,7 @@ func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray
for _, link := range splitLinkLines(sub) {
pageLinks = append(pageLinks, link)
pageEmails = append(pageEmails, email)
pageRemarks = append(pageRemarks, s.linkRemarks[link])
}
}
@@ -3583,6 +3593,7 @@ func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray
SubSupportUrl: subSupportUrl,
Result: pageLinks,
Emails: pageEmails,
LinkRemarks: pageRemarks,
}
}