예제 #1
0
 /**
  * @param string $sLine
  * @param \RainLoop\Model\Account $oAccount = null
  * @param bool $bUrlEncode = false
  *
  * @return string
  */
 private function compileLogParams($sLine, $oAccount = null, $bUrlEncode = false)
 {
     if (false !== \strpos($sLine, '{date:')) {
         $iTimeOffset = (int) $this->Config()->Get('logs', 'time_offset', 0);
         $sLine = \preg_replace_callback('/\\{date:([^}]+)\\}/', function ($aMatch) use($iTimeOffset, $bUrlEncode) {
             return \RainLoop\Utils::UrlEncode(\MailSo\Log\Logger::DateHelper($aMatch[1], $iTimeOffset), $bUrlEncode);
         }, $sLine);
         $sLine = \preg_replace('/\\{date:([^}]*)\\}/', 'date', $sLine);
     }
     if (false !== \strpos($sLine, '{imap:') || false !== \strpos($sLine, '{smtp:')) {
         if (!$oAccount) {
             $this->ParseQueryAuthString();
             $oAccount = $this->getAccountFromToken(false);
         }
         if ($oAccount) {
             $sLine = \str_replace('{imap:login}', \RainLoop\Utils::UrlEncode($oAccount->IncLogin(), $bUrlEncode), $sLine);
             $sLine = \str_replace('{imap:host}', \RainLoop\Utils::UrlEncode($oAccount->DomainIncHost(), $bUrlEncode), $sLine);
             $sLine = \str_replace('{imap:port}', \RainLoop\Utils::UrlEncode($oAccount->DomainIncPort(), $bUrlEncode), $sLine);
             $sLine = \str_replace('{smtp:login}', \RainLoop\Utils::UrlEncode($oAccount->OutLogin(), $bUrlEncode), $sLine);
             $sLine = \str_replace('{smtp:host}', \RainLoop\Utils::UrlEncode($oAccount->DomainOutHost(), $bUrlEncode), $sLine);
             $sLine = \str_replace('{smtp:port}', \RainLoop\Utils::UrlEncode($oAccount->DomainOutPort(), $bUrlEncode), $sLine);
         }
         $sLine = \preg_replace('/\\{imap:([^}]*)\\}/i', 'imap', $sLine);
         $sLine = \preg_replace('/\\{smtp:([^}]*)\\}/i', 'smtp', $sLine);
     }
     if (false !== \strpos($sLine, '{request:')) {
         if (false !== \strpos($sLine, '{request:ip}')) {
             $sLine = \str_replace('{request:ip}', \RainLoop\Utils::UrlEncode($this->Http()->GetClientIp($this->Config()->Get('labs', 'http_client_ip_check_proxy', false)), $bUrlEncode), $sLine);
         }
         if (false !== \strpos($sLine, '{request:domain}')) {
             $sLine = \str_replace('{request:domain}', \RainLoop\Utils::UrlEncode($this->Http()->GetHost(false, true, true), $bUrlEncode), $sLine);
         }
         if (false !== \strpos($sLine, '{request:domain-clear}')) {
             $sLine = \str_replace('{request:domain-clear}', \RainLoop\Utils::UrlEncode(\MailSo\Base\Utils::GetClearDomainName($this->Http()->GetHost(false, true, true)), $bUrlEncode), $sLine);
         }
         $sLine = \preg_replace('/\\{request:([^}]*)\\}/i', 'request', $sLine);
     }
     if (false !== \strpos($sLine, '{user:'******'{user:uid}')) {
             $sLine = \str_replace('{user:uid}', \RainLoop\Utils::UrlEncode(\base_convert(\sprintf('%u', \crc32(\md5(\RainLoop\Utils::GetConnectionToken()))), 10, 32), $bUrlEncode), $sLine);
         }
         if (false !== \strpos($sLine, '{user:ip}')) {
             $sLine = \str_replace('{user:ip}', \RainLoop\Utils::UrlEncode($this->Http()->GetClientIp($this->Config()->Get('labs', 'http_client_ip_check_proxy', false)), $bUrlEncode), $sLine);
         }
         if (\preg_match('/\\{user:(email|login|domain)\\}/i', $sLine)) {
             if (!$oAccount) {
                 $this->ParseQueryAuthString();
                 $oAccount = $this->getAccountFromToken(false);
             }
             if ($oAccount) {
                 $sEmail = $oAccount->Email();
                 $sLine = \str_replace('{user:email}', \RainLoop\Utils::UrlEncode($sEmail, $bUrlEncode), $sLine);
                 $sLine = \str_replace('{user:login}', \RainLoop\Utils::UrlEncode(\MailSo\Base\Utils::GetAccountNameFromEmail($sEmail), $bUrlEncode), $sLine);
                 $sLine = \str_replace('{user:domain}', \RainLoop\Utils::UrlEncode(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), $bUrlEncode), $sLine);
                 $sLine = \str_replace('{user:domain-clear}', \RainLoop\Utils::UrlEncode(\MailSo\Base\Utils::GetClearDomainName(\MailSo\Base\Utils::GetDomainFromEmail($sEmail)), $bUrlEncode), $sLine);
             }
         }
         $sLine = \preg_replace('/\\{user:([^}]*)\\}/i', 'unknown', $sLine);
     }
     if (false !== \strpos($sLine, '{labs:')) {
         $sLine = \preg_replace_callback('/\\{labs:rand:([1-9])\\}/', function ($aMatch) {
             return \rand(\pow(10, $aMatch[1] - 1), \pow(10, $aMatch[1]) - 1);
         }, $sLine);
         $sLine = \preg_replace('/\\{labs:([^}]*)\\}/', 'labs', $sLine);
     }
     return $sLine;
 }