mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 08:40:24 +00:00
Improve passwd change command https://github.com/webmin/webmin/pull/1477#issuecomment-825446689
1. Allow passing username as regular param 2. Do no print verbose `Success:` on success
This commit is contained in:
23
bin/passwd
23
bin/passwd
@@ -16,10 +16,18 @@ sub main
|
||||
'config|c=s' => \$opt{'config'},
|
||||
'user|u=s' => \$opt{'user'},
|
||||
'password|p=s' => \$opt{'password'});
|
||||
pod2usage(0) if ($opt{'help'} || !$opt{'user'});
|
||||
|
||||
$opt{'config'} ||= "/etc/webmin";
|
||||
# If username passed as regular param
|
||||
my $user = scalar(@ARGV) == 1 && $ARGV[0];
|
||||
|
||||
# Show usage
|
||||
pod2usage(0) if ($opt{'help'} || (!$opt{'user'} && !$user));
|
||||
|
||||
# Assign defaults
|
||||
$opt{'config'} ||= "/etc/webmin";
|
||||
$opt{'user'} = $user if ($user && !$opt{'user'});
|
||||
|
||||
# Catch kill signal
|
||||
my $sigkill = sub {
|
||||
system("stty echo");
|
||||
print "\n^C";
|
||||
@@ -28,6 +36,7 @@ sub main
|
||||
};
|
||||
$SIG{INT} = \&$sigkill;
|
||||
|
||||
# Run change password command
|
||||
change_password(\%opt);
|
||||
|
||||
return 0;
|
||||
@@ -87,7 +96,7 @@ sub change_password
|
||||
|
||||
# Check for main user file
|
||||
&$conf_check([$minserv_uconf_file]);
|
||||
|
||||
|
||||
# Read and parse `miniserv.users` config file
|
||||
read_file($minserv_uconf_file, \%lusers, undef, undef, ":");
|
||||
@users = keys %lusers;
|
||||
@@ -104,7 +113,7 @@ sub change_password
|
||||
}
|
||||
|
||||
# Ask for password on stdin
|
||||
my $suc_pre_msg = GREEN . 'Success:' . RESET;
|
||||
my $suc_pre_msg = "";
|
||||
my $suc_msg = 'updated successfully';
|
||||
if (!$pass) {
|
||||
print "Enter password for user ", BRIGHT_YELLOW, $user, RESET, ":";
|
||||
@@ -123,7 +132,7 @@ sub change_password
|
||||
}
|
||||
chomp $pass;
|
||||
if (!$pass) {
|
||||
$suc_pre_msg = BOLD BRIGHT_RED ON_WHITE . 'Warning:' . RESET;
|
||||
$suc_pre_msg = BOLD BRIGHT_RED ON_WHITE . 'Warning:' . RESET . " ";
|
||||
$suc_msg = "has been removed, enabling anyone to login without authentication";
|
||||
}
|
||||
}
|
||||
@@ -142,7 +151,7 @@ sub change_password
|
||||
system("$confdif/start >/dev/null 2>&1");
|
||||
|
||||
# Print user message
|
||||
say "$suc_pre_msg Password for Webmin user ", BRIGHT_YELLOW, $user, RESET, " $suc_msg";
|
||||
say "${suc_pre_msg}Password for Webmin user ", BRIGHT_YELLOW, $user, RESET, " $suc_msg";
|
||||
|
||||
exit 0;
|
||||
}
|
||||
@@ -199,6 +208,8 @@ Print this usage summary and exit.
|
||||
|
||||
Examples of usage:
|
||||
|
||||
- passwd root
|
||||
|
||||
- passwd --user root
|
||||
|
||||
- passwd --user root --password ycwyMQRVAZY
|
||||
|
||||
Reference in New Issue
Block a user