mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Merge branch 'new-option-validation'
This commit is contained in:
commit
2b63d07329
53 changed files with 367 additions and 818 deletions
12
src/acl.erl
12
src/acl.erl
|
@ -199,13 +199,13 @@ load_from_config() ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Host) ->
|
fun(Host) ->
|
||||||
ACLs = ejabberd_config:get_option(
|
ACLs = ejabberd_config:get_option(
|
||||||
{acl, Host}, fun(V) -> V end, []),
|
{acl, Host}, []),
|
||||||
AccessRules = ejabberd_config:get_option(
|
AccessRules = ejabberd_config:get_option(
|
||||||
{access, Host}, fun(V) -> V end, []),
|
{access, Host}, []),
|
||||||
AccessRulesNew = ejabberd_config:get_option(
|
AccessRulesNew = ejabberd_config:get_option(
|
||||||
{access_rules, Host}, fun(V) -> V end, []),
|
{access_rules, Host}, []),
|
||||||
ShaperRules = ejabberd_config:get_option(
|
ShaperRules = ejabberd_config:get_option(
|
||||||
{shaper_rules, Host}, fun(V) -> V end, []),
|
{shaper_rules, Host}, []),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({ACLName, SpecList}) ->
|
fun({ACLName, SpecList}) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
@ -605,7 +605,7 @@ access_rules_validator(Rules0) ->
|
||||||
(deny) -> true;
|
(deny) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
end),
|
end),
|
||||||
throw({replace_with, Rules}).
|
Rules.
|
||||||
|
|
||||||
|
|
||||||
shaper_rules_validator(Name) when is_atom(Name) ->
|
shaper_rules_validator(Name) when is_atom(Name) ->
|
||||||
|
@ -616,7 +616,7 @@ shaper_rules_validator(Rules0) ->
|
||||||
(V2) when is_integer(V2) -> true;
|
(V2) when is_integer(V2) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
end),
|
end),
|
||||||
throw({replace_with, Rules}).
|
Rules.
|
||||||
|
|
||||||
access_shaper_rules_validator([{Type, Acls} = Rule | Rest], RuleTypeCheck) ->
|
access_shaper_rules_validator([{Type, Acls} = Rule | Rest], RuleTypeCheck) ->
|
||||||
case RuleTypeCheck(Type) of
|
case RuleTypeCheck(Type) of
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
check_password :: check_password_fun(),
|
check_password :: check_password_fun(),
|
||||||
auth_module :: atom(),
|
auth_module :: atom(),
|
||||||
host = <<"">> :: binary(),
|
host = <<"">> :: binary(),
|
||||||
hostfqdn = <<"">> :: binary() | [binary()]}).
|
hostfqdn = [] :: [binary()]}).
|
||||||
|
|
||||||
start(_Opts) ->
|
start(_Opts) ->
|
||||||
Fqdn = get_local_fqdn(),
|
Fqdn = get_local_fqdn(),
|
||||||
|
@ -204,8 +204,6 @@ is_digesturi_valid(DigestURICase, JabberDomain,
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_host_fqdn(Host, Fqdn) when is_binary(Fqdn) ->
|
|
||||||
Host == Fqdn;
|
|
||||||
is_host_fqdn(_Host, []) ->
|
is_host_fqdn(_Host, []) ->
|
||||||
false;
|
false;
|
||||||
is_host_fqdn(Host, [Fqdn | _FqdnTail]) when Host == Fqdn ->
|
is_host_fqdn(Host, [Fqdn | _FqdnTail]) when Host == Fqdn ->
|
||||||
|
@ -214,26 +212,13 @@ is_host_fqdn(Host, [Fqdn | FqdnTail]) when Host /= Fqdn ->
|
||||||
is_host_fqdn(Host, FqdnTail).
|
is_host_fqdn(Host, FqdnTail).
|
||||||
|
|
||||||
get_local_fqdn() ->
|
get_local_fqdn() ->
|
||||||
case catch get_local_fqdn2() of
|
case ejabberd_config:get_option(fqdn) of
|
||||||
Str when is_binary(Str) -> Str;
|
undefined ->
|
||||||
List when is_list(List) -> List;
|
{ok, Hostname} = inet:gethostname(),
|
||||||
_ ->
|
{ok, {hostent, Fqdn, _, _, _, _}} = inet:gethostbyname(Hostname),
|
||||||
<<"unknown-fqdn, please configure fqdn "
|
[list_to_binary(Fqdn)];
|
||||||
"option in ejabberd.yml!">>
|
Fqdn ->
|
||||||
end.
|
Fqdn
|
||||||
|
|
||||||
get_local_fqdn2() ->
|
|
||||||
case ejabberd_config:get_option(
|
|
||||||
fqdn, fun(X) -> X end) of
|
|
||||||
ConfiguredFqdn when is_binary(ConfiguredFqdn) ->
|
|
||||||
ConfiguredFqdn;
|
|
||||||
[A | _] = ConfiguredFqdns when is_binary(A) ->
|
|
||||||
ConfiguredFqdns;
|
|
||||||
undefined ->
|
|
||||||
{ok, Hostname} = inet:gethostname(),
|
|
||||||
{ok, {hostent, Fqdn, _, _, _, _}} =
|
|
||||||
inet:gethostbyname(Hostname),
|
|
||||||
list_to_binary(Fqdn)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
hex(S) ->
|
hex(S) ->
|
||||||
|
@ -275,5 +260,10 @@ response(KeyVals, User, Passwd, Nonce, AuthzId,
|
||||||
":", (hex((erlang:md5(A2))))/binary>>,
|
":", (hex((erlang:md5(A2))))/binary>>,
|
||||||
hex((erlang:md5(T))).
|
hex((erlang:md5(T))).
|
||||||
|
|
||||||
opt_type(fqdn) -> fun iolist_to_binary/1;
|
opt_type(fqdn) ->
|
||||||
|
fun(FQDN) when is_binary(FQDN) ->
|
||||||
|
[FQDN];
|
||||||
|
(FQDNs) when is_list(FQDNs) ->
|
||||||
|
[iolist_to_binary(FQDN) || FQDN <- FQDNs]
|
||||||
|
end;
|
||||||
opt_type(_) -> [fqdn].
|
opt_type(_) -> [fqdn].
|
||||||
|
|
|
@ -239,8 +239,7 @@ get_definitions(#state{definitions = none, fragments_generators = Gens} = State)
|
||||||
[{acl,{acl,admin}},
|
[{acl,{acl,admin}},
|
||||||
{oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
|
{oauth,[<<"ejabberd:admin">>],[{acl,{acl,admin}}]}],
|
||||||
{all, [start, stop]}}}],
|
{all, [start, stop]}}}],
|
||||||
ApiPerms = ejabberd_config:get_option(api_permissions, fun(A) -> A end,
|
ApiPerms = ejabberd_config:get_option(api_permissions, DefaultOptions),
|
||||||
DefaultOptions),
|
|
||||||
AllCommands = ejabberd_commands:get_commands_definition(),
|
AllCommands = ejabberd_commands:get_commands_definition(),
|
||||||
Frags = lists:foldl(
|
Frags = lists:foldl(
|
||||||
fun({_Name, Generator}, Acc) ->
|
fun({_Name, Generator}, Acc) ->
|
||||||
|
@ -334,7 +333,7 @@ command_matches_patterns(C, [_ | Tail]) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
parse_api_permissions(Data) when is_list(Data) ->
|
parse_api_permissions(Data) when is_list(Data) ->
|
||||||
throw({replace_with, [parse_api_permission(Name, Args) || {Name, Args} <- Data]}).
|
[parse_api_permission(Name, Args) || {Name, Args} <- Data].
|
||||||
|
|
||||||
parse_api_permission(Name, Args0) ->
|
parse_api_permission(Name, Args0) ->
|
||||||
Args = lists:flatten(Args0),
|
Args = lists:flatten(Args0),
|
||||||
|
@ -374,8 +373,6 @@ parse_who(Name, Defs, ParseOauth) when is_list(Defs) ->
|
||||||
throw:{invalid_syntax, Msg} ->
|
throw:{invalid_syntax, Msg} ->
|
||||||
report_error(<<"Invalid access rule: '~s' used inside 'who' section for api_permission '~s'">>,
|
report_error(<<"Invalid access rule: '~s' used inside 'who' section for api_permission '~s'">>,
|
||||||
[Msg, Name]);
|
[Msg, Name]);
|
||||||
throw:{replace_with, NVal} ->
|
|
||||||
{access, NVal};
|
|
||||||
error:_ ->
|
error:_ ->
|
||||||
report_error(<<"Invalid access rule '~p' used inside 'who' section for api_permission '~s'">>,
|
report_error(<<"Invalid access rule '~p' used inside 'who' section for api_permission '~s'">>,
|
||||||
[Val, Name])
|
[Val, Name])
|
||||||
|
|
|
@ -89,12 +89,7 @@ stop(_State) ->
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
connect_nodes() ->
|
connect_nodes() ->
|
||||||
Nodes = ejabberd_config:get_option(
|
Nodes = ejabberd_config:get_option(cluster_nodes, []),
|
||||||
cluster_nodes,
|
|
||||||
fun(Ns) ->
|
|
||||||
true = lists:all(fun is_atom/1, Ns),
|
|
||||||
Ns
|
|
||||||
end, []),
|
|
||||||
lists:foreach(fun(Node) ->
|
lists:foreach(fun(Node) ->
|
||||||
net_kernel:connect_node(Node)
|
net_kernel:connect_node(Node)
|
||||||
end, Nodes).
|
end, Nodes).
|
||||||
|
@ -142,10 +137,7 @@ delete_pid_file() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_settings_from_config() ->
|
set_settings_from_config() ->
|
||||||
Ticktime = ejabberd_config:get_option(
|
Ticktime = ejabberd_config:get_option(net_ticktime, 60),
|
||||||
net_ticktime,
|
|
||||||
opt_type(net_ticktime),
|
|
||||||
60),
|
|
||||||
net_kernel:set_net_ticktime(Ticktime).
|
net_kernel:set_net_ticktime(Ticktime).
|
||||||
|
|
||||||
file_queue_init() ->
|
file_queue_init() ->
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
get_password_s/2, get_password_with_authmodule/2,
|
get_password_s/2, get_password_with_authmodule/2,
|
||||||
is_user_exists/2, is_user_exists_in_other_modules/3,
|
is_user_exists/2, is_user_exists_in_other_modules/3,
|
||||||
remove_user/2, remove_user/3, plain_password_required/1,
|
remove_user/2, remove_user/3, plain_password_required/1,
|
||||||
store_type/1, entropy/1, backend_type/1]).
|
store_type/1, entropy/1, backend_type/1, password_format/1]).
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
@ -497,6 +497,9 @@ backend_type(Mod) ->
|
||||||
_ -> Mod
|
_ -> Mod
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
password_format(LServer) ->
|
||||||
|
ejabberd_config:get_option({auth_password_format, LServer}, plain).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
@ -508,8 +511,7 @@ auth_modules() ->
|
||||||
auth_modules(Server) ->
|
auth_modules(Server) ->
|
||||||
LServer = jid:nameprep(Server),
|
LServer = jid:nameprep(Server),
|
||||||
Default = ejabberd_config:default_db(LServer, ?MODULE),
|
Default = ejabberd_config:default_db(LServer, ?MODULE),
|
||||||
Methods = ejabberd_config:get_option(
|
Methods = ejabberd_config:get_option({auth_method, LServer}, [Default]),
|
||||||
{auth_method, LServer}, opt_type(auth_method), [Default]),
|
|
||||||
[misc:binary_to_atom(<<"ejabberd_auth_",
|
[misc:binary_to_atom(<<"ejabberd_auth_",
|
||||||
(misc:atom_to_binary(M))/binary>>)
|
(misc:atom_to_binary(M))/binary>>)
|
||||||
|| M <- Methods].
|
|| M <- Methods].
|
||||||
|
@ -537,4 +539,8 @@ opt_type(auth_method) ->
|
||||||
lists:map(fun(M) -> ejabberd_config:v_db(?MODULE, M) end, V);
|
lists:map(fun(M) -> ejabberd_config:v_db(?MODULE, M) end, V);
|
||||||
(V) -> [ejabberd_config:v_db(?MODULE, V)]
|
(V) -> [ejabberd_config:v_db(?MODULE, V)]
|
||||||
end;
|
end;
|
||||||
opt_type(_) -> [auth_method].
|
opt_type(auth_password_format) ->
|
||||||
|
fun (plain) -> plain;
|
||||||
|
(scram) -> scram
|
||||||
|
end;
|
||||||
|
opt_type(_) -> [auth_method, auth_password_format].
|
||||||
|
|
|
@ -26,9 +26,11 @@
|
||||||
-module(ejabberd_auth_anonymous).
|
-module(ejabberd_auth_anonymous).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
-behaviour(ejabberd_config).
|
||||||
|
-behaviour(ejabberd_auth).
|
||||||
-author('mickael.remond@process-one.net').
|
-author('mickael.remond@process-one.net').
|
||||||
|
|
||||||
-export([start/1,
|
-export([start/1,
|
||||||
|
stop/1,
|
||||||
allow_anonymous/1,
|
allow_anonymous/1,
|
||||||
is_sasl_anonymous_enabled/1,
|
is_sasl_anonymous_enabled/1,
|
||||||
is_login_anonymous_enabled/1,
|
is_login_anonymous_enabled/1,
|
||||||
|
@ -59,6 +61,12 @@ start(Host) ->
|
||||||
?MODULE, unregister_connection, 100),
|
?MODULE, unregister_connection, 100),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
stop(Host) ->
|
||||||
|
ejabberd_hooks:delete(sm_register_connection_hook, Host,
|
||||||
|
?MODULE, register_connection, 100),
|
||||||
|
ejabberd_hooks:delete(sm_remove_connection_hook, Host,
|
||||||
|
?MODULE, unregister_connection, 100).
|
||||||
|
|
||||||
%% Return true if anonymous is allowed for host or false otherwise
|
%% Return true if anonymous is allowed for host or false otherwise
|
||||||
allow_anonymous(Host) ->
|
allow_anonymous(Host) ->
|
||||||
lists:member(?MODULE, ejabberd_auth:auth_modules(Host)).
|
lists:member(?MODULE, ejabberd_auth:auth_modules(Host)).
|
||||||
|
@ -93,21 +101,12 @@ is_login_anonymous_enabled(Host) ->
|
||||||
%% Return the anonymous protocol to use: sasl_anon|login_anon|both
|
%% Return the anonymous protocol to use: sasl_anon|login_anon|both
|
||||||
%% defaults to login_anon
|
%% defaults to login_anon
|
||||||
anonymous_protocol(Host) ->
|
anonymous_protocol(Host) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({anonymous_protocol, Host}, sasl_anon).
|
||||||
{anonymous_protocol, Host},
|
|
||||||
fun(sasl_anon) -> sasl_anon;
|
|
||||||
(login_anon) -> login_anon;
|
|
||||||
(both) -> both
|
|
||||||
end,
|
|
||||||
sasl_anon).
|
|
||||||
|
|
||||||
%% Return true if multiple connections have been allowed in the config file
|
%% Return true if multiple connections have been allowed in the config file
|
||||||
%% defaults to false
|
%% defaults to false
|
||||||
allow_multiple_connections(Host) ->
|
allow_multiple_connections(Host) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({allow_multiple_connections, Host}, false).
|
||||||
{allow_multiple_connections, Host},
|
|
||||||
fun(V) when is_boolean(V) -> V end,
|
|
||||||
false).
|
|
||||||
|
|
||||||
anonymous_user_exist(User, Server) ->
|
anonymous_user_exist(User, Server) ->
|
||||||
lists:any(
|
lists:any(
|
||||||
|
|
|
@ -48,12 +48,7 @@
|
||||||
%%% API
|
%%% API
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
start(Host) ->
|
start(Host) ->
|
||||||
Cmd = ejabberd_config:get_option(
|
Cmd = ejabberd_config:get_option({extauth_program, Host}, "extauth"),
|
||||||
{extauth_program, Host},
|
|
||||||
fun(V) ->
|
|
||||||
binary_to_list(iolist_to_binary(V))
|
|
||||||
end,
|
|
||||||
"extauth"),
|
|
||||||
extauth:start(Host, Cmd),
|
extauth:start(Host, Cmd),
|
||||||
check_cache_last_options(Host),
|
check_cache_last_options(Host),
|
||||||
ejabberd_auth_mnesia:start(Host).
|
ejabberd_auth_mnesia:start(Host).
|
||||||
|
@ -179,12 +174,8 @@ remove_user(User, Server, Password) ->
|
||||||
|
|
||||||
%% @spec (Host::string()) -> false | {true, CacheTime::integer()}
|
%% @spec (Host::string()) -> false | {true, CacheTime::integer()}
|
||||||
get_cache_option(Host) ->
|
get_cache_option(Host) ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({extauth_cache, Host}, false) of
|
||||||
{extauth_cache, Host},
|
false -> false;
|
||||||
fun(false) -> undefined;
|
|
||||||
(I) when is_integer(I), I >= 0 -> I
|
|
||||||
end) of
|
|
||||||
undefined -> false;
|
|
||||||
CacheTime -> {true, CacheTime}
|
CacheTime -> {true, CacheTime}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -319,12 +310,11 @@ get_mod_last_configured(Server) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_configured(Host, Module) ->
|
is_configured(Host, Module) ->
|
||||||
Os = ejabberd_config:get_option({modules, Host},
|
Os = ejabberd_config:get_option({modules, Host}, []),
|
||||||
fun(M) when is_list(M) -> M end),
|
|
||||||
lists:keymember(Module, 1, Os).
|
lists:keymember(Module, 1, Os).
|
||||||
|
|
||||||
opt_type(extauth_cache) ->
|
opt_type(extauth_cache) ->
|
||||||
fun (false) -> undefined;
|
fun (false) -> false;
|
||||||
(I) when is_integer(I), I >= 0 -> I
|
(I) when is_integer(I), I >= 0 -> I
|
||||||
end;
|
end;
|
||||||
opt_type(extauth_program) ->
|
opt_type(extauth_program) ->
|
||||||
|
|
|
@ -381,7 +381,7 @@ parse_options(Host) ->
|
||||||
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
||||||
UserFilter = case gen_mod:get_opt(
|
UserFilter = case gen_mod:get_opt(
|
||||||
{ldap_filter, Host}, [],
|
{ldap_filter, Host}, [],
|
||||||
fun check_filter/1, <<"">>) of
|
fun eldap_utils:check_filter/1, <<"">>) of
|
||||||
<<"">> ->
|
<<"">> ->
|
||||||
SubFilter;
|
SubFilter;
|
||||||
F ->
|
F ->
|
||||||
|
@ -399,7 +399,7 @@ parse_options(Host) ->
|
||||||
[iolist_to_binary(A)
|
[iolist_to_binary(A)
|
||||||
|| A <- DNFA]
|
|| A <- DNFA]
|
||||||
end,
|
end,
|
||||||
NewDNF = check_filter(DNF),
|
NewDNF = eldap_utils:check_filter(DNF),
|
||||||
{NewDNF, NewDNFA}
|
{NewDNF, NewDNFA}
|
||||||
end, {undefined, []}),
|
end, {undefined, []}),
|
||||||
LocalFilter = gen_mod:get_opt(
|
LocalFilter = gen_mod:get_opt(
|
||||||
|
@ -418,31 +418,15 @@ parse_options(Host) ->
|
||||||
sfilter = SearchFilter, lfilter = LocalFilter,
|
sfilter = SearchFilter, lfilter = LocalFilter,
|
||||||
dn_filter = DNFilter, dn_filter_attrs = DNFilterAttrs}.
|
dn_filter = DNFilter, dn_filter_attrs = DNFilterAttrs}.
|
||||||
|
|
||||||
check_filter(F) ->
|
|
||||||
NewF = iolist_to_binary(F),
|
|
||||||
{ok, _} = eldap_filter:parse(NewF),
|
|
||||||
NewF.
|
|
||||||
|
|
||||||
opt_type(ldap_dn_filter) ->
|
opt_type(ldap_dn_filter) ->
|
||||||
fun ([{DNF, DNFA}]) ->
|
fun ([{DNF, DNFA}]) ->
|
||||||
NewDNFA = case DNFA of
|
NewDNFA = case DNFA of
|
||||||
undefined -> [];
|
undefined -> [];
|
||||||
_ -> [iolist_to_binary(A) || A <- DNFA]
|
_ -> [iolist_to_binary(A) || A <- DNFA]
|
||||||
end,
|
end,
|
||||||
NewDNF = check_filter(DNF),
|
NewDNF = eldap_utils:check_filter(DNF),
|
||||||
{NewDNF, NewDNFA}
|
{NewDNF, NewDNFA}
|
||||||
end;
|
end;
|
||||||
opt_type(ldap_filter) -> fun check_filter/1;
|
|
||||||
opt_type(ldap_local_filter) -> fun (V) -> V end;
|
opt_type(ldap_local_filter) -> fun (V) -> V end;
|
||||||
opt_type(ldap_uids) ->
|
|
||||||
fun (Us) ->
|
|
||||||
lists:map(fun ({U, P}) ->
|
|
||||||
{iolist_to_binary(U), iolist_to_binary(P)};
|
|
||||||
({U}) -> {iolist_to_binary(U)};
|
|
||||||
(U) -> {iolist_to_binary(U)}
|
|
||||||
end,
|
|
||||||
lists:flatten(Us))
|
|
||||||
end;
|
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[ldap_dn_filter, ldap_filter, ldap_local_filter,
|
[ldap_dn_filter, ldap_local_filter].
|
||||||
ldap_uids].
|
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
-compile([{parse_transform, ejabberd_sql_pt}]).
|
-compile([{parse_transform, ejabberd_sql_pt}]).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(ejabberd_auth).
|
-behaviour(ejabberd_auth).
|
||||||
|
@ -41,7 +39,7 @@
|
||||||
get_vh_registered_users_number/2, get_password/2,
|
get_vh_registered_users_number/2, get_password/2,
|
||||||
get_password_s/2, is_user_exists/2, remove_user/2,
|
get_password_s/2, is_user_exists/2, remove_user/2,
|
||||||
remove_user/3, store_type/0, export/1, import/2,
|
remove_user/3, store_type/0, export/1, import/2,
|
||||||
plain_password_required/0, opt_type/1]).
|
plain_password_required/0]).
|
||||||
-export([need_transform/1, transform/1]).
|
-export([need_transform/1, transform/1]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
|
@ -89,8 +87,7 @@ plain_password_required() ->
|
||||||
is_scrammed().
|
is_scrammed().
|
||||||
|
|
||||||
store_type() ->
|
store_type() ->
|
||||||
ejabberd_config:get_option({auth_password_format, ?MYNAME},
|
ejabberd_auth:password_format(?MYNAME).
|
||||||
opt_type(auth_password_format), plain).
|
|
||||||
|
|
||||||
check_password(User, AuthzId, Server, Password) ->
|
check_password(User, AuthzId, Server, Password) ->
|
||||||
if AuthzId /= <<>> andalso AuthzId /= User ->
|
if AuthzId /= <<>> andalso AuthzId /= User ->
|
||||||
|
@ -494,9 +491,3 @@ export(_Server) ->
|
||||||
import(LServer, [LUser, Password, _TimeStamp]) ->
|
import(LServer, [LUser, Password, _TimeStamp]) ->
|
||||||
mnesia:dirty_write(
|
mnesia:dirty_write(
|
||||||
#passwd{us = {LUser, LServer}, password = Password}).
|
#passwd{us = {LUser, LServer}, password = Password}).
|
||||||
|
|
||||||
opt_type(auth_password_format) ->
|
|
||||||
fun (plain) -> plain;
|
|
||||||
(scram) -> scram
|
|
||||||
end;
|
|
||||||
opt_type(_) -> [auth_password_format].
|
|
||||||
|
|
|
@ -112,18 +112,10 @@ store_type() -> external.
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
get_pam_service(Host) ->
|
get_pam_service(Host) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({pam_service, Host}, <<"ejabberd">>).
|
||||||
{pam_service, Host},
|
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"ejabberd">>).
|
|
||||||
|
|
||||||
get_pam_userinfotype(Host) ->
|
get_pam_userinfotype(Host) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({pam_userinfotype, Host}, username).
|
||||||
{pam_userinfotype, Host},
|
|
||||||
fun(username) -> username;
|
|
||||||
(jid) -> jid
|
|
||||||
end,
|
|
||||||
username).
|
|
||||||
|
|
||||||
opt_type(pam_service) -> fun iolist_to_binary/1;
|
opt_type(pam_service) -> fun iolist_to_binary/1;
|
||||||
opt_type(pam_userinfotype) ->
|
opt_type(pam_userinfotype) ->
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
-compile([{parse_transform, ejabberd_sql_pt}]).
|
-compile([{parse_transform, ejabberd_sql_pt}]).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(ejabberd_auth).
|
-behaviour(ejabberd_auth).
|
||||||
|
@ -42,7 +40,7 @@
|
||||||
get_vh_registered_users_number/2, get_password/2,
|
get_vh_registered_users_number/2, get_password/2,
|
||||||
get_password_s/2, is_user_exists/2, remove_user/2,
|
get_password_s/2, is_user_exists/2, remove_user/2,
|
||||||
remove_user/3, store_type/0, export/1, import/2,
|
remove_user/3, store_type/0, export/1, import/2,
|
||||||
plain_password_required/0, opt_type/1]).
|
plain_password_required/0]).
|
||||||
-export([passwd_schema/0]).
|
-export([passwd_schema/0]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
|
@ -272,9 +270,7 @@ remove_user(User, Server, Password) ->
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
is_scrammed() ->
|
is_scrammed() ->
|
||||||
scram ==
|
scram == ejabberd_auth:password_format(?MYNAME).
|
||||||
ejabberd_config:get_option({auth_password_format, ?MYNAME},
|
|
||||||
opt_type(auth_password_format), plain).
|
|
||||||
|
|
||||||
password_to_scram(Password) ->
|
password_to_scram(Password) ->
|
||||||
password_to_scram(Password,
|
password_to_scram(Password,
|
||||||
|
@ -320,9 +316,3 @@ export(_Server) ->
|
||||||
import(LServer, [LUser, Password, _TimeStamp]) ->
|
import(LServer, [LUser, Password, _TimeStamp]) ->
|
||||||
Passwd = #passwd{us = {LUser, LServer}, password = Password},
|
Passwd = #passwd{us = {LUser, LServer}, password = Password},
|
||||||
ejabberd_riak:put(Passwd, passwd_schema(), [{'2i', [{<<"host">>, LServer}]}]).
|
ejabberd_riak:put(Passwd, passwd_schema(), [{'2i', [{<<"host">>, LServer}]}]).
|
||||||
|
|
||||||
opt_type(auth_password_format) ->
|
|
||||||
fun (plain) -> plain;
|
|
||||||
(scram) -> scram
|
|
||||||
end;
|
|
||||||
opt_type(_) -> [auth_password_format].
|
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
-compile([{parse_transform, ejabberd_sql_pt}]).
|
-compile([{parse_transform, ejabberd_sql_pt}]).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(ejabberd_auth).
|
-behaviour(ejabberd_auth).
|
||||||
|
@ -41,7 +39,7 @@
|
||||||
get_vh_registered_users_number/2, get_password/2,
|
get_vh_registered_users_number/2, get_password/2,
|
||||||
get_password_s/2, is_user_exists/2, remove_user/2,
|
get_password_s/2, is_user_exists/2, remove_user/2,
|
||||||
remove_user/3, store_type/0, plain_password_required/0,
|
remove_user/3, store_type/0, plain_password_required/0,
|
||||||
convert_to_scram/1, opt_type/1]).
|
convert_to_scram/1]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -408,9 +406,7 @@ remove_user(User, Server, Password) ->
|
||||||
%%%
|
%%%
|
||||||
|
|
||||||
is_scrammed() ->
|
is_scrammed() ->
|
||||||
scram ==
|
scram == ejabberd_auth:password_format(?MYNAME).
|
||||||
ejabberd_config:get_option({auth_password_format, ?MYNAME},
|
|
||||||
opt_type(auth_password_format), plain).
|
|
||||||
|
|
||||||
password_to_scram(Password) ->
|
password_to_scram(Password) ->
|
||||||
password_to_scram(Password,
|
password_to_scram(Password,
|
||||||
|
@ -509,9 +505,3 @@ convert_to_scram(Server) ->
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
opt_type(auth_password_format) ->
|
|
||||||
fun (plain) -> plain;
|
|
||||||
(scram) -> scram
|
|
||||||
end;
|
|
||||||
opt_type(_) -> [auth_password_format].
|
|
||||||
|
|
|
@ -293,45 +293,37 @@ process_terminated(State, _Reason) ->
|
||||||
tls_options(#{lserver := LServer, tls_options := DefaultOpts}) ->
|
tls_options(#{lserver := LServer, tls_options := DefaultOpts}) ->
|
||||||
TLSOpts1 = case ejabberd_config:get_option(
|
TLSOpts1 = case ejabberd_config:get_option(
|
||||||
{c2s_certfile, LServer},
|
{c2s_certfile, LServer},
|
||||||
fun iolist_to_binary/1,
|
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{domain_certfile, LServer},
|
{domain_certfile, LServer})) of
|
||||||
fun iolist_to_binary/1)) of
|
|
||||||
undefined -> DefaultOpts;
|
undefined -> DefaultOpts;
|
||||||
CertFile -> lists:keystore(certfile, 1, DefaultOpts,
|
CertFile -> lists:keystore(certfile, 1, DefaultOpts,
|
||||||
{certfile, CertFile})
|
{certfile, CertFile})
|
||||||
end,
|
end,
|
||||||
TLSOpts2 = case ejabberd_config:get_option(
|
TLSOpts2 = case ejabberd_config:get_option(
|
||||||
{c2s_ciphers, LServer},
|
{c2s_ciphers, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts1;
|
undefined -> TLSOpts1;
|
||||||
Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
|
Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
|
||||||
{ciphers, Ciphers})
|
{ciphers, Ciphers})
|
||||||
end,
|
end,
|
||||||
TLSOpts3 = case ejabberd_config:get_option(
|
TLSOpts3 = case ejabberd_config:get_option(
|
||||||
{c2s_protocol_options, LServer},
|
{c2s_protocol_options, LServer}) of
|
||||||
fun (Options) -> str:join(Options, <<$|>>) end) of
|
|
||||||
undefined -> TLSOpts2;
|
undefined -> TLSOpts2;
|
||||||
ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
|
ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
|
||||||
{protocol_options, ProtoOpts})
|
{protocol_options, ProtoOpts})
|
||||||
end,
|
end,
|
||||||
TLSOpts4 = case ejabberd_config:get_option(
|
TLSOpts4 = case ejabberd_config:get_option(
|
||||||
{c2s_dhfile, LServer},
|
{c2s_dhfile, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts3;
|
undefined -> TLSOpts3;
|
||||||
DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
|
DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
|
||||||
{dhfile, DHFile})
|
{dhfile, DHFile})
|
||||||
end,
|
end,
|
||||||
TLSOpts5 = case ejabberd_config:get_option(
|
TLSOpts5 = case ejabberd_config:get_option(
|
||||||
{c2s_cafile, LServer},
|
{c2s_cafile, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts4;
|
undefined -> TLSOpts4;
|
||||||
CAFile -> lists:keystore(cafile, 1, TLSOpts4,
|
CAFile -> lists:keystore(cafile, 1, TLSOpts4,
|
||||||
{cafile, CAFile})
|
{cafile, CAFile})
|
||||||
end,
|
end,
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({c2s_tls_compression, LServer}) of
|
||||||
{c2s_tls_compression, LServer},
|
|
||||||
fun(B) when is_boolean(B) -> B end) of
|
|
||||||
undefined -> TLSOpts5;
|
undefined -> TLSOpts5;
|
||||||
false -> [compression_none | TLSOpts5];
|
false -> [compression_none | TLSOpts5];
|
||||||
true -> lists:delete(compression_none, TLSOpts5)
|
true -> lists:delete(compression_none, TLSOpts5)
|
||||||
|
@ -360,13 +352,7 @@ authenticated_stream_features(#{lserver := LServer}) ->
|
||||||
ejabberd_hooks:run_fold(c2s_post_auth_features, LServer, [], [LServer]).
|
ejabberd_hooks:run_fold(c2s_post_auth_features, LServer, [], [LServer]).
|
||||||
|
|
||||||
sasl_mechanisms(Mechs, #{lserver := LServer}) ->
|
sasl_mechanisms(Mechs, #{lserver := LServer}) ->
|
||||||
Mechs1 = ejabberd_config:get_option(
|
Mechs1 = ejabberd_config:get_option({disable_sasl_mechanisms, LServer}, []),
|
||||||
{disable_sasl_mechanisms, LServer},
|
|
||||||
fun(V) when is_list(V) ->
|
|
||||||
lists:map(fun(M) -> str:to_upper(M) end, V);
|
|
||||||
(V) ->
|
|
||||||
[str:to_upper(V)]
|
|
||||||
end, []),
|
|
||||||
Mechs2 = case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(LServer) of
|
Mechs2 = case ejabberd_auth_anonymous:is_sasl_anonymous_enabled(LServer) of
|
||||||
true -> Mechs1;
|
true -> Mechs1;
|
||||||
false -> [<<"ANONYMOUS">>|Mechs1]
|
false -> [<<"ANONYMOUS">>|Mechs1]
|
||||||
|
@ -805,22 +791,15 @@ resource_conflict_action(U, S, R) ->
|
||||||
OptionRaw = case ejabberd_sm:is_existing_resource(U, S, R) of
|
OptionRaw = case ejabberd_sm:is_existing_resource(U, S, R) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{resource_conflict, S},
|
{resource_conflict, S}, acceptnew);
|
||||||
fun(setresource) -> setresource;
|
|
||||||
(closeold) -> closeold;
|
|
||||||
(closenew) -> closenew;
|
|
||||||
(acceptnew) -> acceptnew
|
|
||||||
end);
|
|
||||||
false ->
|
false ->
|
||||||
acceptnew
|
acceptnew
|
||||||
end,
|
end,
|
||||||
Option = case OptionRaw of
|
Option = case OptionRaw of
|
||||||
setresource -> setresource;
|
setresource -> setresource;
|
||||||
closeold ->
|
closeold -> acceptnew; %% ejabberd_sm will close old session
|
||||||
acceptnew; %% ejabberd_sm will close old session
|
|
||||||
closenew -> closenew;
|
closenew -> closenew;
|
||||||
acceptnew -> acceptnew;
|
acceptnew -> acceptnew
|
||||||
_ -> acceptnew %% default ejabberd behavior
|
|
||||||
end,
|
end,
|
||||||
case Option of
|
case Option of
|
||||||
acceptnew -> {accept_resource, R};
|
acceptnew -> {accept_resource, R};
|
||||||
|
@ -922,7 +901,6 @@ format_reason(_, _) ->
|
||||||
transform_listen_option(Opt, Opts) ->
|
transform_listen_option(Opt, Opts) ->
|
||||||
[Opt|Opts].
|
[Opt|Opts].
|
||||||
|
|
||||||
opt_type(domain_certfile) -> fun iolist_to_binary/1;
|
|
||||||
opt_type(c2s_certfile) -> fun iolist_to_binary/1;
|
opt_type(c2s_certfile) -> fun iolist_to_binary/1;
|
||||||
opt_type(c2s_ciphers) -> fun iolist_to_binary/1;
|
opt_type(c2s_ciphers) -> fun iolist_to_binary/1;
|
||||||
opt_type(c2s_dhfile) -> fun iolist_to_binary/1;
|
opt_type(c2s_dhfile) -> fun iolist_to_binary/1;
|
||||||
|
@ -945,6 +923,6 @@ opt_type(disable_sasl_mechanisms) ->
|
||||||
(V) -> [str:to_upper(V)]
|
(V) -> [str:to_upper(V)]
|
||||||
end;
|
end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[domain_certfile, c2s_certfile, c2s_ciphers, c2s_cafile,
|
[c2s_certfile, c2s_ciphers, c2s_cafile,
|
||||||
c2s_protocol_options, c2s_tls_compression, resource_conflict,
|
c2s_protocol_options, c2s_tls_compression, resource_conflict,
|
||||||
disable_sasl_mechanisms].
|
disable_sasl_mechanisms].
|
||||||
|
|
|
@ -26,24 +26,20 @@
|
||||||
|
|
||||||
-module(ejabberd_c2s_config).
|
-module(ejabberd_c2s_config).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('mremond@process-one.net').
|
-author('mremond@process-one.net').
|
||||||
|
|
||||||
-export([get_c2s_limits/0, opt_type/1]).
|
-export([get_c2s_limits/0]).
|
||||||
|
|
||||||
%% Get first c2s configuration limitations to apply it to other c2s
|
%% Get first c2s configuration limitations to apply it to other c2s
|
||||||
%% connectors.
|
%% connectors.
|
||||||
get_c2s_limits() ->
|
get_c2s_limits() ->
|
||||||
case ejabberd_config:get_option(listen, fun(V) -> V end) of
|
C2SFirstListen = ejabberd_config:get_option(listen, []),
|
||||||
undefined -> [];
|
case lists:keysearch(ejabberd_c2s, 2, C2SFirstListen) of
|
||||||
C2SFirstListen ->
|
false -> [];
|
||||||
case lists:keysearch(ejabberd_c2s, 2, C2SFirstListen) of
|
{value, {_Port, ejabberd_c2s, Opts}} ->
|
||||||
false -> [];
|
select_opts_values(Opts)
|
||||||
{value, {_Port, ejabberd_c2s, Opts}} ->
|
|
||||||
select_opts_values(Opts)
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Only get access, shaper and max_stanza_size values
|
%% Only get access, shaper and max_stanza_size values
|
||||||
|
|
||||||
select_opts_values(Opts) ->
|
select_opts_values(Opts) ->
|
||||||
|
@ -65,6 +61,3 @@ select_opts_values([{max_stanza_size, Value} | Opts],
|
||||||
[{max_stanza_size, Value} | SelectedValues]);
|
[{max_stanza_size, Value} | SelectedValues]);
|
||||||
select_opts_values([_Opt | Opts], SelectedValues) ->
|
select_opts_values([_Opt | Opts], SelectedValues) ->
|
||||||
select_opts_values(Opts, SelectedValues).
|
select_opts_values(Opts, SelectedValues).
|
||||||
|
|
||||||
opt_type(listen) -> fun (V) -> V end;
|
|
||||||
opt_type(_) -> [listen].
|
|
||||||
|
|
|
@ -350,12 +350,7 @@ do_create_image(Key) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_prog_name() ->
|
get_prog_name() ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option(captcha_cmd) of
|
||||||
captcha_cmd,
|
|
||||||
fun(FileName) ->
|
|
||||||
F = iolist_to_binary(FileName),
|
|
||||||
if F /= <<"">> -> F end
|
|
||||||
end) of
|
|
||||||
undefined ->
|
undefined ->
|
||||||
?DEBUG("The option captcha_cmd is not configured, "
|
?DEBUG("The option captcha_cmd is not configured, "
|
||||||
"but some module wants to use the CAPTCHA "
|
"but some module wants to use the CAPTCHA "
|
||||||
|
@ -367,10 +362,7 @@ get_prog_name() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_url(Str) ->
|
get_url(Str) ->
|
||||||
CaptchaHost = ejabberd_config:get_option(
|
CaptchaHost = ejabberd_config:get_option(captcha_host, <<"">>),
|
||||||
captcha_host,
|
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"">>),
|
|
||||||
case str:tokens(CaptchaHost, <<":">>) of
|
case str:tokens(CaptchaHost, <<":">>) of
|
||||||
[Host] ->
|
[Host] ->
|
||||||
<<"http://", Host/binary, "/captcha/", Str/binary>>;
|
<<"http://", Host/binary, "/captcha/", Str/binary>>;
|
||||||
|
@ -395,7 +387,7 @@ get_transfer_protocol(PortString) ->
|
||||||
get_captcha_transfer_protocol(PortListeners).
|
get_captcha_transfer_protocol(PortListeners).
|
||||||
|
|
||||||
get_port_listeners(PortNumber) ->
|
get_port_listeners(PortNumber) ->
|
||||||
AllListeners = ejabberd_config:get_option(listen, fun(V) -> V end),
|
AllListeners = ejabberd_config:get_option(listen, []),
|
||||||
lists:filter(fun (Listener) when is_list(Listener) ->
|
lists:filter(fun (Listener) when is_list(Listener) ->
|
||||||
case proplists:get_value(port, Listener) of
|
case proplists:get_value(port, Listener) of
|
||||||
PortNumber -> true;
|
PortNumber -> true;
|
||||||
|
@ -425,9 +417,7 @@ get_captcha_transfer_protocol([_ | Listeners]) ->
|
||||||
|
|
||||||
is_limited(undefined) -> false;
|
is_limited(undefined) -> false;
|
||||||
is_limited(Limiter) ->
|
is_limited(Limiter) ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option(captcha_limit) of
|
||||||
captcha_limit,
|
|
||||||
fun(I) when is_integer(I), I > 0 -> I end) of
|
|
||||||
undefined -> false;
|
undefined -> false;
|
||||||
Int ->
|
Int ->
|
||||||
case catch gen_server:call(?MODULE,
|
case catch gen_server:call(?MODULE,
|
||||||
|
@ -545,6 +535,5 @@ opt_type(captcha_cmd) ->
|
||||||
opt_type(captcha_host) -> fun iolist_to_binary/1;
|
opt_type(captcha_host) -> fun iolist_to_binary/1;
|
||||||
opt_type(captcha_limit) ->
|
opt_type(captcha_limit) ->
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
fun (I) when is_integer(I), I > 0 -> I end;
|
||||||
opt_type(listen) -> fun (V) -> V end;
|
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[captcha_cmd, captcha_host, captcha_limit, listen].
|
[captcha_cmd, captcha_host, captcha_limit].
|
||||||
|
|
|
@ -211,6 +211,7 @@
|
||||||
-author('badlop@process-one.net').
|
-author('badlop@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
-behaviour(ejabberd_config).
|
||||||
|
|
||||||
-define(DEFAULT_VERSION, 1000000).
|
-define(DEFAULT_VERSION, 1000000).
|
||||||
|
|
||||||
|
@ -822,10 +823,7 @@ get_access_commands(AccessCommands, _Version) ->
|
||||||
get_exposed_commands() ->
|
get_exposed_commands() ->
|
||||||
get_exposed_commands(?DEFAULT_VERSION).
|
get_exposed_commands(?DEFAULT_VERSION).
|
||||||
get_exposed_commands(Version) ->
|
get_exposed_commands(Version) ->
|
||||||
Opts0 = ejabberd_config:get_option(
|
Opts0 = ejabberd_config:get_option(commands, []),
|
||||||
commands,
|
|
||||||
fun(V) when is_list(V) -> V end,
|
|
||||||
[]),
|
|
||||||
Opts = lists:map(fun(V) when is_tuple(V) -> [V]; (V) -> V end, Opts0),
|
Opts = lists:map(fun(V) when is_tuple(V) -> [V]; (V) -> V end, Opts0),
|
||||||
CommandsList = list_commands_policy(Version),
|
CommandsList = list_commands_policy(Version),
|
||||||
OpenCmds = [N || {N, _, _, open} <- CommandsList],
|
OpenCmds = [N || {N, _, _, open} <- CommandsList],
|
||||||
|
@ -876,10 +874,7 @@ is_admin(Name, Auth, Extra) ->
|
||||||
_ ->
|
_ ->
|
||||||
{Extra, global}
|
{Extra, global}
|
||||||
end,
|
end,
|
||||||
AdminAccess = ejabberd_config:get_option(
|
AdminAccess = ejabberd_config:get_option(commands_admin_access, none),
|
||||||
commands_admin_access,
|
|
||||||
fun(V) -> V end,
|
|
||||||
none),
|
|
||||||
case acl:access_matches(AdminAccess, ACLInfo, Server) of
|
case acl:access_matches(AdminAccess, ACLInfo, Server) of
|
||||||
allow ->
|
allow ->
|
||||||
case catch check_auth(get_command_definition(Name), Auth) of
|
case catch check_auth(get_command_definition(Name), Auth) of
|
||||||
|
@ -893,9 +888,7 @@ is_admin(Name, Auth, Extra) ->
|
||||||
permission_addon() ->
|
permission_addon() ->
|
||||||
[{<<"'commands' option compatibility shim">>,
|
[{<<"'commands' option compatibility shim">>,
|
||||||
{[],
|
{[],
|
||||||
[{access, ejabberd_config:get_option(commands_admin_access,
|
[{access, ejabberd_config:get_option(commands_admin_access, none)}],
|
||||||
fun(V) -> V end,
|
|
||||||
none)}],
|
|
||||||
{get_exposed_commands(), []}}}].
|
{get_exposed_commands(), []}}}].
|
||||||
|
|
||||||
opt_type(commands_admin_access) -> fun acl:access_rules_validator/1;
|
opt_type(commands_admin_access) -> fun acl:access_rules_validator/1;
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-export([start/0, load_file/1, reload_file/0, read_file/1,
|
-export([start/0, load_file/1, reload_file/0, read_file/1,
|
||||||
get_option/2, get_option/3, add_option/2, has_option/1,
|
get_option/1, get_option/2, add_option/2, has_option/1,
|
||||||
get_vh_by_auth_method/1, is_file_readable/1,
|
get_vh_by_auth_method/1, is_file_readable/1,
|
||||||
get_version/0, get_myhosts/0, get_mylang/0,
|
get_version/0, get_myhosts/0, get_mylang/0, get_lang/1,
|
||||||
get_ejabberd_config_path/0, is_using_elixir_config/0,
|
get_ejabberd_config_path/0, is_using_elixir_config/0,
|
||||||
prepare_opt_val/4, transform_options/1, collect_options/1,
|
prepare_opt_val/4, transform_options/1, collect_options/1,
|
||||||
convert_to_yaml/1, convert_to_yaml/2, v_db/2,
|
convert_to_yaml/1, convert_to_yaml/2, v_db/2,
|
||||||
|
@ -44,11 +44,13 @@
|
||||||
%% The following functions are deprecated.
|
%% The following functions are deprecated.
|
||||||
-export([add_global_option/2, add_local_option/2,
|
-export([add_global_option/2, add_local_option/2,
|
||||||
get_global_option/2, get_local_option/2,
|
get_global_option/2, get_local_option/2,
|
||||||
get_global_option/3, get_local_option/3]).
|
get_global_option/3, get_local_option/3,
|
||||||
|
get_option/3]).
|
||||||
|
|
||||||
-deprecated([{add_global_option, 2}, {add_local_option, 2},
|
-deprecated([{add_global_option, 2}, {add_local_option, 2},
|
||||||
{get_global_option, 2}, {get_local_option, 2},
|
{get_global_option, 2}, {get_local_option, 2},
|
||||||
{get_global_option, 3}, {get_local_option, 3}]).
|
{get_global_option, 3}, {get_local_option, 3},
|
||||||
|
{get_option, 3}]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -766,10 +768,7 @@ set_opts(State) ->
|
||||||
set_log_level().
|
set_log_level().
|
||||||
|
|
||||||
set_log_level() ->
|
set_log_level() ->
|
||||||
Level = get_option(
|
Level = get_option(loglevel, 4),
|
||||||
loglevel,
|
|
||||||
fun(P) when P>=0, P=<5 -> P end,
|
|
||||||
4),
|
|
||||||
ejabberd_logger:set(Level).
|
ejabberd_logger:set(Level).
|
||||||
|
|
||||||
add_global_option(Opt, Val) ->
|
add_global_option(Opt, Val) ->
|
||||||
|
@ -819,34 +818,38 @@ prepare_opt_val(Opt, Val, F, Default) ->
|
||||||
|
|
||||||
-spec get_global_option(any(), check_fun()) -> any().
|
-spec get_global_option(any(), check_fun()) -> any().
|
||||||
|
|
||||||
get_global_option(Opt, F) ->
|
get_global_option(Opt, _) ->
|
||||||
get_option(Opt, F, undefined).
|
get_option(Opt, undefined).
|
||||||
|
|
||||||
-spec get_global_option(any(), check_fun(), any()) -> any().
|
-spec get_global_option(any(), check_fun(), any()) -> any().
|
||||||
|
|
||||||
get_global_option(Opt, F, Default) ->
|
get_global_option(Opt, _, Default) ->
|
||||||
get_option(Opt, F, Default).
|
get_option(Opt, Default).
|
||||||
|
|
||||||
-spec get_local_option(any(), check_fun()) -> any().
|
-spec get_local_option(any(), check_fun()) -> any().
|
||||||
|
|
||||||
get_local_option(Opt, F) ->
|
get_local_option(Opt, _) ->
|
||||||
get_option(Opt, F, undefined).
|
get_option(Opt, undefined).
|
||||||
|
|
||||||
-spec get_local_option(any(), check_fun(), any()) -> any().
|
-spec get_local_option(any(), check_fun(), any()) -> any().
|
||||||
|
|
||||||
get_local_option(Opt, F, Default) ->
|
get_local_option(Opt, _, Default) ->
|
||||||
get_option(Opt, F, Default).
|
get_option(Opt, Default).
|
||||||
|
|
||||||
-spec get_option(any(), check_fun()) -> any().
|
-spec get_option(any()) -> any().
|
||||||
|
get_option(Opt) ->
|
||||||
get_option(Opt, F) ->
|
get_option(Opt, undefined).
|
||||||
get_option(Opt, F, undefined).
|
|
||||||
|
|
||||||
-spec get_option(any(), check_fun(), any()) -> any().
|
-spec get_option(any(), check_fun(), any()) -> any().
|
||||||
|
get_option(Opt, _, Default) ->
|
||||||
|
get_option(Opt, Default).
|
||||||
|
|
||||||
get_option(Opt, F, Default) when is_atom(Opt) ->
|
-spec get_option(any(), check_fun() | any()) -> any().
|
||||||
get_option({Opt, global}, F, Default);
|
get_option(Opt, F) when is_function(F) ->
|
||||||
get_option(Opt, F, Default) ->
|
get_option(Opt, undefined);
|
||||||
|
get_option(Opt, Default) when is_atom(Opt) ->
|
||||||
|
get_option({Opt, global}, Default);
|
||||||
|
get_option(Opt, Default) ->
|
||||||
{Key, Host} = case Opt of
|
{Key, Host} = case Opt of
|
||||||
{O, global} when is_atom(O) -> Opt;
|
{O, global} when is_atom(O) -> Opt;
|
||||||
{O, H} when is_atom(O), is_binary(H) -> Opt;
|
{O, H} when is_atom(O), is_binary(H) -> Opt;
|
||||||
|
@ -858,7 +861,7 @@ get_option(Opt, F, Default) ->
|
||||||
case ejabberd_options:is_known(Key) of
|
case ejabberd_options:is_known(Key) of
|
||||||
true ->
|
true ->
|
||||||
case ejabberd_options:Key(Host) of
|
case ejabberd_options:Key(Host) of
|
||||||
{ok, Val} -> prepare_opt_val(Opt, Val, F, Default);
|
{ok, Val} -> Val;
|
||||||
undefined -> Default
|
undefined -> Default
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
|
@ -867,7 +870,7 @@ get_option(Opt, F, Default) ->
|
||||||
|
|
||||||
-spec has_option(atom() | {atom(), global | binary()}) -> any().
|
-spec has_option(atom() | {atom(), global | binary()}) -> any().
|
||||||
has_option(Opt) ->
|
has_option(Opt) ->
|
||||||
get_option(Opt, fun(_) -> true end, false).
|
get_option(Opt) /= undefined.
|
||||||
|
|
||||||
init_module_db_table(Modules) ->
|
init_module_db_table(Modules) ->
|
||||||
%% Dirty hack for mod_pubsub
|
%% Dirty hack for mod_pubsub
|
||||||
|
@ -954,7 +957,7 @@ default_ram_db(Host, Module) ->
|
||||||
|
|
||||||
-spec default_db(default_db | default_ram_db, binary() | global, module()) -> atom().
|
-spec default_db(default_db | default_ram_db, binary() | global, module()) -> atom().
|
||||||
default_db(Opt, Host, Module) ->
|
default_db(Opt, Host, Module) ->
|
||||||
case get_option({Opt, Host}, fun(T) when is_atom(T) -> T end) of
|
case get_option({Opt, Host}) of
|
||||||
undefined ->
|
undefined ->
|
||||||
mnesia;
|
mnesia;
|
||||||
DBType ->
|
DBType ->
|
||||||
|
@ -999,11 +1002,9 @@ validate_opts(#state{opts = Opts} = State) ->
|
||||||
{ok, [Mod|_]} ->
|
{ok, [Mod|_]} ->
|
||||||
VFun = Mod:opt_type(Opt),
|
VFun = Mod:opt_type(Opt),
|
||||||
try VFun(Val) of
|
try VFun(Val) of
|
||||||
_ ->
|
NewVal ->
|
||||||
true
|
{true, In#local_config{value = NewVal}}
|
||||||
catch {replace_with, NewVal} ->
|
catch {invalid_syntax, Error} ->
|
||||||
{true, In#local_config{value = NewVal}};
|
|
||||||
{invalid_syntax, Error} ->
|
|
||||||
?ERROR_MSG("ignoring option '~s' with "
|
?ERROR_MSG("ignoring option '~s' with "
|
||||||
"invalid value: ~p: ~s",
|
"invalid value: ~p: ~s",
|
||||||
[Opt, Val, Error]),
|
[Opt, Val, Error]),
|
||||||
|
@ -1030,7 +1031,7 @@ get_vh_by_auth_method(AuthMethod) ->
|
||||||
get_vh_by_auth_method(AuthMethod, Hosts, []).
|
get_vh_by_auth_method(AuthMethod, Hosts, []).
|
||||||
|
|
||||||
get_vh_by_auth_method(Method, [Host|Hosts], Result) ->
|
get_vh_by_auth_method(Method, [Host|Hosts], Result) ->
|
||||||
Methods = get_option({auth_method, Host}, fun(Ms) -> Ms end, []),
|
Methods = get_option({auth_method, Host}, []),
|
||||||
case lists:member(Method, Methods) of
|
case lists:member(Method, Methods) of
|
||||||
true when Host == global ->
|
true when Host == global ->
|
||||||
get_myhosts();
|
get_myhosts();
|
||||||
|
@ -1064,15 +1065,16 @@ get_version() ->
|
||||||
-spec get_myhosts() -> [binary()].
|
-spec get_myhosts() -> [binary()].
|
||||||
|
|
||||||
get_myhosts() ->
|
get_myhosts() ->
|
||||||
get_option(hosts, fun(V) -> V end).
|
get_option(hosts).
|
||||||
|
|
||||||
-spec get_mylang() -> binary().
|
-spec get_mylang() -> binary().
|
||||||
|
|
||||||
get_mylang() ->
|
get_mylang() ->
|
||||||
get_option(
|
get_lang(global).
|
||||||
language,
|
|
||||||
fun iolist_to_binary/1,
|
-spec get_lang(global | binary()) -> binary().
|
||||||
<<"en">>).
|
get_lang(Host) ->
|
||||||
|
get_option({language, Host}, <<"en">>).
|
||||||
|
|
||||||
replace_module(mod_announce_odbc) -> {mod_announce, sql};
|
replace_module(mod_announce_odbc) -> {mod_announce, sql};
|
||||||
replace_module(mod_blocking_odbc) -> {mod_blocking, sql};
|
replace_module(mod_blocking_odbc) -> {mod_blocking, sql};
|
||||||
|
@ -1208,7 +1210,6 @@ transform_terms(Terms) ->
|
||||||
%% We could check all ejabberd beams, but this
|
%% We could check all ejabberd beams, but this
|
||||||
%% slows down start-up procedure :(
|
%% slows down start-up procedure :(
|
||||||
Mods = [mod_register,
|
Mods = [mod_register,
|
||||||
mod_last,
|
|
||||||
ejabberd_s2s,
|
ejabberd_s2s,
|
||||||
ejabberd_listener,
|
ejabberd_listener,
|
||||||
ejabberd_sql_sup,
|
ejabberd_sql_sup,
|
||||||
|
@ -1317,6 +1318,10 @@ transform_options(Opt, Opts) when Opt == override_global;
|
||||||
Opt == override_acls ->
|
Opt == override_acls ->
|
||||||
?WARNING_MSG("Ignoring '~s' option which has no effect anymore", [Opt]),
|
?WARNING_MSG("Ignoring '~s' option which has no effect anymore", [Opt]),
|
||||||
Opts;
|
Opts;
|
||||||
|
transform_options({node_start, {_, _, _} = Now}, Opts) ->
|
||||||
|
?WARNING_MSG("Old 'node_start' format detected. This is still supported "
|
||||||
|
"but it is better to fix your config.", []),
|
||||||
|
[{node_start, now_to_seconds(Now)}|Opts];
|
||||||
transform_options({host_config, Host, HOpts}, Opts) ->
|
transform_options({host_config, Host, HOpts}, Opts) ->
|
||||||
{AddOpts, HOpts1} =
|
{AddOpts, HOpts1} =
|
||||||
lists:mapfoldl(
|
lists:mapfoldl(
|
||||||
|
@ -1353,14 +1358,15 @@ emit_deprecation_warning(Module, NewModule) ->
|
||||||
[Module, NewModule])
|
[Module, NewModule])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec now_to_seconds(erlang:timestamp()) -> non_neg_integer().
|
||||||
|
now_to_seconds({MegaSecs, Secs, _MicroSecs}) ->
|
||||||
|
MegaSecs * 1000000 + Secs.
|
||||||
|
|
||||||
opt_type(hide_sensitive_log_data) ->
|
opt_type(hide_sensitive_log_data) ->
|
||||||
fun (H) when is_boolean(H) -> H end;
|
fun (H) when is_boolean(H) -> H end;
|
||||||
opt_type(hosts) ->
|
opt_type(hosts) ->
|
||||||
fun(L) when is_list(L) ->
|
fun(L) ->
|
||||||
lists:map(
|
[iolist_to_binary(H) || H <- L]
|
||||||
fun(H) ->
|
|
||||||
iolist_to_binary(H)
|
|
||||||
end, L)
|
|
||||||
end;
|
end;
|
||||||
opt_type(language) ->
|
opt_type(language) ->
|
||||||
fun iolist_to_binary/1;
|
fun iolist_to_binary/1;
|
||||||
|
@ -1390,19 +1396,21 @@ opt_type(cache_life_time) ->
|
||||||
(infinity) -> infinity;
|
(infinity) -> infinity;
|
||||||
(unlimited) -> infinity
|
(unlimited) -> infinity
|
||||||
end;
|
end;
|
||||||
|
opt_type(domain_certfile) ->
|
||||||
|
fun iolist_to_binary/1;
|
||||||
|
opt_type(shared_key) ->
|
||||||
|
fun iolist_to_binary/1;
|
||||||
|
opt_type(node_start) ->
|
||||||
|
fun(I) when is_integer(I), I>=0 -> I end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[hide_sensitive_log_data, hosts, language, max_fsm_queue,
|
[hide_sensitive_log_data, hosts, language, max_fsm_queue,
|
||||||
default_db, default_ram_db, queue_type, queue_dir, loglevel,
|
default_db, default_ram_db, queue_type, queue_dir, loglevel,
|
||||||
use_cache, cache_size, cache_missed, cache_life_time].
|
use_cache, cache_size, cache_missed, cache_life_time,
|
||||||
|
domain_certfile, shared_key, node_start].
|
||||||
|
|
||||||
-spec may_hide_data(any()) -> any().
|
-spec may_hide_data(any()) -> any().
|
||||||
may_hide_data(Data) ->
|
may_hide_data(Data) ->
|
||||||
case get_option(
|
case get_option(hide_sensitive_log_data, false) of
|
||||||
hide_sensitive_log_data,
|
|
||||||
fun(false) -> false;
|
|
||||||
(true) -> true
|
|
||||||
end,
|
|
||||||
false) of
|
|
||||||
false ->
|
false ->
|
||||||
Data;
|
Data;
|
||||||
true ->
|
true ->
|
||||||
|
@ -1415,9 +1423,7 @@ fsm_limit_opts(Opts) ->
|
||||||
{_, I} when is_integer(I), I>0 ->
|
{_, I} when is_integer(I), I>0 ->
|
||||||
[{max_queue, I}];
|
[{max_queue, I}];
|
||||||
false ->
|
false ->
|
||||||
case get_option(
|
case get_option(max_fsm_queue) of
|
||||||
max_fsm_queue,
|
|
||||||
fun(I) when is_integer(I), I>0 -> I end) of
|
|
||||||
undefined -> [];
|
undefined -> [];
|
||||||
N -> [{max_queue, N}]
|
N -> [{max_queue, N}]
|
||||||
end
|
end
|
||||||
|
@ -1425,25 +1431,25 @@ fsm_limit_opts(Opts) ->
|
||||||
|
|
||||||
-spec queue_dir() -> binary() | undefined.
|
-spec queue_dir() -> binary() | undefined.
|
||||||
queue_dir() ->
|
queue_dir() ->
|
||||||
get_option(queue_dir, opt_type(queue_dir)).
|
get_option(queue_dir).
|
||||||
|
|
||||||
-spec default_queue_type(binary()) -> ram | file.
|
-spec default_queue_type(binary()) -> ram | file.
|
||||||
default_queue_type(Host) ->
|
default_queue_type(Host) ->
|
||||||
get_option({queue_type, Host}, opt_type(queue_type), ram).
|
get_option({queue_type, Host}, ram).
|
||||||
|
|
||||||
-spec use_cache(binary() | global) -> boolean().
|
-spec use_cache(binary() | global) -> boolean().
|
||||||
use_cache(Host) ->
|
use_cache(Host) ->
|
||||||
get_option({use_cache, Host}, opt_type(use_cache), true).
|
get_option({use_cache, Host}, true).
|
||||||
|
|
||||||
-spec cache_size(binary() | global) -> pos_integer() | infinity.
|
-spec cache_size(binary() | global) -> pos_integer() | infinity.
|
||||||
cache_size(Host) ->
|
cache_size(Host) ->
|
||||||
get_option({cache_size, Host}, opt_type(cache_size), 1000).
|
get_option({cache_size, Host}, 1000).
|
||||||
|
|
||||||
-spec cache_missed(binary() | global) -> boolean().
|
-spec cache_missed(binary() | global) -> boolean().
|
||||||
cache_missed(Host) ->
|
cache_missed(Host) ->
|
||||||
get_option({cache_missed, Host}, opt_type(cache_missed), true).
|
get_option({cache_missed, Host}, true).
|
||||||
|
|
||||||
-spec cache_life_time(binary() | global) -> pos_integer() | infinity.
|
-spec cache_life_time(binary() | global) -> pos_integer() | infinity.
|
||||||
%% NOTE: the integer value returned is in *seconds*
|
%% NOTE: the integer value returned is in *seconds*
|
||||||
cache_life_time(Host) ->
|
cache_life_time(Host) ->
|
||||||
get_option({cache_life_time, Host}, opt_type(cache_life_time), 3600).
|
get_option({cache_life_time, Host}, 3600).
|
||||||
|
|
|
@ -289,8 +289,7 @@ process2(Args, AccessCommands, Auth, Version) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_accesscommands() ->
|
get_accesscommands() ->
|
||||||
ejabberd_config:get_option(ejabberdctl_access_commands,
|
ejabberd_config:get_option(ejabberdctl_access_commands, []).
|
||||||
fun(V) when is_list(V) -> V end, []).
|
|
||||||
|
|
||||||
%%-----------------------------
|
%%-----------------------------
|
||||||
%% Command calling
|
%% Command calling
|
||||||
|
|
|
@ -521,12 +521,7 @@ analyze_ip_xff(IP, [], _Host) -> IP;
|
||||||
analyze_ip_xff({IPLast, Port}, XFF, Host) ->
|
analyze_ip_xff({IPLast, Port}, XFF, Host) ->
|
||||||
[ClientIP | ProxiesIPs] = str:tokens(XFF, <<", ">>) ++
|
[ClientIP | ProxiesIPs] = str:tokens(XFF, <<", ">>) ++
|
||||||
[misc:ip_to_list(IPLast)],
|
[misc:ip_to_list(IPLast)],
|
||||||
TrustedProxies = ejabberd_config:get_option(
|
TrustedProxies = ejabberd_config:get_option({trusted_proxies, Host}, []),
|
||||||
{trusted_proxies, Host},
|
|
||||||
fun(all) -> all;
|
|
||||||
(TPs) ->
|
|
||||||
[iolist_to_binary(TP) || TP <- TPs]
|
|
||||||
end, []),
|
|
||||||
IPClient = case is_ipchain_trusted(ProxiesIPs,
|
IPClient = case is_ipchain_trusted(ProxiesIPs,
|
||||||
TrustedProxies)
|
TrustedProxies)
|
||||||
of
|
of
|
||||||
|
|
|
@ -123,11 +123,9 @@ init([{#ws{ip = IP, http_opts = HOpts}, _} = WS]) ->
|
||||||
Opts = ejabberd_c2s_config:get_c2s_limits() ++ SOpts,
|
Opts = ejabberd_c2s_config:get_c2s_limits() ++ SOpts,
|
||||||
PingInterval = ejabberd_config:get_option(
|
PingInterval = ejabberd_config:get_option(
|
||||||
{websocket_ping_interval, ?MYNAME},
|
{websocket_ping_interval, ?MYNAME},
|
||||||
fun(I) when is_integer(I), I>=0 -> I end,
|
|
||||||
?PING_INTERVAL) * 1000,
|
?PING_INTERVAL) * 1000,
|
||||||
WSTimeout = ejabberd_config:get_option(
|
WSTimeout = ejabberd_config:get_option(
|
||||||
{websocket_timeout, ?MYNAME},
|
{websocket_timeout, ?MYNAME},
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
|
||||||
?WEBSOCKET_TIMEOUT) * 1000,
|
?WEBSOCKET_TIMEOUT) * 1000,
|
||||||
Socket = {http_ws, self(), IP},
|
Socket = {http_ws, self(), IP},
|
||||||
?DEBUG("Client connected through websocket ~p",
|
?DEBUG("Client connected through websocket ~p",
|
||||||
|
|
|
@ -49,24 +49,20 @@ init(_) ->
|
||||||
{ok, {{one_for_one, 10, 1}, listeners_childspec()}}.
|
{ok, {{one_for_one, 10, 1}, listeners_childspec()}}.
|
||||||
|
|
||||||
listeners_childspec() ->
|
listeners_childspec() ->
|
||||||
case ejabberd_config:get_option(listen, fun validate_cfg/1) of
|
Ls = ejabberd_config:get_option(listen, []),
|
||||||
undefined ->
|
Specs = lists:map(
|
||||||
[];
|
fun({Port, Module, Opts}) ->
|
||||||
Ls ->
|
maybe_start_sip(Module),
|
||||||
Specs = lists:map(
|
ets:insert(?MODULE, {Port, Module, Opts}),
|
||||||
fun({Port, Module, Opts}) ->
|
{Port,
|
||||||
maybe_start_sip(Module),
|
{?MODULE, start, [Port, Module, Opts]},
|
||||||
ets:insert(?MODULE, {Port, Module, Opts}),
|
transient,
|
||||||
{Port,
|
brutal_kill,
|
||||||
{?MODULE, start, [Port, Module, Opts]},
|
worker,
|
||||||
transient,
|
[?MODULE]}
|
||||||
brutal_kill,
|
end, Ls),
|
||||||
worker,
|
report_duplicated_portips(Ls),
|
||||||
[?MODULE]}
|
Specs.
|
||||||
end, Ls),
|
|
||||||
report_duplicated_portips(Ls),
|
|
||||||
Specs
|
|
||||||
end.
|
|
||||||
|
|
||||||
start_listeners() ->
|
start_listeners() ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
@ -384,7 +380,7 @@ start_listener_sup(Port, Module, Opts) ->
|
||||||
supervisor:start_child(?MODULE, ChildSpec).
|
supervisor:start_child(?MODULE, ChildSpec).
|
||||||
|
|
||||||
stop_listeners() ->
|
stop_listeners() ->
|
||||||
Ports = ejabberd_config:get_option(listen, fun validate_cfg/1),
|
Ports = ejabberd_config:get_option(listen, []),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({PortIpNetp, Module, _Opts}) ->
|
fun({PortIpNetp, Module, _Opts}) ->
|
||||||
delete_listener(PortIpNetp, Module)
|
delete_listener(PortIpNetp, Module)
|
||||||
|
@ -438,10 +434,7 @@ maybe_start_sip(_) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
config_reloaded() ->
|
config_reloaded() ->
|
||||||
New = case ejabberd_config:get_option(listen, fun validate_cfg/1) of
|
New = ejabberd_config:get_option(listen, []),
|
||||||
undefined -> [];
|
|
||||||
Ls -> Ls
|
|
||||||
end,
|
|
||||||
Old = ets:tab2list(?MODULE),
|
Old = ets:tab2list(?MODULE),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({PortIP, Module, _Opts}) ->
|
fun({PortIP, Module, _Opts}) ->
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
-module(ejabberd_oauth).
|
-module(ejabberd_oauth).
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
-behaviour(ejabberd_config).
|
||||||
|
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
|
||||||
|
@ -199,7 +200,6 @@ authenticate_user({User, Server}, Ctx) ->
|
||||||
Access =
|
Access =
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{oauth_access, JID#jid.lserver},
|
{oauth_access, JID#jid.lserver},
|
||||||
fun(A) -> A end,
|
|
||||||
none),
|
none),
|
||||||
case acl:match_rule(JID#jid.lserver, Access, JID) of
|
case acl:match_rule(JID#jid.lserver, Access, JID) of
|
||||||
allow ->
|
allow ->
|
||||||
|
@ -402,22 +402,19 @@ use_cache(DBMod) ->
|
||||||
true -> DBMod:use_cache();
|
true -> DBMod:use_cache();
|
||||||
false ->
|
false ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
oauth_use_cache, opt_type(oauth_use_cache),
|
oauth_use_cache,
|
||||||
ejabberd_config:use_cache(global))
|
ejabberd_config:use_cache(global))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
cache_opts() ->
|
cache_opts() ->
|
||||||
MaxSize = ejabberd_config:get_option(
|
MaxSize = ejabberd_config:get_option(
|
||||||
oauth_cache_size,
|
oauth_cache_size,
|
||||||
opt_type(oauth_cache_size),
|
|
||||||
ejabberd_config:cache_size(global)),
|
ejabberd_config:cache_size(global)),
|
||||||
CacheMissed = ejabberd_config:get_option(
|
CacheMissed = ejabberd_config:get_option(
|
||||||
oauth_cache_missed,
|
oauth_cache_missed,
|
||||||
opt_type(oauth_cache_missed),
|
|
||||||
ejabberd_config:cache_missed(global)),
|
ejabberd_config:cache_missed(global)),
|
||||||
LifeTime = case ejabberd_config:get_option(
|
LifeTime = case ejabberd_config:get_option(
|
||||||
oauth_cache_life_time,
|
oauth_cache_life_time,
|
||||||
opt_type(oauth_cache_life_time),
|
|
||||||
ejabberd_config:cache_life_time(global)) of
|
ejabberd_config:cache_life_time(global)) of
|
||||||
infinity -> infinity;
|
infinity -> infinity;
|
||||||
I -> timer:seconds(I)
|
I -> timer:seconds(I)
|
||||||
|
@ -425,10 +422,7 @@ cache_opts() ->
|
||||||
[{max_size, MaxSize}, {life_time, LifeTime}, {cache_missed, CacheMissed}].
|
[{max_size, MaxSize}, {life_time, LifeTime}, {cache_missed, CacheMissed}].
|
||||||
|
|
||||||
expire() ->
|
expire() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(oauth_expire, ?EXPIRE).
|
||||||
oauth_expire,
|
|
||||||
fun(I) when is_integer(I) -> I end,
|
|
||||||
?EXPIRE).
|
|
||||||
|
|
||||||
-define(DIV(Class, Els),
|
-define(DIV(Class, Els),
|
||||||
?XAE(<<"div">>, [{<<"class">>, Class}], Els)).
|
?XAE(<<"div">>, [{<<"class">>, Class}], Els)).
|
||||||
|
@ -623,9 +617,8 @@ process(_Handlers, _Request) ->
|
||||||
|
|
||||||
get_db_backend() ->
|
get_db_backend() ->
|
||||||
DBType = ejabberd_config:get_option(
|
DBType = ejabberd_config:get_option(
|
||||||
oauth_db_type,
|
oauth_db_type,
|
||||||
fun(T) -> ejabberd_config:v_db(?MODULE, T) end,
|
ejabberd_config:default_db(?MODULE)),
|
||||||
mnesia),
|
|
||||||
list_to_atom("ejabberd_oauth_" ++ atom_to_list(DBType)).
|
list_to_atom("ejabberd_oauth_" ++ atom_to_list(DBType)).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
-module(ejabberd_oauth_rest).
|
-module(ejabberd_oauth_rest).
|
||||||
|
|
||||||
|
-behaviour(ejabberd_config).
|
||||||
|
|
||||||
-export([init/0,
|
-export([init/0,
|
||||||
store/1,
|
store/1,
|
||||||
lookup/1,
|
lookup/1,
|
||||||
|
@ -87,9 +89,7 @@ clean(_TS) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
path(Path) ->
|
path(Path) ->
|
||||||
Base = ejabberd_config:get_option(ext_api_path_oauth,
|
Base = ejabberd_config:get_option(ext_api_path_oauth, <<"/oauth">>),
|
||||||
fun(X) -> iolist_to_binary(X) end,
|
|
||||||
<<"/oauth">>),
|
|
||||||
<<Base/binary, "/", Path/binary>>.
|
<<Base/binary, "/", Path/binary>>.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,9 @@
|
||||||
|
|
||||||
-module(ejabberd_piefxis).
|
-module(ejabberd_piefxis).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-protocol({xep, 227, '1.0'}).
|
-protocol({xep, 227, '1.0'}).
|
||||||
|
|
||||||
-export([import_file/1, export_server/1, export_host/2,
|
-export([import_file/1, export_server/1, export_host/2]).
|
||||||
opt_type/1]).
|
|
||||||
|
|
||||||
-define(CHUNK_SIZE, 1024*20). %20k
|
-define(CHUNK_SIZE, 1024*20). %20k
|
||||||
|
|
||||||
|
@ -169,7 +166,7 @@ export_users([], _Server, _Fd) ->
|
||||||
export_user(User, Server, Fd) ->
|
export_user(User, Server, Fd) ->
|
||||||
Password = ejabberd_auth:get_password_s(User, Server),
|
Password = ejabberd_auth:get_password_s(User, Server),
|
||||||
LServer = jid:nameprep(Server),
|
LServer = jid:nameprep(Server),
|
||||||
PasswordFormat = ejabberd_config:get_option({auth_password_format, LServer}, fun(X) -> X end, plain),
|
PasswordFormat = ejabberd_auth:password_format(LServer),
|
||||||
Pass = case Password of
|
Pass = case Password of
|
||||||
{_,_,_,_} ->
|
{_,_,_,_} ->
|
||||||
case PasswordFormat of
|
case PasswordFormat of
|
||||||
|
@ -389,7 +386,7 @@ process_user(#xmlel{name = <<"user">>, attrs = Attrs, children = Els},
|
||||||
#state{server = LServer} = State) ->
|
#state{server = LServer} = State) ->
|
||||||
Name = fxml:get_attr_s(<<"name">>, Attrs),
|
Name = fxml:get_attr_s(<<"name">>, Attrs),
|
||||||
Password = fxml:get_attr_s(<<"password">>, Attrs),
|
Password = fxml:get_attr_s(<<"password">>, Attrs),
|
||||||
PasswordFormat = ejabberd_config:get_option({auth_password_format, LServer}, fun(X) -> X end, plain),
|
PasswordFormat = ejabberd_auth:password_format(LServer),
|
||||||
Pass = case PasswordFormat of
|
Pass = case PasswordFormat of
|
||||||
scram ->
|
scram ->
|
||||||
case Password of
|
case Password of
|
||||||
|
@ -596,7 +593,3 @@ make_xinclude(Fn) ->
|
||||||
|
|
||||||
print(Fd, String) ->
|
print(Fd, String) ->
|
||||||
file:write(Fd, String).
|
file:write(Fd, String).
|
||||||
|
|
||||||
opt_type(auth_password_format) -> fun (X) -> X end;
|
|
||||||
opt_type(_) -> [auth_password_format].
|
|
||||||
|
|
||||||
|
|
|
@ -100,13 +100,7 @@ stop_host(Host) ->
|
||||||
%% Returns {true, App} if we have configured sql for the given host
|
%% Returns {true, App} if we have configured sql for the given host
|
||||||
needs_sql(Host) ->
|
needs_sql(Host) ->
|
||||||
LHost = jid:nameprep(Host),
|
LHost = jid:nameprep(Host),
|
||||||
case ejabberd_config:get_option({sql_type, LHost},
|
case ejabberd_config:get_option({sql_type, LHost}, undefined) of
|
||||||
fun(mysql) -> mysql;
|
|
||||||
(pgsql) -> pgsql;
|
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end, undefined) of
|
|
||||||
mysql -> {true, p1_mysql};
|
mysql -> {true, p1_mysql};
|
||||||
pgsql -> {true, p1_pgsql};
|
pgsql -> {true, p1_pgsql};
|
||||||
sqlite -> {true, sqlite3};
|
sqlite -> {true, sqlite3};
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
-define(GEN_SERVER, gen_server).
|
-define(GEN_SERVER, gen_server).
|
||||||
-endif.
|
-endif.
|
||||||
-behaviour(?GEN_SERVER).
|
-behaviour(?GEN_SERVER).
|
||||||
|
-behaviour(ejabberd_config).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/4,
|
-export([start_link/4,
|
||||||
|
@ -41,7 +42,8 @@
|
||||||
starttls/2,
|
starttls/2,
|
||||||
compress/2,
|
compress/2,
|
||||||
become_controller/2,
|
become_controller/2,
|
||||||
close/1]).
|
close/1,
|
||||||
|
opt_type/1]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([init/1, handle_call/3, handle_cast/2,
|
||||||
|
@ -59,9 +61,6 @@
|
||||||
xml_stream_state :: fxml_stream:xml_stream_state() | undefined,
|
xml_stream_state :: fxml_stream:xml_stream_state() | undefined,
|
||||||
timeout = infinity:: timeout()}).
|
timeout = infinity:: timeout()}).
|
||||||
|
|
||||||
-define(HIBERNATE_TIMEOUT, ejabberd_config:get_option(receiver_hibernate, fun(X) when is_integer(X); X == hibernate-> X end, 90000)).
|
|
||||||
|
|
||||||
|
|
||||||
-spec start_link(inet:socket(), atom(), shaper:shaper(),
|
-spec start_link(inet:socket(), atom(), shaper:shaper(),
|
||||||
non_neg_integer() | infinity) -> ignore |
|
non_neg_integer() | infinity) -> ignore |
|
||||||
{error, any()} |
|
{error, any()} |
|
||||||
|
@ -137,7 +136,7 @@ handle_call({starttls, TLSSocket}, _From, State) ->
|
||||||
case fast_tls:recv_data(TLSSocket, <<"">>) of
|
case fast_tls:recv_data(TLSSocket, <<"">>) of
|
||||||
{ok, TLSData} ->
|
{ok, TLSData} ->
|
||||||
{reply, ok,
|
{reply, ok,
|
||||||
process_data(TLSData, NewState), ?HIBERNATE_TIMEOUT};
|
process_data(TLSData, NewState), hibernate_timeout()};
|
||||||
{error, _} = Err ->
|
{error, _} = Err ->
|
||||||
{stop, normal, Err, NewState}
|
{stop, normal, Err, NewState}
|
||||||
end;
|
end;
|
||||||
|
@ -156,31 +155,31 @@ handle_call({compress, Data}, _From,
|
||||||
case ezlib:recv_data(ZlibSocket, <<"">>) of
|
case ezlib:recv_data(ZlibSocket, <<"">>) of
|
||||||
{ok, ZlibData} ->
|
{ok, ZlibData} ->
|
||||||
{reply, {ok, ZlibSocket},
|
{reply, {ok, ZlibSocket},
|
||||||
process_data(ZlibData, NewState), ?HIBERNATE_TIMEOUT};
|
process_data(ZlibData, NewState), hibernate_timeout()};
|
||||||
{error, _} = Err ->
|
{error, _} = Err ->
|
||||||
{stop, normal, Err, NewState}
|
{stop, normal, Err, NewState}
|
||||||
end;
|
end;
|
||||||
handle_call(reset_stream, _From, State) ->
|
handle_call(reset_stream, _From, State) ->
|
||||||
NewState = reset_parser(State),
|
NewState = reset_parser(State),
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{reply, Reply, NewState, ?HIBERNATE_TIMEOUT};
|
{reply, Reply, NewState, hibernate_timeout()};
|
||||||
handle_call({become_controller, C2SPid}, _From, State) ->
|
handle_call({become_controller, C2SPid}, _From, State) ->
|
||||||
XMLStreamState = fxml_stream:new(C2SPid, State#state.max_stanza_size),
|
XMLStreamState = fxml_stream:new(C2SPid, State#state.max_stanza_size),
|
||||||
NewState = State#state{c2s_pid = C2SPid,
|
NewState = State#state{c2s_pid = C2SPid,
|
||||||
xml_stream_state = XMLStreamState},
|
xml_stream_state = XMLStreamState},
|
||||||
activate_socket(NewState),
|
activate_socket(NewState),
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{reply, Reply, NewState, ?HIBERNATE_TIMEOUT};
|
{reply, Reply, NewState, hibernate_timeout()};
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
Reply = ok, {reply, Reply, State, ?HIBERNATE_TIMEOUT}.
|
Reply = ok, {reply, Reply, State, hibernate_timeout()}.
|
||||||
|
|
||||||
handle_cast({change_shaper, Shaper}, State) ->
|
handle_cast({change_shaper, Shaper}, State) ->
|
||||||
NewShaperState = shaper:new(Shaper),
|
NewShaperState = shaper:new(Shaper),
|
||||||
{noreply, State#state{shaper_state = NewShaperState},
|
{noreply, State#state{shaper_state = NewShaperState},
|
||||||
?HIBERNATE_TIMEOUT};
|
hibernate_timeout()};
|
||||||
handle_cast(close, State) -> {stop, normal, State};
|
handle_cast(close, State) -> {stop, normal, State};
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT}.
|
{noreply, State, hibernate_timeout()}.
|
||||||
|
|
||||||
handle_info({Tag, _TCPSocket, Data},
|
handle_info({Tag, _TCPSocket, Data},
|
||||||
#state{socket = Socket, sock_mod = SockMod} = State)
|
#state{socket = Socket, sock_mod = SockMod} = State)
|
||||||
|
@ -191,7 +190,7 @@ handle_info({Tag, _TCPSocket, Data},
|
||||||
case fast_tls:recv_data(Socket, Data) of
|
case fast_tls:recv_data(Socket, Data) of
|
||||||
{ok, TLSData} ->
|
{ok, TLSData} ->
|
||||||
{noreply, process_data(TLSData, State),
|
{noreply, process_data(TLSData, State),
|
||||||
?HIBERNATE_TIMEOUT};
|
hibernate_timeout()};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
if is_binary(Reason) ->
|
if is_binary(Reason) ->
|
||||||
?DEBUG("TLS error = ~s", [Reason]);
|
?DEBUG("TLS error = ~s", [Reason]);
|
||||||
|
@ -204,11 +203,11 @@ handle_info({Tag, _TCPSocket, Data},
|
||||||
case ezlib:recv_data(Socket, Data) of
|
case ezlib:recv_data(Socket, Data) of
|
||||||
{ok, ZlibData} ->
|
{ok, ZlibData} ->
|
||||||
{noreply, process_data(ZlibData, State),
|
{noreply, process_data(ZlibData, State),
|
||||||
?HIBERNATE_TIMEOUT};
|
hibernate_timeout()};
|
||||||
{error, _Reason} -> {stop, normal, State}
|
{error, _Reason} -> {stop, normal, State}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
{noreply, process_data(Data, State), ?HIBERNATE_TIMEOUT}
|
{noreply, process_data(Data, State), hibernate_timeout()}
|
||||||
end;
|
end;
|
||||||
handle_info({Tag, _TCPSocket}, State)
|
handle_info({Tag, _TCPSocket}, State)
|
||||||
when (Tag == tcp_closed) or (Tag == ssl_closed) ->
|
when (Tag == tcp_closed) or (Tag == ssl_closed) ->
|
||||||
|
@ -216,18 +215,18 @@ handle_info({Tag, _TCPSocket}, State)
|
||||||
handle_info({Tag, _TCPSocket, Reason}, State)
|
handle_info({Tag, _TCPSocket, Reason}, State)
|
||||||
when (Tag == tcp_error) or (Tag == ssl_error) ->
|
when (Tag == tcp_error) or (Tag == ssl_error) ->
|
||||||
case Reason of
|
case Reason of
|
||||||
timeout -> {noreply, State, ?HIBERNATE_TIMEOUT};
|
timeout -> {noreply, State, hibernate_timeout()};
|
||||||
_ -> {stop, normal, State}
|
_ -> {stop, normal, State}
|
||||||
end;
|
end;
|
||||||
handle_info({timeout, _Ref, activate}, State) ->
|
handle_info({timeout, _Ref, activate}, State) ->
|
||||||
activate_socket(State),
|
activate_socket(State),
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
{noreply, State, hibernate_timeout()};
|
||||||
handle_info(timeout, State) ->
|
handle_info(timeout, State) ->
|
||||||
proc_lib:hibernate(?GEN_SERVER, enter_loop,
|
proc_lib:hibernate(?GEN_SERVER, enter_loop,
|
||||||
[?MODULE, [], State]),
|
[?MODULE, [], State]),
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
{noreply, State, hibernate_timeout()};
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT}.
|
{noreply, State, hibernate_timeout()}.
|
||||||
|
|
||||||
terminate(_Reason,
|
terminate(_Reason,
|
||||||
#state{xml_stream_state = XMLStreamState,
|
#state{xml_stream_state = XMLStreamState,
|
||||||
|
@ -345,3 +344,13 @@ do_call(Pid, Msg) ->
|
||||||
_:_ ->
|
_:_ ->
|
||||||
{error, einval}
|
{error, einval}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
hibernate_timeout() ->
|
||||||
|
ejabberd_config:get_option(receiver_hibernate, timer:seconds(90)).
|
||||||
|
|
||||||
|
opt_type(receiver_hibernate) ->
|
||||||
|
fun(I) when is_integer(I), I>0 -> I;
|
||||||
|
(hibernate) -> hibernate
|
||||||
|
end;
|
||||||
|
opt_type(_) ->
|
||||||
|
[receiver_hibernate].
|
||||||
|
|
|
@ -421,26 +421,13 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
-spec connect(state()) -> {ok, pid()} | {error, any()}.
|
-spec connect(state()) -> {ok, pid()} | {error, any()}.
|
||||||
connect(#state{num = Num}) ->
|
connect(#state{num = Num}) ->
|
||||||
Server = ejabberd_config:get_option(redis_server,
|
Server = ejabberd_config:get_option(redis_server, "localhost"),
|
||||||
fun iolist_to_list/1,
|
Port = ejabberd_config:get_option(redis_port, 6379),
|
||||||
"localhost"),
|
DB = ejabberd_config:get_option(redis_db, 0),
|
||||||
Port = ejabberd_config:get_option(redis_port,
|
Pass = ejabberd_config:get_option(redis_password, ""),
|
||||||
fun(P) when is_integer(P),
|
|
||||||
P>0, P<65536 ->
|
|
||||||
P
|
|
||||||
end, 6379),
|
|
||||||
DB = ejabberd_config:get_option(redis_db,
|
|
||||||
fun(I) when is_integer(I), I >= 0 ->
|
|
||||||
I
|
|
||||||
end, 0),
|
|
||||||
Pass = ejabberd_config:get_option(redis_password,
|
|
||||||
fun iolist_to_list/1,
|
|
||||||
""),
|
|
||||||
ConnTimeout = timer:seconds(
|
ConnTimeout = timer:seconds(
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
redis_connect_timeout,
|
redis_connect_timeout, 1)),
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
|
||||||
1)),
|
|
||||||
try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of
|
try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of
|
||||||
{ok, Client} ->
|
{ok, Client} ->
|
||||||
?DEBUG("Connection #~p established to Redis at ~s:~p",
|
?DEBUG("Connection #~p established to Redis at ~s:~p",
|
||||||
|
@ -552,10 +539,6 @@ reply(Val) ->
|
||||||
_ -> queued
|
_ -> queued
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec iolist_to_list(iodata()) -> string().
|
|
||||||
iolist_to_list(IOList) ->
|
|
||||||
binary_to_list(iolist_to_binary(IOList)).
|
|
||||||
|
|
||||||
-spec max_fsm_queue() -> pos_integer().
|
-spec max_fsm_queue() -> pos_integer().
|
||||||
max_fsm_queue() ->
|
max_fsm_queue() ->
|
||||||
proplists:get_value(max_queue, fsm_limit_opts(), ?DEFAULT_MAX_QUEUE).
|
proplists:get_value(max_queue, fsm_limit_opts(), ?DEFAULT_MAX_QUEUE).
|
||||||
|
@ -564,14 +547,9 @@ fsm_limit_opts() ->
|
||||||
ejabberd_config:fsm_limit_opts([]).
|
ejabberd_config:fsm_limit_opts([]).
|
||||||
|
|
||||||
get_queue_type() ->
|
get_queue_type() ->
|
||||||
case ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
redis_queue_type,
|
redis_queue_type,
|
||||||
ejabberd_redis_sup:opt_type(redis_queue_type)) of
|
ejabberd_config:default_queue_type(global)).
|
||||||
undefined ->
|
|
||||||
ejabberd_config:default_queue_type(global);
|
|
||||||
Type ->
|
|
||||||
Type
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec flush_queue(p1_queue:queue()) -> p1_queue:queue().
|
-spec flush_queue(p1_queue:queue()) -> p1_queue:queue().
|
||||||
flush_queue(Q) ->
|
flush_queue(Q) ->
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
-module(ejabberd_redis_sup).
|
-module(ejabberd_redis_sup).
|
||||||
|
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
|
-behaviour(ejabberd_config).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0, get_pool_size/0,
|
-export([start_link/0, get_pool_size/0,
|
||||||
|
@ -107,15 +108,9 @@ is_redis_configured(Host) ->
|
||||||
PoolSize = ejabberd_config:has_option({redis_pool_size, Host}),
|
PoolSize = ejabberd_config:has_option({redis_pool_size, Host}),
|
||||||
ConnTimeoutConfigured = ejabberd_config:has_option(
|
ConnTimeoutConfigured = ejabberd_config:has_option(
|
||||||
{redis_connect_timeout, Host}),
|
{redis_connect_timeout, Host}),
|
||||||
Modules = ejabberd_config:get_option(
|
Modules = ejabberd_config:get_option({modules, Host}, []),
|
||||||
{modules, Host},
|
SMConfigured = ejabberd_config:get_option({sm_db_type, Host}) == redis,
|
||||||
fun(L) when is_list(L) -> L end, []),
|
RouterConfigured = ejabberd_config:get_option({router_db_type, Host}) == redis,
|
||||||
SMConfigured = ejabberd_config:get_option(
|
|
||||||
{sm_db_type, Host},
|
|
||||||
fun(V) -> V end) == redis,
|
|
||||||
RouterConfigured = ejabberd_config:get_option(
|
|
||||||
{router_db_type, Host},
|
|
||||||
fun(V) -> V end) == redis,
|
|
||||||
ModuleWithRedisDBConfigured =
|
ModuleWithRedisDBConfigured =
|
||||||
lists:any(
|
lists:any(
|
||||||
fun({Module, Opts}) ->
|
fun({Module, Opts}) ->
|
||||||
|
@ -133,10 +128,7 @@ get_specs() ->
|
||||||
end, lists:seq(1, get_pool_size())).
|
end, lists:seq(1, get_pool_size())).
|
||||||
|
|
||||||
get_pool_size() ->
|
get_pool_size() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(redis_pool_size, ?DEFAULT_POOL_SIZE) + 1.
|
||||||
redis_pool_size,
|
|
||||||
fun(N) when is_integer(N), N >= 1 -> N end,
|
|
||||||
?DEFAULT_POOL_SIZE) + 1.
|
|
||||||
|
|
||||||
iolist_to_list(IOList) ->
|
iolist_to_list(IOList) ->
|
||||||
binary_to_list(iolist_to_binary(IOList)).
|
binary_to_list(iolist_to_binary(IOList)).
|
||||||
|
|
|
@ -87,15 +87,9 @@ is_riak_configured(Host) ->
|
||||||
AuthConfigured = lists:member(
|
AuthConfigured = lists:member(
|
||||||
ejabberd_auth_riak,
|
ejabberd_auth_riak,
|
||||||
ejabberd_auth:auth_modules(Host)),
|
ejabberd_auth:auth_modules(Host)),
|
||||||
SMConfigured = ejabberd_config:get_option(
|
SMConfigured = ejabberd_config:get_option({sm_db_type, Host}) == riak,
|
||||||
{sm_db_type, Host},
|
RouterConfigured = ejabberd_config:get_option({router_db_type, Host}) == riak,
|
||||||
ejabberd_sm:opt_type(sm_db_type)) == riak,
|
Modules = ejabberd_config:get_option({modules, Host}, []),
|
||||||
RouterConfigured = ejabberd_config:get_option(
|
|
||||||
{router_db_type, Host},
|
|
||||||
ejabberd_router:opt_type(router_db_type)) == riak,
|
|
||||||
Modules = ejabberd_config:get_option(
|
|
||||||
{modules, Host},
|
|
||||||
fun(L) when is_list(L) -> L end, []),
|
|
||||||
ModuleWithRiakDBConfigured = lists:any(
|
ModuleWithRiakDBConfigured = lists:any(
|
||||||
fun({Module, Opts}) ->
|
fun({Module, Opts}) ->
|
||||||
gen_mod:db_type(Host, Opts, Module) == riak
|
gen_mod:db_type(Host, Opts, Module) == riak
|
||||||
|
@ -150,50 +144,25 @@ get_specs() ->
|
||||||
end, lists:seq(1, PoolSize)).
|
end, lists:seq(1, PoolSize)).
|
||||||
|
|
||||||
get_start_interval() ->
|
get_start_interval() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_start_interval, ?DEFAULT_RIAK_START_INTERVAL).
|
||||||
riak_start_interval,
|
|
||||||
fun(N) when is_integer(N), N >= 1 -> N end,
|
|
||||||
?DEFAULT_RIAK_START_INTERVAL).
|
|
||||||
|
|
||||||
get_pool_size() ->
|
get_pool_size() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_pool_size, ?DEFAULT_POOL_SIZE).
|
||||||
riak_pool_size,
|
|
||||||
fun(N) when is_integer(N), N >= 1 -> N end,
|
|
||||||
?DEFAULT_POOL_SIZE).
|
|
||||||
|
|
||||||
get_riak_server() ->
|
get_riak_server() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_server, ?DEFAULT_RIAK_HOST).
|
||||||
riak_server,
|
|
||||||
fun(S) ->
|
|
||||||
binary_to_list(iolist_to_binary(S))
|
|
||||||
end, ?DEFAULT_RIAK_HOST).
|
|
||||||
|
|
||||||
get_riak_cacertfile() ->
|
get_riak_cacertfile() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_cacertfile, nil).
|
||||||
riak_cacertfile,
|
|
||||||
fun(S) ->
|
|
||||||
binary_to_list(iolist_to_binary(S))
|
|
||||||
end, nil).
|
|
||||||
|
|
||||||
get_riak_username() ->
|
get_riak_username() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_username, nil).
|
||||||
riak_username,
|
|
||||||
fun(S) ->
|
|
||||||
binary_to_list(iolist_to_binary(S))
|
|
||||||
end, nil).
|
|
||||||
|
|
||||||
get_riak_password() ->
|
get_riak_password() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_password, nil).
|
||||||
riak_password,
|
|
||||||
fun(S) ->
|
|
||||||
binary_to_list(iolist_to_binary(S))
|
|
||||||
end, nil).
|
|
||||||
|
|
||||||
get_riak_port() ->
|
get_riak_port() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(riak_port, ?DEFAULT_RIAK_PORT).
|
||||||
riak_port,
|
|
||||||
fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
|
|
||||||
?DEFAULT_RIAK_PORT).
|
|
||||||
|
|
||||||
get_pids() ->
|
get_pids() ->
|
||||||
[ejabberd_riak:get_proc(I) || I <- lists:seq(1, get_pool_size())].
|
[ejabberd_riak:get_proc(I) || I <- lists:seq(1, get_pool_size())].
|
||||||
|
@ -210,16 +179,20 @@ transform_options({riak_server, {S, P}}, Opts) ->
|
||||||
transform_options(Opt, Opts) ->
|
transform_options(Opt, Opts) ->
|
||||||
[Opt|Opts].
|
[Opt|Opts].
|
||||||
|
|
||||||
opt_type(modules) -> fun (L) when is_list(L) -> L end;
|
|
||||||
opt_type(riak_pool_size) ->
|
opt_type(riak_pool_size) ->
|
||||||
fun (N) when is_integer(N), N >= 1 -> N end;
|
fun (N) when is_integer(N), N >= 1 -> N end;
|
||||||
opt_type(riak_port) -> fun (_) -> true end;
|
opt_type(riak_port) ->
|
||||||
opt_type(riak_server) -> fun (_) -> true end;
|
fun(P) when is_integer(P), P > 0, P < 65536 -> P end;
|
||||||
|
opt_type(riak_server) ->
|
||||||
|
fun(S) -> binary_to_list(iolist_to_binary(S)) end;
|
||||||
opt_type(riak_start_interval) ->
|
opt_type(riak_start_interval) ->
|
||||||
fun (N) when is_integer(N), N >= 1 -> N end;
|
fun (N) when is_integer(N), N >= 1 -> N end;
|
||||||
opt_type(riak_cacertfile) -> fun iolist_to_binary/1;
|
opt_type(riak_cacertfile) ->
|
||||||
opt_type(riak_username) -> fun iolist_to_binary/1;
|
fun(S) -> binary_to_list(iolist_to_binary(S)) end;
|
||||||
opt_type(riak_password) -> fun iolist_to_binary/1;
|
opt_type(riak_username) ->
|
||||||
|
fun(S) -> binary_to_list(iolist_to_binary(S)) end;
|
||||||
|
opt_type(riak_password) ->
|
||||||
|
fun(S) -> binary_to_list(iolist_to_binary(S)) end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[modules, riak_pool_size, riak_port, riak_server,
|
[riak_pool_size, riak_port, riak_server,
|
||||||
riak_start_interval, riak_cacertfile, riak_username, riak_password].
|
riak_start_interval, riak_cacertfile, riak_username, riak_password].
|
||||||
|
|
|
@ -385,15 +385,11 @@ balancing_route(From, To, Packet, Rs) ->
|
||||||
|
|
||||||
-spec get_component_number(binary()) -> pos_integer() | undefined.
|
-spec get_component_number(binary()) -> pos_integer() | undefined.
|
||||||
get_component_number(LDomain) ->
|
get_component_number(LDomain) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({domain_balancing_component_number, LDomain}).
|
||||||
{domain_balancing_component_number, LDomain},
|
|
||||||
fun(N) when is_integer(N), N > 1 -> N end,
|
|
||||||
undefined).
|
|
||||||
|
|
||||||
-spec get_domain_balancing(jid(), jid(), binary()) -> any().
|
-spec get_domain_balancing(jid(), jid(), binary()) -> any().
|
||||||
get_domain_balancing(From, To, LDomain) ->
|
get_domain_balancing(From, To, LDomain) ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({domain_balancing, LDomain}) of
|
||||||
{domain_balancing, LDomain}, fun(D) when is_atom(D) -> D end) of
|
|
||||||
undefined -> p1_time_compat:system_time();
|
undefined -> p1_time_compat:system_time();
|
||||||
random -> p1_time_compat:system_time();
|
random -> p1_time_compat:system_time();
|
||||||
source -> jid:tolower(From);
|
source -> jid:tolower(From);
|
||||||
|
@ -404,14 +400,9 @@ get_domain_balancing(From, To, LDomain) ->
|
||||||
|
|
||||||
-spec get_backend() -> module().
|
-spec get_backend() -> module().
|
||||||
get_backend() ->
|
get_backend() ->
|
||||||
DBType = case ejabberd_config:get_option(
|
DBType = ejabberd_config:get_option(
|
||||||
router_db_type,
|
router_db_type,
|
||||||
fun(T) -> ejabberd_config:v_db(?MODULE, T) end) of
|
ejabberd_config:default_ram_db(?MODULE)),
|
||||||
undefined ->
|
|
||||||
ejabberd_config:default_ram_db(?MODULE);
|
|
||||||
T ->
|
|
||||||
T
|
|
||||||
end,
|
|
||||||
list_to_atom("ejabberd_router_" ++ atom_to_list(DBType)).
|
list_to_atom("ejabberd_router_" ++ atom_to_list(DBType)).
|
||||||
|
|
||||||
-spec cache_nodes(module()) -> [node()].
|
-spec cache_nodes(module()) -> [node()].
|
||||||
|
@ -427,7 +418,7 @@ use_cache(Mod) ->
|
||||||
true -> Mod:use_cache();
|
true -> Mod:use_cache();
|
||||||
false ->
|
false ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
router_use_cache, opt_type(router_use_cache),
|
router_use_cache,
|
||||||
ejabberd_config:use_cache(global))
|
ejabberd_config:use_cache(global))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -454,15 +445,12 @@ init_cache(Mod) ->
|
||||||
cache_opts() ->
|
cache_opts() ->
|
||||||
MaxSize = ejabberd_config:get_option(
|
MaxSize = ejabberd_config:get_option(
|
||||||
router_cache_size,
|
router_cache_size,
|
||||||
opt_type(router_cache_size),
|
|
||||||
ejabberd_config:cache_size(global)),
|
ejabberd_config:cache_size(global)),
|
||||||
CacheMissed = ejabberd_config:get_option(
|
CacheMissed = ejabberd_config:get_option(
|
||||||
router_cache_missed,
|
router_cache_missed,
|
||||||
opt_type(router_cache_missed),
|
|
||||||
ejabberd_config:cache_missed(global)),
|
ejabberd_config:cache_missed(global)),
|
||||||
LifeTime = case ejabberd_config:get_option(
|
LifeTime = case ejabberd_config:get_option(
|
||||||
router_cache_life_time,
|
router_cache_life_time,
|
||||||
opt_type(router_cache_life_time),
|
|
||||||
ejabberd_config:cache_life_time(global)) of
|
ejabberd_config:cache_life_time(global)) of
|
||||||
infinity -> infinity;
|
infinity -> infinity;
|
||||||
I -> timer:seconds(I)
|
I -> timer:seconds(I)
|
||||||
|
|
|
@ -200,45 +200,37 @@ dirty_get_connections() ->
|
||||||
tls_options(LServer, DefaultOpts) ->
|
tls_options(LServer, DefaultOpts) ->
|
||||||
TLSOpts1 = case ejabberd_config:get_option(
|
TLSOpts1 = case ejabberd_config:get_option(
|
||||||
{s2s_certfile, LServer},
|
{s2s_certfile, LServer},
|
||||||
fun iolist_to_binary/1,
|
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{domain_certfile, LServer},
|
{domain_certfile, LServer})) of
|
||||||
fun iolist_to_binary/1)) of
|
|
||||||
undefined -> DefaultOpts;
|
undefined -> DefaultOpts;
|
||||||
CertFile -> lists:keystore(certfile, 1, DefaultOpts,
|
CertFile -> lists:keystore(certfile, 1, DefaultOpts,
|
||||||
{certfile, CertFile})
|
{certfile, CertFile})
|
||||||
end,
|
end,
|
||||||
TLSOpts2 = case ejabberd_config:get_option(
|
TLSOpts2 = case ejabberd_config:get_option(
|
||||||
{s2s_ciphers, LServer},
|
{s2s_ciphers, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts1;
|
undefined -> TLSOpts1;
|
||||||
Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
|
Ciphers -> lists:keystore(ciphers, 1, TLSOpts1,
|
||||||
{ciphers, Ciphers})
|
{ciphers, Ciphers})
|
||||||
end,
|
end,
|
||||||
TLSOpts3 = case ejabberd_config:get_option(
|
TLSOpts3 = case ejabberd_config:get_option(
|
||||||
{s2s_protocol_options, LServer},
|
{s2s_protocol_options, LServer}) of
|
||||||
fun (Options) -> str:join(Options, <<$|>>) end) of
|
|
||||||
undefined -> TLSOpts2;
|
undefined -> TLSOpts2;
|
||||||
ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
|
ProtoOpts -> lists:keystore(protocol_options, 1, TLSOpts2,
|
||||||
{protocol_options, ProtoOpts})
|
{protocol_options, ProtoOpts})
|
||||||
end,
|
end,
|
||||||
TLSOpts4 = case ejabberd_config:get_option(
|
TLSOpts4 = case ejabberd_config:get_option(
|
||||||
{s2s_dhfile, LServer},
|
{s2s_dhfile, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts3;
|
undefined -> TLSOpts3;
|
||||||
DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
|
DHFile -> lists:keystore(dhfile, 1, TLSOpts3,
|
||||||
{dhfile, DHFile})
|
{dhfile, DHFile})
|
||||||
end,
|
end,
|
||||||
TLSOpts5 = case ejabberd_config:get_option(
|
TLSOpts5 = case ejabberd_config:get_option(
|
||||||
{s2s_cafile, LServer},
|
{s2s_cafile, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> TLSOpts4;
|
undefined -> TLSOpts4;
|
||||||
CAFile -> lists:keystore(cafile, 1, TLSOpts4,
|
CAFile -> lists:keystore(cafile, 1, TLSOpts4,
|
||||||
{cafile, CAFile})
|
{cafile, CAFile})
|
||||||
end,
|
end,
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({s2s_tls_compression, LServer}) of
|
||||||
{s2s_tls_compression, LServer},
|
|
||||||
fun(B) when is_boolean(B) -> B end) of
|
|
||||||
undefined -> TLSOpts5;
|
undefined -> TLSOpts5;
|
||||||
false -> [compression_none | TLSOpts5];
|
false -> [compression_none | TLSOpts5];
|
||||||
true -> lists:delete(compression_none, TLSOpts5)
|
true -> lists:delete(compression_none, TLSOpts5)
|
||||||
|
@ -261,37 +253,21 @@ tls_enabled(LServer) ->
|
||||||
|
|
||||||
-spec zlib_enabled(binary()) -> boolean().
|
-spec zlib_enabled(binary()) -> boolean().
|
||||||
zlib_enabled(LServer) ->
|
zlib_enabled(LServer) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({s2s_zlib, LServer}, false).
|
||||||
{s2s_zlib, LServer},
|
|
||||||
fun(B) when is_boolean(B) -> B end,
|
|
||||||
false).
|
|
||||||
|
|
||||||
-spec use_starttls(binary()) -> boolean() | optional | required | required_trusted.
|
-spec use_starttls(binary()) -> boolean() | optional | required | required_trusted.
|
||||||
use_starttls(LServer) ->
|
use_starttls(LServer) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({s2s_use_starttls, LServer}, false).
|
||||||
{s2s_use_starttls, LServer},
|
|
||||||
fun(true) -> true;
|
|
||||||
(false) -> false;
|
|
||||||
(optional) -> optional;
|
|
||||||
(required) -> required;
|
|
||||||
(required_trusted) -> required_trusted
|
|
||||||
end, false).
|
|
||||||
|
|
||||||
-spec get_idle_timeout(binary()) -> non_neg_integer() | infinity.
|
-spec get_idle_timeout(binary()) -> non_neg_integer() | infinity.
|
||||||
get_idle_timeout(LServer) ->
|
get_idle_timeout(LServer) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({s2s_timeout, LServer}, timer:minutes(10)).
|
||||||
{s2s_timeout, LServer},
|
|
||||||
fun(I) when is_integer(I), I >= 0 -> timer:seconds(I);
|
|
||||||
(infinity) -> infinity
|
|
||||||
end, timer:minutes(10)).
|
|
||||||
|
|
||||||
-spec queue_type(binary()) -> ram | file.
|
-spec queue_type(binary()) -> ram | file.
|
||||||
queue_type(LServer) ->
|
queue_type(LServer) ->
|
||||||
case ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{s2s_queue_type, LServer}, opt_type(s2s_queue_type)) of
|
{s2s_queue_type, LServer},
|
||||||
undefined -> ejabberd_config:default_queue_type(LServer);
|
ejabberd_config:default_queue_type(LServer)).
|
||||||
Type -> Type
|
|
||||||
end.
|
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -543,9 +519,7 @@ needed_connections_number(Ls, MaxS2SConnectionsNumber,
|
||||||
-spec is_service(jid(), jid()) -> boolean().
|
-spec is_service(jid(), jid()) -> boolean().
|
||||||
is_service(From, To) ->
|
is_service(From, To) ->
|
||||||
LFromDomain = From#jid.lserver,
|
LFromDomain = From#jid.lserver,
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({route_subdomains, LFromDomain}, local) of
|
||||||
{route_subdomains, LFromDomain},
|
|
||||||
fun(s2s) -> s2s; (local) -> local end, local) of
|
|
||||||
s2s -> % bypass RFC 3920 10.3
|
s2s -> % bypass RFC 3920 10.3
|
||||||
false;
|
false;
|
||||||
local ->
|
local ->
|
||||||
|
@ -645,10 +619,7 @@ allow_host(MyServer, S2SHost) ->
|
||||||
not is_temporarly_blocked(S2SHost).
|
not is_temporarly_blocked(S2SHost).
|
||||||
|
|
||||||
allow_host1(MyHost, S2SHost) ->
|
allow_host1(MyHost, S2SHost) ->
|
||||||
Rule = ejabberd_config:get_option(
|
Rule = ejabberd_config:get_option({s2s_access, MyHost}, all),
|
||||||
{s2s_access, MyHost},
|
|
||||||
fun acl:access_rules_validator/1,
|
|
||||||
all),
|
|
||||||
JID = jid:make(S2SHost),
|
JID = jid:make(S2SHost),
|
||||||
case acl:match_rule(MyHost, Rule, JID) of
|
case acl:match_rule(MyHost, Rule, JID) of
|
||||||
deny -> false;
|
deny -> false;
|
||||||
|
@ -724,7 +695,6 @@ opt_type(route_subdomains) ->
|
||||||
end;
|
end;
|
||||||
opt_type(s2s_access) ->
|
opt_type(s2s_access) ->
|
||||||
fun acl:access_rules_validator/1;
|
fun acl:access_rules_validator/1;
|
||||||
opt_type(domain_certfile) -> fun iolist_to_binary/1;
|
|
||||||
opt_type(s2s_certfile) -> fun iolist_to_binary/1;
|
opt_type(s2s_certfile) -> fun iolist_to_binary/1;
|
||||||
opt_type(s2s_ciphers) -> fun iolist_to_binary/1;
|
opt_type(s2s_ciphers) -> fun iolist_to_binary/1;
|
||||||
opt_type(s2s_dhfile) -> fun iolist_to_binary/1;
|
opt_type(s2s_dhfile) -> fun iolist_to_binary/1;
|
||||||
|
@ -742,13 +712,16 @@ opt_type(s2s_use_starttls) ->
|
||||||
(required) -> required;
|
(required) -> required;
|
||||||
(required_trusted) -> required_trusted
|
(required_trusted) -> required_trusted
|
||||||
end;
|
end;
|
||||||
|
opt_type(s2s_zlib) ->
|
||||||
|
fun(B) when is_boolean(B) -> B end;
|
||||||
opt_type(s2s_timeout) ->
|
opt_type(s2s_timeout) ->
|
||||||
fun(I) when is_integer(I), I>=0 -> I;
|
fun(I) when is_integer(I), I >= 0 -> timer:seconds(I);
|
||||||
(infinity) -> infinity
|
(infinity) -> infinity;
|
||||||
|
(unlimited) -> infinity
|
||||||
end;
|
end;
|
||||||
opt_type(s2s_queue_type) ->
|
opt_type(s2s_queue_type) ->
|
||||||
fun(ram) -> ram; (file) -> file end;
|
fun(ram) -> ram; (file) -> file end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[route_subdomains, s2s_access, s2s_certfile,
|
[route_subdomains, s2s_access, s2s_certfile, s2s_zlib,
|
||||||
s2s_ciphers, s2s_dhfile, s2s_cafile, s2s_protocol_options,
|
s2s_ciphers, s2s_dhfile, s2s_cafile, s2s_protocol_options,
|
||||||
s2s_tls_compression, s2s_use_starttls, s2s_timeout, s2s_queue_type].
|
s2s_tls_compression, s2s_use_starttls, s2s_timeout, s2s_queue_type].
|
||||||
|
|
|
@ -191,42 +191,21 @@ tls_enabled(#{server := LServer}) ->
|
||||||
connect_timeout(#{server := LServer}) ->
|
connect_timeout(#{server := LServer}) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{outgoing_s2s_timeout, LServer},
|
{outgoing_s2s_timeout, LServer},
|
||||||
fun(TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
|
timer:seconds(10)).
|
||||||
timer:seconds(TimeOut);
|
|
||||||
(infinity) ->
|
|
||||||
infinity
|
|
||||||
end, timer:seconds(10)).
|
|
||||||
|
|
||||||
default_port(#{server := LServer}) ->
|
default_port(#{server := LServer}) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({outgoing_s2s_port, LServer}, 5269).
|
||||||
{outgoing_s2s_port, LServer},
|
|
||||||
fun(I) when is_integer(I), I > 0, I =< 65536 -> I end,
|
|
||||||
5269).
|
|
||||||
|
|
||||||
address_families(#{server := LServer}) ->
|
address_families(#{server := LServer}) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{outgoing_s2s_families, LServer},
|
{outgoing_s2s_families, LServer},
|
||||||
fun(Families) ->
|
[inet, inet6]).
|
||||||
lists:map(
|
|
||||||
fun(ipv4) -> inet;
|
|
||||||
(ipv6) -> inet6
|
|
||||||
end, Families)
|
|
||||||
end, [inet, inet6]).
|
|
||||||
|
|
||||||
dns_retries(#{server := LServer}) ->
|
dns_retries(#{server := LServer}) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({s2s_dns_retries, LServer}, 2).
|
||||||
{s2s_dns_retries, LServer},
|
|
||||||
fun(I) when is_integer(I), I>=0 -> I end,
|
|
||||||
2).
|
|
||||||
|
|
||||||
dns_timeout(#{server := LServer}) ->
|
dns_timeout(#{server := LServer}) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({s2s_dns_timeout, LServer}, timer:seconds(10)).
|
||||||
{s2s_dns_timeout, LServer},
|
|
||||||
fun(I) when is_integer(I), I>=0 ->
|
|
||||||
timer:seconds(I);
|
|
||||||
(infinity) ->
|
|
||||||
infinity
|
|
||||||
end, timer:seconds(10)).
|
|
||||||
|
|
||||||
handle_auth_success(Mech, #{sockmod := SockMod,
|
handle_auth_success(Mech, #{sockmod := SockMod,
|
||||||
socket := Socket, ip := IP,
|
socket := Socket, ip := IP,
|
||||||
|
@ -391,10 +370,7 @@ mk_bounce_error(_Lang, _State) ->
|
||||||
|
|
||||||
-spec get_delay() -> non_neg_integer().
|
-spec get_delay() -> non_neg_integer().
|
||||||
get_delay() ->
|
get_delay() ->
|
||||||
MaxDelay = ejabberd_config:get_option(
|
MaxDelay = ejabberd_config:get_option(s2s_max_retry_delay, 300),
|
||||||
s2s_max_retry_delay,
|
|
||||||
fun(I) when is_integer(I), I > 0 -> I end,
|
|
||||||
300),
|
|
||||||
crypto:rand_uniform(1, MaxDelay).
|
crypto:rand_uniform(1, MaxDelay).
|
||||||
|
|
||||||
-spec set_idle_timeout(state()) -> state().
|
-spec set_idle_timeout(state()) -> state().
|
||||||
|
@ -464,26 +440,28 @@ maybe_report_huge_timeout(_, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
opt_type(outgoing_s2s_families) ->
|
opt_type(outgoing_s2s_families) ->
|
||||||
fun (Families) ->
|
fun(Families) ->
|
||||||
true = lists:all(fun (ipv4) -> true;
|
lists:map(
|
||||||
(ipv6) -> true
|
fun(ipv4) -> inet;
|
||||||
end,
|
(ipv6) -> inet6
|
||||||
Families),
|
end, Families)
|
||||||
Families
|
|
||||||
end;
|
end;
|
||||||
opt_type(outgoing_s2s_port) ->
|
opt_type(outgoing_s2s_port) ->
|
||||||
fun (I) when is_integer(I), I > 0, I =< 65536 -> I end;
|
fun (I) when is_integer(I), I > 0, I =< 65536 -> I end;
|
||||||
opt_type(outgoing_s2s_timeout) ->
|
opt_type(outgoing_s2s_timeout) ->
|
||||||
fun (TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
|
fun(TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
|
||||||
TimeOut;
|
timer:seconds(TimeOut);
|
||||||
(infinity) -> infinity
|
(unlimited) ->
|
||||||
|
infinity;
|
||||||
|
(infinity) ->
|
||||||
|
infinity
|
||||||
end;
|
end;
|
||||||
opt_type(s2s_dns_retries) ->
|
opt_type(s2s_dns_retries) ->
|
||||||
fun (I) when is_integer(I), I >= 0 -> I end;
|
fun (I) when is_integer(I), I >= 0 -> I end;
|
||||||
opt_type(s2s_dns_timeout) ->
|
opt_type(s2s_dns_timeout) ->
|
||||||
fun (TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
|
fun(I) when is_integer(I), I>=0 -> timer:seconds(I);
|
||||||
TimeOut;
|
(infinity) -> infinity;
|
||||||
(infinity) -> infinity
|
(unlimited) -> infinity
|
||||||
end;
|
end;
|
||||||
opt_type(s2s_max_retry_delay) ->
|
opt_type(s2s_max_retry_delay) ->
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
fun (I) when is_integer(I), I > 0 -> I end;
|
||||||
|
|
|
@ -865,14 +865,9 @@ force_update_presence({LUser, LServer}) ->
|
||||||
-spec get_sm_backend(binary()) -> module().
|
-spec get_sm_backend(binary()) -> module().
|
||||||
|
|
||||||
get_sm_backend(Host) ->
|
get_sm_backend(Host) ->
|
||||||
DBType = case ejabberd_config:get_option(
|
DBType = ejabberd_config:get_option(
|
||||||
{sm_db_type, Host},
|
{sm_db_type, Host},
|
||||||
fun(T) -> ejabberd_config:v_db(?MODULE, T) end) of
|
ejabberd_config:default_ram_db(Host, ?MODULE)),
|
||||||
undefined ->
|
|
||||||
ejabberd_config:default_ram_db(Host, ?MODULE);
|
|
||||||
T ->
|
|
||||||
T
|
|
||||||
end,
|
|
||||||
list_to_atom("ejabberd_sm_" ++ atom_to_list(DBType)).
|
list_to_atom("ejabberd_sm_" ++ atom_to_list(DBType)).
|
||||||
|
|
||||||
-spec get_sm_backends() -> [module()].
|
-spec get_sm_backends() -> [module()].
|
||||||
|
@ -904,15 +899,12 @@ init_cache() ->
|
||||||
cache_opts() ->
|
cache_opts() ->
|
||||||
MaxSize = ejabberd_config:get_option(
|
MaxSize = ejabberd_config:get_option(
|
||||||
sm_cache_size,
|
sm_cache_size,
|
||||||
opt_type(sm_cache_size),
|
|
||||||
ejabberd_config:cache_size(global)),
|
ejabberd_config:cache_size(global)),
|
||||||
CacheMissed = ejabberd_config:get_option(
|
CacheMissed = ejabberd_config:get_option(
|
||||||
sm_cache_missed,
|
sm_cache_missed,
|
||||||
opt_type(sm_cache_missed),
|
|
||||||
ejabberd_config:cache_missed(global)),
|
ejabberd_config:cache_missed(global)),
|
||||||
LifeTime = case ejabberd_config:get_option(
|
LifeTime = case ejabberd_config:get_option(
|
||||||
sm_cache_life_time,
|
sm_cache_life_time,
|
||||||
opt_type(sm_cache_life_time),
|
|
||||||
ejabberd_config:cache_life_time(global)) of
|
ejabberd_config:cache_life_time(global)) of
|
||||||
infinity -> infinity;
|
infinity -> infinity;
|
||||||
I -> timer:seconds(I)
|
I -> timer:seconds(I)
|
||||||
|
@ -943,7 +935,6 @@ use_cache(Mod, LServer) ->
|
||||||
false ->
|
false ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{sm_use_cache, LServer},
|
{sm_use_cache, LServer},
|
||||||
ejabberd_sm:opt_type(sm_use_cache),
|
|
||||||
ejabberd_config:use_cache(LServer))
|
ejabberd_config:use_cache(LServer))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,12 @@
|
||||||
-define(GEN_SERVER, p1_server).
|
-define(GEN_SERVER, p1_server).
|
||||||
-endif.
|
-endif.
|
||||||
-behaviour(?GEN_SERVER).
|
-behaviour(?GEN_SERVER).
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-behaviour(ejabberd_sm).
|
-behaviour(ejabberd_sm).
|
||||||
|
|
||||||
-export([init/0, set_session/1, delete_session/1,
|
-export([init/0, set_session/1, delete_session/1,
|
||||||
get_sessions/0, get_sessions/1, get_sessions/2,
|
get_sessions/0, get_sessions/1, get_sessions/2,
|
||||||
cache_nodes/1, opt_type/1]).
|
cache_nodes/1]).
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
-export([init/1, handle_cast/2, handle_call/3, handle_info/2,
|
||||||
terminate/2, code_change/3, start_link/0]).
|
terminate/2, code_change/3, start_link/0]).
|
||||||
|
@ -169,9 +168,6 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
iolist_to_list(IOList) ->
|
|
||||||
binary_to_list(iolist_to_binary(IOList)).
|
|
||||||
|
|
||||||
us_to_key({LUser, LServer}) ->
|
us_to_key({LUser, LServer}) ->
|
||||||
<<"ejabberd:sm:", LUser/binary, "@", LServer/binary>>.
|
<<"ejabberd:sm:", LUser/binary, "@", LServer/binary>>.
|
||||||
|
|
||||||
|
@ -214,17 +210,3 @@ clean_table() ->
|
||||||
catch _:{badmatch, {error, _}} ->
|
catch _:{badmatch, {error, _}} ->
|
||||||
?ERROR_MSG("failed to clean redis c2s sessions", [])
|
?ERROR_MSG("failed to clean redis c2s sessions", [])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
opt_type(redis_connect_timeout) ->
|
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
|
||||||
opt_type(redis_db) ->
|
|
||||||
fun (I) when is_integer(I), I >= 0 -> I end;
|
|
||||||
opt_type(redis_password) -> fun iolist_to_list/1;
|
|
||||||
opt_type(redis_port) ->
|
|
||||||
fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
|
|
||||||
opt_type(redis_reconnect_timeout) ->
|
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
|
||||||
opt_type(redis_server) -> fun iolist_to_list/1;
|
|
||||||
opt_type(_) ->
|
|
||||||
[redis_connect_timeout, redis_db, redis_password,
|
|
||||||
redis_port, redis_reconnect_timeout, redis_server].
|
|
||||||
|
|
|
@ -252,8 +252,7 @@ sqlite_db(Host) ->
|
||||||
|
|
||||||
-spec sqlite_file(binary()) -> string().
|
-spec sqlite_file(binary()) -> string().
|
||||||
sqlite_file(Host) ->
|
sqlite_file(Host) ->
|
||||||
case ejabberd_config:get_option({sql_database, Host},
|
case ejabberd_config:get_option({sql_database, Host}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined ->
|
undefined ->
|
||||||
{ok, Cwd} = file:get_cwd(),
|
{ok, Cwd} = file:get_cwd(),
|
||||||
filename:join([Cwd, "sqlite", atom_to_list(node()),
|
filename:join([Cwd, "sqlite", atom_to_list(node()),
|
||||||
|
@ -266,9 +265,7 @@ sqlite_file(Host) ->
|
||||||
%%% Callback functions from gen_fsm
|
%%% Callback functions from gen_fsm
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
init([Host, StartInterval]) ->
|
init([Host, StartInterval]) ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option({sql_keepalive_interval, Host}) of
|
||||||
{sql_keepalive_interval, Host},
|
|
||||||
fun(I) when is_integer(I), I>0 -> I end) of
|
|
||||||
undefined ->
|
undefined ->
|
||||||
ok;
|
ok;
|
||||||
KeepaliveInterval ->
|
KeepaliveInterval ->
|
||||||
|
@ -278,8 +275,7 @@ init([Host, StartInterval]) ->
|
||||||
[DBType | _] = db_opts(Host),
|
[DBType | _] = db_opts(Host),
|
||||||
(?GEN_FSM):send_event(self(), connect),
|
(?GEN_FSM):send_event(self(), connect),
|
||||||
ejabberd_sql_sup:add_pid(Host, self()),
|
ejabberd_sql_sup:add_pid(Host, self()),
|
||||||
QueueType = case ejabberd_config:get_option(
|
QueueType = case ejabberd_config:get_option({sql_queue_type, Host}) of
|
||||||
{sql_queue_type, Host}, opt_type(sql_queue_type)) of
|
|
||||||
undefined ->
|
undefined ->
|
||||||
ejabberd_config:default_queue_type(Host);
|
ejabberd_config:default_queue_type(Host);
|
||||||
Type ->
|
Type ->
|
||||||
|
@ -927,20 +923,9 @@ log(Level, Format, Args) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
db_opts(Host) ->
|
db_opts(Host) ->
|
||||||
Type = ejabberd_config:get_option({sql_type, Host},
|
Type = ejabberd_config:get_option({sql_type, Host}, odbc),
|
||||||
fun(mysql) -> mysql;
|
Server = ejabberd_config:get_option({sql_server, Host}, <<"localhost">>),
|
||||||
(pgsql) -> pgsql;
|
Transport = case ejabberd_config:get_option({sql_ssl, Host}, false) of
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end, odbc),
|
|
||||||
Server = ejabberd_config:get_option({sql_server, Host},
|
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"localhost">>),
|
|
||||||
Transport = case ejabberd_config:get_option(
|
|
||||||
{sql_ssl, Host},
|
|
||||||
fun(B) when is_boolean(B) -> B end,
|
|
||||||
false) of
|
|
||||||
false -> tcp;
|
false -> tcp;
|
||||||
true -> ssl
|
true -> ssl
|
||||||
end,
|
end,
|
||||||
|
@ -953,20 +938,16 @@ db_opts(Host) ->
|
||||||
_ ->
|
_ ->
|
||||||
Port = ejabberd_config:get_option(
|
Port = ejabberd_config:get_option(
|
||||||
{sql_port, Host},
|
{sql_port, Host},
|
||||||
fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
|
|
||||||
case Type of
|
case Type of
|
||||||
mssql -> ?MSSQL_PORT;
|
mssql -> ?MSSQL_PORT;
|
||||||
mysql -> ?MYSQL_PORT;
|
mysql -> ?MYSQL_PORT;
|
||||||
pgsql -> ?PGSQL_PORT
|
pgsql -> ?PGSQL_PORT
|
||||||
end),
|
end),
|
||||||
DB = ejabberd_config:get_option({sql_database, Host},
|
DB = ejabberd_config:get_option({sql_database, Host},
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"ejabberd">>),
|
<<"ejabberd">>),
|
||||||
User = ejabberd_config:get_option({sql_username, Host},
|
User = ejabberd_config:get_option({sql_username, Host},
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"ejabberd">>),
|
<<"ejabberd">>),
|
||||||
Pass = ejabberd_config:get_option({sql_password, Host},
|
Pass = ejabberd_config:get_option({sql_password, Host},
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"">>),
|
<<"">>),
|
||||||
SSLOpts = get_ssl_opts(Transport, Host),
|
SSLOpts = get_ssl_opts(Transport, Host),
|
||||||
case Type of
|
case Type of
|
||||||
|
@ -986,19 +967,15 @@ warn_if_ssl_unsupported(ssl, Type) ->
|
||||||
?WARNING_MSG("SSL connection is not supported for ~s", [Type]).
|
?WARNING_MSG("SSL connection is not supported for ~s", [Type]).
|
||||||
|
|
||||||
get_ssl_opts(ssl, Host) ->
|
get_ssl_opts(ssl, Host) ->
|
||||||
Opts1 = case ejabberd_config:get_option({sql_ssl_certfile, Host},
|
Opts1 = case ejabberd_config:get_option({sql_ssl_certfile, Host}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> [];
|
undefined -> [];
|
||||||
CertFile -> [{certfile, CertFile}]
|
CertFile -> [{certfile, CertFile}]
|
||||||
end,
|
end,
|
||||||
Opts2 = case ejabberd_config:get_option({sql_ssl_cafile, Host},
|
Opts2 = case ejabberd_config:get_option({sql_ssl_cafile, Host}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
undefined -> Opts1;
|
undefined -> Opts1;
|
||||||
CAFile -> [{cacertfile, CAFile}|Opts1]
|
CAFile -> [{cacertfile, CAFile}|Opts1]
|
||||||
end,
|
end,
|
||||||
case ejabberd_config:get_option({sql_ssl_verify, Host},
|
case ejabberd_config:get_option({sql_ssl_verify, Host}, false) of
|
||||||
fun(B) when is_boolean(B) -> B end,
|
|
||||||
false) of
|
|
||||||
true ->
|
true ->
|
||||||
case lists:keymember(cacertfile, 1, Opts2) of
|
case lists:keymember(cacertfile, 1, Opts2) of
|
||||||
true ->
|
true ->
|
||||||
|
@ -1017,16 +994,9 @@ get_ssl_opts(tcp, _) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_mssql(Host) ->
|
init_mssql(Host) ->
|
||||||
Server = ejabberd_config:get_option({sql_server, Host},
|
Server = ejabberd_config:get_option({sql_server, Host}, <<"localhost">>),
|
||||||
fun iolist_to_binary/1,
|
Port = ejabberd_config:get_option({sql_port, Host}, ?MSSQL_PORT),
|
||||||
<<"localhost">>),
|
DB = ejabberd_config:get_option({sql_database, Host}, <<"ejabberd">>),
|
||||||
Port = ejabberd_config:get_option(
|
|
||||||
{sql_port, Host},
|
|
||||||
fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
|
|
||||||
?MSSQL_PORT),
|
|
||||||
DB = ejabberd_config:get_option({sql_database, Host},
|
|
||||||
fun iolist_to_binary/1,
|
|
||||||
<<"ejabberd">>),
|
|
||||||
FreeTDS = io_lib:fwrite("[~s]~n"
|
FreeTDS = io_lib:fwrite("[~s]~n"
|
||||||
"\thost = ~s~n"
|
"\thost = ~s~n"
|
||||||
"\tport = ~p~n"
|
"\tport = ~p~n"
|
||||||
|
@ -1109,13 +1079,6 @@ opt_type(sql_password) -> fun iolist_to_binary/1;
|
||||||
opt_type(sql_port) ->
|
opt_type(sql_port) ->
|
||||||
fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
|
fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
|
||||||
opt_type(sql_server) -> fun iolist_to_binary/1;
|
opt_type(sql_server) -> fun iolist_to_binary/1;
|
||||||
opt_type(sql_type) ->
|
|
||||||
fun (mysql) -> mysql;
|
|
||||||
(pgsql) -> pgsql;
|
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end;
|
|
||||||
opt_type(sql_username) -> fun iolist_to_binary/1;
|
opt_type(sql_username) -> fun iolist_to_binary/1;
|
||||||
opt_type(sql_ssl) -> fun(B) when is_boolean(B) -> B end;
|
opt_type(sql_ssl) -> fun(B) when is_boolean(B) -> B end;
|
||||||
opt_type(sql_ssl_verify) -> fun(B) when is_boolean(B) -> B end;
|
opt_type(sql_ssl_verify) -> fun(B) when is_boolean(B) -> B end;
|
||||||
|
@ -1125,6 +1088,6 @@ opt_type(sql_queue_type) ->
|
||||||
fun(ram) -> ram; (file) -> file end;
|
fun(ram) -> ram; (file) -> file end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[sql_database, sql_keepalive_interval,
|
[sql_database, sql_keepalive_interval,
|
||||||
sql_password, sql_port, sql_server, sql_type,
|
sql_password, sql_port, sql_server,
|
||||||
sql_username, sql_ssl, sql_ssl_verify, sql_ssl_cerfile,
|
sql_username, sql_ssl, sql_ssl_verify, sql_ssl_cerfile,
|
||||||
sql_ssl_cafile, sql_queue_type].
|
sql_ssl_cafile, sql_queue_type].
|
||||||
|
|
|
@ -62,15 +62,8 @@ start_link(Host) ->
|
||||||
init([Host]) ->
|
init([Host]) ->
|
||||||
StartInterval = ejabberd_config:get_option(
|
StartInterval = ejabberd_config:get_option(
|
||||||
{sql_start_interval, Host},
|
{sql_start_interval, Host},
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
|
||||||
?DEFAULT_SQL_START_INTERVAL),
|
?DEFAULT_SQL_START_INTERVAL),
|
||||||
Type = ejabberd_config:get_option({sql_type, Host},
|
Type = ejabberd_config:get_option({sql_type, Host}, odbc),
|
||||||
fun(mysql) -> mysql;
|
|
||||||
(pgsql) -> pgsql;
|
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end, odbc),
|
|
||||||
PoolSize = get_pool_size(Type, Host),
|
PoolSize = get_pool_size(Type, Host),
|
||||||
case Type of
|
case Type of
|
||||||
sqlite ->
|
sqlite ->
|
||||||
|
@ -119,7 +112,6 @@ remove_pid(Host, Pid) ->
|
||||||
get_pool_size(SQLType, Host) ->
|
get_pool_size(SQLType, Host) ->
|
||||||
PoolSize = ejabberd_config:get_option(
|
PoolSize = ejabberd_config:get_option(
|
||||||
{sql_pool_size, Host},
|
{sql_pool_size, Host},
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
|
||||||
case SQLType of
|
case SQLType of
|
||||||
sqlite -> 1;
|
sqlite -> 1;
|
||||||
_ -> ?DEFAULT_POOL_SIZE
|
_ -> ?DEFAULT_POOL_SIZE
|
||||||
|
@ -230,12 +222,5 @@ opt_type(sql_pool_size) ->
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
fun (I) when is_integer(I), I > 0 -> I end;
|
||||||
opt_type(sql_start_interval) ->
|
opt_type(sql_start_interval) ->
|
||||||
fun (I) when is_integer(I), I > 0 -> I end;
|
fun (I) when is_integer(I), I > 0 -> I end;
|
||||||
opt_type(sql_type) ->
|
|
||||||
fun (mysql) -> mysql;
|
|
||||||
(pgsql) -> pgsql;
|
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end;
|
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[sql_pool_size, sql_start_interval, sql_type].
|
[sql_pool_size, sql_start_interval].
|
||||||
|
|
|
@ -53,10 +53,7 @@
|
||||||
%% Description: Starts the server
|
%% Description: Starts the server
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
start_link() ->
|
start_link() ->
|
||||||
LH = ejabberd_config:get_option(
|
LH = ejabberd_config:get_option(watchdog_large_heap, 1000000),
|
||||||
watchdog_large_heap,
|
|
||||||
fun(I) when is_integer(I), I > 0 -> I end,
|
|
||||||
1000000),
|
|
||||||
Opts = [{large_heap, LH}],
|
Opts = [{large_heap, LH}],
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, Opts,
|
gen_server:start_link({local, ?MODULE}, ?MODULE, Opts,
|
||||||
[]).
|
[]).
|
||||||
|
@ -205,13 +202,7 @@ send_message(From, To, Body, ExtraEls) ->
|
||||||
sub_els = ExtraEls}).
|
sub_els = ExtraEls}).
|
||||||
|
|
||||||
get_admin_jids() ->
|
get_admin_jids() ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(watchdog_admins, []).
|
||||||
watchdog_admins,
|
|
||||||
fun(JIDs) ->
|
|
||||||
[jid:tolower(
|
|
||||||
jid:decode(
|
|
||||||
iolist_to_binary(S))) || S <- JIDs]
|
|
||||||
end, []).
|
|
||||||
|
|
||||||
detailed_info(Pid) ->
|
detailed_info(Pid) ->
|
||||||
case process_info(Pid, dictionary) of
|
case process_info(Pid, dictionary) of
|
||||||
|
|
|
@ -920,12 +920,7 @@ process_admin(Host,
|
||||||
end;
|
end;
|
||||||
_ -> nothing
|
_ -> nothing
|
||||||
end,
|
end,
|
||||||
Rules = case ejabberd_config:get_option(
|
Rules = ejabberd_config:get_option({access, Name, Host}, []),
|
||||||
{access, Name, Host}, fun(V) -> V end)
|
|
||||||
of
|
|
||||||
undefined -> [];
|
|
||||||
Rs1 -> Rs1
|
|
||||||
end,
|
|
||||||
make_xhtml([?XC(<<"h1">>,
|
make_xhtml([?XC(<<"h1">>,
|
||||||
(str:format(
|
(str:format(
|
||||||
?T(<<"~s access rule configuration">>),
|
?T(<<"~s access rule configuration">>),
|
||||||
|
@ -2980,8 +2975,7 @@ make_menu_item(item, 3, URI, Name, Lang) ->
|
||||||
%%%==================================
|
%%%==================================
|
||||||
|
|
||||||
|
|
||||||
opt_type(access) -> fun acl:access_rules_validator/1;
|
|
||||||
opt_type(access_readonly) -> fun acl:access_rules_validator/1;
|
opt_type(access_readonly) -> fun acl:access_rules_validator/1;
|
||||||
opt_type(_) -> [access, access_readonly].
|
opt_type(_) -> [access_readonly].
|
||||||
|
|
||||||
%%% vim: set foldmethod=marker foldmarker=%%%%,%%%=:
|
%%% vim: set foldmethod=marker foldmarker=%%%%,%%%=:
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
-behaviour(ejabberd_config).
|
-behaviour(ejabberd_config).
|
||||||
-author('mremond@process-one.net').
|
-author('mremond@process-one.net').
|
||||||
|
|
||||||
-export([generate_subfilter/1, find_ldap_attrs/2,
|
-export([generate_subfilter/1, find_ldap_attrs/2, check_filter/1,
|
||||||
get_ldap_attr/2, get_user_part/2, make_filter/2,
|
get_ldap_attr/2, get_user_part/2, make_filter/2,
|
||||||
get_state/2, case_insensitive_match/2, get_config/2,
|
get_state/2, case_insensitive_match/2, get_config/2,
|
||||||
decode_octet_string/3, uids_domain_subst/2, opt_type/1]).
|
decode_octet_string/3, uids_domain_subst/2, opt_type/1]).
|
||||||
|
@ -137,6 +137,11 @@ make_filter(Data, UIDs) ->
|
||||||
eldap:'and'(Filter)
|
eldap:'and'(Filter)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
check_filter(F) ->
|
||||||
|
NewF = iolist_to_binary(F),
|
||||||
|
{ok, _} = eldap_filter:parse(NewF),
|
||||||
|
NewF.
|
||||||
|
|
||||||
-spec case_insensitive_match(binary(), binary()) -> boolean().
|
-spec case_insensitive_match(binary(), binary()) -> boolean().
|
||||||
|
|
||||||
case_insensitive_match(X, Y) ->
|
case_insensitive_match(X, Y) ->
|
||||||
|
@ -380,8 +385,19 @@ opt_type(ldap_tls_verify) ->
|
||||||
(soft) -> soft;
|
(soft) -> soft;
|
||||||
(false) -> false
|
(false) -> false
|
||||||
end;
|
end;
|
||||||
|
opt_type(ldap_filter) ->
|
||||||
|
fun check_filter/1;
|
||||||
|
opt_type(ldap_uids) ->
|
||||||
|
fun (Us) ->
|
||||||
|
lists:map(fun ({U, P}) ->
|
||||||
|
{iolist_to_binary(U), iolist_to_binary(P)};
|
||||||
|
({U}) -> {iolist_to_binary(U)};
|
||||||
|
(U) -> {iolist_to_binary(U)}
|
||||||
|
end,
|
||||||
|
lists:flatten(Us))
|
||||||
|
end;
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[deref_aliases, ldap_backups, ldap_base,
|
[deref_aliases, ldap_backups, ldap_base, ldap_uids,
|
||||||
ldap_deref_aliases, ldap_encrypt, ldap_password,
|
ldap_deref_aliases, ldap_encrypt, ldap_password,
|
||||||
ldap_port, ldap_rootdn, ldap_servers,
|
ldap_port, ldap_rootdn, ldap_servers, ldap_filter,
|
||||||
ldap_tls_cacertfile, ldap_tls_depth, ldap_tls_verify].
|
ldap_tls_cacertfile, ldap_tls_depth, ldap_tls_verify].
|
||||||
|
|
|
@ -439,11 +439,7 @@ short_spec({Module, Attrs}) when is_atom(Module), is_list(Attrs) ->
|
||||||
{Module, proplists:get_value(summary, Attrs, "")}.
|
{Module, proplists:get_value(summary, Attrs, "")}.
|
||||||
|
|
||||||
is_contrib_allowed() ->
|
is_contrib_allowed() ->
|
||||||
ejabberd_config:get_option(allow_contrib_modules,
|
ejabberd_config:get_option(allow_contrib_modules, true).
|
||||||
fun(false) -> false;
|
|
||||||
(no) -> false;
|
|
||||||
(_) -> true
|
|
||||||
end, true).
|
|
||||||
|
|
||||||
%% -- build functions
|
%% -- build functions
|
||||||
|
|
||||||
|
|
|
@ -105,11 +105,7 @@ random_instance(MaxNum) ->
|
||||||
randoms:uniform(MaxNum) - 1.
|
randoms:uniform(MaxNum) - 1.
|
||||||
|
|
||||||
get_instances(Server) ->
|
get_instances(Server) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({extauth_instances, Server}, 1).
|
||||||
{extauth_instances, Server},
|
|
||||||
fun(V) when is_integer(V), V > 0 ->
|
|
||||||
V
|
|
||||||
end, 1).
|
|
||||||
|
|
||||||
loop(Port, Timeout, ProcessName, ExtPrg) ->
|
loop(Port, Timeout, ProcessName, ExtPrg) ->
|
||||||
receive
|
receive
|
||||||
|
|
|
@ -119,14 +119,7 @@ start_modules() ->
|
||||||
end, ?MYHOSTS).
|
end, ?MYHOSTS).
|
||||||
|
|
||||||
get_modules_options(Host) ->
|
get_modules_options(Host) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option({modules, Host}, []).
|
||||||
{modules, Host},
|
|
||||||
fun(Mods) ->
|
|
||||||
lists:map(
|
|
||||||
fun({M, A}) when is_atom(M), is_list(A) ->
|
|
||||||
{M, A}
|
|
||||||
end, Mods)
|
|
||||||
end, []).
|
|
||||||
|
|
||||||
sort_modules(Host, ModOpts) ->
|
sort_modules(Host, ModOpts) ->
|
||||||
G = digraph:new([acyclic]),
|
G = digraph:new([acyclic]),
|
||||||
|
@ -211,8 +204,7 @@ start_module(Host, Module, Opts0) ->
|
||||||
|
|
||||||
-spec reload_modules(binary()) -> ok.
|
-spec reload_modules(binary()) -> ok.
|
||||||
reload_modules(Host) ->
|
reload_modules(Host) ->
|
||||||
NewMods = ejabberd_config:get_option(
|
NewMods = ejabberd_config:get_option({modules, Host}, []),
|
||||||
{modules, Host}, opt_type(modules), []),
|
|
||||||
OldMods = ets:select(
|
OldMods = ets:select(
|
||||||
ejabberd_modules,
|
ejabberd_modules,
|
||||||
ets:fun2ms(
|
ets:fun2ms(
|
||||||
|
@ -369,7 +361,7 @@ get_opt(Opt, Opts, F) ->
|
||||||
get_opt({Opt, Host}, Opts, F, Default) ->
|
get_opt({Opt, Host}, Opts, F, Default) ->
|
||||||
case lists:keysearch(Opt, 1, Opts) of
|
case lists:keysearch(Opt, 1, Opts) of
|
||||||
false ->
|
false ->
|
||||||
ejabberd_config:get_option({Opt, Host}, F, Default);
|
ejabberd_config:get_option({Opt, Host}, Default);
|
||||||
{value, {_, Val}} ->
|
{value, {_, Val}} ->
|
||||||
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
|
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
-module(mod_last).
|
-module(mod_last).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-protocol({xep, 12, '2.0'}).
|
-protocol({xep, 12, '2.0'}).
|
||||||
|
@ -36,8 +34,8 @@
|
||||||
-export([start/2, stop/1, reload/3, process_local_iq/1, export/1,
|
-export([start/2, stop/1, reload/3, process_local_iq/1, export/1,
|
||||||
process_sm_iq/1, on_presence_update/4, import_info/0,
|
process_sm_iq/1, on_presence_update/4, import_info/0,
|
||||||
import/5, import_start/2, store_last_info/4, get_last_info/2,
|
import/5, import_start/2, store_last_info/4, get_last_info/2,
|
||||||
remove_user/2, transform_options/1, mod_opt_type/1,
|
remove_user/2, mod_opt_type/1,
|
||||||
opt_type/1, register_user/2, depends/2, privacy_check_packet/4]).
|
register_user/2, depends/2, privacy_check_packet/4]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -121,19 +119,13 @@ process_local_iq(#iq{type = get} = IQ) ->
|
||||||
%% @doc Get the uptime of the ejabberd node, expressed in seconds.
|
%% @doc Get the uptime of the ejabberd node, expressed in seconds.
|
||||||
%% When ejabberd is starting, ejabberd_config:start/0 stores the datetime.
|
%% When ejabberd is starting, ejabberd_config:start/0 stores the datetime.
|
||||||
get_node_uptime() ->
|
get_node_uptime() ->
|
||||||
case ejabberd_config:get_option(
|
case ejabberd_config:get_option(node_start) of
|
||||||
node_start,
|
|
||||||
fun(S) when is_integer(S), S >= 0 -> S end) of
|
|
||||||
undefined ->
|
undefined ->
|
||||||
trunc(element(1, erlang:statistics(wall_clock)) / 1000);
|
trunc(element(1, erlang:statistics(wall_clock)) / 1000);
|
||||||
Now ->
|
Now ->
|
||||||
p1_time_compat:system_time(seconds) - Now
|
p1_time_compat:system_time(seconds) - Now
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec now_to_seconds(erlang:timestamp()) -> non_neg_integer().
|
|
||||||
now_to_seconds({MegaSecs, Secs, _MicroSecs}) ->
|
|
||||||
MegaSecs * 1000000 + Secs.
|
|
||||||
|
|
||||||
%%%
|
%%%
|
||||||
%%% Serve queries about user last online
|
%%% Serve queries about user last online
|
||||||
%%%
|
%%%
|
||||||
|
@ -273,23 +265,9 @@ export(LServer) ->
|
||||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||||
Mod:export(LServer).
|
Mod:export(LServer).
|
||||||
|
|
||||||
transform_options(Opts) ->
|
|
||||||
lists:foldl(fun transform_options/2, [], Opts).
|
|
||||||
|
|
||||||
transform_options({node_start, {_, _, _} = Now}, Opts) ->
|
|
||||||
?WARNING_MSG("Old 'node_start' format detected. This is still supported "
|
|
||||||
"but it is better to fix your config.", []),
|
|
||||||
[{node_start, now_to_seconds(Now)}|Opts];
|
|
||||||
transform_options(Opt, Opts) ->
|
|
||||||
[Opt|Opts].
|
|
||||||
|
|
||||||
depends(_Host, _Opts) ->
|
depends(_Host, _Opts) ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
|
mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end;
|
||||||
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
||||||
mod_opt_type(_) -> [db_type, iqdisc].
|
mod_opt_type(_) -> [db_type, iqdisc].
|
||||||
|
|
||||||
opt_type(node_start) ->
|
|
||||||
fun (S) when is_integer(S), S >= 0 -> S end;
|
|
||||||
opt_type(_) -> [node_start].
|
|
||||||
|
|
|
@ -200,9 +200,7 @@ make_sql_query(User, LServer, MAMQuery, RSM) ->
|
||||||
With = proplists:get_value(with, MAMQuery),
|
With = proplists:get_value(with, MAMQuery),
|
||||||
WithText = proplists:get_value(withtext, MAMQuery),
|
WithText = proplists:get_value(withtext, MAMQuery),
|
||||||
{Max, Direction, ID} = get_max_direction_id(RSM),
|
{Max, Direction, ID} = get_max_direction_id(RSM),
|
||||||
ODBCType = ejabberd_config:get_option(
|
ODBCType = ejabberd_config:get_option({sql_type, LServer}),
|
||||||
{sql_type, LServer},
|
|
||||||
ejabberd_sql:opt_type(sql_type)),
|
|
||||||
Escape =
|
Escape =
|
||||||
case ODBCType of
|
case ODBCType of
|
||||||
mssql -> fun ejabberd_sql:standard_escape/1;
|
mssql -> fun ejabberd_sql:standard_escape/1;
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
-protocol({xep, 334, '0.2'}).
|
-protocol({xep, 334, '0.2'}).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-author('badlop@process-one.net').
|
-author('badlop@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
@ -41,7 +39,7 @@
|
||||||
|
|
||||||
-export([init/1, handle_call/3, handle_cast/2,
|
-export([init/1, handle_call/3, handle_cast/2,
|
||||||
handle_info/2, terminate/2, code_change/3,
|
handle_info/2, terminate/2, code_change/3,
|
||||||
mod_opt_type/1, opt_type/1, depends/2]).
|
mod_opt_type/1, depends/2]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -182,10 +180,7 @@ init_state(Host, Opts) ->
|
||||||
NoFollow = gen_mod:get_opt(spam_prevention, Opts,
|
NoFollow = gen_mod:get_opt(spam_prevention, Opts,
|
||||||
fun(B) when is_boolean(B) -> B end,
|
fun(B) when is_boolean(B) -> B end,
|
||||||
true),
|
true),
|
||||||
Lang = ejabberd_config:get_option(
|
Lang = ejabberd_config:get_lang(Host),
|
||||||
{language, Host},
|
|
||||||
fun iolist_to_binary/1,
|
|
||||||
?MYLANG),
|
|
||||||
#logstate{host = Host, out_dir = OutDir,
|
#logstate{host = Host, out_dir = OutDir,
|
||||||
dir_type = DirType, dir_name = DirName,
|
dir_type = DirType, dir_name = DirName,
|
||||||
file_format = FileFormat, css_file = CSSFile,
|
file_format = FileFormat, css_file = CSSFile,
|
||||||
|
@ -1242,6 +1237,3 @@ mod_opt_type(_) ->
|
||||||
[access_log, cssfile, dirname, dirtype, file_format,
|
[access_log, cssfile, dirname, dirtype, file_format,
|
||||||
file_permissions, outdir, spam_prevention, timezone,
|
file_permissions, outdir, spam_prevention, timezone,
|
||||||
top_link].
|
top_link].
|
||||||
|
|
||||||
opt_type(language) -> fun iolist_to_binary/1;
|
|
||||||
opt_type(_) -> [language].
|
|
||||||
|
|
|
@ -435,15 +435,7 @@ check_from(JID, Server) ->
|
||||||
|
|
||||||
check_timeout(undefined) -> true;
|
check_timeout(undefined) -> true;
|
||||||
check_timeout(Source) ->
|
check_timeout(Source) ->
|
||||||
Timeout = ejabberd_config:get_option(
|
Timeout = ejabberd_config:get_option(registration_timeout, 600),
|
||||||
registration_timeout,
|
|
||||||
fun(TO) when is_integer(TO), TO > 0 ->
|
|
||||||
TO;
|
|
||||||
(infinity) ->
|
|
||||||
infinity;
|
|
||||||
(unlimited) ->
|
|
||||||
infinity
|
|
||||||
end, 600),
|
|
||||||
if is_integer(Timeout) ->
|
if is_integer(Timeout) ->
|
||||||
Priority = -p1_time_compat:system_time(seconds),
|
Priority = -p1_time_compat:system_time(seconds),
|
||||||
CleanPriority = Priority + Timeout,
|
CleanPriority = Priority + Timeout,
|
||||||
|
@ -488,15 +480,7 @@ clean_treap(Treap, CleanPriority) ->
|
||||||
|
|
||||||
remove_timeout(undefined) -> true;
|
remove_timeout(undefined) -> true;
|
||||||
remove_timeout(Source) ->
|
remove_timeout(Source) ->
|
||||||
Timeout = ejabberd_config:get_option(
|
Timeout = ejabberd_config:get_option(registration_timeout, 600),
|
||||||
registration_timeout,
|
|
||||||
fun(TO) when is_integer(TO), TO > 0 ->
|
|
||||||
TO;
|
|
||||||
(infinity) ->
|
|
||||||
infinity;
|
|
||||||
(unlimited) ->
|
|
||||||
infinity
|
|
||||||
end, 600),
|
|
||||||
if is_integer(Timeout) ->
|
if is_integer(Timeout) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
Treap = case mnesia:read(mod_register_ip, treap, write)
|
Treap = case mnesia:read(mod_register_ip, treap, write)
|
||||||
|
|
|
@ -265,7 +265,7 @@ s2s_out_packet(State, _) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
-spec make_key(binary(), binary(), binary()) -> binary().
|
-spec make_key(binary(), binary(), binary()) -> binary().
|
||||||
make_key(From, To, StreamID) ->
|
make_key(From, To, StreamID) ->
|
||||||
Secret = ejabberd_config:get_option(shared_key, fun(V) -> V end),
|
Secret = ejabberd_config:get_option(shared_key),
|
||||||
str:to_hexlist(
|
str:to_hexlist(
|
||||||
crypto:hmac(sha256, str:to_hexlist(crypto:hash(sha256, Secret)),
|
crypto:hmac(sha256, str:to_hexlist(crypto:hash(sha256, Secret)),
|
||||||
[To, " ", From, " ", StreamID])).
|
[To, " ", From, " ", StreamID])).
|
||||||
|
|
|
@ -499,13 +499,13 @@ parse_options(Host, Opts) ->
|
||||||
(true) -> true
|
(true) -> true
|
||||||
end, true),
|
end, true),
|
||||||
ConfigFilter = gen_mod:get_opt({ldap_filter, Host}, Opts,
|
ConfigFilter = gen_mod:get_opt({ldap_filter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun eldap_utils:check_filter/1, <<"">>),
|
||||||
ConfigUserFilter = gen_mod:get_opt({ldap_ufilter, Host}, Opts,
|
ConfigUserFilter = gen_mod:get_opt({ldap_ufilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun eldap_utils:check_filter/1, <<"">>),
|
||||||
ConfigGroupFilter = gen_mod:get_opt({ldap_gfilter, Host}, Opts,
|
ConfigGroupFilter = gen_mod:get_opt({ldap_gfilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun eldap_utils:check_filter/1, <<"">>),
|
||||||
RosterFilter = gen_mod:get_opt({ldap_rfilter, Host}, Opts,
|
RosterFilter = gen_mod:get_opt({ldap_rfilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun eldap_utils:check_filter/1, <<"">>),
|
||||||
SubFilter = <<"(&(", UIDAttr/binary, "=",
|
SubFilter = <<"(&(", UIDAttr/binary, "=",
|
||||||
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
|
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
|
||||||
UserSubFilter = case ConfigUserFilter of
|
UserSubFilter = case ConfigUserFilter of
|
||||||
|
@ -552,11 +552,6 @@ parse_options(Host, Opts) ->
|
||||||
ufilter = UserFilter, rfilter = RosterFilter,
|
ufilter = UserFilter, rfilter = RosterFilter,
|
||||||
gfilter = GroupFilter, auth_check = AuthCheck}.
|
gfilter = GroupFilter, auth_check = AuthCheck}.
|
||||||
|
|
||||||
check_filter(F) ->
|
|
||||||
NewF = iolist_to_binary(F),
|
|
||||||
{ok, _} = eldap_filter:parse(NewF),
|
|
||||||
NewF.
|
|
||||||
|
|
||||||
init_cache(Host, Opts) ->
|
init_cache(Host, Opts) ->
|
||||||
UseCache = use_cache(Host, Opts),
|
UseCache = use_cache(Host, Opts),
|
||||||
case UseCache of
|
case UseCache of
|
||||||
|
@ -654,8 +649,8 @@ mod_opt_type(ldap_auth_check) ->
|
||||||
(false) -> false;
|
(false) -> false;
|
||||||
(true) -> true
|
(true) -> true
|
||||||
end;
|
end;
|
||||||
mod_opt_type(ldap_filter) -> fun check_filter/1;
|
mod_opt_type(ldap_filter) -> fun eldap_utils:check_filter/1;
|
||||||
mod_opt_type(ldap_gfilter) -> fun check_filter/1;
|
mod_opt_type(ldap_gfilter) -> fun eldap_utils:check_filter/1;
|
||||||
mod_opt_type(O) when O == cache_size;
|
mod_opt_type(O) when O == cache_size;
|
||||||
O == cache_life_time ->
|
O == cache_life_time ->
|
||||||
fun (I) when is_integer(I), I > 0 -> I;
|
fun (I) when is_integer(I), I > 0 -> I;
|
||||||
|
@ -672,8 +667,8 @@ mod_opt_type(ldap_memberattr_format_re) ->
|
||||||
fun (S) ->
|
fun (S) ->
|
||||||
Re = iolist_to_binary(S), {ok, MP} = re:compile(Re), MP
|
Re = iolist_to_binary(S), {ok, MP} = re:compile(Re), MP
|
||||||
end;
|
end;
|
||||||
mod_opt_type(ldap_rfilter) -> fun check_filter/1;
|
mod_opt_type(ldap_rfilter) -> fun eldap_utils:check_filter/1;
|
||||||
mod_opt_type(ldap_ufilter) -> fun check_filter/1;
|
mod_opt_type(ldap_ufilter) -> fun eldap_utils:check_filter/1;
|
||||||
mod_opt_type(ldap_userdesc) -> fun iolist_to_binary/1;
|
mod_opt_type(ldap_userdesc) -> fun iolist_to_binary/1;
|
||||||
mod_opt_type(ldap_useruid) -> fun iolist_to_binary/1;
|
mod_opt_type(ldap_useruid) -> fun iolist_to_binary/1;
|
||||||
mod_opt_type(_) ->
|
mod_opt_type(_) ->
|
||||||
|
@ -687,9 +682,8 @@ mod_opt_type(_) ->
|
||||||
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
||||||
ldap_tls_verify, use_cache, cache_missed, cache_size, cache_life_time].
|
ldap_tls_verify, use_cache, cache_missed, cache_size, cache_life_time].
|
||||||
|
|
||||||
opt_type(ldap_filter) -> fun check_filter/1;
|
opt_type(ldap_gfilter) -> fun eldap_utils:check_filter/1;
|
||||||
opt_type(ldap_gfilter) -> fun check_filter/1;
|
opt_type(ldap_rfilter) -> fun eldap_utils:check_filter/1;
|
||||||
opt_type(ldap_rfilter) -> fun check_filter/1;
|
opt_type(ldap_ufilter) -> fun eldap_utils:check_filter/1;
|
||||||
opt_type(ldap_ufilter) -> fun check_filter/1;
|
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[ldap_filter, ldap_gfilter, ldap_rfilter, ldap_ufilter].
|
[ldap_gfilter, ldap_rfilter, ldap_ufilter].
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(mod_sip_proxy).
|
-module(mod_sip_proxy).
|
||||||
|
|
||||||
-behaviour(ejabberd_config).
|
|
||||||
|
|
||||||
-define(GEN_FSM, p1_fsm).
|
-define(GEN_FSM, p1_fsm).
|
||||||
-behaviour(?GEN_FSM).
|
-behaviour(?GEN_FSM).
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@
|
||||||
-export([init/1, wait_for_request/2,
|
-export([init/1, wait_for_request/2,
|
||||||
wait_for_response/2, handle_event/3,
|
wait_for_response/2, handle_event/3,
|
||||||
handle_sync_event/4, handle_info/3, terminate/3,
|
handle_sync_event/4, handle_info/3, terminate/3,
|
||||||
code_change/4, opt_type/1]).
|
code_change/4]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
@ -269,8 +267,7 @@ cancel_pending_transactions(State) ->
|
||||||
lists:foreach(fun esip:cancel/1, State#state.tr_ids).
|
lists:foreach(fun esip:cancel/1, State#state.tr_ids).
|
||||||
|
|
||||||
add_certfile(LServer, Opts) ->
|
add_certfile(LServer, Opts) ->
|
||||||
case ejabberd_config:get_option({domain_certfile, LServer},
|
case ejabberd_config:get_option({domain_certfile, LServer}) of
|
||||||
fun iolist_to_binary/1) of
|
|
||||||
CertFile when is_binary(CertFile), CertFile /= <<"">> ->
|
CertFile when is_binary(CertFile), CertFile /= <<"">> ->
|
||||||
[{certfile, CertFile}|Opts];
|
[{certfile, CertFile}|Opts];
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -331,7 +328,7 @@ make_sign(TS, Hdrs) ->
|
||||||
LTServer = safe_nameprep(TServer),
|
LTServer = safe_nameprep(TServer),
|
||||||
FromTag = esip:get_param(<<"tag">>, FParams),
|
FromTag = esip:get_param(<<"tag">>, FParams),
|
||||||
CallID = esip:get_hdr('call-id', Hdrs),
|
CallID = esip:get_hdr('call-id', Hdrs),
|
||||||
SharedKey = ejabberd_config:get_option(shared_key, fun(V) -> V end),
|
SharedKey = ejabberd_config:get_option(shared_key),
|
||||||
str:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
|
str:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
|
||||||
FromTag, CallID, TS]).
|
FromTag, CallID, TS]).
|
||||||
|
|
||||||
|
@ -455,7 +452,3 @@ safe_nameprep(S) ->
|
||||||
error -> S;
|
error -> S;
|
||||||
S1 -> S1
|
S1 -> S1
|
||||||
end.
|
end.
|
||||||
|
|
||||||
opt_type(domain_certfile) -> fun iolist_to_binary/1;
|
|
||||||
opt_type(shared_key) -> fun (V) -> V end;
|
|
||||||
opt_type(_) -> [domain_certfile, shared_key].
|
|
||||||
|
|
|
@ -379,7 +379,7 @@ parse_options(Host, Opts) ->
|
||||||
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
||||||
UserFilter = case gen_mod:get_opt(
|
UserFilter = case gen_mod:get_opt(
|
||||||
{ldap_filter, Host}, Opts,
|
{ldap_filter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>) of
|
fun eldap_utils:check_filter/1, <<"">>) of
|
||||||
<<"">> ->
|
<<"">> ->
|
||||||
SubFilter;
|
SubFilter;
|
||||||
F ->
|
F ->
|
||||||
|
@ -447,12 +447,7 @@ parse_options(Host, Opts) ->
|
||||||
search_reported_attrs = SearchReportedAttrs,
|
search_reported_attrs = SearchReportedAttrs,
|
||||||
matches = Matches}.
|
matches = Matches}.
|
||||||
|
|
||||||
check_filter(F) ->
|
mod_opt_type(ldap_filter) -> fun eldap_utils:check_filter/1;
|
||||||
NewF = iolist_to_binary(F),
|
|
||||||
{ok, _} = eldap_filter:parse(NewF),
|
|
||||||
NewF.
|
|
||||||
|
|
||||||
mod_opt_type(ldap_filter) -> fun check_filter/1;
|
|
||||||
mod_opt_type(ldap_search_fields) ->
|
mod_opt_type(ldap_search_fields) ->
|
||||||
fun (Ls) ->
|
fun (Ls) ->
|
||||||
[{iolist_to_binary(S), iolist_to_binary(P)}
|
[{iolist_to_binary(S), iolist_to_binary(P)}
|
||||||
|
@ -525,17 +520,8 @@ mod_opt_type(_) ->
|
||||||
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
||||||
ldap_tls_verify].
|
ldap_tls_verify].
|
||||||
|
|
||||||
opt_type(ldap_filter) -> fun check_filter/1;
|
|
||||||
opt_type(ldap_uids) ->
|
|
||||||
fun (Us) ->
|
|
||||||
lists:map(fun ({U, P}) ->
|
|
||||||
{iolist_to_binary(U), iolist_to_binary(P)};
|
|
||||||
({U}) -> {iolist_to_binary(U)}
|
|
||||||
end,
|
|
||||||
Us)
|
|
||||||
end;
|
|
||||||
opt_type(_) ->
|
opt_type(_) ->
|
||||||
[ldap_filter, ldap_uids, deref_aliases, ldap_backups, ldap_base,
|
[deref_aliases, ldap_backups, ldap_base,
|
||||||
ldap_deref_aliases, ldap_encrypt, ldap_password,
|
ldap_deref_aliases, ldap_encrypt, ldap_password,
|
||||||
ldap_port, ldap_rootdn, ldap_servers,
|
ldap_port, ldap_rootdn, ldap_servers,
|
||||||
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
ldap_tls_cacertfile, ldap_tls_certfile, ldap_tls_depth,
|
||||||
|
|
10
src/rest.erl
10
src/rest.erl
|
@ -37,12 +37,7 @@
|
||||||
|
|
||||||
start(Host) ->
|
start(Host) ->
|
||||||
p1_http:start(),
|
p1_http:start(),
|
||||||
Pool_size =
|
Pool_size = ejabberd_config:get_option({ext_api_http_pool_size, Host}, 100),
|
||||||
ejabberd_config:get_option({ext_api_http_pool_size, Host},
|
|
||||||
fun(X) when is_integer(X), X > 0->
|
|
||||||
X
|
|
||||||
end,
|
|
||||||
100),
|
|
||||||
p1_http:set_pool_size(Pool_size).
|
p1_http:set_pool_size(Pool_size).
|
||||||
|
|
||||||
stop(_Host) ->
|
stop(_Host) ->
|
||||||
|
@ -167,9 +162,6 @@ base_url(Server, Path) ->
|
||||||
<<"http", _Url/binary>> -> Tail;
|
<<"http", _Url/binary>> -> Tail;
|
||||||
_ ->
|
_ ->
|
||||||
Base = ejabberd_config:get_option({ext_api_url, Server},
|
Base = ejabberd_config:get_option({ext_api_url, Server},
|
||||||
fun(X) ->
|
|
||||||
iolist_to_binary(X)
|
|
||||||
end,
|
|
||||||
<<"http://localhost/api">>),
|
<<"http://localhost/api">>),
|
||||||
<<Base/binary, "/", Tail/binary>>
|
<<Base/binary, "/", Tail/binary>>
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -85,8 +85,7 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
-spec load_from_config() -> ok | {error, any()}.
|
-spec load_from_config() -> ok | {error, any()}.
|
||||||
|
|
||||||
load_from_config() ->
|
load_from_config() ->
|
||||||
Shapers = ejabberd_config:get_option(
|
Shapers = ejabberd_config:get_option(shaper, []),
|
||||||
shaper, fun(V) -> V end, []),
|
|
||||||
case mnesia:transaction(
|
case mnesia:transaction(
|
||||||
fun() ->
|
fun() ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
|
|
@ -246,9 +246,7 @@ users_number(LServer) ->
|
||||||
fun(pgsql, _) ->
|
fun(pgsql, _) ->
|
||||||
case
|
case
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
{pgsql_users_number_estimate, LServer},
|
{pgsql_users_number_estimate, LServer}, false) of
|
||||||
fun(V) when is_boolean(V) -> V end,
|
|
||||||
false) of
|
|
||||||
true ->
|
true ->
|
||||||
ejabberd_sql:sql_query_t(
|
ejabberd_sql:sql_query_t(
|
||||||
?SQL("select @(reltuples :: bigint)d from pg_class"
|
?SQL("select @(reltuples :: bigint)d from pg_class"
|
||||||
|
@ -634,13 +632,6 @@ set_roster_version(LUser, Version) ->
|
||||||
["!username=%(LUser)s",
|
["!username=%(LUser)s",
|
||||||
"version=%(Version)s"]).
|
"version=%(Version)s"]).
|
||||||
|
|
||||||
opt_type(sql_type) ->
|
|
||||||
fun (pgsql) -> pgsql;
|
|
||||||
(mysql) -> mysql;
|
|
||||||
(sqlite) -> sqlite;
|
|
||||||
(mssql) -> mssql;
|
|
||||||
(odbc) -> odbc
|
|
||||||
end;
|
|
||||||
opt_type(pgsql_users_number_estimate) ->
|
opt_type(pgsql_users_number_estimate) ->
|
||||||
fun (V) when is_boolean(V) -> V end;
|
fun (V) when is_boolean(V) -> V end;
|
||||||
opt_type(_) -> [sql_type, pgsql_users_number_estimate].
|
opt_type(_) -> [pgsql_users_number_estimate].
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue