|
@ -53,6 +53,15 @@ func isFileExist(filePath string) bool { |
|
|
return !s.IsDir() |
|
|
return !s.IsDir() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func createFolder(folderPath string) { |
|
|
|
|
|
log.Debugf("Loading folder -> %s", folderPath) |
|
|
|
|
|
err := os.MkdirAll(folderPath, 0755) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Errorf("Create folder `%s` failed", folderPath) |
|
|
|
|
|
panic("Create folder failed") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func saveConfig(configDir string, caption string, content string, overwrite bool) { |
|
|
func saveConfig(configDir string, caption string, content string, overwrite bool) { |
|
|
filePath := configDir + "/" + caption + ".json" |
|
|
filePath := configDir + "/" + caption + ".json" |
|
|
if !overwrite && isFileExist(filePath) { // file exist and don't overwrite
|
|
|
if !overwrite && isFileExist(filePath) { // file exist and don't overwrite
|
|
@ -67,16 +76,20 @@ func saveConfig(configDir string, caption string, content string, overwrite bool |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func proxyConfig(configDir string, logLevel string, logDir string) { |
|
|
func loadProxy(configDir string, exposeDir string) { |
|
|
// TODO: mkdir -p configDir and exposeDir
|
|
|
createFolder(exposeDir + "/log") |
|
|
|
|
|
createFolder(exposeDir + "/config") |
|
|
|
|
|
createFolder(configDir) |
|
|
|
|
|
saveConfig(exposeDir+"/config", "dns", dnsConfig+"\n", false) |
|
|
|
|
|
saveConfig(exposeDir+"/config", "route", routeConfig+"\n", false) |
|
|
|
|
|
saveConfig(exposeDir+"/config", "outbounds", outboundsConfig+"\n", false) |
|
|
|
|
|
|
|
|
logConfig = strings.ReplaceAll(logConfig, "${LEVEL}", logLevel) |
|
|
logConfig = strings.ReplaceAll(logConfig, "${LEVEL}", logLevel) |
|
|
logConfig = strings.ReplaceAll(logConfig, "${DIR}", logDir) |
|
|
logConfig = strings.ReplaceAll(logConfig, "${DIR}", exposeDir+"/log") |
|
|
|
|
|
saveConfig(configDir, "log", logConfig+"\n", true) |
|
|
|
|
|
|
|
|
// TODO: load inbounds config
|
|
|
// TODO: load inbounds config
|
|
|
|
|
|
|
|
|
saveConfig(configDir, "log", logConfig+"\n", true) |
|
|
// TODO: copy exposeDir/config/*.json -> configDir (exclude log and inbounds)
|
|
|
saveConfig(configDir, "dns", dnsConfig+"\n", false) |
|
|
|
|
|
saveConfig(configDir, "route", routeConfig+"\n", false) |
|
|
|
|
|
saveConfig(configDir, "outbounds", outboundsConfig+"\n", false) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|