Pārlūkot izejas kodu

improve randomShortId , format document

mhsanaei 3 mēneši atpakaļ
vecāks
revīzija
b8c3555b09

+ 161 - 123
web/assets/js/model/outbound.js

@@ -72,10 +72,12 @@ const WireguardDomainStrategy = [
 Object.freeze(Protocols);
 Object.freeze(SSMethods);
 Object.freeze(TLS_FLOW_CONTROL);
+Object.freeze(UTLS_FINGERPRINT);
 Object.freeze(ALPN_OPTION);
 Object.freeze(OutboundDomainStrategies);
 Object.freeze(WireguardDomainStrategy);
 
+
 class CommonClass {
 
     static toJsonArray(arr) {
@@ -90,30 +92,30 @@ class CommonClass {
         return this;
     }
 
-    toString(format=true) {
+    toString(format = true) {
         return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson());
     }
 }
 
 class TcpStreamSettings extends CommonClass {
-    constructor(type='none', host, path) {
+    constructor(type = 'none', host, path) {
         super();
         this.type = type;
         this.host = host;
         this.path = path;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         let header = json.header;
         if (!header) return new TcpStreamSettings();
-        if(header.type == 'http' && header.request){
+        if (header.type == 'http' && header.request) {
             return new TcpStreamSettings(
                 header.type,
                 header.request.headers.Host.join(','),
                 header.request.path.join(','),
             );
         }
-        return new TcpStreamSettings(header.type,'','');
+        return new TcpStreamSettings(header.type, '', '');
     }
 
     toJson() {
@@ -132,15 +134,17 @@ class TcpStreamSettings extends CommonClass {
 }
 
 class KcpStreamSettings extends CommonClass {
-    constructor(mtu=1350, tti=20,
-                uplinkCapacity=5,
-                downlinkCapacity=20,
-                congestion=false,
-                readBufferSize=2,
-                writeBufferSize=2,
-                type='none',
-                seed='',
-                ) {
+    constructor(
+        mtu = 1350,
+        tti = 50,
+        uplinkCapacity = 5,
+        downlinkCapacity = 20,
+        congestion = false,
+        readBufferSize = 2,
+        writeBufferSize = 2,
+        type = 'none',
+        seed = '',
+    ) {
         super();
         this.mtu = mtu;
         this.tti = tti;
@@ -153,7 +157,7 @@ class KcpStreamSettings extends CommonClass {
         this.seed = seed;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new KcpStreamSettings(
             json.mtu,
             json.tti,
@@ -185,13 +189,13 @@ class KcpStreamSettings extends CommonClass {
 }
 
 class WsStreamSettings extends CommonClass {
-    constructor(path='/', host='') {
+    constructor(path = '/', host = '') {
         super();
         this.path = path;
         this.host = host;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new WsStreamSettings(
             json.path,
             json.host,
@@ -207,13 +211,13 @@ class WsStreamSettings extends CommonClass {
 }
 
 class HttpStreamSettings extends CommonClass {
-    constructor(path='/', host='') {
+    constructor(path = '/', host = '') {
         super();
         this.path = path;
         this.host = host;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new HttpStreamSettings(
             json.path,
             json.host ? json.host.join(',') : '',
@@ -229,15 +233,18 @@ class HttpStreamSettings extends CommonClass {
 }
 
 class QuicStreamSettings extends CommonClass {
-    constructor(security='none',
-                key='', type='none') {
+    constructor(
+        security = 'none',
+        key = '',
+        type = 'none'
+    ) {
         super();
         this.security = security;
         this.key = key;
         this.type = type;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new QuicStreamSettings(
             json.security,
             json.key,
@@ -257,15 +264,19 @@ class QuicStreamSettings extends CommonClass {
 }
 
 class GrpcStreamSettings extends CommonClass {
-    constructor(serviceName="", authority="", multiMode=false) {
+    constructor(
+        serviceName = "",
+        authority = "",
+        multiMode = false
+    ) {
         super();
         this.serviceName = serviceName;
         this.authority = authority;
         this.multiMode = multiMode;
     }
 
-    static fromJson(json={}) {
-        return new GrpcStreamSettings(json.serviceName, json.authority, json.multiMode );
+    static fromJson(json = {}) {
+        return new GrpcStreamSettings(json.serviceName, json.authority, json.multiMode);
     }
 
     toJson() {
@@ -278,13 +289,13 @@ class GrpcStreamSettings extends CommonClass {
 }
 
 class HttpUpgradeStreamSettings extends CommonClass {
-    constructor(path='/', host='') {
+    constructor(path = '/', host = '') {
         super();
         this.path = path;
         this.host = host;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new HttpUpgradeStreamSettings(
             json.path,
             json.host,
@@ -300,13 +311,13 @@ class HttpUpgradeStreamSettings extends CommonClass {
 }
 
 class SplitHTTPStreamSettings extends CommonClass {
-    constructor(path='/', host='') {
+    constructor(path = '/', host = '') {
         super();
         this.path = path;
         this.host = host;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new SplitHTTPStreamSettings(
             json.path,
             json.host,
@@ -322,10 +333,12 @@ class SplitHTTPStreamSettings extends CommonClass {
 }
 
 class TlsStreamSettings extends CommonClass {
-    constructor(serverName='',
-                alpn=[],
-                fingerprint = '',
-                allowInsecure = false) {
+    constructor(
+        serverName = '',
+        alpn = [],
+        fingerprint = '',
+        allowInsecure = false
+    ) {
         super();
         this.serverName = serverName;
         this.alpn = alpn;
@@ -333,7 +346,7 @@ class TlsStreamSettings extends CommonClass {
         this.allowInsecure = allowInsecure;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new TlsStreamSettings(
             json.serverName,
             json.alpn,
@@ -353,7 +366,13 @@ class TlsStreamSettings extends CommonClass {
 }
 
 class RealityStreamSettings extends CommonClass {
-    constructor(publicKey = '', fingerprint = '', serverName = '', shortId = '', spiderX = '/') {
+    constructor(
+        publicKey = '',
+        fingerprint = '',
+        serverName = '',
+        shortId = '',
+        spiderX = '/'
+    ) {
         super();
         this.publicKey = publicKey;
         this.fingerprint = fingerprint;
@@ -381,7 +400,13 @@ class RealityStreamSettings extends CommonClass {
     }
 };
 class SockoptStreamSettings extends CommonClass {
-    constructor(dialerProxy = "", tcpFastOpen = false, tcpKeepAliveInterval = 0, tcpMptcp = false, tcpNoDelay = false) {
+    constructor(
+        dialerProxy = "",
+        tcpFastOpen = false,
+        tcpKeepAliveInterval = 0,
+        tcpMptcp = false,
+        tcpNoDelay = false
+    ) {
         super();
         this.dialerProxy = dialerProxy;
         this.tcpFastOpen = tcpFastOpen;
@@ -413,20 +438,21 @@ class SockoptStreamSettings extends CommonClass {
 }
 
 class StreamSettings extends CommonClass {
-    constructor(network='tcp',
-                security='none',
-                tlsSettings=new TlsStreamSettings(),
-                realitySettings = new RealityStreamSettings(),
-                tcpSettings=new TcpStreamSettings(),
-                kcpSettings=new KcpStreamSettings(),
-                wsSettings=new WsStreamSettings(),
-                httpSettings=new HttpStreamSettings(),
-                quicSettings=new QuicStreamSettings(),
-                grpcSettings=new GrpcStreamSettings(),
-                httpupgradeSettings=new HttpUpgradeStreamSettings(),
-                splithttpSettings=new SplitHTTPStreamSettings(),
-                sockopt = undefined,
-                ) {
+    constructor(
+        network = 'tcp',
+        security = 'none',
+        tlsSettings = new TlsStreamSettings(),
+        realitySettings = new RealityStreamSettings(),
+        tcpSettings = new TcpStreamSettings(),
+        kcpSettings = new KcpStreamSettings(),
+        wsSettings = new WsStreamSettings(),
+        httpSettings = new HttpStreamSettings(),
+        quicSettings = new QuicStreamSettings(),
+        grpcSettings = new GrpcStreamSettings(),
+        httpupgradeSettings = new HttpUpgradeStreamSettings(),
+        splithttpSettings = new SplitHTTPStreamSettings(),
+        sockopt = undefined,
+    ) {
         super();
         this.network = network;
         this.security = security;
@@ -442,7 +468,7 @@ class StreamSettings extends CommonClass {
         this.splithttp = splithttpSettings;
         this.sockopt = sockopt;
     }
-    
+
     get isTls() {
         return this.security === 'tls';
     }
@@ -459,7 +485,7 @@ class StreamSettings extends CommonClass {
         this.sockopt = value ? new SockoptStreamSettings() : undefined;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new StreamSettings(
             json.network,
             json.security,
@@ -528,9 +554,9 @@ class Mux extends CommonClass {
 
 class Outbound extends CommonClass {
     constructor(
-        tag='',
-        protocol=Protocols.VMess,
-        settings=null,
+        tag = '',
+        protocol = Protocols.VMess,
+        settings = null,
         streamSettings = new StreamSettings(),
         sendThrough,
         mux = new Mux(),
@@ -556,7 +582,7 @@ class Outbound extends CommonClass {
 
     canEnableTls() {
         if (![Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(this.protocol)) return false;
-        return ["tcp", "ws", "http", "quic", "grpc", "httpupgrade" , "splithttp"].includes(this.stream.network);
+        return ["tcp", "ws", "http", "quic", "grpc", "httpupgrade", "splithttp"].includes(this.stream.network);
     }
 
     //this is used for xtls-rprx-vision
@@ -577,7 +603,7 @@ class Outbound extends CommonClass {
     }
 
     canEnableMux() {
-        if (this.settings.flow && this.settings.flow != ''){
+        if (this.settings.flow && this.settings.flow != '') {
             this.mux.enabled = false;
             return false;
         }
@@ -608,7 +634,7 @@ class Outbound extends CommonClass {
         return [Protocols.Socks, Protocols.HTTP].includes(this.protocol);
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new Outbound(
             json.tag,
             json.protocol,
@@ -639,8 +665,8 @@ class Outbound extends CommonClass {
 
     static fromLink(link) {
         data = link.split('://');
-        if(data.length !=2) return null;
-        switch(data[0].toLowerCase()){
+        if (data.length != 2) return null;
+        switch (data[0].toLowerCase()) {
             case Protocols.VMess:
                 return this.fromVmessLink(JSON.parse(Base64.decode(data[1])));
             case Protocols.VLESS:
@@ -652,7 +678,7 @@ class Outbound extends CommonClass {
         }
     }
 
-    static fromVmessLink(json={}){
+    static fromVmessLink(json = {}) {
         let stream = new StreamSettings(json.net, json.tls);
 
         let network = json.net;
@@ -666,7 +692,7 @@ class Outbound extends CommonClass {
             stream.type = json.type;
             stream.seed = json.path;
         } else if (network === 'ws') {
-            stream.ws = new WsStreamSettings(json.path,json.host);
+            stream.ws = new WsStreamSettings(json.path, json.host);
         } else if (network === 'http' || network == 'h2') {
             stream.network = 'http'
             stream.http = new HttpStreamSettings(
@@ -680,12 +706,12 @@ class Outbound extends CommonClass {
         } else if (network === 'grpc') {
             stream.grpc = new GrpcStreamSettings(json.path, json.authority, json.type == 'multi');
         } else if (network === 'httpupgrade') {
-            stream.httpupgrade = new HttpUpgradeStreamSettings(json.path,json.host);
+            stream.httpupgrade = new HttpUpgradeStreamSettings(json.path, json.host);
         } else if (network === 'splithttp') {
-            stream.splithttp = new SplitHTTPStreamSettings(json.path,json.host);
+            stream.splithttp = new SplitHTTPStreamSettings(json.path, json.host);
         }
 
-        if(json.tls && json.tls == 'tls'){
+        if (json.tls && json.tls == 'tls') {
             stream.tls = new TlsStreamSettings(
                 json.sni,
                 json.alpn ? json.alpn.split(',') : [],
@@ -698,7 +724,7 @@ class Outbound extends CommonClass {
         return new Outbound(json.ps, Protocols.VMess, new Outbound.VmessSettings(json.add, port, json.id), stream);
     }
 
-    static fromParamLink(link){
+    static fromParamLink(link) {
         const url = new URL(link);
         let type = url.searchParams.get('type') ?? 'tcp';
         let security = url.searchParams.get('security') ?? 'none';
@@ -715,9 +741,9 @@ class Outbound extends CommonClass {
             stream.kcp.type = headerType ?? 'none';
             stream.kcp.seed = path;
         } else if (type === 'ws') {
-            stream.ws = new WsStreamSettings(path,host);
+            stream.ws = new WsStreamSettings(path, host);
         } else if (type === 'http' || type == 'h2') {
-            stream.http = new HttpStreamSettings(path,host);
+            stream.http = new HttpStreamSettings(path, host);
         } else if (type === 'quic') {
             stream.quic = new QuicStreamSettings(
                 url.searchParams.get('quicSecurity') ?? 'none',
@@ -729,25 +755,25 @@ class Outbound extends CommonClass {
                 url.searchParams.get('authority') ?? '',
                 url.searchParams.get('mode') == 'multi');
         } else if (type === 'httpupgrade') {
-            stream.httpupgrade = new HttpUpgradeStreamSettings(path,host);
+            stream.httpupgrade = new HttpUpgradeStreamSettings(path, host);
         } else if (type === 'splithttp') {
-            stream.splithttp = new SplitHTTPStreamSettings(path,host);
+            stream.splithttp = new SplitHTTPStreamSettings(path, host);
         }
 
-        if(security == 'tls'){
-            let fp=url.searchParams.get('fp') ?? 'none';
-            let alpn=url.searchParams.get('alpn');
-            let allowInsecure=url.searchParams.get('allowInsecure');
-            let sni=url.searchParams.get('sni') ?? '';
+        if (security == 'tls') {
+            let fp = url.searchParams.get('fp') ?? 'none';
+            let alpn = url.searchParams.get('alpn');
+            let allowInsecure = url.searchParams.get('allowInsecure');
+            let sni = url.searchParams.get('sni') ?? '';
             stream.tls = new TlsStreamSettings(sni, alpn ? alpn.split(',') : [], fp, allowInsecure == 1);
         }
 
-        if(security == 'reality'){
-            let pbk=url.searchParams.get('pbk');
-            let fp=url.searchParams.get('fp');
-            let sni=url.searchParams.get('sni') ?? '';
-            let sid=url.searchParams.get('sid') ?? '';
-            let spx=url.searchParams.get('spx') ?? '';
+        if (security == 'reality') {
+            let pbk = url.searchParams.get('pbk');
+            let fp = url.searchParams.get('fp');
+            let sni = url.searchParams.get('sni') ?? '';
+            let sid = url.searchParams.get('sid') ?? '';
+            let spx = url.searchParams.get('spx') ?? '';
             stream.reality = new RealityStreamSettings(pbk, fp, sni, sid, spx);
         }
 
@@ -755,14 +781,14 @@ class Outbound extends CommonClass {
         const match = link.match(regex);
 
         if (!match) return null;
-        let [, protocol, userData, address, port, ] = match;
+        let [, protocol, userData, address, port,] = match;
         port *= 1;
-        if(protocol == 'ss') {
+        if (protocol == 'ss') {
             protocol = 'shadowsocks';
             userData = atob(userData).split(':');
         }
         var settings;
-        switch(protocol){
+        switch (protocol) {
             case Protocols.VLESS:
                 settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? '');
                 break;
@@ -770,7 +796,7 @@ class Outbound extends CommonClass {
                 settings = new Outbound.TrojanSettings(address, port, userData);
                 break;
             case Protocols.Shadowsocks:
-                let method = userData.splice(0,1)[0];
+                let method = userData.splice(0, 1)[0];
                 settings = new Outbound.ShadowsocksSettings(address, port, userData.join(":"), method, true);
                 break;
             default:
@@ -826,13 +852,13 @@ Outbound.Settings = class extends CommonClass {
     }
 };
 Outbound.FreedomSettings = class extends CommonClass {
-    constructor(domainStrategy='', fragment={}) {
+    constructor(domainStrategy = '', fragment = {}) {
         super();
         this.domainStrategy = domainStrategy;
         this.fragment = fragment;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new Outbound.FreedomSettings(
             json.domainStrategy,
             json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined,
@@ -847,14 +873,14 @@ Outbound.FreedomSettings = class extends CommonClass {
     }
 };
 Outbound.FreedomSettings.Fragment = class extends CommonClass {
-    constructor(packets='1-3',length='',interval=''){
+    constructor(packets = '1-3', length = '', interval = '') {
         super();
         this.packets = packets;
         this.length = length;
         this.interval = interval;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new Outbound.FreedomSettings.Fragment(
             json.packets,
             json.length,
@@ -868,7 +894,7 @@ Outbound.BlackholeSettings = class extends CommonClass {
         this.type = type;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         return new Outbound.BlackholeSettings(
             json.response ? json.response.type : undefined,
         );
@@ -876,19 +902,19 @@ Outbound.BlackholeSettings = class extends CommonClass {
 
     toJson() {
         return {
-            response: ObjectUtil.isEmpty(this.type) ? undefined : {type: this.type},
+            response: ObjectUtil.isEmpty(this.type) ? undefined : { type: this.type },
         };
     }
 };
 Outbound.DNSSettings = class extends CommonClass {
-    constructor(network='udp', address='1.1.1.1', port=53) {
+    constructor(network = 'udp', address = '1.1.1.1', port = 53) {
         super();
         this.network = network;
         this.address = address;
         this.port = port;
     }
 
-    static fromJson(json={}){
+    static fromJson(json = {}) {
         return new Outbound.DNSSettings(
             json.network,
             json.address,
@@ -904,8 +930,8 @@ Outbound.VmessSettings = class extends CommonClass {
         this.id = id;
     }
 
-    static fromJson(json={}) {
-        if(ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VmessSettings();
+    static fromJson(json = {}) {
+        if (ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VmessSettings();
         return new Outbound.VmessSettings(
             json.vnext[0].address,
             json.vnext[0].port,
@@ -918,13 +944,13 @@ Outbound.VmessSettings = class extends CommonClass {
             vnext: [{
                 address: this.address,
                 port: this.port,
-                users: [{id: this.id}],
+                users: [{ id: this.id }],
             }],
         };
     }
 };
 Outbound.VLESSSettings = class extends CommonClass {
-    constructor(address, port, id, flow, encryption='none') {
+    constructor(address, port, id, flow, encryption = 'none') {
         super();
         this.address = address;
         this.port = port;
@@ -933,8 +959,8 @@ Outbound.VLESSSettings = class extends CommonClass {
         this.encryption = encryption
     }
 
-    static fromJson(json={}) {
-        if(ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VLESSSettings();
+    static fromJson(json = {}) {
+        if (ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VLESSSettings();
         return new Outbound.VLESSSettings(
             json.vnext[0].address,
             json.vnext[0].port,
@@ -949,7 +975,7 @@ Outbound.VLESSSettings = class extends CommonClass {
             vnext: [{
                 address: this.address,
                 port: this.port,
-                users: [{id: this.id, flow: this.flow, encryption: 'none',}],
+                users: [{ id: this.id, flow: this.flow, encryption: 'none', }],
             }],
         };
     }
@@ -962,8 +988,8 @@ Outbound.TrojanSettings = class extends CommonClass {
         this.password = password;
     }
 
-    static fromJson(json={}) {
-        if(ObjectUtil.isArrEmpty(json.servers)) return new Outbound.TrojanSettings();
+    static fromJson(json = {}) {
+        if (ObjectUtil.isArrEmpty(json.servers)) return new Outbound.TrojanSettings();
         return new Outbound.TrojanSettings(
             json.servers[0].address,
             json.servers[0].port,
@@ -992,9 +1018,9 @@ Outbound.ShadowsocksSettings = class extends CommonClass {
         this.UoTVersion = UoTVersion;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         let servers = json.servers;
-        if(ObjectUtil.isArrEmpty(servers)) servers=[{}];
+        if (ObjectUtil.isArrEmpty(servers)) servers = [{}];
         return new Outbound.ShadowsocksSettings(
             servers[0].address,
             servers[0].port,
@@ -1028,9 +1054,9 @@ Outbound.SocksSettings = class extends CommonClass {
         this.pass = pass;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         let servers = json.servers;
-        if(ObjectUtil.isArrEmpty(servers)) servers=[{users: [{}]}];
+        if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
         return new Outbound.SocksSettings(
             servers[0].address,
             servers[0].port,
@@ -1044,7 +1070,7 @@ Outbound.SocksSettings = class extends CommonClass {
             servers: [{
                 address: this.address,
                 port: this.port,
-                users: ObjectUtil.isEmpty(this.user) ? [] : [{user: this.user, pass: this.pass}],
+                users: ObjectUtil.isEmpty(this.user) ? [] : [{ user: this.user, pass: this.pass }],
             }],
         };
     }
@@ -1058,9 +1084,9 @@ Outbound.HttpSettings = class extends CommonClass {
         this.pass = pass;
     }
 
-    static fromJson(json={}) {
+    static fromJson(json = {}) {
         let servers = json.servers;
-        if(ObjectUtil.isArrEmpty(servers)) servers=[{users: [{}]}];
+        if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
         return new Outbound.HttpSettings(
             servers[0].address,
             servers[0].port,
@@ -1074,7 +1100,7 @@ Outbound.HttpSettings = class extends CommonClass {
             servers: [{
                 address: this.address,
                 port: this.port,
-                users: ObjectUtil.isEmpty(this.user) ? [] : [{user: this.user, pass: this.pass}],
+                users: ObjectUtil.isEmpty(this.user) ? [] : [{ user: this.user, pass: this.pass }],
             }],
         };
     }
@@ -1082,17 +1108,23 @@ Outbound.HttpSettings = class extends CommonClass {
 
 Outbound.WireguardSettings = class extends CommonClass {
     constructor(
-            mtu=1420, secretKey='',
-            address=[''], workers=2, domainStrategy='', reserved='',
-            peers=[new Outbound.WireguardSettings.Peer()], kernelMode=false) {
+        mtu = 1420,
+        secretKey = '',
+        address = [''],
+        workers = 2,
+        domainStrategy = '',
+        reserved = '',
+        peers = [new Outbound.WireguardSettings.Peer()],
+        kernelMode = false
+    ) {
         super();
         this.mtu = mtu;
         this.secretKey = secretKey;
-        this.pubKey = secretKey.length>0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
-        this.address = address instanceof Array ? address.join(',') : address;
+        this.pubKey = secretKey.length > 0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
+        this.address = Array.isArray(address) ? address.join(',') : address;
         this.workers = workers;
         this.domainStrategy = domainStrategy;
-        this.reserved = reserved instanceof Array ? reserved.join(',') : reserved;
+        this.reserved = Array.isArray(reserved) ? reserved.join(',') : reserved;
         this.peers = peers;
         this.kernelMode = kernelMode;
     }
@@ -1105,7 +1137,7 @@ Outbound.WireguardSettings = class extends CommonClass {
         this.peers.splice(index, 1);
     }
 
-    static fromJson(json={}){
+    static fromJson(json = {}) {
         return new Outbound.WireguardSettings(
             json.mtu,
             json.secretKey,
@@ -1120,10 +1152,10 @@ Outbound.WireguardSettings = class extends CommonClass {
 
     toJson() {
         return {
-            mtu: this.mtu?? undefined,
+            mtu: this.mtu ?? undefined,
             secretKey: this.secretKey,
             address: this.address ? this.address.split(",") : [],
-            workers: this.workers?? undefined,
+            workers: this.workers ?? undefined,
             domainStrategy: WireguardDomainStrategy.includes(this.domainStrategy) ? this.domainStrategy : undefined,
             reserved: this.reserved ? this.reserved.split(",").map(Number) : undefined,
             peers: Outbound.WireguardSettings.Peer.toJsonArray(this.peers),
@@ -1133,7 +1165,13 @@ Outbound.WireguardSettings = class extends CommonClass {
 };
 
 Outbound.WireguardSettings.Peer = class extends CommonClass {
-    constructor(publicKey='', psk='', allowedIPs=['0.0.0.0/0','::/0'], endpoint='', keepAlive=0) {
+    constructor(
+        publicKey = '',
+        psk = '',
+        allowedIPs = ['0.0.0.0/0', '::/0'],
+        endpoint = '',
+        keepAlive = 0
+    ) {
         super();
         this.publicKey = publicKey;
         this.psk = psk;
@@ -1142,7 +1180,7 @@ Outbound.WireguardSettings.Peer = class extends CommonClass {
         this.keepAlive = keepAlive;
     }
 
-    static fromJson(json={}){
+    static fromJson(json = {}) {
         return new Outbound.WireguardSettings.Peer(
             json.publicKey,
             json.preSharedKey,
@@ -1155,10 +1193,10 @@ Outbound.WireguardSettings.Peer = class extends CommonClass {
     toJson() {
         return {
             publicKey: this.publicKey,
-            preSharedKey: this.psk.length>0 ? this.psk : undefined,
+            preSharedKey: this.psk.length > 0 ? this.psk : undefined,
             allowedIPs: this.allowedIPs ? this.allowedIPs : undefined,
             endpoint: this.endpoint,
-            keepAlive: this.keepAlive?? undefined,
+            keepAlive: this.keepAlive ?? undefined,
         };
     }
 };

+ 1 - 1
web/assets/js/model/setting.js

@@ -26,7 +26,7 @@ class AllSetting {
         this.secretEnable = false;
         this.subEnable = false;
         this.subListen = "";
-        this.subPort = "2096";
+        this.subPort = 2096;
         this.subPath = "/sub/";
         this.subJsonPath = "/json/";
         this.subDomain = "";

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 235 - 194
web/assets/js/model/xray.js


+ 15 - 5
web/assets/js/util/utils.js

@@ -100,12 +100,22 @@ class RandomUtil {
     }
 
     static randomShortId() {
-        let str = '';
-        for (let i = 0; i < 8; ++i) {
-            str += seq[this.randomInt(16)];
+        const lengths = [2, 4, 6, 8, 10, 12, 14, 16];
+        for (let i = lengths.length - 1; i > 0; i--) {
+            const j = Math.floor(Math.random() * (i + 1));
+            [lengths[i], lengths[j]] = [lengths[j], lengths[i]];
         }
-        return str;
-    }
+
+        let shortIds = [];
+        for (let length of lengths) {
+            let shortId = '';
+            for (let i = 0; i < length; i++) {
+                shortId += seq[this.randomInt(16)];
+            }
+            shortIds.push(shortId);
+        }
+        return shortIds;
+    }    
 
     static randomLowerAndNum(len) {
         let str = '';

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels