antibot - manage direct access to challenge page

This commit is contained in:
florian 2023-04-24 15:11:01 +02:00
parent a372ffd521
commit 7eefcb8f8d
No known key found for this signature in database
GPG key ID: 3D80806F12602A7C
2 changed files with 21 additions and 3 deletions

2
TODO
View file

@ -1,5 +1,3 @@
- bwcli with redis
- direct access to ANTIBOT_URI without prepare_challenge call
- don't fail if session err is not nil (new session will be created)
- stream refactoring
- stream examples

View file

@ -45,6 +45,14 @@ function antibot:access()
return self:ret(true, "redirecting client to the challenge uri", nil, self.variables["ANTIBOT_URI"])
end
-- Direct access without session => prepare challenge
if not self:challenge_prepared() then
local ok, err = self:prepare_challenge()
if not ok then
return self:ret(false, "can't prepare challenge : " .. err, ngx.HTTP_INTERNAL_SERVER_ERROR)
end
end
-- Display challenge needed
if ngx.ctx.bw.request_method == "GET" then
ngx.ctx.bw.antibot_display_content = true
@ -98,7 +106,7 @@ function antibot:challenge_resolved()
end
local ok, err, raw_data = utils.get_session_var("antibot")
if not raw_data then
return false, "session is set but no antibot data", nil
return false, "session is set but no antibot data"
end
local data = raw_data
if data.resolved and self.variables["USE_ANTIBOT"] == data.type then
@ -107,6 +115,18 @@ function antibot:challenge_resolved()
return false, "challenge not resolved", data.original_uri
end
function antibot:challenge_prepared()
local session, err, exists, refreshed = utils.get_session()
if not exists then
return false
end
local ok, err, raw_data = utils.get_session_var("antibot")
if not raw_data then
return false
end
return self.variables["USE_ANTIBOT"] == raw_data.type
end
function antibot:prepare_challenge()
local session, err, exists, refreshed = utils.get_session()
local set_needed = false