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>2024-08-06 18:06:39 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2024-08-06 18:10:42 +0300
commitb8c3555b09d716d877b69b477a7f390e8acbc9af (patch)
tree4d51a0e5b7acd4de6ffbbac2ac526f4064e23d70 /web/assets/js/model/xray.js
parent2d2b30daf1d3b3bc06b1acbf879b1c650054a92b (diff)
improve randomShortId , format document
Diffstat (limited to 'web/assets/js/model/xray.js')
-rw-r--r--web/assets/js/model/xray.js541
1 files changed, 291 insertions, 250 deletions
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);
- }
+ }
params.set("flow", flow);
}
@@ -1826,13 +1867,13 @@ class Inbound extends XrayCommonClass {
return txt;
}
- genLink(address='', port=this.port, forceTls='same', remark='', client) {
+ genLink(address = '', port = this.port, forceTls = 'same', remark = '', client) {
switch (this.protocol) {
case Protocols.VMESS:
return this.ge