hi guys
i’m having trouble over at helpdesk.oneorzero.com
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 '
'; ?>
thanks
regards
shane
ZFD Expert