feat(captcha): Added some new services 🤖 (#1771)

* feat(captcha): Added some new services

* Updated

* Updated

* Update GoogleCaptchaV2.php

* Updated

* Updated

* Create HCaptcha.php

* Update HCaptcha.php

* Update HCaptcha.php

* Create YandexSmartCaptcha.php

* Update YandexSmartCaptcha.php

* Create CloudflareTurnstileCaptcha.php

* Update CloudflareTurnstileCaptcha.php

* Update config.php

* Update functions.php

* Update functions.php

* Update functions.php

* Update GoogleCaptchaV3.php

* Update GoogleCaptchaV3.php

* Update HCaptcha.php

* Update YandexSmartCaptcha.php

* Update CloudflareTurnstileCaptcha.php

* Updated

* Updated

* Update functions.php

* Updated

* Updated

* Update HCaptcha.php

* Updated

* Updated

* Updated

* Update functions.php

* Update main.php

* Updated

* Update HCaptcha.php

* Update HCaptcha.php

* Update GoogleCaptchaV3.php

* Update GoogleCaptchaV3.php

* Updated

* Updated

* Update GoogleCaptchaV2.php

* Update GoogleCaptchaV2.php
This commit is contained in:
Roman Kelesidis 2025-01-26 12:38:47 +03:00 committed by GitHub
commit d413c71718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 449 additions and 43 deletions

View file

@ -2044,56 +2044,50 @@ function hash_search($hash)
}
/**
* Функция для получения и проверки правильности ответа от Google ReCaptcha.
*
* @param $mode
* @param string $callback
* Function for checking captcha answer
*
* @param string $mode
* @return bool|string
*/
function bb_captcha($mode, $callback = '')
function bb_captcha(string $mode): bool|string
{
global $bb_cfg, $lang;
$secret = $bb_cfg['captcha']['secret_key'];
$public = $bb_cfg['captcha']['public_key'];
$cp_theme = $bb_cfg['captcha']['theme'] ?? 'light';
$settings = $bb_cfg['captcha'];
$settings['language'] = $bb_cfg['default_lang'];
if (!$bb_cfg['captcha']['disabled'] && (!$public || !$secret)) {
bb_die($lang['CAPTCHA_SETTINGS']);
// Checking captcha settings
if (!$settings['disabled']) {
if (empty($settings['public_key']) || empty($settings['secret_key'])) {
bb_die($lang['CAPTCHA_SETTINGS']);
}
}
$reCaptcha = new \ReCaptcha\ReCaptcha($secret);
switch ($mode) {
case 'get':
return "
<script type=\"text/javascript\">
var onloadCallback = function() {
grecaptcha.render('tp-captcha', {
'sitekey' : '" . $public . "',
'theme' : '" . $cp_theme . "',
'callback' : '" . $callback . "'
});
};
</script>
<div id=\"tp-captcha\"></div>
<script src=\"https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit\" async defer></script>";
break;
case 'check':
$resp = $reCaptcha->verify(
request_var('g-recaptcha-response', ''),
$_SERVER["REMOTE_ADDR"]
);
if ($resp->isSuccess()) {
return true;
}
break;
default:
bb_simple_die(__FUNCTION__ . ": invalid mode '$mode'");
// Selecting captcha service
$captchaClasses = [
'googleV2' => \TorrentPier\Captcha\GoogleCaptchaV2::class,
'googleV3' => \TorrentPier\Captcha\GoogleCaptchaV3::class,
'hCaptcha' => \TorrentPier\Captcha\HCaptcha::class,
'yandex' => \TorrentPier\Captcha\YandexSmartCaptcha::class,
'cloudflare' => \TorrentPier\Captcha\CloudflareTurnstileCaptcha::class,
];
if (!isset($captchaClasses[$settings['service']])) {
bb_die(sprintf('Captcha service (%s) not supported', $settings['service']));
}
$captchaClass = $captchaClasses[$settings['service']];
$captcha = new $captchaClass($settings);
// Selection mode
if (isset($captcha)) {
switch ($mode) {
case 'get':
case 'check':
return $captcha->$mode();
default:
bb_die(sprintf('Invalid mode: %s', $mode));
}
}
return false;
}