Fix command delivery: close dead sockets on write error, use cmd.exe for power commands
This commit is contained in:
@@ -3,10 +3,29 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// execPowerCommand runs shutdown or reboot on Unix/Linux/macOS.
|
||||
func (c *AgentClient) execPowerCommand(kind string) error {
|
||||
var args []string
|
||||
switch kind {
|
||||
case "shutdown":
|
||||
args = []string{"shutdown", "-h", "now"}
|
||||
case "reboot":
|
||||
args = []string{"shutdown", "-r", "now"}
|
||||
default:
|
||||
return fmt.Errorf("unknown power command: %s", kind)
|
||||
}
|
||||
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *AgentClient) platformRecon(action, command string) (handled bool, success bool, message string) {
|
||||
var out []byte
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user