From dea38fc6fff7df2f6454e717bcb45e85266791a8 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Tue, 2 Jul 2024 06:32:36 -0700 Subject: [PATCH] Add ability to easily ban user in account_manager.php. --- .../rslight/scripts/account_manager.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Rocksolid_Light/rslight/scripts/account_manager.php b/Rocksolid_Light/rslight/scripts/account_manager.php index ab00be6..e32f235 100644 --- a/Rocksolid_Light/rslight/scripts/account_manager.php +++ b/Rocksolid_Light/rslight/scripts/account_manager.php @@ -49,6 +49,16 @@ if ($argv[1][0] == '-') { echo "Email: " . $argv[3] . "\n"; } break; + case "-banuser": + if (! isset($argv[2])) { + echo "Usage: -banuser username\n"; + exit(); + } else { + ban_user($argv[2]); + echo "User is banned: " . $argv[2] . "\n"; + echo "To unban, remove from $config_dir/banned_users.conf\n"; + } + break; case "-delete": if (! isset($argv[2])) { echo "Usage: -delete username\n"; @@ -83,6 +93,8 @@ if ($argv[1][0] == '-') { echo "-newemail: Change user email '-newemail username emailaddress'\n"; echo " Email address will remain listed as 'verified'\n"; echo " Be sure to verify the address is correct\n"; + echo "-banuser: Disable ability for user to log in '-banuser username'\n"; + echo " This doesn't block the site, just posting and other user features\n"; echo "-delete: Delete user account '-delete username'\n"; echo " Be careful with this. You will not be asked to confirm\n"; echo " Account files will be placed in a dir named 'deleted'\n"; @@ -93,6 +105,31 @@ if ($argv[1][0] == '-') { exit(); } +function ban_user($username) { + global $config_dir; + $banfile = $config_dir . '/banned_users.conf'; + $username = strtolower($username); + $userfile = $config_dir . '/users/' . $username; + if(! file_exists($userfile)) { + echo "User:" . $username . " Not Found\r\n"; + return; + } else { + $lines = file($banfile); + foreach ($lines as $k => $v) { + if (!trim($v)) { + unset($lines[$k]); + } else { + if(trim($v) == $username) { + echo "User:" . $username . " already banned.\n"; + return; + } + } + } + $lines[] = $username; + file_put_contents($banfile, "\n" . implode($lines) . "\n"); + } +} + function change_user_email($username, $email) { global $config_dir; $username = strtolower($username);