support http,socks,mixed links
This commit is contained in:
+28
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var InboundTypeWithLink = []string{"shadowsocks", "naive", "hysteria", "hysteria2", "anytls", "tuic", "vless", "trojan", "vmess"}
|
var InboundTypeWithLink = []string{"socks", "http", "mixed", "shadowsocks", "naive", "hysteria", "hysteria2", "anytls", "tuic", "vless", "trojan", "vmess"}
|
||||||
|
|
||||||
func LinkGenerator(clientConfig json.RawMessage, i *model.Inbound, hostname string) []string {
|
func LinkGenerator(clientConfig json.RawMessage, i *model.Inbound, hostname string) []string {
|
||||||
inbound, err := i.MarshalFull()
|
inbound, err := i.MarshalFull()
|
||||||
@@ -61,6 +61,13 @@ func LinkGenerator(clientConfig json.RawMessage, i *model.Inbound, hostname stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch i.Type {
|
switch i.Type {
|
||||||
|
case "socks":
|
||||||
|
return socksLink(userConfig["socks"], *inbound, Addrs)
|
||||||
|
case "http":
|
||||||
|
return httpLink(userConfig["http"], *inbound, Addrs)
|
||||||
|
case "mixed":
|
||||||
|
return append(
|
||||||
|
socksLink(userConfig["socks"], *inbound, Addrs), httpLink(userConfig["http"], *inbound, Addrs)...)
|
||||||
case "shadowsocks":
|
case "shadowsocks":
|
||||||
return shadowsocksLink(userConfig, *inbound, Addrs)
|
return shadowsocksLink(userConfig, *inbound, Addrs)
|
||||||
case "naive":
|
case "naive":
|
||||||
@@ -106,6 +113,26 @@ func prepareTls(t *model.Tls) map[string]interface{} {
|
|||||||
return oTls
|
return oTls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func socksLink(userConfig map[string]interface{}, inbound map[string]interface{}, addrs []map[string]interface{}) []string {
|
||||||
|
var links []string
|
||||||
|
for _, addr := range addrs {
|
||||||
|
links = append(links, fmt.Sprintf("socks5://%s:%s@%s:%d", userConfig["username"], userConfig["password"], addr["server"].(string), uint(addr["server_port"].(float64))))
|
||||||
|
}
|
||||||
|
return links
|
||||||
|
}
|
||||||
|
|
||||||
|
func httpLink(userConfig map[string]interface{}, inbound map[string]interface{}, addrs []map[string]interface{}) []string {
|
||||||
|
var links []string
|
||||||
|
var protocol string = "http"
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if addr["tls"] != nil {
|
||||||
|
protocol = "https"
|
||||||
|
}
|
||||||
|
links = append(links, fmt.Sprintf("%s://%s:%s@%s:%d", protocol, userConfig["username"], userConfig["password"], addr["server"].(string), uint(addr["server_port"].(float64))))
|
||||||
|
}
|
||||||
|
return links
|
||||||
|
}
|
||||||
|
|
||||||
func shadowsocksLink(
|
func shadowsocksLink(
|
||||||
userConfig map[string]map[string]interface{},
|
userConfig map[string]map[string]interface{},
|
||||||
inbound map[string]interface{},
|
inbound map[string]interface{},
|
||||||
|
|||||||
@@ -481,6 +481,7 @@ func getTls(security string, q *url.Values) *map[string]interface{} {
|
|||||||
tls_sni := q.Get("sni")
|
tls_sni := q.Get("sni")
|
||||||
tls_insecure := q.Get("allowInsecure")
|
tls_insecure := q.Get("allowInsecure")
|
||||||
tls_alpn := q.Get("alpn")
|
tls_alpn := q.Get("alpn")
|
||||||
|
tls_ech := q.Get("ech")
|
||||||
switch security {
|
switch security {
|
||||||
case "tls":
|
case "tls":
|
||||||
tls["enabled"] = true
|
tls["enabled"] = true
|
||||||
@@ -507,5 +508,13 @@ func getTls(security string, q *url.Values) *map[string]interface{} {
|
|||||||
"fingerprint": tls_fp,
|
"fingerprint": tls_fp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(tls_ech) > 0 {
|
||||||
|
tls["ech"] = map[string]interface{}{
|
||||||
|
"enabled": true,
|
||||||
|
"config": []string{
|
||||||
|
tls_ech,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
return &tls
|
return &tls
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user