From 99480f3fe33832602d20d6fa4a9df36c533d9fa0 Mon Sep 17 00:00:00 2001 From: Fimeg Date: Sat, 1 Nov 2025 21:56:31 -0400 Subject: [PATCH] fix: resolve frontend approval error and add invalid command handling - Added missing approveMultiple function to updateApi - Fixed API endpoint from /updates/bulk-approve to /updates/approve - Enhanced invalid command handling in both Linux and Windows agents - Agents now report unknown command types as failed commands back to server --- aggregator-agent/cmd/agent/main.go | 15 +++++++++++- aggregator-agent/internal/service/windows.go | 24 ++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/aggregator-agent/cmd/agent/main.go b/aggregator-agent/cmd/agent/main.go index 88ae76a..50cf0f1 100644 --- a/aggregator-agent/cmd/agent/main.go +++ b/aggregator-agent/cmd/agent/main.go @@ -695,7 +695,20 @@ func runAgent(cfg *config.Config) error { log.Printf("[Reboot] Error processing reboot command: %v\n", err) } default: - log.Printf("Unknown command type: %s\n", cmd.Type) + log.Printf("Unknown command type: %s - reporting as invalid command\n", cmd.Type) + // Report invalid command back to server + logReport := client.LogReport{ + CommandID: cmd.ID, + Action: "process_command", + Result: "failed", + Stdout: "", + Stderr: fmt.Sprintf("Invalid command type: %s", cmd.Type), + ExitCode: 1, + DurationSeconds: 0, + } + if reportErr := reportLogWithAck(apiClient, cfg, ackTracker, logReport); reportErr != nil { + log.Printf("Failed to report invalid command result: %v", reportErr) + } } } diff --git a/aggregator-agent/internal/service/windows.go b/aggregator-agent/internal/service/windows.go index 02cbf6a..b9f4be6 100644 --- a/aggregator-agent/internal/service/windows.go +++ b/aggregator-agent/internal/service/windows.go @@ -209,16 +209,16 @@ func (s *redflagService) runAgent() { } } - if len(commands) == 0 { + if len(commands.Commands) == 0 { log.Printf("Check-in successful - no new commands") elog.Info(1, "Check-in successful - no new commands") } else { - log.Printf("Check-in successful - received %d command(s)", len(commands)) - elog.Info(1, fmt.Sprintf("Check-in successful - received %d command(s)", len(commands))) + log.Printf("Check-in successful - received %d command(s)", len(commands.Commands)) + elog.Info(1, fmt.Sprintf("Check-in successful - received %d command(s)", len(commands.Commands))) } // Process each command with full implementation - for _, cmd := range commands { + for _, cmd := range commands.Commands { log.Printf("Processing command: %s (%s)\n", cmd.Type, cmd.ID) elog.Info(1, fmt.Sprintf("Processing command: %s (%s)", cmd.Type, cmd.ID)) @@ -256,8 +256,22 @@ func (s *redflagService) runAgent() { elog.Error(1, fmt.Sprintf("Error disabling heartbeat: %v", err)) } default: - log.Printf("Unknown command type: %s\n", cmd.Type) + log.Printf("Unknown command type: %s - reporting as invalid command\n", cmd.Type) elog.Error(1, fmt.Sprintf("Unknown command type: %s", cmd.Type)) + // Report invalid command back to server + logReport := client.LogReport{ + CommandID: cmd.ID, + Action: "process_command", + Result: "failed", + Stdout: "", + Stderr: fmt.Sprintf("Invalid command type: %s", cmd.Type), + ExitCode: 1, + DurationSeconds: 0, + } + if reportErr := apiClient.ReportLog(s.agent.AgentID, logReport); reportErr != nil { + log.Printf("Failed to report invalid command result: %v", reportErr) + elog.Error(1, fmt.Sprintf("Failed to report invalid command result: %v", reportErr)) + } } }