This commit is contained in:
wh1te909 2022-11-28 23:18:22 -08:00
parent 6ac14b6d64
commit 7358907b3c
6 changed files with 13 additions and 13 deletions

View File

@ -221,7 +221,7 @@ type CmdOptions struct {
IsScript bool
IsExecutable bool
Detached bool
Env []string
EnvVars []string
}
func (a *Agent) NewCMDOpts() *CmdOptions {
@ -250,10 +250,10 @@ func (a *Agent) CmdV2(c *CmdOptions) CmdStatus {
})
}
if len(c.Env) > 0 {
if len(c.EnvVars) > 0 {
cmdOptions.BeforeExec = append(cmdOptions.BeforeExec, func(cmd *exec.Cmd) {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, c.Env...)
cmd.Env = append(cmd.Env, c.EnvVars...)
})
}

View File

@ -82,7 +82,7 @@ func NewAgentConfig() *rmm.AgentConfig {
}
}
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envs []string) (stdout, stderr string, exitcode int, e error) {
func (a *Agent) RunScript(code string, shell string, args []string, timeout int, runasuser bool, envVars []string) (stdout, stderr string, exitcode int, e error) {
content := []byte(code)
@ -158,9 +158,9 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
cmd.Stdout = &outb
cmd.Stderr = &errb
if len(envs) > 0 {
if len(envVars) > 0 {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, envs...)
cmd.Env = append(cmd.Env, envVars...)
}
if cmdErr := cmd.Start(); cmdErr != nil {

View File

@ -169,7 +169,7 @@ type ScriptCheckResult struct {
// ScriptCheck runs either bat, powershell or python script
func (a *Agent) ScriptCheck(data rmm.Check, r *resty.Client) {
start := time.Now()
stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.Env)
stdout, stderr, retcode, _ := a.RunScript(data.Script.Code, data.Script.Shell, data.ScriptArgs, data.Timeout, data.Script.RunAsUser, data.Script.EnvVars)
payload := ScriptCheckResult{
ID: data.CheckPK,

View File

@ -41,7 +41,7 @@ type NatsMsg struct {
ID int `json:"id"`
Code string `json:"code"`
RunAsUser bool `json:"run_as_user"`
Env []string `json:"env"`
EnvVars []string `json:"env_vars"`
}
var (
@ -262,7 +262,7 @@ func (a *Agent) RunRPC() {
var resultData rmm.RunScriptResp
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
start := time.Now()
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env)
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.EnvVars)
resultData.ExecTime = time.Since(start).Seconds()
resultData.ID = p.ID
@ -292,7 +292,7 @@ func (a *Agent) RunRPC() {
var retData rmm.RunScriptResp
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
start := time.Now()
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.Env)
stdout, stderr, retcode, err := a.RunScript(p.Data["code"], p.Data["shell"], p.ScriptArgs, p.Timeout, p.RunAsUser, p.EnvVars)
retData.ExecTime = time.Since(start).Seconds()
if err != nil {

View File

@ -59,7 +59,7 @@ func (a *Agent) RunTask(id int) error {
action_start := time.Now()
if action.ActionType == "script" {
stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser, action.Env)
stdout, stderr, retcode, err := a.RunScript(action.Code, action.Shell, action.Args, action.Timeout, action.RunAsUser, action.EnvVars)
if err != nil {
a.Logger.Debugln(err)

View File

@ -144,7 +144,7 @@ type Script struct {
Shell string `json:"shell"`
Code string `json:"code"`
RunAsUser bool `json:"run_as_user"`
Env []string `json:"env"`
EnvVars []string `json:"env_vars"`
}
type CheckInfo struct {
@ -191,7 +191,7 @@ type TaskAction struct {
Args []string `json:"script_args"`
Timeout int `json:"timeout"`
RunAsUser bool `json:"run_as_user"`
Env []string `json:"env"`
EnvVars []string `json:"env_vars"`
}
type AutomatedTask struct {