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
This commit is contained in:
@@ -695,7 +695,20 @@ func runAgent(cfg *config.Config) error {
|
|||||||
log.Printf("[Reboot] Error processing reboot command: %v\n", err)
|
log.Printf("[Reboot] Error processing reboot command: %v\n", err)
|
||||||
}
|
}
|
||||||
default:
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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")
|
log.Printf("Check-in successful - no new commands")
|
||||||
elog.Info(1, "Check-in successful - no new commands")
|
elog.Info(1, "Check-in successful - no new commands")
|
||||||
} else {
|
} else {
|
||||||
log.Printf("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)))
|
elog.Info(1, fmt.Sprintf("Check-in successful - received %d command(s)", len(commands.Commands)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process each command with full implementation
|
// 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)
|
log.Printf("Processing command: %s (%s)\n", cmd.Type, cmd.ID)
|
||||||
elog.Info(1, fmt.Sprintf("Processing command: %s (%s)", 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))
|
elog.Error(1, fmt.Sprintf("Error disabling heartbeat: %v", err))
|
||||||
}
|
}
|
||||||
default:
|
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))
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user