*/ const SBR_GARDE_SECRET = ''; // vide = lu dans getenv('SBR_CAPTCHA_SECRET') // Préfixes d'URL jamais filtrés : administration, webhooks, API appelées par des machines. const SBR_GARDE_EXCLUS = ['/wp-admin', '/wp-login.php', '/wp-cron.php', '/wp-json', '/xmlrpc.php', '/admin', '/api/', '/webhook']; // secure.rayor.fr injoignable : true = on laisse passer (le site reste utilisable), // false = on refuse (plus strict). const SBR_GARDE_SI_PANNE = true; // Niveau de suspicion maximal accepté (0 = confiance … 5 = bot avéré). 5 = tout réussi est accepté. const SBR_GARDE_NIVEAU_MAX = 5; (function () { if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') return; $path = (string) (parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/'); foreach (SBR_GARDE_EXCLUS as $p) if (strpos($path, $p) === 0) return; // Seuls les vrais formulaires HTML sont filtrés ; les envois JSON (API, appli) passent. $ct = strtolower((string) ($_SERVER['CONTENT_TYPE'] ?? '')); if ($ct !== '' && strpos($ct, 'application/x-www-form-urlencoded') === false && strpos($ct, 'multipart/form-data') === false) return; $token = (string) ($_POST['sbr-captcha-response'] ?? ''); if ($token === '') sbr_garde_refuse(); $secret = SBR_GARDE_SECRET !== '' ? SBR_GARDE_SECRET : (string) getenv('SBR_CAPTCHA_SECRET'); $r = @file_get_contents('https://secure.rayor.fr/captcha/siteverify', false, stream_context_create(['http' => [ 'method' => 'POST', 'timeout' => 5, 'ignore_errors' => true, 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query(['secret' => $secret, 'response' => $token]), ]])); $d = $r === false ? null : json_decode($r, true); if (!is_array($d)) { if (SBR_GARDE_SI_PANNE) return; sbr_garde_refuse(); } if (empty($d['success']) || (int) ($d['level'] ?? 0) > SBR_GARDE_NIVEAU_MAX) sbr_garde_refuse(); // Pour le script qui suit : niveau auquel le visiteur a réussi (0 à 5). $_SERVER['SBR_CAPTCHA_LEVEL'] = (int) ($d['level'] ?? 0); unset($_POST['sbr-captcha-response'], $_REQUEST['sbr-captcha-response']); })(); function sbr_garde_refuse(): void { http_response_code(403); header('Content-Type: text/html; charset=utf-8'); exit('' . '
' . 'La vérification anti-robot a échoué ou a expiré. Revenez en arrière, ' . 'cochez « Je ne suis pas un robot », puis renvoyez le formulaire.
'); }