Handle hostnames with upper-case letters
[webmin.git] / cluster-passwd / save_passwd.cgi
1 #!/usr/local/bin/perl
2 # save_passwd.cgi
3 # Change a user's password
4
5 require './cluster-passwd-lib.pl';
6 &foreign_require("useradmin", "user-lib.pl");
7 &error_setup($text{'passwd_err'});
8 &ReadParse();
9 @hosts = &cluster_useradmin::list_useradmin_hosts();
10 @ulist = &get_all_users(\@hosts);
11 ($user) = grep { $_->{'user'} eq $in{'user'} } @ulist;
12 $user || &error($passwd::text{'passwd_euser'});
13 &can_edit_passwd($user) || &error($passwd::text{'passwd_ecannot'});
14
15 # Validate inputs
16 if ($access{'old'} == 1 ||
17     $access{'old'} == 2 && $user->{'user'} ne $remote_user) {
18         &useradmin::validate_password($in{'old'}, $user->{'pass'}) ||
19                 &error($passwd::text{'passwd_eold'});
20         }
21 if ($access{'repeat'}) {
22         $in{'new'} eq $in{'repeat'} || &error($passwd::text{'passwd_erepeat'});
23         }
24 $err = &useradmin::check_password_restrictions(
25         $in{'new'}, $user->{'user'});
26 &error($err) if ($err);
27
28 # Output header
29 $| = 1;
30 $theme_no_table++;
31 &ui_print_header(undef, $text{'passwd_title'}, "");
32
33 # Do it on all servers
34 &modify_on_hosts(\@hosts, $user->{'user'}, $in{'new'},
35                  ($access{'others'} == 1 ||
36                   $access{'others'} == 2 && $in{'others'}), \&print_func);
37
38 # Log the change
39 delete($user->{'plainpass'});
40 delete($user->{'pass'});
41 &webmin_log("passwd", undef, $user->{'user'}, $user);
42
43 &ui_print_footer($in{'one'} ? ( "/", $text{'index'} )
44                             : ( "", $passwd::text{'index_return'} ));
45
46 # print_func(mode, message)
47 sub print_func
48 {
49 if ($_[0] == -1) {
50         print "<b>$_[1]</b><p>\n";
51         print "<ul>\n";
52         }
53 elsif ($_[0] == -2) {
54         print "$_[1]<br>\n";
55         }
56 elsif ($_[0] == -3) {
57         print "$_[1]<p>\n";
58         }
59 elsif ($_[0] == -4) {
60         print "</ul>\n";
61         }
62 elsif ($_[0] > 0) {
63         print "$_[1]<p>\n";
64         print "</ul>\n";
65         }
66 }