mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2025-10-28 01:31:19 +00:00
重构部分代码
fix: vless ws 配置缺少 path 字段
This commit is contained in:
@@ -5,14 +5,14 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
)
|
||||
|
||||
// hysteria2://letmein@example.com/?insecure=1&obfs=salamander&obfs-password=gawrgura&pinSHA256=deadbeef&sni=real.example.com
|
||||
|
||||
func ParseHysteria2(proxy string) (model2.Proxy, error) {
|
||||
func ParseHysteria2(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "hysteria2://") && !strings.HasPrefix(proxy, "hy2://") {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria2 Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria2 Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "hysteria2://"), "@", 2)
|
||||
serverInfo := strings.SplitN(parts[1], "/?", 2)
|
||||
@@ -20,36 +20,38 @@ func ParseHysteria2(proxy string) (model2.Proxy, error) {
|
||||
if len(serverAndPort) == 1 {
|
||||
serverAndPort = append(serverAndPort, "443")
|
||||
} else if len(serverAndPort) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria2 Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria2 Url")
|
||||
}
|
||||
params, err := url.ParseQuery(serverInfo[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria2 Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria2 Url")
|
||||
}
|
||||
port, err := strconv.Atoi(serverAndPort[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria2 Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria2 Url")
|
||||
}
|
||||
remarks := params.Get("name")
|
||||
server := serverAndPort[0]
|
||||
password := parts[0]
|
||||
network := params.Get("network")
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "hysteria2",
|
||||
Tag: remarks,
|
||||
Hysteria2: model2.Hysteria2{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
Password: password,
|
||||
Obfs: &model2.Hysteria2Obfs{
|
||||
Hysteria2Options: model.Hysteria2OutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
Password: password,
|
||||
Obfs: &model.Hysteria2Obfs{
|
||||
Type: params.Get("obfs"),
|
||||
Password: params.Get("obfs-password"),
|
||||
},
|
||||
TLS: &model2.OutboundTLSOptions{
|
||||
Enabled: params.Get("pinSHA256") != "",
|
||||
Insecure: params.Get("insecure") == "1",
|
||||
ServerName: params.Get("sni"),
|
||||
Certificate: []string{params.Get("pinSHA256")},
|
||||
OutboundTLSOptionsContainer: model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{Enabled: params.Get("pinSHA256") != "",
|
||||
Insecure: params.Get("insecure") == "1",
|
||||
ServerName: params.Get("sni"),
|
||||
Certificate: []string{params.Get("pinSHA256")}},
|
||||
},
|
||||
Network: network,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user