3 # Display a form for editing a user, or creating a new user
5 require './cluster-useradmin-lib.pl';
6 require 'timelocal.pl';
8 &foreign_require("useradmin", "user-lib.pl");
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'}};
19 local ($u) = grep { $_->{'user'} eq $in{'user'} } @{$h->{'users'}};
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'}, "");
32 # build list of used shells
34 foreach $u (@{$h->{'users'}}) {
35 push(@shlist, $u->{'shell'}) if ($u->{'shell'});
38 open(SHELLS, "/etc/shells");
42 push(@shlist, $_) if (/\S/);
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";
53 print "<tr> <td><b>$text{'user'}</b></td>\n";
54 print "<td><input name=user size=10 value=\"$uinfo{'user'}\"></td> </tr>\n";
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",
61 print "<input name=uid size=10></td> </tr>\n";
63 if ($uconfig{'extra_real'}) {
64 local @real = split(/,/, $uinfo{'real'}, 5);
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",
71 print "<input name=real size=20></td> </tr>\n";
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",
78 print "<input name=office size=20></td> </tr>\n";
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",
85 print "<input name=workph size=20></td> </tr>\n";
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",
92 print "<input name=homeph size=20></td> </tr>\n";
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",
99 print "<input name=extra size=20></td> </tr>\n";
102 if (length($uinfo{'real'}) > 20) {
103 $uinfo{'real'} =~ s/,.*$//;
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",
111 print "<input name=real size=30></td> </tr>\n";
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",
121 printf "<input type=radio name=home_def value=0> %s\n",
123 print "<input name=home size=30> ",&file_chooser_button("home", 1),
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",
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 "" ? "<None>" : $s;
137 print "</select></td>\n";
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",
150 printf "<input name=encpass size=13></td> </tr>\n";
152 print "</table></td></tr></table><p>\n";
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",
166 &date_input("", "", "", 'change');
167 print " <input name=changeh size=3>";
168 print ":<input name=changemi size=3></td> </tr>\n";
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",
176 &date_input("", "", "", 'expire');
177 print " <input name=expireh size=3>";
178 print ":<input name=expiremi size=3></td> </tr>\n";
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",
186 print "<input name=class size=10></td> </tr>\n";
188 print "</table></td></tr></table><p>\n";
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";
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)));
201 $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900;
203 else { print "$text{'uedit_unknown'}\n"; }
205 print "<input type=checkbox name=forcechange value=1> ",
206 "$text{'uedit_forcechange'}\n";
208 print "</td> </tr>\n";
210 print "<td><b>$text{'expire'}</b></td> <td>\n";
211 if ($uinfo{'expire'}) {
212 @tm = localtime($uinfo{'expire'} * 60*60*24);
215 $eyear = $tm[5]+1900;
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",
222 &date_input(undef, undef, undef, 'expire');
223 print "</td> </tr>\n";
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",
231 print "<input size=5 name=min></td> </tr>\n";
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",
239 print "<input size=5 name=max></td></tr>\n";
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",
247 print "<input size=5 name=warn></td> </tr>\n";
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",
255 print "<input size=5 name=inactive></td></tr>\n";
257 print "</table></td></tr></table><p>\n";
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";
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];
272 else { print "<td>$text{'uedit_unknown'}</td> </tr>\n"; }
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)/;
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",
296 &date_input(undef, undef, undef, 'expire');
297 print " <input name=expireh size=3>";
298 print "<b>:</b><input name=expiremi size=3></td> </tr>\n";
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",
306 print "<input size=5 name=min></td> </tr>\n";
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",
314 print "<input size=5 name=max></td></tr>\n";
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",
322 print "<input size=5 name=warn></td> </tr>\n";
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",
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";
337 print "</table></td></tr></table><p>\n";
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";
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",
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";
353 foreach $g (@{$host->{'groups'}}) {
354 @mems = split(/,/ , $g->{'members'});
355 push(@ugroups, $g->{'group'}) if (&indexof($uinfo{'user'}, @mems) >= 0);
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";
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";
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";
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";
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";
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";
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";
401 print "</table></td> </tr></table><p>\n";
403 print "<table width=100%>\n";
404 print "<tr> <td><input type=submit value=\"$text{'save'}\"></td>\n";
406 # Find the servers this user is on
407 foreach $h (@hosts) {
408 local ($ou) = grep { $_->{'user'} eq $in{'user'} } @{$h->{'users'}};
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'});
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";
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";
437 print &ui_subheading($text{'uedit_hosts'});
438 &icons_table(\@links, \@titles, \@icons);
440 &ui_print_footer("", $text{'index_return'});
442 # date_input(day, month, year, prefix)
445 print "<input name=$_[3]d size=3 value='$_[0]'>";
446 print "/<select name=$_[3]m>\n";
449 printf "<option value=%d %s>%s\n",
450 $m, $_[1] eq $m ? 'selected' : '', $text{"smonth_$m"};
453 print "/<input name=$_[3]y size=5 value='$_[2]'>";
454 print &date_chooser_button("$_[3]d", "$_[3]m", "$_[3]y");