mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2025-06-16 10:03:18 +08:00
重构部分代码
fix: vless ws 配置缺少 path 字段
This commit is contained in:
@ -5,7 +5,7 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
)
|
||||
|
||||
//hysteria://host:port?protocol=udp&auth=123456&peer=sni.domain&insecure=1&upmbps=100&downmbps=100&alpn=hysteria&obfs=xplus&obfsParam=123456#remarks
|
||||
@ -23,23 +23,23 @@ import (
|
||||
//- obfsParam: Obfuscation password (optional)
|
||||
//- remarks: remarks (optional)
|
||||
|
||||
func ParseHysteria(proxy string) (model2.Proxy, error) {
|
||||
func ParseHysteria(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "hysteria://") {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "hysteria://"), "?", 2)
|
||||
serverInfo := strings.SplitN(parts[0], ":", 2)
|
||||
if len(serverInfo) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria Url")
|
||||
}
|
||||
params, err := url.ParseQuery(parts[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria Url")
|
||||
}
|
||||
host := serverInfo[0]
|
||||
port, err := strconv.Atoi(serverInfo[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria Url")
|
||||
}
|
||||
protocol := params.Get("protocol")
|
||||
auth := params.Get("auth")
|
||||
@ -64,23 +64,27 @@ func ParseHysteria(proxy string) (model2.Proxy, error) {
|
||||
}
|
||||
insecureBool, err := strconv.ParseBool(insecure)
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid hysteria Url")
|
||||
return model.Outbound{}, errors.New("invalid hysteria Url")
|
||||
}
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "hysteria",
|
||||
Tag: remarks,
|
||||
Hysteria: model2.Hysteria{
|
||||
Server: host,
|
||||
ServerPort: uint16(port),
|
||||
Up: upmbps,
|
||||
Down: downmbps,
|
||||
Auth: []byte(auth),
|
||||
Obfs: obfs,
|
||||
Network: protocol,
|
||||
TLS: &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
Insecure: insecureBool,
|
||||
ALPN: alpn,
|
||||
HysteriaOptions: model.HysteriaOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: host,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
Up: upmbps,
|
||||
Down: downmbps,
|
||||
Auth: []byte(auth),
|
||||
Obfs: obfs,
|
||||
Network: protocol,
|
||||
OutboundTLSOptionsContainer: model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
Insecure: insecureBool,
|
||||
ALPN: alpn,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"sub2sing-box/model"
|
||||
)
|
||||
|
||||
var ParserMap map[string]func(string) (model.Proxy, error) = map[string]func(string) (model.Proxy, error){
|
||||
var ParserMap map[string]func(string) (model.Outbound, error) = map[string]func(string) (model.Outbound, error){
|
||||
"ss://": ParseShadowsocks,
|
||||
"vmess://": ParseVmess,
|
||||
"trojan://": ParseTrojan,
|
||||
|
@ -5,43 +5,43 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
"sub2sing-box/util"
|
||||
)
|
||||
|
||||
func ParseShadowsocks(proxy string) (model2.Proxy, error) {
|
||||
func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "ss://") {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "ss://"), "@", 2)
|
||||
if len(parts) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
if !strings.Contains(parts[0], ":") {
|
||||
decoded, err := util.DecodeBase64(parts[0])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
parts[0] = decoded
|
||||
}
|
||||
credentials := strings.SplitN(parts[0], ":", 2)
|
||||
if len(credentials) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
serverInfo := strings.SplitN(parts[1], "#", 2)
|
||||
serverAndPort := strings.SplitN(serverInfo[0], ":", 2)
|
||||
if len(serverAndPort) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
remarks := ""
|
||||
if len(serverInfo) == 2 {
|
||||
unescape, err := url.QueryUnescape(serverInfo[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
remarks = strings.TrimSpace(unescape)
|
||||
} else {
|
||||
@ -50,14 +50,16 @@ func ParseShadowsocks(proxy string) (model2.Proxy, error) {
|
||||
method := credentials[0]
|
||||
password := credentials[1]
|
||||
server := strings.TrimSpace(serverAndPort[0])
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "shadowsocks",
|
||||
Tag: remarks,
|
||||
Shadowsocks: model2.Shadowsocks{
|
||||
Method: method,
|
||||
Password: password,
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
ShadowsocksOptions: model.ShadowsocksOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
Method: method,
|
||||
Password: password,
|
||||
},
|
||||
}
|
||||
return result, nil
|
||||
|
@ -5,30 +5,30 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
)
|
||||
|
||||
func ParseTrojan(proxy string) (model2.Proxy, error) {
|
||||
func ParseTrojan(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "trojan://") {
|
||||
return model2.Proxy{}, errors.New("invalid trojan Url")
|
||||
return model.Outbound{}, errors.New("invalid trojan Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "trojan://"), "@", 2)
|
||||
if len(parts) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid trojan Url")
|
||||
return model.Outbound{}, errors.New("invalid trojan Url")
|
||||
}
|
||||
serverInfo := strings.SplitN(parts[1], "#", 2)
|
||||
serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
|
||||
serverAndPort := strings.SplitN(serverAndPortAndParams[0], ":", 2)
|
||||
params, err := url.ParseQuery(serverAndPortAndParams[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
if len(serverAndPort) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid trojan Url")
|
||||
return model.Outbound{}, errors.New("invalid trojan Url")
|
||||
}
|
||||
port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
remarks := ""
|
||||
if len(serverInfo) == 2 {
|
||||
@ -38,14 +38,16 @@ func ParseTrojan(proxy string) (model2.Proxy, error) {
|
||||
}
|
||||
server := strings.TrimSpace(serverAndPort[0])
|
||||
password := strings.TrimSpace(parts[0])
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "trojan",
|
||||
Tag: remarks,
|
||||
Trojan: model2.Trojan{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
Password: password,
|
||||
Network: params.Get("type"),
|
||||
TrojanOptions: model.TrojanOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
Password: password,
|
||||
Network: params.Get("type"),
|
||||
},
|
||||
}
|
||||
if params.Get("security") == "xtls" || params.Get("security") == "tls" {
|
||||
@ -55,31 +57,35 @@ func ParseTrojan(proxy string) (model2.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
result.Trojan.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ALPN: alpn,
|
||||
ServerName: params.Get("sni"),
|
||||
result.TrojanOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ALPN: alpn,
|
||||
ServerName: params.Get("sni"),
|
||||
},
|
||||
}
|
||||
}
|
||||
if params.Get("security") == "reality" {
|
||||
result.Trojan.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ServerName: params.Get("sni"),
|
||||
Reality: &model2.OutboundRealityOptions{
|
||||
Enabled: true,
|
||||
PublicKey: params.Get("pbk"),
|
||||
ShortID: params.Get("sid"),
|
||||
},
|
||||
UTLS: &model2.OutboundUTLSOptions{
|
||||
Enabled: params.Get("fp") != "",
|
||||
Fingerprint: params.Get("fp"),
|
||||
result.TrojanOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
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 = &model2.V2RayTransportOptions{
|
||||
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "ws",
|
||||
WebsocketOptions: model2.V2RayWebsocketOptions{
|
||||
WebsocketOptions: model.V2RayWebsocketOptions{
|
||||
Path: params.Get("path"),
|
||||
Headers: map[string]string{
|
||||
"Host": params.Get("host"),
|
||||
@ -88,24 +94,24 @@ func ParseTrojan(proxy string) (model2.Proxy, error) {
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "http" {
|
||||
result.Trojan.Transport = &model2.V2RayTransportOptions{
|
||||
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "http",
|
||||
HTTPOptions: model2.V2RayHTTPOptions{
|
||||
HTTPOptions: model.V2RayHTTPOptions{
|
||||
Host: []string{params.Get("host")},
|
||||
Path: params.Get("path"),
|
||||
},
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "quic" {
|
||||
result.Trojan.Transport = &model2.V2RayTransportOptions{
|
||||
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "quic",
|
||||
QUICOptions: model2.V2RayQUICOptions{},
|
||||
QUICOptions: model.V2RayQUICOptions{},
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "grpc" {
|
||||
result.Trojan.Transport = &model2.V2RayTransportOptions{
|
||||
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "grpc",
|
||||
GRPCOptions: model2.V2RayGRPCOptions{
|
||||
GRPCOptions: model.V2RayGRPCOptions{
|
||||
ServiceName: params.Get("serviceName"),
|
||||
},
|
||||
}
|
||||
|
@ -5,30 +5,30 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
)
|
||||
|
||||
func ParseVless(proxy string) (model2.Proxy, error) {
|
||||
func ParseVless(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "vless://") {
|
||||
return model2.Proxy{}, errors.New("invalid vless Url")
|
||||
return model.Outbound{}, errors.New("invalid vless Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "vless://"), "@", 2)
|
||||
if len(parts) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid vless Url")
|
||||
return model.Outbound{}, errors.New("invalid vless Url")
|
||||
}
|
||||
serverInfo := strings.SplitN(parts[1], "#", 2)
|
||||
serverAndPortAndParams := strings.SplitN(serverInfo[0], "?", 2)
|
||||
serverAndPort := strings.SplitN(serverAndPortAndParams[0], ":", 2)
|
||||
params, err := url.ParseQuery(serverAndPortAndParams[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
if len(serverAndPort) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid vless Url")
|
||||
return model.Outbound{}, errors.New("invalid vless Url")
|
||||
}
|
||||
port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
remarks := ""
|
||||
if len(serverInfo) == 2 {
|
||||
@ -37,25 +37,27 @@ func ParseVless(proxy string) (model2.Proxy, error) {
|
||||
} else {
|
||||
remarks, err = url.QueryUnescape(serverInfo[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
remarks, err = url.QueryUnescape(serverAndPort[0])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
}
|
||||
server := strings.TrimSpace(serverAndPort[0])
|
||||
uuid := strings.TrimSpace(parts[0])
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "vless",
|
||||
Tag: remarks,
|
||||
VLESS: model2.VLESS{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
UUID: uuid,
|
||||
Flow: params.Get("flow"),
|
||||
VLESSOptions: model.VLESSOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
UUID: uuid,
|
||||
Flow: params.Get("flow"),
|
||||
},
|
||||
}
|
||||
if params.Get("security") == "tls" {
|
||||
@ -65,10 +67,12 @@ func ParseVless(proxy string) (model2.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
result.VLESS.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ALPN: alpn,
|
||||
Insecure: params.Get("allowInsecure") == "1",
|
||||
result.VLESSOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ALPN: alpn,
|
||||
Insecure: params.Get("allowInsecure") == "1",
|
||||
},
|
||||
}
|
||||
}
|
||||
if params.Get("security") == "reality" {
|
||||
@ -78,45 +82,49 @@ func ParseVless(proxy string) (model2.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
result.VLESS.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ServerName: params.Get("sni"),
|
||||
UTLS: &model2.OutboundUTLSOptions{
|
||||
Enabled: params.Get("fp") != "",
|
||||
Fingerprint: params.Get("fp"),
|
||||
result.VLESSOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
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: alpn,
|
||||
},
|
||||
Reality: &model2.OutboundRealityOptions{
|
||||
Enabled: true,
|
||||
PublicKey: params.Get("pbk"),
|
||||
ShortID: params.Get("sid"),
|
||||
},
|
||||
ALPN: alpn,
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "ws" {
|
||||
result.VLESS.Transport = &model2.V2RayTransportOptions{
|
||||
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "ws",
|
||||
WebsocketOptions: model2.V2RayWebsocketOptions{
|
||||
WebsocketOptions: model.V2RayWebsocketOptions{
|
||||
Path: params.Get("path"),
|
||||
Headers: map[string]string{
|
||||
"Host": params.Get("host"),
|
||||
},
|
||||
},
|
||||
}
|
||||
if params.Get("host") != "" {
|
||||
result.VLESSOptions.Transport.WebsocketOptions.Headers["Host"] = params.Get("host")
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "quic" {
|
||||
result.VLESS.Transport = &model2.V2RayTransportOptions{
|
||||
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "quic",
|
||||
QUICOptions: model2.V2RayQUICOptions{},
|
||||
QUICOptions: model.V2RayQUICOptions{},
|
||||
}
|
||||
result.VLESS.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
result.VLESSOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
if params.Get("type") == "grpc" {
|
||||
result.VLESS.Transport = &model2.V2RayTransportOptions{
|
||||
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "grpc",
|
||||
GRPCOptions: model2.V2RayGRPCOptions{
|
||||
GRPCOptions: model.V2RayGRPCOptions{
|
||||
ServiceName: params.Get("serviceName"),
|
||||
},
|
||||
}
|
||||
@ -124,11 +132,11 @@ func ParseVless(proxy string) (model2.Proxy, error) {
|
||||
if params.Get("type") == "http" {
|
||||
host, err := url.QueryUnescape(params.Get("host"))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, err
|
||||
return model.Outbound{}, err
|
||||
}
|
||||
result.VLESS.Transport = &model2.V2RayTransportOptions{
|
||||
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "http",
|
||||
HTTPOptions: model2.V2RayHTTPOptions{
|
||||
HTTPOptions: model.V2RayHTTPOptions{
|
||||
Host: strings.Split(host, ","),
|
||||
},
|
||||
}
|
||||
|
@ -6,29 +6,29 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
"sub2sing-box/util"
|
||||
)
|
||||
|
||||
func ParseVmess(proxy string) (model2.Proxy, error) {
|
||||
func ParseVmess(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "vmess://") {
|
||||
return model2.Proxy{}, errors.New("invalid vmess url")
|
||||
return model.Outbound{}, errors.New("invalid vmess url")
|
||||
}
|
||||
base64, err := util.DecodeBase64(strings.TrimPrefix(proxy, "vmess://"))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid vmess url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid vmess url" + err.Error())
|
||||
}
|
||||
var vmess model2.VmessJson
|
||||
var vmess model.VmessJson
|
||||
err = json.Unmarshal([]byte(base64), &vmess)
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid vmess url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid vmess url" + err.Error())
|
||||
}
|
||||
port := 0
|
||||
switch vmess.Port.(type) {
|
||||
case string:
|
||||
port, err = strconv.Atoi(vmess.Port.(string))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid vmess url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid vmess url" + err.Error())
|
||||
}
|
||||
case float64:
|
||||
port = int(vmess.Port.(float64))
|
||||
@ -38,7 +38,7 @@ func ParseVmess(proxy string) (model2.Proxy, error) {
|
||||
case string:
|
||||
aid, err = strconv.Atoi(vmess.Aid.(string))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid vmess url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid vmess url" + err.Error())
|
||||
}
|
||||
case float64:
|
||||
aid = int(vmess.Aid.(float64))
|
||||
@ -52,15 +52,17 @@ func ParseVmess(proxy string) (model2.Proxy, error) {
|
||||
name = vmess.Ps
|
||||
}
|
||||
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "vmess",
|
||||
Tag: name,
|
||||
VMess: model2.VMess{
|
||||
Server: vmess.Add,
|
||||
ServerPort: uint16(port),
|
||||
UUID: vmess.Id,
|
||||
AlterId: aid,
|
||||
Security: vmess.Scy,
|
||||
VMessOptions: model.VMessOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: vmess.Add,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
UUID: vmess.Id,
|
||||
AlterId: aid,
|
||||
Security: vmess.Scy,
|
||||
},
|
||||
}
|
||||
|
||||
@ -71,12 +73,14 @@ func ParseVmess(proxy string) (model2.Proxy, error) {
|
||||
} else {
|
||||
alpn = nil
|
||||
}
|
||||
result.VMess.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
UTLS: &model2.OutboundUTLSOptions{
|
||||
Fingerprint: vmess.Fp,
|
||||
result.VMessOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
UTLS: &model.OutboundUTLSOptions{
|
||||
Fingerprint: vmess.Fp,
|
||||
},
|
||||
ALPN: alpn,
|
||||
},
|
||||
ALPN: alpn,
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,46 +91,47 @@ func ParseVmess(proxy string) (model2.Proxy, error) {
|
||||
if vmess.Host == "" {
|
||||
vmess.Host = vmess.Add
|
||||
}
|
||||
ws := model2.V2RayWebsocketOptions{
|
||||
Path: vmess.Path,
|
||||
Headers: map[string]string{
|
||||
"Host": vmess.Host,
|
||||
result.VMessOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "ws",
|
||||
WebsocketOptions: model.V2RayWebsocketOptions{
|
||||
Path: vmess.Path,
|
||||
Headers: map[string]string{
|
||||
"Host": vmess.Host,
|
||||
},
|
||||
},
|
||||
}
|
||||
result.VMess.Transport = &model2.V2RayTransportOptions{
|
||||
Type: "ws",
|
||||
WebsocketOptions: ws,
|
||||
}
|
||||
}
|
||||
|
||||
if vmess.Net == "quic" {
|
||||
quic := model2.V2RayQUICOptions{}
|
||||
result.VMess.Transport = &model2.V2RayTransportOptions{
|
||||
quic := model.V2RayQUICOptions{}
|
||||
result.VMessOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "quic",
|
||||
QUICOptions: quic,
|
||||
}
|
||||
result.VMess.TLS = &model2.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
result.VMessOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
|
||||
TLS: &model.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if vmess.Net == "grpc" {
|
||||
grpc := model2.V2RayGRPCOptions{
|
||||
grpc := model.V2RayGRPCOptions{
|
||||
ServiceName: vmess.Path,
|
||||
PermitWithoutStream: true,
|
||||
}
|
||||
result.VMess.Transport = &model2.V2RayTransportOptions{
|
||||
result.VMessOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "grpc",
|
||||
GRPCOptions: grpc,
|
||||
}
|
||||
}
|
||||
|
||||
if vmess.Net == "h2" {
|
||||
httpOps := model2.V2RayHTTPOptions{
|
||||
httpOps := model.V2RayHTTPOptions{
|
||||
Host: strings.Split(vmess.Host, ","),
|
||||
Path: vmess.Path,
|
||||
}
|
||||
result.VMess.Transport = &model2.V2RayTransportOptions{
|
||||
result.VMessOptions.Transport = &model.V2RayTransportOptions{
|
||||
Type: "http",
|
||||
HTTPOptions: httpOps,
|
||||
}
|
||||
|
Reference in New Issue
Block a user