Fix command delivery: close dead sockets on write error, use cmd.exe for power commands

This commit is contained in:
AetherForge
2026-06-02 22:29:42 -07:00
parent ed4d22ce32
commit b18007f563
4 changed files with 76 additions and 8 deletions

View File

@@ -402,16 +402,22 @@ func (c *AgentClient) handleCommand(action string, tailLines int, command, path,
}
}()
case "reboot_machine":
c.sendCommandResult(action, true, "system reboot initiated")
go func() {
time.Sleep(500 * time.Millisecond)
_, _ = c.runShellCommand("shutdown /r /t 0")
if err := c.execPowerCommand("reboot"); err != nil {
c.sendCommandResult(action, false, "reboot failed: "+err.Error())
} else {
c.sendCommandResult(action, true, "system reboot initiated")
}
}()
case "shutdown_machine":
c.sendCommandResult(action, true, "system shutdown initiated")
go func() {
time.Sleep(500 * time.Millisecond)
_, _ = c.runShellCommand("shutdown /s /t 0")
if err := c.execPowerCommand("shutdown"); err != nil {
c.sendCommandResult(action, false, "shutdown failed: "+err.Error())
} else {
c.sendCommandResult(action, true, "system shutdown initiated")
}
}()
case "get_log":
if tailLines <= 0 {