/** * Change the default address * * @param string $username The username of the user to add the Exchange account to * @param string $emailAddress The email address to make default * @param bool $isGUID Is the username passed a GUID or a samAccountName * @return bool */ public function primaryAddress($username, $emailAddress, $isGUID = false) { if ($username === NULL) { return "Missing compulsory field [username]"; } if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } // Find the dn of the user $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID); if ($user[0]["dn"] === NULL) { return false; } $userDn = $user[0]["dn"]; if (is_array($user[0]["proxyaddresses"])) { $modAddresses = array(); for ($i = 0; $i < sizeof($user[0]['proxyaddresses']); $i++) { if (strstr($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) { $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]); } if ($user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { $user[0]['proxyaddresses'][$i] = str_replace('smtp:', 'SMTP:', $user[0]['proxyaddresses'][$i]); } if ($user[0]['proxyaddresses'][$i] != '') { $modAddresses['proxyAddresses'][$i] = $user[0]['proxyaddresses'][$i]; } } $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $modAddresses); if ($result == false) { return false; } return true; } }
public function authenticate() { /*if (Request::ajax()):*/ $isAccountActive = FALSE; $adldap = new adLDAP(); $username = Request::input('username'); $password = md5(Request::input('password')); $authUser = $adldap->authenticate($username, Request::input('password')); if ($authUser && $this->login_status) { $user_fields = array('displayname', 'mail', 'company', 'physicaldeliveryofficename', 'givenname', 'sn'); $this->user_info = $adldap->user()->info($username, $user_fields); //working $this->_processUser($username, $password); //return array("status" => $this->response_status, "message" => $this->response_text); } else { $this->login_status = FALSE; $this->_check_failed_login_duration($username); //return array("status" => $this->response_status, "message" => $this->response_text); } //todo WFH. SEARCH FOR VLANS if (!$this->wfh) { // if user is allowed to work from home then check his IP $user_ip_address = Request::getClientIp(true); $tmpIP = $user_ip_address; $pos = strrpos($tmpIP, '.'); $tmpIP = substr($tmpIP, 0, $pos) . '.'; $qry2 = "\n\t\t\t\tSELECT * FROM vlans v \n\t\t\t\tINNER JOIN offices o ON v.office_id = o.office_id \n\t\t\t\tWHERE subnet like '" . $tmpIP . "%';\n\t\t\t"; $res2 = DB::select($qry2); if (count($res2) == 0 && ip2long($user_ip_address)) { $this->login_status = FALSE; $this->response_text = 'You are not authorised to login remotely. If this is incorrect please contact HR.'; $this->response_status = 'failed'; Auth::logout(); return array("status" => $this->response_status, "message" => $this->response_text); } } if (!$this->login_status) { $this->response_status = 'failed'; $this->response_text = $this->messages['invalid']; } return array("status" => $this->response_status, "message" => $this->response_text); /*else: return array("status" => $this->response_status, "message" => $this->response_text); endif;*/ }
/** * Remove a user from a group * * @param string $group The group to remove a user from * @param string $user The AD user to remove from the group * @param bool $isGUID Is the username passed a GUID or a samAccountName * @return bool */ public function removeUser($group, $user, $isGUID = false) { // Find the parent dn $groupInfo = $this->info($group, array("cn")); if ($groupInfo[0]["dn"] === NULL) { return false; } $groupDn = $groupInfo[0]["dn"]; // Find the users dn $userDn = $this->adldap->user()->dn($user, $isGUID); if ($userDn === false) { return false; } $del = array(); $del["member"] = $userDn; $result = @ldap_mod_del($this->adldap->getLdapConnection(), $groupDn, $del); if ($result == false) { return false; } return true; }
public function testLdap() { $ad = new adLDAP(); //$ad->user()->modify("genesis.gallardo", array("email" => "*****@*****.**")); $results = $ad->user()->info("angelique.torrano"); echo "<pre>"; print_r($results); }