3 # Script for the user to change their webmin password
5 # Check command line arguments
6 usage() if (@ARGV != 3);
7 ($config, $user, $pass) = @ARGV;
9 print STDERR "The config directory $config does not exist\n";
12 if (!open(CONF, "$config/miniserv.conf")) {
13 print STDERR "Failed to open $config/miniserv.conf : $!\n";
14 print STDERR "Maybe $config is not the Webmin config directory.\n";
18 if (/^([^=]+)=(\S+)/) { $config{$1} = $2; }
22 # Update the users file
23 if (!open(USERS, $config{'userfile'})) {
24 print STDERR "Failed to open Webmin users file $config{'userfile'} : $!\n";
29 local @user = split(/:/, $_);
31 $users{$user[0]} = \@user;
32 push(@users, $user[0]);
36 if (!defined($users{$user})) {
37 print STDERR "The Webmin user $user does not exist\n";
38 print STDERR "The users on your system are: ",join(" ", @users),"\n";
41 $salt = substr(time(), 0, 2);
42 $users{$user}->[1] = crypt($pass, $salt);
43 if (!open(USERS, "> $config{'userfile'}")) {
44 print STDERR "Failed to open Webmin users file $config{'userfile'} : $!\n";
47 foreach $v (values %users) {
48 print USERS join(":", @$v),"\n";
51 print "Updated password of Webmin user $user\n";
53 # Send a signal to have miniserv reload it's config
54 if (open(PID, $config{'pidfile'})) {
59 print STDERR "Webmin is not running - cannot refresh configuration\n";
61 elsif (!kill('USR1', $pid)) {
62 print STDERR "Failed to signal process $pid - cannot refresh configuration\n";
66 print STDERR "Webmin is not running - cannot refresh configuration\n";
72 usage: changepass.pl <config-dir> <login> <password>
74 This program allows you to change the password of a user in the Webmin
75 password file. For example, to change the password of the admin user
76 to foo, you would run:
77 changepass.pl /etc/webmin admin foo
78 This assumes that /etc/webmin is the Webmin configuration directory.