basic antibot feature through cookie
This commit is contained in:
@@ -5,11 +5,16 @@ local use_whitelist_reverse = %USE_WHITELIST_REVERSE%
|
||||
local use_blacklist_ip = %USE_BLACKLIST_IP%
|
||||
local use_blacklist_reverse = %USE_BLACKLIST_REVERSE%
|
||||
local use_dnsbl = %USE_DNSBL%
|
||||
local use_antibot_cookie = %USE_ANTIBOT_COOKIE%
|
||||
|
||||
-- include LUA code
|
||||
local whitelist = require "whitelist"
|
||||
local blacklist = require "blacklist"
|
||||
local dnsbl = require "dnsbl"
|
||||
local cookie = require "cookie"
|
||||
|
||||
-- antibot
|
||||
local antibot_uri = "%ANTIBOT_URI%"
|
||||
|
||||
-- check if already in whitelist cache
|
||||
if use_whitelist_ip and whitelist.ip_cached_ok() then
|
||||
@@ -67,6 +72,21 @@ if use_dnsbl and not dnsbl.cached() then
|
||||
end
|
||||
end
|
||||
|
||||
-- cookie check
|
||||
if use_antibot_cookie then
|
||||
if not cookie.is_set() then
|
||||
if ngx.var.uri ~= antibot_uri then
|
||||
cookie.set()
|
||||
return ngx.redirect(antibot_uri)
|
||||
end
|
||||
return ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||
else
|
||||
if ngx.var.uri == antibot_uri then
|
||||
return ngx.redirect(cookie.get_uri())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ngx.exit(ngx.OK)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user