Net-LDAPapi

 view release on metacpan or  search on metacpan

examples/web500.pl  view on Meta::CPAN



####
# print_options - Print Top Options
####

sub print_options
{
   local $Flag;
   $Flag=0;
   print "<center><a href=$LDAPCGI_NAME?op=search>[SEARCH]</a>";
   if ($ldap_auth{'dn'} eq $ldap_default_auth{'dn'})
   {
      print "<a href=$LDAPCGI_NAME?op=authenticate>[LOGIN]</a>  ";
      $Flag=1;
   } else {
      print "<a href=$LDAPCGI_NAME?op=searchuser&ldap_myuid=CLEAR&ldap_mypass=CLEAR>[LOGOUT]</a>  ";
      print "<a href=$LDAPCGI_NAME?op=moduser>[CHANGE PASSWORD/INFO]</a>  ";
      print "<a href=$LDAPCGI_NAME?op=adduser>[ADD]</a>  ";
   }
   print "<a href=$LDAPCGI_NAME?op=help>[HELP]</a></center>",p;
   if ($Flag) {
	print "NOTE: Please LOGIN before you change password and other information.<br><br>";
   }
   return;
}


####
# searchuser_entry - The main search screen
####

sub searchuser_entry
{

# If 'my_base_dn' is passed, use it, otherwise use the default

   if (param('my_base_dn'))
   {
      $my_base_dn = param('my_base_dn');
   } else {
      $my_base_dn = $LDAP_BASEDN;
   }

# Get rid of extra spaces after commas.  This probably isn't the
# safest way to do this, but should be okay for now.

   $my_base_dn =~ s/,\s/,/g;

# Now make sure that anything passed contains our default BASEDN, otherwise
# 'my_base_dn' may not be useful.

   if ($my_base_dn !~ /$LDAP_BASEDN$/)
   {
      $my_base_dn = $LDAP_BASEDN;
   }

# Splits the DN into segments.  Netscape makes this easy with ldap_explode_dn,
# but I have to do it manually because none of the other SDKs support it.
# We're building a hash with all the levels above our own for use in the
# popup_menu.

   @splitbase = split(/,/,$my_base_dn);
   @splitdefault = split(/,/,$LDAP_BASEDN);

   for ($count = 0; $count <= $#splitbase; $count++)
   {
      for ($base_count = $count; $base_count <= $#splitbase; $base_count++)
      {
         if ($count != $base_count)
         {
            $base_vals[$count] = $base_vals[$count] . ",";
         }
         $base_vals[$count] = $base_vals[$count] . $splitbase[$base_count];
      }
      $shortname = $splitbase[$count];
      $shortname =~ s/^.*=//;
      $basename{$base_vals[$count]} = $shortname;
   }

# We don't want people to be able to go higher than the default level.
   $#base_vals = $#base_vals - $#splitdefault;

# Now print the form with the query and the popup containing higher
# levels within the LDAP tree.

   print "<b>Current Search Base:</b> $my_base_dn",
     start_form,
     hidden('op','searchresult'),
     hidden('searchfor','yes'),
     "Move Up To: ",popup_menu('my_base_dn',\@base_vals,$base_vals[0],\%basename),p;
   foreach $searchattr (@searchuser_onattr)
   {
      print textfield(-name=>"searchfor_$searchattr",-size=>50),
      $fields{$searchattr}[0],"\n",br;
   }
   print p,submit('Search'),reset('Reset'),
   end_form,p,"\n";

# This search will find all the organizations and localities one level below
# our current level.  This allows people to navigate downwards.

   if (ldap_search_s($ld,$my_base_dn,LDAP_SCOPE_ONELEVEL,$DOWN_FILTER,[],1,$result) != LDAP_SUCCESS)
   {
      &print_error;
      ldap_unbind($ld);
      exit;
   }

   print h3("Move Down To:\n");
   print "<ul>\n";
   $entrycount = 0;
   for ($ent=ldap_first_entry($ld,$result);$ent!=0;$ent=ldap_next_entry($ld,$ent))
   {
      $entrycount = $entrycount + 1;
      $newbase = ldap_get_dn($ld,$ent);
      $subbase = $newbase;

# We need to escape certain special characters.  I'm sure there are more
# than these, but this was all I could think of for now.
      $subbase =~ s/ /%20/g;
      $subbase =~ s/=/%3D/g;

# We simply pass parameters that would change my_base_dn and continue searching
      print "<li><a href='$LDAPCGI_NAME?op=searchuser&my_base_dn=$subbase'>$newbase</a>\n";
   }
   if ($entrycount == 0)
   {
      print "<li>Nothing Below\n";
   }
   print "</ul>\n",hr;

   &print_bottom;
   ldap_unbind($ld);
   exit;
}

sub searchuser_results
{
   $filter = "";
   $noattrs = 0;
   
   foreach $searchattr (@searchuser_onattr)
   {
      if (param("searchfor_$searchattr"))
      {
         $noattrs++;
         $filter = $filter . "($searchattr=*" . param("searchfor_$searchattr") .  "*)";
      }
   }



( run in 0.733 second using v1.01-cache-2.11-cpan-364913b4093 )