|
@@ -21,17 +21,18 @@ import (
|
21
|
21
|
"gopkg.in/yaml.v2"
|
22
|
22
|
)
|
23
|
23
|
|
|
24
|
+// PassConfig holds the connection password.
|
24
|
25
|
type PassConfig struct {
|
25
|
26
|
Password string
|
26
|
27
|
}
|
27
|
28
|
|
28
|
|
-// TLSListenConfig defines configuration options for listening on TLS
|
|
29
|
+// TLSListenConfig defines configuration options for listening on TLS.
|
29
|
30
|
type TLSListenConfig struct {
|
30
|
31
|
Cert string
|
31
|
32
|
Key string
|
32
|
33
|
}
|
33
|
34
|
|
34
|
|
-// Certificate returns the TLS certificate assicated with this TLSListenConfig
|
|
35
|
+// Config returns the TLS contiguration assicated with this TLSListenConfig.
|
35
|
36
|
func (conf *TLSListenConfig) Config() (*tls.Config, error) {
|
36
|
37
|
cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
|
37
|
38
|
if err != nil {
|
|
@@ -43,6 +44,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
|
43
|
44
|
}, err
|
44
|
45
|
}
|
45
|
46
|
|
|
47
|
+// PasswordBytes returns the bytes represented by the password hash.
|
46
|
48
|
func (conf *PassConfig) PasswordBytes() []byte {
|
47
|
49
|
bytes, err := DecodePasswordHash(conf.Password)
|
48
|
50
|
if err != nil {
|
|
@@ -51,6 +53,7 @@ func (conf *PassConfig) PasswordBytes() []byte {
|
51
|
53
|
return bytes
|
52
|
54
|
}
|
53
|
55
|
|
|
56
|
+// AccountRegistrationConfig controls account registration.
|
54
|
57
|
type AccountRegistrationConfig struct {
|
55
|
58
|
Enabled bool
|
56
|
59
|
EnabledCallbacks []string `yaml:"enabled-callbacks"`
|
|
@@ -72,10 +75,12 @@ type AccountRegistrationConfig struct {
|
72
|
75
|
}
|
73
|
76
|
}
|
74
|
77
|
|
|
78
|
+// ChannelRegistrationConfig controls channel registration.
|
75
|
79
|
type ChannelRegistrationConfig struct {
|
76
|
80
|
Enabled bool
|
77
|
81
|
}
|
78
|
82
|
|
|
83
|
+// OperClassConfig defines a specific operator class.
|
79
|
84
|
type OperClassConfig struct {
|
80
|
85
|
Title string
|
81
|
86
|
WhoisLine string
|
|
@@ -83,6 +88,7 @@ type OperClassConfig struct {
|
83
|
88
|
Capabilities []string
|
84
|
89
|
}
|
85
|
90
|
|
|
91
|
+// OperConfig defines a specific operator's configuration.
|
86
|
92
|
type OperConfig struct {
|
87
|
93
|
Class string
|
88
|
94
|
Vhost string
|
|
@@ -98,11 +104,13 @@ func (conf *OperConfig) PasswordBytes() []byte {
|
98
|
104
|
return bytes
|
99
|
105
|
}
|
100
|
106
|
|
|
107
|
+// RestAPIConfig controls the integrated REST API.
|
101
|
108
|
type RestAPIConfig struct {
|
102
|
109
|
Enabled bool
|
103
|
110
|
Listen string
|
104
|
111
|
}
|
105
|
112
|
|
|
113
|
+// ConnectionLimitsConfig controls the automated connection limits.
|
106
|
114
|
type ConnectionLimitsConfig struct {
|
107
|
115
|
Enabled bool
|
108
|
116
|
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
|
@@ -111,6 +119,7 @@ type ConnectionLimitsConfig struct {
|
111
|
119
|
Exempted []string
|
112
|
120
|
}
|
113
|
121
|
|
|
122
|
+// ConnectionThrottleConfig controls the automated connection throttling.
|
114
|
123
|
type ConnectionThrottleConfig struct {
|
115
|
124
|
Enabled bool
|
116
|
125
|
CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
|
|
@@ -124,6 +133,7 @@ type ConnectionThrottleConfig struct {
|
124
|
133
|
Exempted []string
|
125
|
134
|
}
|
126
|
135
|
|
|
136
|
+// LoggingConfig controls a single logging method.
|
127
|
137
|
type LoggingConfig struct {
|
128
|
138
|
Method string
|
129
|
139
|
MethodStderr bool
|
|
@@ -136,11 +146,13 @@ type LoggingConfig struct {
|
136
|
146
|
Level logger.Level `yaml:"level-real"`
|
137
|
147
|
}
|
138
|
148
|
|
|
149
|
+// LineLenConfig controls line lengths.
|
139
|
150
|
type LineLenConfig struct {
|
140
|
151
|
Tags int
|
141
|
152
|
Rest int
|
142
|
153
|
}
|
143
|
154
|
|
|
155
|
+// STSConfig controls the STS configuration/
|
144
|
156
|
type STSConfig struct {
|
145
|
157
|
Enabled bool
|
146
|
158
|
Duration time.Duration `yaml:"duration-real"`
|
|
@@ -161,6 +173,7 @@ func (sts *STSConfig) Value() string {
|
161
|
173
|
return val
|
162
|
174
|
}
|
163
|
175
|
|
|
176
|
+// Config defines the overall configuration.
|
164
|
177
|
type Config struct {
|
165
|
178
|
Network struct {
|
166
|
179
|
Name string
|
|
@@ -215,12 +228,14 @@ type Config struct {
|
215
|
228
|
}
|
216
|
229
|
}
|
217
|
230
|
|
|
231
|
+// OperClass defines an assembled operator class.
|
218
|
232
|
type OperClass struct {
|
219
|
233
|
Title string
|
220
|
234
|
WhoisLine string `yaml:"whois-line"`
|
221
|
235
|
Capabilities map[string]bool // map to make lookups much easier
|
222
|
236
|
}
|
223
|
237
|
|
|
238
|
+// OperatorClasses returns a map of assembled operator classes from the given config.
|
224
|
239
|
func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
|
225
|
240
|
ocs := make(map[string]OperClass)
|
226
|
241
|
|
|
@@ -290,6 +305,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
|
290
|
305
|
return &ocs, nil
|
291
|
306
|
}
|
292
|
307
|
|
|
308
|
+// Oper represents a single assembled operator's config.
|
293
|
309
|
type Oper struct {
|
294
|
310
|
Class *OperClass
|
295
|
311
|
WhoisLine string
|
|
@@ -297,6 +313,7 @@ type Oper struct {
|
297
|
313
|
Pass []byte
|
298
|
314
|
}
|
299
|
315
|
|
|
316
|
+// Operators returns a map of operator configs from the given OperClass and config.
|
300
|
317
|
func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) {
|
301
|
318
|
operators := make(map[string]Oper)
|
302
|
319
|
for name, opConf := range conf.Opers {
|
|
@@ -327,6 +344,7 @@ func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error)
|
327
|
344
|
return operators, nil
|
328
|
345
|
}
|
329
|
346
|
|
|
347
|
+// TLSListeners returns a list of TLS listeners and their configs.
|
330
|
348
|
func (conf *Config) TLSListeners() map[string]*tls.Config {
|
331
|
349
|
tlsListeners := make(map[string]*tls.Config)
|
332
|
350
|
for s, tlsListenersConf := range conf.Server.TLSListeners {
|
|
@@ -344,6 +362,7 @@ func (conf *Config) TLSListeners() map[string]*tls.Config {
|
344
|
362
|
return tlsListeners
|
345
|
363
|
}
|
346
|
364
|
|
|
365
|
+// LoadConfig loads the given YAML configuration file.
|
347
|
366
|
func LoadConfig(filename string) (config *Config, err error) {
|
348
|
367
|
data, err := ioutil.ReadFile(filename)
|
349
|
368
|
if err != nil {
|