diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3c4f05a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +name: Run tests + +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + name: Run tests + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: '1.18.3' + + - name: Ensure linux agent compiles + run: | + ARCHS='amd64 386 arm64 arm' + for i in ${ARCHS}; do + env CGO_ENABLED=0 GOOS=linux GOARCH=${i} go build -ldflags "-s -w" + done + + - name: Ensure windows agent compiles + run: | + ARCHS='amd64 386' + for i in ${ARCHS}; do + env CGO_ENABLED=0 GOOS=windows GOARCH=${i} go build -ldflags "-s -w" + done + + - name: Ensure mac agent compiles + run: | + ARCHS='amd64 arm64' + for i in ${ARCHS}; do + env CGO_ENABLED=0 GOOS=darwin GOARCH=${i} go build -ldflags "-s -w" + done + + - name: Ensure freebsd agent compiles + run: | + ARCHS='amd64 386 arm64 arm' + for i in ${ARCHS}; do + env CGO_ENABLED=0 GOOS=freebsd GOARCH=${i} go build -ldflags "-s -w" + done diff --git a/.gitignore b/.gitignore index ba76619..363cf4a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,3 @@ *.bmp build/Output tacticalagent-v* -tacticalagent -agent/testargs.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 432fcfd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch file", - "type": "go", - "request": "launch", - "mode": "debug", - "env": {}, - "args": ["-m", "svc", "-log", "DEBUG", "-logto", "stdout"], - "buildFlags": "-tags=DEBUG", - "program": "${workspaceRoot}" - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 3ff7ba4..4a236a8 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,4 @@ Add to settings.json "-vet=off" ], "go.testTags": "TEST", -``` \ No newline at end of file +``` diff --git a/agent/agent_unix.go b/agent/agent_unix.go index 12d96a8..ddd5bac 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -281,14 +281,14 @@ func (a *Agent) NixMeshNodeID() string { meshSuccess := false a.Logger.Debugln("Getting mesh node id") - if !trmm.FileExists(a.MeshSystemBin) { - a.Logger.Debugln(a.MeshSystemBin, "does not exist. Skipping.") + if !trmm.FileExists(a.MeshSystemEXE) { + a.Logger.Debugln(a.MeshSystemEXE, "does not exist. Skipping.") return "" } opts := a.NewCMDOpts() opts.IsExecutable = true - opts.Shell = a.MeshSystemBin + opts.Shell = a.MeshSystemEXE opts.Command = "-nodeid" for !meshSuccess { diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 3aad884..64ca2b6 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.MeshSystemBin, []string{"-nodeid"}, 10, false) + out, err := CMD(a.MeshSystemEXE, []string{"-nodeid"}, 10, false) if err != nil { a.Logger.Debugln(err) return "", err @@ -835,6 +835,11 @@ func (a *Agent) InstallService() error { // skip on first call of inno setup if this is a new install _, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS) + if err != nil { + return nil + } + + s, err := service.New(a, a.ServiceConfig) if err != nil { return err } diff --git a/agent/install.go b/agent/install.go index af3654e..db8fad3 100644 --- a/agent/install.go +++ b/agent/install.go @@ -138,19 +138,11 @@ func (a *Agent) Install(i *Installer) { rClient.SetProxy(i.Proxy) } - var arch string - switch a.Arch { - case "x86_64": - arch = "64" - case "x86": - arch = "32" - } - - var installerMeshSystemBin string + var installerMeshSystemEXE string if len(i.MeshDir) > 0 { - installerMeshSystemBin = filepath.Join(i.MeshDir, "MeshAgent.exe") + installerMeshSystemEXE = filepath.Join(i.MeshDir, "MeshAgent.exe") } else { - installerMeshSystemBin = a.MeshSystemBin + installerMeshSystemEXE = a.MeshSystemEXE } var meshNodeID string @@ -159,7 +151,7 @@ func (a *Agent) Install(i *Installer) { mesh := filepath.Join(a.ProgramDir, a.MeshInstaller) if i.LocalMesh == "" { a.Logger.Infoln("Downloading mesh agent...") - payload := map[string]string{"arch": arch, "plat": a.Platform} + payload := map[string]string{"goarch": a.GoArch, "plat": a.Platform} r, err := rClient.R().SetBody(payload).SetOutput(mesh).Post(fmt.Sprintf("%s/api/v3/meshexe/", baseURL)) if err != nil { a.installerMsg(fmt.Sprintf("Failed to download mesh agent: %s", err.Error()), "error", i.Silent) @@ -178,7 +170,7 @@ func (a *Agent) Install(i *Installer) { a.Logger.Debugln("Mesh agent:", mesh) time.Sleep(1 * time.Second) - meshNodeID, err = a.installMesh(mesh, installerMeshSystemBin, i.Proxy) + meshNodeID, err = a.installMesh(mesh, installerMeshSystemEXE, i.Proxy) if err != nil { a.installerMsg(fmt.Sprintf("Failed to install mesh agent: %s", err.Error()), "error", i.Silent) } diff --git a/agent/install_unix.go b/agent/install_unix.go index f41da59..ee7654e 100644 --- a/agent/install_unix.go +++ b/agent/install_unix.go @@ -19,6 +19,10 @@ import ( "github.com/spf13/viper" ) +const ( + etcConfig = "/etc/tacticalagent" +) + func (a *Agent) checkExistingAndRemove(silent bool) {} func (a *Agent) installerMsg(msg, alert string, silent bool) { @@ -40,10 +44,7 @@ func createAgentConfig(baseurl, agentid, apiurl, token, agentpk, cert, proxy, me viper.Set("proxy", proxy) viper.Set("meshdir", meshdir) viper.SetConfigPermissions(0660) - configLocation := "/etc/tacticalagent" - - err := viper.SafeWriteConfigAs(configLocation) - + err := viper.SafeWriteConfigAs(etcConfig) if err != nil { log.Fatalln("createAgentConfig", err) } diff --git a/agent/install_windows.go b/agent/install_windows.go index be46f2e..3f8b630 100644 --- a/agent/install_windows.go +++ b/agent/install_windows.go @@ -78,7 +78,6 @@ 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 err == nil { hasReg = true } diff --git a/agent/rpc.go b/agent/rpc.go index 2990135..7d24d0b 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -49,10 +49,6 @@ var ( ) func (a *Agent) RunRPC() { - if rmm.DEBUG { - a.Logger.Infoln("DEBUG BUILD STARTED") - } - a.Logger.Infoln("Agent service started") go a.RunAsService() var wg sync.WaitGroup diff --git a/agent/testargs.json.example b/agent/testargs.json.example deleted file mode 100644 index c4ba6c8..0000000 --- a/agent/testargs.json.example +++ /dev/null @@ -1,19 +0,0 @@ -{ - "api": "", - "clientid": 1, - "siteid": 1, - "description": "", - "agenttype": "workstation", - "power": false, - "rdp": false, - "ping": false, - "token": "", - "localmesh": "", - "cert": "", - "proxy": "", - "timeout": 30, - "silent": true, - "nomesh": true, - "meshdir": "", - "meshnodeid": "" -} \ No newline at end of file diff --git a/build/setup.iss b/build/setup.iss index 99bcd12..fd64abe 100644 --- a/build/setup.iss +++ b/build/setup.iss @@ -1,5 +1,5 @@ #define MyAppName "Tactical RMM Agent" -#define MyAppVersion "2.0.4" +#define MyAppVersion "2.1.0-dev" #define MyAppPublisher "AmidaWare LLC" #define MyAppURL "https://github.com/amidaware" #define MyAppExeName "tacticalrmm.exe" diff --git a/main.go b/main.go index c0f8dae..1042e35 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( ) var ( - version = "development" + version = "2.1.0-dev" log = logrus.New() logFile *os.File ) diff --git a/shared/debug.go b/shared/debug.go deleted file mode 100644 index 0893720..0000000 --- a/shared/debug.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build DEBUG - -package shared - -const DEBUG = true \ No newline at end of file diff --git a/shared/nodebug.go b/shared/nodebug.go deleted file mode 100644 index e2032ee..0000000 --- a/shared/nodebug.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build !DEBUG - -package shared - -const DEBUG = false \ No newline at end of file diff --git a/shared/notest.go b/shared/notest.go deleted file mode 100644 index c79656a..0000000 --- a/shared/notest.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build !TEST - -package shared - -const TEST = false \ No newline at end of file diff --git a/shared/test.go b/shared/test.go deleted file mode 100644 index c1dbff8..0000000 --- a/shared/test.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build TEST - -package shared - -const TEST = true \ No newline at end of file