#!/usr/local/bin/perl # edit_user.cgi # Display a form for editing a user, or creating a new user require './user-lib.pl'; require 'timelocal.pl'; &ReadParse(); $n = $in{'num'}; %access = &get_module_acl(); if ($n eq "") { $access{'ucreate'} || &error($text{'uedit_ecreate'}); &ui_print_header(undef, $text{'uedit_title2'}, "", "create_user"); } else { @ulist = &list_users(); %uinfo = %{$ulist[$n]}; &can_edit_user(\%access, \%uinfo) || &error($text{'uedit_eedit'}); &ui_print_header(undef, $text{'uedit_title'}, "", "edit_user"); } # build list of used shells %shells = map { $_, 1 } split(/,/, $config{'shells'}); @shlist = ($config{'default_shell'} ? ( $config{'default_shell'} ) : ( )); push(@shlist, "/bin/sh", "/bin/csh", "/bin/false") if ($shells{'fixed'}); &build_user_used(\%used, $shells{'passwd'} ? \@shlist : undef); if ($shells{'shells'}) { open(SHELLS, "/etc/shells"); while() { s/\r|\n//g; s/#.*$//; push(@shlist, $_) if (/\S/); } close(SHELLS); } if (%uinfo) { push(@shlist, $uinfo{'shell'}); } print "
\n"; if ($n ne "") { print "\n"; } print "\n"; print "\n"; print "
$text{'uedit_details'}
\n"; print "\n"; if ($n eq "" && $config{'new_user_group'} && $access{'gcreate'}) { $onch = "newgid.value = user.value"; } if ($access{'urename'} || $n eq "") { print "\n"; } else { print "\n"; print &ui_hidden("user", $uinfo{'user'}),"\n"; } print "\n"; if ($n eq "") { $defuid = &allocate_uid(\%used); print "\n"; } else { print "\n"; } if ($config{'extra_real'}) { local @real = split(/,/, $uinfo{'real'}, 5); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } else { print "\n"; print "\n"; } # Show input for home directory print "\n"; if ($access{'autohome'}) { print "\n"; } else { print "\n"; # Show shell drop-down print "\n"; print "\n"; # Show password field $pass = %uinfo ? $uinfo{'pass'} : $config{'lock_string'}; if (!%uinfo && $config{'random_password'}) { &seed_random(); foreach (1 .. 15) { $random_password .= $random_password_chars[ rand(scalar(@random_password_chars))]; } } if (%uinfo && $pass ne $config{'lock_string'} && $pass ne "") { # Can disable if not already locked, or if a new account $can_disable = 1; if ($pass =~ /^\Q$disable_string\E/) { $disabled = 1; $pass =~ s/^\Q$disable_string\E//; } } elsif (!%uinfo) { $can_disable = 1; } print "\n"; # Show other-shell option if (!$shells) { print "\n"; print "\n"; print "\n"; } print "
",&hlink("$text{'user'}","user"),"$uinfo{'user'}",&hlink("$text{'uid'}","uid"),"\n"; if ( $access{'calcuid'} && $access{'autouid'} && $access{'useruid'} ) { # Show options for calculated, auto-incremented and user entered UID printf " %s\n", $config{'uid_mode'} eq '1' ? "checked" : "", $text{'uedit_uid_def'}; printf " %s\n", $config{'uid_mode'} eq '2' ? "checked" : "", $text{'uedit_uid_calc'}; printf " %s\n", $config{'uid_mode'} eq '0' ? "checked" : "", ""; } if ( $access{'calcuid'} && $access{'autouid'} && !$access{'useruid'} ) { # Show options for calculated and auto-incremented UID printf " %s\n", $config{'uid_mode'} eq '1' ? "checked" : "", $text{'uedit_uid_def'}; printf " %s\n", $config{'uid_mode'} eq '2' ? "checked" : "", $text{'uedit_uid_calc'}; } if ( $access{'calcuid'} && !$access{'autouid'} && $access{'useruid'} ) { # Show options for calculated and user entered UID printf " %s\n", $config{'uid_mode'} eq '2' ? "checked" : "", $text{'uedit_uid_calc'}; printf " %s\n", $config{'uid_mode'} eq '0' ? "checked" : "", ""; } if ( !$access{'calcuid'} && $access{'autouid'} && $access{'useruid'} ) { # Show options for auto-incremented and user entered UID printf " %s\n", $config{'uid_mode'} eq '1' ? "checked" : "", $text{'uedit_uid_def'}; printf " %s\n", $config{'uid_mode'} eq '0' ? "checked" : "", ""; } if ( $access{'calcuid'} && !$access{'autouid'} && !$access{'useruid'} ) { # Hidden field for calculated UID print ""; print "$text{'uedit_uid_calc'}\n"; } if ( !$access{'calcuid'} && $access{'autouid'} && !$access{'useruid'} ) { # Hidden field for auto-incremented UID print ""; print "$text{'uedit_uid_calc'}\n"; } if ( !$access{'calcuid'} && !$access{'autouid'} && $access{'useruid'} ) { # Show field for user entered UID print ""; print "UID: \n"; } if ( !$access{'calcuid'} && !$access{'autouid'} && !$access{'useruid'} ) { if ( $config{'uid_mode'} eq '0' ) { print ""; print "UID: \n"; } else { print ""; print "$text{'uedit_uid_def'}\n" if ( $config{'uid_mode'} eq '1' ); print "$text{'uedit_uid_calc'}\n" if ( $config{'uid_mode'} eq '2' ); } } print "
",&hlink("$text{'real'}","real"),"",&hlink("$text{'office'}","office"),"
",&hlink("$text{'workph'}","workph"),"",&hlink("$text{'homeph'}","homeph"),"
",&hlink("$text{'extra'}","extra"),"
",&hlink("$text{'real'}","real"),"",&hlink("$text{'home'}","home"),"$text{'uedit_auto'} ", $n eq "" ? "" : "( $uinfo{'home'} )", "\n"; if ($config{'home_base'}) { local $grp = &my_getgrgid($uinfo{'gid'}); local $hb = $n eq "" || &auto_home_dir($config{'home_base'}, $uinfo{'user'}, $grp) eq $uinfo{'home'}; printf " %s\n", $hb ? "checked" : "", $text{'uedit_auto'}; printf "\n", $hb ? "" : "checked"; printf " %s\n", $hb ? "" : $uinfo{'home'}, &file_chooser_button("home", 1); } else { print "\n", &file_chooser_button("home", 1); } } print "
",&hlink("$text{'shell'}","shell"),"",&hlink("$text{'pass'}","pass"), " \n"; printf" %s
\n", $pass eq "" && $random_password eq "" ? "checked" : "", $config{'empty_mode'} ? $text{'none1'} : $text{'none2'}; printf" $text{'nologin'}
\n", $pass eq $config{'lock_string'} && $random_password eq "" ? "checked" : ""; printf " $text{'clear'}\n", $random_password ne "" ? "checked" : ""; printf "
\n", $config{'passwd_stars'} ? "type=password" : "", $config{'random_password'} && $n eq "" ? $random_password : ""; if ($access{'nocrypt'}) { printf " $text{'nochange'}\n", $pass && $pass ne $config{'lock_string'} && $random_password eq "" ? "checked" : ""; print "\n"; } else { printf " $text{'encrypted'}\n", $pass && $pass ne $config{'lock_string'} ? "checked" : ""; printf "\n", $pass && $pass ne $config{'lock_string'} ? $pass : ""; } # Show password lock checkbox if ($can_disable) { printf "
   ". " %s\n", $disabled ? "checked" : "", $text{'uedit_disabled'}; } print "
$text{'uedit_other'}\n"; print &file_chooser_button("othersh", 0),"

\n"; $pft = &passfiles_type(); if (($pft == 1 || $pft == 6) && $access{'peopt'}) { # This is a BSD system.. a few extra password options are supported print "\n"; print "\n"; print "
$text{'uedit_passopts'}
\n"; print "\n"; if ($uinfo{'change'}) { @tm = localtime($uinfo{'change'}); $cday = $tm[3]; $cmon = $tm[4]+1; $cyear = $tm[5]+1900; $chour = sprintf "%2.2d", $tm[2]; $cmin = sprintf "%2.2d", $tm[1]; } print "\n"; print "\n"; if ($n eq "") { if ($config{'default_expire'} =~ /^(\d+)\/(\d+)\/(\d+)$/) { $eday = $1; $emon = $2; $eyear = $3; $ehour = "00"; $emin = "00"; } } elsif ($uinfo{'expire'}) { @tm = localtime($uinfo{'expire'}); $eday = $tm[3]; $emon = $tm[4]+1; $eyear = $tm[5]+1900; $ehour = sprintf "%2.2d", $tm[2]; $emin = sprintf "%2.2d", $tm[1]; } print "\n"; print "\n"; print "\n"; print "\n"; print "
",&hlink("$text{'change2'}", "change2"),""; &date_input($cday, $cmon, $cyear, 'change'); print "   "; print ":",&hlink("$text{'expire2'}","expire2"),""; &date_input($eday, $emon, $eyear, 'expire'); print "   "; print ":
",&hlink("$text{'class'}","class"),"

\n"; } elsif (($pft == 2 || $pft == 5) && $access{'peopt'}) { # System has a shadow password file as well.. which means it supports # password expiry and so on print "\n"; print "\n"; print "
$text{'uedit_passopts'}
\n"; print "\n"; print "\n"; if ($pft == 2) { print "\n"; if ($n eq "") { if ($config{'default_expire'} =~ /^(\d+)\/(\d+)\/(\d+)$/) { $eday = $1; $emon = $2; $eyear = $3; } } elsif ($uinfo{'expire'}) { @tm = localtime(timelocal(gmtime($uinfo{'expire'} * 60*60*24))); $eday = $tm[3]; $emon = $tm[4]+1; $eyear = $tm[5]+1900; } print "\n"; } else { print "\n"; printf "\n", $uinfo{'change'} eq '0' ? '' : 'checked', $text{'no'}; } print "\n"; print "\n"; printf "\n", $n eq "" ? $config{'default_min'} : $uinfo{'min'}; print "\n"; printf "\n", $n eq "" ? $config{'default_max'} : $uinfo{'max'}; if ($pft == 2) { # SCO does not have these password file options print "\n"; printf "\n", $n eq "" ? $config{'default_warn'} : $uinfo{'warn'}; print "\n"; printf "\n", $n eq "" ? $config{'default_inactive'} : $uinfo{'inactive'}; } print "
",&hlink("$text{'change'}","change"),""; if ($uinfo{'change'}) { @tm = localtime(timelocal(gmtime($uinfo{'change'} * 60*60*24))); printf "%s/%s/%s\n", $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900; } elsif ($n eq "") { print "$text{'uedit_never'}\n"; } else { print "$text{'uedit_unknown'}\n"; } if ($uinfo{'max'} && $pft == 2) { print " ", "$text{'uedit_forcechange'}\n"; } print "",&hlink("$text{'expire'}","expire"), ""; &date_input($eday, $emon, $eyear, 'expire'); print "",&hlink("$text{'ask'}","ask")," %s\n", $uinfo{'change'} eq '0' ? 'checked' : '', $text{'yes'}; printf " %s
",&hlink("$text{'min'}","min"),"",&hlink("$text{'max'}","max"),"
",&hlink("$text{'warn'}","warn"),"",&hlink("$text{'inactive'}","inactive"),"

\n"; } elsif ($pft == 4 && $access{'peopt'}) { # System has extra AIX password information print "\n"; print "\n"; print "
$text{'uedit_passopts'}
\n"; print "\n"; if ($uinfo{'change'}) { @tm = localtime($uinfo{'change'}); printf "\n", $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900, $tm[2], $tm[1], $tm[0]; } elsif ($n eq "") { print "\n"; } else { print "\n"; } print "\n"; if ($uinfo{'expire'}) { $uinfo{'expire'} =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/; $emon = $1; $eday = $2; $ehour = $3; $emin = $4; $eyear = $5; if ($eyear > 38) { $eyear += 1900; } else { $eyear += 2000; } } $emon =~ s/0(\d)/$1/; # strip leading 0 print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
",&hlink("$text{'change'}","change"), "%s/%s/%s %2.2d:%2.2d:%2.2d$text{'uedit_never'}$text{'uedit_unknown'}",&hlink("$text{'expire'}","expire"),""; &date_input($eday, $emon, $eyear, 'expire'); print "   "; print ":
",&hlink("$text{'min_weeks'}","min_weeks"),"",&hlink("$text{'max_weeks'}","max_weeks"),"
",&hlink("$text{'warn'}","warn"),"",&hlink("$text{'flags'}","flags"), " \n"; printf " %s
\n", $uinfo{'admin'} ? 'checked' : '', $text{'uedit_admin'}; printf " %s
\n", $uinfo{'admchg'} ? 'checked' : '', $text{'uedit_admchg'}; printf " %s\n", $uinfo{'nocheck'} ? 'checked' : '', $text{'uedit_nocheck'}; print "

\n"; } # Output group memberships print "\n"; print "\n"; print "
$text{'uedit_gmem'}
\n"; print "\n"; } else { print "\n"; } if ($config{'secmode'} != 1) { # Work out which secondary groups the user is in @defsecs = &split_quoted_string($config{'default_secs'}); @glist = &list_groups(); @glist = sort { $a->{'group'} cmp $b->{'group'} } @glist if ($config{'sort_mode'}); %ingroups = ( ); foreach $g (@glist) { @mems = split(/,/ , $g->{'members'}); $ismem = &indexof($uinfo{'user'}, @mems) >= 0; if ($n eq "") { $ismem = 1 if (&indexof($g->{'group'}, @defsecs) >= 0); } $ingroups{$g->{'group'}} = $ismem; } print "\n"; } if ($config{'secmode'} == 0) { # Show secondary groups with select menu print "\n"; } elsif ($config{'secmode'} == 2) { # Show a text box @insecs = ( ); foreach $g (@glist) { if ($ingroups{$g->{'group'}}) { push(@insecs, $g->{'group'}); } } print "\n"; } else { # Don't show print "\n"; } print "\n"; print "
",&hlink("$text{'group'}","group"), " \n"; if ($n eq "" && $access{'gcreate'}) { printf " %s
\n", $config{'new_user_group'} ? 'checked' : '', $text{'uedit_samg'}; printf " %s\n", $text{'uedit_newg'}; print "
\n"; printf " %s\n", $config{'new_user_group'} ? '' : 'checked', $text{'uedit_oldg'}; } if ($access{'ugroups'} eq "*" || $access{'uedit_gmode'} >= 3) { local $w = 300; local $h = 200; if ($gconfig{'db_sizeuser'}) { ($w, $h) = split(/x/, $gconfig{'db_sizeuser'}); } printf "\n", $n eq "" ? $config{'default_group'} : scalar(&my_getgrgid($uinfo{'gid'})); print "
", &hlink("$text{'uedit_2nd'}","2nd"),"",&ui_textarea("sgid", join("\n", @insecs), 5, 20),"

\n"; if ($n ne "") { # Editing a user - show options for moving home directory, changing IDs # and updating in other modules if ($access{'movehome'} == 1 || $access{'chuid'} == 1 || $access{'chgid'} == 1 || $access{'mothers'} == 1) { print &ui_table_start($text{'onsave'}, "width=100%", 2, [ "width=30%" ]); # Move home directory if ($access{'movehome'} == 1) { print &ui_table_row( &hlink($text{'uedit_movehome'}, "movehome"), &ui_yesno_radio("movehome", 1)); } # Change UID on files if ($access{'chuid'} == 1) { print &ui_table_row( &hlink($text{'uedit_chuid'},"chuid"), &ui_radio("chuid", 1, [ [ 0, $text{'no'} ], [ 1, $text{'home'} ], [ 2, $text{'uedit_allfiles'} ] ])); } # Change GID on files if ($access{'chgid'} == 1) { print &ui_table_row( &hlink($text{'uedit_chgid'},"chgid"), &ui_radio("chgid", 1, [ [ 0, $text{'no'} ], [ 1, $text{'home'} ], [ 2, $text{'uedit_allfiles'} ] ])); } # Modify in other modules if ($access{'mothers'} == 1) { print &ui_table_row( &hlink($text{'uedit_mothers'},"others"), &ui_yesno_radio("others", $config{'default_other'} ? 1 : 0)); } # Rename group, if the same and if editable @ginfo = &my_getgrgid($uinfo{'gid'}); if ($ginfo[0] eq $uinfo{'user'}) { ($group) = grep { $_->{'gid'} == $uinfo{'gid'} } &list_groups(); if (&can_edit_group(\%access, $group)) { print &ui_table_row( &hlink($text{'uedit_grename'},"grename"), &ui_yesno_radio("grename", 1)); } } print &ui_table_end(),"

\n"; } } else { # Creating a user - show options for creating home directory, copying # skel files and creating in other modules if ($access{'makehome'} == 1 || $access{'copy'} == 1 || $access{'cothers'} == 1) { print "\n"; print "\n"; print "
$text{'uedit_oncreate'}
\n"; if ($access{'makehome'} == 1) { print "\n"; print "\n"; print "\n"; } if ($config{'user_files'} =~ /\S/ && $access{'copy'} == 1) { print "\n"; print "\n"; print "\n"; } if ($access{'cothers'} == 1) { print "\n"; printf "\n", $config{'default_other'} ? "checked" : ""; printf "\n", $config{'default_other'} ? "" : "checked"; } print "
",&hlink($text{'uedit_makehome'},"makehome")," $text{'yes'} $text{'no'}
",&hlink($text{'uedit_copy'}, "copy_files")," $text{'yes'} $text{'no'}
",&hlink($text{'uedit_cothers'},"others")," $text{'yes'} $text{'no'}

\n"; } } if ($n ne "") { print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; if (&foreign_available("mailboxes") && &foreign_installed("mailboxes", 1)) { # Link to the mailboxes module, if installed print "\n"; print "\n"; print "\n"; } if (&foreign_available("usermin") && &foreign_installed("usermin", 1) && (%uacl = &get_module_acl("usermin") && $uacl{'sessions'})) { # Link to Usermin module for switching to some user &foreign_require("usermin", "usermin-lib.pl"); local %uminiserv; &usermin::get_usermin_miniserv_config(\%uminiserv); if ($uminiserv{'session'}) { print "\n"; print "\n"; print "\n"; } } if ($access{'udelete'}) { print "\n"; print "\n"; print "\n"; print "\n"; } print "
\n"; print "
\n"; print "
\n"; print "", "

\n"; } else { print "

\n"; } &ui_print_footer("", $text{'index_return'});