From ebd316a7f100896266d62e7be47194baf0348259 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Tue, 31 Dec 2024 21:14:37 +0800 Subject: [PATCH] Exposed log and db filepath setting --- src/config.go | 10 ++++++++-- src/def.go | 10 +++++++--- src/main.go | 2 +- src/reverseproxy.go | 2 +- src/start.go | 8 ++++---- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/config.go b/src/config.go index cf67d06..eacea02 100644 --- a/src/config.go +++ b/src/config.go @@ -167,7 +167,11 @@ func ExportConfigAsZip(w http.ResponseWriter, r *http.Request) { } // Specify the folder path to be zipped - folderPath := "./conf/" + if !utils.FileExists("./conf") { + SystemWideLogger.PrintAndLog("Backup", "Configuration folder not found", nil) + return + } + folderPath := "./conf" // Set the Content-Type header to indicate it's a zip file w.Header().Set("Content-Type", "application/zip") @@ -222,7 +226,7 @@ func ExportConfigAsZip(w http.ResponseWriter, r *http.Request) { } // Open the file on disk - file, err := os.Open("sys.db") + file, err := os.Open("./sys.db") if err != nil { SystemWideLogger.PrintAndLog("Backup", "Unable to open sysdb", err) return @@ -271,6 +275,8 @@ func ImportConfigFromZip(w http.ResponseWriter, r *http.Request) { targetDir := "./conf" 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()))) } diff --git a/src/def.go b/src/def.go index b484945..0ebeb5a 100644 --- a/src/def.go +++ b/src/def.go @@ -46,7 +46,6 @@ const ( DEVELOPMENT_BUILD = false /* Development: Set to false to use embedded web fs */ /* System Constants */ - DATABASE_PATH = "sys.db" TMP_FOLDER = "./tmp" WEBSERV_DEFAULT_PORT = 5487 MDNS_HOSTNAME_PREFIX = "zoraxy_" /* Follow by node UUID */ @@ -59,7 +58,6 @@ const ( ACME_AUTORENEW_CONFIG_PATH = "./conf/acme_conf.json" CSRF_COOKIENAME = "zoraxy_csrf" LOG_PREFIX = "zr" - LOG_FOLDER = "./log" LOG_EXTENSION = ".log" /* Configuration Folder Storage Path Constants */ @@ -86,10 +84,16 @@ var ( acmeAutoRenewInterval = flag.Int("autorenew", 86400, "ACME auto TLS/SSL certificate renew check interval (seconds)") acmeCertAutoRenewDays = flag.Int("earlyrenew", 30, "Number of days to early renew a soon expiring certificate (days)") enableHighSpeedGeoIPLookup = flag.Bool("fastgeoip", false, "Enable high speed geoip lookup, require 1GB extra memory (Not recommend for low end devices)") - staticWebServerRoot = flag.String("webroot", "./www", "Static web server root folder. Only allow chnage in start paramters") allowWebFileManager = flag.Bool("webfm", true, "Enable web file manager for static web server root folder") enableAutoUpdate = flag.Bool("cfgupgrade", true, "Enable auto config upgrade if breaking change is detected") + /* Path Configuration Flags */ + //path_database = flag.String("dbpath", "./sys.db", "Database path") + //path_conf = flag.String("conf", "./conf", "Configuration folder path") + path_uuid = flag.String("uuid", "./sys.uuid", "sys.uuid file path") + path_logFile = flag.String("log", "./log", "Log folder path") + path_webserver = flag.String("webroot", "./www", "Static web server root folder. Only allow change in start paramters") + /* Maintaince Function Flags */ geoDbUpdate = flag.Bool("update_geoip", false, "Download the latest GeoIP data and exit") ) diff --git a/src/main.go b/src/main.go index 0fd0618..67b71bf 100644 --- a/src/main.go +++ b/src/main.go @@ -86,7 +86,7 @@ func main() { SetupCloseHandler() //Read or create the system uuid - uuidRecord := "./sys.uuid" + uuidRecord := *path_uuid if !utils.FileExists(uuidRecord) { newSystemUUID := uuid.New().String() os.WriteFile(uuidRecord, []byte(newSystemUUID), 0775) diff --git a/src/reverseproxy.go b/src/reverseproxy.go index 159d38f..c55b6db 100644 --- a/src/reverseproxy.go +++ b/src/reverseproxy.go @@ -96,7 +96,7 @@ func ReverseProxtInit() { RedirectRuleTable: redirectTable, GeodbStore: geodbStore, StatisticCollector: statisticCollector, - WebDirectory: *staticWebServerRoot, + WebDirectory: *path_webserver, AccessController: accessController, AutheliaRouter: autheliaRouter, LoadBalancer: loadBalancer, diff --git a/src/start.go b/src/start.go index bdf0a90..d237b8a 100644 --- a/src/start.go +++ b/src/start.go @@ -54,14 +54,14 @@ var ( func startupSequence() { //Start a system wide logger and log viewer - l, err := logger.NewLogger(LOG_PREFIX, LOG_FOLDER) + l, err := logger.NewLogger(LOG_PREFIX, *path_logFile) if err == nil { SystemWideLogger = l } else { panic(err) } LogViewer = logviewer.NewLogViewer(&logviewer.ViewerOption{ - RootFolder: LOG_FOLDER, + RootFolder: *path_logFile, Extension: LOG_EXTENSION, }) @@ -73,7 +73,7 @@ func startupSequence() { backendType = dbinc.BackendBoltDB } l.PrintAndLog("database", "Using "+backendType.String()+" as the database backend", nil) - db, err := database.NewDatabase(DATABASE_PATH, backendType) + db, err := database.NewDatabase("./sys.db", backendType) if err != nil { log.Fatal(err) } @@ -158,7 +158,7 @@ func startupSequence() { staticWebServer = webserv.NewWebServer(&webserv.WebServerOptions{ Sysdb: sysdb, Port: strconv.Itoa(WEBSERV_DEFAULT_PORT), //Default Port - WebRoot: *staticWebServerRoot, + WebRoot: *path_webserver, EnableDirectoryListing: true, EnableWebDirManager: *allowWebFileManager, Logger: SystemWideLogger,