add tls
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Hysteria, Hysteria2, InTypes, Inbound, Naive, Shadowsocks, TUIC, Trojan, VLESS, VMess } from "@/types/inbounds"
|
||||
import { HTTP, WebSocket, QUIC, gRPC, HTTPUpgrade, Transport, TrspTypes } from "@/types/transport";
|
||||
import { HTTP, WebSocket, gRPC, HTTPUpgrade, Transport, TrspTypes } from "@/types/transport";
|
||||
|
||||
export interface Link {
|
||||
type: "local" | "external" | "sub"
|
||||
@@ -13,25 +13,25 @@ function utf8ToBase64(utf8String: string): string {
|
||||
}
|
||||
|
||||
export namespace LinkUtil {
|
||||
export function linkGenerator(user: string, inbound: Inbound): string {
|
||||
export function linkGenerator(user: string, inbound: Inbound, tlsClient: any = null): string {
|
||||
const addr = location.hostname
|
||||
switch(inbound.type){
|
||||
case InTypes.Shadowsocks:
|
||||
return shadowsocksLink(user,<Shadowsocks>inbound,addr)
|
||||
return shadowsocksLink(user,<Shadowsocks>inbound, addr)
|
||||
case InTypes.Naive:
|
||||
return naiveLink(user,<Naive>inbound,addr)
|
||||
return naiveLink(user,<Naive>inbound, addr, tlsClient)
|
||||
case InTypes.Hysteria:
|
||||
return hysteriaLink(user,<Hysteria>inbound,addr)
|
||||
return hysteriaLink(user,<Hysteria>inbound, addr, tlsClient)
|
||||
case InTypes.Hysteria2:
|
||||
return hysteria2Link(user,<Hysteria2>inbound,addr)
|
||||
return hysteria2Link(user,<Hysteria2>inbound, addr, tlsClient)
|
||||
case InTypes.TUIC:
|
||||
return tuicLink(user,<TUIC>inbound,addr)
|
||||
return tuicLink(user,<TUIC>inbound, addr, tlsClient)
|
||||
case InTypes.VLESS:
|
||||
return vlessLink(user,<VLESS>inbound,addr)
|
||||
return vlessLink(user,<VLESS>inbound, addr, tlsClient)
|
||||
case InTypes.Trojan:
|
||||
return trojanLink(user,<Trojan>inbound,addr)
|
||||
return trojanLink(user,<Trojan>inbound, addr, tlsClient)
|
||||
case InTypes.VMess:
|
||||
return vmessLink(user,<VMess>inbound,addr)
|
||||
return vmessLink(user,<VMess>inbound, addr, tlsClient)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
@@ -40,7 +40,6 @@ export namespace LinkUtil {
|
||||
const userPass = inbound.users?.find(i => i.name == user)?.password
|
||||
const password = [userPass]
|
||||
if (inbound.method.startsWith('2022')) password.push(inbound.password)
|
||||
|
||||
const params = {
|
||||
tfo: inbound.tcp_fast_open? 1 : null,
|
||||
network: inbound.network?? null
|
||||
@@ -56,7 +55,7 @@ export namespace LinkUtil {
|
||||
return uri.toString()
|
||||
}
|
||||
|
||||
function hysteriaLink(user: string, inbound: Hysteria, addr: string): string {
|
||||
function hysteriaLink(user: string, inbound: Hysteria, addr: string, tlsClient: any): string {
|
||||
const auth = inbound.users.find(i => i.name == user)?.auth_str
|
||||
const params = {
|
||||
upmbps: inbound.up_mbps?? null,
|
||||
@@ -65,7 +64,8 @@ export namespace LinkUtil {
|
||||
peer: inbound.tls.server_name?? null,
|
||||
alpn: inbound.tls.alpn?.join(',')?? null,
|
||||
obfsParam: inbound.obfs?? null,
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0,
|
||||
insecure: tlsClient?.insecure ? 1 : null
|
||||
}
|
||||
const uri = new URL(`hysteria://${addr}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
@@ -77,7 +77,7 @@ export namespace LinkUtil {
|
||||
return uri.toString()
|
||||
}
|
||||
|
||||
function hysteria2Link(user: string, inbound: Hysteria2, addr: string): string {
|
||||
function hysteria2Link(user: string, inbound: Hysteria2, addr: string, tlsClient: any): string {
|
||||
const password = inbound.users.find(i => i.name == user)?.password
|
||||
const params = {
|
||||
upmbps: inbound.up_mbps?? null,
|
||||
@@ -86,7 +86,8 @@ export namespace LinkUtil {
|
||||
alpn: inbound.tls.alpn?.join(',')?? null,
|
||||
obfs: inbound.obfs?.type?? null,
|
||||
'obfs-password': inbound.obfs?.password?? null,
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0
|
||||
fastopen: inbound.tcp_fast_open? 1 : 0,
|
||||
insecure: tlsClient?.insecure ? 1 : null
|
||||
}
|
||||
const uri = new URL(`hysteria2://${password}@${addr}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
@@ -98,13 +99,14 @@ export namespace LinkUtil {
|
||||
return uri.toString()
|
||||
}
|
||||
|
||||
function naiveLink(user: string, inbound: Naive, addr: string): string {
|
||||
function naiveLink(user: string, inbound: Naive, addr: string, tlsClient: any): string {
|
||||
const password = inbound.users.find(i => i.username == user)?.password
|
||||
const params = {
|
||||
padding: 1,
|
||||
peer: inbound.tls.server_name?? null,
|
||||
alpn: inbound.tls.alpn?.join(',')?? null,
|
||||
tfo: inbound.tcp_fast_open? 1 : 0
|
||||
tfo: inbound.tcp_fast_open? 1 : 0,
|
||||
allowInsecure: tlsClient?.insecure ? 1 : null
|
||||
}
|
||||
const uri = `http2://${utf8ToBase64(user + ":" + password + "@" + addr + ":" + inbound.listen_port)}`
|
||||
const paramsArray = []
|
||||
@@ -116,12 +118,14 @@ export namespace LinkUtil {
|
||||
return uri.toString() + "?" + paramsArray.join('&') + "#" + inbound.tag
|
||||
}
|
||||
|
||||
function tuicLink(user: string, inbound: TUIC, addr: string): string {
|
||||
function tuicLink(user: string, inbound: TUIC, addr: string, tlsClient: any): string {
|
||||
const u = inbound.users.find(i => i.name == user)
|
||||
const params = {
|
||||
sni: inbound.tls.server_name?? null,
|
||||
alpn: inbound.tls.alpn?.join(',')?? null,
|
||||
congestion_control: inbound.congestion_control?? null
|
||||
congestion_control: inbound.congestion_control?? null,
|
||||
allowInsecure: tlsClient?.insecure ? 1 : null,
|
||||
disable_sni: tlsClient?.disable_sni ? 1 : null
|
||||
}
|
||||
const uri = new URL(`tuic://${u?.uuid}:${u?.password}@${addr}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries(params)){
|
||||
@@ -166,7 +170,7 @@ export namespace LinkUtil {
|
||||
return params
|
||||
}
|
||||
|
||||
function vlessLink(user: string, inbound: VLESS, addr: string): string {
|
||||
function vlessLink(user: string, inbound: VLESS, addr: string, tlsClient: any): string {
|
||||
const u = inbound.users.find(i => i.name == user)
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
@@ -174,10 +178,14 @@ export namespace LinkUtil {
|
||||
|
||||
const params = {
|
||||
type: transport?.type?? 'tcp',
|
||||
security: inbound.tls?.enabled? 'tls' : null,
|
||||
security: inbound.tls?.enabled? inbound.tls?.reality?.enabled ? 'reality' : 'tls' : null,
|
||||
alpn: inbound.tls?.alpn?.join(',')?? null,
|
||||
sni: inbound.tls?.server_name?? null,
|
||||
flow: inbound.tls?.enabled ? u?.flow?? null : null
|
||||
flow: inbound.tls?.enabled ? u?.flow?? null : null,
|
||||
allowInsecure: tlsClient?.insecure ? 1 : null,
|
||||
fp: tlsClient?.utls?.enabled ? tlsClient.utls.fingerprint : null,
|
||||
pbk: tlsClient?.reality?.public_key?? null,
|
||||
sid: inbound.tls?.reality?.enabled ? (inbound.tls?.reality?.short_id?.length>0 ? inbound.tls.reality.short_id[0] : null) : null
|
||||
}
|
||||
const uri = new URL(`vless://${u?.uuid}@${addr}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
@@ -189,7 +197,7 @@ export namespace LinkUtil {
|
||||
return uri.toString()
|
||||
}
|
||||
|
||||
function trojanLink(user: string, inbound: Trojan, addr: string): string {
|
||||
function trojanLink(user: string, inbound: Trojan, addr: string, tlsClient: any): string {
|
||||
const u = inbound.users.find(i => i.name == user)
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
@@ -197,9 +205,13 @@ export namespace LinkUtil {
|
||||
|
||||
const params = {
|
||||
type: transport?.type?? 'tcp',
|
||||
security: inbound.tls?.enabled? 'tls' : null,
|
||||
security: inbound.tls?.enabled? inbound.tls?.reality?.enabled ? 'reality' : 'tls' : null,
|
||||
alpn: inbound.tls?.alpn?.join(',')?? null,
|
||||
sni: inbound.tls?.server_name?? null,
|
||||
allowInsecure: tlsClient?.insecure ? 1 : null,
|
||||
fp: tlsClient?.utls?.enabled ? tlsClient.utls.fingerprint : null,
|
||||
pbk: tlsClient?.reality?.public_key?? null,
|
||||
sid: inbound.tls?.reality?.enabled ? (inbound.tls?.reality?.short_id?.length>0 ? inbound.tls.reality.short_id[0] : null) : null
|
||||
}
|
||||
const uri = new URL(`trojan://${u?.password}@${addr}:${inbound.listen_port}`)
|
||||
for (const [key, value] of Object.entries({...params, ...tParams})){
|
||||
@@ -211,7 +223,7 @@ export namespace LinkUtil {
|
||||
return uri.toString()
|
||||
}
|
||||
|
||||
function vmessLink(user: string, inbound: VMess, addr: string): string {
|
||||
function vmessLink(user: string, inbound: VMess, addr: string, tlsClient: any): string {
|
||||
const u = inbound.users.find(i => i.name == user)
|
||||
const transport = <Transport>inbound.transport
|
||||
|
||||
@@ -224,13 +236,14 @@ export namespace LinkUtil {
|
||||
aid: u?.alterId,
|
||||
host: tParams.host?? undefined,
|
||||
id: u?.uuid,
|
||||
net: transport?.type == undefined || transport?.type == 'http' ? 'tcp' : transport.type,
|
||||
net: transport?.type == undefined || transport?.type == 'http' ? 'tcp' : transport.type,
|
||||
type: transport?.type == 'http' ? 'http' : undefined,
|
||||
path: tParams.path?? undefined,
|
||||
port: inbound.listen_port,
|
||||
ps: inbound.tag,
|
||||
sni: inbound.tls.server_name?? undefined,
|
||||
tls: Object.keys(inbound.tls).length>0? 'tls' : 'none'
|
||||
tls: Object.keys(inbound.tls).length>0? 'tls' : 'none',
|
||||
allowInsecure: tlsClient?.insecure ? 1 : undefined
|
||||
}
|
||||
return 'vmess://' + utf8ToBase64(JSON.stringify(params, null, 2))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user