Files
copymailrpi/web/includes/auth.php
Jules 0be1b9119a init: projet complet copymail pour Raspberry Pi
Stack: Nginx + PHP 8.2 + MariaDB + Postfix + Dovecot + Samba
- install.sh: script installation automatisé pour RPi OS Bookworm
- Interface web: visionneuse mails + admin (comptes, domaine, dashboard)
- Chaque compte mail génère automatiquement un share Samba
- Processeur cron: extraction pièces jointes via zbateson/mail-mime-parser
- Zéro injection SQL (PDO + prepared statements)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-04 09:36:35 +02:00

40 lines
924 B
PHP

<?php
function auth_start(): void {
if (session_status() === PHP_SESSION_NONE) {
session_name('copymail_sess');
session_start();
}
}
function auth_check(): void {
auth_start();
if (empty($_SESSION['admin_id'])) {
header('Location: /login.php');
exit;
}
}
function auth_login(string $username, string $password): bool {
$st = db()->prepare('SELECT id, password FROM admin_users WHERE username = ? LIMIT 1');
$st->execute([$username]);
$row = $st->fetch();
if ($row && password_verify($password, $row['password'])) {
$_SESSION['admin_id'] = $row['id'];
$_SESSION['admin_user'] = $username;
return true;
}
return false;
}
function auth_logout(): void {
auth_start();
session_destroy();
header('Location: /login.php');
exit;
}
function current_user(): string {
return $_SESSION['admin_user'] ?? '';
}