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 @@
require_once('config.inc');
require_once('auth.inc');
$password = isset($argv[1]) ? $argv[1] : '';
$confirm = isset($argv[2]) ? $argv[2] : '';
$fp = fopen('php://stdin', 'r');
if (!empty($password) && $password === $confirm) {
/* the installer needs this code to change the password */
if (isset($argv[1]) && isset($argv[2]) && $argv[1] === '-h' && $argv[2] === '0') {
$admin_user = &getUserEntryByUID(0);
if ($admin_user) {
local_user_set_password($admin_user, $password);
write_config('Root user reset from console');
if (!$admin_user) {
echo "user not found\n";
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);
}
$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]: ";
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