Merge remote-tracking branch 'upstream/develop' into BigRefactor
This commit is contained in:
commit
29e304fa4e
17 changed files with 71 additions and 88 deletions
49
.github/workflows/ci.yml
vendored
Normal file
49
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -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
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -10,5 +10,3 @@
|
||||||
*.bmp
|
*.bmp
|
||||||
build/Output
|
build/Output
|
||||||
tacticalagent-v*
|
tacticalagent-v*
|
||||||
tacticalagent
|
|
||||||
agent/testargs.json
|
|
||||||
18
.vscode/launch.json
vendored
18
.vscode/launch.json
vendored
|
|
@ -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}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -36,4 +36,4 @@ Add to settings.json
|
||||||
"-vet=off"
|
"-vet=off"
|
||||||
],
|
],
|
||||||
"go.testTags": "TEST",
|
"go.testTags": "TEST",
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -281,14 +281,14 @@ func (a *Agent) NixMeshNodeID() string {
|
||||||
meshSuccess := false
|
meshSuccess := false
|
||||||
a.Logger.Debugln("Getting mesh node id")
|
a.Logger.Debugln("Getting mesh node id")
|
||||||
|
|
||||||
if !trmm.FileExists(a.MeshSystemBin) {
|
if !trmm.FileExists(a.MeshSystemEXE) {
|
||||||
a.Logger.Debugln(a.MeshSystemBin, "does not exist. Skipping.")
|
a.Logger.Debugln(a.MeshSystemEXE, "does not exist. Skipping.")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := a.NewCMDOpts()
|
opts := a.NewCMDOpts()
|
||||||
opts.IsExecutable = true
|
opts.IsExecutable = true
|
||||||
opts.Shell = a.MeshSystemBin
|
opts.Shell = a.MeshSystemEXE
|
||||||
opts.Command = "-nodeid"
|
opts.Command = "-nodeid"
|
||||||
|
|
||||||
for !meshSuccess {
|
for !meshSuccess {
|
||||||
|
|
|
||||||
|
|
@ -797,7 +797,7 @@ func (a *Agent) RecoverMesh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) getMeshNodeID() (string, error) {
|
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 {
|
if err != nil {
|
||||||
a.Logger.Debugln(err)
|
a.Logger.Debugln(err)
|
||||||
return "", 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
|
// skip on first call of inno setup if this is a new install
|
||||||
_, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
|
_, 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,19 +138,11 @@ func (a *Agent) Install(i *Installer) {
|
||||||
rClient.SetProxy(i.Proxy)
|
rClient.SetProxy(i.Proxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
var arch string
|
var installerMeshSystemEXE string
|
||||||
switch a.Arch {
|
|
||||||
case "x86_64":
|
|
||||||
arch = "64"
|
|
||||||
case "x86":
|
|
||||||
arch = "32"
|
|
||||||
}
|
|
||||||
|
|
||||||
var installerMeshSystemBin string
|
|
||||||
if len(i.MeshDir) > 0 {
|
if len(i.MeshDir) > 0 {
|
||||||
installerMeshSystemBin = filepath.Join(i.MeshDir, "MeshAgent.exe")
|
installerMeshSystemEXE = filepath.Join(i.MeshDir, "MeshAgent.exe")
|
||||||
} else {
|
} else {
|
||||||
installerMeshSystemBin = a.MeshSystemBin
|
installerMeshSystemEXE = a.MeshSystemEXE
|
||||||
}
|
}
|
||||||
|
|
||||||
var meshNodeID string
|
var meshNodeID string
|
||||||
|
|
@ -159,7 +151,7 @@ func (a *Agent) Install(i *Installer) {
|
||||||
mesh := filepath.Join(a.ProgramDir, a.MeshInstaller)
|
mesh := filepath.Join(a.ProgramDir, a.MeshInstaller)
|
||||||
if i.LocalMesh == "" {
|
if i.LocalMesh == "" {
|
||||||
a.Logger.Infoln("Downloading mesh agent...")
|
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))
|
r, err := rClient.R().SetBody(payload).SetOutput(mesh).Post(fmt.Sprintf("%s/api/v3/meshexe/", baseURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.installerMsg(fmt.Sprintf("Failed to download mesh agent: %s", err.Error()), "error", i.Silent)
|
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)
|
a.Logger.Debugln("Mesh agent:", mesh)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
meshNodeID, err = a.installMesh(mesh, installerMeshSystemBin, i.Proxy)
|
meshNodeID, err = a.installMesh(mesh, installerMeshSystemEXE, i.Proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.installerMsg(fmt.Sprintf("Failed to install mesh agent: %s", err.Error()), "error", i.Silent)
|
a.installerMsg(fmt.Sprintf("Failed to install mesh agent: %s", err.Error()), "error", i.Silent)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
etcConfig = "/etc/tacticalagent"
|
||||||
|
)
|
||||||
|
|
||||||
func (a *Agent) checkExistingAndRemove(silent bool) {}
|
func (a *Agent) checkExistingAndRemove(silent bool) {}
|
||||||
|
|
||||||
func (a *Agent) installerMsg(msg, alert string, 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("proxy", proxy)
|
||||||
viper.Set("meshdir", meshdir)
|
viper.Set("meshdir", meshdir)
|
||||||
viper.SetConfigPermissions(0660)
|
viper.SetConfigPermissions(0660)
|
||||||
configLocation := "/etc/tacticalagent"
|
err := viper.SafeWriteConfigAs(etcConfig)
|
||||||
|
|
||||||
err := viper.SafeWriteConfigAs(configLocation)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("createAgentConfig", err)
|
log.Fatalln("createAgentConfig", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@ func createAgentConfig(baseurl, agentid, apiurl, token, agentpk, cert, proxy, me
|
||||||
func (a *Agent) checkExistingAndRemove(silent bool) {
|
func (a *Agent) checkExistingAndRemove(silent bool) {
|
||||||
hasReg := false
|
hasReg := false
|
||||||
_, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
|
_, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
hasReg = true
|
hasReg = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Agent) RunRPC() {
|
func (a *Agent) RunRPC() {
|
||||||
if rmm.DEBUG {
|
|
||||||
a.Logger.Infoln("DEBUG BUILD STARTED")
|
|
||||||
}
|
|
||||||
|
|
||||||
a.Logger.Infoln("Agent service started")
|
a.Logger.Infoln("Agent service started")
|
||||||
go a.RunAsService()
|
go a.RunAsService()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
|
||||||
|
|
@ -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": ""
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#define MyAppName "Tactical RMM Agent"
|
#define MyAppName "Tactical RMM Agent"
|
||||||
#define MyAppVersion "2.0.4"
|
#define MyAppVersion "2.1.0-dev"
|
||||||
#define MyAppPublisher "AmidaWare LLC"
|
#define MyAppPublisher "AmidaWare LLC"
|
||||||
#define MyAppURL "https://github.com/amidaware"
|
#define MyAppURL "https://github.com/amidaware"
|
||||||
#define MyAppExeName "tacticalrmm.exe"
|
#define MyAppExeName "tacticalrmm.exe"
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "development"
|
version = "2.1.0-dev"
|
||||||
log = logrus.New()
|
log = logrus.New()
|
||||||
logFile *os.File
|
logFile *os.File
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build DEBUG
|
|
||||||
|
|
||||||
package shared
|
|
||||||
|
|
||||||
const DEBUG = true
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build !DEBUG
|
|
||||||
|
|
||||||
package shared
|
|
||||||
|
|
||||||
const DEBUG = false
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build !TEST
|
|
||||||
|
|
||||||
package shared
|
|
||||||
|
|
||||||
const TEST = false
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//go:build TEST
|
|
||||||
|
|
||||||
package shared
|
|
||||||
|
|
||||||
const TEST = true
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue