1
|
require_once("config.inc");
|
2
|
require("auth.inc");
|
3
|
require_once("functions.inc");
|
4
|
|
5
|
global $g, $config, $argv, $userindex;
|
6
|
$userindex = index_users();
|
7
|
|
8
|
$args = array_slice($argv, 3);
|
9
|
|
10
|
$password = "";
|
11
|
$confpassword = "";
|
12
|
$username = "";
|
13
|
|
14
|
$fp = fopen('php://stdin', 'r');
|
15
|
|
16
|
// If the first parameter is empty, ask for username
|
17
|
if (empty($args[0])) {
|
18
|
echo gettext("Enter username: ");
|
19
|
$username = fgets($fp);
|
20
|
} else {
|
21
|
$username = $args[0];
|
22
|
}
|
23
|
$username = trim($username);
|
24
|
|
25
|
// If the user does not exist, bail
|
26
|
$user =& getUserEntry($username);
|
27
|
if ($user == NULL) {
|
28
|
printf(gettext("User '%s' does not exist.\n"), $username);
|
29
|
exit(-1);
|
30
|
} else {
|
31
|
printf(gettext("Changing password for '%s'.\n"), $username);
|
32
|
}
|
33
|
|
34
|
// If the user does exist, prompt for password
|
35
|
while (empty($password)) {
|
36
|
echo gettext("New Password") . ": ";
|
37
|
exec('/bin/stty -echo');
|
38
|
$password = trim(fgets($fp));
|
39
|
exec('/bin/stty echo');
|
40
|
echo "\n";
|
41
|
}
|
42
|
|
43
|
// Confirm password
|
44
|
while (empty($confpassword)) {
|
45
|
echo gettext("Confirm New Password") . ": ";
|
46
|
exec('/bin/stty -echo');
|
47
|
$confpassword = trim(fgets($fp));
|
48
|
exec('/bin/stty echo');
|
49
|
echo "\n";
|
50
|
}
|
51
|
|
52
|
// Check if user is disabled
|
53
|
if (is_account_disabled($username)) {
|
54
|
echo gettext("Account is disabled, would you like to re-enable? [y|n]") . ": ";
|
55
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
56
|
unset($user['disabled']);
|
57
|
}
|
58
|
}
|
59
|
// Check if user is expired
|
60
|
if (is_account_expired($username)) {
|
61
|
echo gettext("Account is expired, would you like to clear the expiration date? [y|n]") . ": ";
|
62
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
63
|
unset($user['expires']);
|
64
|
}
|
65
|
}
|
66
|
|
67
|
fclose($fp);
|
68
|
|
69
|
// Compare password and confirm
|
70
|
if ($password == $confpassword) {
|
71
|
//Reset password
|
72
|
local_user_set_password($user, $password);
|
73
|
local_user_set($user);
|
74
|
write_config(sprintf(gettext("password changed for user '%s' from console."), $username));
|
75
|
exit(0);
|
76
|
} else {
|
77
|
echo gettext("New and Confirm passwords did not match.") . "\n";
|
78
|
exit(-1);
|
79
|
}
|