From 310cbd6cb6ab8e8951d291f657d6f9f6fdb4df7f Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 15 Aug 2022 20:10:31 +0800 Subject: [PATCH] feat: proxy options in config file --- src/config.go | 14 ++++++++++++++ src/load.go | 3 +++ src/main.go | 28 ++++++++++++---------------- test.yml | 16 +++++++++++----- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/config.go b/src/config.go index 34bfe61..d1cca44 100644 --- a/src/config.go +++ b/src/config.go @@ -27,6 +27,13 @@ type netConfig struct { } type Config struct { + 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"` + } Network struct { DNS []string `yaml:"dns"` // system dns server ByPass []string `yaml:"bypass"` // cidr bypass list @@ -118,4 +125,11 @@ func loadConfig(rawConfig []byte) { panic("Invalid IPv6 gateway -> " + v6Gateway) } log.Infof("IPv6 -> address = %s | gateway = %s", v6Address, v6Gateway) + + httpInbounds = config.Proxy.Http + log.Infof("Http inbounds -> %v", httpInbounds) + socksInbounds = config.Proxy.Socks + log.Infof("Socks inbounds -> %v", socksInbounds) + addOnInbounds = config.Proxy.AddOn + log.Infof("Add-on inbounds -> %v", addOnInbounds) } diff --git a/src/load.go b/src/load.go index 3936698..bb954b8 100644 --- a/src/load.go +++ b/src/load.go @@ -210,6 +210,9 @@ func loadProxy(configDir string, exposeDir string) { for tag, port := range socksInbounds { inboundsObject.Inbounds = append(inboundsObject.Inbounds, loadSocksProxy(tag, port, sniffObject)) } + for _, addon := range addOnInbounds { + inboundsObject.Inbounds = append(inboundsObject.Inbounds, addon) + } inboundsConfig, _ := json.MarshalIndent(inboundsObject, "", " ") // json encode saveConfig(configDir, "inbounds", string(inboundsConfig), true) diff --git a/src/main.go b/src/main.go index 9e04122..a35f7d4 100644 --- a/src/main.go +++ b/src/main.go @@ -1,8 +1,8 @@ package main import ( - "fmt" log "github.com/sirupsen/logrus" + "os" ) var logLevel = "warning" @@ -12,27 +12,23 @@ var v6TProxyPort = 7289 var enableSniff = false var enableRedirect = true -var httpInbounds = make(map[string]int) -var socksInbounds = make(map[string]int) +var httpInbounds map[string]int +var socksInbounds map[string]int +var addOnInbounds []interface{} func main() { log.SetLevel(log.DebugLevel) log.Warning("XProxy start") - httpInbounds["ipv4"] = 1084 - httpInbounds["ipv6"] = 1086 - fmt.Println(httpInbounds) - - socksInbounds["nodeA"] = 1681 - socksInbounds["nodeB"] = 1682 - socksInbounds["nodeC"] = 1683 - fmt.Println(socksInbounds) + content, err := os.ReadFile("test.yml") + if err != nil { + panic(err) + } + loadConfig(content) + //fmt.Println(httpInbounds) + //fmt.Println(socksInbounds) + //fmt.Println(addOnInbounds) loadProxy("/etc/xproxy/config", "/xproxy") - //content, err := os.ReadFile("test.yml") - //if err != nil { - // panic(err) - //} - //loadConfig(content) } diff --git a/test.yml b/test.yml index 3fccf2c..4312605 100644 --- a/test.yml +++ b/test.yml @@ -2,12 +2,18 @@ proxy: sniff: true redirect: true http: - - ipv4: 1084 - - ipv6: 1086 + ipv4: 1084 + ipv6: 1086 socks: - - nodeA: 1681 - - nodeB: 1682 - - nodeC: 1683 + nodeA: 1681 + nodeB: 1682 + nodeC: 1683 + addon: + - tag: metrics + port: 9090 + protocol: dokodemo-door + settings: + address: 127.0.0.1 network: dns: