mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-03 18:02:28 +01:00
* src/mod_ip_blacklist.erl: Better error handling (EJAB-625).
SVN Revision: 1321
This commit is contained in:
parent
1a2bb06075
commit
977a20700a
@ -1,3 +1,7 @@
|
|||||||
|
2008-05-09 Mickael Remond <mremond@process-one.net>
|
||||||
|
|
||||||
|
* src/mod_ip_blacklist.erl: Better error handling (EJAB-625).
|
||||||
|
|
||||||
2008-05-05 Mickael Remond <mremond@process-one.net>
|
2008-05-05 Mickael Remond <mremond@process-one.net>
|
||||||
|
|
||||||
* src/ejabberd_c2s.erl: Added C2S blacklist support (EJAB-625).
|
* src/ejabberd_c2s.erl: Added C2S blacklist support (EJAB-625).
|
||||||
|
@ -85,20 +85,25 @@ loop(_State) ->
|
|||||||
%% TODO: Support comment lines starting by %
|
%% TODO: Support comment lines starting by %
|
||||||
update_bl_c2s() ->
|
update_bl_c2s() ->
|
||||||
?INFO_MSG("Updating C2S Blacklist", []),
|
?INFO_MSG("Updating C2S Blacklist", []),
|
||||||
{ok, {{_Version, 200, _Reason}, _Headers, Body}} = http:request(?BLC2S),
|
case http:request(?BLC2S) of
|
||||||
|
{ok, {{_Version, 200, _Reason}, _Headers, Body}} ->
|
||||||
IPs = string:tokens(Body,"\n"),
|
IPs = string:tokens(Body,"\n"),
|
||||||
ets:delete_all_objects(bl_c2s),
|
ets:delete_all_objects(bl_c2s),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(IP) ->
|
fun(IP) ->
|
||||||
ets:insert(bl_c2s, #bl_c2s{ip=list_to_binary(IP)})
|
ets:insert(bl_c2s, #bl_c2s{ip=list_to_binary(IP)})
|
||||||
end, IPs).
|
end, IPs);
|
||||||
|
{error, Reason} ->
|
||||||
|
?ERROR_MSG("Cannot download C2S blacklist file. Reason: ~p",
|
||||||
|
[Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
%% Hook is run with:
|
%% Hook is run with:
|
||||||
%% ejabberd_hooks:run_fold(check_bl_c2s, false, [IP]),
|
%% ejabberd_hooks:run_fold(check_bl_c2s, false, [IP]),
|
||||||
%% Return: false: IP not blacklisted
|
%% Return: false: IP not blacklisted
|
||||||
%% true: IP is blacklisted
|
%% true: IP is blacklisted
|
||||||
%% IPV4 IP tuple:
|
%% IPV4 IP tuple:
|
||||||
is_ip_in_c2s_blacklist(_Val, IP) ->
|
is_ip_in_c2s_blacklist(_Val, IP) when is_tuple(IP) ->
|
||||||
BinaryIP = list_to_binary(jlib:ip_to_list(IP)),
|
BinaryIP = list_to_binary(jlib:ip_to_list(IP)),
|
||||||
case ets:lookup(bl_c2s, BinaryIP) of
|
case ets:lookup(bl_c2s, BinaryIP) of
|
||||||
[] -> %% Not in blacklist
|
[] -> %% Not in blacklist
|
||||||
|
Loading…
Reference in New Issue
Block a user