Commit 749ef5cd authored by Franco Fichtner's avatar Franco Fichtner

rc: mock '-h 0' behaviour of pw usermod for easier installer access

parent 76eb058d
...@@ -31,21 +31,34 @@ ...@@ -31,21 +31,34 @@
require_once('config.inc'); require_once('config.inc');
require_once('auth.inc'); require_once('auth.inc');
$password = isset($argv[1]) ? $argv[1] : ''; $fp = fopen('php://stdin', 'r');
$confirm = isset($argv[2]) ? $argv[2] : '';
if (!empty($password) && $password === $confirm) { if (isset($argv[1]) && isset($argv[2]) && $argv[1] === '-h' && $argv[2] === '0') {
/* the installer needs this code to change the password */
$admin_user = &getUserEntryByUID(0); $admin_user = &getUserEntryByUID(0);
if ($admin_user) { if (!$admin_user) {
local_user_set_password($admin_user, $password); echo "user not found\n";
write_config('Root user reset from console'); exit(1);
} }
echo "new password for user {$admin_user['name']}:";
shell_exec('/bin/stty -echo');
$password = chop(fgets($fp));
shell_exec('/bin/stty echo');
echo "\n";
if (empty($password)) {
echo "empty password read\n";
exit(1);
}
local_user_set_password($admin_user, $password);
local_user_set($admin_user);
write_config('Root user reset from console');
exit(0); exit(0);
} }
$fp = fopen('php://stdin', 'r');
echo "The root user login behaviour will be restored to its defaults.\n\nDo you want to proceed? [y/N]: "; echo "The root user login behaviour will be restored to its defaults.\n\nDo you want to proceed? [y/N]: ";
if (strcasecmp(chop(fgets($fp)), 'y') != 0) { if (strcasecmp(chop(fgets($fp)), 'y') != 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment