remote API - basic send of bad IPs
This commit is contained in:
@@ -21,17 +21,29 @@ end
|
||||
local use_remote_api = {% if USE_REMOTE_API == "yes" %}true{% else %}false{% endif +%}
|
||||
local remoteapi = require "remoteapi"
|
||||
|
||||
if use_remote_api then
|
||||
if use_remote_api and ngx.shared.remote_api:get("id") ~= "empty" then
|
||||
if ngx.status == ngx.HTTP_FORBIDDEN then
|
||||
local reason = "other"
|
||||
if use_bad_behavior and new_bad_behavior_ban then
|
||||
reason = "behavior"
|
||||
end
|
||||
local res, data = remoteapi.ip(ngx.var.remote_addr, reason)
|
||||
if res then
|
||||
logger.log(ngx.NOTICE, "REMOTE API", "Successfully reported ip " .. ngx.var.remote_addr)
|
||||
else
|
||||
logger.log(ngx.ERR, "REMOTE API", "Error while reporting ip " .. ngx.var.remote_addr .. " : " .. data)
|
||||
local report_ip = function (premature, ip, reason)
|
||||
if premature then
|
||||
return
|
||||
end
|
||||
local remoteapi = require "remoteapi"
|
||||
local logger = require "logger"
|
||||
local res, data = remoteapi.ip(ip, reason)
|
||||
-- TODO : find a way to log ?
|
||||
-- if res then
|
||||
-- logger.log(ngx.ERR, "REMOTE API", "Successfully reported ip " .. ngx.var.remote_addr)
|
||||
-- else
|
||||
-- logger.log(ngx.ERR, "REMOTE API", "Error while reporting ip " .. ngx.var.remote_addr .. " : " .. data)
|
||||
-- end
|
||||
end
|
||||
local ok, err = ngx.timer.at(0, report_ip, ngx.var.remote_addr, reason)
|
||||
if not ok then
|
||||
logger.log(ngx.ERR, "REMOTE API", "Error while creating report timer " .. err)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user