/**
  * @param \RainLoop\Account $oAccount
  * @param string $sPrevPassword
  * @param string $sNewPassword
  *
  * @return bool
  */
 public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
 {
     if ($this->oLogger) {
         $this->oLogger->Write('DirectAdmin: Try to change password for ' . $oAccount->Email());
     }
     $bResult = false;
     if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) {
         $sEmail = \trim(\strtolower($oAccount->Email()));
         $sHost = \trim($this->sHost);
         $sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost);
         $sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost);
         $sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost);
         $sHost = \rtrim($this->sHost, '/\\');
         if (!\preg_match('/^http[s]?:\\/\\//i', $sHost)) {
             $sHost = 'http://' . $sHost;
         }
         $sUrl = $sHost . ':' . $this->iPort . '/CMD_CHANGE_EMAIL_PASSWORD';
         $iCode = 0;
         $oHttp = \MailSo\Base\Http::SingletonInstance();
         if ($this->oLogger) {
             $this->oLogger->Write('DirectAdmin[Api Request]:' . $sUrl);
         }
         $mResult = $oHttp->SendPostRequest($sUrl, array('email' => $sEmail, 'oldpassword' => $sPrevPassword, 'password1' => $sNewPassword, 'password2' => $sNewPassword, 'api' => '1'), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger);
         if (false !== $mResult && 200 === $iCode) {
             $aRes = null;
             @\parse_str($mResult, $aRes);
             if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) {
                 $bResult = true;
             } else {
                 if ($this->oLogger) {
                     $this->oLogger->Write('DirectAdmin[Error]: Response: ' . $mResult);
                 }
             }
         } else {
             if ($this->oLogger) {
                 $this->oLogger->Write('DirectAdmin[Error]: Empty Response: Code:' . $iCode);
             }
         }
     }
     return $bResult;
 }
 /**
  * @param \RainLoop\Account $oAccount
  *
  * @return bool
  */
 public function PasswordChangePossibility($oAccount)
 {
     return $oAccount && $oAccount->Domain() && \in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
 }
Beispiel #3
0
 /**
  * @param \RainLoop\Account $oAccount
  *
  * @throws \RainLoop\Exceptions\ClientException
  */
 public function CheckMailConnection($oAccount)
 {
     try {
         $this->MailClient()->Connect($oAccount->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())), $oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure())->Login($oAccount->IncLogin(), $oAccount->Password());
     } catch (\RainLoop\Exceptions\ClientException $oException) {
         throw $oException;
     } catch (\MailSo\Net\Exceptions\ConnectionException $oException) {
         throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ConnectionError, $oException);
     } catch (\Exception $oException) {
         throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError, $oException);
     }
 }