示例#1
0
 /**
  * Authenticates the user with the configured Zarafa server
  *
  * @param string        $username
  * @param string        $domain
  * @param string        $password
  *
  * @access public
  * @return boolean
  * @throws AuthenticationRequiredException
  */
 public function Logon($user, $domain, $pass)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->Logon(): Trying to authenticate user '%s'..", $user));
     $this->mainUser = strtolower($user);
     try {
         // check if notifications are available in php-mapi
         if (function_exists('mapi_feature') && mapi_feature('LOGONFLAGS')) {
             $this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER, null, null, 0);
             $this->notifications = true;
         } else {
             $this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER);
             $this->notifications = false;
         }
         if (mapi_last_hresult()) {
             ZLog::Write(LOGLEVEL_ERROR, sprintf("ZarafaBackend->Logon(): login failed with error code: 0x%X", mapi_last_hresult()));
             if (mapi_last_hresult() == MAPI_E_NETWORK_ERROR) {
                 throw new HTTPReturnCodeException("Error connecting to ZCP (login)", 503, null, LOGLEVEL_INFO);
             }
         }
     } catch (MAPIException $ex) {
         throw new AuthenticationRequiredException($ex->getDisplayMessage());
     }
     if (!$this->session) {
         ZLog::Write(LOGLEVEL_WARN, sprintf("ZarafaBackend->Logon(): logon failed for user '%s'", $user));
         $this->defaultstore = false;
         return false;
     }
     // Get/open default store
     $this->defaultstore = $this->openMessageStore($this->mainUser);
     if (mapi_last_hresult() == MAPI_E_FAILONEPROVIDER) {
         throw new HTTPReturnCodeException("Error connecting to ZCP (open store)", 503, null, LOGLEVEL_INFO);
     }
     if ($this->defaultstore === false) {
         throw new AuthenticationRequiredException(sprintf("ZarafaBackend->Logon(): User '%s' has no default store", $user));
     }
     $this->store = $this->defaultstore;
     $this->storeName = $this->mainUser;
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->Logon(): User '%s' is authenticated", $user));
     // check if this is a Zarafa 7 store with unicode support
     MAPIUtils::IsUnicodeStore($this->store);
     return true;
 }
示例#2
0
 /**
  * Authenticates the user with the configured Kopano server
  *
  * @param string        $username
  * @param string        $domain
  * @param string        $password
  *
  * @access public
  * @return boolean
  * @throws AuthenticationRequiredException
  */
 public function Logon($user, $domain, $pass)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Logon(): Trying to authenticate user '%s'..", $user));
     $this->mainUser = strtolower($user);
     try {
         // check if notifications are available in php-mapi
         if (function_exists('mapi_feature') && mapi_feature('LOGONFLAGS')) {
             // send Z-Push version and user agent to ZCP - ZP-589
             if (Utils::CheckMapiExtVersion('7.2.0')) {
                 $zpush_version = 'Z-Push_' . @constant('ZPUSH_VERSION');
                 $user_agent = Request::GetDeviceID() ? ZPush::GetDeviceManager()->GetUserAgent() : "unknown";
                 $this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER, null, null, 0, $zpush_version, $user_agent);
             } else {
                 $this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER, null, null, 0);
             }
             $this->notifications = true;
         } else {
             $this->session = @mapi_logon_zarafa($user, $pass, MAPI_SERVER);
             $this->notifications = false;
         }
         if (mapi_last_hresult()) {
             ZLog::Write(LOGLEVEL_ERROR, sprintf("KopanoBackend->Logon(): login failed with error code: 0x%X", mapi_last_hresult()));
             if (mapi_last_hresult() == MAPI_E_NETWORK_ERROR) {
                 throw new HTTPReturnCodeException("Error connecting to KC (login)", 503, null, LOGLEVEL_INFO);
             }
         }
     } catch (MAPIException $ex) {
         throw new AuthenticationRequiredException($ex->getDisplayMessage());
     }
     if (!$this->session) {
         ZLog::Write(LOGLEVEL_WARN, sprintf("KopanoBackend->Logon(): logon failed for user '%s'", $user));
         $this->defaultstore = false;
         return false;
     }
     // Get/open default store
     $this->defaultstore = $this->openMessageStore($this->mainUser);
     if (mapi_last_hresult() == MAPI_E_FAILONEPROVIDER) {
         throw new HTTPReturnCodeException("Error connecting to KC (open store)", 503, null, LOGLEVEL_INFO);
     }
     if ($this->defaultstore === false) {
         throw new AuthenticationRequiredException(sprintf("KopanoBackend->Logon(): User '%s' has no default store", $user));
     }
     $this->store = $this->defaultstore;
     $this->storeName = $this->mainUser;
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("KopanoBackend->Logon(): User '%s' is authenticated", $user));
     $this->isZPushEnabled();
     // check if this is a Zarafa 7 store with unicode support
     MAPIUtils::IsUnicodeStore($this->store);
     return true;
 }