forked from wh1te909/rmmagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
157 lines (144 loc) · 3.7 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/sirupsen/logrus"
"github.com/wh1te909/rmmagent/agent"
)
var (
version = "1.0.0"
log = logrus.New()
logFile *os.File
)
func main() {
hostname, _ := os.Hostname()
ver := flag.Bool("version", false, "Prints version")
mode := flag.String("m", "", "The mode to run")
taskPK := flag.Int("p", 0, "Task PK")
logLevel := flag.String("log", "INFO", "The log level")
logTo := flag.String("logto", "file", "Where to log to")
api := flag.String("api", "", "API URL")
clientID := flag.Int("client-id", 0, "Client ID")
siteID := flag.Int("site-id", 0, "Site ID")
timeout := flag.Duration("timeout", 900, "Installer timeout (seconds)")
desc := flag.String("desc", hostname, "Agent's Description")
atype := flag.String("agent-type", "server", "server or workstation")
token := flag.String("auth", "", "Token")
power := flag.Bool("power", false, "Disable sleep/hibernate")
rdp := flag.Bool("rdp", false, "Enable RDP")
ping := flag.Bool("ping", false, "Enable ping")
localMesh := flag.String("local-mesh", "", "Path to mesh executable")
cert := flag.String("cert", "", "Path to domain CA .pem")
updateurl := flag.String("updateurl", "", "Download link to updater")
inno := flag.String("inno", "", "Inno setup file")
updatever := flag.String("updatever", "", "Update version")
silent := flag.Bool("silent", false, "Do not popup any message boxes during installation")
flag.Parse()
if *ver {
agent.ShowVersionInfo(version)
return
}
if len(os.Args) == 1 {
agent.ShowStatus(version)
return
}
setupLogging(logLevel, logTo)
defer logFile.Close()
a := *agent.New(log, version)
switch *mode {
case "rpc":
a.RunRPC()
case "pk":
fmt.Println(a.AgentPK)
case "winagentsvc":
a.RunAsService()
case "runchecks":
a.RunChecks()
case "sysinfo":
a.GetWMI()
case "software":
a.SendSoftware()
case "sync":
a.Sync()
case "wmi":
a.GetWMI()
case "recoversalt":
a.RecoverSalt()
case "cleanup":
a.UninstallCleanup()
case "publicip":
fmt.Println(a.PublicIP())
case "removesalt":
a.RemoveSalt()
case "getpython":
a.GetPython(true)
case "taskrunner":
if len(os.Args) < 5 || *taskPK == 0 {
return
}
a.RunTask(*taskPK)
case "update":
if *updateurl == "" || *inno == "" || *updatever == "" {
updateUsage()
return
}
a.AgentUpdate(*updateurl, *inno, *updatever)
case "install":
log.SetOutput(os.Stdout)
if *api == "" || *clientID == 0 || *siteID == 0 || *token == "" {
installUsage()
return
}
a.Install(&agent.Installer{
RMM: *api,
ClientID: *clientID,
SiteID: *siteID,
Description: *desc,
AgentType: *atype,
Power: *power,
RDP: *rdp,
Ping: *ping,
Token: *token,
LocalMesh: *localMesh,
Cert: *cert,
Timeout: *timeout,
Silent: *silent,
})
default:
agent.ShowStatus(version)
}
}
func setupLogging(level, to *string) {
ll, err := logrus.ParseLevel(*level)
if err != nil {
ll = logrus.InfoLevel
}
log.SetLevel(ll)
if *to == "stdout" {
log.SetOutput(os.Stdout)
} else {
switch runtime.GOOS {
case "windows":
logFile, _ = os.OpenFile(filepath.Join(os.Getenv("ProgramFiles"), "TABAgent", "agent.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
case "linux":
// todo
}
log.SetOutput(logFile)
}
}
func installUsage() {
switch runtime.GOOS {
case "windows":
u := `Usage: tacticalrmm.exe -m install -api <https://api.example.com> -client-id X -site-id X -auth <TOKEN>`
fmt.Println(u)
case "linux":
// todo
}
}
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`
fmt.Println(u)
}