From 4df056f6a23ab8b3d35bd613ed24933389355084 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Mon, 8 Jan 2024 20:23:34 +0100 Subject: [PATCH] [outbound] update wireguard --- web/assets/js/model/outbound.js | 101 ++++++++++++++++++------- web/html/xui/form/outbound.html | 72 +++++++++++++++--- web/html/xui/xray.html | 2 +- web/translation/translate.en_US.toml | 2 + web/translation/translate.fa_IR.toml | 4 +- web/translation/translate.ru_RU.toml | 2 + web/translation/translate.vi_VN.toml | 2 + web/translation/translate.zh_Hans.toml | 2 + 8 files changed, 149 insertions(+), 38 deletions(-) diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index 89032514..7d9c1e2a 100644 --- a/web/assets/js/model/outbound.js +++ b/web/assets/js/model/outbound.js @@ -47,18 +47,27 @@ const ALPN_OPTION = { HTTP1: "http/1.1", }; -const outboundDomainStrategies = [ +const OutboundDomainStrategies = [ "AsIs", "UseIP", "UseIPv4", "UseIPv6" -] +]; + +const WireguardDomainStrategy = [ + "ForceIP", + "ForceIPv4", + "ForceIPv4v6", + "ForceIPv6", + "ForceIPv6v4" +]; Object.freeze(Protocols); Object.freeze(SSMethods); Object.freeze(TLS_FLOW_CONTROL); Object.freeze(ALPN_OPTION); -Object.freeze(outboundDomainStrategies); +Object.freeze(OutboundDomainStrategies); +Object.freeze(WireguardDomainStrategy); class CommonClass { @@ -901,42 +910,82 @@ Outbound.HttpSettings = class extends CommonClass { }; } }; -Outbound.WireguardSettings = class extends CommonClass{ - constructor(mtu=1420, secretKey='', address='', publicKey='', allowedIPs='0.0.0.0/0,::/0', endpoint='', keepAlive=0) { +Outbound.WireguardSettings = class extends CommonClass { + constructor( + mtu=1420, secretKey='', address='', workers=2, domainStrategy='', reserved='', + peers=[new Outbound.WireguardSettings.Peer()], kernelMode=false) { super(); - this.mtu = mtu, - this.secretKey = secretKey, - this.address = address, - this.publicKey = publicKey, - this.allowedIPs = allowedIPs, - this.endpoint = endpoint, - this.keepAlive = keepAlive + this.mtu = mtu; + this.secretKey = secretKey; + this.address = address instanceof Array ? address.join(',') : address; + this.workers = workers; + this.domainStrategy = domainStrategy; + this.reserved = reserved instanceof Array ? reserved.join(',') : reserved; + this.peers = peers; + this.kernelMode = kernelMode; + } + + addPeer() { + this.peers.push(new Outbound.WireguardSettings.Peer()); + } + + delPeer(index) { + this.peers.splice(index, 1); } static fromJson(json={}){ - const peers = json.peers return new Outbound.WireguardSettings( json.mtu, json.secretKey, - json.address.toString(), - peers[0].publicKey, - peers[0].allowedIPs.toString(), - peers[0].endpoint, - peers[0].keepAlive + json.address, + json.workers, + json.domainStrategy, + json.reserved, + json.peers.map(peer => Outbound.WireguardSettings.Peer.fromJson(peer)), + json.kernelMode, ); } toJson() { return { - mtu: this.mtu, + mtu: this.mtu?? undefined, secretKey: this.secretKey, address: this.address ? this.address.split(",") : [], - peers: [{ - publicKey:this.publicKey, - allowedIPs: this.allowedIPs ? this.allowedIPs.split(",") : [], - keepAlive: this.keepAlive, - endpoint: this.endpoint - }] + workers: this.workers?? undefined, + domainStrategy: WireguardDomainStrategy.includes(this.domainStrategy) ? this.domainStrategy : undefined, + reserved: this.reserved ? this.reserved.split(",") : undefined, + peers: Outbound.WireguardSettings.Peer.toJsonArray(this.peers), + kernelMode: this.kernelMode, }; } -}; \ No newline at end of file +}; +Outbound.WireguardSettings.Peer = class extends CommonClass { + constructor(publicKey='', psk='', allowedIPs='0.0.0.0/0,::/0', endpoint='', keepAlive=0) { + super(); + this.publicKey = publicKey; + this.psk = psk; + this.allowedIPs = allowedIPs instanceof Array ? allowedIPs.join(',') : allowedIPs; + this.endpoint = endpoint; + this.keepAlive = keepAlive; + } + + static fromJson(json={}){ + return new Outbound.WireguardSettings.Peer( + json.publicKey, + json.preSharedKey, + json.allowedIPs, + json.endpoint, + json.keepAlive + ); + } + + toJson() { + return { + publicKey: this.publicKey, + preSharedKey: this.psk.length>0 ? this.psk : undefined, + allowedIPs: this.allowedIPs ? this.allowedIPs.split(",") : [], + keepAlive: this.keepAlive?? undefined, + endpoint: this.endpoint + }; + } +} \ No newline at end of file diff --git a/web/html/xui/form/outbound.html b/web/html/xui/form/outbound.html index ab2db4f2..edc00cc5 100644 --- a/web/html/xui/form/outbound.html +++ b/web/html/xui/form/outbound.html @@ -18,7 +18,7 @@ - [[ s ]] + [[ s ]] @@ -71,24 +71,76 @@ - + + - - + + + [[ wds ]] + - - + + - - + + - - + + + + + + + + + + Peer [[ index + 1 ]] + + + + + + + + + + + + + + + + + + + + diff --git a/web/html/xui/xray.html b/web/html/xui/xray.html index ab7e8e0a..ba487c15 100644 --- a/web/html/xui/xray.html +++ b/web/html/xui/xray.html @@ -127,7 +127,7 @@ - [[ s ]] + [[ s ]] diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml index a3561cf3..01ca6218 100644 --- a/web/translation/translate.en_US.toml +++ b/web/translation/translate.en_US.toml @@ -392,6 +392,8 @@ "publicKey" = "Public Key" "allowedIPs" = "Allowed IPs" "endpoint" = "End Point" +"psk" = "PreShared Key" +"domainStrategy" = "Domain Strategy" [tgbot] "noResult" = "❗ No result!" diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml index 79336a3d..61352c1c 100644 --- a/web/translation/translate.fa_IR.toml +++ b/web/translation/translate.fa_IR.toml @@ -389,8 +389,10 @@ "intercon" = "اتصال میانی" "secretKey" = "کلید شخصی" "publicKey" = "کلید عمومی" -"allowedIPs" = "های مجاز IP" +"allowedIPs" = "آی‌پی‌های مجاز" "endpoint" = "نقطه پایانی" +"psk" = "کلید مشترک" +"domainStrategy" = "استراتژی حل دامنه" [tgbot] "noResult" = "❗نتیجه‌ای یافت نشد" diff --git a/web/translation/translate.ru_RU.toml b/web/translation/translate.ru_RU.toml index 8057656f..b99e1656 100644 --- a/web/translation/translate.ru_RU.toml +++ b/web/translation/translate.ru_RU.toml @@ -392,6 +392,8 @@ "publicKey" = "Открытый ключ" "allowedIPs" = "Разрешенные IP-адреса" "endpoint" = "Конечная точка" +"psk" = "Общий ключ" +"domainStrategy" = "Стратегия домена" [tgbot] "noResult" = "❗ Нет результатов!" diff --git a/web/translation/translate.vi_VN.toml b/web/translation/translate.vi_VN.toml index e1221874..f63542e4 100644 --- a/web/translation/translate.vi_VN.toml +++ b/web/translation/translate.vi_VN.toml @@ -392,6 +392,8 @@ "publicKey" = "Khóa công khai" "allowedIPs" = "IP được phép" "endpoint" = "Điểm cuối" +"psk" = "Khóa chia sẻ" +"domainStrategy" = "Chiến lược tên miền" [tgbot] "noResult" = "❗ Không có kết quả!" diff --git a/web/translation/translate.zh_Hans.toml b/web/translation/translate.zh_Hans.toml index 1959f7e8..98f5040e 100644 --- a/web/translation/translate.zh_Hans.toml +++ b/web/translation/translate.zh_Hans.toml @@ -392,6 +392,8 @@ "publicKey" = "公钥" "allowedIPs" = "允许的 IP" "endpoint" = "终点" +"psk" = "共享密钥" +"domainStrategy" = "域策略" [tgbot] "noResult" = "❗ 没有结果!"