diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 5b334d9..c322432 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -8,7 +8,7 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti $SERVER_NAME = if ($env:SERVER_NAME -ne $null) { $env:SERVER_NAME } else { "wazuh-agent-status" } $CLIENT_NAME = if ($env:CLIENT_NAME -ne $null) { $env:CLIENT_NAME } else { "wazuh-agent-status-client" } $PROFILE = if ($env:PROFILE -ne $null) { $env:PROFILE } else { "user" } -$APP_VERSION = if ($env:APP_VERSION -ne $null) { $env:APP_VERSION } else { "0.2.7" } +$APP_VERSION = if ($env:APP_VERSION -ne $null) { $env:APP_VERSION } else { "0.3.0" } if ($PROFILE -eq "admin") { $WAS_VERSION = $APP_VERSION diff --git a/scripts/install.sh b/scripts/install.sh index 41accd1..b0c6cfe 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -19,7 +19,7 @@ DESKTOP_UNIT_FOLDER=${DESKTOP_UNIT_FOLDER:-"$HOME/.config/autostart"} DESKTOP_UNIT_FILE=${DESKTOP_UNIT_FILE:-"$DESKTOP_UNIT_FOLDER/$CLIENT_NAME.desktop"} PROFILE=${PROFILE:-"user"} -APP_VERSION=${APP_VERSION:-"0.2.7"} +APP_VERSION=${APP_VERSION:-"0.3.0"} # Assign app version based on profile case "$PROFILE" in diff --git a/wazuh-agent-status-client/main.go b/wazuh-agent-status-client/main.go index 71d4156..adac631 100644 --- a/wazuh-agent-status-client/main.go +++ b/wazuh-agent-status-client/main.go @@ -6,11 +6,11 @@ import ( "fmt" "log" "net" + "os" + "path/filepath" "runtime" "strings" "time" - "os" - "path/filepath" "github.com/getlantern/systray" "gopkg.in/natefinch/lumberjack.v2" @@ -21,28 +21,45 @@ var embeddedFiles embed.FS var ( statusItem, connectionItem, updateItem, versionItem *systray.MenuItem - enabledIcon, disabledIcon []byte - isMonitoringUpdate bool + enabledIcon, disabledIcon []byte + isMonitoringUpdate bool ) -// Set up log rotation using lumberjack.func init() { - func init() { - homeDir, err := os.UserHomeDir() - if err != nil { - log.Fatalf("failed to get home directory: %v", err) - } - - logFilePath := filepath.Join(homeDir, ".wazuh-agent-status-client.log") - - log.SetOutput(&lumberjack.Logger{ - Filename: logFilePath, - MaxSize: 10, - MaxBackups: 3, - MaxAge: 28, - Compress: true, - }) +func getUserLogFilePath() string { + var logDir string + + switch runtime.GOOS { + case "linux": + logDir = filepath.Join(os.Getenv("HOME"), ".wazuh") + case "darwin": + logDir = filepath.Join(os.Getenv("HOME"), "Library", "Logs", "wazuh") + case "windows": + logDir = filepath.Join(os.Getenv("APPDATA"), "wazuh", "logs") + default: + logDir = "./logs" // Fallback } + // Ensure the directory exists + if err := os.MkdirAll(logDir, 0755); err != nil { + log.Fatalf("failed to create log directory: %v", err) + } + + return filepath.Join(logDir, "wazuh-agent-status-client.log") +} + +// Set up log rotation using lumberjack.func init() { +func init() { + logFilePath := getUserLogFilePath() + + log.SetOutput(&lumberjack.Logger{ + Filename: logFilePath, + MaxSize: 10, + MaxBackups: 3, + MaxAge: 30, + Compress: true, + }) +} + // Main entry point func main() { log.Println("Starting frontend...") @@ -309,4 +326,4 @@ func getIconPath() string { // onExit is called when the application is terminated func onExit() { log.Println("Frontend application stopped") -} \ No newline at end of file +} diff --git a/wazuh-agent-status/main.go b/wazuh-agent-status/main.go index cc29290..038e6ce 100644 --- a/wazuh-agent-status/main.go +++ b/wazuh-agent-status/main.go @@ -11,29 +11,48 @@ import ( "io" "os" "os/exec" - "path/filepath" + "gopkg.in/natefinch/lumberjack.v2" ) const versionURL = "https://raw.githubusercontent.com/ADORSYS-GIS/wazuh-agent/main/version.txt" var isUpdateInProgress bool // Flag to track if the update is in progress -func init() { - homeDir, err := os.UserHomeDir() - if err != nil { - log.Fatalf("failed to get home directory: %v", err) +func getSystemLogFilePath() string { + var logDir string + + switch runtime.GOOS { + case "linux", "darwin": + logDir = "/var/log" + case "windows": + logDir = "C:\\ProgramData\\wazuh\\logs" + default: + logDir = "./logs" + } + + // Ensure the directory exists (Windows only, since /var/log usually exists) + if runtime.GOOS == "windows" { + if err := os.MkdirAll(logDir, 0755); err != nil { + log.Fatalf("failed to create log directory: %v", err) + } } - logFilePath := filepath.Join(homeDir, "wazuh-agent-status.log") + return filepath.Join(logDir, "wazuh-agent-status.log") +} + +func init() { + logFilePath := getSystemLogFilePath() log.SetOutput(&lumberjack.Logger{ - Filename: logFilePath, - MaxSize: 10, - MaxBackups: 3, - MaxAge: 28, - Compress: true, + Filename: logFilePath, + MaxSize: 10, // MB + MaxBackups: 3, + MaxAge: 28, // days + Compress: true, }) + + log.Printf("Logging to: %s", logFilePath) // Debugging info } func main() {