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
|
||||
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
|
||||
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 pow_cookie_secret = os.getenv("POW_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
|
||||
local ddos_map = Map.new("/etc/haproxy/map/ddos.map", Map._str);
|
||||
local captcha_provider_domain = ""
|
||||
local captcha_classname = ""
|
||||
local captcha_script_src = ""
|
||||
local captcha_siteverify_path = ""
|
||||
local captcha_backend_name = ""
|
||||
if os.getenv("HCAPTCHA_SITEKEY") then
|
||||
captcha_provider_domain = "hcaptcha.com"
|
||||
captcha_classname = "h-captcha"
|
||||
captcha_script_src = "https://hcaptcha.com/1/api.js"
|
||||
captcha_siteverify_path = "/siteverify"
|
||||
captcha_backend_name = "hcaptcha"
|
||||
else
|
||||
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_backend_name = "recaptcha"
|
||||
end
|
||||
|
||||
function _M.secondsToDate(seconds)
|
||||
@ -185,10 +175,7 @@ function _M.view(applet)
|
||||
if captcha_enabled then
|
||||
captcha_body = string.format(
|
||||
templates.captcha_section,
|
||||
ll["Please solve the captcha to continue."],
|
||||
captcha_classname,
|
||||
captcha_sitekey,
|
||||
captcha_script_src
|
||||
ll["Please solve the captcha to continue."]
|
||||
)
|
||||
else
|
||||
pow_body = string.format(
|
||||
@ -330,8 +317,6 @@ function _M.view(applet)
|
||||
-- format the url for verifying the captcha response
|
||||
local captcha_url = string.format(
|
||||
"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_siteverify_path
|
||||
)
|
||||
|
@ -82,26 +82,27 @@ _M.pow_section = [[
|
||||
</div>
|
||||
]]
|
||||
|
||||
-- alternative, spinner animation
|
||||
-- .loader{display:inline-block;position:relative;width:80px;height:80px}
|
||||
-- .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}
|
||||
-- .loader div:nth-child(1){animation-delay:-0.45s}
|
||||
-- .loader div:nth-child(2){animation-delay:-0.3s}
|
||||
-- .loader div:nth-child(3){animation-delay:-0.15s}
|
||||
-- @keyframes loader{0%%{transform:rotate(0deg)}100%%{transform:rotate(360deg)}}
|
||||
-- <div class="jsonly">
|
||||
-- <div class="loader"><div></div><div></div><div></div><div></div></div>
|
||||
-- </div>
|
||||
|
||||
-- message, captcha form and submit button
|
||||
_M.captcha_section = [[
|
||||
<p>
|
||||
-- captcha section
|
||||
local captcha_sitekey = os.getenv("HCAPTCHA_SITEKEY") or os.getenv("RECAPTCHA_SITEKEY")
|
||||
local captcha_classname = ""
|
||||
local captcha_script_src = ""
|
||||
if os.getenv("HCAPTCHA_SITEKEY") then
|
||||
captcha_classname = "h-captcha"
|
||||
captcha_script_src = "https://hcaptcha.com/1/api.js"
|
||||
else
|
||||
captcha_classname = "g-recaptcha"
|
||||
captcha_script_src = "https://www.google.com/recaptcha/api.js"
|
||||
end
|
||||
_M.captcha_section = string.format([[
|
||||
<span>
|
||||
%s
|
||||
</p>
|
||||
</span>
|
||||
<div id="captcha" class="jsonly">
|
||||
<div class="%s" data-sitekey="%s" data-callback="onCaptchaSubmit"></div>
|
||||
<script src="%s" async defer></script>
|
||||
</div>
|
||||
]]
|
||||
]], "%s", captcha_classname, captcha_sitekey, captcha_script_src)
|
||||
|
||||
|
||||
|
||||
return _M
|
||||
|
Reference in New Issue
Block a user