1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-24 12:04:42 -05:00
This commit is contained in:
Nite07 2024-03-11 12:53:58 +08:00
parent a6a4d63545
commit 80994b835c
4 changed files with 124 additions and 37 deletions

View File

@ -31,10 +31,6 @@ func ParseHysteria2(proxy string) (model.Proxy, error) {
return model.Proxy{}, errors.New("invalid hysteria2 Url") return model.Proxy{}, errors.New("invalid hysteria2 Url")
} }
remarks := params.Get("name") remarks := params.Get("name")
certificate := make([]string, 0)
if params.Get("pinSHA256") != "" {
certificate = append(certificate, params.Get("pinSHA256"))
}
server := serverAndPort[0] server := serverAndPort[0]
password := parts[0] password := parts[0]
network := params.Get("network") network := params.Get("network")
@ -53,7 +49,7 @@ func ParseHysteria2(proxy string) (model.Proxy, error) {
Enabled: params.Get("pinSHA256") != "", Enabled: params.Get("pinSHA256") != "",
Insecure: params.Get("insecure") == "1", Insecure: params.Get("insecure") == "1",
ServerName: params.Get("sni"), ServerName: params.Get("sni"),
Certificate: certificate, Certificate: []string{params.Get("pinSHA256")},
}, },
Network: network, Network: network,
}, },

View File

@ -50,6 +50,10 @@ func ParseShadowsocks(proxy string) (model.Proxy, error) {
method := credentials[0] method := credentials[0]
password := credentials[1] password := credentials[1]
server := strings.TrimSpace(serverAndPort[0]) server := strings.TrimSpace(serverAndPort[0])
// params, err := url.ParseQuery(proxy)
// if err != nil {
// return model.Proxy{}, err
// }
result := model.Proxy{ result := model.Proxy{
Type: "shadowsocks", Type: "shadowsocks",
Shadowsocks: model.Shadowsocks{ Shadowsocks: model.Shadowsocks{

View File

@ -44,13 +44,65 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
Tag: remarks, Tag: remarks,
Server: server, Server: server,
ServerPort: uint16(port), ServerPort: uint16(port),
TLS: &model.OutboundTLSOptions{ Password: password,
Network: params.Get("type"),
},
}
if params.Get("security") == "xtls" || params.Get("security") == "tls" {
result.Trojan.TLS = &model.OutboundTLSOptions{
Enabled: true,
ALPN: strings.Split(params.Get("alpn"), ","),
ServerName: params.Get("sni"),
}
}
if params.Get("security") == "reality" {
result.Trojan.TLS = &model.OutboundTLSOptions{
Enabled: true, Enabled: true,
ServerName: params.Get("sni"), ServerName: params.Get("sni"),
Reality: &model.OutboundRealityOptions{
Enabled: true,
PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"),
}, },
Password: password, UTLS: &model.OutboundUTLSOptions{
Network: "tcp", Enabled: params.Get("fp") != "",
Fingerprint: params.Get("fp"),
}, },
} }
}
if params.Get("type") == "ws" {
result.Trojan.Transport = &model.V2RayTransportOptions{
Type: "ws",
WebsocketOptions: model.V2RayWebsocketOptions{
Path: params.Get("path"),
Headers: map[string]string{
"Host": params.Get("host"),
},
},
}
}
if params.Get("type") == "http" {
result.Trojan.Transport = &model.V2RayTransportOptions{
Type: "http",
HTTPOptions: model.V2RayHTTPOptions{
Host: []string{params.Get("host")},
Path: params.Get("path"),
},
}
}
if params.Get("type") == "quic" {
result.Trojan.Transport = &model.V2RayTransportOptions{
Type: "quic",
QUICOptions: model.V2RayQUICOptions{},
}
}
if params.Get("type") == "grpc" {
result.Trojan.Transport = &model.V2RayTransportOptions{
Type: "grpc",
GRPCOptions: model.V2RayGRPCOptions{
ServiceName: params.Get("serviceName"),
},
}
}
return result, nil return result, nil
} }

View File

@ -57,33 +57,68 @@ func ParseVless(proxy string) (model.Proxy, error) {
ServerPort: uint16(port), ServerPort: uint16(port),
UUID: uuid, UUID: uuid,
Network: network, Network: network,
TLS: &model.OutboundTLSOptions{ Flow: params.Get("flow"),
Enabled: params.Get("security") == "reality", },
}
if params.Get("security") == "tls" {
result.VLESS.TLS = &model.OutboundTLSOptions{
Enabled: true,
ALPN: strings.Split(params.Get("alpn"), ","),
Insecure: params.Get("allowInsecure") == "1",
}
}
if params.Get("security") == "reality" {
result.VLESS.TLS = &model.OutboundTLSOptions{
Enabled: true,
ServerName: params.Get("sni"), ServerName: params.Get("sni"),
UTLS: &model.OutboundUTLSOptions{ UTLS: &model.OutboundUTLSOptions{
Enabled: params.Get("fp") != "", Enabled: params.Get("fp") != "",
Fingerprint: params.Get("fp"), Fingerprint: params.Get("fp"),
}, },
Reality: &model.OutboundRealityOptions{ Reality: &model.OutboundRealityOptions{
Enabled: params.Get("pbk") != "", Enabled: true,
PublicKey: params.Get("pbk"), PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"), ShortID: params.Get("sid"),
}, },
ALPN: strings.Split(params.Get("alpn"), ","), ALPN: strings.Split(params.Get("alpn"), ","),
}, }
Transport: &model.V2RayTransportOptions{ }
if params.Get("type") == "ws" {
result.VLESS.Transport = &model.V2RayTransportOptions{
Type: "ws",
WebsocketOptions: model.V2RayWebsocketOptions{ WebsocketOptions: model.V2RayWebsocketOptions{
Path: params.Get("path"), Path: params.Get("path"),
Headers: map[string]string{ Headers: map[string]string{
"Host": params.Get("host"), "Host": params.Get("host"),
}, },
}, },
}
}
if params.Get("type") == "quic" {
result.VLESS.Transport = &model.V2RayTransportOptions{
Type: "quic",
QUICOptions: model.V2RayQUICOptions{},
}
}
if params.Get("type") == "grpc" {
result.VLESS.Transport = &model.V2RayTransportOptions{
Type: "grpc",
GRPCOptions: model.V2RayGRPCOptions{ GRPCOptions: model.V2RayGRPCOptions{
ServiceName: params.Get("serviceName"), ServiceName: params.Get("serviceName"),
}, },
}
}
if params.Get("type") == "http" {
host, err := url.QueryUnescape(params.Get("host"))
if err != nil {
return model.Proxy{}, err
}
result.VLESS.Transport = &model.V2RayTransportOptions{
Type: "http",
HTTPOptions: model.V2RayHTTPOptions{
Host: strings.Split(host, ","),
}, },
Flow: params.Get("flow"), }
},
} }
return result, nil return result, nil
} }