feat: support http and socks5 upstream node uris
This commit is contained in:
@@ -78,10 +78,10 @@ type MultiPortConfig struct {
|
||||
|
||||
// ManagementConfig controls the monitoring HTTP endpoint.
|
||||
type ManagementConfig struct {
|
||||
Enabled *bool `yaml:"enabled"`
|
||||
Listen string `yaml:"listen"`
|
||||
ProbeTarget string `yaml:"probe_target"`
|
||||
Password string `yaml:"password"` // WebUI 访问密码,为空则不需要密码
|
||||
Enabled *bool `yaml:"enabled"`
|
||||
Listen string `yaml:"listen"`
|
||||
ProbeTarget string `yaml:"probe_target"`
|
||||
Password string `yaml:"password"` // WebUI 访问密码,为空则不需要密码
|
||||
HealthCheckInterval time.Duration `yaml:"health_check_interval"`
|
||||
}
|
||||
|
||||
@@ -111,6 +111,20 @@ const (
|
||||
InboundProtocolMixed = "mixed"
|
||||
)
|
||||
|
||||
var supportedProxyURISchemes = []string{
|
||||
"vmess://",
|
||||
"vless://",
|
||||
"trojan://",
|
||||
"ss://",
|
||||
"ssr://",
|
||||
"hysteria://",
|
||||
"hysteria2://",
|
||||
"hy2://",
|
||||
"anytls://",
|
||||
"http://",
|
||||
"socks5://",
|
||||
}
|
||||
|
||||
// NormalizeInboundProtocol normalizes inbound protocol aliases and validates the value.
|
||||
func NormalizeInboundProtocol(value string) (string, error) {
|
||||
protocol := strings.ToLower(strings.TrimSpace(value))
|
||||
@@ -683,9 +697,9 @@ func isBase64(s string) bool {
|
||||
|
||||
// IsProxyURI checks if a string is a valid proxy URI
|
||||
func IsProxyURI(s string) bool {
|
||||
schemes := []string{"vmess://", "vless://", "trojan://", "ss://", "ssr://", "hysteria://", "hysteria2://", "hy2://", "anytls://"}
|
||||
for _, scheme := range schemes {
|
||||
if strings.HasPrefix(strings.ToLower(s), scheme) {
|
||||
lower := strings.ToLower(strings.TrimSpace(s))
|
||||
for _, scheme := range supportedProxyURISchemes {
|
||||
if strings.HasPrefix(lower, scheme) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIsProxyURIRecognizesHTTPAndSOCKS5(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
uri string
|
||||
want bool
|
||||
}{
|
||||
{name: "http", uri: "http://alice:secret@example.com:8080", want: true},
|
||||
{name: "socks5", uri: "socks5://alice:secret@example.com:1080", want: true},
|
||||
{name: "vmess", uri: "vmess://example", want: true},
|
||||
{name: "invalid", uri: "ftp://example.com", want: false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
if got := IsProxyURI(tt.uri); got != tt.want {
|
||||
t.Fatalf("%s: IsProxyURI(%q) = %v, want %v", tt.name, tt.uri, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user