diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index c6f5bf50..89032514 100644 --- a/web/assets/js/model/outbound.js +++ b/web/assets/js/model/outbound.js @@ -8,6 +8,7 @@ const Protocols = { Shadowsocks: "shadowsocks", Socks: "socks", HTTP: "http", + Wireguard: "wireguard" }; const SSMethods = { @@ -625,6 +626,7 @@ Outbound.Settings = class extends CommonClass { case Protocols.Shadowsocks: return new Outbound.ShadowsocksSettings(); case Protocols.Socks: return new Outbound.SocksSettings(); case Protocols.HTTP: return new Outbound.HttpSettings(); + case Protocols.Wireguard: return new Outbound.WireguardSettings(); default: return null; } } @@ -640,6 +642,7 @@ Outbound.Settings = class extends CommonClass { case Protocols.Shadowsocks: return Outbound.ShadowsocksSettings.fromJson(json); case Protocols.Socks: return Outbound.SocksSettings.fromJson(json); case Protocols.HTTP: return Outbound.HttpSettings.fromJson(json); + case Protocols.Wireguard: return Outbound.WireguardSettings.fromJson(json); default: return null; } } @@ -897,4 +900,43 @@ 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) { + super(); + this.mtu = mtu, + this.secretKey = secretKey, + this.address = address, + this.publicKey = publicKey, + this.allowedIPs = allowedIPs, + this.endpoint = endpoint, + this.keepAlive = keepAlive + } + + 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 + ); + } + + toJson() { + return { + mtu: this.mtu, + 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 + }] + }; + } }; \ No newline at end of file diff --git a/web/html/xui/form/outbound.html b/web/html/xui/form/outbound.html index a5bfe3fd..4cc77ac9 100644 --- a/web/html/xui/form/outbound.html +++ b/web/html/xui/form/outbound.html @@ -66,6 +66,31 @@ + + +