This commit is contained in:
wh1te909 2022-06-26 15:34:00 -07:00
parent aed33b9a95
commit 8d2511129c
8 changed files with 29 additions and 13 deletions

View File

@ -66,6 +66,9 @@ type Agent struct {
Platform string Platform string
GoArch string GoArch string
ServiceConfig *service.Config ServiceConfig *service.Config
NatsServer string
NatsProxyPath string
NatsProxyPort string
} }
const ( const (
@ -139,6 +142,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{ return &Agent{
Hostname: info.Hostname, Hostname: info.Hostname,
BaseURL: ac.BaseURL, BaseURL: ac.BaseURL,
@ -163,6 +177,9 @@ func New(logger *logrus.Logger, version string) *Agent {
Platform: runtime.GOOS, Platform: runtime.GOOS,
GoArch: runtime.GOARCH, GoArch: runtime.GOARCH,
ServiceConfig: svcConf, ServiceConfig: svcConf,
NatsServer: natsServer,
NatsProxyPath: natsProxyPath,
NatsProxyPort: natsProxyPort,
} }
} }
@ -359,6 +376,7 @@ func (a *Agent) setupNatsOptions() []nats.Option {
opts = append(opts, nats.RetryOnFailedConnect(true)) opts = append(opts, nats.RetryOnFailedConnect(true))
opts = append(opts, nats.MaxReconnects(-1)) opts = append(opts, nats.MaxReconnects(-1))
opts = append(opts, nats.ReconnectBufSize(-1)) opts = append(opts, nats.ReconnectBufSize(-1))
opts = append(opts, nats.ProxyPath("natsws"))
return opts return opts
} }

View File

@ -154,6 +154,8 @@ func NewAgentConfig() *rmm.AgentConfig {
Cert: viper.GetString("cert"), Cert: viper.GetString("cert"),
Proxy: viper.GetString("proxy"), Proxy: viper.GetString("proxy"),
CustomMeshDir: viper.GetString("meshdir"), CustomMeshDir: viper.GetString("meshdir"),
NatsProxyPath: viper.GetString("natsproxypath"),
NatsProxyPort: viper.GetString("natsproxyport"),
} }
return ret return ret
} }

View File

@ -61,6 +61,8 @@ func NewAgentConfig() *rmm.AgentConfig {
cert, _, _ := k.GetStringValue("Cert") cert, _, _ := k.GetStringValue("Cert")
proxy, _, _ := k.GetStringValue("Proxy") proxy, _, _ := k.GetStringValue("Proxy")
customMeshDir, _, _ := k.GetStringValue("MeshDir") customMeshDir, _, _ := k.GetStringValue("MeshDir")
natsProxyPath, _, _ := k.GetStringValue("NatsProxyPath")
natsProxyPort, _, _ := k.GetStringValue("NatsProxyPort")
return &rmm.AgentConfig{ return &rmm.AgentConfig{
BaseURL: baseurl, BaseURL: baseurl,
@ -72,6 +74,8 @@ func NewAgentConfig() *rmm.AgentConfig {
Cert: cert, Cert: cert,
Proxy: proxy, Proxy: proxy,
CustomMeshDir: customMeshDir, CustomMeshDir: customMeshDir,
NatsProxyPath: natsProxyPath,
NatsProxyPort: natsProxyPort,
} }
} }

View File

@ -12,7 +12,6 @@ https://license.tacticalrmm.com
package agent package agent
import ( import (
"fmt"
"runtime" "runtime"
"time" "time"
@ -78,8 +77,7 @@ func (a *Agent) NatsMessage(nc *nats.Conn, mode string) {
func (a *Agent) DoNatsCheckIn() { func (a *Agent) DoNatsCheckIn() {
opts := a.setupNatsOptions() opts := a.setupNatsOptions()
server := fmt.Sprintf("tls://%s:4222", a.ApiURL) nc, err := nats.Connect(a.NatsServer, opts...)
nc, err := nats.Connect(server, opts...)
if err != nil { if err != nil {
a.Logger.Errorln(err) a.Logger.Errorln(err)
return return

View File

@ -82,11 +82,6 @@ func (a *Agent) Install(i *Installer) {
a.Logger.Debugln("API:", i.SaltMaster) a.Logger.Debugln("API:", i.SaltMaster)
terr := TestTCP(fmt.Sprintf("%s:4222", i.SaltMaster))
if terr != nil {
a.installerMsg(fmt.Sprintf("ERROR: Either port 4222 TCP is not open on your RMM, or nats.service is not running.\n\n%s", terr.Error()), "error", i.Silent)
}
baseURL := u.Scheme + "://" + u.Host baseURL := u.Scheme + "://" + u.Host
a.Logger.Debugln("Base URL:", baseURL) a.Logger.Debugln("Base URL:", baseURL)

View File

@ -54,8 +54,7 @@ func (a *Agent) RunRPC() {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
opts := a.setupNatsOptions() opts := a.setupNatsOptions()
server := fmt.Sprintf("tls://%s:4222", a.ApiURL) nc, err := nats.Connect(a.NatsServer, opts...)
nc, err := nats.Connect(server, opts...)
if err != nil { if err != nil {
a.Logger.Fatalln("RunRPC() nats.Connect()", err) a.Logger.Fatalln("RunRPC() nats.Connect()", err)
} }

View File

@ -12,7 +12,6 @@ https://license.tacticalrmm.com
package agent package agent
import ( import (
"fmt"
"sync" "sync"
"time" "time"
@ -38,8 +37,7 @@ func (a *Agent) AgentSvc() {
time.Sleep(time.Duration(sleepDelay) * time.Second) time.Sleep(time.Duration(sleepDelay) * time.Second)
opts := a.setupNatsOptions() opts := a.setupNatsOptions()
server := fmt.Sprintf("tls://%s:4222", a.ApiURL) nc, err := nats.Connect(a.NatsServer, opts...)
nc, err := nats.Connect(server, opts...)
if err != nil { if err != nil {
a.Logger.Fatalln("AgentSvc() nats.Connect()", err) a.Logger.Fatalln("AgentSvc() nats.Connect()", err)
} }

View File

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