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>
This commit is contained in:
39
web/includes/auth.php
Normal file
39
web/includes/auth.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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'] ?? '';
|
||||
}
|
||||
Reference in New Issue
Block a user