mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
Precompute captcha section on startup since its based on (what) an ENV
Remove unused captcha_backend_name and captcha backend in config, not needed since haproxy 2.7
This commit is contained in:
@ -184,11 +184,3 @@ backend bot_check_post_throttle
|
|||||||
|
|
||||||
backend count_qs_throttle
|
backend count_qs_throttle
|
||||||
stick-table type string size 100k expire 60s store http_req_rate(60s)
|
stick-table type string size 100k expire 60s store http_req_rate(60s)
|
||||||
|
|
||||||
backend hcaptcha
|
|
||||||
mode http
|
|
||||||
server hcaptcha hcaptcha.com:443
|
|
||||||
|
|
||||||
backend recaptcha
|
|
||||||
mode http
|
|
||||||
server recaptcha www.google.com:443
|
|
||||||
|
@ -47,7 +47,6 @@ local ddos_default_config = {
|
|||||||
|
|
||||||
-- captcha variables
|
-- captcha variables
|
||||||
local captcha_secret = os.getenv("HCAPTCHA_SECRET") or os.getenv("RECAPTCHA_SECRET")
|
local captcha_secret = os.getenv("HCAPTCHA_SECRET") or os.getenv("RECAPTCHA_SECRET")
|
||||||
local captcha_sitekey = os.getenv("HCAPTCHA_SITEKEY") or os.getenv("RECAPTCHA_SITEKEY")
|
|
||||||
local captcha_cookie_secret = os.getenv("CAPTCHA_COOKIE_SECRET")
|
local captcha_cookie_secret = os.getenv("CAPTCHA_COOKIE_SECRET")
|
||||||
local pow_cookie_secret = os.getenv("POW_COOKIE_SECRET")
|
local pow_cookie_secret = os.getenv("POW_COOKIE_SECRET")
|
||||||
local hmac_cookie_secret = os.getenv("HMAC_COOKIE_SECRET")
|
local hmac_cookie_secret = os.getenv("HMAC_COOKIE_SECRET")
|
||||||
@ -55,22 +54,13 @@ local ray_id = os.getenv("RAY_ID")
|
|||||||
-- load captcha map and set hcaptcha/recaptch based off env vars
|
-- load captcha map and set hcaptcha/recaptch based off env vars
|
||||||
local ddos_map = Map.new("/etc/haproxy/map/ddos.map", Map._str);
|
local ddos_map = Map.new("/etc/haproxy/map/ddos.map", Map._str);
|
||||||
local captcha_provider_domain = ""
|
local captcha_provider_domain = ""
|
||||||
local captcha_classname = ""
|
|
||||||
local captcha_script_src = ""
|
|
||||||
local captcha_siteverify_path = ""
|
local captcha_siteverify_path = ""
|
||||||
local captcha_backend_name = ""
|
|
||||||
if os.getenv("HCAPTCHA_SITEKEY") then
|
if os.getenv("HCAPTCHA_SITEKEY") then
|
||||||
captcha_provider_domain = "hcaptcha.com"
|
captcha_provider_domain = "hcaptcha.com"
|
||||||
captcha_classname = "h-captcha"
|
|
||||||
captcha_script_src = "https://hcaptcha.com/1/api.js"
|
|
||||||
captcha_siteverify_path = "/siteverify"
|
captcha_siteverify_path = "/siteverify"
|
||||||
captcha_backend_name = "hcaptcha"
|
|
||||||
else
|
else
|
||||||
captcha_provider_domain = "www.google.com"
|
captcha_provider_domain = "www.google.com"
|
||||||
captcha_classname = "g-recaptcha"
|
|
||||||
captcha_script_src = "https://www.google.com/recaptcha/api.js"
|
|
||||||
captcha_siteverify_path = "/recaptcha/api/siteverify"
|
captcha_siteverify_path = "/recaptcha/api/siteverify"
|
||||||
captcha_backend_name = "recaptcha"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.secondsToDate(seconds)
|
function _M.secondsToDate(seconds)
|
||||||
@ -185,10 +175,7 @@ function _M.view(applet)
|
|||||||
if captcha_enabled then
|
if captcha_enabled then
|
||||||
captcha_body = string.format(
|
captcha_body = string.format(
|
||||||
templates.captcha_section,
|
templates.captcha_section,
|
||||||
ll["Please solve the captcha to continue."],
|
ll["Please solve the captcha to continue."]
|
||||||
captcha_classname,
|
|
||||||
captcha_sitekey,
|
|
||||||
captcha_script_src
|
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
pow_body = string.format(
|
pow_body = string.format(
|
||||||
@ -330,8 +317,6 @@ function _M.view(applet)
|
|||||||
-- format the url for verifying the captcha response
|
-- format the url for verifying the captcha response
|
||||||
local captcha_url = string.format(
|
local captcha_url = string.format(
|
||||||
"https://%s%s",
|
"https://%s%s",
|
||||||
--Seems this is no longer needed, captcha_provider_domain works since 2.7
|
|
||||||
--core.backends[captcha_backend_name].servers[captcha_backend_name]:get_addr(),
|
|
||||||
captcha_provider_domain,
|
captcha_provider_domain,
|
||||||
captcha_siteverify_path
|
captcha_siteverify_path
|
||||||
)
|
)
|
||||||
|
@ -82,26 +82,27 @@ _M.pow_section = [[
|
|||||||
</div>
|
</div>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- alternative, spinner animation
|
-- captcha section
|
||||||
-- .loader{display:inline-block;position:relative;width:80px;height:80px}
|
local captcha_sitekey = os.getenv("HCAPTCHA_SITEKEY") or os.getenv("RECAPTCHA_SITEKEY")
|
||||||
-- .loader div{box-sizing:border-box;display:block;position:absolute;width:32px;height:32px;margin:10px;border:5px solid var(--text-color);border-radius:50%%;animation:loader 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;border-color:var(--text-color) transparent transparent transparent}
|
local captcha_classname = ""
|
||||||
-- .loader div:nth-child(1){animation-delay:-0.45s}
|
local captcha_script_src = ""
|
||||||
-- .loader div:nth-child(2){animation-delay:-0.3s}
|
if os.getenv("HCAPTCHA_SITEKEY") then
|
||||||
-- .loader div:nth-child(3){animation-delay:-0.15s}
|
captcha_classname = "h-captcha"
|
||||||
-- @keyframes loader{0%%{transform:rotate(0deg)}100%%{transform:rotate(360deg)}}
|
captcha_script_src = "https://hcaptcha.com/1/api.js"
|
||||||
-- <div class="jsonly">
|
else
|
||||||
-- <div class="loader"><div></div><div></div><div></div><div></div></div>
|
captcha_classname = "g-recaptcha"
|
||||||
-- </div>
|
captcha_script_src = "https://www.google.com/recaptcha/api.js"
|
||||||
|
end
|
||||||
-- message, captcha form and submit button
|
_M.captcha_section = string.format([[
|
||||||
_M.captcha_section = [[
|
<span>
|
||||||
<p>
|
|
||||||
%s
|
%s
|
||||||
</p>
|
</span>
|
||||||
<div id="captcha" class="jsonly">
|
<div id="captcha" class="jsonly">
|
||||||
<div class="%s" data-sitekey="%s" data-callback="onCaptchaSubmit"></div>
|
<div class="%s" data-sitekey="%s" data-callback="onCaptchaSubmit"></div>
|
||||||
<script src="%s" async defer></script>
|
<script src="%s" async defer></script>
|
||||||
</div>
|
</div>
|
||||||
]]
|
]], "%s", captcha_classname, captcha_sitekey, captcha_script_src)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
Reference in New Issue
Block a user