From 276ec004a0ff34a3558ccfe34fda011fc1fee53c Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Thu, 18 Aug 2022 12:36:05 +0800 Subject: [PATCH] feat: sniff options --- Dockerfile | 1 + cmd/config/decode.go | 27 ++++++++++++++++----------- cmd/config/default.go | 8 +------- cmd/config/main.go | 1 + cmd/proxy/config.go | 7 ++++--- cmd/proxy/main.go | 8 +++++--- cmd/xproxy.go | 2 +- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Dockerfile b/Dockerfile index 10597ff..08ce87f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,4 +45,5 @@ FROM alpine:3.16 ENV XRAY_LOCATION_ASSET=/xproxy/assets RUN apk add --no-cache iptables ip6tables COPY --from=asset /asset/ / +WORKDIR /xproxy CMD ["xproxy"] diff --git a/cmd/config/decode.go b/cmd/config/decode.go index 18d1ef5..b357218 100644 --- a/cmd/config/decode.go +++ b/cmd/config/decode.go @@ -12,18 +12,21 @@ type yamlNetConfig struct { } type yamlConfig struct { - Log string `yaml:"log"` Custom []string `yaml:"custom"` Update struct { Cron string `yaml:"cron"` Url map[string]string `yaml:"url"` } `yaml:"update"` Proxy struct { - Sniff bool `yaml:"sniff"` - Redirect bool `yaml:"redirect"` - Http map[string]int `yaml:"http"` - Socks map[string]int `yaml:"socks"` - AddOn []interface{} `yaml:"addon"` + Log string `yaml:"log"` + Sniff struct { + Enable bool `yaml:"enable"` + Redirect bool `yaml:"redirect"` + Exclude []string `yaml:"exclude"` + } `yaml:"sniff"` + Http map[string]int `yaml:"http"` + Socks map[string]int `yaml:"socks"` + AddOn []interface{} `yaml:"addon"` } `yaml:"proxy"` Network struct { DNS []string `yaml:"dns"` // system dns server @@ -99,10 +102,12 @@ func decodeIPv6(rawConfig *yamlConfig) (string, string) { } func decodeProxy(rawConfig *yamlConfig, config *Config) { - config.EnableSniff = rawConfig.Proxy.Sniff - log.Debugf("Connection sniff -> %v", config.EnableSniff) - config.EnableRedirect = rawConfig.Proxy.Redirect - log.Debugf("Connection redirect -> %v", config.EnableRedirect) + config.EnableSniff = rawConfig.Proxy.Sniff.Enable + log.Debugf("Connection sniff -> %t", config.EnableSniff) + config.EnableRedirect = rawConfig.Proxy.Sniff.Redirect + log.Debugf("Connection redirect -> %t", config.EnableRedirect) + config.SniffExclude = rawConfig.Proxy.Sniff.Exclude + log.Debugf("Connection sniff exlcude -> %v", config.SniffExclude) config.HttpInbounds = rawConfig.Proxy.Http log.Debugf("Http inbounds -> %v", config.HttpInbounds) config.SocksInbounds = rawConfig.Proxy.Socks @@ -127,7 +132,7 @@ func decodeCustom(rawConfig *yamlConfig) []string { func decode(rawConfig yamlConfig) Config { var config Config - config.LogLevel = rawConfig.Log + config.LogLevel = rawConfig.Proxy.Log config.DNS = decodeDns(&rawConfig) config.V4Bypass, config.V6Bypass = decodeBypass(&rawConfig) config.V4Address, config.V4Gateway = decodeIPv4(&rawConfig) diff --git a/cmd/config/default.go b/cmd/config/default.go index 8508d80..f1ecad9 100644 --- a/cmd/config/default.go +++ b/cmd/config/default.go @@ -1,16 +1,10 @@ package config var defaultConfig = `# default configure file for xproxy -log: debug - proxy: - sniff: true - redirect: true + log: warning network: - dns: null - ipv4: null - ipv6: null bypass: - 169.254.0.0/16 - 224.0.0.0/3 diff --git a/cmd/config/main.go b/cmd/config/main.go index 6d7206f..eaa51d0 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -22,6 +22,7 @@ type Config struct { EnableSniff bool EnableRedirect bool + SniffExclude []string HttpInbounds map[string]int SocksInbounds map[string]int AddOnInbounds []interface{} diff --git a/cmd/proxy/config.go b/cmd/proxy/config.go index 6675383..05e49c8 100644 --- a/cmd/proxy/config.go +++ b/cmd/proxy/config.go @@ -49,9 +49,10 @@ type inboundsObject struct { } type sniffObject struct { - Enabled bool `json:"enabled"` - RouteOnly bool `json:"routeOnly"` - DestOverride []string `json:"destOverride"` + Enabled bool `json:"enabled"` + RouteOnly bool `json:"routeOnly"` + DestOverride []string `json:"destOverride"` + DomainsExcluded []string `json:"domainsExcluded"` } type inboundObject struct { diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index fcb25a4..50b1706 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -10,6 +10,7 @@ type Config struct { V4TProxyPort int V6TProxyPort int LogLevel string + SniffExclude []string HttpInbounds map[string]int SocksInbounds map[string]int AddOnInbounds []interface{} @@ -22,9 +23,10 @@ func saveConfig(configDir string, caption string, content string, overwrite bool func loadInbounds(config Config) string { sniff := sniffObject{ - Enabled: config.Sniff, - RouteOnly: !config.Redirect, - DestOverride: []string{"http", "tls"}, + Enabled: config.Sniff, + RouteOnly: !config.Redirect, + DestOverride: []string{"http", "tls", "quic"}, + DomainsExcluded: config.SniffExclude, } var inbounds []interface{} inbounds = append(inbounds, loadTProxyConfig("tproxy", config.V4TProxyPort, sniff)) diff --git a/cmd/xproxy.go b/cmd/xproxy.go index b30d93a..4cea9ce 100644 --- a/cmd/xproxy.go +++ b/cmd/xproxy.go @@ -41,7 +41,7 @@ func blockWait() { func main() { defer func() { if err := recover(); err != nil { - log.Errorf("Unknown error -> %v", err) + log.Errorf("Panic exit -> %v", err) } }()