From 30123bc023e195bf2bbd4102b5414f045d27897b Mon Sep 17 00:00:00 2001 From: redanthrax Date: Wed, 15 Jun 2022 20:04:57 -0700 Subject: [PATCH] updates for testing and windows --- agent/agent_windows.go | 2 +- agent/install.go | 7 +++++++ agent/install_linux.go | 2 +- agent/install_windows.go | 7 +++++++ shared/notest.go | 5 +++++ shared/test.go | 5 +++++ 6 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 shared/notest.go create mode 100644 shared/test.go diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 0912cd2..9df3eb5 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -797,7 +797,7 @@ func (a *Agent) RecoverMesh() { } func (a *Agent) getMeshNodeID() (string, error) { - out, err := CMD(a.MeshSystemEXE, []string{"-nodeid"}, 10, false) + out, err := CMD(a.MeshSystemBin, []string{"-nodeid"}, 10, false) if err != nil { a.Logger.Debugln(err) return "", err diff --git a/agent/install.go b/agent/install.go index af3654e..6beaefb 100644 --- a/agent/install.go +++ b/agent/install.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "github.com/amidaware/rmmagent/shared" "github.com/go-resty/resty/v2" trmm "github.com/wh1te909/trmm-shared" ) @@ -251,10 +252,16 @@ func (a *Agent) Install(i *Installer) { time.Sleep(1 * time.Second) a.Logger.Infoln("Starting service...") out := a.ControlService(winSvcName, "start") + + if shared.TEST { + goto SKIPSTART; + } + if !out.Success { a.installerMsg(out.ErrorMsg, "error", i.Silent) } + SKIPSTART: a.Logger.Infoln("Skipping service start in test.") a.Logger.Infoln("Adding windows defender exclusions") a.addDefenderExlusions() diff --git a/agent/install_linux.go b/agent/install_linux.go index 3d2251d..915b111 100644 --- a/agent/install_linux.go +++ b/agent/install_linux.go @@ -41,7 +41,7 @@ func createAgentConfig(baseurl, agentid, apiurl, token, agentpk, cert, proxy, me viper.Set("meshdir", meshdir) viper.SetConfigPermissions(0660) configLocation := "/etc/tacticalagent" - if strings.HasSuffix(os.Args[0], ".test") { + if shared.TEST { configLocation = "tacticalagent" } diff --git a/agent/install_windows.go b/agent/install_windows.go index 3f8b630..f145757 100644 --- a/agent/install_windows.go +++ b/agent/install_windows.go @@ -17,12 +17,14 @@ import ( "os" "path/filepath" + "github.com/amidaware/rmmagent/shared" "github.com/gonutz/w32/v2" "golang.org/x/sys/windows/registry" ) func createAgentConfig(baseurl, agentid, apiurl, token, agentpk, cert, proxy, meshdir string) { k, _, err := registry.CreateKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS) + if err != nil { log.Fatalln("Error creating registry key:", err) } @@ -78,6 +80,11 @@ func createAgentConfig(baseurl, agentid, apiurl, token, agentpk, cert, proxy, me func (a *Agent) checkExistingAndRemove(silent bool) { hasReg := false _, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS) + if shared.TEST { + err = nil + _, err = registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS) + } + if err == nil { hasReg = true } diff --git a/shared/notest.go b/shared/notest.go new file mode 100644 index 0000000..c79656a --- /dev/null +++ b/shared/notest.go @@ -0,0 +1,5 @@ +//go:build !TEST + +package shared + +const TEST = false \ No newline at end of file diff --git a/shared/test.go b/shared/test.go new file mode 100644 index 0000000..c1dbff8 --- /dev/null +++ b/shared/test.go @@ -0,0 +1,5 @@ +//go:build TEST + +package shared + +const TEST = true \ No newline at end of file