-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmisc_types.go
227 lines (193 loc) · 4.47 KB
/
misc_types.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
package hitron
import (
"encoding/json"
"fmt"
"net"
"strconv"
"time"
)
const (
on = "ON"
yes = "YES"
enabled = "Enabled"
)
// Error contains common error code information.
type Error struct {
Code string `json:"errCode"`
Message string `json:"errMsg"`
}
func (e Error) String() string {
if e.Code == "000" {
return ""
}
return fmt.Sprintf("Error %s: %s", e.Code, e.Message)
}
// NoError represents the successful state
//
//nolint:gochecknoglobals
var NoError = Error{Code: "000", Message: ""}
// Time -
type Time struct {
Error
TZ *time.Location
SNTPServer string
DaylightTime int
Enable bool
Daylight bool
}
// UnmarshalJSON - implements json.Unmarshaler
func (s *Time) UnmarshalJSON(b []byte) error {
raw := struct {
Error
SntpOnOff string
SntpTimeZone string
SntpSrvName string
DaylightOnOff string
DaylightTime string
}{}
err := json.Unmarshal(b, &raw)
if err != nil {
return fmt.Errorf("failed to unmarshal Time %q: %w", string(b), err)
}
s.Error = raw.Error
s.Enable = raw.SntpOnOff == on
s.Daylight = raw.DaylightOnOff == on
s.SNTPServer = raw.SntpSrvName
s.TZ, _ = tzToLocation(raw.SntpTimeZone)
return nil
}
// DNS -
type DNS struct {
Error
DomainSuffix string
ProxyName1 string
ProxyName2 string
LanDNS1 net.IP
LanDNS2 net.IP
AutoEnable bool // whether to set DNS servers automatically, or manually
ProxyEnable bool // enable DNS proxying to DHCP clients on the LAN
}
// UnmarshalJSON - implements json.Unmarshaler
func (s *DNS) UnmarshalJSON(b []byte) error {
raw := struct {
Error
LanDNSOnOff string
DNSProxyOnOff string
DomainSuffix string
ProxyName1 string
ProxyName2 string
LanDNS1 net.IP
LanDNS2 net.IP
}{}
err := json.Unmarshal(b, &raw)
if err != nil {
return fmt.Errorf("failed to unmarshal DNS %q: %w", string(b), err)
}
s.Error = raw.Error
s.LanDNS1 = raw.LanDNS1
s.LanDNS2 = raw.LanDNS2
s.DomainSuffix = raw.DomainSuffix
s.ProxyName1 = raw.ProxyName1
s.ProxyName2 = raw.ProxyName2
s.AutoEnable = raw.LanDNSOnOff == on
s.ProxyEnable = raw.DNSProxyOnOff == on
return nil
}
// DDNS -
type DDNS struct {
Error
Provider string
Username string
Password string
Hostname string
UpdateInterval time.Duration
Enable bool
}
// UnmarshalJSON - implements json.Unmarshaler
func (s *DDNS) UnmarshalJSON(b []byte) error {
raw := struct {
Error
DDNSOnOff string
DDNSUsername string
DDNSPassword string
DDNSHostnames string
DDNSUpdateInterval string
DDNSSrvProvider int
}{}
err := json.Unmarshal(b, &raw)
if err != nil {
return fmt.Errorf("failed to unmarshal DDNS %q: %w", string(b), err)
}
s.Error = raw.Error
s.Username = raw.DDNSUsername
s.Password = raw.DDNSPassword
s.Hostname = raw.DDNSHostnames
s.Enable = raw.DDNSOnOff == on
// Just default to 0 if it can't be parsed
d, _ := strconv.Atoi(raw.DDNSUpdateInterval)
s.UpdateInterval = time.Duration(d) * time.Second
providers := map[int]string{
1: "[email protected]",
2: "[email protected]",
3: "[email protected]",
4: "[email protected]",
5: "[email protected]",
6: "[email protected]",
7: "[email protected]",
8: "[email protected]",
9: "[email protected]",
10: "[email protected]",
11: "[email protected]",
}
s.Provider = providers[raw.DDNSSrvProvider]
return nil
}
// Hosts -
type Hosts struct {
Error
Hosts []Host `json:"Hosts_List"`
}
// Host -
type Host struct {
Name string
AddressSource string
ConnectType string
Action string
MacAddr net.HardwareAddr
IP net.IP
ConnectTo net.HardwareAddr
Comnum int
AppEnable bool
}
// UnmarshalJSON - implements json.Unmarshaler
func (s *Host) UnmarshalJSON(b []byte) error {
raw := struct {
HostName string
AddressSource string
MacAddr string
ConnectType string
ConnectTo string
AppEnable string
Action string
IP net.IP
Comnum int
}{}
err := json.Unmarshal(b, &raw)
if err != nil {
return fmt.Errorf("failed to unmarshal Host %q: %w", string(b), err)
}
s.Name = raw.HostName
s.AddressSource = raw.AddressSource
s.IP = raw.IP
s.ConnectType = raw.ConnectType
s.Comnum = raw.Comnum
s.Action = raw.Action
s.AppEnable = raw.AppEnable == "TRUE"
s.MacAddr, _ = net.ParseMAC(raw.MacAddr)
s.ConnectTo, _ = net.ParseMAC(raw.ConnectTo)
return nil
}
type UsersCSRF struct {
Error
CSRF string
}