1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 14:44: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")
}
remarks := params.Get("name")
certificate := make([]string, 0)
if params.Get("pinSHA256") != "" {
certificate = append(certificate, params.Get("pinSHA256"))
}
server := serverAndPort[0]
password := parts[0]
network := params.Get("network")
@ -53,7 +49,7 @@ func ParseHysteria2(proxy string) (model.Proxy, error) {
Enabled: params.Get("pinSHA256") != "",
Insecure: params.Get("insecure") == "1",
ServerName: params.Get("sni"),
Certificate: certificate,
Certificate: []string{params.Get("pinSHA256")},
},
Network: network,
},

View File

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

View File

@ -44,13 +44,65 @@ func ParseTrojan(proxy string) (model.Proxy, error) {
Tag: remarks,
Server: server,
ServerPort: uint16(port),
TLS: &model.OutboundTLSOptions{
Enabled: true,
ServerName: params.Get("sni"),
},
Password: password,
Network: "tcp",
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,
ServerName: params.Get("sni"),
Reality: &model.OutboundRealityOptions{
Enabled: true,
PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"),
},
UTLS: &model.OutboundUTLSOptions{
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
}

View File

@ -57,33 +57,68 @@ func ParseVless(proxy string) (model.Proxy, error) {
ServerPort: uint16(port),
UUID: uuid,
Network: network,
TLS: &model.OutboundTLSOptions{
Enabled: params.Get("security") == "reality",
ServerName: params.Get("sni"),
UTLS: &model.OutboundUTLSOptions{
Enabled: params.Get("fp") != "",
Fingerprint: params.Get("fp"),
},
Reality: &model.OutboundRealityOptions{
Enabled: params.Get("pbk") != "",
PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"),
},
ALPN: strings.Split(params.Get("alpn"), ","),
},
Transport: &model.V2RayTransportOptions{
WebsocketOptions: model.V2RayWebsocketOptions{
Path: params.Get("path"),
Headers: map[string]string{
"Host": params.Get("host"),
},
},
GRPCOptions: model.V2RayGRPCOptions{
ServiceName: params.Get("serviceName"),
},
},
Flow: params.Get("flow"),
Flow: params.Get("flow"),
},
}
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"),
UTLS: &model.OutboundUTLSOptions{
Enabled: params.Get("fp") != "",
Fingerprint: params.Get("fp"),
},
Reality: &model.OutboundRealityOptions{
Enabled: true,
PublicKey: params.Get("pbk"),
ShortID: params.Get("sid"),
},
ALPN: strings.Split(params.Get("alpn"), ","),
}
}
if params.Get("type") == "ws" {
result.VLESS.Transport = &model.V2RayTransportOptions{
Type: "ws",
WebsocketOptions: model.V2RayWebsocketOptions{
Path: params.Get("path"),
Headers: map[string]string{
"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{
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, ","),
},
}
}
return result, nil
}