fix: get client reverse tag in the outbound

This commit is contained in:
MHSanaei
2026-05-06 00:43:47 +02:00
parent 8bea0fde2b
commit 50603fd430
5 changed files with 38 additions and 6 deletions

View File

@@ -44,7 +44,7 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string,
fragmentOrNoises := false fragmentOrNoises := false
if fragment != "" || noises != "" { if fragment != "" || noises != "" {
fragmentOrNoises = true fragmentOrNoises = true
defaultOutboundsSettings := map[string]interface{}{ defaultOutboundsSettings := map[string]any{
"domainStrategy": "UseIP", "domainStrategy": "UseIP",
"redirect": "", "redirect": "",
} }
@@ -57,7 +57,7 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string,
defaultOutboundsSettings["noises"] = json_util.RawMessage(noises) defaultOutboundsSettings["noises"] = json_util.RawMessage(noises)
} }
defaultDirectOutbound := map[string]interface{}{ defaultDirectOutbound := map[string]any{
"protocol": "freedom", "protocol": "freedom",
"settings": defaultOutboundsSettings, "settings": defaultOutboundsSettings,
"tag": "direct_out", "tag": "direct_out",

View File

@@ -71,14 +71,19 @@ func (a *XraySettingController) getXraySetting(c *gin.Context) {
jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err) jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err)
return return
} }
clientReverseTags, err := a.InboundService.GetClientReverseTags()
if err != nil {
clientReverseTags = "[]"
}
outboundTestUrl, _ := a.SettingService.GetXrayOutboundTestUrl() outboundTestUrl, _ := a.SettingService.GetXrayOutboundTestUrl()
if outboundTestUrl == "" { if outboundTestUrl == "" {
outboundTestUrl = "https://www.google.com/generate_204" outboundTestUrl = "https://www.google.com/generate_204"
} }
xrayResponse := map[string]interface{}{ xrayResponse := map[string]any{
"xraySetting": json.RawMessage(xraySetting), "xraySetting": json.RawMessage(xraySetting),
"inboundTags": json.RawMessage(inboundTags), "inboundTags": json.RawMessage(inboundTags),
"outboundTestUrl": outboundTestUrl, "clientReverseTags": json.RawMessage(clientReverseTags),
"outboundTestUrl": outboundTestUrl,
} }
result, err := json.Marshal(xrayResponse) result, err := json.Marshal(xrayResponse)
if err != nil { if err != nil {

View File

@@ -204,6 +204,13 @@
if (app.enableDNS && !ObjectUtil.isEmpty(app.dnsTag)) this.inboundTags.push(app.dnsTag) 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 => this.outboundTags = ["", ...app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj =>
obj.tag)]; obj.tag)];
if (app.clientReverseTags) {
app.clientReverseTags.forEach(tag => {
if (tag && !this.outboundTags.includes(tag)) {
this.outboundTags.push(tag);
}
});
}
this.balancerTags = [""]; this.balancerTags = [""];
if (app.templateSettings.routing && app.templateSettings.routing.balancers) { if (app.templateSettings.routing && app.templateSettings.routing.balancers) {
this.balancerTags = ["", ...app.templateSettings.routing.balancers.filter((o) => !ObjectUtil.isEmpty(o.tag)) this.balancerTags = ["", ...app.templateSettings.routing.balancers.filter((o) => !ObjectUtil.isEmpty(o.tag))

View File

@@ -280,6 +280,7 @@
outboundTestUrl: 'https://www.google.com/generate_204', outboundTestUrl: 'https://www.google.com/generate_204',
oldOutboundTestUrl: 'https://www.google.com/generate_204', oldOutboundTestUrl: 'https://www.google.com/generate_204',
inboundTags: [], inboundTags: [],
clientReverseTags: [],
outboundsTraffic: [], outboundsTraffic: [],
outboundTestStates: {}, // Track testing state and results for each outbound outboundTestStates: {}, // Track testing state and results for each outbound
saveBtnDisable: true, saveBtnDisable: true,
@@ -559,6 +560,7 @@
this.oldXraySetting = xs; this.oldXraySetting = xs;
this.xraySetting = xs; this.xraySetting = xs;
this.inboundTags = result.inboundTags; this.inboundTags = result.inboundTags;
this.clientReverseTags = result.clientReverseTags || [];
this.outboundTestUrl = result.outboundTestUrl || 'https://www.google.com/generate_204'; this.outboundTestUrl = result.outboundTestUrl || 'https://www.google.com/generate_204';
this.oldOutboundTestUrl = this.outboundTestUrl; this.oldOutboundTestUrl = this.outboundTestUrl;
this.saveBtnDisable = true; this.saveBtnDisable = true;

View File

@@ -1764,6 +1764,24 @@ func (s *InboundService) GetInboundTags() (string, error) {
return string(tags), nil 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() { func (s *InboundService) MigrationRemoveOrphanedTraffics() {
db := database.GetDB() db := database.GetDB()
db.Exec(` db.Exec(`