Handle hostnames with upper-case letters
[webmin.git] / cluster-useradmin / edit_user.cgi
1 #!/usr/local/bin/perl
2 # edit_user.cgi
3 # Display a form for editing a user, or creating a new user
4
5 require './cluster-useradmin-lib.pl';
6 require 'timelocal.pl';
7 &ReadParse();
8 &foreign_require("useradmin", "user-lib.pl");
9
10 @hosts = &list_useradmin_hosts();
11 @servers = &list_servers();
12 if ($in{'host'} ne '') {
13         ($host) = grep { $_->{'id'} == $in{'host'} } @hosts;
14         local ($u) = grep { $_->{'user'} eq $in{'user'} } @{$host->{'users'}};
15         %uinfo = %$u;
16         }
17 else {
18         foreach $h (@hosts) {
19                 local ($u) = grep { $_->{'user'} eq $in{'user'} } @{$h->{'users'}};
20                 if ($u) {
21                         $host = $h;
22                         %uinfo = %$u;
23                         last;
24                         }
25                 }
26         }
27 ($serv) = grep { $_->{'id'} == $host->{'id'} } @servers;
28 $desc = &text('uedit_host', $serv->{'desc'} ?
29                 $serv->{'desc'} : $serv->{'host'});
30 &ui_print_header(undef, $text{'uedit_title'}, "");
31
32 # build list of used shells
33 foreach $h (@hosts) {
34         foreach $u (@{$h->{'users'}}) {
35                 push(@shlist, $u->{'shell'}) if ($u->{'shell'});
36                 }
37         }
38 open(SHELLS, "/etc/shells");
39 while(<SHELLS>) {
40         s/\r|\n//g;
41         s/#.*$//;
42         push(@shlist, $_) if (/\S/);
43         }
44 close(SHELLS);
45
46 print "<form action=save_user.cgi method=post>\n";
47 print "<input type=hidden name=olduser value=\"$in{'user'}\">\n";
48 print "<input type=hidden name=host value=\"$host->{'id'}\">\n";
49 print "<table border width=100%>\n";
50 print "<tr $tb> <td><b>$text{'uedit_details'}</b></td> </tr>\n";
51 print "<tr $cb> <td><table width=100%>\n";
52
53 print "<tr> <td><b>$text{'user'}</b></td>\n";
54 print "<td><input name=user size=10 value=\"$uinfo{'user'}\"></td> </tr>\n";
55
56 print "<tr> <td><b>$text{'uid'}</b></td>\n";
57 printf "<td><input type=radio name=uid_def value=1 checked> %s (%s)\n",
58         $text{'uedit_leave'}, $uinfo{'uid'};
59 printf "<input type=radio name=uid_def value=0> %s\n",
60         $text{'uedit_set'};
61 print "<input name=uid size=10></td> </tr>\n";
62
63 if ($uconfig{'extra_real'}) {
64         local @real = split(/,/, $uinfo{'real'}, 5);
65
66         print "<tr> <td><b>$text{'real'}</b></td> <td>\n";
67         printf "<input type=radio name=real_def value=1 checked> %s (%s)\n",
68                 $text{'uedit_leave'}, $real[0] ? $real[0] : $text{uedit_none};
69         printf "<input type=radio name=real_def value=0> %s\n",
70                 $text{'uedit_set'};
71         print "<input name=real size=20></td> </tr>\n";
72
73         print "<tr> <td><b>$text{'office'}</b></td> <td>\n";
74         printf "<input type=radio name=office_def value=1 checked> %s (%s)\n",
75                 $text{'uedit_leave'}, $real[1] ? $real[1] : $text{uedit_none};
76         printf "<input type=radio name=office_def value=0> %s\n",
77                 $text{'uedit_set'};
78         print "<input name=office size=20></td> </tr>\n";
79
80         print "<tr> <td><b>$text{'workph'}</b></td> <td>\n";
81         printf "<input type=radio name=workph_def value=1 checked> %s (%s)\n",
82                 $text{'uedit_leave'}, $real[2] ? $real[2] : $text{uedit_none};
83         printf "<input type=radio name=workph_def value=0> %s\n",
84                 $text{'uedit_set'};
85         print "<input name=workph size=20></td> </tr>\n";
86
87         print "<tr> <td><b>$text{'homeph'}</b></td> <td>\n";
88         printf "<input type=radio name=homeph_def value=1 checked> %s (%s)\n",
89                 $text{'uedit_leave'}, $real[3] ? $real[3] : $text{uedit_none};
90         printf "<input type=radio name=homeph_def value=0> %s\n",
91                 $text{'uedit_set'};
92         print "<input name=homeph size=20></td> </tr>\n";
93
94         print "<tr> <td><b>$text{'extra'}</b></td> <td>\n";
95         printf "<input type=radio name=extra_def value=1 checked> %s (%s)\n",
96                 $text{'uedit_leave'}, $real[4] ? $real[4] : $text{uedit_none};
97         printf "<input type=radio name=extra_def value=0> %s\n",
98                 $text{'uedit_set'};
99         print "<input name=extra size=20></td> </tr>\n";
100         }
101 else {
102         if (length($uinfo{'real'}) > 20) {
103                 $uinfo{'real'} =~ s/,.*$//;
104                 }
105         print "<tr> <td><b>$text{'real'}</b></td> <td>\n";
106         printf "<input type=radio name=real_def value=1 checked> %s (%s)\n",
107                 $text{'uedit_leave'},
108                 $uinfo{'real'} ? $uinfo{'real'} : $text{uedit_none};
109         printf "<input type=radio name=real_def value=0> %s\n",
110                 $text{'uedit_set'};
111         print "<input name=real size=30></td> </tr>\n";
112         }
113
114 print "<tr> <td><b>$text{'home'}</b></td>\n";
115 printf "<td><input type=radio name=home_def value=1 checked> %s (%s)\n",
116         $text{'uedit_leave'}, $uinfo{'home'};
117 if ($uconfig{'home_base'}) {
118         printf "<input type=radio name=home_def value=2> %s\n",
119                 $text{'uedit_auto'};
120         }
121 printf "<input type=radio name=home_def value=0> %s\n",
122         $text{'uedit_set'};
123 print "<input name=home size=30> ",&file_chooser_button("home", 1),
124       "</td> </tr>\n";
125
126 print "<tr> <td><b>$text{'shell'}</b></td>\n";
127 printf "<td><input type=radio name=shell_def value=1 checked> %s (%s)\n",
128         $text{'uedit_leave'}, $uinfo{'shell'};
129 printf "<input type=radio name=shell_def value=0> %s\n",
130         $text{'uedit_set'};
131 print "<select name=shell>\n";
132 @shlist = &unique(@shlist);
133 foreach $s (@shlist) {
134         printf "<option value='%s'>%s\n", $s,
135                 $s eq "" ? "&lt;None&gt;" : $s;
136         }
137 print "</select></td>\n";
138
139 print "<tr> <td valign=top><b>$text{'pass'}</b></td>\n";
140 printf "<td><input type=radio name=passmode value=-1 checked> %s (%s)\n",
141         $text{'uedit_leave'}, $uinfo{'pass'};
142 printf "<input type=radio name=passmode value=0> %s\n",
143         $uconfig{'empty_mode'} ? $text{'none1'} : $text{'none2'};
144 printf "<input type=radio name=passmode value=1> %s<br>\n", $text{'nologin'};
145 printf "<input type=radio name=passmode value=3> %s\n", $text{'clear'};
146 printf "<input %s name=pass size=15>\n",
147         $uconfig{'passwd_stars'} ? "type=password" : "";
148 printf "<input type=radio name=passmode value=2> %s\n",
149         $text{'encrypted'};
150 printf "<input name=encpass size=13></td> </tr>\n";
151
152 print "</table></td></tr></table><p>\n";
153
154 $pft = &foreign_call("useradmin", "passfiles_type");
155 if ($pft == 1 || $pft == 6) {
156         # This is a BSD system.. a few extra password options are supported
157         print "<table border width=100%>\n";
158         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
159         print "<tr $cb> <td><table width=100%>\n";
160         print "<tr> <td><b>$text{'change2'}</b></td> <td>\n";
161         printf "<input type=radio name=change_def value=1 checked> %s (%s)\n",
162                 $text{'uedit_leave'}, $uinfo{'change'} ?
163                     scalar(localtime($uinfo{'change'})) : $text{'uedit_none'};
164         printf "<input type=radio name=change_def value=0> %s\n",
165                 $text{'uedit_set'};
166         &date_input("", "", "", 'change');
167         print " &nbsp; <input name=changeh size=3>";
168         print ":<input name=changemi size=3></td> </tr>\n";
169
170         print "<tr> <td><b>$text{'expire2'}</b></td> <td>\n";
171         printf "<input type=radio name=expire_def value=1 checked> %s (%s)\n",
172                 $text{'uedit_leave'}, $uinfo{'expire'} ?
173                     scalar(localtime($uinfo{'expire'})) : $text{'uedit_none'};
174         printf "<input type=radio name=expire_def value=0> %s\n",
175                 $text{'uedit_set'};
176         &date_input("", "", "", 'expire');
177         print " &nbsp; <input name=expireh size=3>";
178         print ":<input name=expiremi size=3></td> </tr>\n";
179
180         print "<tr> <td><b>$text{'class'}</b></td> <td>\n";
181         printf "<input type=radio name=class_def value=1 checked> %s (%s)\n",
182                 $text{'uedit_leave'}, $uinfo{'class'} ? $uinfo{'class'}
183                                                       : $text{'uedit_none'};
184         printf "<input type=radio name=class_def value=0> %s\n",
185                 $text{'uedit_set'};
186         print "<input name=class size=10></td> </tr>\n";
187
188         print "</table></td></tr></table><p>\n";
189         }
190 elsif ($pft == 2) {
191         # System has a shadow password file as well.. which means it supports
192         # password expiry and so on
193         print "<table border width=100%>\n";
194         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
195         print "<tr $cb> <td><table width=100%>\n";
196
197         print "<tr> <td><b>$text{'change'}</b></td> <td>\n";
198         if ($uinfo{'change'}) {
199                 @tm = localtime(timelocal(gmtime($uinfo{'change'} * 60*60*24)));
200                 printf "%s/%s/%s\n",
201                         $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900;
202                 }
203         else { print "$text{'uedit_unknown'}\n"; }
204         if ($uinfo{'max'}) {
205                 print "<input type=checkbox name=forcechange value=1> ",
206                       "$text{'uedit_forcechange'}\n";
207                 }
208         print "</td> </tr>\n";
209
210         print "<td><b>$text{'expire'}</b></td> <td>\n";
211         if ($uinfo{'expire'}) {
212                 @tm = localtime($uinfo{'expire'} * 60*60*24);
213                 $eday = $tm[3];
214                 $emon = $tm[4]+1;
215                 $eyear = $tm[5]+1900;
216                 }
217         printf "<input type=radio name=expire_def value=1 checked> %s (%s)\n",
218                 $text{'uedit_leave'}, $uinfo{'expire'} ? "$eday/$emon/$eyear"
219                                                        : $text{'uedit_none'};
220         printf "<input type=radio name=expire_def value=0> %s\n",
221                 $text{'uedit_set'};
222         &date_input(undef, undef, undef, 'expire');
223         print "</td> </tr>\n";
224
225         print "<tr> <td><b>$text{'min'}</b></td>\n";
226         printf "<td><input type=radio name=min_def value=1 checked> %s (%s)\n",
227                 $text{'uedit_leave'}, $uinfo{'min'} ? $uinfo{'min'}
228                                                     : $text{'uedit_none'};
229         printf "<input type=radio name=min_def value=0> %s\n",
230                 $text{'uedit_set'};
231         print "<input size=5 name=min></td> </tr>\n";
232
233         print "<tr> <td><b>$text{'max'}</b></td>\n";
234         printf "<td><input type=radio name=max_def value=1 checked> %s (%s)\n",
235                 $text{'uedit_leave'}, $uinfo{'max'} ? $uinfo{'max'}
236                                                     : $text{'uedit_none'};
237         printf "<input type=radio name=max_def value=0> %s\n",
238                 $text{'uedit_set'};
239         print "<input size=5 name=max></td></tr>\n";
240
241         print "<tr> <td><b>$text{'warn'}</b></td>\n";
242         printf "<td><input type=radio name=warn_def value=1 checked> %s (%s)\n",
243                 $text{'uedit_leave'}, $uinfo{'warn'} ? $uinfo{'warn'}
244                                                      : $text{'uedit_none'};
245         printf "<input type=radio name=warn_def value=0> %s\n",
246                 $text{'uedit_set'};
247         print "<input size=5 name=warn></td> </tr>\n";
248
249         print "<tr> <td><b>$text{'inactive'}</b></td> <td>\n";
250         printf "<input type=radio name=inactive_def value=1 checked> %s (%s)\n",
251                 $text{'uedit_leave'}, $uinfo{'inactive'} ? $uinfo{'inactive'}
252                                                          : $text{'uedit_none'};
253         printf "<input type=radio name=inactive_def value=0> %s\n",
254                 $text{'uedit_set'};
255         print "<input size=5 name=inactive></td></tr>\n";
256
257         print "</table></td></tr></table><p>\n";
258         }
259 elsif ($pft == 4) {
260         # This is an AIX system
261         print "<table border width=100%>\n";
262         print "<tr $tb> <td><b>$text{'uedit_passopts'}</b></td> </tr>\n";
263         print "<tr $cb> <td><table width=100%>\n";
264
265         print "<tr> <td><b>$text{'change'}</b></td>\n";
266         if ($uinfo{'change'}) {
267                 @tm = localtime($uinfo{'change'});
268                 printf "<td>%s/%s/%s %2.2d:%2.2d:%2.2d</td> </tr>\n",
269                         $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900,
270                         $tm[2], $tm[1], $tm[0];
271                 }
272         else { print "<td>$text{'uedit_unknown'}</td> </tr>\n"; }
273
274         print "<td><b>$text{'expire'}</b></td> <td>\n";
275         if ($uinfo{'expire'}) {
276                 $uinfo{'expire'} =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
277                 $emon = $1;
278                 $eday = $2;
279                 $ehour = $3;
280                 $emin = $4;
281                 $eyear = $5;
282                 if ($eyear > 38) {
283                         $eyear += 1900;
284                         }
285                 else {
286                         $eyear += 2000;
287                         }
288                 }
289         $emon =~ s/0(\d)/$1/;   # strip leading 0 
290         printf "<input type=radio name=expire_def value=1 checked> %s (%s)\n",
291                 $text{'uedit_leave'},
292                 $uinfo{'expire'} ? "$eday/$emon/$eyear $ehour:$emin"
293                                  : $text{'uedit_none'};
294         printf "<input type=radio name=expire_def value=0> %s\n",
295                 $text{'uedit_set'};
296         &date_input(undef, undef, undef, 'expire');
297         print " &nbsp; <input name=expireh size=3>";
298         print "<b>:</b><input name=expiremi size=3></td> </tr>\n";
299
300         print "<tr> <td><b>$text{'min_weeks'}</b></td>\n";
301         printf "<td><input type=radio name=min_def value=1 checked> %s (%s)\n",
302                 $text{'uedit_leave'}, $uinfo{'min'} ? $uinfo{'min'}
303                                                     : $text{'uedit_none'};
304         printf "<input type=radio name=min_def value=0> %s\n",
305                 $text{'uedit_set'};
306         print "<input size=5 name=min></td> </tr>\n";
307
308         print "<td><b>$text{'max_weeks'}</b></td>\n";
309         printf "<td><input type=radio name=max_def value=1 checked> %s (%s)\n",
310                 $text{'uedit_leave'}, $uinfo{'max'} ? $uinfo{'max'}
311                                                     : $text{'uedit_none'};
312         printf "<input type=radio name=max_def value=0> %s\n",
313                 $text{'uedit_set'};
314         print "<input size=5 name=max></td></tr>\n";
315
316         print "<tr> <td valign=top><b>$text{'warn'}</b></td>\n";
317         printf "<td><input type=radio name=warn_def value=1 checked> %s (%s)\n",
318                 $text{'uedit_leave'}, $uinfo{'warn'} ? $uinfo{'warn'}
319                                                      : $text{'uedit_none'};
320         printf "<input type=radio name=warn_def value=0> %s\n",
321                 $text{'uedit_set'};
322         print "<input size=5 name=warn></td> </tr>\n";
323
324         print "<td valign=top><b>$text{'flags'}</b></td> <td>\n";
325         printf "<input type=radio name=flags_def value=1 checked> %s\n",
326                 $text{'uedit_leave'};
327         printf "<input type=radio name=flags_def value=0> %s\n",
328                 $text{'uedit_set'};
329         printf "<input type=checkbox name=flags value=admin %s> %s<br>\n",
330                 $text{'uedit_admin'};
331         printf "<input type=checkbox name=flags value=admchg %s> %s<br>\n",
332                 $text{'uedit_admchg'};
333         printf "<input type=checkbox name=flags value=nocheck %s> %s\n",
334                 $text{'uedit_nocheck'};
335         print "</td> </tr>\n";
336
337         print "</table></td></tr></table><p>\n";
338         }
339
340 # Output group memberships
341 print "<table border width=100%>\n";
342 print "<tr $tb> <td><b>$text{'uedit_gmem'}</b></td> </tr>\n";
343 print "<tr $cb> <td><table width=100%>\n";
344
345 print "<tr> <td><b>$text{'group'}</b></td>\n";
346 printf "<td><input type=radio name=gid_def value=1 checked> %s (%s)\n",
347         $text{'uedit_leave'}, scalar(getgrgid($uinfo{'gid'}));
348 printf "<input type=radio name=gid_def value=0> %s\n",
349         $text{'uedit_set'};
350 printf "<input name=gid size=8>\n";
351 print "<input type=button onClick='ifield = document.forms[0].gid; chooser = window.open(\"/useradmin/my_group_chooser.cgi?multi=0&group=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=300,height=200\"); chooser.ifield = ifield' value=\"...\"></td> </tr>\n";
352
353 foreach $g (@{$host->{'groups'}}) {
354         @mems = split(/,/ , $g->{'members'});
355         push(@ugroups, $g->{'group'}) if (&indexof($uinfo{'user'}, @mems) >= 0);
356         }
357 print "<tr> <td valign=top><b>$text{'uedit_2nd'}</b></td> <td>\n";
358 printf "<input type=radio name=sgid_def value=0 checked> %s (%s)<br>\n",
359         $text{'uedit_leave'},
360         @ugroups ? join(", ", @ugroups) : $text{'uedit_none'};
361 printf "<input type=radio name=sgid_def value=1> %s\n",
362         $text{'uedit_addto'};
363 printf "<input name=sgidadd size=40> %s<br>\n",
364         &group_chooser_button("sgidadd", 1);
365 printf "<input type=radio name=sgid_def value=2> %s\n",
366         $text{'uedit_delfrom'};
367 printf "<input name=sgiddel size=40> %s</td> </tr>\n",
368         &group_chooser_button("sgiddel", 1);
369 print "</table></td></tr></table><p>\n";
370
371 print "<table border width=100%>\n";
372 print "<tr $tb> <td><b>$text{'onsave'}</b></td> </tr>\n";
373 print "<tr $cb> <td><table>\n";
374
375 print "<tr> <td><b>$text{'uedit_movehome'}</b></td>\n";
376 print "<td><input type=radio name=movehome value=1 checked> $text{'yes'}</td>\n";
377 print "<td><input type=radio name=movehome value=0> $text{'no'}</td> </tr>\n";
378
379 print "<tr> <td><b>$text{'uedit_chuid'}</b></td>\n";
380 print "<td><input type=radio name=chuid value=0> $text{'no'}</td>\n";
381 print "<td><input type=radio name=chuid value=1 checked> ",
382       "$text{'home'}</td>\n";
383 print "<td><input type=radio name=chuid value=2> ",
384       "$text{'uedit_allfiles'}</td></tr>\n";
385
386 print "<tr> <td><b>$text{'chgid'}</b></td>\n";
387 print "<td><input type=radio name=chgid value=0> $text{'no'}</td>\n";
388 print "<td><input type=radio name=chgid value=1 checked> ".
389       "$text{'home'}</td>\n";
390 print "<td><input type=radio name=chgid value=2> ",
391       "$text{'uedit_allfiles'}</td></tr>\n";
392
393 print "<tr> <td><b>$text{'uedit_servs'}</b></td>\n";
394 print "<td><input type=radio name=servs value=1> $text{'uedit_mall'}</td>\n";
395 print "<td><input type=radio name=servs value=0 checked> $text{'uedit_mthis'}</td> </tr>\n";
396
397 print "<tr> <td><b>$text{'uedit_mothers'}</b></td>\n";
398 print "<td><input type=radio name=others value=1 checked> $text{'yes'}</td>\n";
399 print "<td><input type=radio name=others value=0> $text{'no'}</td> </tr>\n";
400
401 print "</table></td> </tr></table><p>\n";
402
403 print "<table width=100%>\n";
404 print "<tr> <td><input type=submit value=\"$text{'save'}\"></td>\n";
405
406 # Find the servers this user is on
407 foreach $h (@hosts) {
408         local ($ou) = grep { $_->{'user'} eq $in{'user'} } @{$h->{'users'}};
409         if ($ou) {
410                 local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
411                 push(@icons, "/servers/images/$s->{'type'}.gif");
412                 push(@links, "edit_host.cgi?id=$h->{'id'}");
413                 push(@titles, $s->{'desc'} ? $s->{'desc'} : $s->{'host'});
414                 }
415         }
416 if (@icons < @hosts) {
417         # Offer to create on all servers
418         print "</form><form action=\"sync.cgi\">\n";
419         print "<input type=hidden name=makehome value=1>\n";
420         print "<input type=hidden name=copy_files value=1>\n";
421         print "<input type=hidden name=server value=-1>\n";
422         print "<input type=hidden name=users_mode value=2>\n";
423         print "<input type=hidden name=usel value='$uinfo{'user'}'>\n";
424         print "<input type=hidden name=groups_mode value=0>\n";
425         print "<input type=hidden name=user value=\"$uinfo{'user'}\">\n";
426         print "<td align=middle><input type=submit ",
427               "value=\"$text{'uedit_sync'}\"></td>\n";
428         }
429
430 print "</form><form action=\"delete_user.cgi\">\n";
431 print "<input type=hidden name=user value=\"$uinfo{'user'}\">\n";
432 print "<td align=right><input type=submit ",
433       "value=\"$text{'delete'}\"></td> </tr>\n";
434 print "</form></table><p>\n";
435
436 print &ui_hr();
437 print &ui_subheading($text{'uedit_hosts'});
438 &icons_table(\@links, \@titles, \@icons);
439
440 &ui_print_footer("", $text{'index_return'});
441
442 # date_input(day, month, year, prefix)
443 sub date_input
444 {
445 print "<input name=$_[3]d size=3 value='$_[0]'>";
446 print "/<select name=$_[3]m>\n";
447 local $m;
448 foreach $m (1..12) {
449         printf "<option value=%d %s>%s\n",
450                 $m, $_[1] eq $m ? 'selected' : '', $text{"smonth_$m"};
451         }
452 print "</select>";
453 print "/<input name=$_[3]y size=5 value='$_[2]'>";
454 print &date_chooser_button("$_[3]d", "$_[3]m", "$_[3]y");
455 }
456