Handle hostnames with upper-case letters
[webmin.git] / change-user / change.cgi
1 #!/usr/local/bin/perl
2 # change.cgi
3 # Make all the changes, and re-direct to / in case the theme has changed
4
5 use strict;
6 use warnings;
7 require './change-user-lib.pl';
8 our (%text, %in, %gconfig, $base_remote_user, %access);
9 &ReadParse();
10
11 my @users = &acl::list_users();
12 my ($user) = grep { $_->{'name'} eq $base_remote_user } @users;
13 my $oldtheme = $user->{'theme'};
14 my $oldoverlay = $user->{'overlay'};
15 if (!defined($oldtheme)) {
16         ($oldtheme, $oldoverlay) = split(/\s+/, $gconfig{'theme'});
17         }
18
19 # Validate the password
20 if ($access{'pass'} && &can_change_pass($user) && !$in{'pass_def'}) {
21         $in{'pass'} =~ /:/ && &error($text{'change_ecolon'});
22         $in{'pass'} eq $in{'pass2'} ||
23                 &error($text{'change_epass2'});
24         my $perr = &acl::check_password_restrictions(
25                 $user->{'name'}, $in{'pass'});
26         &error(&text('change_epass', $perr)) if ($perr);
27         }
28
29 # Parse custom language
30 if ($access{'lang'}) {
31         if ($in{'lang_def'}) {
32                 $user->{'lang'} = undef;
33                 }
34         else {
35                 $user->{'lang'} = $in{'lang'};
36                 }
37         }
38
39 # Parse custom theme and possibly overlay
40 my ($newoverlay, $newtheme);
41 if ($access{'theme'}) {
42         if ($in{'theme_def'}) {
43                 $user->{'theme'} = undef;
44                 }
45         else {
46                 $user->{'theme'} = $in{'theme'};
47                 }
48         $newtheme = $user->{'theme'};
49         if (!defined($newtheme)) {
50                 $newtheme = $gconfig{'theme'};
51                 }
52
53         # Overlay
54         if (!$in{'overlay'}) {
55                 $newoverlay = undef;
56                 $user->{'overlay'} = undef;
57                 }
58         else {
59                 $newoverlay = $in{'overlay'};
60                 $user->{'theme'} || &error($text{'change_eoverlay'});
61                 my %oinfo = &get_theme_info($in{'overlay'});
62                 if ($oinfo{'overlays'} &&
63                     &indexof($user->{'theme'},
64                              split(/\s+/, $oinfo{'overlays'})) < 0) {
65                         &error($text{'change_eoverlay2'});
66                         }
67                 $user->{'overlay'} = $in{'overlay'};
68                 }
69         }
70
71 # Parse password change
72 if ($access{'pass'} && &can_change_pass($user) && !$in{'pass_def'}) {
73         $user->{'pass'} = &acl::encrypt_password($in{'pass'});
74         $user->{'temppass'} = 0;
75         }
76
77 &ui_print_unbuffered_header(undef, $text{'change_title'}, "");
78
79 print "$text{'change_user'}<br>\n";
80 &acl::modify_user($user->{'name'}, $user);
81 print "$text{'change_done'}<p>\n";
82
83 print "$text{'change_restart'}<br>\n";
84 &reload_miniserv();
85 print "$text{'change_done'}<p>\n";
86
87 if ($access{'theme'} &&
88     ($newtheme ne $oldtheme || $newoverlay ne $oldoverlay)) {
89         print "$text{'change_redirect'}<br>\n";
90         print &js_redirect("/", "top");
91         print "$text{'change_done'}<p>\n";
92         }
93
94 &ui_print_footer("/", $text{'index'});
95