fix: Converter for vless/vmess/ss URI Scheme
This commit is contained in:
parent
b658bb415b
commit
5141ddc96e
1 changed files with 72 additions and 54 deletions
|
@ -148,7 +148,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
vless["uuid"] = urlVless.User.Username()
|
vless["uuid"] = urlVless.User.Username()
|
||||||
vless["udp"] = true
|
vless["udp"] = true
|
||||||
vless["skip-cert-verify"] = false
|
vless["skip-cert-verify"] = false
|
||||||
|
vless["tls"] = false
|
||||||
|
tls := strings.ToLower(query.Get("security"))
|
||||||
|
if strings.Contains(tls, "tls") {
|
||||||
|
vless["tls"] = true
|
||||||
|
}
|
||||||
sni := query.Get("sni")
|
sni := query.Get("sni")
|
||||||
if sni != "" {
|
if sni != "" {
|
||||||
vless["servername"] = sni
|
vless["servername"] = sni
|
||||||
|
@ -160,50 +164,54 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
network := strings.ToLower(query.Get("type"))
|
network := strings.ToLower(query.Get("type"))
|
||||||
if network != "" {
|
|
||||||
fakeType := strings.ToLower(query.Get("headerType"))
|
fakeType := strings.ToLower(query.Get("headerType"))
|
||||||
if network == "tcp" && fakeType == "http" {
|
if fakeType == "http" {
|
||||||
network = "http"
|
network = "http"
|
||||||
}
|
} else if network == "http" {
|
||||||
if network == "http" {
|
|
||||||
network = "h2"
|
network = "h2"
|
||||||
}
|
}
|
||||||
vless["network"] = network
|
vless["network"] = network
|
||||||
}
|
|
||||||
|
|
||||||
switch network {
|
switch network {
|
||||||
case "http":
|
case "tcp":
|
||||||
|
if fakeType != "none" {
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
httpOpts := make(map[string]any)
|
httpOpts := make(map[string]any)
|
||||||
|
httpOpts["path"] = []string{"/"}
|
||||||
|
|
||||||
|
if query.Get("host") != "" {
|
||||||
|
headers["Host"] = []string{query.Get("host")}
|
||||||
|
}
|
||||||
|
|
||||||
if query.Get("method") != "" {
|
if query.Get("method") != "" {
|
||||||
httpOpts["method"] = query.Get("method")
|
httpOpts["method"] = query.Get("method")
|
||||||
}
|
}
|
||||||
|
|
||||||
if query.Get("path") != "" {
|
if query.Get("path") != "" {
|
||||||
httpOpts["path"] = query.Get("path")
|
httpOpts["path"] = []string{query.Get("path")}
|
||||||
}
|
}
|
||||||
headers["User-Agent"] = RandUserAgent()
|
|
||||||
httpOpts["headers"] = headers
|
httpOpts["headers"] = headers
|
||||||
|
|
||||||
vless["http-opts"] = httpOpts
|
vless["http-opts"] = httpOpts
|
||||||
|
}
|
||||||
|
|
||||||
case "h2":
|
case "http":
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
h2Opts := make(map[string]any)
|
h2Opts := make(map[string]any)
|
||||||
|
h2Opts["path"] = []string{"/"}
|
||||||
headers["User-Agent"] = RandUserAgent()
|
if query.Get("path") != "" {
|
||||||
h2Opts["path"] = query.Get("path")
|
h2Opts["path"] = []string{query.Get("path")}
|
||||||
|
}
|
||||||
|
if query.Get("host") != "" {
|
||||||
|
h2Opts["host"] = []string{query.Get("host")}
|
||||||
|
}
|
||||||
h2Opts["headers"] = headers
|
h2Opts["headers"] = headers
|
||||||
|
|
||||||
vless["h2-opts"] = h2Opts
|
vless["h2-opts"] = h2Opts
|
||||||
|
|
||||||
case "ws":
|
case "ws":
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
wsOpts := make(map[string]any)
|
wsOpts := make(map[string]any)
|
||||||
|
|
||||||
//headers["Host"] = RandHost()
|
headers["Host"] = []string{query.Get("host")}
|
||||||
headers["User-Agent"] = RandUserAgent()
|
wsOpts["path"] = []string{query.Get("path")}
|
||||||
wsOpts["path"] = query.Get("path")
|
|
||||||
wsOpts["headers"] = headers
|
wsOpts["headers"] = headers
|
||||||
|
|
||||||
vless["ws-opts"] = wsOpts
|
vless["ws-opts"] = wsOpts
|
||||||
|
@ -240,6 +248,7 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
vmess["alterId"] = values["aid"]
|
vmess["alterId"] = values["aid"]
|
||||||
vmess["cipher"] = "auto"
|
vmess["cipher"] = "auto"
|
||||||
vmess["udp"] = true
|
vmess["udp"] = true
|
||||||
|
vmess["tls"] = false
|
||||||
vmess["skip-cert-verify"] = false
|
vmess["skip-cert-verify"] = false
|
||||||
|
|
||||||
if values["cipher"] != nil && values["cipher"] != "" {
|
if values["cipher"] != nil && values["cipher"] != "" {
|
||||||
|
@ -251,16 +260,16 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
vmess["servername"] = sni
|
vmess["servername"] = sni
|
||||||
}
|
}
|
||||||
|
|
||||||
host := values["host"]
|
|
||||||
network := strings.ToLower(values["net"].(string))
|
network := strings.ToLower(values["net"].(string))
|
||||||
|
if values["type"] == "http" {
|
||||||
|
network = "http"
|
||||||
|
} else if network == "http" {
|
||||||
|
network = "h2"
|
||||||
|
}
|
||||||
vmess["network"] = network
|
vmess["network"] = network
|
||||||
|
|
||||||
tls := strings.ToLower(values["tls"].(string))
|
tls := strings.ToLower(values["tls"].(string))
|
||||||
if tls != "" && tls != "0" && tls != "null" {
|
if strings.Contains(tls, "tls") {
|
||||||
if host != "" || host != nil {
|
|
||||||
vmess["servername"] = host
|
|
||||||
}
|
|
||||||
vmess["tls"] = true
|
vmess["tls"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,11 +277,13 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
case "http":
|
case "http":
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
httpOpts := make(map[string]any)
|
httpOpts := make(map[string]any)
|
||||||
|
if values["host"] != "" && values["host"] != nil {
|
||||||
headers["Host"] = RandHost()
|
headers["Host"] = []string{values["host"].(string)}
|
||||||
headers["User-Agent"] = RandUserAgent()
|
}
|
||||||
httpOpts["method"] = values["method"]
|
httpOpts["path"] = []string{"/"}
|
||||||
httpOpts["path"] = values["path"]
|
if values["path"] != "" && values["path"] != nil {
|
||||||
|
httpOpts["path"] = []string{values["path"].(string)}
|
||||||
|
}
|
||||||
httpOpts["headers"] = headers
|
httpOpts["headers"] = headers
|
||||||
|
|
||||||
vmess["http-opts"] = httpOpts
|
vmess["http-opts"] = httpOpts
|
||||||
|
@ -280,9 +291,10 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
case "h2":
|
case "h2":
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
h2Opts := make(map[string]any)
|
h2Opts := make(map[string]any)
|
||||||
|
if values["host"] != "" && values["host"] != nil {
|
||||||
|
headers["Host"] = []string{values["host"].(string)}
|
||||||
|
}
|
||||||
|
|
||||||
//headers["Host"] = RandHost()
|
|
||||||
headers["User-Agent"] = RandUserAgent()
|
|
||||||
h2Opts["path"] = values["path"]
|
h2Opts["path"] = values["path"]
|
||||||
h2Opts["headers"] = headers
|
h2Opts["headers"] = headers
|
||||||
|
|
||||||
|
@ -291,16 +303,14 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
case "ws":
|
case "ws":
|
||||||
headers := make(map[string]any)
|
headers := make(map[string]any)
|
||||||
wsOpts := make(map[string]any)
|
wsOpts := make(map[string]any)
|
||||||
if host != "" && host != nil {
|
wsOpts["path"] = []string{"/"}
|
||||||
headers["Host"] = host
|
if values["host"] != "" && values["host"] != nil {
|
||||||
|
headers["Host"] = []string{values["host"].(string)}
|
||||||
}
|
}
|
||||||
headers["User-Agent"] = RandUserAgent()
|
if values["path"] != "" && values["path"] != nil {
|
||||||
|
wsOpts["path"] = []string{values["path"].(string)}
|
||||||
if values["path"] != nil || values["path"] != "" {
|
|
||||||
wsOpts["path"] = values["path"]
|
|
||||||
}
|
}
|
||||||
wsOpts["headers"] = headers
|
wsOpts["headers"] = headers
|
||||||
|
|
||||||
vmess["ws-opts"] = wsOpts
|
vmess["ws-opts"] = wsOpts
|
||||||
|
|
||||||
case "grpc":
|
case "grpc":
|
||||||
|
@ -356,8 +366,16 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
ss["port"] = urlSS.Port()
|
ss["port"] = urlSS.Port()
|
||||||
ss["cipher"] = cipher
|
ss["cipher"] = cipher
|
||||||
ss["password"] = password
|
ss["password"] = password
|
||||||
|
query := urlSS.Query()
|
||||||
ss["udp"] = true
|
ss["udp"] = true
|
||||||
|
if strings.Contains(query.Get("plugin"), "obfs") {
|
||||||
|
obfsParams := strings.Split(query.Get("plugin"), ";")
|
||||||
|
ss["plugin"] = "obfs"
|
||||||
|
ss["plugin-opts"] = map[string]any{
|
||||||
|
"host": obfsParams[2][10:],
|
||||||
|
"mode": obfsParams[1][5:],
|
||||||
|
}
|
||||||
|
}
|
||||||
proxies = append(proxies, ss)
|
proxies = append(proxies, ss)
|
||||||
case "ssr":
|
case "ssr":
|
||||||
dcBuf, err := encRaw.DecodeString(body)
|
dcBuf, err := encRaw.DecodeString(body)
|
||||||
|
|
Loading…
Reference in a new issue