Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2024-02-18 00:16:49 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-02-18 00:16:49 +0300
commit61489077d7d5740250702c68846abae6a3598c6f (patch)
treefd14eb27a4ac981a50b7b63b5f445d656e159a8b /web/assets
parent4621933e5bad743aafd2b15bd72ed99069df99ad (diff)
[wg] auto multi-peer and qrcode
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
Diffstat (limited to 'web/assets')
-rw-r--r--web/assets/js/model/xray.js40
1 files changed, 38 insertions, 2 deletions
diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js
index 7018fb75..d7d1fa0d 100644
--- a/web/assets/js/model/xray.js
+++ b/web/assets/js/model/xray.js
@@ -1534,6 +1534,28 @@ class Inbound extends XrayCommonClass {
return url.toString();
}
+ getWireguardLink(address, port, remark, peerId) {
+ let txt = `[Interface]\n`
+ txt += `PrivateKey = ${this.settings.peers[peerId].privateKey}\n`
+ txt += `Address = ${this.settings.peers[peerId].allowedIPs[0]}\n`
+ txt += `DNS = 1.1.1.1, 1.0.0.1\n`
+ if (this.settings.mtu) {
+ txt += `MTU = ${this.settings.mtu}\n`
+ }
+ txt += `\n# ${remark}\n`
+ txt += `[Peer]\n`
+ txt += `PublicKey = ${this.settings.pubKey}\n`
+ txt += `AllowedIPs = 0.0.0.0/0, ::/0\n`
+ txt += `Endpoint = ${address}:${port}`
+ if (this.settings.peers[peerId].psk) {
+ txt += `\nPresharedKey = ${this.settings.peers[peerId].psk}`
+ }
+ if (this.settings.peers[peerId].keepAlive) {
+ txt += `\nPersistentKeepalive = ${this.settings.peers[peerId].keepAlive}\n`
+ }
+ return txt;
+ }
+
genLink(address='', port=this.port, forceTls='same', remark='', client) {
switch (this.protocol) {
case Protocols.VMESS:
@@ -1580,6 +1602,7 @@ class Inbound extends XrayCommonClass {
}
genInboundLinks(remark = '', remarkModel = '-ieo') {
+ let addr = !ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0" ? this.listen : location.hostname;
if(this.clients){
let links = [];
this.clients.forEach((client) => {
@@ -1589,7 +1612,14 @@ class Inbound extends XrayCommonClass {
});
return links.join('\r\n');
} else {
- if(this.protocol == Protocols.SHADOWSOCKS && !this.isSSMultiUser) return this.genSSLink(this.listen, this.port, 'same', remark);
+ if(this.protocol == Protocols.SHADOWSOCKS && !this.isSSMultiUser) return this.genSSLink(addr, this.port, 'same', remark);
+ if(this.protocol == Protocols.WIREGUARD) {
+ let links = [];
+ this.settings.peers.forEach((p,index) => {
+ links.push(this.getWireguardLink(addr,this.port,remark + remarkModel.charAt(0) + (index+1),index));
+ });
+ return links.join('\r\n');
+ }
return '';
}
}
@@ -2297,9 +2327,13 @@ Inbound.WireguardSettings = class extends XrayCommonClass {
};
Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
- constructor(publicKey=Wireguard.generateKeypair().publicKey, psk='', allowedIPs=['0.0.0.0/0','::/0'], keepAlive=0) {
+ constructor(privateKey, publicKey, psk='', allowedIPs=['10.0.0.0/24'], keepAlive=0) {
super();
+ this.privateKey = privateKey
this.publicKey = publicKey;
+ if (!this.publicKey){
+ [this.publicKey, this.privateKey] = Object.values(Wireguard.generateKeypair())
+ }
this.psk = psk;
this.allowedIPs = allowedIPs;
this.keepAlive = keepAlive;
@@ -2307,6 +2341,7 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
static fromJson(json={}){
return new Inbound.WireguardSettings.Peer(
+ json.privateKey,
json.publicKey,
json.preSharedKey,
json.allowedIPs,
@@ -2316,6 +2351,7 @@ Inbound.WireguardSettings.Peer = class extends XrayCommonClass {
toJson() {
return {
+ privateKey: this.privateKey,
publicKey: this.publicKey,
preSharedKey: this.psk.length>0 ? this.psk : undefined,
allowedIPs: this.allowedIPs,