forked from dim13/unifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sta.go
120 lines (109 loc) · 3.86 KB
/
sta.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
// 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"
)
// Response[]UAP from controller
var response struct {
Data []json.RawMessage
Meta meta
}
type StaMap map[string]Sta
// Station data
type Sta struct {
u *Unifi
ID string `json:"_id"`
IsGuestByUsw bool `json:"_is_guest_by_usw,omitempty"`
LastSeenByUsw int `json:"_last_seen_by_usw,omitempty"`
UptimeByUsw int `json:"_uptime_by_usw,omitempty"`
AssocTime int `json:"assoc_time"`
FirstSeen int64 `json:"first_seen"`
IP string `json:"ip"`
IsGuest bool `json:"is_guest"`
IsWired bool `json:"is_wired"`
LastSeen int64 `json:"last_seen"`
LatestAssocTime int `json:"latest_assoc_time"`
Mac string `json:"mac"`
Network string `json:"network,omitempty"`
NetworkID string `json:"network_id,omitempty"`
Oui string `json:"oui"`
SiteID string `json:"site_id"`
SwDepth int `json:"sw_depth,omitempty"`
SwMac string `json:"sw_mac,omitempty"`
SwPort int `json:"sw_port,omitempty"`
Uptime int `json:"uptime"`
UserID string `json:"user_id"`
Hostname string `json:"hostname,omitempty"`
IsGuestByUap bool `json:"_is_guest_by_uap,omitempty"`
LastSeenByUap int `json:"_last_seen_by_uap,omitempty"`
RoamCount int `json:"roam_count,omitempty"`
UptimeByUap int `json:"_uptime_by_uap,omitempty"`
ApMac string `json:"ap_mac,omitempty"`
Authorized bool `json:"authorized,omitempty"`
BSSID string `json:"bssid,omitempty"`
BytesR int `json:"bytes-r,omitempty"`
Ccq int `json:"ccq,omitempty"`
Channel int `json:"channel,omitempty"`
ESSID string `json:"essid,omitempty"`
Idletime int `json:"idletime,omitempty"`
Is11R bool `json:"is_11r,omitempty"`
Noise int `json:"noise,omitempty"`
PowersaveEnabled bool `json:"powersave_enabled,omitempty"`
QosPolicyApplied bool `json:"qos_policy_applied,omitempty"`
Radio string `json:"radio,omitempty"`
RadioProto string `json:"radio_proto,omitempty"`
Rssi int `json:"rssi,omitempty"`
RxBytes int `json:"rx_bytes,omitempty"`
RxBytesR int `json:"rx_bytes-r,omitempty"`
RxPackets int `json:"rx_packets,omitempty"`
RxRate int `json:"rx_rate,omitempty"`
Signal int `json:"signal,omitempty"`
TxBytes int `json:"tx_bytes,omitempty"`
TxBytesR int `json:"tx_bytes-r,omitempty"`
TxPackets int `json:"tx_packets,omitempty"`
TxPower int `json:"tx_power,omitempty"`
TxRate int `json:"tx_rate,omitempty"`
Vlan int `json:"vlan,omitempty"`
}
// Returns a station name
func (s Sta) Name() string {
if s.Hostname != "" {
return s.Hostname
}
if s.IP != "" {
return s.IP
}
return s.Mac
}
func (s Sta) Block(site *Site) error {
if s.u == nil {
return ErrLoginFirst
}
return s.u.stacmd(site, s.Mac, "block-sta", Params{})
}
func (s Sta) UnBlock(site *Site) error {
if s.u == nil {
return ErrLoginFirst
}
return s.u.stacmd(site, s.Mac, "unblock-sta", Params{})
}
func (s Sta) Disconnect(site *Site) error {
if s.u == nil {
return ErrLoginFirst
}
return s.u.stacmd(site, s.Mac, "kick-sta", Params{})
}
func (s Sta) AuthorizeGuest(site *Site, params Params) error {
if s.u == nil {
return ErrLoginFirst
}
return s.u.stacmd(site, s.Mac, "authorize-guest", params)
}
func (s Sta) UnauthorizeGuest(site *Site) error {
if s.u == nil {
return ErrLoginFirst
}
return s.u.stacmd(site, s.Mac, "unauthorize-guest", Params{})
}