From 45f81f96ae7029d9beb356e419e7298cad4bc142 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Mon, 16 Sep 2024 21:00:20 +1000 Subject: [PATCH] Optimizations, remove a call to string.format, remove an if in else/if for deciding pow and/or captcha check --- src/lua/scripts/bot-check.lua | 15 +++++---------- src/lua/scripts/templates.lua | 13 ++++--------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/lua/scripts/bot-check.lua b/src/lua/scripts/bot-check.lua index 884e1e7..4cd70a0 100644 --- a/src/lua/scripts/bot-check.lua +++ b/src/lua/scripts/bot-check.lua @@ -152,7 +152,6 @@ function _M.view(applet) local combined_challenge = user_key .. "#" .. challenge_hash .. "#" .. expiry .. "#" .. signature -- define body sections - local site_name_body = "" local captcha_body = "" local pow_body = "" local noscript_extra_body = "" @@ -183,10 +182,6 @@ function _M.view(applet) end -- pow at least is always enabled when reaching bot-check page - site_name_body = string.format( - templates.site_name_section, - string.format(ll["Verifying your connection to %s"], host) - ) if captcha_enabled then captcha_body = string.format( templates.captcha_section, @@ -235,7 +230,7 @@ function _M.view(applet) argon_time, argon_kb, ddos_config["pt"], - site_name_body, + string.format(ll["Verifying your connection to %s"], host), pow_body, captcha_body, ll["JavaScript is required on this page."], @@ -485,11 +480,11 @@ function _M.decide_checks_necessary(txn) if ddos_map_json.m == 0 or (ddos_map_json.t == true and txn.sf:hdr("X-Country-Code") ~= "T1") then return - elseif ddos_map_json.m == 1 then + else txn:set_var("txn.validate_pow", true) - elseif ddos_map_json.m == 2 then - txn:set_var("txn.validate_pow", true) - txn:set_var("txn.validate_captcha", true) + if ddos_map_json.m == 2 then + txn:set_var("txn.validate_captcha", true) + end end end -- no entry in the map diff --git a/src/lua/scripts/templates.lua b/src/lua/scripts/templates.lua index f7302be..0e3d2d7 100644 --- a/src/lua/scripts/templates.lua +++ b/src/lua/scripts/templates.lua @@ -16,7 +16,10 @@ _M.body = [[ - %s +

+  + %s +

%s %s