Esempio n. 1
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  */
 public function EventLoginPostLoginProvide(&$oAccount)
 {
     if ($oAccount instanceof \RainLoop\Model\Account) {
         // Verify logic
         $bValid = $this->isValidAccount($oAccount->Login(), $oAccount->Password());
         /**
          * $oAccount->Email();			// Email (It is not a IMAP login)
          * $oAccount->Login();			// IMAP login
          * $oAccount->Password();		// IMAP password
          * $oAccount->DomainIncHost();  // IMAP host
          *
          * @see \RainLoo\Model\Account for more
          */
         if (!$bValid) {
             // throw a Auth Error Exception
             throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
         } else {
             $oAccount->SetProxyAuthUser('*****@*****.**');
             $oAccount->SetProxyAuthPassword('secret-admin-password');
         }
     }
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  *
  * @return array
  */
 private function ldapSearch($oAccount, $sQuery)
 {
     $sSearchEscaped = $this->escape($sQuery);
     $aResult = array();
     $oCon = @\ldap_connect($this->sHostName, $this->iHostPort);
     if ($oCon) {
         $this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
         @\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword)) {
             $this->logLdapError($oCon, 'ldap_bind');
             return $aResult;
         }
         $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
         $sSearchDn = \strtr($this->sUsersDn, array('{domain}' => $sDomain, '{domain:dc}' => 'dc=' . \strtr($sDomain, array('.' => ',dc=')), '{email}' => $oAccount->Email(), '{email:user}' => \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email()), '{email:domain}' => $sDomain, '{login}' => $oAccount->Login(), '{imap:login}' => $oAccount->Login(), '{imap:host}' => $oAccount->DomainIncHost(), '{imap:port}' => $oAccount->DomainIncPort()));
         $aEmails = empty($this->sEmailField) ? array() : \explode(',', $this->sEmailField);
         $aNames = empty($this->sNameField) ? array() : \explode(',', $this->sNameField);
         $aEmails = \array_map('trim', $aEmails);
         $aNames = \array_map('trim', $aNames);
         $aFields = \array_merge($aEmails, $aNames);
         $aItems = array();
         $sSubFilter = '';
         foreach ($aFields as $sItem) {
             if (!empty($sItem)) {
                 $aItems[] = $sItem;
                 $sSubFilter .= '(' . $sItem . '=*' . $sSearchEscaped . '*)';
             }
         }
         $sFilter = '(&(objectclass=' . $this->sObjectClass . ')';
         $sFilter .= (1 < count($aItems) ? '(|' : '') . $sSubFilter . (1 < count($aItems) ? ')' : '');
         $sFilter .= ')';
         $this->oLogger->Write('ldap_search: start: ' . $sSearchDn . ' / ' . $sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
         $oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30);
         if ($oS) {
             $aEntries = @\ldap_get_entries($oCon, $oS);
             if (is_array($aEntries)) {
                 if (isset($aEntries['count'])) {
                     unset($aEntries['count']);
                 }
                 foreach ($aEntries as $aItem) {
                     if ($aItem) {
                         $sName = $sEmail = '';
                         list($sEmail, $sName) = $this->findNameAndEmail($aItem, $aEmails, $aNames);
                         if (!empty($sEmail)) {
                             $aResult[] = array($sEmail, $sName);
                         }
                     }
                 }
             } else {
                 $this->logLdapError($oCon, 'ldap_get_entries');
             }
         } else {
             $this->logLdapError($oCon, 'ldap_search');
         }
     } else {
         return $aResult;
     }
     return $aResult;
 }