Handle hostnames with upper-case letters
[webmin.git] / cluster-webmin / edit_user.cgi
1 #!/usr/local/bin/perl
2 # edit_user.cgi
3 # Display details of an existing user for changing
4
5 require './cluster-webmin-lib.pl';
6 &ReadParse();
7 &ui_print_header(undef, $text{'user_title2'}, "");
8
9 @hosts = &list_webmin_hosts();
10 @mods = &all_modules(\@hosts);
11 @themes = &all_themes(\@hosts);
12 @wgroups = &all_groups(\@hosts);
13 @servers = &list_servers();
14 if ($in{'host'} ne '') {
15         ($host) = grep { $_->{'id'} == $in{'host'} } @hosts;
16         ($user) = grep { $_->{'name'} eq $in{'user'} } @{$host->{'users'}};
17         }
18 else {
19         foreach $h (@hosts) {
20                 local ($u) = grep { $_->{'name'} eq $in{'user'} } @{$h->{'users'}};
21                 if ($u) {
22                         $host = $h;
23                         $user = $u;
24                         last;
25                         }
26                 }
27         }
28 ($serv) = grep { $_->{'id'} == $host->{'id'} } @servers;
29 foreach $h (@hosts) {
30         local ($u) = grep { $_->{'name'} eq $in{'user'} } @{$h->{'users'}};
31         if ($u) {
32                 push(@got, grep { $_->{'id'} == $h->{'id'} } @servers);
33                 }
34         }
35
36 print "<form action=save_user.cgi method=post>\n";
37 print "<input type=hidden name=old value=\"$in{'user'}\">\n";
38 print "<input type=hidden name=host value=\"$host->{'id'}\">\n";
39 print "<table border width=100%>\n";
40 print "<tr $tb> <td><b>",&text('user_header2', &server_name($serv)),
41       "</b></td> </tr>\n";
42 print "<tr $cb> <td><table width=100%>\n";
43
44 print "<tr> <td><b>$text{'user_name'}</b></td>\n";
45 printf "<td><input name=name size=15 value='%s'></td> </tr>\n",
46         $user->{'name'};
47
48 foreach $g (@{$host->{'groups'}}) {
49         if (&indexof($user->{'name'}, @{$g->{'members'}}) >= 0) {
50                 $group = $g;
51                 last;
52                 }
53         }
54 print "<tr> <td><b>$text{'user_group'}</b></td> <td>\n";
55 printf "<input type=radio name=group_def value=1 checked> %s (%s)\n",
56         $text{'user_leave'}, $group ? $group->{'name'} : $text{'user_nogroup2'};
57 printf "<input type=radio name=group_def value=0> %s\n",
58         $text{'user_set'};
59 print "<select name=group>\n";
60 print "<option selected value=''>$text{'user_nogroup'}\n";
61 foreach $g (@wgroups) {
62         print "<option>$g->{'name'}\n";
63         }
64 print "</select></td> </tr>\n";
65
66 print "<tr> <td><b>$text{'user_pass'}</b></td> <td>\n";
67 print "<select name=pass_def>\n";
68 print "<option value=1 checked> $text{'user_leave'}\n";
69 print "<option value=0> $text{'user_set'} ..\n";
70 print "<option value=3> $text{'user_unix'}\n";
71 print "<option value=4> $text{'user_lock'}\n";
72 print "<option value=5> $text{'user_extauth'}\n";
73 print "</select><input type=password name=pass size=25></td> </tr>\n";
74
75 @langs = &list_languages();
76 %langdesc = map { $_->{'lang'}, $_->{'desc'} } @langs;
77 print "<tr> <td><b>$text{'user_lang'}</b></td> <td>\n";
78 printf "<input type=radio name=lang_def value=1 checked> %s (%s)\n",
79         $text{'user_leave'}, $user->{'lang'} ? $langdesc{$user->{'lang'}}
80                                              : $text{'user_default'};
81 printf "<input type=radio name=lang_def value=0> %s\n",
82         $text{'user_set'};
83 print "<select name=lang>\n";
84 print "<option value='' selected>$text{'user_default'}\n";
85 foreach $l (@langs) {
86         printf "<option value=%s>%s (%s)\n",
87                 $l->{'lang'},
88                 $l->{'desc'}, uc($l->{'lang'});
89         }
90 print "</select></td> </tr>\n";
91
92 %themedesc = map { $_->{'dir'}, $_->{'desc'} } @themes;
93 print "<tr> <td><b>$text{'user_theme'}</b></td> <td>\n";
94 printf "<input type=radio name=theme_def value=1 checked> %s (%s)\n",
95         $text{'user_leave'},
96         $user->{'theme'} ? $themedesc{$user->{'theme'}} :
97         !defined($user->{'theme'}) ? $text{'user_default'} : $text{'user_themedef'};
98 printf "<input type=radio name=theme_def value=0> %s\n",
99         $text{'user_set'};
100 print "<select name=theme>\n";
101 print "<option value=webmin selected>$text{'user_default'}\n";
102 foreach $t ( { 'desc' => $text{'user_themedef'} }, @themes) {
103         printf "<option value='%s'>%s\n", $t->{'dir'}, $t->{'desc'};
104         }
105 print "</select></td> </tr>\n";
106
107 print "<tr> <td valign=top><b>$text{'user_notabs'}</b></td>\n";
108 print "<td>",ui_radio("notabs", int($user->{'notabs'}),
109                           [ [ 1, $text{'yes'} ],
110                             [ 2, $text{'no'} ],
111                             [ 0, $text{'default'} ] ]),"</td> </tr>\n";
112
113 print "<tr> <td valign=top><b>$text{'user_ips'}</b></td>\n";
114 print "<td>\n";
115 print "<input name=ipmode type=radio value=-1 checked> $text{'user_leave'}\n";
116 if ($user->{'allow'}) {
117         print "($text{'user_allow2'} $user->{'allow'})\n";
118         }
119 elsif ($user->{'deny'}) {
120         print "($text{'user_deny2'} $user->{'deny'})\n";
121         }
122 else {
123         print "($text{'user_allowall'})\n";
124         }
125 print "<table cellpadding=0 cellspacing=0><tr><td valign=top>\n";
126 print "<input name=ipmode type=radio value=0> $text{'user_allips'}<br>\n";
127 print "<input name=ipmode type=radio value=1> $text{'user_allow'}<br>\n";
128 print "<input name=ipmode type=radio value=2> $text{'user_deny'}</td>\n";
129 print "<td><textarea name=ips rows=4 cols=30></textarea></td>\n";
130 print "</td> </tr></table> </tr>\n";
131
132 $mp = int((scalar(@mods)+2)/3);
133 @umods = $group ? @{$user->{'ownmods'}} : @{$user->{'modules'}};
134 map { $umods{$_}++ } @umods;
135 print "<tr> <td valign=top><b>$text{'user_mods'}</b><br>",
136       "$text{'user_groupmods'}</td> <td nowrap>\n";
137 print "<input type=radio name=mods_def value=1 checked> ",
138         &text('user_mleave', scalar(@umods)),"<br>\n";
139 print "<input type=radio name=mods_def value=2> $text{'user_modsel'}\n";
140 print "<input type=radio name=mods_def value=3> $text{'user_modadd'}\n";
141 print "<input type=radio name=mods_def value=0> $text{'user_moddel'}\n";
142 print "<br>\n";
143 print "<select name=mods1 size=$mp multiple>\n";
144 for($i=0; $i<$mp; $i++) {
145         printf "<option value=%s %s>%s\n",
146                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
147                 $mods[$i]->{'desc'};
148         }
149 print "</select>\n";
150 print "<select name=mods2 size=$mp multiple>\n";
151 for($i=$mp; $i<$mp*2; $i++) {
152         printf "<option value=%s %s>%s\n",
153                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
154                 $mods[$i]->{'desc'};
155         }
156 print "</select>\n";
157 print "<select name=mods3 size=$mp multiple>\n";
158 for($i=$mp*2; $i<@mods; $i++) {
159         printf "<option value=%s %s>%s\n",
160                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
161                 $mods[$i]->{'desc'};
162         }
163 print "</select>\n";
164
165 print "<br>\n";
166 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = true; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = true; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = true; } return false'>$text{'user_sall'}</a>&nbsp;\n";
167 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = false; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = false; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = false; } return false'>$text{'user_snone'}</a>&nbsp;\n";
168 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = !document.forms[0].mods1.options[i].selected; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = !document.forms[0].mods2.options[i].selected; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = !document.forms[0].mods3.options[i].selected; } return false'>$text{'user_sinvert'}</a><br>\n";
169
170 print "</td> </tr>\n";
171
172 print "</table></td></tr></table>\n";
173 print "<table width=100%><tr>\n";
174 print "<td><input type=submit value='$text{'save'}'></td></form>\n";
175
176 %mdesc = map { $_->{'dir'}, $_->{'desc'} } @mods;
177 foreach $h (@hosts) {
178         local %ingroup;
179         foreach $g (@{$h->{'groups'}}) {
180                 map { $ingroup{$_}++ } @{$g->{'members'}};
181                 }
182         local ($u) = grep { $_->{'name'} eq $in{'user'} } @{$h->{'users'}};
183         next if (!$u);
184         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
185         local $d = &server_name($s);
186         $sel .= "<option value='$h->{'id'},'>".&text('user_aclhg', $d)."\n"
187                 if (!$ingroup{$in{'user'}});
188         foreach $m (@{$h->{'modules'}}) {
189                 local @um = $ingroup{$in{'user'}} ? @{$u->{'ownmods'}}
190                                                   : @{$u->{'modules'}};
191                 next if (&indexof($m->{'dir'}, @um) < 0);
192                 $sel .= "<option value='$h->{'id'},$m->{'dir'}'>".
193                         &text('user_aclh', $m->{'desc'}, $d)."\n";
194                 }
195         }
196 if ($sel) {
197         print "<form action=edit_acl.cgi><td align=center>\n";
198         print "<input type=hidden name=user value='$in{'user'}'>\n";
199         print "<input type=submit value='$text{'user_acl'}'>\n";
200         print "<select name=modhost>\n";
201         print $sel;
202         print "</select></td></form>\n";
203         }
204
205 print "<form action=delete_user.cgi>\n";
206 print "<input type=hidden name=user value=\"$in{'user'}\">\n";
207 print "<td align=right><input type=submit value='$text{'delete'}'></td></form>\n";
208 print "</tr></table>\n";
209
210 # Show hosts with the user
211 print &ui_hr();
212 print &ui_subheading($text{'user_hosts'});
213 @icons = map { "/servers/images/$_->{'type'}.gif" } @got;
214 @links = map { "edit_host.cgi?id=$_->{'id'}" } @got;
215 @titles = map { &server_name($_) } @got;
216 &icons_table(\@links, \@titles, \@icons);
217
218 &ui_print_footer("", $text{'index_return'});
219