From 54946e725e835a291f9c8e226788cd8a166e190b Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 11 Apr 2023 18:18:37 +0330 Subject: [PATCH 1/4] xtls bug fix --- web/assets/js/model/xray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index f0ea1efd..d3668519 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -715,7 +715,7 @@ class StreamSettings extends XrayCommonClass { static fromJson(json = {}) { let tls, reality; if (json.security === "xtls") { - tls = TlsStreamSettings.fromJson(json.xtlsSettings); + tls = TlsStreamSettings.fromJson(json.XTLSSettings); } else if (json.security === "tls") { tls = TlsStreamSettings.fromJson(json.tlsSettings); } From 8c40e7281fe40b3dfe40093446a339a99c2f2e1a Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 11 Apr 2023 18:39:07 +0330 Subject: [PATCH 2/4] bug fix Co-Authored-By: Alireza Ahmadi --- web/service/inbound.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/web/service/inbound.go b/web/service/inbound.go index 74765ab3..2372e574 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -453,12 +453,10 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr } continue } - // get settings clients - settings := map[string]interface{}{} - json.Unmarshal([]byte(inbound.Settings), &settings) - clients, ok := settings["clients"].([]model.Client) + // get clients + clients, err := s.getClients(inbound) needUpdate := false - if ok { + if err == nil { for client_index, client := range clients { if traffic.Email == client.Email { if client.ExpiryTime < 0 { @@ -473,7 +471,16 @@ func (s *InboundService) adjustTraffics(traffics []*xray.ClientTraffic) (full_tr } if needUpdate { - settings["clients"] = clients + settings := map[string]interface{}{} + json.Unmarshal([]byte(inbound.Settings), &settings) + + // Convert clients to []interface to update clients in settings + var clientsInterface []interface{} + for _, c := range clients { + clientsInterface = append(clientsInterface, interface{}(c)) + } + + settings["clients"] = clientsInterface modifiedSettings, err := json.MarshalIndent(settings, "", " ") if err != nil { return nil, err From 4e7ad9e6de7520a3ed510fadb9644a47237aeb53 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 11 Apr 2023 19:23:40 +0330 Subject: [PATCH 3/4] bug fix --- web/html/xui/inbound_info_modal.html | 2 +- web/service/sub.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/web/html/xui/inbound_info_modal.html b/web/html/xui/inbound_info_modal.html index 1b05a12c..049d529e 100644 --- a/web/html/xui/inbound_info_modal.html +++ b/web/html/xui/inbound_info_modal.html @@ -49,7 +49,7 @@ tls: {{ i18n "enabled" }}
tls {{ i18n "domainName" }}: [[ inbound.serverName ? inbound.serverName : '' ]] - + xtls: {{ i18n "enabled" }}
xtls {{ i18n "domainName" }}: [[ inbound.serverName ? inbound.serverName : '' ]] diff --git a/web/service/sub.go b/web/service/sub.go index d1891e14..8d96866c 100644 --- a/web/service/sub.go +++ b/web/service/sub.go @@ -300,7 +300,7 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { if security == "xtls" { params["security"] = "xtls" - xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{}) + xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{}) alpns, _ := xtlsSetting["alpn"].([]interface{}) var alpn []string for _, a := range alpns { @@ -310,15 +310,15 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string { params["alpn"] = strings.Join(alpn, ",") } - xtlsSettings, _ := searchKey(xtlsSetting, "settings") + XTLSSettings, _ := searchKey(xtlsSetting, "settings") if xtlsSetting != nil { - if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok { + if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok { params["sni"], _ = sniValue.(string) } - if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok { + if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok { params["fp"], _ = fpValue.(string) } - if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok { + if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok { if insecure.(bool) { params["allowInsecure"] = "1" } @@ -444,7 +444,7 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string if security == "xtls" { params["security"] = "xtls" - xtlsSetting, _ := stream["xtlsSettings"].(map[string]interface{}) + xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{}) alpns, _ := xtlsSetting["alpn"].([]interface{}) var alpn []string for _, a := range alpns { @@ -454,15 +454,15 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string params["alpn"] = strings.Join(alpn, ",") } - xtlsSettings, _ := searchKey(xtlsSetting, "settings") + XTLSSettings, _ := searchKey(xtlsSetting, "settings") if xtlsSetting != nil { - if sniValue, ok := searchKey(xtlsSettings, "serverName"); ok { + if sniValue, ok := searchKey(XTLSSettings, "serverName"); ok { params["sni"], _ = sniValue.(string) } - if fpValue, ok := searchKey(xtlsSettings, "fingerprint"); ok { + if fpValue, ok := searchKey(XTLSSettings, "fingerprint"); ok { params["fp"], _ = fpValue.(string) } - if insecure, ok := searchKey(xtlsSettings, "allowInsecure"); ok { + if insecure, ok := searchKey(XTLSSettings, "allowInsecure"); ok { if insecure.(bool) { params["allowInsecure"] = "1" } From c38d75f3d901e7a3f550ab05aef711f95421cae6 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 11 Apr 2023 22:30:24 +0330 Subject: [PATCH 4/4] reality for trojan --- web/assets/js/model/xray.js | 74 ++++++++++++++++++++++++++----------- web/service/sub.go | 24 ++++++++++++ 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index d3668519..31a192af 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -600,8 +600,20 @@ TlsStreamSettings.Settings = class extends XrayCommonClass { }; class RealityStreamSettings extends XrayCommonClass { - constructor(show = false,xver = 0, fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX, dest = 'github.io:443', serverNames = 'github.io,www.github.io,', privateKey = RandomUtil.randomX25519PrivateKey(), publicKey = '', minClient = '', - maxClient = '', maxTimediff = 0, shortIds = RandomUtil.randowShortId()) { + + constructor( + show = false,xver = 0, + fingerprint = UTLS_FINGERPRINT.UTLS_FIREFOX, + dest = 'yahoo.com:443', + serverNames = 'yahoo.com,www.yahoo.com', + privateKey = RandomUtil.randomX25519PrivateKey(), + publicKey = '', + minClient = '', + maxClient = '', + maxTimediff = 0, + shortIds = RandomUtil.randowShortId() + ) + { super(); this.show = show; this.xver = xver; @@ -613,11 +625,9 @@ class RealityStreamSettings extends XrayCommonClass { this.minClient = minClient; this.maxClient = maxClient; this.maxTimediff = maxTimediff; - this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds; - - } - - static fromJson(json = {}) { + this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds; + } + static fromJson(json = {}) { return new RealityStreamSettings( json.show, json.xver, @@ -631,9 +641,8 @@ class RealityStreamSettings extends XrayCommonClass { json.maxTimediff, json.shortIds ); - - } - toJson() { + } + toJson() { return { show: this.show, xver: this.xver, @@ -646,22 +655,22 @@ class RealityStreamSettings extends XrayCommonClass { maxClient: this.maxClient, maxTimediff: this.maxTimediff, shortIds: this.shortIds.split(/,|,|\s+/) - }; + }; + } } -} class StreamSettings extends XrayCommonClass { constructor(network='tcp', - security='none', - tlsSettings=new TlsStreamSettings(), - realitySettings = new RealityStreamSettings(), - tcpSettings=new TcpStreamSettings(), - kcpSettings=new KcpStreamSettings(), - wsSettings=new WsStreamSettings(), - httpSettings=new HttpStreamSettings(), - quicSettings=new QuicStreamSettings(), - grpcSettings=new GrpcStreamSettings(), - ) { + security='none', + tlsSettings=new TlsStreamSettings(), + realitySettings = new RealityStreamSettings(), + tcpSettings=new TcpStreamSettings(), + kcpSettings=new KcpStreamSettings(), + wsSettings=new WsStreamSettings(), + httpSettings=new HttpStreamSettings(), + quicSettings=new QuicStreamSettings(), + grpcSettings=new GrpcStreamSettings(), + ) { super(); this.network = network; this.security = security; @@ -1056,6 +1065,7 @@ class Inbound extends XrayCommonClass { canEnableReality() { switch (this.protocol) { case Protocols.VLESS: + case Protocols.TROJAN: break; default: return false; @@ -1379,6 +1389,26 @@ class Inbound extends XrayCommonClass { } } + if (this.reality) { + params.set("security", "reality"); + if (!ObjectUtil.isArrEmpty(this.stream.reality.serverNames)) { + params.set("sni", this.stream.reality.serverNames.split(/,|,|\s+/)[0]); + } + if (this.stream.reality.publicKey != "") { + //params.set("pbk", Ed25519.getPublicKey(this.stream.reality.privateKey)); + params.set("pbk", this.stream.reality.publicKey); + } + if (this.stream.network === 'tcp') { + params.set("flow", this.settings.trojans[clientIndex].flow); + } + if (this.stream.reality.shortIds != "") { + params.set("sid", this.stream.reality.shortIds); + } + if (this.stream.reality.fingerprint != "") { + params.set("fp", this.stream.reality.fingerprint); + } + } + if (this.XTLS) { params.set("security", "xtls"); params.set("alpn", this.stream.tls.alpn); diff --git a/web/service/sub.go b/web/service/sub.go index 8d96866c..f0a5a160 100644 --- a/web/service/sub.go +++ b/web/service/sub.go @@ -442,6 +442,30 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string } } + if security == "reality" { + params["security"] = "reality" + realitySetting, _ := stream["realitySettings"].(map[string]interface{}) + realitySettings, _ := searchKey(realitySetting, "settings") + if realitySetting != nil { + if sniValue, ok := searchKey(realitySettings, "serverName"); ok { + params["sni"], _ = sniValue.(string) + } + if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok { + params["pbk"], _ = pbkValue.(string) + } + if sidValue, ok := searchKey(realitySettings, "shortIds"); ok { + params["sid"], _ = sidValue.(string) + } + if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok { + params["fp"], _ = fpValue.(string) + } + } + serverName, _ := realitySetting["serverName"].(string) + if serverName != "" { + address = serverName + } + } + if security == "xtls" { params["security"] = "xtls" xtlsSetting, _ := stream["XTLSSettings"].(map[string]interface{})