fix NetworkSettings decode for sing

This commit is contained in:
yuzuki999 2023-08-27 13:20:31 +08:00
parent de8402ecd5
commit e51591c7f7

View File

@ -86,33 +86,43 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
case "tcp": case "tcp":
t.Type = "" t.Type = ""
case "ws": case "ws":
network := WsNetworkConfig{} var (
err := json.Unmarshal(n.NetworkSettings, &network) path string
if err != nil { ed int
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) headers map[string]option.Listable[string]
} )
var u *url.URL if len(n.NetworkSettings) != 0 {
u, err = url.Parse(network.Path) network := WsNetworkConfig{}
if err != nil { err := json.Unmarshal(n.NetworkSettings, &network)
return option.Inbound{}, fmt.Errorf("parse path error: %s", err) if err != nil {
} return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
ed, _ := strconv.Atoi(u.Query().Get("ed")) }
h := make(map[string]option.Listable[string], len(network.Headers)) var u *url.URL
for k, v := range network.Headers { u, err = url.Parse(network.Path)
h[k] = option.Listable[string]{ if err != nil {
v, return option.Inbound{}, fmt.Errorf("parse path error: %s", err)
}
path = u.Path
ed, _ = strconv.Atoi(u.Query().Get("ed"))
headers = make(map[string]option.Listable[string], len(network.Headers))
for k, v := range network.Headers {
headers[k] = option.Listable[string]{
v,
}
} }
} }
t.WebsocketOptions = option.V2RayWebsocketOptions{ t.WebsocketOptions = option.V2RayWebsocketOptions{
Path: u.Path, Path: path,
EarlyDataHeaderName: "Sec-WebSocket-Protocol", EarlyDataHeaderName: "Sec-WebSocket-Protocol",
MaxEarlyData: uint32(ed), MaxEarlyData: uint32(ed),
Headers: h, Headers: headers,
} }
case "grpc": case "grpc":
err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions) if len(n.NetworkSettings) != 0 {
if err != nil { err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions)
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err) if err != nil {
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
}
} }
} }
if info.Type == "vless" { if info.Type == "vless" {