Skip to content

Commit

Permalink
new: add basic socks, http, and https proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 9, 2024
1 parent 2d6d49a commit 0b78d4f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var examples = map[string][]string{
"wg://server.com:5319?publicKey=verypublicKeyss&privateKey=veryprivatekey&presharedKey=verysharedkey&ip=10.0.0.1&mtu=1380&keepalive=30&udp=1&reserved=0,0,0&ifp=5-10#direct%20WireGuard",
},
"warp": {
"#profile-title: Hiddify WARP\nwarp://p2@auto#Remote&&detour=warp://p1@auto#Local",
"warp://key@host:1234/#WARPkey",
"warp://engage.cloudflareclient.com:2408#WARPnoKey",
"warp://[email protected]:2408/?ifp=5-10#WARPparam",
Expand All @@ -58,6 +59,13 @@ var examples = map[string][]string{
"warp://auto&&detour=warp://auto",
"vless://[email protected]:2053?encryption=none&flow=&fp=chrome&pbk=SbVKOEMjK0sIlbwg4akyBg5mL5KZwwB-ed4eEE7YnRc&security=reality&serviceName=xyz&sid=&sni=discordapp.com&type=grpc#رایگان | REALITY | @EliV2ray | FR🇫🇷 | 0️⃣1️⃣&&detour=tuic://3618921b-adeb-4bd3-a2a0-f98b72a674b1:[email protected]:23450?allow_insecure=1&alpn=h3&congestion_control=bbr&sni=www.google.com&udp_relay_mode=native#رایگان | TUIC | @V2rayCollector | CA🇨🇦 | 0️⃣1️⃣",
},
"socks": {
"socks://a:b@c:80?v=4",
},
"http": {
"phttp://a:b@c:80/?path=ssss",
"phttps://a:b@c:80/?path=ssss&sni=d&insecure=1",
},
"direct": {
"direct://?fgsize=10-100&fgsleep=100-200",
},
Expand Down
5 changes: 5 additions & 0 deletions ray2sing/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var configTypes = map[string]ParserFunc{
"ssconf://": BeepassSingbox,
"warp://": WarpSingbox,
"direct://": DirectSingbox,
"socks://": SocksSingbox,
"phttp://": HttpSingbox,
"phttps://": HttpsSingbox,
"http://": HttpSingbox,
"https://": HttpsSingbox,
}

func processSingleConfig(config string) (outbound *T.Outbound, err error) {
Expand Down
76 changes: 76 additions & 0 deletions ray2sing/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ray2sing

import (
C "github.com/sagernet/sing-box/constant"
T "github.com/sagernet/sing-box/option"
)

func HttpSingbox(url string) (*T.Outbound, error) {
u, err := ParseUrl(url, 0)
if err != nil {
return nil, err
}

out := &T.Outbound{
Type: C.TypeHTTP,
Tag: u.Name,
HTTPOptions: T.HTTPOutboundOptions{
ServerOptions: u.GetServerOption(),
Username: u.Username,
Password: u.Password,
},
}
if _, err := getOneOf(u.Params, "tls", "sni", "insecure"); err == nil {
out.HTTPOptions.OutboundTLSOptionsContainer.TLS = &T.OutboundTLSOptions{
Enabled: true,
}
}
if sni, err := getOneOf(u.Params, "sni"); err == nil {
out.HTTPOptions.OutboundTLSOptionsContainer.TLS.ServerName = sni
}
if insecure, err := getOneOf(u.Params, "insecure"); err == nil {
out.HTTPOptions.OutboundTLSOptionsContainer.TLS.Insecure = insecure != "0"
}
if path, err := getOneOf(u.Params, "path"); err == nil {
out.HTTPOptions.Path = path
}
// if net, err := getOneOf(u.Params, "net", "network"); err == nil {
// out.SocksOptions.Network= net
// }
return out, nil
}

func HttpsSingbox(url string) (*T.Outbound, error) {
u, err := ParseUrl(url, 0)
if err != nil {
return nil, err
}

out := &T.Outbound{
Type: C.TypeHTTP,
Tag: u.Name,
HTTPOptions: T.HTTPOutboundOptions{
ServerOptions: u.GetServerOption(),
Username: u.Username,
Password: u.Password,
},
}
out.HTTPOptions.OutboundTLSOptionsContainer.TLS = &T.OutboundTLSOptions{
Enabled: true,
}
if sni, err := getOneOf(u.Params, "sni"); err == nil {
out.HTTPOptions.OutboundTLSOptionsContainer.TLS.ServerName = sni
}
if insecure, err := getOneOf(u.Params, "insecure"); err == nil {
out.HTTPOptions.OutboundTLSOptionsContainer.TLS.Insecure = insecure != "0"
}

if path, err := getOneOf(u.Params, "path"); err == nil {
out.HTTPOptions.Path = path
}

// if net, err := getOneOf(u.Params, "net", "network"); err == nil {
// out.SocksOptions.Network= net
// }
return out, nil
}
30 changes: 30 additions & 0 deletions ray2sing/socks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ray2sing

import (
C "github.com/sagernet/sing-box/constant"
T "github.com/sagernet/sing-box/option"
)

func SocksSingbox(url string) (*T.Outbound, error) {
u, err := ParseUrl(url, 0)
if err != nil {
return nil, err
}

out := &T.Outbound{
Type: C.TypeSOCKS,
Tag: u.Name,
SocksOptions: T.SocksOutboundOptions{
ServerOptions: u.GetServerOption(),
Username: u.Username,
Password: u.Password,
},
}
if version, err := getOneOf(u.Params, "v", "ver", "version"); err == nil {
out.SocksOptions.Version = version
}
// if net, err := getOneOf(u.Params, "net", "network"); err == nil {
// out.SocksOptions.Network= net
// }
return out, nil
}

0 comments on commit 0b78d4f

Please sign in to comment.