diff options
-rw-r--r-- | useradm.php | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/useradm.php b/useradm.php index 738ef59..e9005a8 100644 --- a/useradm.php +++ b/useradm.php @@ -15,7 +15,7 @@ if (count($options) == 0 || isset($options["help"])) { print "Manage Epube user database. Usage: - --add USER:PASSWORD + --add USER --del USER --list\n"; } @@ -23,30 +23,41 @@ if (isset($options["del"])) { $user = $options["del"]; - print "Deleting user $user...\n"; - $sth = $dbh->prepare("DELETE FROM epube_users WHERE user = ?"); - + $sth = $dbh->prepare("SELECT id FROM epube_users WHERE user = ?"); $sth->execute([$user]); + + if ($sth->fetch()) { + print "Deleting user $user...\n"; + + $sth = $dbh->prepare("DELETE FROM epube_users WHERE user = ?"); + $sth->execute([$user]); + } else { + print "User $user not found.\n"; + } } if (isset($options["list"])) { $res = $dbh->query("SELECT id, user FROM epube_users ORDER BY user"); while ($line = $res->fetch()) { - printf("%d. %s\n", $line["id"], $line["user"]); + print $line["user"] . "\n"; } } if (isset($options["add"])) { - @list($user, $pass) = explode(":", $options["add"]); + $user = $options["add"]; - if (!$user || !$pass) { + if (!$user) { print "Not enough arguments.\n"; exit; } + print "Enter password for user $user: "; + $pass = fgets(STDIN); + $user = trim(mb_strtolower($user)); + $pass = trim($pass); $pass_hash = 'SHA256:' . hash('sha256', "$user:" . trim($pass)); print "Adding user $user with password $pass...\n"; |