Skip to content

Commit 617fef8

Browse files
authored
feat: converter support anytls/socks/http (#2100)
1 parent d191993 commit 617fef8

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

common/convert/converter.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,95 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
513513
}
514514

515515
proxies = append(proxies, ssr)
516+
517+
case "socks", "socks5", "socks5h", "http", "https":
518+
link, err := url.Parse(line)
519+
if err != nil {
520+
continue
521+
}
522+
server := link.Hostname()
523+
if server == "" {
524+
continue
525+
}
526+
portStr := link.Port()
527+
if portStr == "" {
528+
continue
529+
}
530+
remarks := link.Fragment
531+
if remarks == "" {
532+
remarks = fmt.Sprintf("%s:%s", server, portStr)
533+
}
534+
name := uniqueName(names, remarks)
535+
encodeStr := link.User.String()
536+
var username, password string
537+
if encodeStr != "" {
538+
decodeStr := string(DecodeBase64([]byte(encodeStr)))
539+
splitStr := strings.Split(decodeStr, ":")
540+
541+
// todo: should use url.QueryUnescape ?
542+
username = splitStr[0]
543+
if len(splitStr) == 2 {
544+
password = splitStr[1]
545+
}
546+
}
547+
socks := make(map[string]any, 10)
548+
socks["name"] = name
549+
socks["type"] = func() string {
550+
switch scheme {
551+
case "socks", "socks5", "socks5h":
552+
return "socks5"
553+
case "http", "https":
554+
return "http"
555+
}
556+
return scheme
557+
}()
558+
socks["server"] = server
559+
socks["port"] = portStr
560+
socks["username"] = username
561+
socks["password"] = password
562+
socks["skip-cert-verify"] = true
563+
564+
proxies = append(proxies, socks)
565+
566+
case "anytls":
567+
// https://github.com/anytls/anytls-go/blob/main/docs/uri_scheme.md
568+
link, err := url.Parse(line)
569+
if err != nil {
570+
continue
571+
}
572+
username := link.User.Username()
573+
password, exist := link.User.Password()
574+
if !exist {
575+
password = username
576+
}
577+
query := link.Query()
578+
server := link.Hostname()
579+
if server == "" {
580+
continue
581+
}
582+
portStr := link.Port()
583+
if portStr == "" {
584+
continue
585+
}
586+
insecure, sni := query.Get("insecure"), query.Get("sni")
587+
insecureBool := insecure == "1"
588+
remarks := link.Fragment
589+
if remarks == "" {
590+
remarks = fmt.Sprintf("%s:%s", server, portStr)
591+
}
592+
name := uniqueName(names, remarks)
593+
anytls := make(map[string]any, 10)
594+
anytls["name"] = name
595+
anytls["type"] = "anytls"
596+
anytls["server"] = server
597+
anytls["port"] = portStr
598+
anytls["username"] = username
599+
anytls["password"] = password
600+
anytls["sni"] = sni
601+
anytls["skip-cert-verify"] = insecureBool
602+
anytls["udp"] = true
603+
604+
proxies = append(proxies, anytls)
516605
}
517606
}
518607

0 commit comments

Comments
 (0)