mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-07-04 11:52:34 +08:00
Enhance Trojan, Vless, and Vmess parsers.
This commit is contained in:
@ -58,7 +58,17 @@ func (p *TrojanParser) Parse(proxy string) (P.Proxy, error) {
|
||||
remarks = strings.TrimSpace(remarks)
|
||||
|
||||
query := link.Query()
|
||||
network, security, alpnStr, sni, pbk, sid, fp, path, host, serviceName, udp := query.Get("type"), query.Get("security"), query.Get("alpn"), query.Get("sni"), query.Get("pbk"), query.Get("sid"), query.Get("fp"), query.Get("path"), query.Get("host"), query.Get("serviceName"), query.Get("udp")
|
||||
network, security, alpnStr, sni, pbk, sid, fp, path, host, serviceName, udp, insecure := query.Get("type"), query.Get("security"), query.Get("alpn"), query.Get("sni"), query.Get("pbk"), query.Get("sid"), query.Get("fp"), query.Get("path"), query.Get("host"), query.Get("serviceName"), query.Get("udp"), query.Get("allowInsecure")
|
||||
|
||||
insecureBool := insecure == "1"
|
||||
result := P.Trojan{
|
||||
Server: server,
|
||||
Port: port,
|
||||
Password: password,
|
||||
Network: network,
|
||||
UDP: udp == "true",
|
||||
SkipCertVerify: insecureBool,
|
||||
}
|
||||
|
||||
var alpn []string
|
||||
if strings.Contains(alpnStr, ",") {
|
||||
@ -66,27 +76,23 @@ func (p *TrojanParser) Parse(proxy string) (P.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
|
||||
result := P.Trojan{
|
||||
Server: server,
|
||||
Port: port,
|
||||
Password: password,
|
||||
Network: network,
|
||||
UDP: udp == "true",
|
||||
if len(alpn) > 0 {
|
||||
result.ALPN = alpn
|
||||
}
|
||||
|
||||
if security == "xtls" || security == "tls" {
|
||||
result.ALPN = alpn
|
||||
if fp != "" {
|
||||
result.ClientFingerprint = fp
|
||||
}
|
||||
|
||||
if sni != "" {
|
||||
result.SNI = sni
|
||||
}
|
||||
|
||||
if security == "reality" {
|
||||
result.SNI = sni
|
||||
result.RealityOpts = P.RealityOptions{
|
||||
PublicKey: pbk,
|
||||
ShortID: sid,
|
||||
}
|
||||
result.Fingerprint = fp
|
||||
}
|
||||
|
||||
if network == "ws" {
|
||||
|
@ -57,6 +57,7 @@ func (p *VlessParser) Parse(proxy string) (P.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
|
||||
remarks := link.Fragment
|
||||
if remarks == "" {
|
||||
remarks = fmt.Sprintf("%s:%s", server, portStr)
|
||||
@ -64,29 +65,36 @@ func (p *VlessParser) Parse(proxy string) (P.Proxy, error) {
|
||||
remarks = strings.TrimSpace(remarks)
|
||||
|
||||
result := P.Vless{
|
||||
Server: server,
|
||||
Port: port,
|
||||
UUID: uuid,
|
||||
Flow: flow,
|
||||
UDP: udp == "true",
|
||||
Server: server,
|
||||
Port: port,
|
||||
UUID: uuid,
|
||||
Flow: flow,
|
||||
UDP: udp == "true",
|
||||
SkipCertVerify: insecureBool,
|
||||
}
|
||||
|
||||
if len(alpn) > 0 {
|
||||
result.ALPN = alpn
|
||||
}
|
||||
|
||||
if fp != "" {
|
||||
result.ClientFingerprint = fp
|
||||
}
|
||||
|
||||
if sni != "" {
|
||||
result.ServerName = sni
|
||||
}
|
||||
|
||||
if security == "tls" {
|
||||
result.TLS = true
|
||||
result.ALPN = alpn
|
||||
result.SkipCertVerify = insecureBool
|
||||
result.Fingerprint = fp
|
||||
result.ServerName = sni
|
||||
}
|
||||
|
||||
if security == "reality" {
|
||||
result.TLS = true
|
||||
result.ServerName = sni
|
||||
result.RealityOpts = P.RealityOptions{
|
||||
PublicKey: pbk,
|
||||
ShortID: sid,
|
||||
}
|
||||
result.Fingerprint = fp
|
||||
}
|
||||
|
||||
if _type == "ws" {
|
||||
|
@ -99,6 +99,13 @@ func (p *VmessParser) Parse(proxy string) (P.Proxy, error) {
|
||||
name = vmess.Ps
|
||||
}
|
||||
|
||||
var alpn []string
|
||||
if strings.Contains(vmess.Alpn, ",") {
|
||||
alpn = strings.Split(vmess.Alpn, ",")
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
|
||||
result := P.Vmess{
|
||||
Server: vmess.Add,
|
||||
Port: port,
|
||||
@ -107,19 +114,22 @@ func (p *VmessParser) Parse(proxy string) (P.Proxy, error) {
|
||||
Cipher: vmess.Scy,
|
||||
}
|
||||
|
||||
if vmess.Tls == "tls" {
|
||||
var alpn []string
|
||||
if strings.Contains(vmess.Alpn, ",") {
|
||||
alpn = strings.Split(vmess.Alpn, ",")
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
result.TLS = true
|
||||
result.Fingerprint = vmess.Fp
|
||||
if len(alpn) > 0 {
|
||||
result.ALPN = alpn
|
||||
}
|
||||
|
||||
if vmess.Fp != "" {
|
||||
result.ClientFingerprint = vmess.Fp
|
||||
}
|
||||
|
||||
if vmess.Sni != "" {
|
||||
result.ServerName = vmess.Sni
|
||||
}
|
||||
|
||||
if vmess.Tls == "tls" {
|
||||
result.TLS = true
|
||||
}
|
||||
|
||||
if vmess.Net == "ws" {
|
||||
if vmess.Path == "" {
|
||||
vmess.Path = "/"
|
||||
|
Reference in New Issue
Block a user