From 1fa9101b405ad1ba0127317ea4f8a151048b97ee Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Mon, 22 May 2023 17:31:41 +0330 Subject: [PATCH] [feature] add multi domain tls (CDN ready) Co-Authored-By: Alireza Ahmadi --- web/assets/js/model/models.js | 4 +- web/assets/js/model/xray.js | 37 +++++------ web/controller/inbound.go | 7 +++ web/html/common/qrcode_modal.html | 86 +++++++++++++++++--------- web/html/xui/form/tls_settings.html | 16 ++++- web/html/xui/inbound_client_table.html | 2 +- web/html/xui/inbound_info_modal.html | 79 ++++++++++++++++------- web/html/xui/inbound_modal.html | 12 ++++ web/html/xui/inbounds.html | 4 +- 9 files changed, 167 insertions(+), 80 deletions(-) diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index dc4c85d0..d8395b56 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -153,9 +153,9 @@ class DBInbound { } } - genLink(clientIndex) { + genLink(address=this.address, remark=this.remark, clientIndex=0) { const inbound = this.toInbound(); - return inbound.genLink(this.address, this.remark, clientIndex); + return inbound.genLink(address, remark, clientIndex); } get genInboundLinks() { diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 9a8fae80..bc8d4d4a 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -498,8 +498,7 @@ class TlsStreamSettings extends XrayCommonClass { } if (!ObjectUtil.isEmpty(json.settings)) { - settings = new TlsStreamSettings.Settings(json.settings.allowInsecure , json.settings.fingerprint, json.settings.serverName); - } + settings = new TlsStreamSettings.Settings(json.settings.allowInsecure , json.settings.fingerprint, json.settings.serverName, json.settings.domains); } return new TlsStreamSettings( json.serverName, json.minVersion, @@ -566,17 +565,19 @@ TlsStreamSettings.Cert = class extends XrayCommonClass { }; TlsStreamSettings.Settings = class extends XrayCommonClass { - constructor(allowInsecure = false, fingerprint = '', serverName = '') { + constructor(allowInsecure = false, fingerprint = '', serverName = '', domains = []) { super(); this.allowInsecure = allowInsecure; this.fingerprint = fingerprint; this.serverName = serverName; + this.domains = domains; } static fromJson(json = {}) { return new TlsStreamSettings.Settings( json.allowInsecure, json.fingerprint, - json.servername, + json.serverName, + json.domains, ); } toJson() { @@ -584,6 +585,7 @@ TlsStreamSettings.Settings = class extends XrayCommonClass { allowInsecure: this.allowInsecure, fingerprint: this.fingerprint, serverName: this.serverName, + domains: this.domains, }; } }; @@ -1507,25 +1509,13 @@ class Inbound extends XrayCommonClass { genLink(address='', remark='', clientIndex=0) { switch (this.protocol) { - case Protocols.VMESS: - if (this.settings.vmesses[clientIndex].email != ""){ - remark += '-' + this.settings.vmesses[clientIndex].email - } + case Protocols.VMESS: return this.genVmessLink(address, remark, clientIndex); case Protocols.VLESS: - if (this.settings.vlesses[clientIndex].email != ""){ - remark += '-' + this.settings.vlesses[clientIndex].email - } return this.genVLESSLink(address, remark, clientIndex); case Protocols.SHADOWSOCKS: - if (this.settings.shadowsockses[clientIndex].email != ""){ - remark = this.settings.shadowsockses[clientIndex].email - } return this.genSSLink(address, remark, clientIndex); case Protocols.TROJAN: - if (this.settings.trojans[clientIndex].email != ""){ - remark += '-' + this.settings.trojans[clientIndex].email - } return this.genTrojanLink(address, remark, clientIndex); default: return ''; } @@ -1537,12 +1527,17 @@ class Inbound extends XrayCommonClass { case Protocols.VMESS: case Protocols.VLESS: case Protocols.TROJAN: - JSON.parse(this.settings).clients.forEach((_,index) => { - link += this.genLink(address, remark, index) + '\r\n'; + case Protocols.SHADOWSOCKS: + JSON.parse(this.settings).clients.forEach((client,index) => { + if(this.tls && !ObjectUtil.isArrEmpty(this.stream.tls.settings.domains)){ + this.stream.tls.settings.domains.forEach((domain) => { + link += this.genLink(domain.domain, remark + '-' + client.email + '-' + domain.remark, index) + '\r\n'; + }); + } else { + link += this.genLink(address, remark + '-' + client.email, index) + '\r\n'; + } }); return link; - case Protocols.SHADOWSOCKS: - return (this.genSSLink(address, remark) + '\r\n'); default: return ''; } } diff --git a/web/controller/inbound.go b/web/controller/inbound.go index d13e40bc..5ce58d53 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -146,11 +146,18 @@ func (a *InboundController) getClientIps(c *gin.Context) { ips, err := a.inboundService.GetInboundClientIps(email) if err != nil { + jsonObj(c, "Failed to get client IPs", nil) + return + } + + if ips == "" { jsonObj(c, "No IP Record", nil) return } + jsonObj(c, ips, nil) } + func (a *InboundController) clearClientIps(c *gin.Context) { email := c.Param("email") diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index 855c349a..3271f3ad 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -7,47 +7,53 @@ {{ i18n "pages.inbounds.clickOnQRcode" }} - - {{ i18n "pages.inbounds.email" }}: "[[ qrModal.clientName ]]" - - + + {{ i18n "pages.inbounds.client" }} + diff --git a/web/html/xui/form/tls_settings.html b/web/html/xui/form/tls_settings.html index d80e820e..31e559da 100644 --- a/web/html/xui/form/tls_settings.html +++ b/web/html/xui/form/tls_settings.html @@ -33,7 +33,21 @@ - + + + + + + + + + + + + + + diff --git a/web/html/xui/inbound_client_table.html b/web/html/xui/inbound_client_table.html index 4b09b43a..bb825437 100644 --- a/web/html/xui/inbound_client_table.html +++ b/web/html/xui/inbound_client_table.html @@ -29,7 +29,7 @@ {{ i18n "depleted" }}
URL -

[[ infoModal.link ]]

- + + [[ link.remark ]]
[[ link.link ]]
+ + + +