From aff1975c5aba80a540272f5bb2756a1c66e92a67 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sun, 20 Jul 2025 14:03:39 +0800 Subject: [PATCH] Updated version code and defs - Updated version code - Replaced hardcoded path of some config folder string with const value --- src/config.go | 16 ++++++++-------- src/def.go | 23 ++++++++++++++--------- src/main.go | 2 +- src/reverseproxy.go | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/config.go b/src/config.go index e3257b3..43b6886 100644 --- a/src/config.go +++ b/src/config.go @@ -108,9 +108,9 @@ func filterProxyConfigFilename(filename string) string { func SaveReverseProxyConfig(endpoint *dynamicproxy.ProxyEndpoint) error { //Get filename for saving - filename := filepath.Join("./conf/proxy/", endpoint.RootOrMatchingDomain+".config") + filename := filepath.Join(CONF_HTTP_PROXY, endpoint.RootOrMatchingDomain+".config") if endpoint.ProxyType == dynamicproxy.ProxyTypeRoot { - filename = "./conf/proxy/root.config" + filename = filepath.Join(CONF_HTTP_PROXY, "root.config") } filename = filterProxyConfigFilename(filename) @@ -125,9 +125,9 @@ func SaveReverseProxyConfig(endpoint *dynamicproxy.ProxyEndpoint) error { } func RemoveReverseProxyConfig(endpoint string) error { - filename := filepath.Join("./conf/proxy/", endpoint+".config") + filename := filepath.Join(CONF_HTTP_PROXY, endpoint+".config") if endpoint == "/" { - filename = "./conf/proxy/root.config" + filename = filepath.Join(CONF_HTTP_PROXY, "/root.config") } filename = filterProxyConfigFilename(filename) @@ -179,11 +179,11 @@ func ExportConfigAsZip(w http.ResponseWriter, r *http.Request) { } // Specify the folder path to be zipped - if !utils.FileExists("./conf") { + if !utils.FileExists(CONF_FOLDER) { SystemWideLogger.PrintAndLog("Backup", "Configuration folder not found", nil) return } - folderPath := "./conf" + folderPath := CONF_FOLDER // Set the Content-Type header to indicate it's a zip file w.Header().Set("Content-Type", "application/zip") @@ -284,12 +284,12 @@ func ImportConfigFromZip(w http.ResponseWriter, r *http.Request) { return } // Create the target directory to unzip the files - targetDir := "./conf" + targetDir := CONF_FOLDER if utils.FileExists(targetDir) { //Backup the old config to old //backupPath := filepath.Dir(*path_conf) + filepath.Base(*path_conf) + ".old_" + strconv.Itoa(int(time.Now().Unix())) //os.Rename(*path_conf, backupPath) - os.Rename("./conf", "./conf.old_"+strconv.Itoa(int(time.Now().Unix()))) + os.Rename(CONF_FOLDER, CONF_FOLDER+".old_"+strconv.Itoa(int(time.Now().Unix()))) } err = os.MkdirAll(targetDir, os.ModePerm) diff --git a/src/def.go b/src/def.go index 2e47323..e36f08b 100644 --- a/src/def.go +++ b/src/def.go @@ -44,7 +44,7 @@ import ( const ( /* Build Constants */ SYSTEM_NAME = "Zoraxy" - SYSTEM_VERSION = "3.2.4" + SYSTEM_VERSION = "3.2.5" DEVELOPMENT_BUILD = false /* System Constants */ @@ -63,14 +63,19 @@ const ( LOG_EXTENSION = ".log" STATISTIC_AUTO_SAVE_INTERVAL = 600 /* Seconds */ - /* Configuration Folder Storage Path Constants */ - CONF_HTTP_PROXY = "./conf/proxy" - CONF_STREAM_PROXY = "./conf/streamproxy" - CONF_CERT_STORE = "./conf/certs" - CONF_REDIRECTION = "./conf/redirect" - CONF_ACCESS_RULE = "./conf/access" - CONF_PATH_RULE = "./conf/rules/pathrules" - CONF_PLUGIN_GROUPS = "./conf/plugin_groups.json" + /* + Configuration Folder Storage Path Constants + Note: No tailing slash in the path + */ + CONF_FOLDER = "./conf" + CONF_HTTP_PROXY = CONF_FOLDER + "/proxy" + CONF_STREAM_PROXY = CONF_FOLDER + "/streamproxy" + CONF_CERT_STORE = CONF_FOLDER + "/certs" + CONF_REDIRECTION = CONF_FOLDER + "/redirect" + CONF_ACCESS_RULE = CONF_FOLDER + "/access" + CONF_PATH_RULE = CONF_FOLDER + "/rules/pathrules" + CONF_PLUGIN_GROUPS = CONF_FOLDER + "/plugin_groups.json" + CONF_GEODB_PATH = CONF_FOLDER + "/geodb" ) /* System Startup Flags */ diff --git a/src/main.go b/src/main.go index f577d50..c848f59 100644 --- a/src/main.go +++ b/src/main.go @@ -69,7 +69,7 @@ func main() { os.Exit(0) } if *geoDbUpdate { - geodb.DownloadGeoDBUpdate("./conf/geodb") + geodb.DownloadGeoDBUpdate(CONF_GEODB_PATH) os.Exit(0) } diff --git a/src/reverseproxy.go b/src/reverseproxy.go index 6bc5e07..61c14e9 100644 --- a/src/reverseproxy.go +++ b/src/reverseproxy.go @@ -135,7 +135,7 @@ func ReverseProxtInit() { Load all conf from files */ - confs, _ := filepath.Glob("./conf/proxy/*.config") + confs, _ := filepath.Glob(CONF_HTTP_PROXY + "/*.config") for _, conf := range confs { err := LoadReverseProxyConfig(conf) if err != nil {