Browse Source

feat: proxy options in config file

v1.x.x
dnomd343 2 years ago
parent
commit
310cbd6cb6
  1. 14
      src/config.go
  2. 3
      src/load.go
  3. 28
      src/main.go
  4. 16
      test.yml

14
src/config.go

@ -27,6 +27,13 @@ type netConfig struct {
} }
type Config 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 { Network struct {
DNS []string `yaml:"dns"` // system dns server DNS []string `yaml:"dns"` // system dns server
ByPass []string `yaml:"bypass"` // cidr bypass list ByPass []string `yaml:"bypass"` // cidr bypass list
@ -118,4 +125,11 @@ func loadConfig(rawConfig []byte) {
panic("Invalid IPv6 gateway -> " + v6Gateway) panic("Invalid IPv6 gateway -> " + v6Gateway)
} }
log.Infof("IPv6 -> address = %s | gateway = %s", v6Address, 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)
} }

3
src/load.go

@ -210,6 +210,9 @@ func loadProxy(configDir string, exposeDir string) {
for tag, port := range socksInbounds { for tag, port := range socksInbounds {
inboundsObject.Inbounds = append(inboundsObject.Inbounds, loadSocksProxy(tag, port, sniffObject)) 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 inboundsConfig, _ := json.MarshalIndent(inboundsObject, "", " ") // json encode
saveConfig(configDir, "inbounds", string(inboundsConfig), true) saveConfig(configDir, "inbounds", string(inboundsConfig), true)

28
src/main.go

@ -1,8 +1,8 @@
package main package main
import ( import (
"fmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"os"
) )
var logLevel = "warning" var logLevel = "warning"
@ -12,27 +12,23 @@ var v6TProxyPort = 7289
var enableSniff = false var enableSniff = false
var enableRedirect = true var enableRedirect = true
var httpInbounds = make(map[string]int) var httpInbounds map[string]int
var socksInbounds = make(map[string]int) var socksInbounds map[string]int
var addOnInbounds []interface{}
func main() { func main() {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
log.Warning("XProxy start") log.Warning("XProxy start")
httpInbounds["ipv4"] = 1084 content, err := os.ReadFile("test.yml")
httpInbounds["ipv6"] = 1086 if err != nil {
fmt.Println(httpInbounds) panic(err)
}
socksInbounds["nodeA"] = 1681 loadConfig(content)
socksInbounds["nodeB"] = 1682
socksInbounds["nodeC"] = 1683
fmt.Println(socksInbounds)
//fmt.Println(httpInbounds)
//fmt.Println(socksInbounds)
//fmt.Println(addOnInbounds)
loadProxy("/etc/xproxy/config", "/xproxy") loadProxy("/etc/xproxy/config", "/xproxy")
//content, err := os.ReadFile("test.yml")
//if err != nil {
// panic(err)
//}
//loadConfig(content)
} }

16
test.yml

@ -2,12 +2,18 @@ proxy:
sniff: true sniff: true
redirect: true redirect: true
http: http:
- ipv4: 1084 ipv4: 1084
- ipv6: 1086 ipv6: 1086
socks: socks:
- nodeA: 1681 nodeA: 1681
- nodeB: 1682 nodeB: 1682
- nodeC: 1683 nodeC: 1683
addon:
- tag: metrics
port: 9090
protocol: dokodemo-door
settings:
address: 127.0.0.1
network: network:
dns: dns:

Loading…
Cancel
Save