Add a new user'."\n"; echo ' users edit|update Update a user'."\n"; echo ' users del|delete|remove Delete a user'."\n"; die; }; $msg = null; $users = $GLOBALS['appconf']['users']; switch ($args[0]) { case 'create': case 'update': case 'edit': case 'new': case 'add': $args = array_slice($args, 1); if (count($args) !== 2) $help(); __session_delete($args[0]); $args[1] = hash_hmac('sha256', $args[1], $GLOBALS['appconf']['users_hash_secret']); $users[$args[0]] = $args[1]; $msg = 'User "'.$args[0].'" has been succesfully saved.'; break; case 'remove': case 'delete': case 'del': $args = array_slice($args, 1); if (count($args) !== 1) $help(); if (!isset($users[$args[0]])) $msg = 'User "'.$args[0].'" does not exist.'; else { unset($users[$args[0]]); __session_delete($args[0]); $msg = 'User "'.$args[0].'" has been succesfully deleted.'; } break; case 'help': default: $help(); } $booladd = true; $newlines = []; $lines = explode("\n", trim(file_get_contents('config/users.php'))); foreach ($lines as $line) { if ($booladd) $newlines []= $line; if (trim($line) === '#start_users') { $booladd = false; continue; } if (trim($line) === '#end_users') { foreach ($users as $uname => $pwd) $newlines []= "$uname $pwd"; $booladd = true; $newlines []= $line; continue; } } file_put_contents('config/users.php', implode("\n", $newlines)); if ($msg !== null) echo $msg."\n"; } function cli__help($full=true) { echo 'APub Control cli.php 1.0 author: bofh@nogafam.es'."\n"; echo "\n"; echo ' Parameters:'."\n"; if ($full === false) return; echo ' users Add/delete/modify web application users'."\n"; die; } switch ($argv[1]) { case 'users': cli__users(array_slice($argv, 2)); break; case 'help': cli__help(); break; }