Browse Source

feat: run custom script

v1.x.x
dnomd343 2 years ago
parent
commit
91f2bd0433
  1. 53
      src/config.go
  2. 9
      src/main.go

53
src/config.go

@ -17,12 +17,36 @@ var v4Address string
var v6Gateway string
var v6Address string
var defaultConfig = `# default configure file for xproxy
proxy:
sniff: true
redirect: true
network:
dns: null
ipv4: null
ipv6: null
bypass:
- 169.254.0.0/16
- 224.0.0.0/3
- fc00::/7
- fe80::/10
- ff00::/8
update:
cron: "0 0 4 * * *"
url:
geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
geosite.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
`
type NetConfig struct {
Gateway string `yaml:"gateway"` // network gateway
Address string `yaml:"address"` // network address
}
type Config struct {
Script []string `yaml:"script"`
Update struct {
Cron string `yaml:"cron"`
Url map[string]string `yaml:"url"`
@ -42,32 +66,6 @@ type Config struct {
} `yaml:"network"`
}
var defaultConfig = `# default configure file for xproxy
proxy:
sniff: true
redirect: true
http: null
socks: null
addon: null
network:
dns: null
ipv4: null
ipv6: null
bypass:
- 169.254.0.0/16
- 224.0.0.0/3
- fc00::/7
- fe80::/10
- ff00::/8
update:
cron: "0 0 4 * * *"
url:
geoip.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat"
geosite.dat: "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
`
func isIP(ipAddr string, isCidr bool) bool {
if !isCidr {
return net.ParseIP(ipAddr) != nil
@ -161,4 +159,7 @@ func loadConfig(configFile string) {
log.Infof("Update cron -> %s", updateCron)
updateUrls = config.Update.Url
log.Infof("Update url -> %v", updateUrls)
preScript = config.Script
log.Infof("Pre-script -> %v", preScript)
}

9
src/main.go

@ -15,6 +15,7 @@ var v6RouteTable = 106
var v4TProxyPort = 7288
var v6TProxyPort = 7289
var preScript []string
var updateCron string
var updateUrls map[string]string
@ -35,9 +36,7 @@ func main() {
log.SetLevel(log.DebugLevel)
log.Warning("XProxy start")
loadConfig("/xproxy/config.yml")
loadProxy("/etc/xproxy/config", "/xproxy")
loadGeoSite("/xproxy/assets")
loadGeoIp("/xproxy/assets")
@ -50,8 +49,10 @@ func main() {
loadDns()
loadNetwork()
loadTProxy()
// TODO: running custom script
for _, script := range preScript {
log.Infof("Run script command -> %s", script)
runCommand("sh", "-c", script)
}
xray := newProcess("xray", "-confdir", "/etc/xproxy/config")
xray.startProcess(true, true)

Loading…
Cancel
Save