From 2dc01e9aa06f42a7fb6e9f49297057fe9ed523ca Mon Sep 17 00:00:00 2001 From: cclohmar Date: Sat, 1 Aug 2026 16:08:56 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20use=20absolute=20config=20path=20next=20?= =?UTF-8?q?to=20binary=20=E2=80=94=20fixes=20permission=20denied=20on=20sa?= =?UTF-8?q?ve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 4b7dc82..f47781b 100644 --- a/config.go +++ b/config.go @@ -4,18 +4,26 @@ import ( "encoding/json" "log" "os" + "path/filepath" "sync" ) -// Config holds all WAF plugin settings, persisted as JSON. +// Config holds all Firewall plugin settings, persisted as JSON. type Config struct { - Enabled bool `json:"enabled"` - NodeURL string `json:"node_url"` // e.g. http://192.168.1.50:8080 - ReturnPort int `json:"return_port"` // port for inspection endpoint async callbacks - TimeoutMs int `json:"timeout_ms"` // inspection timeout in milliseconds + Enabled bool `json:"enabled"` + NodeURL string `json:"node_url"` // e.g. http://192.168.1.50:8080 + ReturnPort int `json:"return_port"` // port for async callbacks + TimeoutMs int `json:"timeout_ms"` // inspection timeout in milliseconds } -const configFile = "waf_config.json" +// configPath resolves to the config file next to the plugin binary. +func configPath() string { + exe, err := os.Executable() + if err != nil { + return "/opt/zoraxy/plugins/zoraxy-waf/waf_config.json" + } + return filepath.Join(filepath.Dir(exe), "waf_config.json") +} var ( cfg Config @@ -35,7 +43,7 @@ func loadConfig() { cfgMu.Lock() defer cfgMu.Unlock() - f, err := os.Open(configFile) + f, err := os.Open(configPath()) if err != nil { cfg = defaultConfig() return @@ -55,7 +63,7 @@ func saveConfig() error { if err != nil { return err } - return os.WriteFile(configFile, data, 0644) + return os.WriteFile(configPath(), data, 0644) } func getConfig() Config {