prepare('SELECT id FROM accounts WHERE username = ? OR email = ?'); $st->execute([$username, $email]); if ($st->fetch()) { $error = "Le compte « {$username} » existe déjà."; } else { $webhook = trim($_POST['webhook_url'] ?? ''); db()->prepare( 'INSERT INTO accounts (username, email, display_name, smb_path, webhook_url) VALUES (?, ?, ?, ?, ?)' )->execute([$username, $email, $display, $smbPath, $webhook ?: null]); // Crée le dossier, l'utilisateur Dovecot et le share Samba $cmd = sprintf( '/opt/copymail/scripts/create_account.sh %s %s %s 2>&1', escapeshellarg($username), escapeshellarg($password), escapeshellarg($domain) ); shell_exec($cmd); flash('success', "Compte {$email} créé. Share SMB : \\\\serveur\\{$username}"); header('Location: /admin/accounts.php'); exit; } } } if ($_POST['action'] === 'delete') { $id = (int)$_POST['account_id']; $st = db()->prepare('SELECT username FROM accounts WHERE id = ?'); $st->execute([$id]); $row = $st->fetch(); if ($row) { $cmd = sprintf('/opt/copymail/scripts/delete_account.sh %s 2>&1', escapeshellarg($row['username'])); shell_exec($cmd); db()->prepare('DELETE FROM accounts WHERE id = ?')->execute([$id]); flash('success', "Compte « {$row['username']} » supprimé."); } header('Location: /admin/accounts.php'); exit; } if ($_POST['action'] === 'toggle') { $id = (int)$_POST['account_id']; db()->prepare('UPDATE accounts SET active = 1 - active WHERE id = ?')->execute([$id]); header('Location: /admin/accounts.php'); exit; } if ($_POST['action'] === 'edit') { $id = (int)$_POST['account_id']; $display = trim($_POST['display_name'] ?? ''); $webhook = trim($_POST['webhook_url'] ?? ''); $newPassword = trim($_POST['new_password'] ?? ''); db()->prepare('UPDATE accounts SET display_name = ?, webhook_url = ? WHERE id = ?') ->execute([$display ?: null, $webhook ?: null, $id]); if (strlen($newPassword) >= 6) { $st = db()->prepare('SELECT username FROM accounts WHERE id = ?'); $st->execute([$id]); $row = $st->fetch(); if ($row) { $domain = cfg('domain'); $hash = shell_exec(sprintf('doveadm pw -s SHA512-CRYPT -p %s', escapeshellarg($newPassword))); $hash = trim($hash ?? ''); if ($hash) { shell_exec(sprintf( "sed -i 's|^%s@%s:.*|%s@%s:%s:::|' /etc/dovecot/users", $row['username'], $domain, $row['username'], $domain, $hash )); $smbUser = $row['username']; shell_exec(sprintf('(echo %s; echo %s) | smbpasswd -s %s 2>/dev/null', escapeshellarg($newPassword), escapeshellarg($newPassword), escapeshellarg($smbUser) )); } } } flash('success', "Compte mis à jour."); header('Location: /admin/accounts.php'); exit; } } $accounts = db()->query( 'SELECT a.*, COUNT(sf.id) as mail_count FROM accounts a LEFT JOIN source_file sf ON sf.account_id = a.id GROUP BY a.id ORDER BY a.created_at DESC' )->fetchAll(); $domain = cfg('domain'); html_head('Comptes'); html_navbar('accounts'); ?>
QR Codes téléversement
Nouveau compte
@
Lettres, chiffres, . _ -
POST JSON à chaque réception de mail.

La création génère automatiquement :
  • Boîte mail username@
  • Dossier /srv/copymail/username/
  • Share SMB \\serveur\username
Comptes existants
Aucun compte créé.
Compte Email Share SMB Mails Statut Actions

\\serveur\