fix wrong error check on phases and add missing ttl for *list cache items
This commit is contained in:
parent
1da4b78f0f
commit
9849ce10ce
|
@ -110,7 +110,12 @@ function cachestore:set(key, value, ex)
|
|||
self.logger:log(ngx.ERR, err)
|
||||
end
|
||||
end
|
||||
local ok, err = self.cache:set(key, nil, value)
|
||||
local ok, err
|
||||
if ex then
|
||||
ok, err = self.cache:set(key, {ttl = ex}, value)
|
||||
else
|
||||
ok, err = self.cache:set(key, nil, value)
|
||||
end
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -161,6 +161,8 @@ for i, plugin in ipairs(plugins) do
|
|||
local ok, ret = helpers.call_plugin(plugin_obj, "init")
|
||||
if not ok then
|
||||
init_logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
init_logger:log(ngx.ERR, plugin.id .. ":init() call failed : " .. ret.msg)
|
||||
else
|
||||
init_logger:log(ngx.NOTICE, plugin.id .. ":init() call successful : " .. ret.msg)
|
||||
end
|
||||
|
|
|
@ -32,10 +32,10 @@ end
|
|||
|
||||
-- Process bans as soon as possible
|
||||
local ok, reason = datastore:get("bans_ip_" .. ngx.var.remote_addr)
|
||||
if not ok and reason then
|
||||
if not ok and reason ~= "not found" then
|
||||
logger:log(ngx.INFO, "error while checking if client is banned : " .. reason)
|
||||
return false
|
||||
elseif reason then
|
||||
elseif ok and reason ~= "not found" then
|
||||
logger:log(ngx.WARN, "IP " .. ngx.var.remote_addr .. " is banned with reason : " .. reason)
|
||||
return ngx.exit(utils.get_deny_status())
|
||||
end
|
||||
|
@ -68,8 +68,10 @@ for i, plugin in ipairs(plugins) do
|
|||
local ok, ret = helpers.call_plugin(plugin_obj, "access")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin.id .. ":access() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin.id .. ":access() call successful : " .. ret.msg)
|
||||
logger:log(ngx.NOTICE, plugin.id .. ":access() call successful : " .. ret.msg)
|
||||
end
|
||||
if ret.status then
|
||||
if ret.status == utils.get_deny_status() then
|
||||
|
|
|
@ -42,11 +42,12 @@ for i, plugin in ipairs(plugins) do
|
|||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "header")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin.id .. ":header() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin.id .. ":header() call successful : " .. ret.msg)
|
||||
logger:log(ngx.NOTICE, plugin.id .. ":header() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -39,8 +39,10 @@ for i, plugin in ipairs(plugins) do
|
|||
local ok, ret = helpers.call_plugin(plugin_obj, "log")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin.id .. ":log() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin.id .. ":log() call successful : " .. ret.msg)
|
||||
logger:log(ngx.NOTICE, plugin.id .. ":log() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -46,8 +46,10 @@ for i, plugin in ipairs(plugins) do
|
|||
local ok, ret = helpers.call_plugin(plugin_obj, "set")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin.id .. ":set() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin.id .. ":set() call successful : " .. ret.msg)
|
||||
logger:log(ngx.NOTICE, plugin.id .. ":set() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -155,7 +155,7 @@ function blacklist:is_in_cache(ele)
|
|||
end
|
||||
|
||||
function blacklist:add_to_cache(ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_blacklist_" .. ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_blacklist_" .. ele, value, 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -101,7 +101,7 @@ function country:is_in_cache(ip)
|
|||
end
|
||||
|
||||
function country:add_to_cache(ip, country, result)
|
||||
local ok, err = self.cachestore:set("plugin_country_cache_" .. ip, cjson.encode({country = country, result = result}))
|
||||
local ok, err = self.cachestore:set("plugin_country_cache_" .. ip, cjson.encode({country = country, result = result}), 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -43,9 +43,9 @@ function dnsbl:access()
|
|||
return self:ret(false, "can't check if client IP is global : " .. err)
|
||||
end
|
||||
if not is_global then
|
||||
local ok, err self:add_to_cache(ngx.var.remote_addr, "ok")
|
||||
local ok, err = self:add_to_cache(ngx.var.remote_addr, "ok")
|
||||
if not ok then
|
||||
return self:ret(false, "error while adding element to cache")
|
||||
return self:ret(false, "error while adding element to cache : " .. err)
|
||||
end
|
||||
return self:ret(true, "client IP is not global, skipping DNSBL check")
|
||||
end
|
||||
|
@ -79,12 +79,12 @@ function dnsbl:is_in_cache(ip)
|
|||
local ok, data = self.cachestore:get("plugin_dnsbl_" .. ip)
|
||||
if not ok then
|
||||
return false, data
|
||||
end
|
||||
end
|
||||
return true, data
|
||||
end
|
||||
|
||||
function dnsbl:add_to_cache(ip, value)
|
||||
local ok, err = self.cachestore:set("plugin_dnsbl_" .. ip, value)
|
||||
local ok, err = self.cachestore:set("plugin_dnsbl_" .. ip, value, 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -239,7 +239,7 @@ function greylist:is_in_cache(ele)
|
|||
end
|
||||
|
||||
function greylist:add_to_cache(ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_greylist_" .. ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_greylist_" .. ele, value, 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -69,7 +69,7 @@ function reversescan:is_in_cache(ip_port)
|
|||
end
|
||||
|
||||
function reversescan:add_to_cache(ip_port, value)
|
||||
local ok, err = self.cachestore:set("plugin_reversescan_cache_" .. ip_port, value)
|
||||
local ok, err = self.cachestore:set("plugin_reversescan_cache_" .. ip_port, value, 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
|
@ -185,7 +185,7 @@ function whitelist:is_in_cache(ele)
|
|||
end
|
||||
|
||||
function whitelist:add_to_cache(ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_whitelist_" .. ele, value)
|
||||
local ok, err = self.cachestore:set("plugin_whitelist_" .. ele, value, 86400)
|
||||
if not ok then
|
||||
return false, err
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue