forked from sg3des/mikrotik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
264 lines (207 loc) · 5.02 KB
/
system.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package mikrotik
type system struct {
Identity identity
NTP ntp
File file
Led leds
User user
Resource resource
Routerboard sysrouterboard
Package syspackage
Scheduler cmd
}
// ====================================
//
// Identity
//
// ====================================
type identity struct {
mikrotik *Mikrotik
path string
}
func (c *identity) Name() (string, error) {
var resp struct {
Name string
}
err := c.mikrotik.Print(c.path+"/print", &resp)
return resp.Name, err
}
func (c *identity) SetName(name string) error {
return c.mikrotik.SetOne(c.path+"/set", "name", name)
}
// ====================================
//
// File
//
// ====================================
type file struct {
mikrotik *Mikrotik
path string
}
func (f *file) Print(v interface{}) error {
return f.mikrotik.Print(f.path+"/print", v)
}
func (f *file) Set(name, value string) error {
return f.mikrotik.SetOne(f.path+"/set", name, value)
}
func (f *file) SetContents(id, contents string) error {
return f.mikrotik.Set(f.path+"/set", id, "=contents="+contents)
}
func (f *file) New(name string) (files []SystemFile, err error) {
re, err := f.mikrotik.RunArgs(f.path+"/print", "=file="+name)
if err != nil {
return nil, err
}
err = f.mikrotik.ParseResponce(re, &files)
return files, err
}
// ====================================
//
// SNTP Client
//
// ====================================
type ntp struct {
Client cfg
}
// ====================================
//
// LEDs
//
// ====================================
type leds struct {
cmd
Settings cfg
}
// ====================================
//
// User
//
// ====================================
type user struct {
cmd
SSHKeys sshkeys
AAA cfg
Active cfg
Group cmd
}
type sshkeys struct {
sshcmds
Private sshcmds
}
// ====================================
//
// Logging
//
// ====================================
type logging struct {
cmd
Action cmd
}
// ====================================
//
// Resource
//
// ====================================
type resource struct {
mikrotik *Mikrotik
path string
USB cfg
CPU cfg
IRQ cfg
PCI respci
}
func (resource *resource) Print(v interface{}) error {
return resource.mikrotik.Print(resource.path+"/print", v)
}
type respci struct {
cfg
}
// USBPowerReset to implement
// ====================================
//
// Routerboard
//
// ====================================
type sysrouterboard struct {
mikrotik *Mikrotik
path string
Settings cfg
ModeButton cfg
USB usbcfg
}
// Print simply calls the mikrotik's Print for the commands that use cmd struct.
func (router *sysrouterboard) Print(v interface{}) error {
return router.mikrotik.Print(router.path+"/print", v)
}
// usbcfg is a struct for System/Routerboard/USB that has cfg's and PowerReset methods
type usbcfg struct {
cfg
}
// PowerReset wants duration and bus in order to stop the power to the USB (bus) for an amount of time (duration). Default: Duration= 3s and Bus = 1.
func (usb *usbcfg) PowerReset(duration, bus string) error {
if duration == "" {
duration = "3s"
} else if bus == "" {
bus = "1"
}
_, err := usb.cfg.mikrotik.RunArgs(usb.path+"/power-reset", "=duration="+duration, "=bus="+bus)
return err
}
// ====================================
//
// Package
//
// ====================================
type syspackage struct {
cmd
Update sysupdate
}
func (sys *syspackage) Uninstall(name string) error {
_, err := sys.cmd.mikrotik.RunArgs(sys.cmd.path+"/uninstall", "=numbers="+name)
return err
}
func (sys *syspackage) Unschedule(name string) error {
_, err := sys.cmd.mikrotik.RunArgs(sys.cmd.path+"/unschedule", "=numbers="+name)
return err
}
func (sys *syspackage) Downgrade() error {
_, err := sys.cmd.mikrotik.RunArgs(sys.cmd.path + "/downgrade")
return err
}
type sysupdate struct {
cfg
}
func (sys *sysupdate) Install() error {
_, err := sys.cfg.mikrotik.RunArgs(sys.cfg.path + "/install")
return err
}
func (sys *sysupdate) Download() error {
_, err := sys.cfg.mikrotik.RunArgs(sys.cfg.path + "/download")
return err
}
func (sys *sysupdate) Cancel() error {
_, err := sys.cfg.mikrotik.RunArgs(sys.cfg.path + "/cancel")
return err
}
func (sys *sysupdate) CheckForUpdates() (updates []SystemCheckForUpdates, err error) {
re, err := sys.cfg.mikrotik.RunArgs(sys.cfg.path + "/check-for-updates")
if err != nil {
return nil, err
}
err = sys.cfg.mikrotik.ParseResponce(re, &updates)
return updates, err
}
// ====================================
//
// Script
//
// ====================================
type script struct {
cmd
Job cmd
Environment cmd
}
func (scr *script) Run(name string) error {
_, err := scr.cmd.mikrotik.RunArgs(scr.cmd.path+"/run", "=number="+name)
return err
}