@@ -40,37 +40,39 @@ import (
4040
4141// Agent struct
4242type Agent struct {
43- Hostname string
44- Arch string
45- AgentID string
46- BaseURL string
47- ApiURL string
48- Token string
49- AgentPK int
50- Cert string
51- ProgramDir string
52- EXE string
53- SystemDrive string
54- MeshInstaller string
55- MeshSystemEXE string
56- MeshSVC string
57- PyBin string
58- Headers map [string ]string
59- Logger * logrus.Logger
60- Version string
61- Debug bool
62- rClient * resty.Client
63- Proxy string
64- LogTo string
65- LogFile * os.File
66- Platform string
67- GoArch string
68- ServiceConfig * service.Config
69- NatsServer string
70- NatsProxyPath string
71- NatsProxyPort string
72- NatsPingInterval int
73- NatsWSCompression bool
43+ Hostname string
44+ Arch string
45+ AgentID string
46+ BaseURL string
47+ ApiURL string
48+ Token string
49+ AgentPK int
50+ Cert string
51+ ProgramDir string
52+ EXE string
53+ SystemDrive string
54+ WinTmpDir string
55+ WinRunAsUserTmpDir string
56+ MeshInstaller string
57+ MeshSystemEXE string
58+ MeshSVC string
59+ PyBin string
60+ Headers map [string ]string
61+ Logger * logrus.Logger
62+ Version string
63+ Debug bool
64+ rClient * resty.Client
65+ Proxy string
66+ LogTo string
67+ LogFile * os.File
68+ Platform string
69+ GoArch string
70+ ServiceConfig * service.Config
71+ NatsServer string
72+ NatsProxyPath string
73+ NatsProxyPort string
74+ NatsPingInterval int
75+ NatsWSCompression bool
7476}
7577
7678const (
@@ -88,7 +90,7 @@ const (
8890 defaultMacMeshSvcDir = "/usr/local/mesh_services"
8991)
9092
91- var winTempDir = filepath .Join (os .Getenv ("PROGRAMDATA" ), "TacticalRMM" )
93+ var defaultWinTmpDir = filepath .Join (os .Getenv ("PROGRAMDATA" ), "TacticalRMM" )
9294var winMeshDir = filepath .Join (os .Getenv ("PROGRAMFILES" ), "Mesh Agent" )
9395var natsCheckin = []string {"agent-hello" , "agent-agentinfo" , "agent-disks" , "agent-winsvc" , "agent-publicip" , "agent-wmi" }
9496var limitNatsData = []string {"agent-winsvc" , "agent-wmi" }
@@ -99,6 +101,8 @@ func New(logger *logrus.Logger, version string) *Agent {
99101 pd := filepath .Join (os .Getenv ("ProgramFiles" ), progFilesName )
100102 exe := filepath .Join (pd , winExeName )
101103 sd := os .Getenv ("SystemDrive" )
104+ winTempDir := defaultWinTmpDir
105+ winRunAsUserTmpDir := defaultWinTmpDir
102106
103107 var pybin string
104108 switch runtime .GOARCH {
@@ -130,6 +134,14 @@ func New(logger *logrus.Logger, version string) *Agent {
130134 restyC .SetRootCertificate (ac .Cert )
131135 }
132136
137+ if len (ac .WinTmpDir ) > 0 {
138+ winTempDir = ac .WinTmpDir
139+ }
140+
141+ if len (ac .WinRunAsUserTmpDir ) > 0 {
142+ winRunAsUserTmpDir = ac .WinRunAsUserTmpDir
143+ }
144+
133145 var MeshSysExe string
134146 switch runtime .GOOS {
135147 case "windows" :
@@ -189,34 +201,36 @@ func New(logger *logrus.Logger, version string) *Agent {
189201 }
190202
191203 return & Agent {
192- Hostname : info .Hostname ,
193- BaseURL : ac .BaseURL ,
194- AgentID : ac .AgentID ,
195- ApiURL : ac .APIURL ,
196- Token : ac .Token ,
197- AgentPK : ac .PK ,
198- Cert : ac .Cert ,
199- ProgramDir : pd ,
200- EXE : exe ,
201- SystemDrive : sd ,
202- MeshInstaller : "meshagent.exe" ,
203- MeshSystemEXE : MeshSysExe ,
204- MeshSVC : meshSvcName ,
205- PyBin : pybin ,
206- Headers : headers ,
207- Logger : logger ,
208- Version : version ,
209- Debug : logger .IsLevelEnabled (logrus .DebugLevel ),
210- rClient : restyC ,
211- Proxy : ac .Proxy ,
212- Platform : runtime .GOOS ,
213- GoArch : runtime .GOARCH ,
214- ServiceConfig : svcConf ,
215- NatsServer : natsServer ,
216- NatsProxyPath : natsProxyPath ,
217- NatsProxyPort : natsProxyPort ,
218- NatsPingInterval : natsPingInterval ,
219- NatsWSCompression : natsWsCompression ,
204+ Hostname : info .Hostname ,
205+ BaseURL : ac .BaseURL ,
206+ AgentID : ac .AgentID ,
207+ ApiURL : ac .APIURL ,
208+ Token : ac .Token ,
209+ AgentPK : ac .PK ,
210+ Cert : ac .Cert ,
211+ ProgramDir : pd ,
212+ EXE : exe ,
213+ SystemDrive : sd ,
214+ WinTmpDir : winTempDir ,
215+ WinRunAsUserTmpDir : winRunAsUserTmpDir ,
216+ MeshInstaller : "meshagent.exe" ,
217+ MeshSystemEXE : MeshSysExe ,
218+ MeshSVC : meshSvcName ,
219+ PyBin : pybin ,
220+ Headers : headers ,
221+ Logger : logger ,
222+ Version : version ,
223+ Debug : logger .IsLevelEnabled (logrus .DebugLevel ),
224+ rClient : restyC ,
225+ Proxy : ac .Proxy ,
226+ Platform : runtime .GOOS ,
227+ GoArch : runtime .GOARCH ,
228+ ServiceConfig : svcConf ,
229+ NatsServer : natsServer ,
230+ NatsProxyPath : natsProxyPath ,
231+ NatsProxyPort : natsProxyPort ,
232+ NatsPingInterval : natsPingInterval ,
233+ NatsWSCompression : natsWsCompression ,
220234 }
221235}
222236
@@ -457,7 +471,7 @@ func (a *Agent) GetUninstallExe() string {
457471
458472func (a * Agent ) CleanupAgentUpdates () {
459473 // TODO remove a.ProgramDir, updates are now in winTempDir
460- dirs := [3 ]string {winTempDir , os .Getenv ("TMP" ), a .ProgramDir }
474+ dirs := [3 ]string {a . WinTmpDir , os .Getenv ("TMP" ), a .ProgramDir }
461475 for _ , dir := range dirs {
462476 err := os .Chdir (dir )
463477 if err != nil {
@@ -491,7 +505,7 @@ func (a *Agent) CleanupAgentUpdates() {
491505
492506func (a * Agent ) RunPythonCode (code string , timeout int , args []string ) (string , error ) {
493507 content := []byte (code )
494- tmpfn , _ := ioutil .TempFile (winTempDir , "*.py" )
508+ tmpfn , _ := ioutil .TempFile (a . WinTmpDir , "*.py" )
495509 if _ , err := tmpfn .Write (content ); err != nil {
496510 a .Logger .Debugln (err )
497511 return "" , err
@@ -537,8 +551,8 @@ func (a *Agent) RunPythonCode(code string, timeout int, args []string) (string,
537551}
538552
539553func createWinTempDir () error {
540- if ! trmm .FileExists (winTempDir ) {
541- err := os .Mkdir (winTempDir , 0775 )
554+ if ! trmm .FileExists (defaultWinTmpDir ) {
555+ err := os .Mkdir (defaultWinTmpDir , 0775 )
542556 if err != nil {
543557 return err
544558 }
0 commit comments