From 78277d341dffaab79e6f6bb94c72dec59d9d2bc2 Mon Sep 17 00:00:00 2001 From: redanthrax Date: Wed, 8 Jun 2022 13:14:22 -0700 Subject: [PATCH] additional mac support - mesh --- README.md | 5 ++++- agent/agent.go | 4 ++++ agent/agent_darwin.go | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d065784..b417cb2 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,7 @@ https://github.com/amidaware/tacticalrmm env CGO_ENABLED=0 GOOS= GOARCH= go build -ldflags "-s -w" ``` - +#### building the mac agent +``` +env GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" +``` \ No newline at end of file diff --git a/agent/agent.go b/agent/agent.go index 567d56a..cbac3d1 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -125,6 +125,10 @@ func New(logger *logrus.Logger, version string) *Agent { MeshSysExe = "/opt/tacticalmesh/meshagent" } + if runtime.GOOS == "darwin" { + MeshSysExe = "/opt/tacticalmesh/meshagent" + } + svcConf := &service.Config{ Executable: exe, Name: winSvcName, diff --git a/agent/agent_darwin.go b/agent/agent_darwin.go index d1d851c..1ee45bd 100644 --- a/agent/agent_darwin.go +++ b/agent/agent_darwin.go @@ -159,9 +159,41 @@ func (a *Agent) AgentUpdate(url, inno, version string) {} func (a *Agent) AgentUninstall(code string) {} -func (a *Agent) NixMeshNodeID() string { return "" } +func (a *Agent) NixMeshNodeID() string { + var meshNodeID string + meshSuccess := false + a.Logger.Debugln("Getting mesh node id") -func (a *Agent) getMeshNodeID() (string, error) { return "", nil } + if !trmm.FileExists(a.MeshSystemEXE) { + a.Logger.Debugln(a.MeshSystemEXE, "does not exist. Skipping.") + return "" + } + + opts := a.NewCMDOpts() + opts.IsExecutable = true + opts.Shell = a.MeshSystemEXE + opts.Command = "-nodeid" + + for !meshSuccess { + out := a.CmdV2(opts) + meshNodeID = out.Stdout + a.Logger.Debugln("Stdout:", out.Stdout) + a.Logger.Debugln("Stderr:", out.Stderr) + if meshNodeID == "" { + time.Sleep(1 * time.Second) + continue + } else if strings.Contains(strings.ToLower(meshNodeID), "graphical version") || strings.Contains(strings.ToLower(meshNodeID), "zenity") { + time.Sleep(1 * time.Second) + continue + } + meshSuccess = true + } + return meshNodeID +} + +func (a *Agent) getMeshNodeID() (string, error) { + return a.NixMeshNodeID(), nil +} func (a *Agent) RecoverMesh() {}