From 50603fd43005e45f0cf56585f67708b9c5fb050c Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Wed, 6 May 2026 00:43:47 +0200 Subject: [PATCH] fix: get client reverse tag in the outbound --- sub/subJsonService.go | 4 ++-- web/controller/xray_setting.go | 13 +++++++++---- web/html/modals/xray_rule_modal.html | 7 +++++++ web/html/xray.html | 2 ++ web/service/inbound.go | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 38f1ddc8..5cbd1895 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -44,7 +44,7 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string, fragmentOrNoises := false if fragment != "" || noises != "" { fragmentOrNoises = true - defaultOutboundsSettings := map[string]interface{}{ + defaultOutboundsSettings := map[string]any{ "domainStrategy": "UseIP", "redirect": "", } @@ -57,7 +57,7 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string, defaultOutboundsSettings["noises"] = json_util.RawMessage(noises) } - defaultDirectOutbound := map[string]interface{}{ + defaultDirectOutbound := map[string]any{ "protocol": "freedom", "settings": defaultOutboundsSettings, "tag": "direct_out", diff --git a/web/controller/xray_setting.go b/web/controller/xray_setting.go index 7e4c7966..10871951 100644 --- a/web/controller/xray_setting.go +++ b/web/controller/xray_setting.go @@ -71,14 +71,19 @@ func (a *XraySettingController) getXraySetting(c *gin.Context) { jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err) return } + clientReverseTags, err := a.InboundService.GetClientReverseTags() + if err != nil { + clientReverseTags = "[]" + } outboundTestUrl, _ := a.SettingService.GetXrayOutboundTestUrl() if outboundTestUrl == "" { outboundTestUrl = "https://www.google.com/generate_204" } - xrayResponse := map[string]interface{}{ - "xraySetting": json.RawMessage(xraySetting), - "inboundTags": json.RawMessage(inboundTags), - "outboundTestUrl": outboundTestUrl, + xrayResponse := map[string]any{ + "xraySetting": json.RawMessage(xraySetting), + "inboundTags": json.RawMessage(inboundTags), + "clientReverseTags": json.RawMessage(clientReverseTags), + "outboundTestUrl": outboundTestUrl, } result, err := json.Marshal(xrayResponse) if err != nil { diff --git a/web/html/modals/xray_rule_modal.html b/web/html/modals/xray_rule_modal.html index c542e029..b64e6182 100644 --- a/web/html/modals/xray_rule_modal.html +++ b/web/html/modals/xray_rule_modal.html @@ -204,6 +204,13 @@ if (app.enableDNS && !ObjectUtil.isEmpty(app.dnsTag)) this.inboundTags.push(app.dnsTag) this.outboundTags = ["", ...app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag)]; + if (app.clientReverseTags) { + app.clientReverseTags.forEach(tag => { + if (tag && !this.outboundTags.includes(tag)) { + this.outboundTags.push(tag); + } + }); + } this.balancerTags = [""]; if (app.templateSettings.routing && app.templateSettings.routing.balancers) { this.balancerTags = ["", ...app.templateSettings.routing.balancers.filter((o) => !ObjectUtil.isEmpty(o.tag)) diff --git a/web/html/xray.html b/web/html/xray.html index 1fffd76f..6ce0972c 100644 --- a/web/html/xray.html +++ b/web/html/xray.html @@ -280,6 +280,7 @@ outboundTestUrl: 'https://www.google.com/generate_204', oldOutboundTestUrl: 'https://www.google.com/generate_204', inboundTags: [], + clientReverseTags: [], outboundsTraffic: [], outboundTestStates: {}, // Track testing state and results for each outbound saveBtnDisable: true, @@ -559,6 +560,7 @@ this.oldXraySetting = xs; this.xraySetting = xs; this.inboundTags = result.inboundTags; + this.clientReverseTags = result.clientReverseTags || []; this.outboundTestUrl = result.outboundTestUrl || 'https://www.google.com/generate_204'; this.oldOutboundTestUrl = this.outboundTestUrl; this.saveBtnDisable = true; diff --git a/web/service/inbound.go b/web/service/inbound.go index d011e093..ddb748f5 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -1764,6 +1764,24 @@ func (s *InboundService) GetInboundTags() (string, error) { return string(tags), nil } +func (s *InboundService) GetClientReverseTags() (string, error) { + db := database.GetDB() + var rawTags []string + err := db.Raw(` + SELECT DISTINCT JSON_EXTRACT(client.value, '$.reverse.tag') + FROM inbounds, + JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client + WHERE inbounds.protocol = 'vless' + AND JSON_EXTRACT(client.value, '$.reverse.tag') IS NOT NULL + AND JSON_EXTRACT(client.value, '$.reverse.tag') != '' + `).Scan(&rawTags).Error + if err != nil && err != gorm.ErrRecordNotFound { + return "[]", err + } + result, _ := json.Marshal(rawTags) + return string(result), nil +} + func (s *InboundService) MigrationRemoveOrphanedTraffics() { db := database.GetDB() db.Exec(`