mirror of
https://github.com/hybula/whmcs-turnstile.git
synced 2025-12-19 14:59:24 +00:00
feat: support captcha on reset page
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 '<script>
|
||||
var turnstileDiv = document.createElement("div");
|
||||
turnstileDiv.innerHTML = \'<div class="cf-turnstile" data-sitekey="'.hybulaTurnstileSite.'" data-callback="javascriptCallback" data-theme="'.hybulaTurnstileTheme.'"></div>'.(hybulaTurnstileCredits ? '<a href="https://github.com/hybula/whmcs-turnstile" target="_blank"><small class="text-muted text-uppercase">Captcha integration by Hybula</small></a>' : '<!-- Captcha integration by Hybula (https://github.com/hybula/whmcs-turnstile) -->').'<br><br>\';
|
||||
turnstileDiv.innerHTML = \'<div class="cf-turnstile" data-sitekey="' . hybulaTurnstileSite . '" data-callback="javascriptCallback" data-theme="' . hybulaTurnstileTheme . '"></div>' . (hybulaTurnstileCredits ? '<a href="https://github.com/hybula/whmcs-turnstile" target="_blank"><small class="text-muted text-uppercase">Captcha integration by Hybula</small></a>' : '<!-- Captcha integration by Hybula (https://github.com/hybula/whmcs-turnstile) -->') . '<br><br>\';
|
||||
if (document.querySelector(\'input[type=submit],#login,div.text-center > button[type=submit],#openTicketSubmit\')) {
|
||||
var form = document.querySelector(\'input[type=submit],#login,div.text-center > button[type=submit],#openTicketSubmit\').parentNode;
|
||||
form.insertBefore(turnstileDiv, document.querySelector(\'input[type=submit],#login,div.text-center > button[type=submit],#openTicketSubmit\'));
|
||||
|
||||
Reference in New Issue
Block a user