26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

mod_fail2ban: Add 'access' option for whitelisting

Closes #535.
This commit is contained in:
Holger Weiss 2015-04-18 11:08:05 +02:00
parent afdc269825
commit aa36742a40

View File

@ -53,6 +53,10 @@ start_link(Host, Opts) ->
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []). gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
c2s_auth_result(false, _User, LServer, {Addr, _Port}) -> c2s_auth_result(false, _User, LServer, {Addr, _Port}) ->
case is_whitelisted(LServer, Addr) of
true ->
ok;
false ->
BanLifetime = gen_mod:get_module_opt( BanLifetime = gen_mod:get_module_opt(
LServer, ?MODULE, c2s_auth_ban_lifetime, LServer, ?MODULE, c2s_auth_ban_lifetime,
fun(T) when is_integer(T), T > 0 -> T end, fun(T) when is_integer(T), T > 0 -> T end,
@ -67,6 +71,7 @@ c2s_auth_result(false, _User, LServer, {Addr, _Port}) ->
ets:insert(failed_auth, {Addr, N+1, UnbanTS, MaxFailures}); ets:insert(failed_auth, {Addr, N+1, UnbanTS, MaxFailures});
[] -> [] ->
ets:insert(failed_auth, {Addr, 1, UnbanTS, MaxFailures}) ets:insert(failed_auth, {Addr, 1, UnbanTS, MaxFailures})
end
end; end;
c2s_auth_result(true, _User, _Server, _AddrPort) -> c2s_auth_result(true, _User, _Server, _AddrPort) ->
ok. ok.
@ -160,6 +165,12 @@ code_change(_OldVsn, State, _Extra) ->
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================
is_whitelisted(Host, Addr) ->
Access = gen_mod:get_module_opt(Host, ?MODULE, access,
fun(A) when is_atom(A) -> A end,
none),
acl:match_rule(Host, Access, Addr) == allow.
unban_timestamp(BanLifetime) -> unban_timestamp(BanLifetime) ->
{MegaSecs, MSecs, USecs} = now(), {MegaSecs, MSecs, USecs} = now(),
UnbanSecs = MegaSecs * 1000000 + MSecs + BanLifetime, UnbanSecs = MegaSecs * 1000000 + MSecs + BanLifetime,