init work remote API

This commit is contained in:
bunkerity
2021-10-02 20:29:50 +02:00
parent 5d94cc8f43
commit 64aa9c2530
6 changed files with 165 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
log_by_lua_block {
local logger = require "logger"
-- bad behavior
local use_bad_behavior = {% if USE_BAD_BEHAVIOR == "yes" %}true{% else %}false{% endif +%}
local behavior = require "behavior"
@@ -12,4 +14,20 @@ if use_bad_behavior then
behavior.count(bad_behavior_status_codes, bad_behavior_threshold, bad_behavior_count_time, bad_behavior_ban_time)
end
-- remote API
local use_remote_api = {% if USE_REMOTE_API == "yes" %}true{% else %}false{% endif +%}
local remoteapi = require "remoteapi"
if use_remote_api then
if ngx.status == ngx.HTTP_FORBIDDEN then
-- TODO check if IP is global + good reason
local res, data = remoteapi.ip(ngx.var.remote_addr, "other")
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)
end
end
end
}