getMessage()); $login=false; } unset($GLOBALS["use_error_exception"]); if ($login) { debug("LDAP - Success binding to AD server as : " . $binduserstring); $bindsuccess=true; } else { debug("LDAP - Failed binding to AD server as : " . $binduserstring); } } else { $searchdns=explode(";",$simpleldap['basedn']); foreach($searchdns as $searchdn) { $binduserstring = $simpleldap['loginfield'] . "=" . $escaped_ldapuser . "," . $searchdn; debug("LDAP - Attempting to bind to AD server as : " . $binduserstring); $GLOBALS["use_error_exception"] = true; try { $login = ldap_bind( $ds, $binduserstring, $simpleldap['ldappassword'] ); } catch(Exception $e) { debug("ERROR: LDAP bind failed " . $e->getMessage()); $login=false; } unset($GLOBALS["use_error_exception"]); if (!$login) { debug("LDAP bind failed: " . $searchdn); } else { $bindsuccess=true; break; } } } ldap_get_option($ds, LDAP_OPT_ERROR_STRING, $last_ldap_error); $response['bindsuccess'] = $bindsuccess ? $lang['status-ok'] : "{$lang['status-fail']} - " . ldap_error($ds) . " ( {$last_ldap_error} )"; $response['memberof'] = array(); $userdetails=simpleldap_authenticate($simpleldap['ldapuser'],$simpleldap['ldappassword']); unset($GLOBALS["use_error_exception"]); if ($userdetails) { $response['success'] = true; $response['message'] = $lang["status-ok"]; $response['domain'] = $userdetails['domain']; $response['binduser'] = $userdetails['binduser']; $response['username'] = $userdetails['username']; $response['displayname'] = $userdetails['displayname']; $response['group'] = $userdetails['group']; $response['email'] = $userdetails['email']; $response['phone'] = $userdetails['phone']; $response['memberof'] = $userdetails['memberof']; } else { $response['success'] = false; $response['message'] = $lang["status-fail"]; } } else { $response['success'] = false; $response['message'] = "LDAP - Invalid connection URL: '" . $connstring . "'"; } $response['complete'] = true; echo json_encode($response); exit();