-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
types.go
356 lines (316 loc) · 8.18 KB
/
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
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
355
356
package utils
import (
"os"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Role int
type ProxyMode string
type LoggingLevel string
const (
GUEST = 0
USER = 1
ADMIN = 2
)
const (
DEBUG = 0
INFO = 1
WARNING = 2
ERROR = 3
)
var LoggingLevelLabels = map[LoggingLevel]int{
"DEBUG": DEBUG,
"INFO": INFO,
"WARNING": WARNING,
"ERROR": ERROR,
}
var ProxyModeList = map[string]string{
"PROXY": "PROXY",
"SPA": "SPA",
"STATIC": "STATIC",
"SERVAPP": "SERVAPP",
"REDIRECT": "REDIRECT",
}
var HTTPSCertModeList = map[string]string{
"DISABLED": "DISABLED",
"PROVIDED": "PROVIDED",
"SELFSIGNED": "SELFSIGNED",
"LETSENCRYPT": "LETSENCRYPT",
}
type FileStats struct {
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
Mode os.FileMode `json:"mode"`
ModTime time.Time `json:"modTime"`
IsDir bool `json:"isDir"`
}
type User struct {
ID primitive.ObjectID `json:"-" bson:"_id,omitempty"`
Nickname string `validate:"required" json:"nickname"`
Password string `validate:"required" json:"-"`
RegisterKey string `json:"registerKey"`
RegisterKeyExp time.Time `json:"registerKeyExp"`
Role Role `validate:"required" json:"role"`
PasswordCycle int `json:"-"`
Link string `json:"link"`
Email string `validate:"email" json:"email"`
RegisteredAt time.Time `json:"registeredAt"`
LastPasswordChangedAt time.Time `json:"lastPasswordChangedAt"`
CreatedAt time.Time `json:"createdAt"`
LastLogin time.Time `json:"lastLogin"`
MFAKey string `json:"-"`
Was2FAVerified bool `json:"-"`
MFAState int `json:"-"` // 0 = done, 1 = needed, 2 = not set
}
type Config struct {
LoggingLevel LoggingLevel `required,validate:"oneof=DEBUG INFO WARNING ERROR"`
MongoDB string
DisableUserManagement bool
NewInstall bool `validate:"boolean"`
HTTPConfig HTTPConfig `validate:"required,dive,required"`
EmailConfig EmailConfig `validate:"required,dive,required"`
DockerConfig DockerConfig
BlockedCountries []string
CountryBlacklistIsWhitelist bool
ServerCountry string
RequireMFA bool
AutoUpdate bool
OpenIDClients []OpenIDClient
MarketConfig MarketConfig
HomepageConfig HomepageConfig
ThemeConfig ThemeConfig
ConstellationConfig ConstellationConfig
MonitoringDisabled bool
MonitoringAlerts map[string]Alert
}
type HomepageConfig struct {
Background string
Widgets []string
Expanded bool
}
type ThemeConfig struct {
PrimaryColor string
SecondaryColor string
}
type HTTPConfig struct {
TLSCert string `validate:"omitempty,contains=\n`
TLSKey string
TLSKeyHostsCached []string
TLSValidUntil time.Time
AuthPrivateKey string
AuthPublicKey string
GenerateMissingAuthCert bool
HTTPSCertificateMode string
DNSChallengeProvider string
ForceHTTPSCertificateRenewal bool
HTTPPort string `validate:"required,containsany=0123456789,min=1,max=6"`
HTTPSPort string `validate:"required,containsany=0123456789,min=1,max=6"`
ProxyConfig ProxyConfig
Hostname string `validate:"required,excludesall=0x2C/ "`
SSLEmail string `validate:"omitempty,email"`
UseWildcardCertificate bool
OverrideWildcardDomains string `validate:"omitempty,excludesall=/ "`
AcceptAllInsecureHostname bool
DNSChallengeConfig map[string]string `json:"DNSChallengeConfig,omitempty"`
UseForwardedFor bool
}
const (
STRICT = 1
NORMAL = 2
LENIENT = 3
)
type SmartShieldPolicy struct {
Enabled bool
PolicyStrictness int
PerUserTimeBudget float64
PerUserRequestLimit int
PerUserByteLimit int64
PerUserSimultaneous int
MaxGlobalSimultaneous int
PrivilegedGroups int
}
type DockerConfig struct {
SkipPruneNetwork bool
DefaultDataPath string
}
type ProxyConfig struct {
Routes []ProxyRouteConfig
}
type AddionalFiltersConfig struct {
Type string
Name string
Value string
}
type ProxyRouteConfig struct {
Disabled bool
Name string `validate:"required"`
Description string
UseHost bool
Host string
UsePathPrefix bool
PathPrefix string
Timeout time.Duration
ThrottlePerMinute int
CORSOrigin string
StripPathPrefix bool
MaxBandwith int64
AuthEnabled bool
AdminOnly bool
Target string `validate:"required"`
SmartShield SmartShieldPolicy
Mode ProxyMode
BlockCommonBots bool
BlockAPIAbuse bool
AcceptInsecureHTTPSTarget bool
HideFromDashboard bool
DisableHeaderHardening bool
VerboseForwardHeader bool
AddionalFilters []AddionalFiltersConfig
RestrictToConstellation bool
OverwriteHostHeader string
WhitelistInboundIPs []string
}
type EmailConfig struct {
Enabled bool
Host string
Port string
Username string
Password string
From string
UseTLS bool
}
type OpenIDClient struct {
ID string `json:"id"`
Secret string `json:"secret"`
Redirect string `json:"redirect"`
}
type MarketConfig struct {
Sources []MarketSource
}
type MarketSource struct {
Name string
Url string
}
type ConstellationConfig struct {
Enabled bool
SlaveMode bool
PrivateNode bool
DNSDisabled bool
DNSPort string
DNSFallback string
DNSBlockBlacklist bool
DNSAdditionalBlocklists []string
CustomDNSEntries []ConstellationDNSEntry
NebulaConfig NebulaConfig
ConstellationHostname string
}
type ConstellationDNSEntry struct {
Type string
Key string
Value string
}
type ConstellationDevice struct {
Nickname string `json:"nickname"`
DeviceName string `json:"deviceName"`
PublicKey string `json:"publicKey"`
IP string `json:"ip"`
IsLighthouse bool `json:"isLighthouse"`
IsRelay bool `json:"isRelay"`
PublicHostname string `json:"publicHostname"`
Port string `json:"port"`
Blocked bool `json:"blocked"`
Fingerprint string `json:"fingerprint"`
APIKey string `json:"-"`
}
type NebulaFirewallRule struct {
Port string `yaml:"port"`
Proto string `yaml:"proto"`
Host string `yaml:"host"`
Groups []string `yaml:"groups,omitempty"omitempty"`
}
type NebulaConntrackConfig struct {
TCPTimeout string `yaml:"tcp_timeout"`
UDPTimeout string `yaml:"udp_timeout"`
DefaultTimeout string `yaml:"default_timeout"`
}
type NebulaConfig struct {
PKI struct {
CA string `yaml:"ca"`
Cert string `yaml:"cert"`
Key string `yaml:"key"`
Blocklist []string `yaml:"blocklist"`
} `yaml:"pki"`
StaticHostMap map[string][]string `yaml:"static_host_map"`
Lighthouse struct {
AMLighthouse bool `yaml:"am_lighthouse"`
Interval int `yaml:"interval"`
Hosts []string `yaml:"hosts"`
} `yaml:"lighthouse"`
Listen struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"listen"`
Punchy struct {
Punch bool `yaml:"punch"`
Respond bool `yaml:"respond"`
} `yaml:"punchy"`
Relay struct {
AMRelay bool `yaml:"am_relay"`
UseRelays bool `yaml:"use_relays"`
Relays []string `yaml:"relays"`
} `yaml:"relay"`
TUN struct {
Disabled bool `yaml:"disabled"`
Dev string `yaml:"dev"`
DropLocalBroadcast bool `yaml:"drop_local_broadcast"`
DropMulticast bool `yaml:"drop_multicast"`
TxQueue int `yaml:"tx_queue"`
MTU int `yaml:"mtu"`
Routes []string `yaml:"routes"`
UnsafeRoutes []string `yaml:"unsafe_routes"`
} `yaml:"tun"`
Logging struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
} `yaml:"logging"`
Firewall struct {
OutboundAction string `yaml:"outbound_action"`
InboundAction string `yaml:"inbound_action"`
Conntrack NebulaConntrackConfig `yaml:"conntrack"`
Outbound []NebulaFirewallRule `yaml:"outbound"`
Inbound []NebulaFirewallRule `yaml:"inbound"`
} `yaml:"firewall"`
}
type Device struct {
DeviceName string `json:"deviceName",validate:"required,min=3,max=32,alphanum"`
Nickname string `json:"nickname",validate:"required,min=3,max=32,alphanum"`
PublicKey string `json:"publicKey",omitempty`
PrivateKey string `json:"privateKey",omitempty`
IP string `json:"ip",validate:"required,ipv4"`
}
type Alert struct {
Name string
Enabled bool
Period string
TrackingMetric string
Condition AlertCondition
Actions []AlertAction
LastTriggered time.Time
Throttled bool
Severity string
}
type AlertCondition struct {
Operator string
Value int
Percent bool
}
type AlertAction struct {
Type string
Target string
}
type AlertMetricTrack struct {
Key string
Object string
Max uint64
}