#!/usr/local/bin/perl # edit_user.cgi # Display details of an existing user and allow editing require './ldap-useradmin-lib.pl'; use Time::Local; &ReadParse(); $ldap = &ldap_connect(); $schema = $ldap->schema(); if ($in{'new'}) { $access{'ucreate'} || &error($text{'uedit_ecreate'}); $pass = $mconfig{'lock_string'}; $shell = $mconfig{'default_shell'} if ($mconfig{'default_shell'}); foreach $oec (split(/\s+/, $config{'other_class'})) { $oclass{$oec}++; } if ($config{'samba_def'}) { $oclass{$samba_class}++; } if ($config{'imap_def'}) { @cyrus_class_3 = split(' ',$cyrus_class); $oclass{$cyrus_class_3[0]}++; } # Get initial values from form parameters foreach $n ("user", "firstname", "lastname", "real", "home", "shell", "gid", "pass", "change", "expire", "min", "max", "warn", "inactive") { if (defined($in{$n})) { $$n = $in{$n}; } } &ui_print_header(undef, $text{'uedit_title2'}, ""); } else { # Get values from current user $rv = $ldap->search(base => $in{'dn'}, scope => 'base', filter => '(objectClass=posixAccount)'); ($uinfo) = $rv->all_entries; @users = $uinfo->get_value('uid'); $user = $users[0]; $uid = $uinfo->get_value('uidNumber'); $firstname = $uinfo->get_value('givenName'); $lastname = $uinfo->get_value('sn'); $real = $uinfo->get_value('cn'); $home = $uinfo->get_value('homeDirectory'); $shell = $uinfo->get_value('loginShell'); $gid = $uinfo->get_value('gidNumber'); $pass = $uinfo->get_value('userPassword'); $change = $uinfo->get_value('shadowLastChange'); $expire = $uinfo->get_value('shadowExpire'); $min = $uinfo->get_value('shadowMin'); $max = $uinfo->get_value('shadowMax'); $warn = $uinfo->get_value('shadowWarning'); $inactive = $uinfo->get_value('shadowInactive'); foreach $oc ($uinfo->get_value('objectClass')) { $oclass{$oc} = 1; } @alias = $uinfo->get_value('alias'); %uinfo = &dn_to_hash($uinfo); &can_edit_user(\%uinfo) || &error($text{'uedit_eedit'}); &ui_print_header(undef, $text{'uedit_title'}, ""); } # build a list of used shells and uids @shlist = ($mconfig{'default_shell'} ? ( $mconfig{'default_shell'} ) : ( )); %shells = map { $_, 1 } split(/,/, $config{'shells'}); push(@shlist, "/bin/sh", "/bin/csh", "/bin/false") if ($shells{'fixed'}); if ($shells{'passwd'}) { # Don't do this unless we need to, as scanning all users is slow &build_user_used(undef, \@shlist); } if ($shells{'shells'}) { open(SHELLS, "/etc/shells"); while() { s/\r|\n//g; s/#.*$//; push(@shlist, $_) if (/\S/); } close(SHELLS); } push(@shlist, $shell) if ($shell); @shlist = &unique(@shlist); print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$text{'uedit_details'}
\n"; if (!$in{'new'}) { print "\n"; print "\n"; print "\n"; print "\n"; } # Show username input print "\n"; if (@users > 1) { print "\n"; } else { print "\n"; } # Show UID input, filled in with a default for new users print "\n"; if ($in{'new'}) { # Find the first free UID above the base $newuid = $mconfig{'base_uid'}; while(&check_uid_used($ldap, $newuid)) { $newuid++; } print "\n"; } else { print "\n"; } if ($config{'given'}) { # Show Full name inputs if ($in{'new'}) { $onch = "onChange='form.real.value = form.firstname.value+\" \"+form.lastname.value'"; } print "\n"; print "\n"; print "\n"; print "\n"; } # Show real name input print "\n"; print "\n"; # Show home directory input, with an 'automatic' option print "\n"; print "\n"; # Show shell selection menu print "\n"; print "\n"; # Show password fields if ($in{'new'} && $mconfig{'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$useradmin::disable_string\E/) { $disabled = 1; $pass =~ s/^\Q$useradmin::disable_string\E//; } } elsif (!%uinfo) { $can_disable = 1; } print "\n"; # Show alternate shell field print "\n"; print "\n"; print "\n"; print "
$text{'uedit_dn'}$in{'dn'}
$text{'uedit_classes'}",join(" , ", map { "$_" } $uinfo->get_value('objectClass')),"
$text{'user'}$text{'uid'}
$text{'uedit_firstname'}$text{'uedit_lastname'}
$text{'real'}$text{'home'}\n"; if ($mconfig{'home_base'}) { local $hb = $in{'new'} || &auto_home_dir($mconfig{'home_base'}, $user) eq $home; printf " %s\n", $hb ? "checked" : "", $text{'uedit_auto'}; printf "\n", $hb ? "" : "checked"; printf " %s\n", $hb ? "" : $home, &file_chooser_button("home", 1); } else { print "\n", &file_chooser_button("home", 1); } print "
$text{'shell'}$text{'pass'}", " \n"; printf" %s
\n", $pass eq "" && $random_password eq "" ? "checked" : "", $mconfig{'empty_mode'} ? $text{'none1'} : $text{'none2'}; printf" $text{'nologin'}
\n", $pass eq $mconfig{'lock_string'} && $random_password eq "" ? "checked" : ""; printf " $text{'clear'}\n", $random_password ne "" ? "checked" : ""; printf "
\n", $mconfig{'passwd_stars'} ? "type=password" : "", $mconfig{'random_password'} && $n eq "" ? $random_password : ""; printf " $text{'encrypted'}\n", $pass && $pass ne $mconfig{'lock_string'} ? "checked" : ""; printf "\n", $pass && $pass ne $mconfig{'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"; if (&in_schema($schema, "shadowLastChange")) { # Show shadow password options print "\n"; print "\n"; print "
$text{'uedit_passopts'}
\n"; print "\n"; print "\n"; print "\n"; if ($in{'new'}) { if ($mconfig{'default_expire'} =~ /^(\d+)\/(\d+)\/(\d+)$/) { $eday = $1; $emon = $2; $eyear = $3; } } elsif ($expire) { @tm = localtime(timelocal(gmtime($expire * 60*60*24))); $eday = $tm[3]; $emon = $tm[4]+1; $eyear = $tm[5]+1900; } print "\n"; print "\n"; printf "\n", $in{'new'} ? $mconfig{'default_min'} : $min; print "\n"; printf "\n", $in{'new'} ? $mconfig{'default_max'} : $max; print "\n"; printf "\n", $in{'new'} ? $mconfig{'default_warn'} : $warn; print "\n"; printf "\n", $in{'new'} ? $mconfig{'default_inactive'} : $inactive; print "
$text{'change'}"; if ($change) { @tm = localtime(timelocal(gmtime($change * 60*60*24))); printf "%s/%s/%s\n", $tm[3], $text{"smonth_".($tm[4]+1)}, $tm[5]+1900; } elsif ($in{'new'}) { print "$text{'uedit_never'}\n"; } else { print "$text{'uedit_unknown'}\n"; } print "$text{'expire'}"; &useradmin::date_input($eday, $emon, $eyear, 'expire'); print "
$text{'min'}$text{'max'}
$text{'warn'}$text{'inactive'}

\n"; } # Show primary group print "\n"; print "\n"; print "
$text{'uedit_gmem'}
\n"; print "\n", $in{'new'} ? $mconfig{'default_group'} : ($x=&all_getgrgid($gid)) || $gid, &group_chooser_button("gid"); if ($config{'secmode'} != 1) { # Work out which secondary groups the user is in @defsecs = &split_quoted_string($mconfig{'default_secs'}); $base = &get_group_base(); $rv = $ldap->search(base => $base, filter => '(objectClass=posixGroup)'); %ingroups = ( ); foreach $g (sort { lc($a->dn()) cmp lc($b->dn()) } $rv->all_entries) { $group = $g->get_value("cn"); @mems = $g->get_value("memberUid"); local $ismem = &indexof($user, @mems) >= 0; if ($n eq "") { $ismem = 1 if (&indexof($group, @defsecs) >= 0); } $ingroups{$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 (sort { lc($a->dn()) cmp lc($b->dn()) } $rv->all_entries) { $group = $g->get_value("cn"); if ($ingroups{$group}) { push(@insecs, $group); } } print "\n"; } else { # Don't show print "\n"; } print "\n"; print "
$text{'group'} \n"; printf " %s$text{'uedit_2nd'}",&ui_textarea("sgid", join("\n", @insecs), 5, 20),"

\n"; # Show extra fields (if any) &extra_fields_input($config{'fields'}, $uinfo); # Show capabilties section print "\n"; print "\n"; print "
$text{'uedit_cap'}
\n"; print "\n"; printf "\n", $oclass{$samba_class} ? "" : "checked", $text{'no'}; if ($config{'imap_host'}) { print "\n"; @cyrus_class_3 = split(' ',$cyrus_class); printf "\n", $oclass{$cyrus_class_3[0]} ? "" : "checked", $text{'no'}; if ($config{'domain'}) { print "\n"; print "\n", join(" ", @alias); } # Show field for changing the quota on existing users, or setting # it for new users if ($config{'quota_support'}) { print "\n"; } } else { printf "\n", $oclass{$cyrus_class}; print "\n"; } print "
$text{'uedit_samba'} %s\n", $oclass{$samba_class} ? "checked" : "", $text{'yes'}; printf " %s$text{'uedit_cyrus'} %s\n", $oclass{$cyrus_class_3[0]} ? "checked" : "", $text{'yes'}; printf " %s
$text{'uedit_alias'}\n"; printf "
$text{'uedit_quota'} \n"; if ($in{'new'} || !$oclass{$cyrus_class_3[0]}) { print &ui_textbox("quota", $config{'quota'}, 10)." kB"; } else { print &ui_opt_textbox("quota", undef, 10, $text{'uedit_unquota'})." Kb"; } print "

\n"; if ($in{'new'}) { print "\n"; print "\n"; print "
$text{'uedit_oncreate'}
\n"; print "\n"; print "\n"; print "\n"; printf "\n", $mconfig{'default_other'} ? "" : "checked"; print "
$text{'uedit_makehome'} $text{'yes'}\n"; print " $text{'no'}
$text{'uedit_cothers'} $text{'yes'}\n", $mconfig{'default_other'} ? "checked" : ""; printf " $text{'no'}
\n"; } else { print "\n"; print "\n"; print "
$text{'onsave'}
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; printf "\n", $mconfig{'default_other'} ? "" : "checked"; print "
$text{'uedit_movehome'} $text{'yes'}\n"; print " $text{'no'}
$text{'uedit_chuid'} $text{'no'}\n"; print " ", "$text{'home'}\n"; print " ", "$text{'uedit_allfiles'}
$text{'chgid'} $text{'no'}\n"; print " ". "$text{'home'}\n"; print " ", "$text{'uedit_allfiles'}
$text{'uedit_mothers'} $text{'yes'}\n", $mconfig{'default_other'} ? "checked" : ""; printf " $text{'no'}
\n"; } print "\n"; if ($in{'new'}) { # Show buttons for new users print "\n"; } else { # Show buttons for existing users print "\n"; print "\n"; if (&foreign_available("mailboxes") && &foreign_installed("mailboxes", 1)) { # Link to the mailboxes module, if installed 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 print "\n"; } print "\n"; } print "
\n"; print "

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