refactored whitelisting of user-agents
This commit is contained in:
parent
e190167bfc
commit
c03d410b0a
@ -96,21 +96,17 @@ end
|
|||||||
|
|
||||||
-- check if user-agent is allowed
|
-- check if user-agent is allowed
|
||||||
if use_user_agent and ngx.var.bad_user_agent == "yes" then
|
if use_user_agent and ngx.var.bad_user_agent == "yes" then
|
||||||
local headers = ngx.req.get_headers()
|
for k, v in pairs(whitelist_user_agent) then
|
||||||
local ua = headers["User-Agent"]
|
if string.match(ngx.var.http_user_agent, v) then
|
||||||
if not whitelist_user_agent ~= "" then
|
ngx.log(ngx.WARN, "[ALLOW] User-Agent " .. ngx.var.http_user_agent .. " is whitelisted")
|
||||||
local k_ua_white, v_ua_white = next(whitelist_user_agent, nil)
|
block = false
|
||||||
while v_ua_white do
|
break
|
||||||
local rst_whitelist = string.match(ua, v_ua_white)
|
fi
|
||||||
if rst_whitelist ~= nil and rst_whitelist ~= "" then
|
end
|
||||||
ngx.log(ngx.WARN, "[ALLOW] User-Agent " .. ngx.var.http_user_agent .. " is whitelisted")
|
if block then
|
||||||
ngx.exit(ngx.OK)
|
ngx.log(ngx.WARN, "[BLOCK] User-Agent " .. ngx.var.http_user_agent .. " is blacklisted")
|
||||||
end
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
k_ua_white, v_ua_white = next(whitelist_user_agent, k_ua_white)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
ngx.log(ngx.WARN, "[BLOCK] User-Agent " .. ngx.var.http_user_agent .. " is blacklisted")
|
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if referrer is allowed
|
-- check if referrer is allowed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user