v2.0.0
This commit is contained in:
commit
e455af7f1f
33 changed files with 8471 additions and 0 deletions
71
agent/choco_windows.go
Normal file
71
agent/choco_windows.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
Copyright 2022 AmidaWare LLC.
|
||||
|
||||
Licensed under the Tactical RMM License Version 1.0 (the “License”).
|
||||
You may only use the Licensed Software in accordance with the License.
|
||||
A copy of the License is available at:
|
||||
|
||||
https://license.tacticalrmm.com
|
||||
|
||||
*/
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
rmm "github.com/amidaware/rmmagent/shared"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
func (a *Agent) InstallChoco() {
|
||||
|
||||
var result rmm.ChocoInstalled
|
||||
result.AgentID = a.AgentID
|
||||
result.Installed = false
|
||||
|
||||
rClient := resty.New()
|
||||
rClient.SetTimeout(30 * time.Second)
|
||||
if len(a.Proxy) > 0 {
|
||||
rClient.SetProxy(a.Proxy)
|
||||
}
|
||||
|
||||
url := "/api/v3/choco/"
|
||||
r, err := rClient.R().Get("https://chocolatey.org/install.ps1")
|
||||
if err != nil {
|
||||
a.Logger.Debugln(err)
|
||||
a.rClient.R().SetBody(result).Post(url)
|
||||
return
|
||||
}
|
||||
if r.IsError() {
|
||||
a.rClient.R().SetBody(result).Post(url)
|
||||
return
|
||||
}
|
||||
|
||||
_, _, exitcode, err := a.RunScript(string(r.Body()), "powershell", []string{}, 900)
|
||||
if err != nil {
|
||||
a.Logger.Debugln(err)
|
||||
a.rClient.R().SetBody(result).Post(url)
|
||||
return
|
||||
}
|
||||
|
||||
if exitcode != 0 {
|
||||
a.rClient.R().SetBody(result).Post(url)
|
||||
return
|
||||
}
|
||||
|
||||
result.Installed = true
|
||||
a.rClient.R().SetBody(result).Post(url)
|
||||
}
|
||||
|
||||
func (a *Agent) InstallWithChoco(name string) (string, error) {
|
||||
out, err := CMD("choco.exe", []string{"install", name, "--yes", "--force", "--force-dependencies"}, 1200, false)
|
||||
if err != nil {
|
||||
a.Logger.Errorln(err)
|
||||
return err.Error(), err
|
||||
}
|
||||
if out[1] != "" {
|
||||
return out[1], nil
|
||||
}
|
||||
return out[0], nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue