From b8c3555b09d716d877b69b477a7f390e8acbc9af Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Tue, 6 Aug 2024 17:06:39 +0200 Subject: improve randomShortId , format document --- web/assets/js/model/outbound.js | 284 ++++++++++++--------- web/assets/js/model/setting.js | 2 +- web/assets/js/model/xray.js | 541 +++++++++++++++++++++------------------- web/assets/js/util/utils.js | 20 +- 4 files changed, 468 insertions(+), 379 deletions(-) (limited to 'web') diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index bcd35478..1ca6cee4 100644 --- a/web/assets/js/model/outbound.js +++ b/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, }; } }; \ No newline at end of file diff --git a/web/assets/js/model/setting.js b/web/assets/js/model/setting.js index cd46ab34..9f745ae8 100644 --- a/web/assets/js/model/setting.js +++ b/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 = ""; diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 5c3f3010..d239160b 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -78,9 +78,9 @@ const ALPN_OPTION = { }; const SNIFFING_OPTION = { - HTTP: "http", - TLS: "tls", - QUIC: "quic", + HTTP: "http", + TLS: "tls", + QUIC: "quic", FAKEDNS: "fakedns" }; @@ -103,6 +103,7 @@ const DOMAIN_STRATEGY_OPTION = { FORCE_IPV4V6: "ForceIPv4v6", FORCE_IPV4: "ForceIPv4", }; + const TCP_CONGESTION_OPTION = { BBR: "bbr", CUBIC: "cubic", @@ -136,7 +137,7 @@ class XrayCommonClass { return this; } - toString(format=true) { + toString(format = true) { return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson()); } @@ -145,7 +146,7 @@ class XrayCommonClass { if (v2Headers) { Object.keys(v2Headers).forEach(key => { let values = v2Headers[key]; - if (typeof(values) === 'string') { + if (typeof (values) === 'string') { newHeaders.push({ name: key, value: values }); } else { for (let i = 0; i < values.length; ++i) { @@ -157,7 +158,7 @@ class XrayCommonClass { return newHeaders; } - static toV2Headers(headers, arr=true) { + static toV2Headers(headers, arr = true) { let v2Headers = {}; for (let i = 0; i < headers.length; ++i) { let name = headers[i].name; @@ -180,11 +181,12 @@ class XrayCommonClass { } class TcpStreamSettings extends XrayCommonClass { - constructor(acceptProxyProtocol=false, - type='none', - request=new TcpStreamSettings.TcpRequest(), - response=new TcpStreamSettings.TcpResponse(), - ) { + constructor( + acceptProxyProtocol = false, + type = 'none', + request = new TcpStreamSettings.TcpRequest(), + response = new TcpStreamSettings.TcpResponse(), + ) { super(); this.acceptProxyProtocol = acceptProxyProtocol; this.type = type; @@ -192,7 +194,7 @@ class TcpStreamSettings extends XrayCommonClass { this.response = response; } - static fromJson(json={}) { + static fromJson(json = {}) { let header = json.header; if (!header) { header = {}; @@ -217,10 +219,11 @@ class TcpStreamSettings extends XrayCommonClass { } TcpStreamSettings.TcpRequest = class extends XrayCommonClass { - constructor(version='1.1', - method='GET', - path=['/'], - headers=[], + constructor( + version = '1.1', + method = 'GET', + path = ['/'], + headers = [], ) { super(); this.version = version; @@ -245,7 +248,7 @@ TcpStreamSettings.TcpRequest = class extends XrayCommonClass { this.headers.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { return new TcpStreamSettings.TcpRequest( json.version, json.method, @@ -265,10 +268,11 @@ TcpStreamSettings.TcpRequest = class extends XrayCommonClass { }; TcpStreamSettings.TcpResponse = class extends XrayCommonClass { - constructor(version='1.1', - status='200', - reason='OK', - headers=[], + constructor( + version = '1.1', + status = '200', + reason = 'OK', + headers = [], ) { super(); this.version = version; @@ -285,7 +289,7 @@ TcpStreamSettings.TcpResponse = class extends XrayCommonClass { this.headers.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { return new TcpStreamSettings.TcpResponse( json.version, json.status, @@ -305,15 +309,17 @@ TcpStreamSettings.TcpResponse = class extends XrayCommonClass { }; class KcpStreamSettings extends XrayCommonClass { - constructor(mtu=1350, tti=20, - uplinkCapacity=5, - downlinkCapacity=20, - congestion=false, - readBufferSize=2, - writeBufferSize=2, - type='none', - seed=RandomUtil.randomSeq(10), - ) { + constructor( + mtu = 1350, + tti = 50, + uplinkCapacity = 5, + downlinkCapacity = 20, + congestion = false, + readBufferSize = 2, + writeBufferSize = 2, + type = 'none', + seed = RandomUtil.randomSeq(10), + ) { super(); this.mtu = mtu; this.tti = tti; @@ -326,7 +332,7 @@ class KcpStreamSettings extends XrayCommonClass { this.seed = seed; } - static fromJson(json={}) { + static fromJson(json = {}) { return new KcpStreamSettings( json.mtu, json.tti, @@ -358,7 +364,12 @@ class KcpStreamSettings extends XrayCommonClass { } class WsStreamSettings extends XrayCommonClass { - constructor(acceptProxyProtocol=false, path='/', host='', headers=[]) { + constructor( + acceptProxyProtocol = false, + path = '/', + host = '', + headers = [] + ) { super(); this.acceptProxyProtocol = acceptProxyProtocol; this.path = path; @@ -374,7 +385,7 @@ class WsStreamSettings extends XrayCommonClass { this.headers.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { return new WsStreamSettings( json.acceptProxyProtocol, json.path, @@ -395,9 +406,9 @@ class WsStreamSettings extends XrayCommonClass { class HttpStreamSettings extends XrayCommonClass { constructor( - path='/', - host=[''], - ) { + path = '/', + host = [''], + ) { super(); this.path = path; this.host = host.length === 0 ? [''] : host; @@ -411,7 +422,7 @@ class HttpStreamSettings extends XrayCommonClass { this.host.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { return new HttpStreamSettings(json.path, json.host); } @@ -430,15 +441,18 @@ class HttpStreamSettings extends XrayCommonClass { } class QuicStreamSettings extends XrayCommonClass { - constructor(security='none', - key=RandomUtil.randomSeq(10), type='none') { + constructor( + security = 'none', + key = RandomUtil.randomSeq(10), + 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, @@ -459,22 +473,22 @@ class QuicStreamSettings extends XrayCommonClass { class GrpcStreamSettings extends XrayCommonClass { constructor( - serviceName="", - authority="", - multiMode=false, - ) { + serviceName = "", + authority = "", + multiMode = false, + ) { super(); this.serviceName = serviceName; this.authority = authority; this.multiMode = multiMode; } - static fromJson(json={}) { + static fromJson(json = {}) { return new GrpcStreamSettings( json.serviceName, json.authority, json.multiMode - ); + ); } toJson() { @@ -487,7 +501,12 @@ class GrpcStreamSettings extends XrayCommonClass { } class HTTPUpgradeStreamSettings extends XrayCommonClass { - constructor(acceptProxyProtocol=false, path='/', host='', headers=[]) { + constructor( + acceptProxyProtocol = false, + path = '/', + host = '', + headers = [] + ) { super(); this.acceptProxyProtocol = acceptProxyProtocol; this.path = path; @@ -503,7 +522,7 @@ class HTTPUpgradeStreamSettings extends XrayCommonClass { this.headers.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { return new HTTPUpgradeStreamSettings( json.acceptProxyProtocol, json.path, @@ -576,16 +595,18 @@ class SplitHTTPStreamSettings extends XrayCommonClass { } class TlsStreamSettings extends XrayCommonClass { - constructor(serverName='', - minVersion = TLS_VERSION_OPTION.TLS12, - maxVersion = TLS_VERSION_OPTION.TLS13, - cipherSuites = '', - rejectUnknownSni = false, - disableSystemRoot = false, - enableSessionResumption = false, - certificates=[new TlsStreamSettings.Cert()], - alpn=[ALPN_OPTION.H3,ALPN_OPTION.H2,ALPN_OPTION.HTTP1], - settings=new TlsStreamSettings.Settings()) { + constructor( + serverName = '', + minVersion = TLS_VERSION_OPTION.TLS12, + maxVersion = TLS_VERSION_OPTION.TLS13, + cipherSuites = '', + rejectUnknownSni = false, + disableSystemRoot = false, + enableSessionResumption = false, + certificates = [new TlsStreamSettings.Cert()], + alpn = [ALPN_OPTION.H3, ALPN_OPTION.H2, ALPN_OPTION.HTTP1], + settings = new TlsStreamSettings.Settings() + ) { super(); this.sni = serverName; this.minVersion = minVersion; @@ -607,15 +628,15 @@ class TlsStreamSettings extends XrayCommonClass { this.certs.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { let certs; let settings; if (!ObjectUtil.isEmpty(json.certificates)) { certs = json.certificates.map(cert => TlsStreamSettings.Cert.fromJson(cert)); } - if (!ObjectUtil.isEmpty(json.settings)) { - settings = new TlsStreamSettings.Settings(json.settings.allowInsecure , json.settings.fingerprint, json.settings.serverName, json.settings.domains); + if (!ObjectUtil.isEmpty(json.settings)) { + settings = new TlsStreamSettings.Settings(json.settings.allowInsecure, json.settings.fingerprint, json.settings.serverName, json.settings.domains); } return new TlsStreamSettings( json.serverName, @@ -663,15 +684,15 @@ TlsStreamSettings.Cert = class extends XrayCommonClass { this.useFile = useFile; this.certFile = certificateFile; this.keyFile = keyFile; - this.cert = certificate instanceof Array ? certificate.join('\n') : certificate; - this.key = key instanceof Array ? key.join('\n') : key; + this.cert = Array.isArray(certificate) ? certificate.join('\n') : certificate; + this.key = Array.isArray(key) ? key.join('\n') : key; this.ocspStapling = ocspStapling; this.oneTimeLoading = oneTimeLoading; this.usage = usage; this.buildChain = buildChain } - static fromJson(json={}) { + static fromJson(json = {}) { if ('certificateFile' in json && 'keyFile' in json) { return new TlsStreamSettings.Cert( true, @@ -739,10 +760,12 @@ TlsStreamSettings.Settings = class extends XrayCommonClass { }; class XtlsStreamSettings extends XrayCommonClass { - constructor(serverName='', - certificates=[new XtlsStreamSettings.Cert()], - alpn=[ALPN_OPTION.H3,ALPN_OPTION.H2,ALPN_OPTION.HTTP1], - settings=new XtlsStreamSettings.Settings()) { + constructor( + serverName = '', + certificates = [new XtlsStreamSettings.Cert()], + alpn = [ALPN_OPTION.H3, ALPN_OPTION.H2, ALPN_OPTION.HTTP1], + settings = new XtlsStreamSettings.Settings() + ) { super(); this.sni = serverName; this.certs = certificates; @@ -758,15 +781,15 @@ class XtlsStreamSettings extends XrayCommonClass { this.certs.splice(index, 1); } - static fromJson(json={}) { + static fromJson(json = {}) { let certs; let settings; if (!ObjectUtil.isEmpty(json.certificates)) { certs = json.certificates.map(cert => XtlsStreamSettings.Cert.fromJson(cert)); } - if (!ObjectUtil.isEmpty(json.settings)) { - settings = new XtlsStreamSettings.Settings(json.settings.allowInsecure , json.settings.serverName); + if (!ObjectUtil.isEmpty(json.settings)) { + settings = new XtlsStreamSettings.Settings(json.settings.allowInsecure, json.settings.serverName); } return new XtlsStreamSettings( json.serverName, @@ -787,19 +810,28 @@ class XtlsStreamSettings extends XrayCommonClass { } XtlsStreamSettings.Cert = class extends XrayCommonClass { - constructor(useFile=true, certificateFile='', keyFile='', certificate='', key='', ocspStapling=3600, oneTimeLoading=false, usage=USAGE_OPTION.ENCIPHERMENT) { + constructor( + useFile = true, + certificateFile = '', + keyFile = '', + certificate = '', + key = '', + ocspStapling = 3600, + oneTimeLoading = false, + usage = USAGE_OPTION.ENCIPHERMENT + ) { super(); this.useFile = useFile; this.certFile = certificateFile; this.keyFile = keyFile; - this.cert = certificate instanceof Array ? certificate.join('\n') : certificate; - this.key = key instanceof Array ? key.join('\n') : key; + this.cert = Array.isArray(certificate) ? certificate.join('\n') : certificate; + this.key = Array.isArray(key) ? key.join('\n') : key; this.ocspStapling = ocspStapling; this.oneTimeLoading = oneTimeLoading; this.usage = usage; } - static fromJson(json={}) { + static fromJson(json = {}) { if ('certificateFile' in json && 'keyFile' in json) { return new XtlsStreamSettings.Cert( true, @@ -860,9 +892,9 @@ XtlsStreamSettings.Settings = class extends XrayCommonClass { }; class RealityStreamSettings extends XrayCommonClass { - constructor( - show = false,xver = 0, + show = false, + xver = 0, dest = 'yahoo.com:443', serverNames = 'yahoo.com,www.yahoo.com', privateKey = '', @@ -870,26 +902,29 @@ class RealityStreamSettings extends XrayCommonClass { maxClient = '', maxTimediff = 0, shortIds = RandomUtil.randomShortId(), - settings= new RealityStreamSettings.Settings() - ){ + settings = new RealityStreamSettings.Settings() + ) { super(); this.show = show; this.xver = xver; this.dest = dest; - this.serverNames = serverNames instanceof Array ? serverNames.join(",") : serverNames; + this.serverNames = Array.isArray(serverNames) ? serverNames.join(",") : serverNames; this.privateKey = privateKey; this.minClient = minClient; this.maxClient = maxClient; this.maxTimediff = maxTimediff; - this.shortIds = shortIds instanceof Array ? shortIds.join(",") : shortIds; + this.shortIds = Array.isArray(shortIds) ? shortIds.join(",") : shortIds; this.settings = settings; } static fromJson(json = {}) { let settings; - if (!ObjectUtil.isEmpty(json.settings)) { - settings = new RealityStreamSettings.Settings(json.settings.publicKey , json.settings.fingerprint, json.settings.serverName, json.settings.spiderX); - } + if (!ObjectUtil.isEmpty(json.settings)) { + settings = new RealityStreamSettings.Settings( + json.settings.publicKey, + json.settings.fingerprint, + json.settings.serverName, + json.settings.spiderX);} return new RealityStreamSettings( json.show, json.xver, @@ -902,8 +937,8 @@ class RealityStreamSettings extends XrayCommonClass { json.shortIds, json.settings, ); - } + toJson() { return { show: this.show, @@ -921,7 +956,12 @@ class RealityStreamSettings extends XrayCommonClass { } RealityStreamSettings.Settings = class extends XrayCommonClass { - constructor(publicKey = '', fingerprint = UTLS_FINGERPRINT.UTLS_RANDOM, serverName = '', spiderX= '/') { + constructor( + publicKey = '', + fingerprint = UTLS_FINGERPRINT.UTLS_RANDOM, + serverName = '', + spiderX = '/' + ) { super(); this.publicKey = publicKey; this.fingerprint = fingerprint; @@ -951,13 +991,13 @@ class SockoptStreamSettings extends XrayCommonClass { acceptProxyProtocol = false, tcpFastOpen = false, mark = 0, - tproxy="off", + tproxy = "off", tcpMptcp = false, tcpNoDelay = false, domainStrategy = DOMAIN_STRATEGY_OPTION.USE_IP, tcpMaxSeg = 1440, dialerProxy = "", - tcpKeepAliveInterval = 0, + tcpKeepAliveInterval = 0, tcpKeepAliveIdle = 300, tcpUserTimeout = 10000, tcpcongestion = TCP_CONGESTION_OPTION.BBR, @@ -983,7 +1023,7 @@ class SockoptStreamSettings extends XrayCommonClass { this.tcpWindowClamp = tcpWindowClamp; this.interfaceName = interfaceName; } - + static fromJson(json = {}) { if (Object.keys(json).length === 0) return undefined; return new SockoptStreamSettings( @@ -1029,22 +1069,22 @@ class SockoptStreamSettings extends XrayCommonClass { } class StreamSettings extends XrayCommonClass { - constructor(network='tcp', - security='none', + constructor(network = 'tcp', + security = 'none', externalProxy = [], - tlsSettings=new TlsStreamSettings(), - xtlsSettings=new XtlsStreamSettings(), + tlsSettings = new TlsStreamSettings(), + xtlsSettings = new XtlsStreamSettings(), 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(), + 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; @@ -1108,7 +1148,7 @@ class StreamSettings extends XrayCommonClass { this.sockopt = value ? new SockoptStreamSettings() : undefined; } - static fromJson(json={}) { + static fromJson(json = {}) { return new StreamSettings( json.network, json.security, @@ -1152,10 +1192,10 @@ class StreamSettings extends XrayCommonClass { class Sniffing extends XrayCommonClass { constructor( - enabled=true, - destOverride=['http', 'tls', 'quic', 'fakedns'], - metadataOnly=false, - routeOnly=false) { + enabled = true, + destOverride = ['http', 'tls', 'quic', 'fakedns'], + metadataOnly = false, + routeOnly = false) { super(); this.enabled = enabled; this.destOverride = destOverride; @@ -1163,7 +1203,7 @@ class Sniffing extends XrayCommonClass { this.routeOnly = routeOnly; } - static fromJson(json={}) { + static fromJson(json = {}) { let destOverride = ObjectUtil.clone(json.destOverride); if (!ObjectUtil.isEmpty(destOverride) && !ObjectUtil.isArrEmpty(destOverride)) { if (ObjectUtil.isEmpty(destOverride[0])) { @@ -1180,15 +1220,16 @@ class Sniffing extends XrayCommonClass { } class Inbound extends XrayCommonClass { - constructor(port=RandomUtil.randomIntRange(10000, 60000), - listen='', - protocol=Protocols.VLESS, - settings=null, - streamSettings=new StreamSettings(), - tag='', - sniffing=new Sniffing(), - clientStats='', - ) { + constructor( + port = RandomUtil.randomIntRange(10000, 60000), + listen = '', + protocol = Protocols.VLESS, + settings = null, + streamSettings = new StreamSettings(), + tag = '', + sniffing = new Sniffing(), + clientStats = '', + ) { super(); this.port = port; this.listen = listen; @@ -1236,7 +1277,7 @@ class Inbound extends XrayCommonClass { this.stream.security = 'none'; } } - + get network() { return this.stream.network; } @@ -1289,8 +1330,8 @@ class Inbound extends XrayCommonClass { get isSSMultiUser() { return this.method != SSMethods.BLAKE3_CHACHA20_POLY1305; } - get isSS2022(){ - return this.method.substring(0,4) === "2022"; + get isSS2022() { + return this.method.substring(0, 4) === "2022"; } get serverName() { @@ -1313,13 +1354,13 @@ class Inbound extends XrayCommonClass { if (this.isTcp) { return this.getHeader(this.stream.tcp.request, 'host'); } else if (this.isWs) { - return this.stream.ws.host?.length>0 ? this.stream.ws.host : this.getHeader(this.stream.ws, 'host'); + return this.stream.ws.host?.length > 0 ? this.stream.ws.host : this.getHeader(this.stream.ws, 'host'); } else if (this.isH2) { return this.stream.http.host[0]; } else if (this.isHttpupgrade) { - return this.stream.httpupgrade.host?.length>0 ? this.stream.httpupgrade.host : this.getHeader(this.stream.httpupgrade, 'host'); + return this.stream.httpupgrade.host?.length > 0 ? this.stream.httpupgrade.host : this.getHeader(this.stream.httpupgrade, 'host'); } else if (this.isSplithttp) { - return this.stream.splithttp.host?.length>0 ? this.stream.splithttp.host : this.getHeader(this.stream.splithttp, 'host'); + return this.stream.splithttp.host?.length > 0 ? this.stream.splithttp.host : this.getHeader(this.stream.splithttp, 'host'); } return null; } @@ -1369,8 +1410,8 @@ class Inbound extends XrayCommonClass { } 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.network); + if (![Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(this.protocol)) return false; + return ["tcp", "ws", "http", "quic", "grpc", "httpupgrade", "splithttp"].includes(this.network); } //this is used for xtls-rprx-vision @@ -1382,12 +1423,12 @@ class Inbound extends XrayCommonClass { } canEnableReality() { - if(![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; + if (![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; return ["tcp", "http", "grpc"].includes(this.network); } canEnableXtls() { - if(![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; + if (![Protocols.VLESS, Protocols.TROJAN].includes(this.protocol)) return false; return this.network === "tcp"; } @@ -1405,7 +1446,7 @@ class Inbound extends XrayCommonClass { this.sniffing = new Sniffing(); } - genVmessLink(address='', port=this.port, forceTls, remark='', clientId) { + genVmessLink(address = '', port = this.port, forceTls, remark = '', clientId) { if (this.protocol !== Protocols.VMESS) { return ''; } @@ -1427,7 +1468,7 @@ class Inbound extends XrayCommonClass { if (tcp.type === 'http') { const request = tcp.request; obj.path = request.path.join(','); - const host = this.getHeader(request,'host'); + const host = this.getHeader(request, 'host'); if (host) obj.host = host; } } else if (network === 'kcp') { @@ -1437,7 +1478,7 @@ class Inbound extends XrayCommonClass { } else if (network === 'ws') { const ws = this.stream.ws; obj.path = ws.path; - obj.host = ws.host?.length>0 ? ws.host : this.getHeader(ws, 'host'); + obj.host = ws.host?.length > 0 ? ws.host : this.getHeader(ws, 'host'); } else if (network === 'http') { obj.net = 'h2'; obj.path = this.stream.http.path; @@ -1449,38 +1490,38 @@ class Inbound extends XrayCommonClass { } else if (network === 'grpc') { obj.path = this.stream.grpc.serviceName; obj.authority = this.stream.grpc.authority; - if (this.stream.grpc.multiMode){ + if (this.stream.grpc.multiMode) { obj.type = 'multi' } } else if (network === 'httpupgrade') { const httpupgrade = this.stream.httpupgrade; obj.path = httpupgrade.path; - obj.host = httpupgrade.host?.length>0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host'); + obj.host = httpupgrade.host?.length > 0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host'); } else if (network === 'splithttp') { const splithttp = this.stream.splithttp; obj.path = splithttp.path; - obj.host = splithttp.host?.length>0 ? splithttp.host : this.getHeader(splithttp, 'host'); + obj.host = splithttp.host?.length > 0 ? splithttp.host : this.getHeader(splithttp, 'host'); } if (security === 'tls') { - if (!ObjectUtil.isEmpty(this.stream.tls.sni)){ + if (!ObjectUtil.isEmpty(this.stream.tls.sni)) { obj.sni = this.stream.tls.sni; } - if (!ObjectUtil.isEmpty(this.stream.tls.settings.fingerprint)){ + if (!ObjectUtil.isEmpty(this.stream.tls.settings.fingerprint)) { obj.fp = this.stream.tls.settings.fingerprint; } - if (this.stream.tls.alpn.length>0){ + if (this.stream.tls.alpn.length > 0) { obj.alpn = this.stream.tls.alpn.join(','); } - if (this.stream.tls.settings.allowInsecure){ + if (this.stream.tls.settings.allowInsecure) { obj.allowInsecure = this.stream.tls.settings.allowInsecure; } } - + return 'vmess://' + base64(JSON.stringify(obj, null, 2)); } - genVLESSLink(address = '', port=this.port, forceTls, remark='', clientId, flow) { + genVLESSLink(address = '', port = this.port, forceTls, remark = '', clientId, flow) { const uuid = clientId; const type = this.stream.network; const security = forceTls == 'same' ? this.stream.security : forceTls; @@ -1508,7 +1549,7 @@ class Inbound extends XrayCommonClass { case "ws": const ws = this.stream.ws; params.set("path", ws.path); - params.set("host", ws.host?.length>0 ? ws.host : this.getHeader(ws, 'host')); + params.set("host", ws.host?.length > 0 ? ws.host : this.getHeader(ws, 'host')); break; case "http": const http = this.stream.http; @@ -1525,31 +1566,31 @@ class Inbound extends XrayCommonClass { const grpc = this.stream.grpc; params.set("serviceName", grpc.serviceName); params.set("authority", grpc.authority); - if(grpc.multiMode){ + if (grpc.multiMode) { params.set("mode", "multi"); } break; case "httpupgrade": - const httpupgrade = this.stream.httpupgrade; - params.set("path", httpupgrade.path); - params.set("host", httpupgrade.host?.length>0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); + const httpupgrade = this.stream.httpupgrade; + params.set("path", httpupgrade.path); + params.set("host", httpupgrade.host?.length > 0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); break; case "splithttp": - const splithttp = this.stream.splithttp; - params.set("path", splithttp.path); - params.set("host", splithttp.host?.length>0 ? splithttp.host : this.getHeader(splithttp, 'host')); + const splithttp = this.stream.splithttp; + params.set("path", splithttp.path); + params.set("host", splithttp.host?.length > 0 ? splithttp.host : this.getHeader(splithttp, 'host')); break; } if (security === 'tls') { params.set("security", "tls"); - if (this.stream.isTls){ - params.set("fp" , this.stream.tls.settings.fingerprint); + if (this.stream.isTls) { + params.set("fp", this.stream.tls.settings.fingerprint); params.set("alpn", this.stream.tls.alpn); - if(this.stream.tls.settings.allowInsecure){ + if (this.stream.tls.settings.allowInsecure) { params.set("allowInsecure", "1"); } - if (!ObjectUtil.isEmpty(this.stream.tls.sni)){ + if (!ObjectUtil.isEmpty(this.stream.tls.sni)) { params.set("sni", this.stream.tls.sni); } if (type == "tcp" && !ObjectUtil.isEmpty(flow)) { @@ -1561,12 +1602,12 @@ class Inbound extends XrayCommonClass { else if (security === 'xtls') { params.set("security", "xtls"); params.set("alpn", this.stream.xtls.alpn); - if(this.stream.xtls.settings.allowInsecure){ + if (this.stream.xtls.settings.allowInsecure) { params.set("allowInsecure", "1"); } - if (!ObjectUtil.isEmpty(this.stream.xtls.sni)){ + if (!ObjectUtil.isEmpty(this.stream.xtls.sni)) { params.set("sni", this.stream.xtls.sni); - } + } params.set("flow", flow); } @@ -1629,7 +1670,7 @@ class Inbound extends XrayCommonClass { case "ws": const ws = this.stream.ws; params.set("path", ws.path); - params.set("host", ws.host?.length>0 ? ws.host : this.getHeader(ws, 'host')); + params.set("host", ws.host?.length > 0 ? ws.host : this.getHeader(ws, 'host')); break; case "http": const http = this.stream.http; @@ -1651,14 +1692,14 @@ class Inbound extends XrayCommonClass { } break; case "httpupgrade": - const httpupgrade = this.stream.httpupgrade; - params.set("path", httpupgrade.path); - params.set("host", httpupgrade.host?.length>0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); + const httpupgrade = this.stream.httpupgrade; + params.set("path", httpupgrade.path); + params.set("host", httpupgrade.host?.length > 0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); break; case "splithttp": - const splithttp = this.stream.splithttp; - params.set("path", splithttp.path); - params.set("host", splithttp.host?.length>0 ? splithttp.host : this.getHeader(splithttp, 'host')); + const splithttp = this.stream.splithttp; + params.set("path", splithttp.path); + params.set("host", splithttp.host?.length > 0 ? splithttp.host : this.getHeader(splithttp, 'host')); break; } @@ -1690,7 +1731,7 @@ class Inbound extends XrayCommonClass { return url.toString(); } - genTrojanLink(address = '', port=this.port, forceTls, remark = '', clientPassword) { + genTrojanLink(address = '', port = this.port, forceTls, remark = '', clientPassword) { const security = forceTls == 'same' ? this.stream.security : forceTls; const type = this.stream.network; const params = new Map(); @@ -1717,7 +1758,7 @@ class Inbound extends XrayCommonClass { case "ws": const ws = this.stream.ws; params.set("path", ws.path); - params.set("host", ws.host?.length>0 ? ws.host : this.getHeader(ws, 'host')); + params.set("host", ws.host?.length > 0 ? ws.host : this.getHeader(ws, 'host')); break; case "http": const http = this.stream.http; @@ -1734,31 +1775,31 @@ class Inbound extends XrayCommonClass { const grpc = this.stream.grpc; params.set("serviceName", grpc.serviceName); params.set("authority", grpc.authority); - if(grpc.multiMode){ + if (grpc.multiMode) { params.set("mode", "multi"); } break; case "httpupgrade": - const httpupgrade = this.stream.httpupgrade; - params.set("path", httpupgrade.path); - params.set("host", httpupgrade.host?.length>0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); + const httpupgrade = this.stream.httpupgrade; + params.set("path", httpupgrade.path); + params.set("host", httpupgrade.host?.length > 0 ? httpupgrade.host : this.getHeader(httpupgrade, 'host')); break; case "splithttp": - const splithttp = this.stream.splithttp; - params.set("path", splithttp.path); - params.set("host", splithttp.host?.length>0 ? splithttp.host : this.getHeader(splithttp, 'host')); + const splithttp = this.stream.splithttp; + params.set("path", splithttp.path); + params.set("host", splithttp.host?.length > 0 ? splithttp.host : this.getHeader(splithttp, 'host')); break; } if (security === 'tls') { params.set("security", "tls"); - if (this.stream.isTls){ - params.set("fp" , this.stream.tls.settings.fingerprint); + if (this.stream.isTls) { + params.set("fp", this.stream.tls.settings.fingerprint); params.set("alpn", this.stream.tls.alpn); - if(this.stream.tls.settings.allowInsecure){ + if (this.stream.tls.settings.allowInsecure) { params.set("allowInsecure", "1"); } - if (!ObjectUtil.isEmpty(this.stream.tls.sni)){ + if (!ObjectUtil.isEmpty(this.stream.tls.sni)) { params.set("sni", this.stream.tls.sni); } } @@ -1779,15 +1820,15 @@ class Inbound extends XrayCommonClass { } } - else if (security === 'xtls') { + else if (security === 'xtls') { params.set("security", "xtls"); params.set("alpn", this.stream.xtls.alpn); - if(this.stream.xtls.settings.allowInsecure){ + if (this.stream.xtls.settings.allowInsecure) { params.set("allowInsecure", "1"); } - if (!ObjectUtil.isEmpty(this.stream.xtls.sni)){ + if (!ObjectUtil.isEmpty(this.stream.xtls.sni)) { params.set("sni", this.stream.xtls.sni); - } + }