diff --git a/web/admin/accounts.php b/web/admin/accounts.php index 2a81fb9..cfc6ff0 100644 --- a/web/admin/accounts.php +++ b/web/admin/accounts.php @@ -71,6 +71,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { 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( @@ -183,13 +219,19 @@ html_navbar('accounts'); -
- - - -
+
+ + + +
+ @@ -201,4 +243,49 @@ html_navbar('accounts'); + + + +