Files
xamxam/app/public/admin/actions/smtp-test.php
Pontoporeia ca5983075d feat: admin audit logging across all admin actions
- AdminLogger: JSON-lines → /var/log/xamxam.log (prod) / storage/logs/admin.log (dev)
  + best-effort DB mirror to admin_audit_log table
- DB: admin_audit_log table, share_links.is_archived column
- ShareLink: archive() replaces delete(), toggleActive() returns new state,
  listActive()/listArchived() split, validateLink blocks archived slugs
- All action handlers wired: publish, unpublish, visibility, delete, csv/db export,
  tfe add/edit, tags, pages, apropos, form-help, access-request, maintenance,
  settings (formulaire toggles, objet types, smtp update), smtp-test
- acces.php: archive button replaces delete; collapsible archived links section
- setup-server.sh: provision /var/log/xamxam.log (www-data:xamxam 640)
2026-05-05 11:04:52 +02:00

76 lines
2.4 KiB
PHP

<?php
require_once __DIR__ . "/../../../bootstrap.php";
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/Database.php';
require_once APP_ROOT . '/src/SmtpRelay.php';
require_once APP_ROOT . '/src/App.php';
// CSRF
if (
!isset($_POST['csrf_token'], $_SESSION['csrf_token']) ||
!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])
) {
App::flash('error', 'Erreur de sécurité : token invalide.');
header('Location: /admin/parametres.php');
exit;
}
$to = trim($_POST['test_email'] ?? '');
if ($to === '' || !filter_var($to, FILTER_VALIDATE_EMAIL)) {
App::flash('error', 'Adresse e-mail de test invalide.');
header('Location: /admin/parametres.php');
exit;
}
$db = new Database();
if (!SmtpRelay::isConfigured($db)) {
App::flash('error', 'Le relay SMTP n\'est pas configuré.');
header('Location: /admin/parametres.php');
exit;
}
$subject = 'Test SMTP - XAMXAM';
$sentDate = date('d/m/Y à H:i:s');
$toSafe = htmlspecialchars($to);
$body = <<<HTML
<html>
<body style="font-family: sans-serif; color: #222; max-width: 600px; margin: 0 auto; padding: 24px;">
<h1 style="font-size: 1.4rem; border-bottom: 2px solid #c00; padding-bottom: 8px;">
Test d'envoi SMTP - XAMXAM
</h1>
<p>Ceci est un e-mail de test envoyé depuis l'interface d'administration de <strong>XAMXAM</strong>.</p>
<p>Si vous recevez ce message, la configuration du relay SMTP est correcte.</p>
<hr style="border:none; border-top:1px solid #ddd; margin: 24px 0;">
<p style="font-size: 0.85rem; color: #666;">
Envoyé le : $sentDate<br>
Destinataire : $toSafe
</p>
</body>
</html>
HTML;
require_once APP_ROOT . '/src/AdminLogger.php';
try {
$ok = SmtpRelay::send($db, $to, $subject, $body);
if ($ok) {
AdminLogger::make()->logSmtpTest($to, true);
App::flash('success', "E-mail de test envoyé à « {$to} ».");
} else {
AdminLogger::make()->logSmtpTest($to, false, 'Send returned false');
App::flash('error', "Échec de l'envoi. Vérifiez la configuration SMTP et les logs serveur.");
}
} catch (SmtpSendException $e) {
$detail = $e->isRecipientRejected()
? "Adresse rejetée par le serveur ({$to}) : " . $e->smtpResponse
: "Erreur SMTP : " . $e->smtpResponse;
AdminLogger::make()->logSmtpTest($to, false, $detail);
App::flash('error', $detail);
}
header('Location: /admin/parametres.php');
exit;