diff --git a/README.md b/README.md index 5702515..5d01786 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ const hybulaTurnstileSite = ''; const hybulaTurnstileSecret = ''; const hybulaTurnstileTheme = 'auto'; const hybulaTurnstileError = 'Something went wrong with your captcha challenge!'; -const hybulaTurnstileLocations = ['login', 'register', 'checkout', 'ticket', 'contact']; +const hybulaTurnstileLocations = ['login', 'register', 'checkout', 'ticket', 'contact', 'reset']; ``` Final notes: Due to some limitations, the captcha will **NOT** be shown when there is an active admin session. If you want to test it, open up your WHMCS in a private window. diff --git a/includes/hooks/hybula_turnstile.php b/includes/hooks/hybula_turnstile.php index 3744a59..d0861b2 100644 --- a/includes/hooks/hybula_turnstile.php +++ b/includes/hooks/hybula_turnstile.php @@ -16,19 +16,24 @@ declare(strict_types=1); -if (!defined('WHMCS')) { +if (! defined('WHMCS')) { die('This file cannot be accessed directly!'); } -if (!isset($_SESSION['adminid'])) { - if (!empty($_POST) && (!isset($_SESSION['uid']) && hybulaTurnstileExcludeLogin)) { +if (! isset($_SESSION['adminid'])) { + if (! empty($_POST) && (! isset($_SESSION['uid']) && hybulaTurnstileExcludeLogin)) { $pageFile = basename($_SERVER['SCRIPT_NAME'], '.php'); - if ((($pageFile == 'index' && isset($_POST['username']) && isset($_POST['password']) && in_array('login', hybulaTurnstileLocations)) || + if (hybulaTurnstileEnabled && + ( + ($pageFile == 'index' && isset($_POST['username']) && isset($_POST['password']) && in_array('login', hybulaTurnstileLocations)) || ($pageFile == 'register' && in_array('register', hybulaTurnstileLocations)) || ($pageFile == 'contact' && in_array('contact', hybulaTurnstileLocations)) || ($pageFile == 'submitticket' && isset($_POST['subject']) && in_array('ticket', hybulaTurnstileLocations)) || - ($pageFile == 'cart' && $_GET['a'] == 'checkout' && in_array('checkout', hybulaTurnstileLocations))) && hybulaTurnstileEnabled) { - if (!isset($_POST['cf-turnstile-response'])) { + ($pageFile == 'cart' && $_GET['a'] == 'checkout' && in_array('checkout', hybulaTurnstileLocations)) || + ($pageFile == 'index' && isset($_POST['email']) && in_array('reset', hybulaCapLocations)) + ) + ) { + if (! isset($_POST['cf-turnstile-response'])) { unset($_SESSION['uid']); die('Missing captcha response in POST data!'); } @@ -54,7 +59,7 @@ if (!isset($_SESSION['adminid'])) { $err = curl_error($curl); curl_close($curl); if ($json = json_decode($result)) { - if (!$json->success) { + if (! $json->success) { unset($_SESSION['uid']); die(hybulaTurnstileError); } @@ -63,18 +68,21 @@ if (!isset($_SESSION['adminid'])) { } add_hook('ClientAreaFooterOutput', 1, function ($vars) { - if (!hybulaTurnstileEnabled || (isset($_SESSION['uid']) && hybulaTurnstileExcludeLogin)) { + if (! hybulaTurnstileEnabled || (isset($_SESSION['uid']) && hybulaTurnstileExcludeLogin)) { return ''; } $pageFile = basename($_SERVER['SCRIPT_NAME'], '.php'); - if ((in_array('login', hybulaTurnstileLocations) && $vars['pagetitle'] == $vars['LANG']['login']) || + if ( + (in_array('login', hybulaTurnstileLocations) && $vars['pagetitle'] == $vars['LANG']['login']) || (in_array('register', hybulaTurnstileLocations) && $pageFile == 'register') || (in_array('contact', hybulaTurnstileLocations) && $pageFile == 'contact') || (in_array('ticket', hybulaTurnstileLocations) && $pageFile == 'submitticket') || - (in_array('checkout', hybulaTurnstileLocations) && $pageFile == 'cart' && $_GET['a'] == 'checkout')) { + (in_array('checkout', hybulaTurnstileLocations) && $pageFile == 'cart' && $_GET['a'] == 'checkout') || + (in_array('reset', hybulaCapLocations) && $vars['pagetitle'] == $vars['LANG']['pwreset']) + ) { return '