Пример #1
0
 /**
  * @return string
  */
 public function ServiceAjax()
 {
     @\ob_start();
     $aResponseItem = null;
     $oException = null;
     $sAction = $this->oHttp->GetPost('Action', null);
     if (empty($sAction) && $this->oHttp->IsGet() && !empty($this->aPaths[2])) {
         $sAction = $this->aPaths[2];
     }
     try {
         if ($this->oHttp->IsPost() && !in_array($sAction, array('JsInfo', 'JsError')) && $this->Config()->Get('security', 'csrf_protection', false) && $this->oHttp->GetPost('XToken', '') !== \RainLoop\Utils::GetCsrfToken()) {
             throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidToken);
         } else {
             if (!empty($sAction)) {
                 $sMethodName = 'Do' . $sAction;
                 $this->Logger()->Write('Action: ' . $sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'AJAX');
                 $aPost = $this->oHttp->GetPostAsArray();
                 if (\is_array($aPost) && 0 < \count($aPost)) {
                     $this->oActions->SetActionParams($aPost, $sMethodName);
                     switch ($sMethodName) {
                         case 'DoLogin':
                         case 'DoAdminLogin':
                         case 'DoAccountAdd':
                             $this->Logger()->AddSecret($this->oActions->GetActionParam('Password', ''));
                             break;
                         case 'DoChangePassword':
                             $this->Logger()->AddSecret($this->oActions->GetActionParam('PrevPassword', ''));
                             $this->Logger()->AddSecret($this->oActions->GetActionParam('NewPassword', ''));
                             break;
                     }
                     $this->Logger()->Write(\MailSo\Base\Utils::Php2js($aPost, $this->Logger()), \MailSo\Log\Enumerations\Type::INFO, 'POST', true);
                 } else {
                     if (3 < \count($this->aPaths) && $this->oHttp->IsGet()) {
                         $this->oActions->SetActionParams(array('RawKey' => empty($this->aPaths[3]) ? '' : $this->aPaths[3]), $sMethodName);
                     }
                 }
                 if (\method_exists($this->oActions, $sMethodName) && \is_callable(array($this->oActions, $sMethodName))) {
                     $this->Plugins()->RunHook('ajax.action-pre-call', array($sAction));
                     $aResponseItem = \call_user_func(array($this->oActions, $sMethodName));
                     $this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem));
                 } else {
                     if ($this->Plugins()->HasAdditionalAjax($sMethodName)) {
                         $this->Plugins()->RunHook('ajax.action-pre-call', array($sAction));
                         $aResponseItem = $this->Plugins()->RunAdditionalAjax($sMethodName);
                         $this->Plugins()->RunHook('ajax.action-post-call', array($sAction, &$aResponseItem));
                     }
                 }
             }
         }
         if (!\is_array($aResponseItem)) {
             throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError);
         }
     } catch (\Exception $oException) {
         $aResponseItem = $this->oActions->ExceptionResponse(empty($sAction) ? 'Unknown' : $sAction, $oException);
         if (\is_array($aResponseItem) && 'Folders' === $sAction && $oException instanceof \RainLoop\Exceptions\ClientException) {
             $aResponseItem['ClearAuth'] = true;
         }
     }
     if (\is_array($aResponseItem)) {
         $aResponseItem['Time'] = (int) ((\microtime(true) - APP_START) * 1000);
     }
     $this->Plugins()->RunHook('filter.ajax-response', array($sAction, &$aResponseItem));
     @\header('Content-Type: application/json; charset=utf-8');
     $sResult = \MailSo\Base\Utils::Php2js($aResponseItem, $this->Logger());
     $sObResult = @\ob_get_clean();
     if ($this->Logger()->IsEnabled()) {
         if (0 < \strlen($sObResult)) {
             $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA');
         }
         if ($oException) {
             $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
         }
         $iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0);
         $this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult) ? \substr($sResult, 0, $iLimit) . '...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'AJAX');
     }
     return $sResult;
 }
Пример #2
0
 /**
  * @param \RainLoop\Actions $oActions
  * @param string $sNameForTest = ''
  *
  * @return \RainLoop\Model\Domain | null
  */
 public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
 {
     $oDomain = null;
     if ($this->bAdmin) {
         $bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
         $sName = (string) $oActions->GetActionParam('Name', '');
         $sIncHost = (string) $oActions->GetActionParam('IncHost', '');
         $iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
         $iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
         $bIncShortLogin = '******' === (string) $oActions->GetActionParam('IncShortLogin', '0');
         $bUseSieve = '1' === (string) $oActions->GetActionParam('UseSieve', '0');
         $bSieveAllowRaw = '1' === (string) $oActions->GetActionParam('SieveAllowRaw', '0');
         $sSieveHost = (string) $oActions->GetActionParam('SieveHost', '');
         $iSievePort = (int) $oActions->GetActionParam('SievePort', 4190);
         $iSieveSecure = (int) $oActions->GetActionParam('SieveSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
         $sOutHost = (string) $oActions->GetActionParam('OutHost', '');
         $iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
         $iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
         $bOutShortLogin = '******' === (string) $oActions->GetActionParam('OutShortLogin', '0');
         $bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
         $bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
         $sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
         if (0 < \strlen($sName) && 0 < strlen($sNameForTest) && false === \strpos($sName, '*')) {
             $sNameForTest = '';
         }
         if (0 < strlen($sName) || 0 < strlen($sNameForTest)) {
             $oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
             if ($oDomain instanceof \RainLoop\Model\Domain) {
                 if ($bCreate) {
                     throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
                 } else {
                     $oDomain->UpdateInstance($sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sWhiteList);
                 }
             } else {
                 $oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin, $bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure, $sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail, $sWhiteList);
             }
         }
         if ($oDomain) {
             $oDomain->SetSieveAllowRaw($bSieveAllowRaw);
         }
     }
     return $oDomain;
 }