/** * @return string */ public function licenseHelper($sForce = false, $bLongCache = false, $iFastCacheTimeInMin = 10, $iLongCacheTimeInDays = 3) { $sDomain = \trim(APP_SITE); $oCacher = $this->Cacher(null, true); $oHttp = \MailSo\Base\Http::SingletonInstance(); if (0 === \strlen($sDomain) || $oHttp->CheckLocalhost($sDomain) || !$oCacher || !$oCacher->Verify(true)) { return 'NO'; } $sDomainKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain); $sDomainLongKeyValue = \RainLoop\KeyPathHelper::LicensingDomainKeyOtherValue($sDomain); $sValue = ''; if (!$sForce) { if ($bLongCache) { $bLock = $oCacher->GetLock($sDomainLongKeyValue); $iTime = $bLock ? 0 : $oCacher->GetTimer($sDomainLongKeyValue); if ($bLock || 0 < $iTime && \time() < $iTime + 60 * 60 * 24 * $iLongCacheTimeInDays) { $sValue = $oCacher->Get($sDomainLongKeyValue); } } else { $iTime = $oCacher->GetTimer($sDomainKeyValue); if (0 < $iTime && \time() < $iTime + 60 * $iFastCacheTimeInMin) { $sValue = $oCacher->Get($sDomainKeyValue); } } } if (0 === \strlen($sValue)) { if ($bLongCache) { if (!$oCacher->SetTimer($sDomainLongKeyValue)) { return 'NO'; } $oCacher->SetLock($sDomainLongKeyValue); } $iCode = 0; $sContentType = ''; // $sValue = $oHttp->GetUrlAsString(APP_STATUS_PATH.$this->domainPathHelper($sDomain), // 'RainLoop/'.APP_VERSION, $sContentType, $iCode, $this->Logger(), 5, // $this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy_auth', ''), // array(), false // ); $sValue = $oHttp->GetUrlAsString(APP_API_PATH . 'status/' . \urlencode($sDomain), 'RainLoop/' . APP_VERSION, $sContentType, $iCode, $this->Logger(), 5, $this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy_auth', ''), array(), false); $this->Logger()->Write($sValue); /*if (404 === $iCode) { $sValue = 'NO'; } else */ if (200 !== $iCode) { $sValue = ''; } $oCacher->SetTimer($sDomainKeyValue); $oCacher->Set($sDomainKeyValue, $sValue); $oCacher->Set($sDomainLongKeyValue, $sValue); if ($bLongCache) { $oCacher->RemoveLock($sDomainLongKeyValue); } } return $sValue; }
/** * @return array */ public function DoAdminLicensing() { $iStart = \time(); $this->IsAdminLoggined(); $sForce = '1' === (string) $this->GetActionParam('Force', '0'); $mResult = false; $iErrorCode = -1; $oHttp = \MailSo\Base\Http::SingletonInstance(); if ($oHttp->CheckLocalhost(APP_SITE)) { return $this->DefaultResponse(__FUNCTION__, $mResult); } $sDomain = APP_SITE; if (2 < \strlen($sDomain)) { $sValue = ''; $iTime = $this->Cacher()->GetTimer(\RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain)); if (!$sForce && $iTime + 60 * 5 > \time()) { $sValue = $this->Cacher()->Get(\RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain)); } if (0 === \strlen($sValue)) { $iCode = 0; $sContentType = ''; $sValue = $oHttp->GetUrlAsString(APP_API_PATH . 'status/' . \urlencode($sDomain), 'RainLoop', $sContentType, $iCode, $this->Logger(), 10, $this->Config()->Get('labs', 'curl_proxy', ''), $this->Config()->Get('labs', 'curl_proxy_auth', '')); if (200 !== $iCode) { $sValue = ''; } if ($iStart === \time()) { \sleep(1); } $this->Cacher()->Set(\RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain), $sValue); $this->Cacher()->SetTimer(\RainLoop\KeyPathHelper::LicensingDomainKeyValue($sDomain)); } $aMatch = array(); if (5 < \strlen($sValue) && \preg_match('/^EXPIRED:([\\d]+)$/', $sValue, $aMatch)) { $mResult = array('Banned' => false, 'Expired' => (int) $aMatch[1]); } else { if ($sValue === 'NO') { $iErrorCode = -1; } else { if ($sValue === 'TOO_MANY_CONNECTIONS') { $iErrorCode = -1; } else { $iErrorCode = \RainLoop\Notifications::LicensingServerIsUnavailable; } } } } if (0 < $iErrorCode && !$mResult) { throw new \RainLoop\Exceptions\ClientException($iErrorCode); } return $this->DefaultResponse(__FUNCTION__, $mResult); }