Add base system configuration commands for agent-wdd

- Implemented new base commands for system configuration:
  * swap: Disable system swap
  * selinux: Disable SELinux
  * firewall: Stop and disable firewalld and ufw
  * sysconfig: Modify system sysctl configuration
  * ssh: Add SSH-related subcommands (key, port, config)

- Updated Config.go to initialize ConfigCache with default values
- Added new utility functions in FileUtils.go for file content manipulation
- Extended Excutor.go with HardCodeCommandExecutor method
This commit is contained in:
zeaslity
2025-02-27 10:57:58 +08:00
parent e8f0e0d4a9
commit 16c041e3eb
5 changed files with 578 additions and 1 deletions

View File

@@ -161,6 +161,37 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) (ok bool, resultLog []s
return success, output
}
// HardCodeCommandExecutor 执行硬编码命令,返回执行结果和输出内容
// hardCodeCommand: 硬编码命令,如 []string{"echo", "hello"}
// 返回值:
//
// bool - 命令是否执行成功true为成功false为失败
// []string - 合并后的标准输出和标准错误内容(按行分割)
func HardCodeCommandExecutor(hardCodeCommand string) (ok bool, resultLog []string) {
log.Info("[Excutor] - start => %v", hardCodeCommand)
if hardCodeCommand == "" {
return false, nil
}
// 执行命令
cmd := exec.Command(hardCodeCommand)
// 执行命令并获取错误信息
err := cmd.Run()
// 合并输出结果
stdoutBuf := bytes.Buffer{}
stderrBuf := bytes.Buffer{}
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
output := mergeOutput(&stdoutBuf, &stderrBuf)
return err == nil, output
}
func main() {
// 成功案例
success, output := SingleLineCommandExecutor([]string{"ls", "-l"})