From fe695ff34a0557a56348eb01ff5c821800defd6c Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Fri, 19 Aug 2022 23:01:48 +0800 Subject: [PATCH] update: xproxy init --- cmd/xproxy.go | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/cmd/xproxy.go b/cmd/xproxy.go index 9049b4e..bfb4fb4 100644 --- a/cmd/xproxy.go +++ b/cmd/xproxy.go @@ -4,28 +4,60 @@ import ( "XProxy/cmd/config" "XProxy/cmd/process" log "github.com/sirupsen/logrus" + "os" + "strconv" ) -var version = "0.1.0" +var version = "0.9.0" var v4RouteTable = 100 var v6RouteTable = 106 var v4TProxyPort = 7288 var v6TProxyPort = 7289 -var exposeDir = "/xproxy" var configDir = "/etc/xproxy" var assetFile = "/assets.tar.xz" -var assetDir = exposeDir + "/assets" -var configFile = exposeDir + "/config.yml" +var assetDir, exposeDir, configFile string var subProcess []*process.Process func xproxyInit() { - // log format - // TODO: set log level - log.SetLevel(log.DebugLevel) - // read tproxy port / route table num from env + log.SetFormatter(&log.TextFormatter{ + FullTimestamp: true, + TimestampFormat: "2006-01-02 15:04:05", + }) + if len(os.Args) > 1 && os.Args[1] == "--debug" { + log.SetLevel(log.DebugLevel) + } else { + log.SetLevel(log.InfoLevel) + } + + if os.Getenv("IPV4_TABLE") != "" { + v4RouteTable, _ = strconv.Atoi(os.Getenv("IPV4_TABLE")) + } + if os.Getenv("IPV6_TABLE") != "" { + v6RouteTable, _ = strconv.Atoi(os.Getenv("IPV6_TABLE")) + } + if os.Getenv("IPV4_TPROXY") != "" { + v4TProxyPort, _ = strconv.Atoi(os.Getenv("IPV4_TPROXY")) + } + if os.Getenv("IPV6_TPROXY") != "" { + v6TProxyPort, _ = strconv.Atoi(os.Getenv("IPV6_TPROXY")) + } + log.Debugf("IPv4 Route Table -> %d", v4RouteTable) + log.Debugf("IPv6 Route Table -> %d", v6RouteTable) + log.Debugf("IPv4 TProxy Port -> %d", v4TProxyPort) + log.Debugf("IPv6 TProxy Port -> %d", v6TProxyPort) + + exposeDir = "/xproxy" // default folder + if os.Getenv("EXPOSE_DIR") != "" { + exposeDir = os.Getenv("EXPOSE_DIR") + } + assetDir = exposeDir + "/assets" + configFile = exposeDir + "/config.yml" + log.Debugf("Expose folder -> %s", exposeDir) + log.Debugf("Assets folder -> %s", assetDir) + log.Debugf("Config file -> %s", configFile) } func main() {