This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
uap.go
354 lines (339 loc) · 16.3 KB
/
uap.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// Copyright (c) 2014 The unifi Authors. All rights reserved.
// Use of this source code is governed by ISC-style license
// that can be found in the LICENSE file.
package unifi
import (
"encoding/json"
"time"
)
// Access point data
type UAP struct {
u *Unifi
ID string `json:"_id"`
//Uptime int `json:"_uptime"`
Adopted bool `json:"adopted"`
AntennaTable []any `json:"antenna_table"`
Bytes int64 `json:"bytes"`
BytesD int64 `json:"bytes-d"`
BytesR int64 `json:"bytes-r"`
Cfgversion string `json:"cfgversion"`
ConfigNetwork struct {
IP string `json:"ip"`
Type string `json:"type"`
} `json:"config_network"`
ConnectRequestIP string `json:"connect_request_ip"`
//ConnectRequestPort int `json:"connect_request_port"` //FIXME: Prior to 5.7.20 type string!
ConsideredLostAt int `json:"considered_lost_at"`
DeviceID string `json:"device_id"`
DownlinkTable []any `json:"downlink_table"`
EthernetTable []struct {
Mac string `json:"mac"`
Name string `json:"name"`
NumPort int `json:"num_port"`
} `json:"ethernet_table"`
FwCaps int `json:"fw_caps"`
GuestNumSta int `json:"guest-num_sta"`
GuestToken string `json:"guest_token"`
HasEth1 bool `json:"has_eth1"`
HasSpeaker bool `json:"has_speaker"`
InformIP string `json:"inform_ip"`
InformURL string `json:"inform_url"`
IP string `json:"ip"`
Isolated bool `json:"isolated"`
KnownCfgversion string `json:"known_cfgversion"`
LastSeen int `json:"last_seen"`
LedOverride string `json:"led_override"`
LicenseState string `json:"license_state"`
Locating bool `json:"locating"`
Mac string `json:"mac"`
MapID string `json:"map_id"`
Model string `json:"model"`
Name string `json:"name"`
NextHeartbeatAt int `json:"next_heartbeat_at"`
NumSta int `json:"num_sta"`
PortStats []any `json:"port_stats"`
PortTable []Port `json:"port_table,omitempty"`
RadioTable []struct {
BuiltinAntGain int `json:"builtin_ant_gain"`
BuiltinAntenna bool `json:"builtin_antenna"`
CurrentAntennaGain int `json:"current_antenna_gain"`
MaxTxpower int `json:"max_txpower"`
MinTxpower int `json:"min_txpower"`
Name string `json:"name"`
Nss int `json:"nss"`
Radio string `json:"radio"`
RadioCaps int `json:"radio_caps"`
WlangroupID string `json:"wlangroup_id"`
HasDfs bool `json:"has_dfs,omitempty"`
HasFccdfs bool `json:"has_fccdfs,omitempty"`
Is11Ac bool `json:"is_11ac,omitempty"`
} `json:"radio_table"`
RadioTableStats []struct {
AstBeXmit any `json:"ast_be_xmit"`
AstCst any `json:"ast_cst"`
AstTxto any `json:"ast_txto"`
Channel int `json:"channel"`
CuSelfRx int `json:"cu_self_rx"`
CuSelfTx int `json:"cu_self_tx"`
CuTotal int `json:"cu_total"`
Extchannel int `json:"extchannel"`
Gain int `json:"gain"`
GuestNumSta int `json:"guest-num_sta"`
Name string `json:"name"`
NumSta int `json:"num_sta"`
Radio string `json:"radio"`
State string `json:"state"`
TxPackets int64 `json:"tx_packets"`
TxPower int64 `json:"tx_power"`
TxRetries int64 `json:"tx_retries"`
UserNumSta int `json:"user-num_sta"`
} `json:"radio_table_stats"`
RxBytes int64 `json:"rx_bytes"`
RxBytesD int64 `json:"rx_bytes-d"`
ScanRadioTable []any `json:"scan_radio_table"`
Scanning bool `json:"scanning"`
Serial string `json:"serial"`
SiteID string `json:"site_id"`
SpectrumScanning bool `json:"spectrum_scanning"`
SSHSessionTable []any `json:"ssh_session_table"`
Stat struct {
Ap struct {
Ap string `json:"ap"`
Bytes float64 `json:"bytes"`
Datetime time.Time `json:"datetime"`
Duration float64 `json:"duration"`
GuestRxBytes float64 `json:"guest-rx_bytes"`
GuestRxCrypts float64 `json:"guest-rx_crypts"`
GuestRxDropped float64 `json:"guest-rx_dropped"`
GuestRxErrors float64 `json:"guest-rx_errors"`
GuestRxFrags float64 `json:"guest-rx_frags"`
GuestRxPackets float64 `json:"guest-rx_packets"`
GuestTxBytes float64 `json:"guest-tx_bytes"`
GuestTxDropped float64 `json:"guest-tx_dropped"`
GuestTxErrors float64 `json:"guest-tx_errors"`
GuestTxPackets float64 `json:"guest-tx_packets"`
GuestTxRetries float64 `json:"guest-tx_retries"`
O string `json:"o"`
Oid string `json:"oid"`
RxBytes float64 `json:"rx_bytes"`
RxCrypts float64 `json:"rx_crypts"`
RxDropped float64 `json:"rx_dropped"`
RxErrors float64 `json:"rx_errors"`
RxFrags float64 `json:"rx_frags"`
RxPackets float64 `json:"rx_packets"`
SiteID string `json:"site_id"`
Time int64 `json:"time"`
TxBytes float64 `json:"tx_bytes"`
TxDropped float64 `json:"tx_dropped"`
TxErrors float64 `json:"tx_errors"`
TxPackets float64 `json:"tx_packets"`
TxRetries float64 `json:"tx_retries"`
UserRxBytes float64 `json:"user-rx_bytes"`
UserRxCrypts float64 `json:"user-rx_crypts"`
UserRxDropped float64 `json:"user-rx_dropped"`
UserRxErrors float64 `json:"user-rx_errors"`
UserRxFrags float64 `json:"user-rx_frags"`
UserRxPackets float64 `json:"user-rx_packets"`
UserTxBytes float64 `json:"user-tx_bytes"`
UserTxDropped float64 `json:"user-tx_dropped"`
UserTxErrors float64 `json:"user-tx_errors"`
UserTxPackets float64 `json:"user-tx_packets"`
UserTxRetries float64 `json:"user-tx_retries"`
UserWifi0Ath05Aa99001C9E77C011Dc149F7RxBytes float64 `json:"user-wifi0-ath0-5aa99001c9e77c011dc149f7-rx_bytes"`
UserWifi0Ath05Aa99001C9E77C011Dc149F7RxPackets float64 `json:"user-wifi0-ath0-5aa99001c9e77c011dc149f7-rx_packets"`
UserWifi0Ath05Aa99001C9E77C011Dc149F7TxBytes float64 `json:"user-wifi0-ath0-5aa99001c9e77c011dc149f7-tx_bytes"`
UserWifi0Ath05Aa99001C9E77C011Dc149F7TxPackets float64 `json:"user-wifi0-ath0-5aa99001c9e77c011dc149f7-tx_packets"`
UserWifi0RxBytes float64 `json:"user-wifi0-rx_bytes"`
UserWifi0RxCrypts float64 `json:"user-wifi0-rx_crypts"`
UserWifi0RxDropped float64 `json:"user-wifi0-rx_dropped"`
UserWifi0RxErrors float64 `json:"user-wifi0-rx_errors"`
UserWifi0RxFrags float64 `json:"user-wifi0-rx_frags"`
UserWifi0RxPackets float64 `json:"user-wifi0-rx_packets"`
UserWifi0TxBytes float64 `json:"user-wifi0-tx_bytes"`
UserWifi0TxDropped float64 `json:"user-wifi0-tx_dropped"`
UserWifi0TxErrors float64 `json:"user-wifi0-tx_errors"`
UserWifi0TxPackets float64 `json:"user-wifi0-tx_packets"`
UserWifi0TxRetries float64 `json:"user-wifi0-tx_retries"`
UserWifi1Ath2NullRxBytes float64 `json:"user-wifi1-ath2-null-rx_bytes"`
UserWifi1Ath2NullRxPackets float64 `json:"user-wifi1-ath2-null-rx_packets"`
UserWifi1Ath2NullTxBytes float64 `json:"user-wifi1-ath2-null-tx_bytes"`
UserWifi1Ath2NullTxPackets float64 `json:"user-wifi1-ath2-null-tx_packets"`
UserWifi1RxBytes float64 `json:"user-wifi1-rx_bytes"`
UserWifi1RxCrypts float64 `json:"user-wifi1-rx_crypts"`
UserWifi1RxDropped float64 `json:"user-wifi1-rx_dropped"`
UserWifi1RxErrors float64 `json:"user-wifi1-rx_errors"`
UserWifi1RxFrags float64 `json:"user-wifi1-rx_frags"`
UserWifi1RxPackets float64 `json:"user-wifi1-rx_packets"`
UserWifi1TxBytes float64 `json:"user-wifi1-tx_bytes"`
UserWifi1TxDropped float64 `json:"user-wifi1-tx_dropped"`
UserWifi1TxErrors float64 `json:"user-wifi1-tx_errors"`
UserWifi1TxPackets float64 `json:"user-wifi1-tx_packets"`
UserWifi1TxRetries float64 `json:"user-wifi1-tx_retries"`
Wifi0RxBytes float64 `json:"wifi0-rx_bytes"`
Wifi0RxCrypts float64 `json:"wifi0-rx_crypts"`
Wifi0RxDropped float64 `json:"wifi0-rx_dropped"`
Wifi0RxErrors float64 `json:"wifi0-rx_errors"`
Wifi0RxFrags float64 `json:"wifi0-rx_frags"`
Wifi0RxPackets float64 `json:"wifi0-rx_packets"`
Wifi0TxBytes float64 `json:"wifi0-tx_bytes"`
Wifi0TxDropped float64 `json:"wifi0-tx_dropped"`
Wifi0TxErrors float64 `json:"wifi0-tx_errors"`
Wifi0TxPackets float64 `json:"wifi0-tx_packets"`
Wifi0TxRetries float64 `json:"wifi0-tx_retries"`
Wifi1RxBytes float64 `json:"wifi1-rx_bytes"`
Wifi1RxCrypts float64 `json:"wifi1-rx_crypts"`
Wifi1RxDropped float64 `json:"wifi1-rx_dropped"`
Wifi1RxErrors float64 `json:"wifi1-rx_errors"`
Wifi1RxFrags float64 `json:"wifi1-rx_frags"`
Wifi1RxPackets float64 `json:"wifi1-rx_packets"`
Wifi1TxBytes float64 `json:"wifi1-tx_bytes"`
Wifi1TxDropped float64 `json:"wifi1-tx_dropped"`
Wifi1TxErrors float64 `json:"wifi1-tx_errors"`
Wifi1TxPackets float64 `json:"wifi1-tx_packets"`
Wifi1TxRetries float64 `json:"wifi1-tx_retries"`
} `json:"at"`
} `json:"stat"`
State DevState `json:"state"`
SysStats struct {
} `json:"sys_stats"`
SystemStats struct {
} `json:"system-stats"`
TxBytes int64 `json:"tx_bytes"`
TxBytesD int64 `json:"tx_bytes-d"`
Type string `json:"type"`
Upgradable bool `json:"upgradable"`
UpgradeState int `json:"upgrade_state"`
UpgradeToFirmware string `json:"upgrade_to_firmware"`
Uplink struct {
FullDuplex bool `json:"full_duplex"`
IP string `json:"ip"`
Mac string `json:"mac"`
MaxSpeed int `json:"max_speed"`
Name string `json:"name"`
Netmask string `json:"netmask"`
NumPort int `json:"num_port"`
RxBytes int64 `json:"rx_bytes"`
RxBytesR int64 `json:"rx_bytes-r"`
RxDropped int64 `json:"rx_dropped"`
RxErrors int64 `json:"rx_errors"`
RxMulticast int64 `json:"rx_multicast"`
RxPackets int64 `json:"rx_packets"`
Speed int `json:"speed"`
TxBytes int64 `json:"tx_bytes"`
TxBytesR int64 `json:"tx_bytes-r"`
TxDropped int64 `json:"tx_dropped"`
TxErrors int64 `json:"tx_errors"`
TxPackets int64 `json:"tx_packets"`
Type string `json:"type"`
Up bool `json:"up"`
} `json:"uplink"`
UplinkTable []any `json:"uplink_table"`
Uptime int `json:"uptime"`
UserNumSta int `json:"user-num_sta"`
VapTable []struct {
ApMac string `json:"ap_mac"`
Bssid string `json:"bssid"`
Ccq int `json:"ccq"`
Channel int `json:"channel"`
Essid string `json:"essid"`
ID string `json:"id"`
IsGuest bool `json:"is_guest"`
IsWep bool `json:"is_wep"`
MapID string `json:"map_id"`
Name string `json:"name"`
NumSta int `json:"num_sta"`
Radio string `json:"radio"`
RadioName string `json:"radio_name"`
RxBytes int64 `json:"rx_bytes"`
RxCrypts int64 `json:"rx_crypts"`
RxDropped int64 `json:"rx_dropped"`
RxErrors int64 `json:"rx_errors"`
RxFrags int64 `json:"rx_frags"`
RxNwids int64 `json:"rx_nwids"`
RxPackets int64 `json:"rx_packets"`
SiteID string `json:"site_id"`
State string `json:"state"`
T string `json:"t"`
TxBytes int64 `json:"tx_bytes"`
TxDropped int64 `json:"tx_dropped"`
TxErrors int64 `json:"tx_errors"`
TxPackets int64 `json:"tx_packets"`
TxPower int64 `json:"tx_power"`
TxRetries int64 `json:"tx_retries"`
Up bool `json:"up"`
Usage string `json:"usage"`
WlanconfID string `json:"wlanconf_id"`
} `json:"vap_table"`
Version string `json:"version"`
VersionIncompatible bool `json:"version_incompatible"`
VwireEnabled bool `json:"vwireEnabled"`
VwireTable []any `json:"vwire_table"`
VwireVapTable []any `json:"vwire_vap_table"`
WifiCaps int `json:"wifi_caps"`
X fuzzyFloat `json:"x"`
XAuthkey string `json:"x_authkey"`
XFingerprint string `json:"x_fingerprint"`
XHasSSHHostkey bool `json:"x_has_ssh_hostkey"`
XInformAuthkey string `json:"x_inform_authkey"`
XSSHHostkeyFingerprint string `json:"x_ssh_hostkey_fingerprint"`
XVwirekey string `json:"x_vwirekey"`
Y fuzzyFloat `json:"y"`
}
type UAPmap map[string]UAP
// Returns a slice of access points
// Deprecated: Use UAPs instead
func (u *Unifi) Aps(site *Site) ([]UAP, error) {
return u.UAPs(site)
}
// Returns a slice of access points
func (u *Unifi) UAPs(site *Site) ([]UAP, error) {
rawDevices, err := u.RawDevices(site, "uap")
if err != nil {
return nil, err
}
// Devices
var uaps []UAP
for _, v := range rawDevices {
var uap UAP
err := json.Unmarshal(v.Data, &uap)
if err != nil {
return uaps, err
}
// Set unifi pointer
uap.u = u
uaps = append(uaps, uap)
}
return uaps, nil
}
// Returns a map of access points with mac as a key
func (u *Unifi) UAPMap(site *Site) (UAPmap, error) {
aps, err := u.Aps(site)
if err != nil {
return nil, err
}
m := make(UAPmap)
for _, a := range aps {
m[a.Mac] = a
}
return m, nil
}
// Reboot access point
func (a UAP) Restart() error {
if a.u == nil {
return ErrLoginFirst
}
return a.u.devcmd(a.Mac, "restart")
}
func (a UAP) DeviceName() string {
if a.Name != "" {
return a.Name
}
// If no name is given, return mac as name
return a.Mac
}
func (a UAP) ModelName() string {
if m, ok := model[a.Model]; ok {
return m
}
return a.Model
}