예제 #1
0
 /**
  * @return bool
  */
 public function Connect()
 {
     $sHost = $this->bUseSsl ? 'ssl://' . $this->sHost : $this->sHost;
     if ($this->IsConnected()) {
         CApi::Log('already connected[' . $sHost . ':' . $this->iPort . ']: result = false', ELogLevel::Error);
         $this->Disconnect();
         return false;
     }
     $sErrorStr = '';
     $iErrorNo = 0;
     CApi::Log('start connect to ' . $sHost . ':' . $this->iPort);
     $this->rConnect = @fsockopen($sHost, $this->iPort, $iErrorNo, $sErrorStr, $this->iConnectTimeOut);
     if (!$this->IsConnected()) {
         CApi::Log('connection error[' . $sHost . ':' . $this->iPort . ']: fsockopen = false (' . $iErrorNo . ': ' . $sErrorStr . ')', ELogLevel::Error);
         return false;
     } else {
         CApi::Log('connected');
     }
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('stream_set_timeout')) {
         @stream_set_timeout($this->rConnect, $this->iSocketTimeOut);
     }
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('@stream_set_blocking')) {
         @stream_set_blocking($this->rConnect, true);
     }
     return true;
 }
예제 #2
0
 /**
  * @return bool
  */
 protected function clearImplementation()
 {
     if (\defined('PHP_SAPI') && 'cli' === PHP_SAPI && \MailSo\Base\Utils::FunctionExistsAndEnabled('system')) {
         \system('clear');
     }
     return true;
 }
예제 #3
0
 /**
  * @param string $sFileName
  * @param string $sFileHeader = ''
  *
  * @return void
  */
 public function __construct($sFileName, $sFileHeader = '')
 {
     $this->sFile = \APP_PRIVATE_DATA . 'configs/' . $sFileName;
     $this->sFileHeader = $sFileHeader;
     $this->aData = $this->defaultValues();
     $this->bUseApcCache = APP_USE_APC_CACHE && \MailSo\Base\Utils::FunctionExistsAndEnabled(array('apc_fetch', 'apc_store'));
 }
	/**
	 * @param bool $bSupported
	 * @param int $iSecurityType
	 * @param bool $bHasSupportedAuth = true
	 *
	 * @return bool
	 */
	public static function UseStartTLS($bSupported, $iSecurityType, $bHasSupportedAuth = true)
	{
		return ($bSupported &&
			(self::STARTTLS === $iSecurityType || 
				(self::AUTO_DETECT === $iSecurityType && (!$bHasSupportedAuth || \MailSo\Config::$PreferStartTlsIfAutoDetect))) &&
			\defined('STREAM_CRYPTO_METHOD_TLS_CLIENT') && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_socket_enable_crypto'));
	}
예제 #5
0
 /**
  * @param string $sFileName
  * @param string $sFileHeader = ''
  * @param string $sAdditionalFileName = ''
  *
  * @return void
  */
 public function __construct($sFileName, $sFileHeader = '', $sAdditionalFileName = '')
 {
     $this->sFile = \APP_PRIVATE_DATA . 'configs/' . \trim($sFileName);
     $sAdditionalFileName = \trim($sAdditionalFileName);
     $this->sAdditionalFile = \APP_PRIVATE_DATA . 'configs/' . $sAdditionalFileName;
     $this->sAdditionalFile = 0 < \strlen($sAdditionalFileName) && \file_exists($this->sAdditionalFile) ? $this->sAdditionalFile : '';
     $this->sFileHeader = $sFileHeader;
     $this->aData = $this->defaultValues();
     $this->bUseApcCache = APP_USE_APC_CACHE && \MailSo\Base\Utils::FunctionExistsAndEnabled(array('apc_fetch', 'apc_store'));
 }
예제 #6
0
 /**
  * @param string $sText
  *
  * @return \DOMDocument | bool
  */
 public static function GetDomFromText($sText)
 {
     static $bOnce = true;
     if ($bOnce) {
         $bOnce = false;
         if (\MailSo\Base\Utils::FunctionExistsAndEnabled('libxml_use_internal_errors')) {
             @\libxml_use_internal_errors(true);
         }
     }
     $oDom = new \DOMDocument('1.0', 'utf-8');
     $oDom->encoding = 'UTF-8';
     @$oDom->loadHTML('<' . '?xml version="1.0" encoding="utf-8"?' . '>' . '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>' . $sText . '</body></html>');
     return $oDom;
 }
예제 #7
0
파일: Loader.php 프로젝트: pigi72333/MailSo
 /**
  * @return array|null
  */
 public static function Statistic()
 {
     $aResult = null;
     if (self::$StoreStatistic) {
         $aResult = array('php' => array('phpversion' => PHP_VERSION, 'ssl' => (int) \function_exists('openssl_open'), 'iconv' => (int) \function_exists('iconv')));
         if (\MailSo\Base\Utils::FunctionExistsAndEnabled('memory_get_usage') && \MailSo\Base\Utils::FunctionExistsAndEnabled('memory_get_peak_usage')) {
             $aResult['php']['memory_get_usage'] = Utils::FormatFileSize(\memory_get_usage(true), 2);
             $aResult['php']['memory_get_peak_usage'] = Utils::FormatFileSize(\memory_get_peak_usage(true), 2);
         }
         self::SetStatistic('TimeDelta', \microtime(true) - self::GetStatistic('Inited'));
         $aResult['statistic'] = self::$aSetStatistic;
         $aResult['counts'] = self::$aIncStatistic;
     }
     return $aResult;
 }
예제 #8
0
 /**
  * @param string $sText
  * @param string $sHtmlAttrs = ''
  * @param string $sBodyAttrs = ''
  *
  * @return \DOMDocument|bool
  */
 public static function GetDomFromText($sText, $sHtmlAttrs = '', $sBodyAttrs = '')
 {
     $bState = true;
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('libxml_use_internal_errors')) {
         $bState = \libxml_use_internal_errors(true);
     }
     $oDom = new \DOMDocument('1.0', 'utf-8');
     $oDom->encoding = 'UTF-8';
     $oDom->strictErrorChecking = false;
     $oDom->formatOutput = false;
     @$oDom->loadHTML('<' . '?xml version="1.0" encoding="utf-8"?' . '>' . '<html ' . $sHtmlAttrs . '><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body ' . $sBodyAttrs . '>' . $sText . '</body></html>');
     @$oDom->normalizeDocument();
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('libxml_use_internal_errors')) {
         @\libxml_clear_errors();
     }
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('libxml_use_internal_errors')) {
         \libxml_use_internal_errors($bState);
     }
     return $oDom;
 }
예제 #9
0
 /**
  * @param string $sHostName = ''
  *
  * @return string
  */
 private function generateNewMessageId($sHostName = '')
 {
     if (0 === \strlen($sHostName)) {
         $sHostName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     }
     if (empty($sHostName) && \MailSo\Base\Utils::FunctionExistsAndEnabled('php_uname')) {
         $sHostName = \php_uname('n');
     }
     if (empty($sHostName)) {
         $sHostName = 'localhost';
     }
     return '<' . \md5(\rand(100000, 999999) . \time() . $sHostName . (\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? @\getmypid() : '')) . '@' . $sHostName . '>';
 }
예제 #10
0
 /**
  * @param string $sHeader
  *
  * @return string
  */
 public function GetHeader($sHeader)
 {
     $sResultHeader = '';
     $sServerKey = 'HTTP_' . \strtoupper(\str_replace('-', '_', $sHeader));
     $sResultHeader = $this->GetServer($sServerKey, '');
     if (0 === \strlen($sResultHeader) && \MailSo\Base\Utils::FunctionExistsAndEnabled('apache_request_headers')) {
         $sHeaders = \apache_request_headers();
         if (isset($sHeaders[$sHeader])) {
             $sResultHeader = $sHeaders[$sHeader];
         }
     }
     return $sResultHeader;
 }
예제 #11
0
 /**
  * @param string $sFileName
  * @param bool $bProcessSections = false
  *
  * @return array
  */
 public static function CustomParseIniFile($sFileName, $bProcessSections = false)
 {
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('parse_ini_file')) {
         return @\parse_ini_file($sFileName, !!$bProcessSections);
     }
     $sData = @\file_get_contents($sFileName);
     return \is_string($sData) ? @\parse_ini_string($sData, !!$bProcessSections) : null;
 }
예제 #12
0
 /**
  * @param string $sServerName
  * @param int $iPort
  * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
  *
  * @return void
  *
  * @throws \MailSo\Base\Exceptions\InvalidArgumentException
  * @throws \MailSo\Net\Exceptions\SocketAlreadyConnectedException
  * @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException
  */
 public function Connect($sServerName, $iPort, $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT)
 {
     if (!\MailSo\Base\Validator::NotEmptyString($sServerName, true) || !\MailSo\Base\Validator::PortInt($iPort)) {
         $this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \MailSo\Log\Enumerations\Type::ERROR, true);
     }
     if ($this->IsConnected()) {
         $this->writeLogException(new Exceptions\SocketAlreadyConnectedException(), \MailSo\Log\Enumerations\Type::ERROR, true);
     }
     $sServerName = \trim($sServerName);
     $sErrorStr = '';
     $iErrorNo = 0;
     $this->iSecurityType = $iSecurityType;
     $this->iConnectedPort = $iPort;
     $this->bSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::UseSSL($iPort, $iSecurityType);
     $this->sConnectedHost = $this->bSecure ? 'ssl://' . $sServerName : $sServerName;
     if (!$this->bSecure && \MailSo\Net\Enumerations\ConnectionSecurityType::SSL === $this->iSecurityType) {
         $this->writeLogException(new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('SSL isn\'t supported'), \MailSo\Log\Enumerations\Type::ERROR, true);
     }
     $this->iStartConnectTime = \microtime(true);
     $this->writeLog('Start connection to "' . $this->sConnectedHost . ':' . $this->iConnectedPort . '"', \MailSo\Log\Enumerations\Type::NOTE);
     $this->rConnect = @\fsockopen($this->sConnectedHost, $this->iConnectedPort, $iErrorNo, $sErrorStr, $this->iConnectTimeOut);
     if (!is_resource($this->rConnect)) {
         $this->writeLogException(new Exceptions\SocketCanNotConnectToHostException($sErrorStr, $iErrorNo, 'Can\'t connect to host "' . $this->sConnectedHost . ':' . $this->iConnectedPort . '"'), \MailSo\Log\Enumerations\Type::NOTICE, true);
     }
     $this->writeLog(\microtime(true) - $this->iStartConnectTime . ' (raw connection)', \MailSo\Log\Enumerations\Type::TIME);
     if ($this->rConnect) {
         if (\MailSo\Base\Utils::FunctionExistsAndEnabled('stream_set_timeout')) {
             @\stream_set_timeout($this->rConnect, $this->iSocketTimeOut);
         }
         if (\MailSo\Base\Utils::FunctionExistsAndEnabled('stream_set_blocking')) {
             @\stream_set_blocking($this->rConnect, 1);
         }
     }
 }
예제 #13
0
 /**
  * @param string $sSearch
  * @param string $sEscapeSign = '='
  *
  * @return string
  */
 private function specialConvertSearchValueLower($sSearch, $sEscapeSign = '=')
 {
     if (!\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower')) {
         return '';
     }
     return '%' . \str_replace(array($sEscapeSign, '_', '%'), array($sEscapeSign . $sEscapeSign, $sEscapeSign . '_', $sEscapeSign . '%'), (string) @\mb_strtolower($sSearch, 'UTF-8')) . '%';
 }
예제 #14
0
 public function UpdateDependentValues()
 {
     $this->Value = \trim($this->Value);
     $this->ValueCustom = \trim($this->ValueCustom);
     $this->TypeStr = \trim($this->TypeStr);
     $this->ValueLower = '';
     if (0 < \strlen($this->Value)) {
         // lower
         if ($this->IsEmail()) {
             $this->Value = \MailSo\Base\Utils::StrToLowerIfAscii($this->Value);
         }
         if ($this->IsName()) {
             $this->Value = \MailSo\Base\Utils::StripSpaces($this->Value);
         }
         // lower value for searching
         if (\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower')) {
             $this->ValueLower = (string) @\mb_strtolower($this->Value, 'UTF-8');
         }
         // phone value for searching
         if ($this->IsPhone()) {
             $sPhone = \trim($this->Value);
             $sPhone = \preg_replace('/^[+]+/', '', $sPhone);
             $sPhone = \preg_replace('/[^\\d]/', '', $sPhone);
             $this->ValueCustom = \trim($sPhone);
         }
     }
 }
예제 #15
0
 /**
  * @param string $sHeader
  *
  * @return string
  */
 public function GetHeaders()
 {
     $aHeaders = array();
     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apache_request_headers')) {
         $aHeaders = \apache_request_headers();
     }
     return $aHeaders;
 }
예제 #16
0
 /**
  * @return array|bool
  */
 public function StreamContextParams()
 {
     return \is_resource($this->rConnect) && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_context_get_options') ? \stream_context_get_params($this->rConnect) : false;
 }
예제 #17
0
 /**
  * @param string $sStr
  *
  * @return string
  */
 public static function CharsetDetect($sStr)
 {
     $mResult = '';
     if (!\MailSo\Base\Utils::IsAscii($sStr)) {
         $mResult = \MailSo\Base\Utils::IsMbStringSupported() && \MailSo\Base\Utils::FunctionExistsAndEnabled('mb_detect_encoding') ? @\mb_detect_encoding($sStr, 'auto', true) : false;
         if (false === $mResult && \MailSo\Base\Utils::IsIconvSupported()) {
             $mResult = \md5(@\iconv('utf-8', 'utf-8//IGNORE', $sStr)) === \md5($sStr) ? 'utf-8' : '';
         }
     }
     return \is_string($mResult) && 0 < \strlen($mResult) ? $mResult : '';
 }
예제 #18
0
 /**
  * @staticvar bool $bOnce
  * @param string $sName
  * @param array $aData = array()
  *
  * @return bool
  */
 public function KeenIO($sName, $aData = array())
 {
     static $bOnce = null;
     if (false === $bOnce) {
         return false;
     }
     if (APP_VERSION === APP_DEV_VERSION || \in_array(APP_SITE, \explode(' ', \base64_decode('bG9jYWxob3N0IHJhaW5sb29wLmRlIHJhaW5sb29wLm5ldCBkZW1vLnJhaW5sb29wLm5ldCBkZW1vLnJhaW5sb29wLmRl')))) {
         return true;
     }
     if (null === $bOnce && (!\MailSo\Base\Utils::FunctionExistsAndEnabled('curl_init') || !\MailSo\Base\Utils::FunctionExistsAndEnabled('json_encode'))) {
         $bOnce = false;
         return false;
     }
     $aOptions = array(CURLOPT_URL => \base64_decode('aHR0cHM6Ly9hcGkua2Vlbi5pby8zLjAvcHJvamVjdHMvNTE2NmRmOGUzODQzMzE3Y2QzMDAwMDA2L2V2ZW50cy8=') . $sName, CURLOPT_HEADER => false, CURLOPT_FAILONERROR => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POST => true, CURLOPT_POSTFIELDS => \json_encode(\array_merge($aData, array('version' => APP_VERSION, 'uid' => \md5(APP_SITE . APP_SALT), 'site' => APP_SITE, 'date' => array('month' => \gmdate('m.Y'), 'day' => \gmdate('d.m.Y'))))), CURLOPT_TIMEOUT => 10);
     $sProxy = $this->Config()->Get('labs', 'curl_proxy', '');
     if (0 < \strlen($sProxy)) {
         $aOptions[CURLOPT_PROXY] = $sProxy;
         $sProxyAuth = $this->Config()->Get('labs', 'curl_proxy_auth', '');
         if (0 < \strlen($sProxyAuth)) {
             $aOptions[CURLOPT_PROXYUSERPWD] = $sProxyAuth;
         }
     }
     $oCurl = \curl_init();
     \curl_setopt_array($oCurl, $aOptions);
     $mResult = \curl_exec($oCurl);
     if (\is_resource($oCurl)) {
         \curl_close($oCurl);
     }
     return !!$mResult;
 }