- Added role-based access control for user management links in admin navigation. - Improved user account display with a dedicated account link. - Implemented form submission confirmation for delete actions in the admin interface. - Introduced a password visibility toggle on the login page. - Added login throttling to prevent brute-force attacks, recording failed attempts. - Created a CLI script for creating an admin user, replacing the previous hardcoded admin credentials. - Updated database schema to support login attempt tracking. - Enhanced user editing functionality, allowing role changes with restrictions. - Improved modal handling for user actions, ensuring better focus management. - Added styles for new account management page and improved modal transitions.
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* CLI-only: create an admin account.
|
|
*
|
|
* Replaces the old admin/password seed in inc/db.php. Run inside the
|
|
* container as www-data, so a newly created fitz.sqlite isn't owned by root:
|
|
* docker exec -it -u www-data the-old-fitz php /var/www/html/bin/create-user.php
|
|
*/
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/../inc/users.php';
|
|
|
|
function prompt(string $label, bool $hidden = false): string {
|
|
fwrite(STDOUT, $label);
|
|
if ($hidden) {
|
|
shell_exec('stty -echo');
|
|
}
|
|
$value = fgets(STDIN);
|
|
if ($hidden) {
|
|
shell_exec('stty echo');
|
|
fwrite(STDOUT, PHP_EOL);
|
|
}
|
|
return trim((string) $value);
|
|
}
|
|
|
|
$username = prompt('Username: ');
|
|
if ($username === '') {
|
|
fwrite(STDERR, "Username is required.\n");
|
|
exit(1);
|
|
}
|
|
if (username_exists($username)) {
|
|
fwrite(STDERR, "User '$username' already exists.\n");
|
|
exit(1);
|
|
}
|
|
|
|
$password = prompt('Password (' . MIN_PASSWORD_LENGTH . '+ chars): ', true);
|
|
if (strlen($password) < MIN_PASSWORD_LENGTH) {
|
|
fwrite(STDERR, 'Password must be at least ' . MIN_PASSWORD_LENGTH . " characters.\n");
|
|
exit(1);
|
|
}
|
|
if (prompt('Confirm password: ', true) !== $password) {
|
|
fwrite(STDERR, "Passwords don't match.\n");
|
|
exit(1);
|
|
}
|
|
|
|
$id = create_user($username, $password, 'admin');
|
|
fwrite(STDOUT, "Created admin '$username' (id $id).\n");
|