even moar refactor

This commit is contained in:
redanthrax 2022-06-17 11:01:34 -07:00
parent d6cd817133
commit 93db0f17a1
11 changed files with 111 additions and 170 deletions

View file

@ -1,90 +0,0 @@
/*
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 (
rmm "github.com/amidaware/rmmagent/shared"
"github.com/kardianos/service"
trmm "github.com/wh1te909/trmm-shared"
)
// windows only below TODO add into stub file
func (a *Agent) GetPython(force bool) {}
type SchedTask struct{ Name string }
func (a *Agent) PatchMgmnt(enable bool) error { return nil }
func (a *Agent) CreateSchedTask(st SchedTask) (bool, error) { return false, nil }
func DeleteSchedTask(name string) error { return nil }
func ListSchedTasks() []string { return []string{} }
func (a *Agent) GetEventLog(logName string, searchLastDays int) []rmm.EventLogMsg {
return []rmm.EventLogMsg{}
}
func (a *Agent) GetServiceDetail(name string) trmm.WindowsService { return trmm.WindowsService{} }
func (a *Agent) ControlService(name, action string) rmm.WinSvcResp {
return rmm.WinSvcResp{Success: false, ErrorMsg: "/na"}
}
func (a *Agent) EditService(name, startupType string) rmm.WinSvcResp {
return rmm.WinSvcResp{Success: false, ErrorMsg: "/na"}
}
func (a *Agent) GetInstalledSoftware() []trmm.WinSoftwareList { return []trmm.WinSoftwareList{} }
func (a *Agent) ChecksRunning() bool { return false }
func (a *Agent) RunTask(id int) error { return nil }
func (a *Agent) InstallChoco() {}
func (a *Agent) InstallWithChoco(name string) (string, error) { return "", nil }
func (a *Agent) GetWinUpdates() {}
func (a *Agent) InstallUpdates(guids []string) {}
func (a *Agent) installMesh(meshbin, exe, proxy string) (string, error) {
return "not implemented", nil
}
func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool) (output [2]string, e error) {
return [2]string{"", ""}, nil
}
func CMD(exe string, args []string, timeout int, detached bool) (output [2]string, e error) {
return [2]string{"", ""}, nil
}
func (a *Agent) GetServices() []trmm.WindowsService { return []trmm.WindowsService{} }
func (a *Agent) Start(_ service.Service) error { return nil }
func (a *Agent) Stop(_ service.Service) error { return nil }
func (a *Agent) InstallService() error { return nil }

View file

@ -1,45 +0,0 @@
package agent
import (
"bytes"
"io"
"os"
"testing"
)
func captureOutput(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
f()
w.Close()
os.Stdout = old
var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}
func TestShowStatus(t *testing.T) {
var (
version = "2.0.4"
)
output := captureOutput(func() {
ShowStatus(version)
})
if output != (version + "\n") {
t.Errorf("ShowStatus output not equal to version defined.")
}
}
func TestOsString(t *testing.T) {
a := New(lg, version)
osString := a.osString()
if osString == "" {
t.Errorf("Could not get OS String")
} else {
t.Logf("Got OS String: %s", osString)
}
}

View file

@ -46,35 +46,7 @@ var (
getDriveType = windows.NewLazySystemDLL("kernel32.dll").NewProc("GetDriveTypeW") getDriveType = windows.NewLazySystemDLL("kernel32.dll").NewProc("GetDriveTypeW")
) )
func NewAgentConfig() *rmm.AgentConfig {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
if err != nil {
return &rmm.AgentConfig{}
}
baseurl, _, _ := k.GetStringValue("BaseURL")
agentid, _, _ := k.GetStringValue("AgentID")
apiurl, _, _ := k.GetStringValue("ApiURL")
token, _, _ := k.GetStringValue("Token")
agentpk, _, _ := k.GetStringValue("AgentPK")
pk, _ := strconv.Atoi(agentpk)
cert, _, _ := k.GetStringValue("Cert")
proxy, _, _ := k.GetStringValue("Proxy")
customMeshDir, _, _ := k.GetStringValue("MeshDir")
return &rmm.AgentConfig{
BaseURL: baseurl,
AgentID: agentid,
APIURL: apiurl,
Token: token,
AgentPK: agentpk,
PK: pk,
Cert: cert,
Proxy: proxy,
CustomMeshDir: customMeshDir,
}
}
func (a *Agent) RunScript(code string, shell string, args []string, timeout int) (stdout, stderr string, exitcode int, e error) { func (a *Agent) RunScript(code string, shell string, args []string, timeout int) (stdout, stderr string, exitcode int, e error) {

View file

@ -0,0 +1,7 @@
package patching
func PatchMgmnt(enable bool) error { return nil }
func GetWinUpdates() {}
func InstallUpdates(guids []string) {}

View file

@ -0,0 +1,25 @@
package services
import (
trmm "github.com/wh1te909/trmm-shared"
rmm "github.com/amidaware/rmmagent/shared"
"github.com/kardianos/service"
)
func GetServiceDetail(name string) trmm.WindowsService { return trmm.WindowsService{} }
func ControlService(name, action string) rmm.WinSvcResp {
return rmm.WinSvcResp{Success: false, ErrorMsg: "/na"}
}
func EditService(name, startupType string) rmm.WinSvcResp {
return rmm.WinSvcResp{Success: false, ErrorMsg: "/na"}
}
func GetServices() []trmm.WindowsService { return []trmm.WindowsService{} }
func Start(_ service.Service) error { return nil }
func Stop(_ service.Service) error { return nil }
func InstallService() error { return nil }

View file

@ -1,3 +0,0 @@
package software
func SendSoftware() {}

View file

@ -0,0 +1,13 @@
package software
import (
trmm "github.com/wh1te909/trmm-shared"
)
func SendSoftware() {}
func GetInstalledSoftware() []trmm.WinSoftwareList { return []trmm.WinSoftwareList{} }
func InstallChoco() {}
func InstallWithChoco(name string) (string, error) { return "", nil }

View file

@ -10,4 +10,6 @@ type CmdOptions struct {
IsScript bool IsScript bool
IsExecutable bool IsExecutable bool
Detached bool Detached bool
} }
type SchedTask struct{ Name string }

View file

@ -15,7 +15,8 @@ import (
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/process" "github.com/shirou/gopsutil/process"
psHost "github.com/shirou/gopsutil/v3/host" psHost "github.com/shirou/gopsutil/v3/host"
"github.com/wh1te909/trmm-shared" rmm "github.com/amidaware/rmmagent/shared"
trmm "github.com/wh1te909/trmm-shared"
) )
func NewCMDOpts() *CmdOptions { func NewCMDOpts() *CmdOptions {
@ -267,4 +268,22 @@ func GetWMIInfo() map[string]interface{} {
func PlatVer() (string, error) { return "", nil } func PlatVer() (string, error) { return "", nil }
func GetServiceStatus(name string) (string, error) { return "", nil } func GetServiceStatus(name string) (string, error) { return "", nil }
func CreateSchedTask(st SchedTask) (bool, error) { return false, nil }
func DeleteSchedTask(name string) error { return nil }
func ListSchedTasks() []string { return []string{} }
func GetEventLog(logName string, searchLastDays int) []rmm.EventLogMsg {
return []rmm.EventLogMsg{}
}
func CMDShell(shell string, cmdArgs []string, command string, timeout int, detached bool) (output [2]string, e error) {
return [2]string{"", ""}, nil
}
func CMD(exe string, args []string, timeout int, detached bool) (output [2]string, e error) {
return [2]string{"", ""}, nil
}

View file

@ -171,4 +171,14 @@ func RecoverMesh(agentID string) {
func UninstallCleanup() {} func UninstallCleanup() {}
func RunMigrations() {} func RunMigrations() {}
func GetPython(force bool) {}
func ChecksRunning() bool { return false }
func RunTask(id int) error { return nil }
func installMesh(meshbin, exe, proxy string) (string, error) {
return "not implemented", nil
}

View file

@ -0,0 +1,31 @@
package tactical
func NewAgentConfig() *rmm.AgentConfig {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
if err != nil {
return &rmm.AgentConfig{}
}
baseurl, _, _ := k.GetStringValue("BaseURL")
agentid, _, _ := k.GetStringValue("AgentID")
apiurl, _, _ := k.GetStringValue("ApiURL")
token, _, _ := k.GetStringValue("Token")
agentpk, _, _ := k.GetStringValue("AgentPK")
pk, _ := strconv.Atoi(agentpk)
cert, _, _ := k.GetStringValue("Cert")
proxy, _, _ := k.GetStringValue("Proxy")
customMeshDir, _, _ := k.GetStringValue("MeshDir")
return &rmm.AgentConfig{
BaseURL: baseurl,
AgentID: agentid,
APIURL: apiurl,
Token: token,
AgentPK: agentpk,
PK: pk,
Cert: cert,
Proxy: proxy,
CustomMeshDir: customMeshDir,
}
}