Merge remote-tracking branch 'upstream/develop' into BigRefactor

This commit is contained in:
redanthrax 2022-06-27 11:14:58 -07:00
commit a8dfa19b3a
9 changed files with 43 additions and 10 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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\*'
`

View file

@ -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

View file

@ -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))
}
}
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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)
}

View file

@ -42,6 +42,8 @@ type AgentConfig struct {
Cert string
Proxy string
CustomMeshDir string
NatsProxyPath string
NatsProxyPort string
}
type RunScriptResp struct {