mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-02 23:15:00 +08:00
feat: 添加 Anytls 代理支持
This commit is contained in:
parent
db00433931
commit
06887d91ac
@ -18,6 +18,7 @@
|
|||||||
- Hysteria (Clash.Meta)
|
- Hysteria (Clash.Meta)
|
||||||
- Hysteria2 (Clash.Meta)
|
- Hysteria2 (Clash.Meta)
|
||||||
- Socks5
|
- Socks5
|
||||||
|
- Anytls (Clash.Meta)
|
||||||
|
|
||||||
## 使用
|
## 使用
|
||||||
|
|
||||||
|
@ -130,6 +130,9 @@ func ParseProxy(proxies ...string) []model.Proxy {
|
|||||||
if strings.HasPrefix(proxy, constant.SocksPrefix) {
|
if strings.HasPrefix(proxy, constant.SocksPrefix) {
|
||||||
proxyItem, err = parser.ParseSocks(proxy)
|
proxyItem, err = parser.ParseSocks(proxy)
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(proxy, constant.AnytlsPrefix) {
|
||||||
|
proxyItem, err = parser.ParseAnytls(proxy)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result = append(result, proxyItem)
|
result = append(result, proxyItem)
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,4 +10,5 @@ const (
|
|||||||
VLESSPrefix string = "vless://"
|
VLESSPrefix string = "vless://"
|
||||||
VMessPrefix string = "vmess://"
|
VMessPrefix string = "vmess://"
|
||||||
SocksPrefix string = "socks"
|
SocksPrefix string = "socks"
|
||||||
|
AnytlsPrefix string = "anytls://"
|
||||||
)
|
)
|
||||||
|
@ -27,6 +27,7 @@ func GetSupportProxyTypes(clashType ClashType) map[string]bool {
|
|||||||
"hysteria": true,
|
"hysteria": true,
|
||||||
"hysteria2": true,
|
"hysteria2": true,
|
||||||
"socks5": true,
|
"socks5": true,
|
||||||
|
"anytls": true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -69,6 +69,9 @@ type Proxy struct {
|
|||||||
Peers []WireGuardPeerOption `yaml:"peers,omitempty"`
|
Peers []WireGuardPeerOption `yaml:"peers,omitempty"`
|
||||||
RemoteDnsResolve bool `yaml:"remote-dns-resolve,omitempty"`
|
RemoteDnsResolve bool `yaml:"remote-dns-resolve,omitempty"`
|
||||||
Dns []string `yaml:"dns,omitempty"`
|
Dns []string `yaml:"dns,omitempty"`
|
||||||
|
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
||||||
|
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
||||||
|
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WireGuardPeerOption struct {
|
type WireGuardPeerOption struct {
|
||||||
@ -98,6 +101,8 @@ func (p Proxy) MarshalYAML() (interface{}, error) {
|
|||||||
return ProxyToHysteria(p), nil
|
return ProxyToHysteria(p), nil
|
||||||
case "hysteria2":
|
case "hysteria2":
|
||||||
return ProxyToHysteria2(p), nil
|
return ProxyToHysteria2(p), nil
|
||||||
|
case "anytls":
|
||||||
|
return ProxyToAnytls(p), nil
|
||||||
default:
|
default:
|
||||||
return _Proxy(p), nil
|
return _Proxy(p), nil
|
||||||
}
|
}
|
||||||
|
37
model/proxy_anytls.go
Normal file
37
model/proxy_anytls.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type Anytls struct {
|
||||||
|
Type string `yaml:"type"`
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Server string `yaml:"server"`
|
||||||
|
Port int `yaml:"port"`
|
||||||
|
Password string `yaml:"password,omitempty"`
|
||||||
|
Alpn []string `yaml:"alpn,omitempty"`
|
||||||
|
SNI string `yaml:"sni,omitempty"`
|
||||||
|
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||||
|
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||||
|
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||||
|
UDP bool `yaml:"udp,omitempty"`
|
||||||
|
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
||||||
|
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
||||||
|
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProxyToAnytls(p Proxy) Anytls {
|
||||||
|
return Anytls{
|
||||||
|
Type: "anytls",
|
||||||
|
Name: p.Name,
|
||||||
|
Server: p.Server,
|
||||||
|
Port: p.Port,
|
||||||
|
Password: p.Password,
|
||||||
|
Alpn: p.Alpn,
|
||||||
|
SNI: p.Sni,
|
||||||
|
ClientFingerprint: p.ClientFingerprint,
|
||||||
|
SkipCertVerify: p.SkipCertVerify,
|
||||||
|
Fingerprint: p.Fingerprint,
|
||||||
|
UDP: p.UDP,
|
||||||
|
IdleSessionCheckInterval: p.IdleSessionCheckInterval,
|
||||||
|
IdleSessionTimeout: p.IdleSessionTimeout,
|
||||||
|
MinIdleSession: p.MinIdleSession,
|
||||||
|
}
|
||||||
|
}
|
74
parser/anytls.go
Normal file
74
parser/anytls.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/nitezs/sub2clash/constant"
|
||||||
|
"github.com/nitezs/sub2clash/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ParseAnytls(proxy string) (model.Proxy, error) {
|
||||||
|
if !strings.HasPrefix(proxy, constant.AnytlsPrefix) {
|
||||||
|
return model.Proxy{}, &ParseError{Type: ErrInvalidPrefix, Raw: proxy}
|
||||||
|
}
|
||||||
|
|
||||||
|
link, err := url.Parse(proxy)
|
||||||
|
if err != nil {
|
||||||
|
return model.Proxy{}, &ParseError{
|
||||||
|
Type: ErrInvalidStruct,
|
||||||
|
Message: "url parse error",
|
||||||
|
Raw: proxy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
username := link.User.Username()
|
||||||
|
password, exist := link.User.Password()
|
||||||
|
if !exist {
|
||||||
|
password = username
|
||||||
|
}
|
||||||
|
|
||||||
|
query := link.Query()
|
||||||
|
server := link.Hostname()
|
||||||
|
if server == "" {
|
||||||
|
return model.Proxy{}, &ParseError{
|
||||||
|
Type: ErrInvalidStruct,
|
||||||
|
Message: "missing server host",
|
||||||
|
Raw: proxy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
portStr := link.Port()
|
||||||
|
if portStr == "" {
|
||||||
|
return model.Proxy{}, &ParseError{
|
||||||
|
Type: ErrInvalidStruct,
|
||||||
|
Message: "missing server port",
|
||||||
|
Raw: proxy,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
port, err := ParsePort(portStr)
|
||||||
|
if err != nil {
|
||||||
|
return model.Proxy{}, &ParseError{
|
||||||
|
Type: ErrInvalidPort,
|
||||||
|
Raw: portStr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
insecure, sni := query.Get("insecure"), query.Get("sni")
|
||||||
|
insecureBool := insecure == "1"
|
||||||
|
remarks := link.Fragment
|
||||||
|
if remarks == "" {
|
||||||
|
remarks = fmt.Sprintf("%s:%s", server, portStr)
|
||||||
|
}
|
||||||
|
remarks = strings.TrimSpace(remarks)
|
||||||
|
|
||||||
|
result := model.Proxy{
|
||||||
|
Type: "anytls",
|
||||||
|
Name: remarks,
|
||||||
|
Server: server,
|
||||||
|
Port: port,
|
||||||
|
Password: password,
|
||||||
|
Sni: sni,
|
||||||
|
SkipCertVerify: insecureBool,
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user