Browse Source

feat: proxy bin option

v1.x.x
Dnomd343 2 years ago
parent
commit
dcdd547c48
  1. 6
      cmd/config/decode.go
  2. 3
      cmd/config/default.go
  3. 15
      cmd/controller.go
  4. 2
      cmd/proxy/main.go
  5. 7
      cmd/xproxy.go

6
cmd/config/decode.go

@ -132,9 +132,11 @@ func decodeIPv6(rawConfig *RawConfig, config *Config) {
func decodeProxy(rawConfig *RawConfig, config *Config) {
config.Proxy = rawConfig.Proxy
// TODO: add proxy bin option
if config.Proxy.Bin == "" {
config.Proxy.Bin = "xray" // default proxy bin
}
log.Debugf("Proxy bin -> %s", config.Proxy.Bin)
log.Debugf("Proxy log level -> %s", config.Proxy.Log)
//log.Debugf("Core type -> %s", config.Proxy.Core)
log.Debugf("Http inbounds -> %v", config.Proxy.Http)
log.Debugf("Socks5 inbounds -> %v", config.Proxy.Socks)
log.Debugf("Add-on inbounds -> %v", config.Proxy.AddOn)

3
cmd/config/default.go

@ -11,9 +11,8 @@ import (
)
var defaultConfig = map[string]interface{}{
// TODO: add proxy bin option
"proxy": map[string]string{
//"core": "xray",
"bin": "xray",
"log": "warning",
},
"network": map[string]interface{}{

15
cmd/controller.go

@ -65,27 +65,20 @@ func loadNetwork(settings *config.Config) {
}
func loadProxy(settings *config.Config) {
if proxyBin != "" {
settings.Proxy.Bin = proxyBin // setting proxy bin from env
}
settings.Proxy.V4TProxyPort = v4TProxyPort
settings.Proxy.V6TProxyPort = v6TProxyPort
proxy.Load(configDir, exposeDir, &settings.Proxy)
}
func runProxy(settings *config.Config) {
//if settings.Proxy.Core == "xray" { // xray-core
// runProcess([]string{"XRAY_LOCATION_ASSET=" + assetDir}, "xray", "-confdir", configDir)
//} else if settings.Proxy.Core == "v2ray" { // v2fly-core
// runProcess([]string{"V2RAY_LOCATION_ASSET=" + assetDir}, "v2ray", "run", "-d", configDir)
//} else if settings.Proxy.Core == "sagray" { // sager-core
// runProcess([]string{"V2RAY_LOCATION_ASSET=" + assetDir}, "sagray", "run", "-confdir", configDir)
//} else {
// log.Panicf("Unknown core type -> %s", settings.Proxy.Core)
//}
assetEnv := []string{
"XRAY_LOCATION_ASSET=" + assetDir, // xray asset folder
"V2RAY_LOCATION_ASSET=" + assetDir, // v2ray / sagray asset folder
}
// TODO: add proxy bin options
runProcess(assetEnv, "xray", "run", "-confdir", configDir)
runProcess(assetEnv, settings.Proxy.Bin, "run", "-confdir", configDir)
}
func runRadvd(settings *config.Config) {

2
cmd/proxy/main.go

@ -7,7 +7,7 @@ import (
)
type Config struct {
//Bin string `yaml:"bin" json:"bin" toml:"bin"`
Bin string `yaml:"bin" json:"bin" toml:"bin"`
Log string `yaml:"log" json:"log" toml:"log"`
Http map[string]int `yaml:"http" json:"http" toml:"http"`
Socks map[string]int `yaml:"socks" json:"socks" toml:"socks"`

7
cmd/xproxy.go

@ -20,6 +20,8 @@ var v4RouteTable = 104
var v6RouteTable = 106
var v4TProxyPort = 7288
var v6TProxyPort = 7289
var proxyBin = ""
var configDir = "/etc/xproxy"
var assetFile = "/assets.tar.xz"
@ -70,8 +72,9 @@ func xproxyInit() {
log.Debugf("Assets folder -> %s", assetDir)
log.Debugf("Config file -> %s", configFile)
// TODO: add PROXY_BIN env option
if os.Getenv("PROXY_BIN") != "" {
proxyBin = os.Getenv("PROXY_BIN")
}
if os.Getenv("IPV4_TABLE") != "" {
v4RouteTable, _ = strconv.Atoi(os.Getenv("IPV4_TABLE"))
}

Loading…
Cancel
Save