mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
Introduce option 'allow_transports'
This is a boolean option. If set to `true` and some server's JID is in user's roster, then messages from any user of this server are accepted even if no subscription present. The option is enabled by default.
This commit is contained in:
parent
9e35af54e0
commit
dfd2045523
@ -86,20 +86,19 @@ check_message(#message{from = From, to = To} = Msg) ->
|
||||
case (Msg#message.body == [] andalso
|
||||
Msg#message.subject == [])
|
||||
orelse ((AllowLocalUsers orelse From#jid.luser == <<"">>) andalso
|
||||
ejabberd_router:is_my_route(From#jid.lserver)) of
|
||||
ejabberd_router:is_my_host(From#jid.lserver)) of
|
||||
false ->
|
||||
{Sub, _} = ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, LServer,
|
||||
{none, []}, [To#jid.luser, LServer, From]),
|
||||
case Sub of
|
||||
case check_subscription(From, To) of
|
||||
none ->
|
||||
Drop = gen_mod:get_module_opt(LServer, ?MODULE, drop, true),
|
||||
Log = gen_mod:get_module_opt(LServer, ?MODULE, log, false),
|
||||
if
|
||||
Log ->
|
||||
?INFO_MSG("Dropping message from ~s to ~s: "
|
||||
"the sender is not in the roster",
|
||||
[jid:encode(From), jid:encode(To)]);
|
||||
?INFO_MSG("~s message from stranger ~s to ~s",
|
||||
[if Drop -> "Dropping";
|
||||
true -> "Allow"
|
||||
end,
|
||||
jid:encode(From), jid:encode(To)]);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
@ -109,13 +108,41 @@ check_message(#message{from = From, to = To} = Msg) ->
|
||||
true ->
|
||||
allow
|
||||
end;
|
||||
_ ->
|
||||
some ->
|
||||
allow
|
||||
end;
|
||||
true ->
|
||||
allow
|
||||
end.
|
||||
|
||||
-spec check_subscription(jid(), jid()) -> none | some.
|
||||
check_subscription(From, To) ->
|
||||
{LocalUser, LocalServer, _} = jid:tolower(To),
|
||||
{RemoteUser, RemoteServer, _} = jid:tolower(From),
|
||||
case ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, LocalServer,
|
||||
{none, []}, [LocalUser, LocalServer, From]) of
|
||||
{none, _} when RemoteUser == <<"">> ->
|
||||
none;
|
||||
{none, _} ->
|
||||
case gen_mod:get_module_opt(LocalServer, ?MODULE,
|
||||
allow_transports, true) of
|
||||
true ->
|
||||
%% Check if the contact's server is in the roster
|
||||
case ejabberd_hooks:run_fold(
|
||||
roster_get_jid_info, LocalServer,
|
||||
{none, []},
|
||||
[LocalUser, LocalServer, jid:make(RemoteServer)]) of
|
||||
{none, _} -> none;
|
||||
_ -> some
|
||||
end;
|
||||
false ->
|
||||
none
|
||||
end;
|
||||
_ ->
|
||||
some
|
||||
end.
|
||||
|
||||
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
|
||||
case ?SETS:next(sets_iterator_from(LBJID, Set)) of
|
||||
{{U, S, _}, _} -> true;
|
||||
@ -151,4 +178,6 @@ mod_opt_type(log) ->
|
||||
fun (B) when is_boolean(B) -> B end;
|
||||
mod_opt_type(allow_local_users) ->
|
||||
fun (B) when is_boolean(B) -> B end;
|
||||
mod_opt_type(_) -> [drop, log, allow_local_users].
|
||||
mod_opt_type(allow_transports) ->
|
||||
fun (B) when is_boolean(B) -> B end;
|
||||
mod_opt_type(_) -> [drop, log, allow_local_users, allow_transports].
|
||||
|
Loading…
Reference in New Issue
Block a user