mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 20:53:18 +08:00
fix: 修复当base64字符串长度不为4的倍数时,解码失败的问题
update: 提高根据ISO匹配国家名称的正确率 fix: 修复vmess的port和aid不规范导致无法解析的问题 modify: 一些没用的修改
This commit is contained in:
144
model/proxy.go
144
model/proxy.go
@ -1,83 +1,81 @@
|
||||
package model
|
||||
|
||||
type PluginOptsStruct struct {
|
||||
Mode string `yaml:"mode"`
|
||||
}
|
||||
|
||||
type SmuxStruct struct {
|
||||
Enabled bool `yaml:"enable"`
|
||||
}
|
||||
|
||||
type HeaderStruct struct {
|
||||
Host string `yaml:"Host"`
|
||||
}
|
||||
|
||||
type WSOptsStruct struct {
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Headers HeaderStruct `yaml:"headers,omitempty"`
|
||||
MaxEarlyData int `yaml:"max-early-data,omitempty"`
|
||||
EarlyDataHeaderName string `yaml:"early-data-header-name,omitempty"`
|
||||
}
|
||||
|
||||
type Vmess struct {
|
||||
V string `json:"v"`
|
||||
Ps string `json:"ps"`
|
||||
Add string `json:"add"`
|
||||
Port string `json:"port"`
|
||||
Id string `json:"id"`
|
||||
Aid string `json:"aid"`
|
||||
Scy string `json:"scy"`
|
||||
Net string `json:"net"`
|
||||
Type string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Tls string `json:"tls"`
|
||||
Sni string `json:"sni"`
|
||||
Alpn string `json:"alpn"`
|
||||
Fp string `json:"fp"`
|
||||
}
|
||||
|
||||
type GRPCOptsStruct struct {
|
||||
GRPCServiceName string `yaml:"grpc-service-name,omitempty"`
|
||||
}
|
||||
|
||||
type RealityOptsStruct struct {
|
||||
PublicKey string `yaml:"public-key,omitempty"`
|
||||
ShortId string `yaml:"short-id,omitempty"`
|
||||
type VmessJson struct {
|
||||
V string `json:"v"`
|
||||
Ps string `json:"ps"`
|
||||
Add string `json:"add"`
|
||||
Port interface{} `json:"port"`
|
||||
Id string `json:"id"`
|
||||
Aid interface{} `json:"aid"`
|
||||
Scy string `json:"scy"`
|
||||
Net string `json:"net"`
|
||||
Type string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Tls string `json:"tls"`
|
||||
Sni string `json:"sni"`
|
||||
Alpn string `json:"alpn"`
|
||||
Fp string `json:"fp"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Server string `yaml:"server,omitempty"`
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Cipher string `yaml:"cipher,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
UUID string `yaml:"uuid,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
Flow string `yaml:"flow,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
UdpOverTcp bool `yaml:"udp-over-tcp,omitempty"`
|
||||
UdpOverTcpVersion string `yaml:"udp-over-tcp-version,omitempty"`
|
||||
Plugin string `yaml:"plugin,omitempty"`
|
||||
PluginOpts PluginOptsStruct `yaml:"plugin-opts,omitempty"`
|
||||
Smux SmuxStruct `yaml:"smux,omitempty"`
|
||||
Sni string `yaml:"sni,omitempty"`
|
||||
AllowInsecure bool `yaml:"allow-insecure,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Alpn []string `yaml:"alpn,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
Servername string `yaml:"servername,omitempty"`
|
||||
WSOpts WSOptsStruct `yaml:"ws-opts,omitempty"`
|
||||
AlterID string `yaml:"alterId,omitempty"`
|
||||
GRPCOpts GRPCOptsStruct `yaml:"grpc-opts,omitempty"`
|
||||
RealityOpts RealityOptsStruct `yaml:"reality-opts,omitempty"`
|
||||
Protocol string `yaml:"protocol,omitempty"`
|
||||
Obfs string `yaml:"obfs,omitempty"`
|
||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||
Remarks []string `yaml:"remarks,omitempty"`
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Server string `yaml:"server,omitempty"`
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Cipher string `yaml:"cipher,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
UUID string `yaml:"uuid,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
Flow string `yaml:"flow,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
Plugin string `yaml:"plugin,omitempty"`
|
||||
PluginOpts map[string]any `yaml:"plugin-opts,omitempty"`
|
||||
Smux SmuxStruct `yaml:"smux,omitempty"`
|
||||
Sni string `yaml:"sni,omitempty"`
|
||||
AllowInsecure bool `yaml:"allow-insecure,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Alpn []string `yaml:"alpn,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
Servername string `yaml:"servername,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
AlterID int `yaml:"alterId,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
Protocol string `yaml:"protocol,omitempty"`
|
||||
Obfs string `yaml:"obfs,omitempty"`
|
||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||
Remarks []string `yaml:"remarks,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
GlobalPadding bool `yaml:"global-padding,omitempty"`
|
||||
AuthenticatedLength bool `yaml:"authenticated-length,omitempty"`
|
||||
UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"`
|
||||
UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"`
|
||||
}
|
||||
|
||||
func (p Proxy) MarshalYAML() (interface{}, error) {
|
||||
switch p.Type {
|
||||
case "vmess":
|
||||
return ProxyToVmess(p), nil
|
||||
case "ss":
|
||||
return ProxyToShadowSocks(p), nil
|
||||
case "ssr":
|
||||
return ProxyToShadowSocksR(p), nil
|
||||
case "vless":
|
||||
return ProxyToVless(p), nil
|
||||
case "trojan":
|
||||
return ProxyToTrojan(p), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -17,6 +17,44 @@ type ProxyGroup struct {
|
||||
Size int `yaml:"-"`
|
||||
}
|
||||
|
||||
type SelectProxyGroup struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Proxies []string `yaml:"proxies,omitempty"`
|
||||
}
|
||||
|
||||
type UrlTestProxyGroup struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Proxies []string `yaml:"proxies,omitempty"`
|
||||
Url string `yaml:"url,omitempty"`
|
||||
Interval int `yaml:"interval,omitempty"`
|
||||
Tolerance int `yaml:"tolerance,omitempty"`
|
||||
Lazy bool `yaml:"lazy"`
|
||||
}
|
||||
|
||||
func (p ProxyGroup) MarshalYAML() (interface{}, error) {
|
||||
switch p.Type {
|
||||
case "select":
|
||||
return SelectProxyGroup{
|
||||
Name: p.Name,
|
||||
Type: p.Type,
|
||||
Proxies: p.Proxies,
|
||||
}, nil
|
||||
case "url-test":
|
||||
return UrlTestProxyGroup{
|
||||
Name: p.Name,
|
||||
Type: p.Type,
|
||||
Proxies: p.Proxies,
|
||||
Url: p.Url,
|
||||
Interval: p.Interval,
|
||||
Tolerance: p.Tolerance,
|
||||
Lazy: p.Lazy,
|
||||
}, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type ProxyGroupsSortByName []ProxyGroup
|
||||
type ProxyGroupsSortBySize []ProxyGroup
|
||||
|
||||
|
33
model/proxy_shadowsocks.go
Normal file
33
model/proxy_shadowsocks.go
Normal file
@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
type ShadowSocks struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Plugin string `yaml:"plugin,omitempty"`
|
||||
PluginOpts map[string]any `yaml:"plugin-opts,omitempty"`
|
||||
UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"`
|
||||
UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToShadowSocks(p Proxy) ShadowSocks {
|
||||
return ShadowSocks{
|
||||
Type: "ss",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
Cipher: p.Cipher,
|
||||
UDP: p.UDP,
|
||||
Plugin: p.Plugin,
|
||||
PluginOpts: p.PluginOpts,
|
||||
UDPOverTCP: p.UDPOverTCP,
|
||||
UDPOverTCPVersion: p.UDPOverTCPVersion,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
31
model/proxy_shadowsocksr.go
Normal file
31
model/proxy_shadowsocksr.go
Normal file
@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
type ShadowSocksR struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
Obfs string `yaml:"obfs"`
|
||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||
Protocol string `yaml:"protocol"`
|
||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToShadowSocksR(p Proxy) ShadowSocksR {
|
||||
return ShadowSocksR{
|
||||
Type: "ssr",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
Cipher: p.Cipher,
|
||||
Obfs: p.Obfs,
|
||||
ObfsParam: p.ObfsParam,
|
||||
Protocol: p.Protocol,
|
||||
ProtocolParam: p.ProtocolParam,
|
||||
UDP: p.UDP,
|
||||
}
|
||||
}
|
39
model/proxy_trojan.go
Normal file
39
model/proxy_trojan.go
Normal file
@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
type Trojan struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
SNI string `yaml:"sni,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToTrojan(p Proxy) Trojan {
|
||||
return Trojan{
|
||||
Type: "trojan",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
ALPN: p.Alpn,
|
||||
SNI: p.Sni,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
UDP: p.UDP,
|
||||
Network: p.Network,
|
||||
RealityOpts: p.RealityOpts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
57
model/proxy_vless.go
Normal file
57
model/proxy_vless.go
Normal file
@ -0,0 +1,57 @@
|
||||
package model
|
||||
|
||||
type Vless struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
UUID string `yaml:"uuid"`
|
||||
Flow string `yaml:"flow,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
WSPath string `yaml:"ws-path,omitempty"`
|
||||
WSHeaders map[string]string `yaml:"ws-headers,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ServerName string `yaml:"servername,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToVless(p Proxy) Vless {
|
||||
return Vless{
|
||||
Type: "vless",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
UUID: p.UUID,
|
||||
Flow: p.Flow,
|
||||
TLS: p.TLS,
|
||||
ALPN: p.Alpn,
|
||||
UDP: p.UDP,
|
||||
PacketAddr: p.PacketAddr,
|
||||
XUDP: p.XUDP,
|
||||
PacketEncoding: p.PacketEncoding,
|
||||
Network: p.Network,
|
||||
RealityOpts: p.RealityOpts,
|
||||
HTTPOpts: p.HTTPOpts,
|
||||
HTTP2Opts: p.HTTP2Opts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
WSPath: p.WSOpts.Path,
|
||||
WSHeaders: p.WSOpts.Headers,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ServerName: p.Servername,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
86
model/proxy_vmess.go
Normal file
86
model/proxy_vmess.go
Normal file
@ -0,0 +1,86 @@
|
||||
package model
|
||||
|
||||
type HTTPOptions struct {
|
||||
Method string `proxy:"method,omitempty"`
|
||||
Path []string `proxy:"path,omitempty"`
|
||||
Headers map[string][]string `proxy:"headers,omitempty"`
|
||||
}
|
||||
|
||||
type HTTP2Options struct {
|
||||
Host []string `proxy:"host,omitempty"`
|
||||
Path string `proxy:"path,omitempty"`
|
||||
}
|
||||
|
||||
type GrpcOptions struct {
|
||||
GrpcServiceName string `proxy:"grpc-service-name,omitempty"`
|
||||
}
|
||||
|
||||
type RealityOptions struct {
|
||||
PublicKey string `proxy:"public-key"`
|
||||
ShortID string `proxy:"short-id"`
|
||||
}
|
||||
|
||||
type WSOptions struct {
|
||||
Path string `proxy:"path,omitempty"`
|
||||
Headers map[string]string `proxy:"headers,omitempty"`
|
||||
MaxEarlyData int `proxy:"max-early-data,omitempty"`
|
||||
EarlyDataHeaderName string `proxy:"early-data-header-name,omitempty"`
|
||||
}
|
||||
|
||||
type Vmess struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
UUID string `yaml:"uuid"`
|
||||
AlterID int `yaml:"alterId"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ServerName string `yaml:"servername,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
GlobalPadding bool `yaml:"global-padding,omitempty"`
|
||||
AuthenticatedLength bool `yaml:"authenticated-length,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToVmess(p Proxy) Vmess {
|
||||
return Vmess{
|
||||
Type: "vmess",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
UUID: p.UUID,
|
||||
AlterID: p.AlterID,
|
||||
Cipher: p.Cipher,
|
||||
UDP: p.UDP,
|
||||
Network: p.Network,
|
||||
TLS: p.TLS,
|
||||
ALPN: p.Alpn,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ServerName: p.Servername,
|
||||
RealityOpts: p.RealityOpts,
|
||||
HTTPOpts: p.HTTPOpts,
|
||||
HTTP2Opts: p.HTTP2Opts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
PacketAddr: p.PacketAddr,
|
||||
XUDP: p.XUDP,
|
||||
PacketEncoding: p.PacketEncoding,
|
||||
GlobalPadding: p.GlobalPadding,
|
||||
AuthenticatedLength: p.AuthenticatedLength,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user