add local config

This commit is contained in:
wh1te909 2022-12-02 23:22:14 -08:00
parent de01fa5d80
commit ec6ea9aded
4 changed files with 61 additions and 13 deletions

View File

@ -493,6 +493,9 @@ func (a *Agent) GetWMIInfo() map[string]interface{} {
} }
// windows only below TODO add into stub file // windows only below TODO add into stub file
func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig {
return ret
}
func (a *Agent) PlatVer() (string, error) { return "", nil } func (a *Agent) PlatVer() (string, error) { return "", nil }

View File

@ -863,6 +863,43 @@ func (a *Agent) InstallService() error {
return service.Control(s, "install") return service.Control(s, "install")
} }
func (a *Agent) GetAgentCheckInConfig(ret AgentCheckInConfig) AgentCheckInConfig {
// if local config present, overwrite
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\TacticalRMM`, registry.ALL_ACCESS)
if err == nil {
if checkInHello, _, err := k.GetStringValue("CheckInHello"); err == nil {
ret.Hello = regRangeToInt(checkInHello)
}
if checkInAgentInfo, _, err := k.GetStringValue("CheckInAgentInfo"); err == nil {
ret.AgentInfo = regRangeToInt(checkInAgentInfo)
}
if checkInWinSvc, _, err := k.GetStringValue("CheckInWinSvc"); err == nil {
ret.WinSvc = regRangeToInt(checkInWinSvc)
}
if checkInPubIP, _, err := k.GetStringValue("CheckInPubIP"); err == nil {
ret.PubIP = regRangeToInt(checkInPubIP)
}
if checkInDisks, _, err := k.GetStringValue("CheckInDisks"); err == nil {
ret.Disks = regRangeToInt(checkInDisks)
}
if checkInSW, _, err := k.GetStringValue("CheckInSW"); err == nil {
ret.SW = regRangeToInt(checkInSW)
}
if checkInWMI, _, err := k.GetStringValue("CheckInWMI"); err == nil {
ret.WMI = regRangeToInt(checkInWMI)
}
if checkInSyncMesh, _, err := k.GetStringValue("CheckInSyncMesh"); err == nil {
ret.SyncMesh = regRangeToInt(checkInSyncMesh)
}
if checkInLimitData, _, err := k.GetStringValue("CheckInLimitData"); err == nil {
if checkInLimitData == "true" {
ret.LimitData = true
}
}
}
return ret
}
// TODO add to stub // TODO add to stub
func (a *Agent) NixMeshNodeID() string { func (a *Agent) NixMeshNodeID() string {
return "not implemented" return "not implemented"

View File

@ -55,7 +55,8 @@ func (a *Agent) AgentSvc(nc *nats.Conn) {
a.Logger.Debugf("AgentSvc() sleeping for %v seconds", sleepDelay) a.Logger.Debugf("AgentSvc() sleeping for %v seconds", sleepDelay)
time.Sleep(time.Duration(sleepDelay) * time.Second) time.Sleep(time.Duration(sleepDelay) * time.Second)
conf := a.GetAgentCheckInConfig() conf := a.GetAgentCheckInConfig(a.GetCheckInConfFromAPI())
a.Logger.Debugf("+%v\n", conf)
for _, s := range natsCheckin { for _, s := range natsCheckin {
if conf.LimitData && stringInSlice(s, limitNatsData) { if conf.LimitData && stringInSlice(s, limitNatsData) {
continue continue
@ -113,7 +114,7 @@ func (a *Agent) AgentStartup() {
} }
} }
func (a *Agent) GetAgentCheckInConfig() AgentCheckInConfig { func (a *Agent) GetCheckInConfFromAPI() AgentCheckInConfig {
ret := AgentCheckInConfig{} ret := AgentCheckInConfig{}
url := fmt.Sprintf("/api/v3/%s/config/", a.AgentID) url := fmt.Sprintf("/api/v3/%s/config/", a.AgentID)
r, err := a.rClient.R().SetResult(&AgentCheckInConfig{}).Get(url) r, err := a.rClient.R().SetResult(&AgentCheckInConfig{}).Get(url)
@ -128,17 +129,16 @@ func (a *Agent) GetAgentCheckInConfig() AgentCheckInConfig {
ret.WMI = randRange(3000, 4000) ret.WMI = randRange(3000, 4000)
ret.SyncMesh = randRange(800, 1200) ret.SyncMesh = randRange(800, 1200)
ret.LimitData = false ret.LimitData = false
return ret } else {
ret.Hello = r.Result().(*AgentCheckInConfig).Hello
ret.AgentInfo = r.Result().(*AgentCheckInConfig).AgentInfo
ret.WinSvc = r.Result().(*AgentCheckInConfig).WinSvc
ret.PubIP = r.Result().(*AgentCheckInConfig).PubIP
ret.Disks = r.Result().(*AgentCheckInConfig).Disks
ret.SW = r.Result().(*AgentCheckInConfig).SW
ret.WMI = r.Result().(*AgentCheckInConfig).WMI
ret.SyncMesh = r.Result().(*AgentCheckInConfig).SyncMesh
ret.LimitData = r.Result().(*AgentCheckInConfig).LimitData
} }
ret.Hello = r.Result().(*AgentCheckInConfig).Hello
ret.AgentInfo = r.Result().(*AgentCheckInConfig).AgentInfo
ret.WinSvc = r.Result().(*AgentCheckInConfig).WinSvc
ret.PubIP = r.Result().(*AgentCheckInConfig).PubIP
ret.Disks = r.Result().(*AgentCheckInConfig).Disks
ret.SW = r.Result().(*AgentCheckInConfig).SW
ret.WMI = r.Result().(*AgentCheckInConfig).WMI
ret.SyncMesh = r.Result().(*AgentCheckInConfig).SyncMesh
ret.LimitData = r.Result().(*AgentCheckInConfig).LimitData
a.Logger.Debugf("%+v\n", r)
return ret return ret
} }

View File

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
goDebug "runtime/debug" goDebug "runtime/debug"
"strconv"
"strings" "strings"
"time" "time"
@ -331,3 +332,10 @@ func stringInSlice(a string, list []string) bool {
} }
return false return false
} }
func regRangeToInt(s string) int {
split := strings.Split(s, ",")
min, _ := strconv.Atoi(split[0])
max, _ := strconv.Atoi(split[1])
return randRange(min, max)
}