/** * Checks that the email address given is a contact that has not yet * been imported into the DB, then imports them. * @author Lea Anthony * @param string $email. Email * @return An array of the user data (if found) */ function ldapImportCustomerFromEmail($email) { global $CONFIG; $toReturn = false; debug_log("ldapImportCustomerFromEmail {$email}", TRUE); if (!empty($email)) { $sql = "SELECT id, username, contact_source FROM `{$GLOBALS['dbContacts']}` WHERE email = '{$email}'"; debug_log($sql, TRUE); $result = mysql_query($sql); if (mysql_error()) { trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING); } if (mysql_num_rows($result) == 1) { // Can only deal with the case where one exists, if multiple contacts have the same email address its difficult to deal with $obj = mysql_fetch_object($result); if ($obj->contact_source == 'sit') { $toReturn = true; } elseif ($obj->contact_source == 'ldap') { if (authenticateLDAP($obj->username, '', $obj->id, false, true, false)) { $toReturn = true; } } else { // Exists but of some other type $toReturn = true; } } elseif (mysql_num_rows($result) > 1) { debug_log("More than one contact was found in LDAP with this address '{$email}', not importing", TRUE); // Contact does exists with these details, just theres more than one of them $toReturn = true; } else { // Zero found if ($CONFIG['use_ldap']) { // Try and search if (authenticateLDAP($email, '', 0, false, true, true)) { $toReturn = true; } } } } return $toReturn; }
} // Use default service level if we didn't find one above if ($servicelevel == '') { $servicelevel = $CONFIG['default_service_level']; } if ($CONFIG['use_ldap']) { // Attempt to update contact $sql = "SELECT username, contact_source FROM `{$GLOBALS['dbContacts']}` WHERE id = {$contactid}"; $result = mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); } $obj = mysql_fetch_object($result); if ($obj->contact_source == 'ldap') { //function authenticateLDAP($username, $password, $id = 0, $user=TRUE, $populateOnly=FALSE, $searchOnEmail=FALSE) authenticateLDAP($obj->username, '', $contactid, false, true, false); } } // Check the service level priorities, look for the highest possible and reduce the chosen priority if needed $sql = "SELECT priority FROM `{$dbServiceLevels}` WHERE tag='{$servicelevel}' ORDER BY priority DESC LIMIT 1"; $result = mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); } list($highestpriority) = mysql_fetch_row($result); if ($priority > $highestpriority) { $prioritychangedmessage = " (" . sprintf($strReducedPrioritySLA, priority_name($priority)) . ")"; $priority = $highestpriority; } $sql = "INSERT INTO `{$dbIncidents}` (title, owner, contact, priority, servicelevel, status, type, maintenanceid, "; $sql .= "product, softwareid, productversion, productservicepacks, opened, lastupdated, timeofnextaction) ";
function authenticateContact($username, $password) { debug_log("authenticateContact called"); global $CONFIG; $toReturn = false; $sql = "SELECT id, password, contact_source, active FROM `{$GLOBALS['dbContacts']}` WHERE username = '******'"; $result = mysql_query($sql); if (mysql_error()) { trigger_error(mysql_error(), E_USER_WARNING); } if (mysql_num_rows($result) == 1) { debug_log("Authenticate: Just one contact in db"); // Exists in SiT DB $obj = mysql_fetch_object($result); if ($obj->contact_source == 'sit') { if ((md5($password) == $obj->password or $password == $obj->password) and $obj->active == 'true') { $toReturn = true; } else { $toReturn = false; } } elseif ($obj->contact_source == 'ldap') { // Auth against LDAP and sync $toReturn = authenticateLDAP($username, $password, $obj->id, false); if ($toReturn === -1) { // Communication with LDAP server failed if ($CONFIG['ldap_allow_cached_password']) { debug_log("LDAP connection failed, using cached password"); // Use cached password if ((md5($password) == $obj->password or $password == $obj->password) and $obj->active == 'true') { $toReturn = true; } else { $toReturn = false; } debug_log("Cached contact {$toReturn} {$password}"); } else { debug_log("Cached passwords are not enabled"); $toReturn = false; } } elseif ($toReturn) { $toReturn = true; } else { $toReturn = false; } } else { debug_log("Source SOMETHING ELSE this shouldn't happen'"); $toReturn = false; } } elseif (mysql_num_rows($result) > 1) { debug_log("Multiple"); // Multiple this should NEVER happen trigger_error($GLOBALS['strUsernameNotUnique'], E_USER_ERROR); $toReturn = false; } else { debug_log("Authenticate: No matching contact '{$username}' found in db"); // Don't exist, check LDAP etc if ($CONFIG['use_ldap'] and !empty($CONFIG['ldap_customer_group'])) { $toReturn = authenticateLDAP($username, $password, 0, false); if ($toReturn === -1) { $toReturn = false; } } } debug_log("authenticateContact returning {$toReturn}"); return $toReturn; }