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 v6Gateway string
var v6Address 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 { type NetConfig struct {
Gateway string `yaml:"gateway"` // network gateway Gateway string `yaml:"gateway"` // network gateway
Address string `yaml:"address"` // network address Address string `yaml:"address"` // network address
} }
type Config struct { type Config struct {
Script []string `yaml:"script"`
Update struct { Update struct {
Cron string `yaml:"cron"` Cron string `yaml:"cron"`
Url map[string]string `yaml:"url"` Url map[string]string `yaml:"url"`
@ -42,32 +66,6 @@ type Config struct {
} `yaml:"network"` } `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 { func isIP(ipAddr string, isCidr bool) bool {
if !isCidr { if !isCidr {
return net.ParseIP(ipAddr) != nil return net.ParseIP(ipAddr) != nil
@ -161,4 +159,7 @@ func loadConfig(configFile string) {
log.Infof("Update cron -> %s", updateCron) log.Infof("Update cron -> %s", updateCron)
updateUrls = config.Update.Url updateUrls = config.Update.Url
log.Infof("Update url -> %v", updateUrls) 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 v4TProxyPort = 7288
var v6TProxyPort = 7289 var v6TProxyPort = 7289
var preScript []string
var updateCron string var updateCron string
var updateUrls map[string]string var updateUrls map[string]string
@ -35,9 +36,7 @@ func main() {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
log.Warning("XProxy start") log.Warning("XProxy start")
loadConfig("/xproxy/config.yml") loadConfig("/xproxy/config.yml")
loadProxy("/etc/xproxy/config", "/xproxy") loadProxy("/etc/xproxy/config", "/xproxy")
loadGeoSite("/xproxy/assets") loadGeoSite("/xproxy/assets")
loadGeoIp("/xproxy/assets") loadGeoIp("/xproxy/assets")
@ -50,8 +49,10 @@ func main() {
loadDns() loadDns()
loadNetwork() loadNetwork()
loadTProxy() loadTProxy()
for _, script := range preScript {
// TODO: running custom script log.Infof("Run script command -> %s", script)
runCommand("sh", "-c", script)
}
xray := newProcess("xray", "-confdir", "/etc/xproxy/config") xray := newProcess("xray", "-confdir", "/etc/xproxy/config")
xray.startProcess(true, true) xray.startProcess(true, true)

Loading…
Cancel
Save