| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/montpellier/components/com_community/helpers/captcha/ |
Upload File : |
<?php
use Joomla\CMS\Factory;
use Joomla\CMS\Http\Http;
use Joomla\Registry\Registry;
defined('_JEXEC') or die('Restricted access');
class CloudflareCCaptchaHelper
{
public $enabled = false;
public $ip;
private $privateKey;
private $publicKey;
private $theme;
private $apiUrl;
private $verifyUrl;
/*
* Load config data and object vars
*/
public function __construct()
{
// Config data
$config = CFactory::getConfig();
$this->enabled = $config->get('nocloudflare', false);
$this->privateKey = $config->get('cloudflareprivate');
$this->publicKey = $config->get('cloudflarepublic');
$this->apiUrl = $config->get('cloudflare_server');
$this->theme = $config->get('cloudflaretheme');
$this->verifyUrl = $config->get('cloudflare_server_verify');
// Grab the IP, remember load balancers
// @todo is there a framework way to do it?
$this->ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
// If any of the vital vars is missing, disable the whole thing
if (!$this->privateKey || !$this->publicKey || !$this->apiUrl || !$this->verifyUrl) {
$this->enabled = false;
}
}
public function html()
{
if (!$this->enabled) {
return '';
}
// start output buffer, if cloudflare is enabled add HTML and JS to the buffer
ob_start(); ?>
<div id="joms-cloudflare"></div>
<script type="text/javascript">
const form = document.getElementsByTagName('form');
var jomsCloudflareCaptchaCallback = function() {
turnstile.render("#joms-cloudflare", {
"sitekey": "<?php echo $this->publicKey; ?>",
"theme": "<?php echo $this->theme; ?>",
callback: function(token) {
jQuery(form).append('<input name="g-cloudflare-response" type="hidden" value="' + token + '" />');
},
})
};
</script>
<script src="<?php echo $this->apiUrl; ?>?onload=jomsCloudflareCaptchaCallback"></script>
<?php
// get the contents of te buffer and return it
$html = ob_get_clean();
return $html;
}
public function verify()
{
// get the Recaptcha response from the form data
$token = Factory::getApplication()->input->get('g-cloudflare-response');
if (!$token) return false;
$http = new Http();
try {
$response = $http->post(
$this->verifyUrl,
array(
'secret' => $this->privateKey,
'remoteip' => $this->ip,
'response' => $token,
)
);
} catch (Exception $e) {
dump($e);
return false;
}
if ($response->code !== 200) {
return false;
}
$result = new Registry($response->body);
if ($result->get('success')) {
return true;
}
return false;
}
}