diff --git a/agent/agent.go b/agent/agent.go index ddf69e2..6e83102 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -109,6 +109,17 @@ func New(logger *logrus.Logger, version string) *Agent { }, } + var natsProxyPath, natsProxyPort string + if ac.NatsProxyPath == "" { + natsProxyPath = "natsws" + } + + if ac.NatsProxyPort == "" { + natsProxyPort = "443" + } + + natsServer := fmt.Sprintf("wss://%s:%s", ac.APIURL, natsProxyPort) + return &Agent{ Hostname: info.Hostname, BaseURL: ac.BaseURL, @@ -133,6 +144,9 @@ func New(logger *logrus.Logger, version string) *Agent { Platform: runtime.GOOS, GoArch: runtime.GOARCH, ServiceConfig: svcConf, + NatsServer: natsServer, + NatsProxyPath: natsProxyPath, + NatsProxyPort: natsProxyPort, } } @@ -313,6 +327,7 @@ func (a *Agent) setupNatsOptions() []nats.Option { opts = append(opts, nats.RetryOnFailedConnect(true)) opts = append(opts, nats.MaxReconnects(-1)) opts = append(opts, nats.ReconnectBufSize(-1)) + opts = append(opts, nats.ProxyPath("natsws")) return opts } @@ -338,6 +353,7 @@ func (a *Agent) CleanupAgentUpdates() { return } + // winagent-v* is deprecated files, err := filepath.Glob("winagent-v*.exe") if err == nil { for _, f := range files { @@ -345,6 +361,13 @@ func (a *Agent) CleanupAgentUpdates() { } } + agents, err := filepath.Glob("tacticalagent-v*.exe") + if err == nil { + for _, f := range agents { + os.Remove(f) + } + } + cderr = os.Chdir(os.Getenv("TMP")) if cderr != nil { a.Logger.Errorln(cderr) diff --git a/agent/agent_unix.go b/agent/agent_unix.go index 7fc4553..f10212c 100644 --- a/agent/agent_unix.go +++ b/agent/agent_unix.go @@ -154,6 +154,8 @@ func NewAgentConfig() *rmm.AgentConfig { Cert: viper.GetString("cert"), Proxy: viper.GetString("proxy"), CustomMeshDir: viper.GetString("meshdir"), + NatsProxyPath: viper.GetString("natsproxypath"), + NatsProxyPort: viper.GetString("natsproxyport"), } return ret } diff --git a/agent/agent_windows.go b/agent/agent_windows.go index 64ca2b6..ad0dc18 100644 --- a/agent/agent_windows.go +++ b/agent/agent_windows.go @@ -61,6 +61,8 @@ func NewAgentConfig() *rmm.AgentConfig { cert, _, _ := k.GetStringValue("Cert") proxy, _, _ := k.GetStringValue("Proxy") customMeshDir, _, _ := k.GetStringValue("MeshDir") + natsProxyPath, _, _ := k.GetStringValue("NatsProxyPath") + natsProxyPort, _, _ := k.GetStringValue("NatsProxyPort") return &rmm.AgentConfig{ BaseURL: baseurl, @@ -72,6 +74,8 @@ func NewAgentConfig() *rmm.AgentConfig { Cert: cert, Proxy: proxy, CustomMeshDir: customMeshDir, + NatsProxyPath: natsProxyPath, + NatsProxyPort: natsProxyPort, } } @@ -635,7 +639,7 @@ func (a *Agent) AgentUninstall(code string) { func (a *Agent) addDefenderExlusions() { code := ` Add-MpPreference -ExclusionPath 'C:\Program Files\TacticalAgent\*' -Add-MpPreference -ExclusionPath 'C:\Windows\Temp\winagent-v*.exe' +Add-MpPreference -ExclusionPath 'C:\Windows\Temp\tacticalagent-v*.exe' Add-MpPreference -ExclusionPath 'C:\Windows\Temp\trmm\*' Add-MpPreference -ExclusionPath 'C:\Program Files\Mesh Agent\*' ` diff --git a/agent/checkin.go b/agent/checkin.go index 1deebbd..9990198 100644 --- a/agent/checkin.go +++ b/agent/checkin.go @@ -12,7 +12,6 @@ https://license.tacticalrmm.com package agent import ( - "fmt" "runtime" "time" @@ -78,8 +77,7 @@ func (a *Agent) NatsMessage(nc *nats.Conn, mode string) { func (a *Agent) DoNatsCheckIn() { opts := a.setupNatsOptions() - server := fmt.Sprintf("tls://%s:4222", a.ApiURL) - nc, err := nats.Connect(server, opts...) + nc, err := nats.Connect(a.NatsServer, opts...) if err != nil { a.Logger.Errorln(err) return diff --git a/agent/process.go b/agent/process.go index bd3e4ee..ae7c392 100644 --- a/agent/process.go +++ b/agent/process.go @@ -64,9 +64,16 @@ func (a *Agent) KillHungUpdates() { if err != nil { continue } + + // winagent-v* is deprecated if strings.Contains(p.Exe, "winagent-v") { a.Logger.Debugln("killing process", p.Exe) KillProc(int32(p.PID)) } + + if strings.Contains(p.Exe, "tacticalagent-v") { + a.Logger.Debugln("killing process", p.Exe) + KillProc(int32(p.PID)) + } } } diff --git a/agent/rpc.go b/agent/rpc.go index 7d24d0b..e457ecd 100644 --- a/agent/rpc.go +++ b/agent/rpc.go @@ -54,8 +54,7 @@ func (a *Agent) RunRPC() { var wg sync.WaitGroup wg.Add(1) opts := a.setupNatsOptions() - server := fmt.Sprintf("tls://%s:4222", a.ApiURL) - nc, err := nats.Connect(server, opts...) + nc, err := nats.Connect(a.NatsServer, opts...) if err != nil { a.Logger.Fatalln("RunRPC() nats.Connect()", err) } diff --git a/agent/svc.go b/agent/svc.go index 6e21b15..e360ebf 100644 --- a/agent/svc.go +++ b/agent/svc.go @@ -12,7 +12,6 @@ https://license.tacticalrmm.com package agent import ( - "fmt" "sync" "time" @@ -38,8 +37,7 @@ func (a *Agent) AgentSvc() { time.Sleep(time.Duration(sleepDelay) * time.Second) opts := a.setupNatsOptions() - server := fmt.Sprintf("tls://%s:4222", a.ApiURL) - nc, err := nats.Connect(server, opts...) + nc, err := nats.Connect(a.NatsServer, opts...) if err != nil { a.Logger.Fatalln("AgentSvc() nats.Connect()", err) } diff --git a/main.go b/main.go index 1042e35..13a0a08 100644 --- a/main.go +++ b/main.go @@ -201,6 +201,6 @@ func installUsage() { } func updateUsage() { - u := `Usage: tacticalrmm.exe -m update -updateurl https://example.com/winagent-vX.X.X.exe -inno winagent-vX.X.X.exe -updatever 1.1.1` + u := `Usage: tacticalrmm.exe -m update -updateurl https://example.com/tacticalagent-vX.X.X.exe -inno tacticalagent-vX.X.X.exe -updatever 1.1.1` fmt.Println(u) } diff --git a/shared/types.go b/shared/types.go index 64ae5be..683b85b 100644 --- a/shared/types.go +++ b/shared/types.go @@ -42,6 +42,8 @@ type AgentConfig struct { Cert string Proxy string CustomMeshDir string + NatsProxyPath string + NatsProxyPort string } type RunScriptResp struct {