1 |
|
-module(mongoose_config_spec). |
2 |
|
|
3 |
|
%% entry point - returns the entire spec |
4 |
|
-export([root/0]). |
5 |
|
|
6 |
|
%% spec parts used by http handlers, modules and services |
7 |
|
-export([wpool/1, |
8 |
|
iqdisc/0, |
9 |
|
tls/2]). |
10 |
|
|
11 |
|
%% callbacks for the 'process' step |
12 |
|
-export([process_root/1, |
13 |
|
process_host/1, |
14 |
|
process_general/1, |
15 |
|
process_listener/2, |
16 |
|
process_c2s_tls/1, |
17 |
|
process_c2s_just_tls/1, |
18 |
|
process_just_tls/1, |
19 |
|
process_fast_tls/1, |
20 |
|
process_sasl_external/1, |
21 |
|
process_sasl_mechanism/1, |
22 |
|
process_auth/1, |
23 |
|
process_pool/2, |
24 |
|
process_ldap_connection/1, |
25 |
|
process_iqdisc/1, |
26 |
|
process_acl_condition/1, |
27 |
|
process_s2s_host_policy/1, |
28 |
|
process_s2s_address/1, |
29 |
|
process_domain_cert/1, |
30 |
|
process_infinity_as_zero/1]). |
31 |
|
|
32 |
|
-include("mongoose_config_spec.hrl"). |
33 |
|
|
34 |
|
-type config_node() :: config_section() | config_list() | config_option(). |
35 |
|
-type config_section() :: #section{}. |
36 |
|
-type config_list() :: #list{}. |
37 |
|
-type config_option() :: #option{}. |
38 |
|
|
39 |
|
-type option_type() :: boolean | binary | string | atom | int_or_infinity |
40 |
|
| int_or_atom | integer | float. |
41 |
|
|
42 |
|
-type wrapper() :: top_level_config_wrapper() | config_part_wrapper(). |
43 |
|
|
44 |
|
%% Wrap the value in a top-level config option |
45 |
|
-type top_level_config_wrapper() :: |
46 |
|
global_config % [{Key, Value}] |
47 |
|
| host_config. % Inside host_config: [{{Key, Host}, Value}] |
48 |
|
% Otherwise: one such option for each configured host |
49 |
|
|
50 |
|
%% Wrap the value in a nested config part - key-value pair or just a value |
51 |
|
-type config_part_wrapper() :: |
52 |
|
default % [{Key, Value}] for section items, [Value] for list items |
53 |
|
| item % [Value] |
54 |
|
| remove % [] - the item is ignored |
55 |
|
| none. % just Value - injects elements of Value into the parent section/list |
56 |
|
|
57 |
|
%% This option allows to put list/section items in a map |
58 |
|
-type format_items() :: |
59 |
|
list % keep the processed items in a list |
60 |
|
| map. % convert the processed items (which have to be a KV list) to a map |
61 |
|
|
62 |
|
-export_type([config_node/0, config_section/0, config_list/0, config_option/0, |
63 |
|
wrapper/0, format_items/0, option_type/0]). |
64 |
|
|
65 |
|
%% Config processing functions are annotated with TOML paths |
66 |
|
%% Path syntax: dotted, like TOML keys with the following additions: |
67 |
|
%% - '[]' denotes an element in a list |
68 |
|
%% - '( ... )' encloses an optional prefix |
69 |
|
%% - '*' is a wildcard for names - usually that name is passed as an argument |
70 |
|
%% If the path is the same as for the previous function, it is not repeated. |
71 |
|
%% |
72 |
|
%% Example: (host_config[].)access.* |
73 |
|
%% Meaning: either a key in the 'access' section, e.g. |
74 |
|
%% [access] |
75 |
|
%% local = ... |
76 |
|
%% or the same, but prefixed for a specific host, e.g. |
77 |
|
%% [[host_config]] |
78 |
|
%% host = "myhost" |
79 |
|
%% host_config.access |
80 |
|
%% local = ... |
81 |
|
|
82 |
|
root() -> |
83 |
53 |
General = general(), |
84 |
53 |
Listen = listen(), |
85 |
53 |
Auth = auth(), |
86 |
53 |
Modules = modules(), |
87 |
53 |
S2S = s2s(), |
88 |
53 |
#section{ |
89 |
|
items = #{<<"general">> => General#section{required = [<<"default_server_domain">>], |
90 |
|
process = fun ?MODULE:process_general/1, |
91 |
|
defaults = general_defaults()}, |
92 |
|
<<"listen">> => Listen#section{include = always}, |
93 |
|
<<"auth">> => Auth#section{include = always}, |
94 |
|
<<"outgoing_pools">> => outgoing_pools(), |
95 |
|
<<"internal_databases">> => internal_databases(), |
96 |
|
<<"services">> => services(), |
97 |
|
<<"modules">> => Modules#section{include = always}, |
98 |
|
<<"shaper">> => shaper(), |
99 |
|
<<"acl">> => acl(), |
100 |
|
<<"access">> => access(), |
101 |
|
<<"s2s">> => S2S#section{include = always}, |
102 |
|
<<"host_config">> => #list{items = host_config(), |
103 |
|
wrap = none} |
104 |
|
}, |
105 |
|
defaults = #{<<"internal_databases">> => default_internal_databases()}, |
106 |
|
required = [<<"general">>], |
107 |
|
process = fun ?MODULE:process_root/1, |
108 |
|
wrap = none, |
109 |
|
format_items = list |
110 |
|
}. |
111 |
|
|
112 |
|
%% path: host_config[] |
113 |
|
host_config() -> |
114 |
53 |
#section{ |
115 |
|
items = #{%% Host is only validated here - it is stored in the path, |
116 |
|
%% see mongoose_config_parser_toml:item_key/1 |
117 |
|
%% |
118 |
|
%% for every configured host the host_type of the same name |
119 |
|
%% is declared automatically. As host_config section is now |
120 |
|
%% used for changing configuration of the host_type, we don't |
121 |
|
%% need host option any more. but to stay compatible with an |
122 |
|
%% old config format we keep host option as well. now it is |
123 |
|
%% just a synonym to host_type. |
124 |
|
<<"host">> => #option{type = binary, |
125 |
|
validate = non_empty, |
126 |
|
wrap = remove}, |
127 |
|
|
128 |
|
<<"host_type">> => #option{type = binary, |
129 |
|
validate = non_empty, |
130 |
|
wrap = remove}, |
131 |
|
|
132 |
|
%% Sections below are allowed in host_config, |
133 |
|
%% but only options with 'wrap = host_config' are accepted. |
134 |
|
%% Options with 'wrap = global_config' would be caught by |
135 |
|
%% mongoose_config_parser_toml:wrap/3 |
136 |
|
<<"general">> => general(), |
137 |
|
<<"auth">> => auth(), |
138 |
|
<<"modules">> => modules(), |
139 |
|
<<"acl">> => acl(), |
140 |
|
<<"access">> => access(), |
141 |
|
<<"s2s">> => s2s() |
142 |
|
}, |
143 |
|
wrap = none, |
144 |
|
format_items = list |
145 |
|
}. |
146 |
|
|
147 |
|
%% path: general |
148 |
|
general() -> |
149 |
106 |
#section{ |
150 |
|
items = #{<<"loglevel">> => #option{type = atom, |
151 |
|
validate = loglevel, |
152 |
|
wrap = global_config}, |
153 |
|
<<"hosts">> => #list{items = #option{type = binary, |
154 |
|
validate = non_empty, |
155 |
|
process = fun ?MODULE:process_host/1}, |
156 |
|
validate = unique, |
157 |
|
wrap = global_config}, |
158 |
|
<<"host_types">> => #list{items = #option{type = binary, |
159 |
|
validate = non_empty}, |
160 |
|
validate = unique, |
161 |
|
wrap = global_config}, |
162 |
|
<<"default_server_domain">> => #option{type = binary, |
163 |
|
validate = non_empty, |
164 |
|
process = fun ?MODULE:process_host/1, |
165 |
|
wrap = global_config}, |
166 |
|
<<"registration_timeout">> => #option{type = int_or_infinity, |
167 |
|
validate = positive, |
168 |
|
wrap = global_config}, |
169 |
|
<<"language">> => #option{type = binary, |
170 |
|
validate = non_empty, |
171 |
|
wrap = global_config}, |
172 |
|
<<"all_metrics_are_global">> => #option{type = boolean, |
173 |
|
wrap = global_config}, |
174 |
|
<<"sm_backend">> => #option{type = atom, |
175 |
|
validate = {module, ejabberd_sm}, |
176 |
|
wrap = global_config}, |
177 |
|
<<"component_backend">> => #option{type = atom, |
178 |
|
validate = {module, mongoose_component}, |
179 |
|
wrap = global_config}, |
180 |
|
<<"s2s_backend">> => #option{type = atom, |
181 |
|
validate = {module, mongoose_s2s}, |
182 |
|
wrap = global_config}, |
183 |
|
<<"max_fsm_queue">> => #option{type = integer, |
184 |
|
validate = positive, |
185 |
|
wrap = global_config}, |
186 |
|
<<"http_server_name">> => #option{type = string, |
187 |
|
wrap = global_config}, |
188 |
|
<<"rdbms_server_type">> => #option{type = atom, |
189 |
|
validate = {enum, [mssql, pgsql]}, |
190 |
|
wrap = global_config}, |
191 |
|
<<"route_subdomains">> => #option{type = atom, |
192 |
|
validate = {enum, [s2s]}, |
193 |
|
wrap = host_config}, |
194 |
|
<<"routing_modules">> => #list{items = #option{type = atom, |
195 |
|
validate = module}, |
196 |
|
process = fun xmpp_router:expand_routing_modules/1, |
197 |
|
wrap = global_config}, |
198 |
|
<<"replaced_wait_timeout">> => #option{type = integer, |
199 |
|
validate = positive, |
200 |
|
wrap = host_config}, |
201 |
|
<<"hide_service_name">> => #option{type = boolean, |
202 |
|
wrap = global_config}, |
203 |
|
<<"domain_certfile">> => #list{items = domain_cert(), |
204 |
|
format_items = map, |
205 |
|
wrap = global_config} |
206 |
|
}, |
207 |
|
wrap = none, |
208 |
|
format_items = list |
209 |
|
}. |
210 |
|
|
211 |
|
general_defaults() -> |
212 |
53 |
#{<<"loglevel">> => warning, |
213 |
|
<<"hosts">> => [], |
214 |
|
<<"host_types">> => [], |
215 |
|
<<"registration_timeout">> => 600, |
216 |
|
<<"language">> => <<"en">>, |
217 |
|
<<"all_metrics_are_global">> => false, |
218 |
|
<<"sm_backend">> => mnesia, |
219 |
|
<<"component_backend">> => mnesia, |
220 |
|
<<"s2s_backend">> => mnesia, |
221 |
|
<<"rdbms_server_type">> => generic, |
222 |
|
<<"routing_modules">> => mongoose_router:default_routing_modules(), |
223 |
|
<<"replaced_wait_timeout">> => 2000, |
224 |
|
<<"hide_service_name">> => false}. |
225 |
|
|
226 |
|
%% path: general.domain_certfile |
227 |
|
domain_cert() -> |
228 |
106 |
#section{ |
229 |
|
items = #{<<"domain">> => #option{type = binary, |
230 |
|
validate = non_empty}, |
231 |
|
<<"certfile">> => #option{type = string, |
232 |
|
validate = filename}}, |
233 |
|
required = all, |
234 |
|
process = fun ?MODULE:process_domain_cert/1 |
235 |
|
}. |
236 |
|
|
237 |
|
%% path: listen |
238 |
|
listen() -> |
239 |
53 |
Keys = [c2s, s2s, service, http], |
240 |
53 |
#section{ |
241 |
212 |
items = maps:from_list([{atom_to_binary(Key), #list{items = listener(Key), wrap = none}} |
242 |
53 |
|| Key <- Keys]), |
243 |
|
process = fun mongoose_listener_config:verify_unique_listeners/1, |
244 |
|
wrap = global_config, |
245 |
|
format_items = list |
246 |
|
}. |
247 |
|
|
248 |
|
%% path: listen.*[] |
249 |
|
listener(Type) -> |
250 |
212 |
mongoose_config_utils:merge_sections(listener_common(), listener_extra(Type)). |
251 |
|
|
252 |
|
listener_common() -> |
253 |
212 |
#section{items = #{<<"port">> => #option{type = integer, |
254 |
|
validate = port}, |
255 |
|
<<"ip_address">> => #option{type = string, |
256 |
|
validate = ip_address}, |
257 |
|
<<"proto">> => #option{type = atom, |
258 |
|
validate = {enum, [tcp]}}, |
259 |
|
<<"ip_version">> => #option{type = integer, |
260 |
|
validate = {enum, [4, 6]}} |
261 |
|
}, |
262 |
|
required = [<<"port">>], |
263 |
|
defaults = #{<<"proto">> => tcp}, |
264 |
|
process = fun ?MODULE:process_listener/2 |
265 |
|
}. |
266 |
|
|
267 |
|
listener_extra(http) -> |
268 |
|
%% tls options passed to ranch_ssl (with verify_mode translated to verify_fun) |
269 |
53 |
#section{items = #{<<"tls">> => tls([server], [just_tls]), |
270 |
|
<<"transport">> => http_transport(), |
271 |
|
<<"protocol">> => http_protocol(), |
272 |
|
<<"handlers">> => mongoose_http_handler:config_spec()}}; |
273 |
|
listener_extra(Type) -> |
274 |
159 |
mongoose_config_utils:merge_sections(xmpp_listener_common(), xmpp_listener_extra(Type)). |
275 |
|
|
276 |
|
xmpp_listener_common() -> |
277 |
159 |
#section{items = #{<<"backlog">> => #option{type = integer, |
278 |
|
validate = non_negative}, |
279 |
|
<<"proxy_protocol">> => #option{type = boolean}, |
280 |
|
<<"hibernate_after">> => #option{type = int_or_infinity, |
281 |
|
validate = non_negative}, |
282 |
|
<<"max_stanza_size">> => #option{type = int_or_infinity, |
283 |
|
validate = positive, |
284 |
|
process = fun ?MODULE:process_infinity_as_zero/1}, |
285 |
|
<<"num_acceptors">> => #option{type = integer, |
286 |
|
validate = positive} |
287 |
|
}, |
288 |
|
defaults = #{<<"backlog">> => 1024, |
289 |
|
<<"proxy_protocol">> => false, |
290 |
|
<<"hibernate_after">> => 0, |
291 |
|
<<"max_stanza_size">> => 0, |
292 |
|
<<"num_acceptors">> => 100} |
293 |
|
}. |
294 |
|
|
295 |
|
xmpp_listener_extra(c2s) -> |
296 |
53 |
#section{items = #{<<"access">> => #option{type = atom, |
297 |
|
validate = non_empty}, |
298 |
|
<<"shaper">> => #option{type = atom, |
299 |
|
validate = non_empty}, |
300 |
|
<<"max_connections">> => #option{type = int_or_infinity, |
301 |
|
validate = positive}, |
302 |
|
<<"c2s_state_timeout">> => #option{type = int_or_infinity, |
303 |
|
validate = non_negative}, |
304 |
|
<<"reuse_port">> => #option{type = boolean}, |
305 |
|
<<"backwards_compatible_session">> => #option{type = boolean}, |
306 |
|
<<"allowed_auth_methods">> => |
307 |
|
#list{items = #option{type = atom, |
308 |
|
validate = {module, ejabberd_auth}}, |
309 |
|
validate = unique}, |
310 |
|
<<"tls">> => tls([server, c2s], [fast_tls, just_tls])}, |
311 |
|
defaults = #{<<"access">> => all, |
312 |
|
<<"shaper">> => none, |
313 |
|
<<"max_connections">> => infinity, |
314 |
|
<<"c2s_state_timeout">> => 5000, |
315 |
|
<<"reuse_port">> => false, |
316 |
|
<<"backwards_compatible_session">> => true} |
317 |
|
}; |
318 |
|
xmpp_listener_extra(s2s) -> |
319 |
53 |
TLSSection = tls([server], [fast_tls]), |
320 |
53 |
#section{items = #{<<"shaper">> => #option{type = atom, |
321 |
|
validate = non_empty}, |
322 |
|
<<"tls">> => TLSSection#section{include = always}}, |
323 |
|
defaults = #{<<"shaper">> => none} |
324 |
|
}; |
325 |
|
xmpp_listener_extra(service) -> |
326 |
53 |
#section{items = #{<<"access">> => #option{type = atom, |
327 |
|
validate = non_empty}, |
328 |
|
<<"shaper_rule">> => #option{type = atom, |
329 |
|
validate = non_empty}, |
330 |
|
<<"check_from">> => #option{type = boolean}, |
331 |
|
<<"hidden_components">> => #option{type = boolean}, |
332 |
|
<<"conflict_behaviour">> => #option{type = atom, |
333 |
|
validate = {enum, [kick_old, disconnect]}}, |
334 |
|
<<"password">> => #option{type = string, |
335 |
|
validate = non_empty}, |
336 |
|
<<"max_fsm_queue">> => #option{type = integer, |
337 |
|
validate = positive} |
338 |
|
}, |
339 |
|
required = [<<"password">>], |
340 |
|
defaults = #{<<"access">> => all, |
341 |
|
<<"shaper_rule">> => none, |
342 |
|
<<"check_from">> => true, |
343 |
|
<<"hidden_components">> => false, |
344 |
|
<<"conflict_behaviour">> => disconnect} |
345 |
|
}. |
346 |
|
|
347 |
|
%% path: listen.http[].transport |
348 |
|
http_transport() -> |
349 |
53 |
#section{ |
350 |
|
items = #{<<"num_acceptors">> => #option{type = integer, |
351 |
|
validate = positive}, |
352 |
|
<<"max_connections">> => #option{type = int_or_infinity, |
353 |
|
validate = non_negative} |
354 |
|
}, |
355 |
|
defaults = #{<<"num_acceptors">> => 100, |
356 |
|
<<"max_connections">> => 1024}, |
357 |
|
include = always |
358 |
|
}. |
359 |
|
|
360 |
|
%% path: listen.http[].protocol |
361 |
|
http_protocol() -> |
362 |
53 |
#section{ |
363 |
|
items = #{<<"compress">> => #option{type = boolean}}, |
364 |
|
defaults = #{<<"compress">> => false}, |
365 |
|
include = always |
366 |
|
}. |
367 |
|
|
368 |
|
%% path: (host_config[].)auth |
369 |
|
auth() -> |
370 |
106 |
Items = maps:from_list([{a2b(Method), ejabberd_auth:config_spec(Method)} || |
371 |
106 |
Method <- all_auth_methods()]), |
372 |
106 |
#section{ |
373 |
|
items = Items#{<<"methods">> => #list{items = #option{type = atom, |
374 |
|
validate = {module, ejabberd_auth}}}, |
375 |
|
<<"password">> => auth_password(), |
376 |
|
<<"sasl_external">> => |
377 |
|
#list{items = #option{type = atom, |
378 |
|
process = fun ?MODULE:process_sasl_external/1}}, |
379 |
|
<<"sasl_mechanisms">> => |
380 |
|
#list{items = #option{type = atom, |
381 |
|
validate = {module, cyrsasl}, |
382 |
|
process = fun ?MODULE:process_sasl_mechanism/1}}, |
383 |
|
<<"max_users_per_domain">> => #option{type = int_or_infinity, |
384 |
|
validate = positive} |
385 |
|
}, |
386 |
|
defaults = #{<<"sasl_external">> => [standard], |
387 |
|
<<"sasl_mechanisms">> => cyrsasl:default_modules(), |
388 |
|
<<"max_users_per_domain">> => infinity}, |
389 |
|
process = fun ?MODULE:process_auth/1, |
390 |
|
wrap = host_config |
391 |
|
}. |
392 |
|
|
393 |
|
%% path: (host_config[].)auth.password |
394 |
|
auth_password() -> |
395 |
106 |
#section{ |
396 |
|
items = #{<<"format">> => #option{type = atom, |
397 |
|
validate = {enum, [scram, plain]}}, |
398 |
|
<<"hash">> => #list{items = #option{type = atom, |
399 |
|
validate = {enum, [sha, sha224, sha256, |
400 |
|
sha384, sha512]}}, |
401 |
|
validate = unique_non_empty |
402 |
|
}, |
403 |
|
<<"scram_iterations">> => #option{type = integer, |
404 |
|
validate = positive} |
405 |
|
}, |
406 |
|
defaults = #{<<"format">> => scram, |
407 |
|
<<"scram_iterations">> => mongoose_scram:iterations()}, |
408 |
|
include = always |
409 |
|
}. |
410 |
|
|
411 |
|
%% path: internal_databases |
412 |
|
internal_databases() -> |
413 |
53 |
Items = #{<<"cets">> => internal_database_cets(), |
414 |
|
<<"mnesia">> => internal_database_mnesia()}, |
415 |
53 |
#section{items = Items, |
416 |
|
format_items = map, |
417 |
|
wrap = global_config}. |
418 |
|
|
419 |
|
default_internal_databases() -> |
420 |
53 |
#{mnesia => #{}}. |
421 |
|
|
422 |
|
%% path: internal_databases.cets |
423 |
|
internal_database_cets() -> |
424 |
53 |
#section{ |
425 |
|
items = #{<<"backend">> => #option{type = atom, |
426 |
|
validate = {enum, [file, rdbms]}}, |
427 |
|
<<"cluster_name">> => #option{type = atom, validate = non_empty}, |
428 |
|
%% Relative to the release directory (or an absolute name) |
429 |
|
<<"node_list_file">> => #option{type = string, |
430 |
|
validate = filename} |
431 |
|
}, |
432 |
|
defaults = #{<<"backend">> => rdbms, <<"cluster_name">> => mongooseim} |
433 |
|
}. |
434 |
|
|
435 |
|
%% path: internal_databases.mnesia |
436 |
|
internal_database_mnesia() -> |
437 |
53 |
#section{}. |
438 |
|
|
439 |
|
%% path: outgoing_pools |
440 |
|
outgoing_pools() -> |
441 |
53 |
PoolTypes = [<<"cassandra">>, <<"elastic">>, <<"http">>, <<"ldap">>, |
442 |
|
<<"rabbit">>, <<"rdbms">>, <<"redis">>], |
443 |
53 |
Items = [{Type, #section{items = #{default => outgoing_pool(Type)}, |
444 |
|
validate_keys = non_empty, |
445 |
|
wrap = none, |
446 |
53 |
format_items = list}} || Type <- PoolTypes], |
447 |
53 |
#section{items = maps:from_list(Items), |
448 |
|
format_items = list, |
449 |
|
wrap = global_config, |
450 |
|
include = always}. |
451 |
|
|
452 |
|
%% path: outgoing_pools.*.* |
453 |
|
outgoing_pool(Type) -> |
454 |
371 |
ExtraDefaults = extra_wpool_defaults(Type), |
455 |
371 |
Pool = mongoose_config_utils:merge_sections(wpool(ExtraDefaults), outgoing_pool_extra(Type)), |
456 |
371 |
Pool#section{wrap = item}. |
457 |
|
|
458 |
|
extra_wpool_defaults(<<"cassandra">>) -> |
459 |
53 |
#{<<"workers">> => 20}; |
460 |
|
extra_wpool_defaults(<<"rdbms">>) -> |
461 |
53 |
#{<<"call_timeout">> => 60000}; |
462 |
|
extra_wpool_defaults(_) -> |
463 |
265 |
#{}. |
464 |
|
|
465 |
|
wpool(ExtraDefaults) -> |
466 |
583 |
#section{items = #{<<"workers">> => #option{type = integer, |
467 |
|
validate = positive}, |
468 |
|
<<"strategy">> => #option{type = atom, |
469 |
|
validate = {enum, wpool_strategy_values()}}, |
470 |
|
<<"call_timeout">> => #option{type = integer, |
471 |
|
validate = positive} |
472 |
|
}, |
473 |
|
defaults = maps:merge(#{<<"workers">> => 10, |
474 |
|
<<"strategy">> => best_worker, |
475 |
|
<<"call_timeout">> => 5000}, ExtraDefaults)}. |
476 |
|
|
477 |
|
outgoing_pool_extra(Type) -> |
478 |
371 |
#section{items = #{<<"scope">> => #option{type = atom, |
479 |
|
validate = {enum, [global, host, single_host]}}, |
480 |
|
<<"host">> => #option{type = binary, |
481 |
|
validate = non_empty}, |
482 |
|
<<"connection">> => outgoing_pool_connection(Type) |
483 |
|
}, |
484 |
|
process = fun ?MODULE:process_pool/2, |
485 |
|
defaults = #{<<"scope">> => global} |
486 |
|
}. |
487 |
|
|
488 |
|
%% path: outgoing_pools.*.*.connection |
489 |
|
outgoing_pool_connection(<<"cassandra">>) -> |
490 |
53 |
#section{ |
491 |
|
items = #{<<"servers">> => #list{items = cassandra_server(), |
492 |
|
validate = unique_non_empty}, |
493 |
|
<<"keyspace">> => #option{type = atom, |
494 |
|
validate = non_empty}, |
495 |
|
<<"auth">> => #section{items = #{<<"plain">> => cassandra_auth_plain()}, |
496 |
|
required = all}, |
497 |
|
<<"tls">> => tls([client], [just_tls]) |
498 |
|
}, |
499 |
|
include = always, |
500 |
|
defaults = #{<<"servers">> => [#{host => "localhost", port => 9042}], |
501 |
|
<<"keyspace">> => mongooseim} |
502 |
|
}; |
503 |
|
outgoing_pool_connection(<<"elastic">>) -> |
504 |
53 |
#section{ |
505 |
|
items = #{<<"host">> => #option{type = binary, |
506 |
|
validate = non_empty}, |
507 |
|
<<"port">> => #option{type = integer, |
508 |
|
validate = port} |
509 |
|
}, |
510 |
|
include = always, |
511 |
|
defaults = #{<<"host">> => <<"localhost">>, |
512 |
|
<<"port">> => 9200} |
513 |
|
}; |
514 |
|
outgoing_pool_connection(<<"http">>) -> |
515 |
53 |
#section{ |
516 |
|
items = #{<<"host">> => #option{type = string, |
517 |
|
validate = non_empty}, |
518 |
|
<<"path_prefix">> => #option{type = binary, |
519 |
|
validate = non_empty}, |
520 |
|
<<"request_timeout">> => #option{type = integer, |
521 |
|
validate = non_negative}, |
522 |
|
<<"tls">> => tls([client], [just_tls]) |
523 |
|
}, |
524 |
|
include = always, |
525 |
|
required = [<<"host">>], |
526 |
|
defaults = #{<<"path_prefix">> => <<"/">>, |
527 |
|
<<"request_timeout">> => 2000} |
528 |
|
}; |
529 |
|
outgoing_pool_connection(<<"ldap">>) -> |
530 |
53 |
#section{ |
531 |
|
items = #{<<"servers">> => #list{items = #option{type = string}, |
532 |
|
validate = unique_non_empty}, |
533 |
|
<<"port">> => #option{type = integer, |
534 |
|
validate = port}, |
535 |
|
<<"root_dn">> => #option{type = binary}, |
536 |
|
<<"password">> => #option{type = binary}, |
537 |
|
<<"connect_interval">> => #option{type = integer, |
538 |
|
validate = positive}, |
539 |
|
<<"tls">> => tls([client], [just_tls]) |
540 |
|
}, |
541 |
|
include = always, |
542 |
|
defaults = #{<<"servers">> => ["localhost"], |
543 |
|
<<"root_dn">> => <<>>, |
544 |
|
<<"password">> => <<>>, |
545 |
|
<<"connect_interval">> => 10000}, |
546 |
|
process = fun ?MODULE:process_ldap_connection/1 |
547 |
|
}; |
548 |
|
outgoing_pool_connection(<<"rabbit">>) -> |
549 |
53 |
#section{ |
550 |
|
items = #{<<"host">> => #option{type = string, |
551 |
|
validate = non_empty}, |
552 |
|
<<"port">> => #option{type = integer, |
553 |
|
validate = port}, |
554 |
|
<<"username">> => #option{type = binary, |
555 |
|
validate = non_empty}, |
556 |
|
<<"password">> => #option{type = binary, |
557 |
|
validate = non_empty}, |
558 |
|
<<"confirms_enabled">> => #option{type = boolean}, |
559 |
|
<<"max_worker_queue_len">> => #option{type = int_or_infinity, |
560 |
|
validate = non_negative} |
561 |
|
}, |
562 |
|
include = always, |
563 |
|
defaults = #{<<"host">> => "localhost", |
564 |
|
<<"port">> => 5672, |
565 |
|
<<"username">> => <<"guest">>, |
566 |
|
<<"password">> => <<"guest">>, |
567 |
|
<<"confirms_enabled">> => false, |
568 |
|
<<"max_worker_queue_len">> => 1000} |
569 |
|
}; |
570 |
|
outgoing_pool_connection(<<"rdbms">>) -> |
571 |
53 |
#section{ |
572 |
|
items = #{<<"driver">> => #option{type = atom, |
573 |
|
validate = {enum, [odbc, pgsql, mysql]}}, |
574 |
|
<<"keepalive_interval">> => #option{type = integer, |
575 |
|
validate = positive}, |
576 |
|
<<"query_timeout">> => #option{type = integer, |
577 |
|
validate = non_negative}, |
578 |
|
<<"max_start_interval">> => #option{type = integer, |
579 |
|
validate = positive}, |
580 |
|
|
581 |
|
% odbc |
582 |
|
<<"settings">> => #option{type = string}, |
583 |
|
|
584 |
|
% mysql, pgsql |
585 |
|
<<"host">> => #option{type = string, |
586 |
|
validate = non_empty}, |
587 |
|
<<"database">> => #option{type = string, |
588 |
|
validate = non_empty}, |
589 |
|
<<"username">> => #option{type = string, |
590 |
|
validate = non_empty}, |
591 |
|
<<"password">> => #option{type = string, |
592 |
|
validate = non_empty}, |
593 |
|
<<"port">> => #option{type = integer, |
594 |
|
validate = port}, |
595 |
|
<<"tls">> => sql_tls() |
596 |
|
}, |
597 |
|
required = [<<"driver">>], |
598 |
|
defaults = #{<<"query_timeout">> => 5000, |
599 |
|
<<"max_start_interval">> => 30}, |
600 |
|
process = fun mongoose_rdbms:process_options/1 |
601 |
|
}; |
602 |
|
outgoing_pool_connection(<<"redis">>) -> |
603 |
53 |
#section{ |
604 |
|
items = #{<<"host">> => #option{type = string, |
605 |
|
validate = non_empty}, |
606 |
|
<<"port">> => #option{type = integer, |
607 |
|
validate = port}, |
608 |
|
<<"database">> => #option{type = integer, |
609 |
|
validate = non_negative}, |
610 |
|
<<"password">> => #option{type = string} |
611 |
|
}, |
612 |
|
include = always, |
613 |
|
defaults = #{<<"host">> => "127.0.0.1", |
614 |
|
<<"port">> => 6379, |
615 |
|
<<"database">> => 0, |
616 |
|
<<"password">> => ""} |
617 |
|
}. |
618 |
|
|
619 |
|
cassandra_server() -> |
620 |
53 |
#section{ |
621 |
|
items = #{<<"host">> => #option{type = string, |
622 |
|
validate = non_empty}, |
623 |
|
<<"port">> => #option{type = integer, |
624 |
|
validate = port}}, |
625 |
|
required = [<<"host">>], |
626 |
|
defaults = #{<<"port">> => 9042} |
627 |
|
}. |
628 |
|
|
629 |
|
%% path: outgoing_pools.cassandra.*.connection.auth.plain |
630 |
|
cassandra_auth_plain() -> |
631 |
53 |
#section{ |
632 |
|
items = #{<<"username">> => #option{type = binary}, |
633 |
|
<<"password">> => #option{type = binary}}, |
634 |
|
required = all |
635 |
|
}. |
636 |
|
|
637 |
|
%% path: outgoing_pools.rdbms.*.connection.tls |
638 |
|
sql_tls() -> |
639 |
53 |
mongoose_config_utils:merge_sections(tls([client], [just_tls]), sql_tls_extra()). |
640 |
|
|
641 |
|
sql_tls_extra() -> |
642 |
53 |
#section{items = #{<<"required">> => #option{type = boolean}}}. |
643 |
|
|
644 |
|
%% TLS options |
645 |
|
|
646 |
|
tls(Entities, Modules) when is_list(Entities), is_list(Modules) -> |
647 |
581 |
Sections = [tls(Entity, Module) || Entity <- [common | Entities], |
648 |
1425 |
Module <- [common | Modules]], |
649 |
581 |
lists:foldl(fun mongoose_config_utils:merge_sections/2, hd(Sections), tl(Sections)); |
650 |
|
tls(common, common) -> |
651 |
581 |
#section{items = #{<<"verify_mode">> => #option{type = atom, |
652 |
|
validate = {enum, [peer, selfsigned_peer, none]}}, |
653 |
|
<<"certfile">> => #option{type = string, |
654 |
|
validate = filename}, |
655 |
|
<<"cacertfile">> => #option{type = string, |
656 |
|
validate = filename}, |
657 |
|
<<"ciphers">> => #option{type = string} |
658 |
|
}, |
659 |
|
defaults = #{<<"verify_mode">> => peer}}; |
660 |
|
tls(common, fast_tls) -> |
661 |
303 |
#section{items = #{<<"protocol_options">> => #list{items = #option{type = string, |
662 |
|
validate = non_empty}}}, |
663 |
|
process = fun ?MODULE:process_fast_tls/1}; |
664 |
|
tls(common, just_tls) -> |
665 |
331 |
#section{items = #{<<"keyfile">> => #option{type = string, |
666 |
|
validate = filename}, |
667 |
|
<<"password">> => #option{type = string}, |
668 |
|
<<"versions">> => #list{items = #option{type = atom}}}, |
669 |
|
process = fun ?MODULE:process_just_tls/1}; |
670 |
|
tls(server, common) -> |
671 |
369 |
#section{items = #{<<"dhfile">> => #option{type = string, |
672 |
|
validate = filename}}}; |
673 |
|
tls(server, _) -> |
674 |
422 |
#section{}; |
675 |
|
tls(client, common) -> |
676 |
318 |
#section{}; |
677 |
|
tls(client, fast_tls) -> |
678 |
106 |
#section{}; |
679 |
|
tls(client, just_tls) -> |
680 |
212 |
#section{items = #{<<"server_name_indication">> => server_name_indication()}}; |
681 |
|
tls(c2s, common) -> |
682 |
157 |
#section{items = #{<<"module">> => #option{type = atom, |
683 |
|
validate = {enum, [fast_tls, just_tls]}}, |
684 |
|
<<"mode">> => #option{type = atom, |
685 |
|
validate = {enum, [tls, starttls, starttls_required]}}}, |
686 |
|
defaults = #{<<"module">> => fast_tls, |
687 |
|
<<"mode">> => starttls}, |
688 |
|
process = fun ?MODULE:process_c2s_tls/1}; |
689 |
|
tls(c2s, just_tls) -> |
690 |
66 |
#section{items = #{<<"disconnect_on_failure">> => #option{type = boolean}, |
691 |
|
<<"crl_files">> => #list{items = #option{type = string, |
692 |
|
validate = filename}}}, |
693 |
|
process = fun ?MODULE:process_c2s_just_tls/1}; |
694 |
|
tls(c2s, fast_tls) -> |
695 |
144 |
#section{}. |
696 |
|
|
697 |
|
server_name_indication() -> |
698 |
212 |
#section{items = #{<<"enabled">> => #option{type = boolean}, |
699 |
|
<<"host">> => #option{type = string, |
700 |
|
validate = non_empty}, |
701 |
|
<<"protocol">> => #option{type = atom, |
702 |
|
validate = {enum, [default, https]}} |
703 |
|
}, |
704 |
|
defaults = #{<<"enabled">> => true, |
705 |
|
<<"protocol">> => default}, |
706 |
|
include = always}. |
707 |
|
|
708 |
|
%% path: (host_config[].)services |
709 |
|
services() -> |
710 |
53 |
Services = [{a2b(Service), mongoose_service:config_spec(Service)} |
711 |
53 |
|| Service <- configurable_services()], |
712 |
53 |
#section{ |
713 |
|
items = maps:from_list(Services), |
714 |
|
wrap = global_config, |
715 |
|
include = always |
716 |
|
}. |
717 |
|
|
718 |
|
configurable_services() -> |
719 |
53 |
[service_mongoose_system_metrics, |
720 |
|
service_domain_db]. |
721 |
|
|
722 |
|
%% path: (host_config[].)modules |
723 |
|
modules() -> |
724 |
106 |
Modules = [{a2b(Module), gen_mod:config_spec(Module)} |
725 |
106 |
|| Module <- configurable_modules()], |
726 |
106 |
Items = maps:from_list(Modules), |
727 |
106 |
#section{ |
728 |
|
items = Items#{default => #section{}}, |
729 |
|
validate_keys = module, |
730 |
|
wrap = host_config |
731 |
|
}. |
732 |
|
|
733 |
|
configurable_modules() -> |
734 |
106 |
[mod_adhoc, |
735 |
|
mod_auth_token, |
736 |
|
mod_blocking, |
737 |
|
mod_bosh, |
738 |
|
mod_cache_users, |
739 |
|
mod_caps, |
740 |
|
mod_carboncopy, |
741 |
|
mod_csi, |
742 |
|
mod_disco, |
743 |
|
mod_event_pusher, |
744 |
|
mod_extdisco, |
745 |
|
mod_global_distrib, |
746 |
|
mod_http_upload, |
747 |
|
mod_inbox, |
748 |
|
mod_jingle_sip, |
749 |
|
mod_keystore, |
750 |
|
mod_last, |
751 |
|
mod_mam, |
752 |
|
mod_muc, |
753 |
|
mod_muc_light, |
754 |
|
mod_muc_log, |
755 |
|
mod_offline, |
756 |
|
mod_offline_chatmarkers, |
757 |
|
mod_ping, |
758 |
|
mod_privacy, |
759 |
|
mod_private, |
760 |
|
mod_pubsub, |
761 |
|
mod_push_service_mongoosepush, |
762 |
|
mod_register, |
763 |
|
mod_roster, |
764 |
|
mod_shared_roster_ldap, |
765 |
|
mod_smart_markers, |
766 |
|
mod_sic, |
767 |
|
mod_stream_management, |
768 |
|
mod_time, |
769 |
|
mod_vcard, |
770 |
|
mod_version, |
771 |
|
mod_domain_isolation]. |
772 |
|
|
773 |
|
%% path: (host_config[].)modules.*.iqdisc |
774 |
|
iqdisc() -> |
775 |
2014 |
#section{ |
776 |
|
items = #{<<"type">> => #option{type = atom, |
777 |
|
validate = {enum, [no_queue, one_queue, parallel, queues]}}, |
778 |
|
<<"workers">> => #option{type = integer, |
779 |
|
validate = positive}}, |
780 |
|
required = [<<"type">>], |
781 |
|
process = fun ?MODULE:process_iqdisc/1 |
782 |
|
}. |
783 |
|
|
784 |
:-( |
process_iqdisc(#{type := Type, workers := N}) -> {queues = Type, N}; |
785 |
:-( |
process_iqdisc(#{type := Type}) -> Type. |
786 |
|
|
787 |
|
%% path: shaper |
788 |
|
shaper() -> |
789 |
53 |
#section{ |
790 |
|
items = #{default => |
791 |
|
#section{ |
792 |
|
items = #{<<"max_rate">> => #option{type = integer, |
793 |
|
validate = positive}}, |
794 |
|
required = all |
795 |
|
} |
796 |
|
}, |
797 |
|
validate_keys = non_empty, |
798 |
|
wrap = global_config |
799 |
|
}. |
800 |
|
|
801 |
|
%% path: (host_config[].)acl |
802 |
|
acl() -> |
803 |
106 |
#section{ |
804 |
|
items = #{default => #list{items = acl_item()}}, |
805 |
|
wrap = host_config |
806 |
|
}. |
807 |
|
|
808 |
|
%% path: (host_config[].)acl.*[] |
809 |
|
acl_item() -> |
810 |
106 |
Match = #option{type = atom, |
811 |
|
validate = {enum, [all, none, current_domain, any_hosted_domain]}}, |
812 |
106 |
Cond = #option{type = binary, |
813 |
|
process = fun ?MODULE:process_acl_condition/1}, |
814 |
106 |
#section{ |
815 |
|
items = #{<<"match">> => Match, |
816 |
|
<<"user">> => Cond, |
817 |
|
<<"server">> => Cond, |
818 |
|
<<"resource">> => Cond, |
819 |
|
<<"user_regexp">> => Cond, |
820 |
|
<<"server_regexp">> => Cond, |
821 |
|
<<"resource_regexp">> => Cond, |
822 |
|
<<"user_glob">> => Cond, |
823 |
|
<<"server_glob">> => Cond, |
824 |
|
<<"resource_glob">> => Cond |
825 |
|
}, |
826 |
|
defaults = #{<<"match">> => current_domain} |
827 |
|
}. |
828 |
|
|
829 |
|
%% path: (host_config[].)access |
830 |
|
access() -> |
831 |
106 |
#section{ |
832 |
|
items = #{default => #list{items = access_rule_item()}}, |
833 |
|
wrap = host_config |
834 |
|
}. |
835 |
|
|
836 |
|
%% path: (host_config[].)access.*[] |
837 |
|
access_rule_item() -> |
838 |
106 |
#section{ |
839 |
|
items = #{<<"acl">> => #option{type = atom, |
840 |
|
validate = non_empty}, |
841 |
|
<<"value">> => #option{type = int_or_atom} |
842 |
|
}, |
843 |
|
required = all |
844 |
|
}. |
845 |
|
|
846 |
|
%% path: (host_config[].)s2s |
847 |
|
s2s() -> |
848 |
106 |
#section{ |
849 |
|
items = #{<<"default_policy">> => #option{type = atom, |
850 |
|
validate = {enum, [allow, deny]}}, |
851 |
|
<<"host_policy">> => #list{items = s2s_host_policy(), |
852 |
|
format_items = map}, |
853 |
|
<<"use_starttls">> => #option{type = atom, |
854 |
|
validate = {enum, [false, optional, required, |
855 |
|
required_trusted]}}, |
856 |
|
<<"certfile">> => #option{type = string, |
857 |
|
validate = filename}, |
858 |
|
<<"shared">> => #option{type = binary, |
859 |
|
validate = non_empty}, |
860 |
|
<<"address">> => #list{items = s2s_address(), |
861 |
|
format_items = map}, |
862 |
|
<<"ciphers">> => #option{type = string}, |
863 |
|
<<"max_retry_delay">> => #option{type = integer, |
864 |
|
validate = positive}, |
865 |
|
<<"outgoing">> => s2s_outgoing(), |
866 |
|
<<"dns">> => s2s_dns()}, |
867 |
|
defaults = #{<<"default_policy">> => allow, |
868 |
|
<<"use_starttls">> => false, |
869 |
|
<<"ciphers">> => mongoose_tls:default_ciphers(), |
870 |
|
<<"max_retry_delay">> => 300}, |
871 |
|
wrap = host_config |
872 |
|
}. |
873 |
|
|
874 |
|
%% path: (host_config[].)s2s.dns |
875 |
|
s2s_dns() -> |
876 |
106 |
#section{ |
877 |
|
items = #{<<"timeout">> => #option{type = integer, |
878 |
|
validate = positive}, |
879 |
|
<<"retries">> => #option{type = integer, |
880 |
|
validate = positive}}, |
881 |
|
include = always, |
882 |
|
defaults = #{<<"timeout">> => 10, |
883 |
|
<<"retries">> => 2} |
884 |
|
}. |
885 |
|
|
886 |
|
%% path: (host_config[].)s2s.outgoing |
887 |
|
s2s_outgoing() -> |
888 |
106 |
#section{ |
889 |
|
items = #{<<"port">> => #option{type = integer, |
890 |
|
validate = port}, |
891 |
|
<<"ip_versions">> => |
892 |
|
#list{items = #option{type = integer, |
893 |
|
validate = {enum, [4, 6]}}, |
894 |
|
validate = unique_non_empty}, |
895 |
|
<<"connection_timeout">> => #option{type = int_or_infinity, |
896 |
|
validate = positive} |
897 |
|
}, |
898 |
|
include = always, |
899 |
|
defaults = #{<<"port">> => 5269, |
900 |
|
<<"ip_versions">> => [4, 6], |
901 |
|
<<"connection_timeout">> => 10000} |
902 |
|
}. |
903 |
|
|
904 |
|
%% path: (host_config[].)s2s.host_policy[] |
905 |
|
s2s_host_policy() -> |
906 |
106 |
#section{ |
907 |
|
items = #{<<"host">> => #option{type = binary, |
908 |
|
validate = non_empty}, |
909 |
|
<<"policy">> => #option{type = atom, |
910 |
|
validate = {enum, [allow, deny]}} |
911 |
|
}, |
912 |
|
required = all, |
913 |
|
process = fun ?MODULE:process_s2s_host_policy/1 |
914 |
|
}. |
915 |
|
|
916 |
|
%% path: (host_config[].)s2s.address[] |
917 |
|
s2s_address() -> |
918 |
106 |
#section{ |
919 |
|
items = #{<<"host">> => #option{type = binary, |
920 |
|
validate = non_empty}, |
921 |
|
<<"ip_address">> => #option{type = string, |
922 |
|
validate = ip_address}, |
923 |
|
<<"port">> => #option{type = integer, |
924 |
|
validate = port} |
925 |
|
}, |
926 |
|
required = [<<"host">>, <<"ip_address">>], |
927 |
|
process = fun ?MODULE:process_s2s_address/1 |
928 |
|
}. |
929 |
|
|
930 |
|
%% Callbacks for 'process' |
931 |
|
|
932 |
|
%% Check that all auth methods and modules enabled for any host type support dynamic domains |
933 |
|
process_root(Items) -> |
934 |
53 |
case proplists:lookup(host_types, Items) of |
935 |
|
{_, [_|_] = HostTypes} -> |
936 |
50 |
HTItems = lists:filter(fun(Item) -> is_host_type_item(Item, HostTypes) end, Items), |
937 |
50 |
case {unsupported_auth_methods(HTItems), unsupported_modules(HTItems)} of |
938 |
|
{[], []} -> |
939 |
50 |
Items; |
940 |
|
{Methods, Modules} -> |
941 |
:-( |
error(#{what => dynamic_domains_not_supported, |
942 |
|
text => ("Dynamic modules not supported by the specified authentication " |
943 |
|
"methods and/or extension modules"), |
944 |
|
unsupported_auth_methods => Methods, |
945 |
|
unsupported_modules => Modules}) |
946 |
|
end; |
947 |
|
_ -> |
948 |
3 |
Items |
949 |
|
end. |
950 |
|
|
951 |
|
unsupported_auth_methods(KVs) -> |
952 |
50 |
[Method || Method <- extract_auth_methods(KVs), |
953 |
127 |
not ejabberd_auth:does_method_support(Method, dynamic_domains)]. |
954 |
|
|
955 |
|
unsupported_modules(KVs) -> |
956 |
50 |
[Module || Module <- extract_modules(KVs), |
957 |
554 |
not gen_mod:does_module_support(Module, dynamic_domains)]. |
958 |
|
|
959 |
|
extract_auth_methods(KVs) -> |
960 |
50 |
lists:usort(lists:flatmap(fun({{auth, _}, Auth}) -> maps:get(methods, Auth); |
961 |
327 |
(_) -> [] |
962 |
|
end, KVs)). |
963 |
|
|
964 |
|
extract_modules(KVs) -> |
965 |
50 |
lists:usort(lists:flatmap(fun({{modules, _}, Modules}) -> maps:keys(Modules); |
966 |
327 |
(_) -> [] |
967 |
|
end, KVs)). |
968 |
|
|
969 |
|
is_host_type_item({{_, HostType}, _}, HostTypes) -> |
970 |
504 |
HostType =:= global orelse lists:member(HostType, HostTypes); |
971 |
|
is_host_type_item(_, _) -> |
972 |
973 |
false. |
973 |
|
|
974 |
|
process_host(Host) -> |
975 |
209 |
Node = jid:nodeprep(Host), |
976 |
209 |
true = Node =/= error, |
977 |
209 |
Node. |
978 |
|
|
979 |
|
process_general(General) -> |
980 |
53 |
hosts_and_host_types_are_unique_and_non_empty(General), |
981 |
53 |
General. |
982 |
|
|
983 |
|
hosts_and_host_types_are_unique_and_non_empty(General) -> |
984 |
53 |
AllHostTypes = get_all_hosts_and_host_types(General), |
985 |
53 |
true = lists:sort(AllHostTypes) =:= lists:usort(AllHostTypes), |
986 |
53 |
true = [] =/= AllHostTypes. |
987 |
|
|
988 |
|
get_all_hosts_and_host_types(General) -> |
989 |
53 |
lists:flatmap(fun({Key, Value}) when Key =:= hosts; |
990 |
|
Key =:= host_types -> |
991 |
106 |
Value; |
992 |
|
(_) -> |
993 |
712 |
[] |
994 |
|
end, General). |
995 |
|
|
996 |
|
%% User chooses just_tls or fast_tls, and this choice limits the allowed keys |
997 |
|
process_c2s_tls(M = #{module := Module}) -> |
998 |
104 |
AllowedItems = (tls([server, c2s], [Module]))#section.items, |
999 |
104 |
AllowedKeys = [binary_to_atom(Key) || Key <- maps:keys(AllowedItems)] ++ [module, mode], |
1000 |
104 |
case maps:keys(M) -- AllowedKeys of |
1001 |
104 |
[] -> M; |
1002 |
:-( |
UnexpectedKeys -> error(#{what => unexpected_tls_options, |
1003 |
|
tls_module => Module, |
1004 |
|
unexpected_keys => UnexpectedKeys}) |
1005 |
|
end. |
1006 |
|
|
1007 |
|
process_c2s_just_tls(#{module := just_tls} = M) -> |
1008 |
13 |
maps:merge(just_tls_c2s_defaults(), M); |
1009 |
|
process_c2s_just_tls(M) -> |
1010 |
91 |
M. |
1011 |
|
|
1012 |
|
just_tls_c2s_defaults() -> |
1013 |
13 |
#{crl_files => [], |
1014 |
|
disconnect_on_failure => true}. |
1015 |
|
|
1016 |
|
process_just_tls(M = #{module := fast_tls}) -> |
1017 |
91 |
M; |
1018 |
|
process_just_tls(M = #{cacertfile := _}) -> |
1019 |
102 |
M; |
1020 |
|
process_just_tls(M = #{verify_mode := none}) -> |
1021 |
70 |
M; |
1022 |
|
process_just_tls(_) -> |
1023 |
:-( |
error(#{what => missing_cacertfile, |
1024 |
|
text => <<"You need to provide CA certificate (cacertfile) " |
1025 |
|
"or disable peer verification (verify_mode)">>}). |
1026 |
|
|
1027 |
|
process_fast_tls(M = #{module := just_tls}) -> |
1028 |
13 |
M; |
1029 |
|
process_fast_tls(#{verify_mode := selfsigned_peer}) -> |
1030 |
:-( |
error(#{what => invalid_tls_verify_mode, |
1031 |
|
text => <<"fast_tls does not support self-signed certificate verification">>}); |
1032 |
|
process_fast_tls(M) -> |
1033 |
144 |
maps:merge(fast_tls_defaults(), M). |
1034 |
|
|
1035 |
|
fast_tls_defaults() -> |
1036 |
144 |
#{ciphers => mongoose_tls:default_ciphers(), |
1037 |
|
protocol_options => ["no_sslv2", "no_sslv3", "no_tlsv1", "no_tlsv1_1"]}. |
1038 |
|
|
1039 |
|
process_listener([item, Type | _], Opts) -> |
1040 |
634 |
mongoose_listener_config:ensure_ip_options(Opts#{module => listener_module(Type), |
1041 |
|
connection_type => connection_type(Type)}). |
1042 |
|
|
1043 |
371 |
listener_module(<<"http">>) -> ejabberd_cowboy; |
1044 |
104 |
listener_module(<<"c2s">>) -> mongoose_c2s_listener; |
1045 |
53 |
listener_module(<<"s2s">>) -> ejabberd_s2s_in; |
1046 |
106 |
listener_module(<<"service">>) -> ejabberd_service. |
1047 |
|
|
1048 |
|
%% required for correct metrics reporting by mongoose_transport module |
1049 |
53 |
connection_type(<<"s2s">>) -> s2s; |
1050 |
106 |
connection_type(<<"service">>) -> component; |
1051 |
475 |
connection_type(_) -> undefined. |
1052 |
|
|
1053 |
|
process_sasl_external(V) when V =:= standard; |
1054 |
|
V =:= common_name; |
1055 |
|
V =:= auth_id -> |
1056 |
21 |
V; |
1057 |
|
process_sasl_external(M) -> |
1058 |
3 |
mongoose_config_validator:validate(M, atom, module), |
1059 |
3 |
{mod, M}. |
1060 |
|
|
1061 |
|
process_sasl_mechanism(V) -> |
1062 |
18 |
list_to_atom("cyrsasl_" ++ atom_to_list(V)). |
1063 |
|
|
1064 |
|
process_auth(Opts = #{methods := Methods}) -> |
1065 |
:-( |
[check_auth_method(Method, Opts) || Method <- Methods], |
1066 |
:-( |
Opts; |
1067 |
|
process_auth(Opts) -> |
1068 |
181 |
MethodsFromSections = lists:filter(fun(K) -> maps:is_key(K, Opts) end, all_auth_methods()), |
1069 |
181 |
Opts#{methods => MethodsFromSections}. |
1070 |
|
|
1071 |
|
all_auth_methods() -> |
1072 |
287 |
[anonymous, dummy, external, http, internal, jwt, ldap, pki, rdbms]. |
1073 |
|
|
1074 |
|
check_auth_method(Method, Opts) -> |
1075 |
:-( |
case maps:is_key(Method, Opts) of |
1076 |
:-( |
true -> ok; |
1077 |
:-( |
false -> error(#{what => missing_section_for_auth_method, auth_method => Method}) |
1078 |
|
end. |
1079 |
|
|
1080 |
|
process_pool([Tag, Type|_], AllOpts = #{scope := ScopeIn, connection := Connection}) -> |
1081 |
159 |
Scope = pool_scope(ScopeIn, maps:get(host, AllOpts, none)), |
1082 |
159 |
Opts = maps:without([scope, host, connection], AllOpts), |
1083 |
159 |
#{type => b2a(Type), |
1084 |
|
scope => Scope, |
1085 |
|
tag => b2a(Tag), |
1086 |
|
opts => Opts, |
1087 |
|
conn_opts => Connection}. |
1088 |
|
|
1089 |
|
pool_scope(single_host, none) -> |
1090 |
:-( |
error(#{what => pool_single_host_not_specified, |
1091 |
|
text => <<"\"host\" option is required if \"single_host\" is used.">>}); |
1092 |
:-( |
pool_scope(single_host, Host) -> Host; |
1093 |
:-( |
pool_scope(host, none) -> host; |
1094 |
159 |
pool_scope(global, none) -> global. |
1095 |
|
|
1096 |
:-( |
process_ldap_connection(ConnOpts = #{port := _}) -> ConnOpts; |
1097 |
:-( |
process_ldap_connection(ConnOpts = #{tls := _}) -> ConnOpts#{port => 636}; |
1098 |
:-( |
process_ldap_connection(ConnOpts) -> ConnOpts#{port => 389}. |
1099 |
|
|
1100 |
318 |
b2a(B) -> binary_to_atom(B, utf8). |
1101 |
|
|
1102 |
5088 |
a2b(A) -> atom_to_binary(A, utf8). |
1103 |
|
|
1104 |
|
wpool_strategy_values() -> |
1105 |
583 |
[best_worker, random_worker, next_worker, available_worker, next_available_worker]. |
1106 |
|
|
1107 |
|
process_acl_condition(Value) -> |
1108 |
:-( |
case jid:nodeprep(Value) of |
1109 |
:-( |
error -> error(#{what => incorrect_acl_condition_value, |
1110 |
|
text => <<"Value could not be parsed as a JID node part">>}); |
1111 |
:-( |
Node -> Node |
1112 |
|
end. |
1113 |
|
|
1114 |
|
process_s2s_host_policy(#{host := S2SHost, policy := Policy}) -> |
1115 |
:-( |
{S2SHost, Policy}. |
1116 |
|
|
1117 |
|
process_s2s_address(M) -> |
1118 |
55 |
maps:take(host, M). |
1119 |
|
|
1120 |
|
process_domain_cert(#{domain := Domain, certfile := Certfile}) -> |
1121 |
:-( |
{Domain, Certfile}. |
1122 |
|
|
1123 |
:-( |
process_infinity_as_zero(infinity) -> 0; |
1124 |
157 |
process_infinity_as_zero(Num) -> Num. |