improve converting link to json
This commit is contained in:
+31
-54
@@ -200,17 +200,9 @@ func hy(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
port, _ = strconv.Atoi(portStr)
|
||||
}
|
||||
|
||||
tls := map[string]interface{}{
|
||||
"enabled": true,
|
||||
"server_name": query.Get("peer"),
|
||||
}
|
||||
alpn := query.Get("alpn")
|
||||
insecure := query.Get("insecure")
|
||||
if len(alpn) > 0 {
|
||||
tls["alpn"] = strings.Split(alpn, ",")
|
||||
}
|
||||
if insecure == "1" || insecure == "true" {
|
||||
tls["insecure"] = true
|
||||
security := query.Get("security")
|
||||
if len(security) == 0 {
|
||||
security = "tls"
|
||||
}
|
||||
|
||||
tag := u.Fragment
|
||||
@@ -224,7 +216,7 @@ func hy(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
"server_port": port,
|
||||
"obfs": query.Get("obfsParam"),
|
||||
"auth_str": query.Get("auth"),
|
||||
"tls": tls,
|
||||
"tls": getTls(security, &query),
|
||||
}
|
||||
down, _ := strconv.Atoi(query.Get("downmbps"))
|
||||
up, _ := strconv.Atoi(query.Get("upmbps"))
|
||||
@@ -253,17 +245,9 @@ func hy2(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
port, _ = strconv.Atoi(portStr)
|
||||
}
|
||||
|
||||
tls := map[string]interface{}{
|
||||
"enabled": true,
|
||||
"server_name": query.Get("sni"),
|
||||
}
|
||||
alpn := query.Get("alpn")
|
||||
insecure := query.Get("insecure")
|
||||
if len(alpn) > 0 {
|
||||
tls["alpn"] = strings.Split(alpn, ",")
|
||||
}
|
||||
if insecure == "1" || insecure == "true" {
|
||||
tls["insecure"] = true
|
||||
security := query.Get("security")
|
||||
if len(security) == 0 {
|
||||
security = "tls"
|
||||
}
|
||||
|
||||
tag := u.Fragment
|
||||
@@ -276,11 +260,13 @@ func hy2(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
"server": host,
|
||||
"server_port": port,
|
||||
"password": u.User.Username(),
|
||||
"tls": tls,
|
||||
"tls": getTls(security, &query),
|
||||
}
|
||||
down, _ := strconv.Atoi(query.Get("downmbps"))
|
||||
up, _ := strconv.Atoi(query.Get("upmbps"))
|
||||
obfs := query.Get("obfs")
|
||||
mport := query.Get("mport")
|
||||
fastopen := query.Get("fastopen")
|
||||
if down > 0 {
|
||||
hy2["down_mbps"] = down
|
||||
}
|
||||
@@ -293,6 +279,12 @@ func hy2(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
"password": query.Get("obfs-password"),
|
||||
}
|
||||
}
|
||||
if len(mport) > 0 {
|
||||
hy2["server_ports"] = strings.Split(mport, ",")
|
||||
}
|
||||
if fastopen == "1" || fastopen == "true" {
|
||||
hy2["fastopen"] = true
|
||||
}
|
||||
return &hy2, tag, nil
|
||||
}
|
||||
|
||||
@@ -304,17 +296,9 @@ func anytls(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
port, _ = strconv.Atoi(portStr)
|
||||
}
|
||||
|
||||
tls := map[string]interface{}{
|
||||
"enabled": true,
|
||||
"server_name": query.Get("sni"),
|
||||
}
|
||||
alpn := query.Get("alpn")
|
||||
insecure := query.Get("insecure")
|
||||
if len(alpn) > 0 {
|
||||
tls["alpn"] = strings.Split(alpn, ",")
|
||||
}
|
||||
if insecure == "1" || insecure == "true" {
|
||||
tls["insecure"] = true
|
||||
security := query.Get("security")
|
||||
if len(security) == 0 {
|
||||
security = "tls"
|
||||
}
|
||||
|
||||
tag := u.Fragment
|
||||
@@ -327,7 +311,7 @@ func anytls(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
"server": host,
|
||||
"server_port": port,
|
||||
"password": u.User.Username(),
|
||||
"tls": tls,
|
||||
"tls": getTls(security, &query),
|
||||
}
|
||||
return &anytls, tag, nil
|
||||
}
|
||||
@@ -340,21 +324,9 @@ func tuic(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
port, _ = strconv.Atoi(portStr)
|
||||
}
|
||||
|
||||
tls := map[string]interface{}{
|
||||
"enabled": true,
|
||||
"server_name": query.Get("sni"),
|
||||
}
|
||||
alpn := query.Get("alpn")
|
||||
insecure := query.Get("allow_insecure")
|
||||
disable_sni := query.Get("disable_sni")
|
||||
if len(alpn) > 0 {
|
||||
tls["alpn"] = strings.Split(alpn, ",")
|
||||
}
|
||||
if insecure == "1" || insecure == "true" {
|
||||
tls["insecure"] = true
|
||||
}
|
||||
if disable_sni == "1" || disable_sni == "true" {
|
||||
tls["disable_sni"] = true
|
||||
security := query.Get("security")
|
||||
if len(security) == 0 {
|
||||
security = "tls"
|
||||
}
|
||||
|
||||
tag := u.Fragment
|
||||
@@ -371,7 +343,7 @@ func tuic(u *url.URL, i int) (*map[string]interface{}, string, error) {
|
||||
"password": password,
|
||||
"congestion_control": query.Get("congestion_control"),
|
||||
"udp_relay_mode": query.Get("udp_relay_mode"),
|
||||
"tls": tls,
|
||||
"tls": getTls(security, &query),
|
||||
}
|
||||
return &tuic, tag, nil
|
||||
}
|
||||
@@ -480,9 +452,11 @@ func getTls(security string, q *url.Values) map[string]interface{} {
|
||||
tls := map[string]interface{}{}
|
||||
tls_fp := q.Get("fp")
|
||||
tls_sni := q.Get("sni")
|
||||
tls_insecure := q.Get("allowInsecure")
|
||||
tls_allow_insecure := q.Get("allowInsecure")
|
||||
tls_insecure := q.Get("insecure")
|
||||
tls_alpn := q.Get("alpn")
|
||||
tls_ech := q.Get("ech")
|
||||
disable_sni := q.Get("disable_sni")
|
||||
switch security {
|
||||
case "tls":
|
||||
tls["enabled"] = true
|
||||
@@ -500,7 +474,7 @@ func getTls(security string, q *url.Values) map[string]interface{} {
|
||||
if len(tls_alpn) > 0 {
|
||||
tls["alpn"] = strings.Split(tls_alpn, ",")
|
||||
}
|
||||
if tls_insecure == "1" || tls_insecure == "true" {
|
||||
if tls_insecure == "1" || tls_insecure == "true" || tls_allow_insecure == "1" || tls_allow_insecure == "true" {
|
||||
tls["insecure"] = true
|
||||
}
|
||||
if len(tls_fp) > 0 {
|
||||
@@ -517,5 +491,8 @@ func getTls(security string, q *url.Values) map[string]interface{} {
|
||||
},
|
||||
}
|
||||
}
|
||||
if disable_sni == "1" || disable_sni == "true" {
|
||||
tls["disable_sni"] = true
|
||||
}
|
||||
return tls
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user