| Current Path : /home/happyrenas/find.myreco.online/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/find.myreco.online/traitement_referencement.php |
<?php
declare(strict_types=1);
include("includes/mail_find.php");
include("configuration.php");
/*
|--------------------------------------------------------------------------
| Vérification Turnstile
|--------------------------------------------------------------------------
*/
function verifierTurnstile(?string $token): array
{
if (empty($token)) {
return [
'success' => false,
'error-codes' => ['token-vide']
];
}
$postFields = http_build_query([
'secret' => TURNSTILE_SECRET_KEY,
'response' => $token,
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? ''
]);
$ch = curl_init('https://challenges.cloudflare.com/turnstile/v0/siteverify');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
if ($response === false) {
$erreurCurl = curl_error($ch);
curl_close($ch);
return [
'success' => false,
'error-codes' => ['curl-error'],
'curl-error' => $erreurCurl
];
}
curl_close($ch);
$resultat = json_decode($response, true);
if (!is_array($resultat)) {
return [
'success' => false,
'error-codes' => ['json-invalide']
];
}
return $resultat;
}
/*
|--------------------------------------------------------------------------
| Vérification méthode
|--------------------------------------------------------------------------
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
afficherPageRetour(
'Accès non autorisé',
'Cette page ne peut être appelée que depuis le formulaire.',
'error',
'referencement.php'
);
}
/*
|--------------------------------------------------------------------------
| Récupération
|--------------------------------------------------------------------------
*/
$nom = nettoyerChamp($_POST['nom'] ?? '');
$email = nettoyerChamp($_POST['email'] ?? '');
$type_hebergement = nettoyerChamp($_POST['type_hebergement'] ?? '');
$nom_hebergement = nettoyerChamp($_POST['nom_hebergement'] ?? '');
$rue = nettoyerChamp($_POST['rue'] ?? '');
$code_postal = nettoyerChamp($_POST['code_postal'] ?? '');
$ville = nettoyerChamp($_POST['ville'] ?? '');
$pays = nettoyerChamp($_POST['pays'] ?? '');
$captcha = $_POST['cf-turnstile-response'] ?? '';
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/
$erreurs = [];
$turnstile = verifierTurnstile($captcha);
if (empty($turnstile['success'])) {
$erreurs[] = 'La vérification anti-spam a échoué. Merci de réessayer.';
}
if ($nom === '') {
$erreurs[] = 'Le nom est obligatoire.';
}
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$erreurs[] = 'L’email est obligatoire et doit être valide.';
}
if ($type_hebergement === '') {
$erreurs[] = 'Le type d’hébergement est obligatoire.';
}
if ($nom_hebergement === '') {
$erreurs[] = 'Le nom de l’hébergement est obligatoire.';
}
if ($rue === '') {
$erreurs[] = 'La rue est obligatoire.';
}
if ($code_postal === '') {
$erreurs[] = 'Le code postal est obligatoire.';
}
if ($ville === '') {
$erreurs[] = 'La ville est obligatoire.';
}
if ($pays === '') {
$erreurs[] = 'Le pays est obligatoire.';
}
if (!empty($erreurs)) {
$htmlErreurs = '<ul class="mb-0">';
foreach ($erreurs as $erreur) {
$htmlErreurs .= '<li>' . ecrireValeur($erreur) . '</li>';
}
$htmlErreurs .= '</ul>';
afficherPageRetour(
'Formulaire incomplet',
$htmlErreurs,
'error',
'referencement.php'
);
}
/*
|--------------------------------------------------------------------------
| Contenu mail
|--------------------------------------------------------------------------
*/
$subject = 'Nouvelle demande de référencement Find';
$fullName = $nom;
$captchaStatut = !empty($turnstile['success']) ? 'OK' : 'ECHEC';
$captchaDate = $turnstile['challenge_ts'] ?? '';
$captchaHost = $turnstile['hostname'] ?? '';
$captchaAction = $turnstile['action'] ?? '';
$htmlBody = '
<html>
<head>
<meta charset="UTF-8">
</head>
<body style="font-family:Arial,Helvetica,sans-serif; color:#162033; background:#f7f7f7; margin:0; padding:24px;">
<div style="max-width:700px; margin:0 auto; background:#ffffff; border:1px solid #e5e5e5; border-radius:16px; overflow:hidden;">
<div style="padding:24px; background:#2b94dc; color:#ffffff;">
<h1 style="margin:0; font-size:24px;">Nouvelle demande de référencement</h1>
</div>
<div style="padding:24px;">
<p style="margin-top:0;">Une nouvelle demande a été envoyée depuis le formulaire Find.</p>
<table style="width:100%; border-collapse:collapse;">
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee; width:220px;"><strong>Nom</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($nom) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Email</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($email) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Type hébergement</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($type_hebergement) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Nom hébergement</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($nom_hebergement) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Rue</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($rue) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Code postal</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($code_postal) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Ville</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($ville) . '</td>
</tr>
<tr>
<td style="padding:10px;"><strong>Pays</strong></td>
<td style="padding:10px;">' . ecrireValeur($pays) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Captcha</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($captchaStatut) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Hostname captcha</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($captchaHost) . '</td>
</tr>
<tr>
<td style="padding:10px;"><strong>Date vérification captcha</strong></td>
<td style="padding:10px;">' . ecrireValeur($captchaDate) . '</td>
</tr>
</table>
</div>
</div>
</body>
</html>';
$textBody =
"Nouvelle demande de référencement\n\n" .
"Captcha : " . $captchaStatut . "\n" .
"Hostname captcha : " . $captchaHost . "\n" .
"Date vérification captcha : " . $captchaDate . "\n\n" .
"Nom : " . $nom . "\n" .
"Email : " . $email . "\n" .
"Type hébergement : " . $type_hebergement . "\n" .
"Nom hébergement : " . $nom_hebergement . "\n" .
"Rue : " . $rue . "\n" .
"Code postal : " . $code_postal . "\n" .
"Ville : " . $ville . "\n" .
"Pays : " . $pays . "\n";
/*
|--------------------------------------------------------------------------
| Envoi
|--------------------------------------------------------------------------
*/
$erreurMail = null;
if (envoyerMailFind($email, $fullName, $subject, $htmlBody, $textBody, $erreurMail)) {
afficherPageRetour(
'Demande envoyée',
'Merci, votre demande de référencement a bien été envoyée.',
'success',
'referencement.php'
);
}
afficherPageRetour(
'Erreur d’envoi',
'Erreur PHPMailer : ' . ecrireValeur((string) $erreurMail),
'error',
'referencement.php'
);