#!/usr/local/bin/perl # index.cgi # List all LDAP users for editing require './ldap-useradmin-lib.pl'; &ui_print_header(undef, $module_info{'desc'}, "", "intro", 1, 1); &useradmin::load_theme_library(); # So that ui functions work # Make sure the LDAP NSS client config file exists, or the needed information # has been provided if ($config{'auth_ldap'}) { if (!-r $config{'auth_ldap'}) { print &text('index_econfig', "$config{'auth_ldap'}", "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } $nss = &get_nss_config(); if ($nss->{'pidfile'} || $nss->{'directory'}) { print &text('index_econfig2', "$config{'auth_ldap'}", "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } } else { if (!$config{'ldap_host'} || !$config{'login'} || !$config{'pass'} || !$config{'user_base'} || !$config{'group_base'}) { print &text('index_ehost', "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } } # Make sure the LDAP Perl module is installed, and if not offer to install if (!$got_net_ldap) { local @needs; foreach $m ("Convert::ASN1", "Net::LDAP") { eval "use $m"; push(@needs, $m) if ($@); } $missing = &urlize(join(" ", @needs)); print &text('index_eperl', "$missing", "/cpan/download.cgi?source=3&cpan=$missing&mode=2&". "return=/$module_name/&returndesc=". &urlize($text{'index_return'})),"
\n"; print "$text{'index_eperl2'}\n"; print "
$net_ldap_error\n"; &ui_print_footer("/", $text{'index'}); exit; } # Try to login .. may fail $ldap = &ldap_connect(1); if (!ref($ldap)) { print &text('index_eldap', $ldap, "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } if ($config{'imap_host'}) { # Make sure the IMAP Perl module is installed, and if not offer # to install if (!$got_net_imap) { print &text('index_eperl', "Net::IMAP", "/cpan/download.cgi?source=3&cpan=Net::IMAP&mode=2&". "return=/$module_name/&returndesc=". &urlize($text{'index_return'})),"
\n"; print "$text{'index_eperl2'}\n"; print "
$net_imap_error\n"; &ui_print_footer("/", $text{'index'}); exit; } # Try to connect to the IMAP server $imap = &imap_connect(1); if (!ref($imap)) { print &text('index_eimap', $imap, "$gconfig{'webprefix'}/config.cgi?$module_name"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } } # If using MD5, make sure needed perl modules or programs are installed if ($config{'md5'} == 1) { # Check if MD5 perl module is installed, and offer to install &foreign_require("useradmin", "user-lib.pl"); if ($err = &useradmin::check_md5()) { print &text('index_emd5', "../config.cgi?$module_name", "$err", "../cpan/download.cgi?source=3&cpan=Digest::MD5&mode=2&return=/$module_name/&returndesc=".&urlize($text{'index_return'})),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } } elsif ($config{'md5'} == 3) { # Check if slappasswd is installed if (!&has_command($config{'slappasswd'})) { print &text('index_eslappasswd', "../config.cgi?$module_name", "$config{'slappasswd'}"),"
\n"; &ui_print_footer("/", $text{'index'}); exit; } } # Count the number of users and groups $base = &get_user_base(); $rv = $ldap->search(base => $base, filter => '(objectClass=posixAccount)', sizelimit => $mconfig{'display_max'}+1); $ucount = $rv->count; $base = &get_group_base(); $rv = $ldap->search(base => $base, filter => '(objectClass=posixGroup)', sizelimit => $mconfig{'display_max'}+1); $gcount = $rv->count; # Get the list of users and groups if ($ucount <= $mconfig{'display_max'}) { @allulist = &list_users(); @ulist = &useradmin::list_allowed_users(\%access, \@allulist); } if ($gcount <= $mconfig{'display_max'}) { @allglist = &list_groups(); @glist = &useradmin::list_allowed_groups(\%access, \@allglist); } # Build links for adding users @links = ( ); if ($access{'ucreate'}) { push(@links, "$text{'index_uadd'}"); } if ($access{'batch'}) { push(@links, "$text{'index_batch'}"); } # Show users list header if ($ucount || $access{'ucreate'}) { print "\n"; print "
| ".&ui_subheading($text{'index_users'})." | \n"; if ($gcount || $access{'gcreate'}) { print "", "$text{'index_gjump'} | \n"; } print "
\n"; print "
\n"; print &ui_links_row(\@links); } elsif (@ulist) { # Show table of all users @ulist = &useradmin::sort_users(\@ulist, $mconfig{'sort_mode'}); &useradmin::users_table(\@ulist, $form++, 1, 0, \@links); } else { # No users $base = &get_user_base(); print "",&text('index_unone', "$base"),"\n"; print &ui_links_row(\@links); } # Show groups header if ($gcount || $access{'gcreate'}) { print "
| ".&ui_subheading($text{'index_groups'})." | \n"; if ($ucount || $access{'ucreate'}) { print "", "$text{'index_ujump'} | \n"; } print "
\n"; print &ui_links_row(\@links); } &ui_print_footer("/", $text{'index'});