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>2026-04-26 21:06:24 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2026-04-26 21:06:24 +0300
commit4521beab7c245a3420ae558ce34c37fb9ed1a53d (patch)
tree7ba02cbea1702715b1932581a3d6b9d0613beaf9 /web/assets
parenta62c637632d0e4f0ff74fe185a3ea50048cb73d8 (diff)
wireguard: link
Diffstat (limited to 'web/assets')
-rw-r--r--web/assets/js/model/inbound.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/web/assets/js/model/inbound.js b/web/assets/js/model/inbound.js
index 26da6cb3..e3816060 100644
--- a/web/assets/js/model/inbound.js
+++ b/web/assets/js/model/inbound.js
@@ -1907,7 +1907,7 @@ class Inbound extends XrayCommonClass {
return url.toString();
}
- getWireguardLink(address, port, remark, peerId) {
+ getWireguardTxt(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`
@@ -1929,6 +1929,48 @@ class Inbound extends XrayCommonClass {
return txt;
}
+ getWireguardLink(address, port, remark, peerId) {
+ const peer = this.settings?.peers?.[peerId];
+ if (!peer) return '';
+
+ const link = `wireguard://${address}:${port}`;
+ const url = new URL(link);
+ url.username = peer.privateKey || '';
+
+ if (this.settings?.pubKey) {
+ url.searchParams.set("publickey", this.settings.pubKey);
+ }
+ if (Array.isArray(peer.allowedIPs) && peer.allowedIPs.length > 0 && peer.allowedIPs[0]) {
+ url.searchParams.set("address", peer.allowedIPs[0]);
+ }
+ if (this.settings?.mtu) {
+ url.searchParams.set("mtu", this.settings.mtu);
+ }
+
+ url.hash = encodeURIComponent(remark);
+ return url.toString();
+ }
+
+ genWireguardLinks(remark = '', remarkModel = '-ieo') {
+ const addr = !ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0" ? this.listen : location.hostname;
+ const separationChar = remarkModel.charAt(0);
+ let links = [];
+ this.settings.peers.forEach((p, index) => {
+ links.push(this.getWireguardLink(addr, this.port, remark + separationChar + (index + 1), index));
+ });
+ return links.join('\r\n');
+ }
+
+ genWireguardConfigs(remark = '', remarkModel = '-ieo') {
+ const addr = !ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0" ? this.listen : location.hostname;
+ const separationChar = remarkModel.charAt(0);
+ let links = [];
+ this.settings.peers.forEach((p, index) => {
+ links.push(this.getWireguardTxt(addr, this.port, remark + separationChar + (index + 1), index));
+ });
+ return links.join('\r\n');
+ }
+
genLink(address = '', port = this.port, forceTls = 'same', remark = '', client) {
switch (this.protocol) {
case Protocols.VMESS:
@@ -1989,11 +2031,7 @@ class Inbound extends XrayCommonClass {
} else {
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 this.genWireguardConfigs(remark, remarkModel);
}
return '';
}