Main Menu
Home
Search
Support
How To's
OpenWiki
Contact Us
Users Blogs
User HowTo's
Announcements
Google Translation

 

 

 

 

Active Directory as Address Book with apache and PHP PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Paul Matthews   

Active Directory as Address Book with apache and PHP

Name: PHP
HomePage: http://www.php.net/
Function: developers to write dynamically generated webpages

Name: Apache
HomePage: http://www.apache.org/
Function: Webserver

 

1. Make sure apache is running

/etc/init.d/httpd start

 

Active Directory as Address Book with apache PHP

2. Next download the following files and put them in your Address Book directory in your apache directory

http://www.opensourcehowto.org/uploads/scripts/search.html.txt

Active Directory as Address Book with apache PHP

http://www.opensourcehowto.org/uploads/scripts/search.php.txt

Active Directory as Address Book with apache PHP

mkdir /var/www/html/search

cp search.html.txt /var/www/html/search/search.html
cp search.php.txt /var/www/html/search/search.php

chown apache:apache -R /var/www/html/search

 

Active Directory as Address Book with apache PHP

3. Now edit the Address Book files, firstly we'll edit the search.php file to suit your own network

nano /var/www/html/search.php

 

search.php:

// Designate a few variables
$host = "ldap://mc1.fedora.directory.server";
$user = " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ";
$pswd = "password";
$ad = ldap_connect($host) or die( "Could not connect!" ); 

// Set version number
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");

// Binding to ldap server
$bd = ldap_bind($ad, $user, $pswd) or die ("Could not bind");

// Create the DN $dn = "dc=domain,dc=controller";
$dn = "dc=fedora,dc=directory,dc=server";

// Specify only those parameters we're interested in displaying
$attrs = array("displayname","mail");

// Create the filter from the search parameters
$filter = $_POST['filter']."=".$_POST['keyword']."*";

$search = ldap_search($ad, $dn, $filter, $attrs) or die ("ldap search failed");
$entries = ldap_get_entries($ad, $search);

if ($entries["count"] > 0) { for ($i=0; $i<$entries["count"]; $i++) { echo "

Name: ".$entries[$i]["displayname"][0]."
"; echo "Email: ".$entries[$i]["mail"][0]."
"; } } else { echo "

No results found!
"; } ldap_unbind($ad);

 

 


 

Active Directory as Address Book with apache PHP

4. Once the search.php file is edited then change search.html file to change what your searching for, eg: "givenName"(First Name), "sn"(Last Name), etc

nano /var/www/html/search/search.html

 

search.html:
<p>
  <form action="search.php" method="post">
    Search criteria:<br />
    <input type="text" name="keyword" size="20"
           maxlength="20" value="" /><br />
    Filter:<br />
    <select name="filter">
        <option value="">Choose One:</option>
        <option value="givenName">First Name</option>
        <option value="sn">Last Name</option>
        <option value="sAMAccountName">User Name</option>
    </select><br />
    <input type="submit" value="Search!" />
  </form>
</p>

 

Active Directory as Address Book with apache PHP

 

5. Once that is done, just go to

http://ip-address-of-your-apache-server/search/search.html

 

Active Directory as Address Book with apache PHP

6. You can dress it up a little and add another search engine, one for each OU if you want, for instance one ou might be teaching staff & another ou might be admin staff

http://www.opensourcehowto.org/uploads/search/search.html

 


BookMarking:

 

cell1

cell3 Submit to del.icio.us
cell4
AddThis Social Bookmark Button

 


Trouble Shooting:

Go to the wiki page

Go to the 'Contact Us ' Forum

Go to the how-to's Support Forum


External Links:

 

http://lotso.livejournal.com/1863.htm

Last Updated ( Sunday, 03 June 2007 )