From 85d42ee91ccd3046732862a41defdb79d85dbda8 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 13 Feb 2026 21:49:43 +0100 Subject: [PATCH] improve converting link to json --- util/linkToJson.go | 85 +++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 54 deletions(-) diff --git a/util/linkToJson.go b/util/linkToJson.go index 654c1d9..448da3d 100644 --- a/util/linkToJson.go +++ b/util/linkToJson.go @@ -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 }