mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
improve randomShortId , format document
This commit is contained in:
parent
2d2b30daf1
commit
b8c3555b09
4 changed files with 468 additions and 379 deletions
|
@ -72,10 +72,12 @@ const WireguardDomainStrategy = [
|
||||||
Object.freeze(Protocols);
|
Object.freeze(Protocols);
|
||||||
Object.freeze(SSMethods);
|
Object.freeze(SSMethods);
|
||||||
Object.freeze(TLS_FLOW_CONTROL);
|
Object.freeze(TLS_FLOW_CONTROL);
|
||||||
|
Object.freeze(UTLS_FINGERPRINT);
|
||||||
Object.freeze(ALPN_OPTION);
|
Object.freeze(ALPN_OPTION);
|
||||||
Object.freeze(OutboundDomainStrategies);
|
Object.freeze(OutboundDomainStrategies);
|
||||||
Object.freeze(WireguardDomainStrategy);
|
Object.freeze(WireguardDomainStrategy);
|
||||||
|
|
||||||
|
|
||||||
class CommonClass {
|
class CommonClass {
|
||||||
|
|
||||||
static toJsonArray(arr) {
|
static toJsonArray(arr) {
|
||||||
|
@ -90,30 +92,30 @@ class CommonClass {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(format=true) {
|
toString(format = true) {
|
||||||
return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson());
|
return format ? JSON.stringify(this.toJson(), null, 2) : JSON.stringify(this.toJson());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TcpStreamSettings extends CommonClass {
|
class TcpStreamSettings extends CommonClass {
|
||||||
constructor(type='none', host, path) {
|
constructor(type = 'none', host, path) {
|
||||||
super();
|
super();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
let header = json.header;
|
let header = json.header;
|
||||||
if (!header) return new TcpStreamSettings();
|
if (!header) return new TcpStreamSettings();
|
||||||
if(header.type == 'http' && header.request){
|
if (header.type == 'http' && header.request) {
|
||||||
return new TcpStreamSettings(
|
return new TcpStreamSettings(
|
||||||
header.type,
|
header.type,
|
||||||
header.request.headers.Host.join(','),
|
header.request.headers.Host.join(','),
|
||||||
header.request.path.join(','),
|
header.request.path.join(','),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return new TcpStreamSettings(header.type,'','');
|
return new TcpStreamSettings(header.type, '', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
|
@ -132,15 +134,17 @@ class TcpStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class KcpStreamSettings extends CommonClass {
|
class KcpStreamSettings extends CommonClass {
|
||||||
constructor(mtu=1350, tti=20,
|
constructor(
|
||||||
uplinkCapacity=5,
|
mtu = 1350,
|
||||||
downlinkCapacity=20,
|
tti = 50,
|
||||||
congestion=false,
|
uplinkCapacity = 5,
|
||||||
readBufferSize=2,
|
downlinkCapacity = 20,
|
||||||
writeBufferSize=2,
|
congestion = false,
|
||||||
type='none',
|
readBufferSize = 2,
|
||||||
seed='',
|
writeBufferSize = 2,
|
||||||
) {
|
type = 'none',
|
||||||
|
seed = '',
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.mtu = mtu;
|
this.mtu = mtu;
|
||||||
this.tti = tti;
|
this.tti = tti;
|
||||||
|
@ -153,7 +157,7 @@ class KcpStreamSettings extends CommonClass {
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new KcpStreamSettings(
|
return new KcpStreamSettings(
|
||||||
json.mtu,
|
json.mtu,
|
||||||
json.tti,
|
json.tti,
|
||||||
|
@ -185,13 +189,13 @@ class KcpStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class WsStreamSettings extends CommonClass {
|
class WsStreamSettings extends CommonClass {
|
||||||
constructor(path='/', host='') {
|
constructor(path = '/', host = '') {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new WsStreamSettings(
|
return new WsStreamSettings(
|
||||||
json.path,
|
json.path,
|
||||||
json.host,
|
json.host,
|
||||||
|
@ -207,13 +211,13 @@ class WsStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpStreamSettings extends CommonClass {
|
class HttpStreamSettings extends CommonClass {
|
||||||
constructor(path='/', host='') {
|
constructor(path = '/', host = '') {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new HttpStreamSettings(
|
return new HttpStreamSettings(
|
||||||
json.path,
|
json.path,
|
||||||
json.host ? json.host.join(',') : '',
|
json.host ? json.host.join(',') : '',
|
||||||
|
@ -229,15 +233,18 @@ class HttpStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class QuicStreamSettings extends CommonClass {
|
class QuicStreamSettings extends CommonClass {
|
||||||
constructor(security='none',
|
constructor(
|
||||||
key='', type='none') {
|
security = 'none',
|
||||||
|
key = '',
|
||||||
|
type = 'none'
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.security = security;
|
this.security = security;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new QuicStreamSettings(
|
return new QuicStreamSettings(
|
||||||
json.security,
|
json.security,
|
||||||
json.key,
|
json.key,
|
||||||
|
@ -257,15 +264,19 @@ class QuicStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GrpcStreamSettings extends CommonClass {
|
class GrpcStreamSettings extends CommonClass {
|
||||||
constructor(serviceName="", authority="", multiMode=false) {
|
constructor(
|
||||||
|
serviceName = "",
|
||||||
|
authority = "",
|
||||||
|
multiMode = false
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
this.multiMode = multiMode;
|
this.multiMode = multiMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new GrpcStreamSettings(json.serviceName, json.authority, json.multiMode );
|
return new GrpcStreamSettings(json.serviceName, json.authority, json.multiMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
|
@ -278,13 +289,13 @@ class GrpcStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpUpgradeStreamSettings extends CommonClass {
|
class HttpUpgradeStreamSettings extends CommonClass {
|
||||||
constructor(path='/', host='') {
|
constructor(path = '/', host = '') {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new HttpUpgradeStreamSettings(
|
return new HttpUpgradeStreamSettings(
|
||||||
json.path,
|
json.path,
|
||||||
json.host,
|
json.host,
|
||||||
|
@ -300,13 +311,13 @@ class HttpUpgradeStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class SplitHTTPStreamSettings extends CommonClass {
|
class SplitHTTPStreamSettings extends CommonClass {
|
||||||
constructor(path='/', host='') {
|
constructor(path = '/', host = '') {
|
||||||
super();
|
super();
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new SplitHTTPStreamSettings(
|
return new SplitHTTPStreamSettings(
|
||||||
json.path,
|
json.path,
|
||||||
json.host,
|
json.host,
|
||||||
|
@ -322,10 +333,12 @@ class SplitHTTPStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TlsStreamSettings extends CommonClass {
|
class TlsStreamSettings extends CommonClass {
|
||||||
constructor(serverName='',
|
constructor(
|
||||||
alpn=[],
|
serverName = '',
|
||||||
fingerprint = '',
|
alpn = [],
|
||||||
allowInsecure = false) {
|
fingerprint = '',
|
||||||
|
allowInsecure = false
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.serverName = serverName;
|
this.serverName = serverName;
|
||||||
this.alpn = alpn;
|
this.alpn = alpn;
|
||||||
|
@ -333,7 +346,7 @@ class TlsStreamSettings extends CommonClass {
|
||||||
this.allowInsecure = allowInsecure;
|
this.allowInsecure = allowInsecure;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new TlsStreamSettings(
|
return new TlsStreamSettings(
|
||||||
json.serverName,
|
json.serverName,
|
||||||
json.alpn,
|
json.alpn,
|
||||||
|
@ -353,7 +366,13 @@ class TlsStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class RealityStreamSettings extends CommonClass {
|
class RealityStreamSettings extends CommonClass {
|
||||||
constructor(publicKey = '', fingerprint = '', serverName = '', shortId = '', spiderX = '/') {
|
constructor(
|
||||||
|
publicKey = '',
|
||||||
|
fingerprint = '',
|
||||||
|
serverName = '',
|
||||||
|
shortId = '',
|
||||||
|
spiderX = '/'
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
this.fingerprint = fingerprint;
|
this.fingerprint = fingerprint;
|
||||||
|
@ -381,7 +400,13 @@ class RealityStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class SockoptStreamSettings 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();
|
super();
|
||||||
this.dialerProxy = dialerProxy;
|
this.dialerProxy = dialerProxy;
|
||||||
this.tcpFastOpen = tcpFastOpen;
|
this.tcpFastOpen = tcpFastOpen;
|
||||||
|
@ -413,20 +438,21 @@ class SockoptStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StreamSettings extends CommonClass {
|
class StreamSettings extends CommonClass {
|
||||||
constructor(network='tcp',
|
constructor(
|
||||||
security='none',
|
network = 'tcp',
|
||||||
tlsSettings=new TlsStreamSettings(),
|
security = 'none',
|
||||||
realitySettings = new RealityStreamSettings(),
|
tlsSettings = new TlsStreamSettings(),
|
||||||
tcpSettings=new TcpStreamSettings(),
|
realitySettings = new RealityStreamSettings(),
|
||||||
kcpSettings=new KcpStreamSettings(),
|
tcpSettings = new TcpStreamSettings(),
|
||||||
wsSettings=new WsStreamSettings(),
|
kcpSettings = new KcpStreamSettings(),
|
||||||
httpSettings=new HttpStreamSettings(),
|
wsSettings = new WsStreamSettings(),
|
||||||
quicSettings=new QuicStreamSettings(),
|
httpSettings = new HttpStreamSettings(),
|
||||||
grpcSettings=new GrpcStreamSettings(),
|
quicSettings = new QuicStreamSettings(),
|
||||||
httpupgradeSettings=new HttpUpgradeStreamSettings(),
|
grpcSettings = new GrpcStreamSettings(),
|
||||||
splithttpSettings=new SplitHTTPStreamSettings(),
|
httpupgradeSettings = new HttpUpgradeStreamSettings(),
|
||||||
sockopt = undefined,
|
splithttpSettings = new SplitHTTPStreamSettings(),
|
||||||
) {
|
sockopt = undefined,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.security = security;
|
this.security = security;
|
||||||
|
@ -459,7 +485,7 @@ class StreamSettings extends CommonClass {
|
||||||
this.sockopt = value ? new SockoptStreamSettings() : undefined;
|
this.sockopt = value ? new SockoptStreamSettings() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new StreamSettings(
|
return new StreamSettings(
|
||||||
json.network,
|
json.network,
|
||||||
json.security,
|
json.security,
|
||||||
|
@ -528,9 +554,9 @@ class Mux extends CommonClass {
|
||||||
|
|
||||||
class Outbound extends CommonClass {
|
class Outbound extends CommonClass {
|
||||||
constructor(
|
constructor(
|
||||||
tag='',
|
tag = '',
|
||||||
protocol=Protocols.VMess,
|
protocol = Protocols.VMess,
|
||||||
settings=null,
|
settings = null,
|
||||||
streamSettings = new StreamSettings(),
|
streamSettings = new StreamSettings(),
|
||||||
sendThrough,
|
sendThrough,
|
||||||
mux = new Mux(),
|
mux = new Mux(),
|
||||||
|
@ -556,7 +582,7 @@ class Outbound extends CommonClass {
|
||||||
|
|
||||||
canEnableTls() {
|
canEnableTls() {
|
||||||
if (![Protocols.VMess, Protocols.VLESS, Protocols.Trojan, Protocols.Shadowsocks].includes(this.protocol)) return false;
|
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
|
//this is used for xtls-rprx-vision
|
||||||
|
@ -577,7 +603,7 @@ class Outbound extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
canEnableMux() {
|
canEnableMux() {
|
||||||
if (this.settings.flow && this.settings.flow != ''){
|
if (this.settings.flow && this.settings.flow != '') {
|
||||||
this.mux.enabled = false;
|
this.mux.enabled = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -608,7 +634,7 @@ class Outbound extends CommonClass {
|
||||||
return [Protocols.Socks, Protocols.HTTP].includes(this.protocol);
|
return [Protocols.Socks, Protocols.HTTP].includes(this.protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new Outbound(
|
return new Outbound(
|
||||||
json.tag,
|
json.tag,
|
||||||
json.protocol,
|
json.protocol,
|
||||||
|
@ -639,8 +665,8 @@ class Outbound extends CommonClass {
|
||||||
|
|
||||||
static fromLink(link) {
|
static fromLink(link) {
|
||||||
data = link.split('://');
|
data = link.split('://');
|
||||||
if(data.length !=2) return null;
|
if (data.length != 2) return null;
|
||||||
switch(data[0].toLowerCase()){
|
switch (data[0].toLowerCase()) {
|
||||||
case Protocols.VMess:
|
case Protocols.VMess:
|
||||||
return this.fromVmessLink(JSON.parse(Base64.decode(data[1])));
|
return this.fromVmessLink(JSON.parse(Base64.decode(data[1])));
|
||||||
case Protocols.VLESS:
|
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 stream = new StreamSettings(json.net, json.tls);
|
||||||
|
|
||||||
let network = json.net;
|
let network = json.net;
|
||||||
|
@ -666,7 +692,7 @@ class Outbound extends CommonClass {
|
||||||
stream.type = json.type;
|
stream.type = json.type;
|
||||||
stream.seed = json.path;
|
stream.seed = json.path;
|
||||||
} else if (network === 'ws') {
|
} 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') {
|
} else if (network === 'http' || network == 'h2') {
|
||||||
stream.network = 'http'
|
stream.network = 'http'
|
||||||
stream.http = new HttpStreamSettings(
|
stream.http = new HttpStreamSettings(
|
||||||
|
@ -680,12 +706,12 @@ class Outbound extends CommonClass {
|
||||||
} else if (network === 'grpc') {
|
} else if (network === 'grpc') {
|
||||||
stream.grpc = new GrpcStreamSettings(json.path, json.authority, json.type == 'multi');
|
stream.grpc = new GrpcStreamSettings(json.path, json.authority, json.type == 'multi');
|
||||||
} else if (network === 'httpupgrade') {
|
} else if (network === 'httpupgrade') {
|
||||||
stream.httpupgrade = new HttpUpgradeStreamSettings(json.path,json.host);
|
stream.httpupgrade = new HttpUpgradeStreamSettings(json.path, json.host);
|
||||||
} else if (network === 'splithttp') {
|
} 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(
|
stream.tls = new TlsStreamSettings(
|
||||||
json.sni,
|
json.sni,
|
||||||
json.alpn ? json.alpn.split(',') : [],
|
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);
|
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);
|
const url = new URL(link);
|
||||||
let type = url.searchParams.get('type') ?? 'tcp';
|
let type = url.searchParams.get('type') ?? 'tcp';
|
||||||
let security = url.searchParams.get('security') ?? 'none';
|
let security = url.searchParams.get('security') ?? 'none';
|
||||||
|
@ -715,9 +741,9 @@ class Outbound extends CommonClass {
|
||||||
stream.kcp.type = headerType ?? 'none';
|
stream.kcp.type = headerType ?? 'none';
|
||||||
stream.kcp.seed = path;
|
stream.kcp.seed = path;
|
||||||
} else if (type === 'ws') {
|
} else if (type === 'ws') {
|
||||||
stream.ws = new WsStreamSettings(path,host);
|
stream.ws = new WsStreamSettings(path, host);
|
||||||
} else if (type === 'http' || type == 'h2') {
|
} else if (type === 'http' || type == 'h2') {
|
||||||
stream.http = new HttpStreamSettings(path,host);
|
stream.http = new HttpStreamSettings(path, host);
|
||||||
} else if (type === 'quic') {
|
} else if (type === 'quic') {
|
||||||
stream.quic = new QuicStreamSettings(
|
stream.quic = new QuicStreamSettings(
|
||||||
url.searchParams.get('quicSecurity') ?? 'none',
|
url.searchParams.get('quicSecurity') ?? 'none',
|
||||||
|
@ -729,25 +755,25 @@ class Outbound extends CommonClass {
|
||||||
url.searchParams.get('authority') ?? '',
|
url.searchParams.get('authority') ?? '',
|
||||||
url.searchParams.get('mode') == 'multi');
|
url.searchParams.get('mode') == 'multi');
|
||||||
} else if (type === 'httpupgrade') {
|
} else if (type === 'httpupgrade') {
|
||||||
stream.httpupgrade = new HttpUpgradeStreamSettings(path,host);
|
stream.httpupgrade = new HttpUpgradeStreamSettings(path, host);
|
||||||
} else if (type === 'splithttp') {
|
} else if (type === 'splithttp') {
|
||||||
stream.splithttp = new SplitHTTPStreamSettings(path,host);
|
stream.splithttp = new SplitHTTPStreamSettings(path, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(security == 'tls'){
|
if (security == 'tls') {
|
||||||
let fp=url.searchParams.get('fp') ?? 'none';
|
let fp = url.searchParams.get('fp') ?? 'none';
|
||||||
let alpn=url.searchParams.get('alpn');
|
let alpn = url.searchParams.get('alpn');
|
||||||
let allowInsecure=url.searchParams.get('allowInsecure');
|
let allowInsecure = url.searchParams.get('allowInsecure');
|
||||||
let sni=url.searchParams.get('sni') ?? '';
|
let sni = url.searchParams.get('sni') ?? '';
|
||||||
stream.tls = new TlsStreamSettings(sni, alpn ? alpn.split(',') : [], fp, allowInsecure == 1);
|
stream.tls = new TlsStreamSettings(sni, alpn ? alpn.split(',') : [], fp, allowInsecure == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(security == 'reality'){
|
if (security == 'reality') {
|
||||||
let pbk=url.searchParams.get('pbk');
|
let pbk = url.searchParams.get('pbk');
|
||||||
let fp=url.searchParams.get('fp');
|
let fp = url.searchParams.get('fp');
|
||||||
let sni=url.searchParams.get('sni') ?? '';
|
let sni = url.searchParams.get('sni') ?? '';
|
||||||
let sid=url.searchParams.get('sid') ?? '';
|
let sid = url.searchParams.get('sid') ?? '';
|
||||||
let spx=url.searchParams.get('spx') ?? '';
|
let spx = url.searchParams.get('spx') ?? '';
|
||||||
stream.reality = new RealityStreamSettings(pbk, fp, sni, sid, spx);
|
stream.reality = new RealityStreamSettings(pbk, fp, sni, sid, spx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,14 +781,14 @@ class Outbound extends CommonClass {
|
||||||
const match = link.match(regex);
|
const match = link.match(regex);
|
||||||
|
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
let [, protocol, userData, address, port, ] = match;
|
let [, protocol, userData, address, port,] = match;
|
||||||
port *= 1;
|
port *= 1;
|
||||||
if(protocol == 'ss') {
|
if (protocol == 'ss') {
|
||||||
protocol = 'shadowsocks';
|
protocol = 'shadowsocks';
|
||||||
userData = atob(userData).split(':');
|
userData = atob(userData).split(':');
|
||||||
}
|
}
|
||||||
var settings;
|
var settings;
|
||||||
switch(protocol){
|
switch (protocol) {
|
||||||
case Protocols.VLESS:
|
case Protocols.VLESS:
|
||||||
settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? '');
|
settings = new Outbound.VLESSSettings(address, port, userData, url.searchParams.get('flow') ?? '');
|
||||||
break;
|
break;
|
||||||
|
@ -770,7 +796,7 @@ class Outbound extends CommonClass {
|
||||||
settings = new Outbound.TrojanSettings(address, port, userData);
|
settings = new Outbound.TrojanSettings(address, port, userData);
|
||||||
break;
|
break;
|
||||||
case Protocols.Shadowsocks:
|
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);
|
settings = new Outbound.ShadowsocksSettings(address, port, userData.join(":"), method, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -826,13 +852,13 @@ Outbound.Settings = class extends CommonClass {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Outbound.FreedomSettings = class extends CommonClass {
|
Outbound.FreedomSettings = class extends CommonClass {
|
||||||
constructor(domainStrategy='', fragment={}) {
|
constructor(domainStrategy = '', fragment = {}) {
|
||||||
super();
|
super();
|
||||||
this.domainStrategy = domainStrategy;
|
this.domainStrategy = domainStrategy;
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new Outbound.FreedomSettings(
|
return new Outbound.FreedomSettings(
|
||||||
json.domainStrategy,
|
json.domainStrategy,
|
||||||
json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined,
|
json.fragment ? Outbound.FreedomSettings.Fragment.fromJson(json.fragment) : undefined,
|
||||||
|
@ -847,14 +873,14 @@ Outbound.FreedomSettings = class extends CommonClass {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Outbound.FreedomSettings.Fragment = class extends CommonClass {
|
Outbound.FreedomSettings.Fragment = class extends CommonClass {
|
||||||
constructor(packets='1-3',length='',interval=''){
|
constructor(packets = '1-3', length = '', interval = '') {
|
||||||
super();
|
super();
|
||||||
this.packets = packets;
|
this.packets = packets;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new Outbound.FreedomSettings.Fragment(
|
return new Outbound.FreedomSettings.Fragment(
|
||||||
json.packets,
|
json.packets,
|
||||||
json.length,
|
json.length,
|
||||||
|
@ -868,7 +894,7 @@ Outbound.BlackholeSettings = class extends CommonClass {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
return new Outbound.BlackholeSettings(
|
return new Outbound.BlackholeSettings(
|
||||||
json.response ? json.response.type : undefined,
|
json.response ? json.response.type : undefined,
|
||||||
);
|
);
|
||||||
|
@ -876,19 +902,19 @@ Outbound.BlackholeSettings = class extends CommonClass {
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
response: ObjectUtil.isEmpty(this.type) ? undefined : {type: this.type},
|
response: ObjectUtil.isEmpty(this.type) ? undefined : { type: this.type },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Outbound.DNSSettings = class extends CommonClass {
|
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();
|
super();
|
||||||
this.network = network;
|
this.network = network;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}){
|
static fromJson(json = {}) {
|
||||||
return new Outbound.DNSSettings(
|
return new Outbound.DNSSettings(
|
||||||
json.network,
|
json.network,
|
||||||
json.address,
|
json.address,
|
||||||
|
@ -904,8 +930,8 @@ Outbound.VmessSettings = class extends CommonClass {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
if(ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VmessSettings();
|
if (ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VmessSettings();
|
||||||
return new Outbound.VmessSettings(
|
return new Outbound.VmessSettings(
|
||||||
json.vnext[0].address,
|
json.vnext[0].address,
|
||||||
json.vnext[0].port,
|
json.vnext[0].port,
|
||||||
|
@ -918,13 +944,13 @@ Outbound.VmessSettings = class extends CommonClass {
|
||||||
vnext: [{
|
vnext: [{
|
||||||
address: this.address,
|
address: this.address,
|
||||||
port: this.port,
|
port: this.port,
|
||||||
users: [{id: this.id}],
|
users: [{ id: this.id }],
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Outbound.VLESSSettings = class extends CommonClass {
|
Outbound.VLESSSettings = class extends CommonClass {
|
||||||
constructor(address, port, id, flow, encryption='none') {
|
constructor(address, port, id, flow, encryption = 'none') {
|
||||||
super();
|
super();
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
@ -933,8 +959,8 @@ Outbound.VLESSSettings = class extends CommonClass {
|
||||||
this.encryption = encryption
|
this.encryption = encryption
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
if(ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VLESSSettings();
|
if (ObjectUtil.isArrEmpty(json.vnext)) return new Outbound.VLESSSettings();
|
||||||
return new Outbound.VLESSSettings(
|
return new Outbound.VLESSSettings(
|
||||||
json.vnext[0].address,
|
json.vnext[0].address,
|
||||||
json.vnext[0].port,
|
json.vnext[0].port,
|
||||||
|
@ -949,7 +975,7 @@ Outbound.VLESSSettings = class extends CommonClass {
|
||||||
vnext: [{
|
vnext: [{
|
||||||
address: this.address,
|
address: this.address,
|
||||||
port: this.port,
|
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;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
if(ObjectUtil.isArrEmpty(json.servers)) return new Outbound.TrojanSettings();
|
if (ObjectUtil.isArrEmpty(json.servers)) return new Outbound.TrojanSettings();
|
||||||
return new Outbound.TrojanSettings(
|
return new Outbound.TrojanSettings(
|
||||||
json.servers[0].address,
|
json.servers[0].address,
|
||||||
json.servers[0].port,
|
json.servers[0].port,
|
||||||
|
@ -992,9 +1018,9 @@ Outbound.ShadowsocksSettings = class extends CommonClass {
|
||||||
this.UoTVersion = UoTVersion;
|
this.UoTVersion = UoTVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
let servers = json.servers;
|
let servers = json.servers;
|
||||||
if(ObjectUtil.isArrEmpty(servers)) servers=[{}];
|
if (ObjectUtil.isArrEmpty(servers)) servers = [{}];
|
||||||
return new Outbound.ShadowsocksSettings(
|
return new Outbound.ShadowsocksSettings(
|
||||||
servers[0].address,
|
servers[0].address,
|
||||||
servers[0].port,
|
servers[0].port,
|
||||||
|
@ -1028,9 +1054,9 @@ Outbound.SocksSettings = class extends CommonClass {
|
||||||
this.pass = pass;
|
this.pass = pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
let servers = json.servers;
|
let servers = json.servers;
|
||||||
if(ObjectUtil.isArrEmpty(servers)) servers=[{users: [{}]}];
|
if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
|
||||||
return new Outbound.SocksSettings(
|
return new Outbound.SocksSettings(
|
||||||
servers[0].address,
|
servers[0].address,
|
||||||
servers[0].port,
|
servers[0].port,
|
||||||
|
@ -1044,7 +1070,7 @@ Outbound.SocksSettings = class extends CommonClass {
|
||||||
servers: [{
|
servers: [{
|
||||||
address: this.address,
|
address: this.address,
|
||||||
port: this.port,
|
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;
|
this.pass = pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}) {
|
static fromJson(json = {}) {
|
||||||
let servers = json.servers;
|
let servers = json.servers;
|
||||||
if(ObjectUtil.isArrEmpty(servers)) servers=[{users: [{}]}];
|
if (ObjectUtil.isArrEmpty(servers)) servers = [{ users: [{}] }];
|
||||||
return new Outbound.HttpSettings(
|
return new Outbound.HttpSettings(
|
||||||
servers[0].address,
|
servers[0].address,
|
||||||
servers[0].port,
|
servers[0].port,
|
||||||
|
@ -1074,7 +1100,7 @@ Outbound.HttpSettings = class extends CommonClass {
|
||||||
servers: [{
|
servers: [{
|
||||||
address: this.address,
|
address: this.address,
|
||||||
port: this.port,
|
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 {
|
Outbound.WireguardSettings = class extends CommonClass {
|
||||||
constructor(
|
constructor(
|
||||||
mtu=1420, secretKey='',
|
mtu = 1420,
|
||||||
address=[''], workers=2, domainStrategy='', reserved='',
|
secretKey = '',
|
||||||
peers=[new Outbound.WireguardSettings.Peer()], kernelMode=false) {
|
address = [''],
|
||||||
|
workers = 2,
|
||||||
|
domainStrategy = '',
|
||||||
|
reserved = '',
|
||||||
|
peers = [new Outbound.WireguardSettings.Peer()],
|
||||||
|
kernelMode = false
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
this.mtu = mtu;
|
this.mtu = mtu;
|
||||||
this.secretKey = secretKey;
|
this.secretKey = secretKey;
|
||||||
this.pubKey = secretKey.length>0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
|
this.pubKey = secretKey.length > 0 ? Wireguard.generateKeypair(secretKey).publicKey : '';
|
||||||
this.address = address instanceof Array ? address.join(',') : address;
|
this.address = Array.isArray(address) ? address.join(',') : address;
|
||||||
this.workers = workers;
|
this.workers = workers;
|
||||||
this.domainStrategy = domainStrategy;
|
this.domainStrategy = domainStrategy;
|
||||||
this.reserved = reserved instanceof Array ? reserved.join(',') : reserved;
|
this.reserved = Array.isArray(reserved) ? reserved.join(',') : reserved;
|
||||||
this.peers = peers;
|
this.peers = peers;
|
||||||
this.kernelMode = kernelMode;
|
this.kernelMode = kernelMode;
|
||||||
}
|
}
|
||||||
|
@ -1105,7 +1137,7 @@ Outbound.WireguardSettings = class extends CommonClass {
|
||||||
this.peers.splice(index, 1);
|
this.peers.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}){
|
static fromJson(json = {}) {
|
||||||
return new Outbound.WireguardSettings(
|
return new Outbound.WireguardSettings(
|
||||||
json.mtu,
|
json.mtu,
|
||||||
json.secretKey,
|
json.secretKey,
|
||||||
|
@ -1120,10 +1152,10 @@ Outbound.WireguardSettings = class extends CommonClass {
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
mtu: this.mtu?? undefined,
|
mtu: this.mtu ?? undefined,
|
||||||
secretKey: this.secretKey,
|
secretKey: this.secretKey,
|
||||||
address: this.address ? this.address.split(",") : [],
|
address: this.address ? this.address.split(",") : [],
|
||||||
workers: this.workers?? undefined,
|
workers: this.workers ?? undefined,
|
||||||
domainStrategy: WireguardDomainStrategy.includes(this.domainStrategy) ? this.domainStrategy : undefined,
|
domainStrategy: WireguardDomainStrategy.includes(this.domainStrategy) ? this.domainStrategy : undefined,
|
||||||
reserved: this.reserved ? this.reserved.split(",").map(Number) : undefined,
|
reserved: this.reserved ? this.reserved.split(",").map(Number) : undefined,
|
||||||
peers: Outbound.WireguardSettings.Peer.toJsonArray(this.peers),
|
peers: Outbound.WireguardSettings.Peer.toJsonArray(this.peers),
|
||||||
|
@ -1133,7 +1165,13 @@ Outbound.WireguardSettings = class extends CommonClass {
|
||||||
};
|
};
|
||||||
|
|
||||||
Outbound.WireguardSettings.Peer = 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();
|
super();
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
this.psk = psk;
|
this.psk = psk;
|
||||||
|
@ -1142,7 +1180,7 @@ Outbound.WireguardSettings.Peer = class extends CommonClass {
|
||||||
this.keepAlive = keepAlive;
|
this.keepAlive = keepAlive;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json={}){
|
static fromJson(json = {}) {
|
||||||
return new Outbound.WireguardSettings.Peer(
|
return new Outbound.WireguardSettings.Peer(
|
||||||
json.publicKey,
|
json.publicKey,
|
||||||
json.preSharedKey,
|
json.preSharedKey,
|
||||||
|
@ -1155,10 +1193,10 @@ Outbound.WireguardSettings.Peer = class extends CommonClass {
|
||||||
toJson() {
|
toJson() {
|
||||||
return {
|
return {
|
||||||
publicKey: this.publicKey,
|
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,
|
allowedIPs: this.allowedIPs ? this.allowedIPs : undefined,
|
||||||
endpoint: this.endpoint,
|
endpoint: this.endpoint,
|
||||||
keepAlive: this.keepAlive?? undefined,
|
keepAlive: this.keepAlive ?? undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -26,7 +26,7 @@ class AllSetting {
|
||||||
this.secretEnable = false;
|
this.secretEnable = false;
|
||||||
this.subEnable = false;
|
this.subEnable = false;
|
||||||
this.subListen = "";
|
this.subListen = "";
|
||||||
this.subPort = "2096";
|
this.subPort = 2096;
|
||||||
this.subPath = "/sub/";
|
this.subPath = "/sub/";
|
||||||
this.subJsonPath = "/json/";
|
this.subJsonPath = "/json/";
|
||||||
this.subDomain = "";
|
this.subDomain = "";
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -100,11 +100,21 @@ class RandomUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
static randomShortId() {
|
static randomShortId() {
|
||||||
let str = '';
|
const lengths = [2, 4, 6, 8, 10, 12, 14, 16];
|
||||||
for (let i = 0; i < 8; ++i) {
|
for (let i = lengths.length - 1; i > 0; i--) {
|
||||||
str += seq[this.randomInt(16)];
|
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) {
|
static randomLowerAndNum(len) {
|
||||||
|
|
Loading…
Reference in a new issue