From 5704a980c5b000fdd094fa9adaf1e18c9cfb9ce6 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Sat, 17 Feb 2018 18:53:35 +0300 Subject: [PATCH] Introduce 'access' option for mod_block_stranger The option is supposed to be used when `allow_local_users` and `allow_transports` are not enough. It's an ACL where `deny` means the message will be rejected (or a CAPTCHA would be generated for a presence), and `allow` means the sender is whitelisted and the stanza will pass through. The default value is `none`, which means nothing is whitelisted. --- src/mod_block_strangers.erl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mod_block_strangers.erl b/src/mod_block_strangers.erl index b60003c84..d6d5c50cb 100644 --- a/src/mod_block_strangers.erl +++ b/src/mod_block_strangers.erl @@ -199,8 +199,10 @@ need_check(Pkt) -> false end, AllowLocalUsers = gen_mod:get_module_opt(LServer, ?MODULE, allow_local_users), - not (IsEmpty orelse ((AllowLocalUsers orelse From#jid.luser == <<"">>) - andalso ejabberd_router:is_my_host(From#jid.lserver))). + Access = gen_mod:get_module_opt(LServer, ?MODULE, access), + not (IsEmpty orelse acl:match_rule(LServer, Access, From) == allow + orelse ((AllowLocalUsers orelse From#jid.luser == <<"">>) + andalso ejabberd_router:is_my_host(From#jid.lserver))). -spec check_subscription(jid(), jid()) -> boolean(). check_subscription(From, To) -> @@ -265,10 +267,14 @@ mod_opt_type(allow_local_users) -> mod_opt_type(allow_transports) -> fun (B) when is_boolean(B) -> B end; mod_opt_type(captcha) -> - fun (B) when is_boolean(B) -> B end. + fun (B) when is_boolean(B) -> B end; +mod_opt_type(access) -> + fun acl:access_rules_validator/1. + mod_options(_) -> - [{drop, true}, + [{access, none}, + {drop, true}, {log, false}, {captcha, false}, {allow_local_users, true},