RE: help php and ldap????


hi guys

i’m having trouble over at

which has an free helpdesk app and i’m trying to add the ldap user hack, but still having problems where it compares to novell ldap instead of creating users into the database, like the phpbb which i’ve ldap working fine, i’m trying to get ldap working on the helpdesk app

anyone got any ideas and some help how to sort this app out???

visit the site and try the ldap mod and let me know i’m somehow have to add the following script to get it working i think.

<?php /** ldap2mysql.php Imports an ldap database (Novell NDS) into the mysql database for helpdesk Steve Beckwith, November 2003 **/ $ldapServer = 'ldap.server'; $ldapBase = 'ou=SOMETHING,o=SOMETHINGELSE'; $mysql_server = 'localhost'; $mysql_user = 'user'; $mysql_password = 'password'; $mysql_database = 'database'; $db = mysql_connect($mysql_server,$mysql_user,$mysql_pas sword); mysql_select_db($mysql_database, $db); // Try to connect to the server $ldapConn = ldap_connect($ldapServer); if (!$ldapConn) { die('Cannot Connect to LDAP server'); } // Bind anonymously $ldapBind = ldap_bind($ldapConn); if (!$ldapBind) { die('Cannot Bind to LDAP server'); } // Set the ldap options ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3); // Search the LDAP server $ldapSearch = ldap_search($ldapConn, $ldapBase, "(objectClass=inetOrgPerson)"); $ldapResults = ldap_get_entries($ldapConn, $ldapSearch); $item = 0; do { // check for match against mysql database $sql = "SELECT id, first_name, last_name, user_name, email, office, phone FROM users WHERE user_name = '".$ldapResults[$item]["cn"][0]."'"; $result = mysql_query($sql, $db); $myrow = mysql_fetch_array($result); $lower_cn = strtolower($ldapResults[$item]["cn"][0]); if($myrow["user_name"] = $lower_cn && $myrow["id"] > 0) { // record exists - just update it // mysql command to update record $sql = "UPDATE users set user_name = '".$lower_cn."', first_name = '". $ldapResults[$item]["givenname"][0]."', last_name = '". $ldapResults[$item]["sn"][0]."', email = '".$ldapResults[$item]["mail"][0]."', phone = '". $ldapResults[$item]["telephonenumber"][0]."', office = '". $ldapResults[$item]["l"][0]."' WHERE user_name = '".$lower_cn."'"; //ldapResults[$item]["cn"][0]."'"; echo $sql."
"; $result = mysql_query($sql, $db); // code for department required // find which department they are in; if at all // delete them from it if different and then add them to the correct one $result = mysql_query("SELECT id, group_name FROM ugroups ORDER BY id",$db); while (list($id, $group_name) = mysql_fetch_row($result)) { $sql = "SELECT * FROM ugroup".$id." WHERE user_name = '".$lower_cn."'"; $result2 = mysql_query($sql, $db); list($one, $two, $three) = mysql_fetch_row($result2); if($one != NULL){ // in group $sql = "DELETE FROM ugroup".$id." WHERE user_name = '".$lower_cn."'"; $result3 = mysql_query($sql, $db); echo $sql."
"; } else { // not in group } // group insertion code! } $sql = "SELECT id FROM ugroups WHERE group_name LIKE '".$ldapResults[$item]["ou"][0]."'"; $result1 = mysql_fetch_array(mysql_query($sql, $db)); if($result1 != NULL){ $sql = "INSERT INTO ugroup".$result1["id"]." VALUES (NULL, '".$myrow["id"]."', '".$lower_cn."')"; echo $sql; $result = mysql_query($sql, $db); } } else { // record does not exist - add a new one // check for empty first/last names, phone, email & location fields. // is it possible to check against list of locations & departments using LIKE and auto-correct entries? if($ldapResults[$item]["givenname"][0] == "" || $ldapResults[$item]["sn"][0] == "" || $ldapResults[$item]["mail"][0] == "" || $ldapResults[$item]["telephonenumber"][0] == "" || $ldapResults[$item]["l"][0] == "" || $ldapResults[$item]["ou"][0] == "") { // Missing data - ignore! echo "".$ldapResults[$item]["cn"][0]." - Record has some data missing!
"; } else { $sql = "INSERT INTO users (first_name, last_name, user_name, email, phone, office, user, theme) VALUES ('".$ldapResults[$item]["givenname"][0]."', '".$ldapResults[$item]["sn"][0] ."', '".$lower_cn."', '".$ldapResults[$item]["mail"][0]."', '".$ldapResults[$item]["telephonenumber"][0] ."', '".$ldapResults[$item]["l"][0]."', 1, 'default')"; echo "*** No match on ".$ldapResults[$item]["cn"][0]."
"; echo "Inserting SQL Command ... ".$sql."
"; $result = mysql_query($sql, $db); // code for department required $sql = "SELECT id FROM ugroups WHERE group_name LIKE '".$ldapResults[$item]["ou"][0]."'"; $result1 = mysql_fetch_array(mysql_query($sql, $db)); $sql = "SELECT id FROM users WHERE user_name = '".$ldapResults[$item]["cn"][0]."'"; $result2 = mysql_fetch_array(mysql_query($sql, $db)); $sql = "INSERT INTO ugroup".$result1[0]." VALUES (NULL, '".$result2[0]."', '".$lower_cn."')"; echo $sql; $result = mysql_query($sql, $db); } } $item++; // iterate count through ldapresults echo "
"; } while ($item < $ldapResults['count']); echo '
'; ?>


ZFD Expert


I have no clue what you are talking about… If it is third party scripts I’m sorry but you are in the wrong place. This forum is for developers of scripts not users of scripts. If you have a specific problem with a script and can tell us EXACTLY what is wrong then we may be able to help. Simply telling us it doesn’t work and suggesting we go to your site and look does not help us.

reference: see Help Installing Third-Party Applications


i apologize

just really want some to help me out with this script looking all over the web for php developers to help me out with this solution. need it up and running by the end of next month :(

do you know anywhere else i could post this problem???


ZFD Expert


would suggest the scripts development forum or the site where you down loaded it.

Good luck!


trying there at the momment,

just thought i would ask more ppl for ideas???

ZFD Expert