mod_limit_auth/mod_limit_auth.lua
changeset 1593 3e4d15ae2133
parent 1583 c1bb2a64aabb
equal deleted inserted replaced
1592:47fb4f36dacd 1593:3e4d15ae2133
     5 
     5 
     6 local period = math.max(module:get_option_number(module.name.."_period", 30), 0);
     6 local period = math.max(module:get_option_number(module.name.."_period", 30), 0);
     7 local max = math.max(module:get_option_number(module.name.."_max", 5), 1);
     7 local max = math.max(module:get_option_number(module.name.."_max", 5), 1);
     8 
     8 
     9 local tarpit_delay = module:get_option_number(module.name.."_tarpit_delay", nil);
     9 local tarpit_delay = module:get_option_number(module.name.."_tarpit_delay", nil);
    10 if tarpit_delay then
    10 if tarpit_delay and tarpit_delay > 0 then
    11 	local waiter = require "util.async".waiter;
    11 	local waiter = require "util.async".waiter;
    12 	local delay = tarpit_delay;
    12 	local delay = tarpit_delay;
    13 	function tarpit_delay()
    13 	function tarpit_delay()
    14 		local wait, done = waiter();
    14 		local wait, done = waiter();
    15 		module:add_timer(delay, done);
    15 		module:add_timer(delay, done);
    44 
    44 
    45 module:hook("authentication-failure", function (event)
    45 module:hook("authentication-failure", function (event)
    46 	get_throttle(event.session.ip):poll(1);
    46 	get_throttle(event.session.ip):poll(1);
    47 end);
    47 end);
    48 
    48 
    49 -- TODO remove old throttles after some time
    49 module:add_timer(144, function (t)
       
    50 	t = t - 86400;
       
    51 	for ip, throttle in pairs(throttles) do
       
    52 		if throttle.t < t then
       
    53 			throttles[ip] = nil;
       
    54 		end
       
    55 	end
       
    56 	return 144;
       
    57 end);