mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-28 10:25:49 +00:00
wireguard: link
This commit is contained in:
parent
a62c637632
commit
4521beab7c
2 changed files with 58 additions and 7 deletions
|
|
@ -1907,7 +1907,7 @@ class Inbound extends XrayCommonClass {
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
getWireguardLink(address, port, remark, peerId) {
|
getWireguardTxt(address, port, remark, peerId) {
|
||||||
let txt = `[Interface]\n`
|
let txt = `[Interface]\n`
|
||||||
txt += `PrivateKey = ${this.settings.peers[peerId].privateKey}\n`
|
txt += `PrivateKey = ${this.settings.peers[peerId].privateKey}\n`
|
||||||
txt += `Address = ${this.settings.peers[peerId].allowedIPs[0]}\n`
|
txt += `Address = ${this.settings.peers[peerId].allowedIPs[0]}\n`
|
||||||
|
|
@ -1929,6 +1929,48 @@ class Inbound extends XrayCommonClass {
|
||||||
return txt;
|
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) {
|
genLink(address = '', port = this.port, forceTls = 'same', remark = '', client) {
|
||||||
switch (this.protocol) {
|
switch (this.protocol) {
|
||||||
case Protocols.VMESS:
|
case Protocols.VMESS:
|
||||||
|
|
@ -1989,11 +2031,7 @@ class Inbound extends XrayCommonClass {
|
||||||
} else {
|
} else {
|
||||||
if (this.protocol == Protocols.SHADOWSOCKS && !this.isSSMultiUser) return this.genSSLink(addr, this.port, 'same', remark);
|
if (this.protocol == Protocols.SHADOWSOCKS && !this.isSSMultiUser) return this.genSSLink(addr, this.port, 'same', remark);
|
||||||
if (this.protocol == Protocols.WIREGUARD) {
|
if (this.protocol == Protocols.WIREGUARD) {
|
||||||
let links = [];
|
return this.genWireguardConfigs(remark, remarkModel);
|
||||||
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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -513,9 +513,19 @@
|
||||||
<div v-html="infoModal.links[index].replaceAll(`\n`,`<br />`)"
|
<div v-html="infoModal.links[index].replaceAll(`\n`,`<br />`)"
|
||||||
:style="{ borderRadius: '1rem', padding: '0.5rem' }" class="client-table-odd-row">
|
:style="{ borderRadius: '1rem', padding: '0.5rem' }" class="client-table-odd-row">
|
||||||
</div>
|
</div>
|
||||||
|
<a-divider orientation="center">Link</a-divider>
|
||||||
|
<tr-info-title class="tr-info-title">
|
||||||
|
<a-tag color="green">Link</a-tag>
|
||||||
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
|
<a-button :style="{ minWidth: '24px' }" size="small" icon="snippets"
|
||||||
|
@click="copy(infoModal.wireguardLinks[index])"></a-button>
|
||||||
|
</a-tooltip>
|
||||||
|
</tr-info-title>
|
||||||
|
<code :style="{ display: 'block', whiteSpace: 'normal', wordBreak: 'break-all' }">[[ infoModal.wireguardLinks[index] ]]</code>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</template>
|
||||||
</table>
|
</table>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -603,6 +613,7 @@
|
||||||
upStats: 0,
|
upStats: 0,
|
||||||
downStats: 0,
|
downStats: 0,
|
||||||
links: [],
|
links: [],
|
||||||
|
wireguardLinks: [],
|
||||||
index: null,
|
index: null,
|
||||||
isExpired: false,
|
isExpired: false,
|
||||||
subLink: '',
|
subLink: '',
|
||||||
|
|
@ -633,9 +644,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.inbound.protocol == Protocols.WIREGUARD) {
|
if (this.inbound.protocol == Protocols.WIREGUARD) {
|
||||||
this.links = this.inbound.genInboundLinks(dbInbound.remark).split('\r\n')
|
this.links = this.inbound.genWireguardConfigs(dbInbound.remark).split('\r\n')
|
||||||
|
this.wireguardLinks = this.inbound.genWireguardLinks(dbInbound.remark).split('\r\n')
|
||||||
} else {
|
} else {
|
||||||
this.links = this.inbound.genAllLinks(this.dbInbound.remark, app.remarkModel, this.clientSettings);
|
this.links = this.inbound.genAllLinks(this.dbInbound.remark, app.remarkModel, this.clientSettings);
|
||||||
|
this.wireguardLinks = [];
|
||||||
}
|
}
|
||||||
if (this.clientSettings) {
|
if (this.clientSettings) {
|
||||||
if (this.clientSettings.subId) {
|
if (this.clientSettings.subId) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue