Road to the MIT

This commit is contained in:
RainLoop Team 2022-08-31 18:15:45 +00:00
parent 13d05dc2ff
commit aa5d3fc89d
75 changed files with 392 additions and 2283 deletions

View file

@ -112,9 +112,9 @@ class Actions
private $oTwoFactorAuthProvider;
/**
* @var \RainLoop\Providers\Prem
* @var \RainLoop\Providers\Version
*/
private $oPremProvider;
private $oVersionProvider;
/**
* @var \RainLoop\Config\Application
@ -157,7 +157,7 @@ class Actions
$this->oSuggestionsProvider = null;
$this->oChangePasswordProvider = null;
$this->oTwoFactorAuthProvider = null;
$this->oPremProvider = null;
$this->oVersionProvider = null;
$this->sSpecAuthToken = '';
$this->sUpdateAuthToken = '';
@ -841,25 +841,18 @@ class Actions
}
/**
* @return \RainLoop\Providers\Prem
* @return \RainLoop\Providers\Version
*/
public function PremProvider()
public function VersionProvider()
{
if (null === $this->oPremProvider)
if (null === $this->oVersionProvider)
{
if (\file_exists(APP_VERSION_ROOT_PATH.'app/libraries/RainLoop/Providers/Prem.php'))
{
$this->oPremProvider = new \RainLoop\Providers\Prem(
$this->Config(), $this->Logger(), $this->Cacher(null, true)
);
}
else
{
$this->oPremProvider = false;
}
$this->oVersionProvider = new \RainLoop\Providers\Version(
$this->Config(), $this->Logger()
);
}
return $this->oPremProvider;
return $this->oVersionProvider;
}
/**
@ -1428,14 +1421,6 @@ class Actions
return $this->GetAccountFromCustomToken($this->getLocalAuthToken(), $bThrowExceptionOnFalse, true, true);
}
/**
* @return bool
*/
public function IsOpen()
{
return !$this->PremProvider();
}
/**
* @param bool $bAdmin = false
* @param bool $bMobile = false
@ -1482,7 +1467,7 @@ class Actions
'customLogoutLink' => $oConfig->Get('labs', 'custom_logout_link', ''),
'forgotPasswordLinkUrl' => \trim($oConfig->Get('login', 'forgot_password_link_url', '')),
'registrationLinkUrl' => \trim($oConfig->Get('login', 'registration_link_url', '')),
'hideSubmitButton' => (bool) $oConfig->Get('login', 'hide_submit_button', true),
'hideSubmitButton' => (bool) $oConfig->Get('login', 'hide_submit_button', false),
'jsHash' => \md5(\RainLoop\Utils::GetConnectionToken()),
'useImapThread' => (bool) $oConfig->Get('labs', 'use_imap_thread', false),
'useImapSubscribe' => (bool) $oConfig->Get('labs', 'use_imap_list_subscribe', true),
@ -1496,7 +1481,6 @@ class Actions
'themes' => $this->GetThemes($bMobile, false),
'languages' => $this->GetLanguages(false),
'languagesAdmin' => $this->GetLanguages(true),
'appVersionType' => APP_VERSION_TYPE,
'attachmentsActions' => $aAttachmentsActions
), $bAdmin ? array(
'adminHostUse' => '' !== $oConfig->Get('security', 'admin_panel_host', ''),
@ -1561,8 +1545,6 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
'ContactsIsAllowed' => false,
'ChangePasswordIsAllowed' => false,
'RequireTwoFactor' => false,
'Community' => true,
'PremType' => false,
'Admin' => array(),
'Capa' => array(),
'Plugins' => array(),
@ -1574,11 +1556,17 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
$aResult['AuthAccountHash'] = $sAuthAccountHash;
}
$oPremProvider = $this->PremProvider();
if ($oPremProvider)
{
$oPremProvider->PopulateAppData($aResult);
}
$aResult['LoginLogo'] = $oConfig->Get('branding', 'login_logo', '');
$aResult['LoginBackground'] = $oConfig->Get('branding', 'login_background', '');
$aResult['LoginCss'] = $oConfig->Get('branding', 'login_css', '');
$aResult['LoginDescription'] = $oConfig->Get('branding', 'login_desc', '');
$aResult['UserLogo'] = $oConfig->Get('branding', 'user_logo', '');
$aResult['UserLogoTitle'] = $oConfig->Get('branding', 'user_logo_title', '');
$aResult['UserLogoMessage'] = $oConfig->Get('branding', 'user_logo_message', '');
$aResult['UserIframeMessage'] = $oConfig->Get('branding', 'user_iframe_message', '');
$aResult['UserCss'] = $oConfig->Get('branding', 'user_css', '');
$aResult['WelcomePageUrl'] = $oConfig->Get('branding', 'welcome_page_url', '');
$aResult['WelcomePageDisplay'] = \strtolower($oConfig->Get('branding', 'welcome_page_display', 'none'));
if ('' !== $aResult['LoadingDescription'] && 'RainLoop' !== $aResult['LoadingDescription'])
{
@ -1811,9 +1799,6 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
$aResult['AllowDropboxSocial'] = (bool) $oConfig->Get('social', 'dropbox_enable', false);
$aResult['DropboxApiKey'] = (string) $oConfig->Get('social', 'dropbox_api_key', '');
$aResult['SubscriptionEnabled'] = (bool) \MailSo\Base\Utils::ValidateDomain($aResult['AdminDomain'], true);
// || \MailSo\Base\Utils::ValidateIP($aResult['AdminDomain']);
$aResult['WeakPassword'] = (bool) $oConfig->ValidatePassword('12345');
$aResult['CoreAccess'] = (bool) $this->rainLoopCoreAccess();
@ -3638,11 +3623,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
}
else if ($bVersionsCache)
{
$oPremProvider = $this->PremProvider();
if ($oPremProvider)
{
$oPremProvider->ClearOldVersion();
}
$this->VersionProvider()->ClearOldVersion();
}
$this->Plugins()->RunHook('service.app-delay-start-end');
@ -3884,11 +3865,19 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
$this->setConfigFromParams($oConfig, 'DropboxEnable', 'social', 'dropbox_enable', 'bool');
$this->setConfigFromParams($oConfig, 'DropboxApiKey', 'social', 'dropbox_api_key', 'string');
$oPremProvider = $this->PremProvider();
if ($oPremProvider)
{
$oPremProvider->PremSection($this, $oConfig);
}
$this->setConfigFromParams($oConfig, 'LoginLogo', 'branding', 'login_logo', 'string');
$this->setConfigFromParams($oConfig, 'LoginBackground', 'branding', 'login_background', 'string');
$this->setConfigFromParams($oConfig, 'LoginDescription', 'branding', 'login_desc', 'string');
$this->setConfigFromParams($oConfig, 'LoginCss', 'branding', 'login_css', 'string');
$this->setConfigFromParams($oConfig, 'UserLogo', 'branding', 'user_logo', 'string');
$this->setConfigFromParams($oConfig, 'UserLogoTitle', 'branding', 'user_logo_title', 'string');
$this->setConfigFromParams($oConfig, 'UserLogoMessage', 'branding', 'user_logo_message', 'string');
$this->setConfigFromParams($oConfig, 'UserIframeMessage', 'branding', 'user_iframe_message', 'string');
$this->setConfigFromParams($oConfig, 'UserCss', 'branding', 'user_css', 'string');
$this->setConfigFromParams($oConfig, 'WelcomePageUrl', 'branding', 'welcome_page_url', 'string');
$this->setConfigFromParams($oConfig, 'WelcomePageDisplay', 'branding', 'welcome_page_display', 'string');
return $this->DefaultResponse(__FUNCTION__, $oConfig->Save());
}
@ -3971,48 +3960,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
public function DoAdminLicensing()
{
$this->IsAdminLoggined();
$bForce = '1' === (string) $this->GetActionParam('Force', '0');
$mResult = false;
$iErrorCode = -1;
$oPremProvider = $this->PremProvider();
if ($oPremProvider && 2 < \strlen(APP_SITE))
{
$sValue = $oPremProvider->Fetcher($bForce);
$this->requestSleep();
$iExpired = 0;
if ($oPremProvider->Parser($sValue, $iExpired))
{
$mResult = array(
'Banned' => false,
'Expired' => $iExpired,
);
}
else if ($sValue === 'NO' || \preg_match('/^EXPIRED:[\d]+$/', $sValue))
{
$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);
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::LicensingServerIsUnavailable);
}
/**
@ -4021,50 +3969,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
public function DoAdminLicensingActivate()
{
$this->IsAdminLoggined();
$sDomain = (string) $this->GetActionParam('Domain', '');
$sKey = (string) $this->GetActionParam('Key', '');
$mResult = false;
$iErrorCode = -1;
$oPrem = $this->PremProvider();
if ($oPrem && 2 < \strlen($sDomain) && 2 < \strlen($sKey) && $sDomain === APP_SITE)
{
$iCode = 0;
$sValue = $oPrem->Activate($sDomain, $sKey, $iCode);
$this->requestSleep();
$aMatch = array();
if ('OK' === $sValue)
{
$mResult = true;
}
else if ('TOO_MANY_CONNECTIONS' === $sValue)
{
$mResult = 'Too many connections. Please try again later.';
}
else if (\preg_match('/^ERROR:(.+)$/', $sValue, $aMatch) && !empty($aMatch[1]))
{
$mResult = trim($aMatch[1]);
$this->Logger()->Write('Activation error for: '.$sKey.' ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR);
$this->Logger()->Write($mResult, \MailSo\Log\Enumerations\Type::ERROR);
}
else
{
$iErrorCode = \RainLoop\Notifications::LicensingServerIsUnavailable;
}
}
if (0 < $iErrorCode && !$mResult)
{
throw new \RainLoop\Exceptions\ClientException($iErrorCode);
}
return $this->DefaultResponse(__FUNCTION__, $mResult);
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::LicensingServerIsUnavailable);
}
/**
@ -4670,7 +4575,6 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
$bRainLoopUpdatable = $this->rainLoopUpdatable();
$bRainLoopAccess = $this->rainLoopCoreAccess();
$oPremProvider = $this->PremProvider();
$aData = array();
if ($bRainLoopUpdatable && $bRainLoopAccess)
@ -4679,9 +4583,9 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
}
$bResult = false;
if ($bReal && $oPremProvider && !empty($aData['file']))
if ($bReal && !empty($aData['file']))
{
$bResult = $oPremProvider->UpdateCore($this, $aData['file']);
$bResult = $this->VersionProvider()->UpdateCore($this, $aData['file']);
}
return $this->DefaultResponse(__FUNCTION__, $bResult);
@ -9701,9 +9605,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc LangLink IncludeBackground Plugins
*/
public function StaticPath($sPath)
{
$sKey = defined('APP_VERSION_TYPE') && 0 < strlen(APP_VERSION_TYPE) ? APP_VERSION_TYPE :
($this->IsOpen() ? 'community' : 'standard');
$sKey = 'legacy';
$sResult = \RainLoop\Utils::WebStaticPath().$sPath;
return $sResult.(false === \strpos($sResult, '?') ? '?' : '&').$sKey;
}

View file

@ -269,7 +269,7 @@ class Application extends \RainLoop\Config\AbstractConfig
'welcome_page' => array(false, ''),
'hide_submit_button' => array(true),
'hide_submit_button' => array(false),
'forgot_password_link_url' => array('', ''),
'registration_link_url' => array('', ''),

View file

@ -4,7 +4,6 @@ namespace RainLoop\Enumerations;
class Capa
{
const PREM = 'PREM';
const TWO_FACTOR = 'TWO_FACTOR';
const TWO_FACTOR_FORCE = 'TWO_FACTOR_FORCE';
const OPEN_PGP = 'OPEN_PGP';

View file

@ -1,390 +0,0 @@
<?php
namespace RainLoop\Providers;
class Prem
{
/**
* @return void
*/
public function __construct($oConfig, $oLogger, $oCacher)
{
$this->oConfig = $oConfig;
$this->oLogger = $oLogger;
$this->oCacher = $oCacher;
}
/**
* @return bool
*/
public function Type()
{
static $bResult = null;
if (null === $bResult)
{
$bResult = $this->Parser($this->Fetcher(false, true));
}
return $bResult;
}
/**
* @return bool
*/
public function IsActive()
{
return true;
}
/**
* @param string $sInput
* @param int $iExpired = 0
*
* @return bool
*/
public function Parser($sInput, &$iExpired = 0)
{
$aMatch = array();
if (\preg_match('/^EXPIRED:([\d]+)$/', $sInput, $aMatch))
{
$iExpired = (int) $aMatch[1];
return \time() < $iExpired;
}
return false;
}
/**
* @param array $aAppData
*/
public function PopulateAppData(&$aAppData)
{
if (\is_array($aAppData))
{
$aAppData['Community'] = false;
$oConfig = $this->oConfig;
if ($oConfig && $this->Type())
{
$aAppData['PremType'] = true;
$aAppData['LoginLogo'] = $oConfig->Get('branding', 'login_logo', '');
$aAppData['LoginBackground'] = $oConfig->Get('branding', 'login_background', '');
$aAppData['LoginCss'] = $oConfig->Get('branding', 'login_css', '');
$aAppData['LoginDescription'] = $oConfig->Get('branding', 'login_desc', '');
$aAppData['UserLogo'] = $oConfig->Get('branding', 'user_logo', '');
$aAppData['UserLogoTitle'] = $oConfig->Get('branding', 'user_logo_title', '');
$aAppData['UserLogoMessage'] = $oConfig->Get('branding', 'user_logo_message', '');
$aAppData['UserIframeMessage'] = $oConfig->Get('branding', 'user_iframe_message', '');
$aAppData['UserCss'] = $oConfig->Get('branding', 'user_css', '');
$aAppData['WelcomePageUrl'] = $oConfig->Get('branding', 'welcome_page_url', '');
$aAppData['WelcomePageDisplay'] = \strtolower($oConfig->Get('branding', 'welcome_page_display', 'none'));
}
}
}
public function PremSection(&$oActions, &$oConfig)
{
if ($oActions && $oActions->HasOneOfActionParams(array(
'LoginLogo', 'LoginBackground', 'LoginDescription', 'LoginCss',
'UserLogo', 'UserLogoTitle', 'UserLogoMessage', 'UserIframeMessage', 'UserCss',
'WelcomePageUrl', 'WelcomePageDisplay'
)) && $this->Type())
{
$oActions->setConfigFromParams($oConfig, 'LoginLogo', 'branding', 'login_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginBackground', 'branding', 'login_background', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginDescription', 'branding', 'login_desc', 'string');
$oActions->setConfigFromParams($oConfig, 'LoginCss', 'branding', 'login_css', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogo', 'branding', 'user_logo', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoTitle', 'branding', 'user_logo_title', 'string');
$oActions->setConfigFromParams($oConfig, 'UserLogoMessage', 'branding', 'user_logo_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserIframeMessage', 'branding', 'user_iframe_message', 'string');
$oActions->setConfigFromParams($oConfig, 'UserCss', 'branding', 'user_css', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageUrl', 'branding', 'welcome_page_url', 'string');
$oActions->setConfigFromParams($oConfig, 'WelcomePageDisplay', 'branding', 'welcome_page_display', 'string');
}
}
/**
* @return string
*/
public function Activate($sDomain, $sKey, &$iCode)
{
$iCode = 0;
$sContentType = '';
$oHttp = \MailSo\Base\Http::SingletonInstance();
$sResult = $oHttp->GetUrlAsString(APP_API_PATH.'activate/'.\urlencode($sDomain).'/'.\urlencode($sKey),
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $this->oLogger, 10,
$this->oConfig->Get('labs', 'curl_proxy', ''), $this->oConfig->Get('labs', 'curl_proxy_auth', ''),
array(), false
);
if (200 !== $iCode)
{
$sResult = '';
}
return $sResult;
}
/**
* @return string
*/
public function Fetcher($sForce = false, $bLongCache = false, $iFastCacheTimeInMin = 10, $iLongCacheTimeInDays = 3)
{
$sDomain = \trim(APP_SITE);
$oConfig = $this->oConfig;
$oLogger = $this->oLogger;
$oCacher = $this->oCacher;
$oHttp = \MailSo\Base\Http::SingletonInstance();
if (0 === \strlen($sDomain) || $oHttp->CheckLocalhost($sDomain) || !$oCacher || !$oConfig || !$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_API_PATH.'status/'.\urlencode($sDomain),
'RainLoop/'.APP_VERSION, $sContentType, $iCode, $oLogger, 5,
$oConfig->Get('labs', 'curl_proxy', ''), $oConfig->Get('labs', 'curl_proxy_auth', ''),
array(), false
);
if ($oLogger)
{
$oLogger->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;
}
public function ClearOldVersion()
{
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin');
}
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir'));
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Count:'.(\is_array($aDirs) ? \count($aDirs) : 0));
}
if (\is_array($aDirs) && 5 < \count($aDirs))
{
\uasort($aDirs, 'version_compare');
foreach ($aDirs as $sName)
{
if (APP_DEV_VERSION !== $sName && APP_VERSION !== $sName)
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin to remove "'.$sVPath.$sName.'" version');
}
if (@\unlink($sVPath.$sName.'/index.php'))
{
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC (Error): index file cant be removed from"'.$sVPath.$sName.'"',
\MailSo\Log\Enumerations\Type::ERROR);
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
}
break;
}
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End');
}
}
public function UpdateCore($oActions, $sFile)
{
$bResult = false;
$sNewVersion = '';
$sTmp = $oActions->downloadRemotePackageByUrl($sFile);
if (!empty($sTmp))
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/pclzip/pclzip.lib.php';
$oArchive = new \PclZip($sTmp);
$sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp);
\mkdir($sTmpFolder);
if (\is_dir($sTmpFolder))
{
$bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
if (!$bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
if ($bResult && \file_exists($sTmpFolder.'/index.php') &&
\is_writable(APP_INDEX_ROOT_PATH.'rainloop/') &&
\is_writable(APP_INDEX_ROOT_PATH.'index.php') &&
\is_dir($sTmpFolder.'/rainloop/'))
{
$aMatch = array();
$sIndexFile = \file_get_contents($sTmpFolder.'/index.php');
if (\preg_match('/\'APP_VERSION\', \'([^\']+)\'/', $sIndexFile, $aMatch) && !empty($aMatch[1]))
{
$sNewVersion = \trim($aMatch[1]);
}
if (empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('Unknown version', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
else if (!\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion))
{
\MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/');
if (\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion) &&
\is_file(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion.'/index.php'))
{
$bResult = \copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php');
if ($bResult)
{
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('opcache_invalidate'))
{
@\opcache_invalidate(APP_INDEX_ROOT_PATH.'index.php', true);
}
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_delete_file'))
{
@\apc_delete_file(APP_INDEX_ROOT_PATH.'index.php');
}
}
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
$this->oLogger->Write($sTmpFolder.'/rainloop/ -> '.APP_INDEX_ROOT_PATH.'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if (!empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('"'.$sNewVersion.'" version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if ($bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot validate package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
\MailSo\Base\Utils::RecRmDir($sTmpFolder);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot create tmp folder: '.$sTmpFolder, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
@\unlink($sTmp);
}
return $bResult;
}
}

View file

@ -0,0 +1,188 @@
<?php
namespace RainLoop\Providers;
class Version
{
/**
* @return void
*/
public function __construct($oConfig, $oLogger)
{
$this->oConfig = $oConfig;
$this->oLogger = $oLogger;
}
/**
* @return bool
*/
public function IsActive()
{
return true;
}
public function ClearOldVersion()
{
$sVPath = APP_INDEX_ROOT_PATH.'rainloop/v/';
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin');
}
$aDirs = @\array_map('basename', @\array_filter(@\glob($sVPath.'*'), 'is_dir'));
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Count:'.(\is_array($aDirs) ? \count($aDirs) : 0));
}
if (\is_array($aDirs) && 5 < \count($aDirs))
{
\uasort($aDirs, 'version_compare');
foreach ($aDirs as $sName)
{
if (APP_DEV_VERSION !== $sName && APP_VERSION !== $sName)
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: Begin to remove "'.$sVPath.$sName.'" version');
}
if (@\unlink($sVPath.$sName.'/index.php'))
{
@\MailSo\Base\Utils::RecRmDir($sVPath.$sName);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC (Error): index file cant be removed from"'.$sVPath.$sName.'"',
\MailSo\Log\Enumerations\Type::ERROR);
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End to remove "'.$sVPath.$sName.'" version');
}
break;
}
}
}
if ($this->oLogger)
{
$this->oLogger->Write('Versions GC: End');
}
}
public function UpdateCore($oActions, $sFile)
{
$bResult = false;
$sNewVersion = '';
$sTmp = $oActions->downloadRemotePackageByUrl($sFile);
if (!empty($sTmp))
{
include_once APP_VERSION_ROOT_PATH.'app/libraries/pclzip/pclzip.lib.php';
$oArchive = new \PclZip($sTmp);
$sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp);
\mkdir($sTmpFolder);
if (\is_dir($sTmpFolder))
{
$bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
if (!$bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
if ($bResult && \file_exists($sTmpFolder.'/index.php') &&
\is_writable(APP_INDEX_ROOT_PATH.'rainloop/') &&
\is_writable(APP_INDEX_ROOT_PATH.'index.php') &&
\is_dir($sTmpFolder.'/rainloop/'))
{
$aMatch = array();
$sIndexFile = \file_get_contents($sTmpFolder.'/index.php');
if (\preg_match('/\'APP_VERSION\', \'([^\']+)\'/', $sIndexFile, $aMatch) && !empty($aMatch[1]))
{
$sNewVersion = \trim($aMatch[1]);
}
if (empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('Unknown version', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
else if (!\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion))
{
\MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/');
if (\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion) &&
\is_file(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion.'/index.php'))
{
$bResult = \copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php');
if ($bResult)
{
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('opcache_invalidate'))
{
@\opcache_invalidate(APP_INDEX_ROOT_PATH.'index.php', true);
}
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_delete_file'))
{
@\apc_delete_file(APP_INDEX_ROOT_PATH.'index.php');
}
}
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
$this->oLogger->Write($sTmpFolder.'/rainloop/ -> '.APP_INDEX_ROOT_PATH.'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if (!empty($sNewVersion))
{
if ($this->oLogger)
{
$this->oLogger->Write('"'.$sNewVersion.'" version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
}
else if ($bResult)
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot validate package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
\MailSo\Base\Utils::RecRmDir($sTmpFolder);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Cannot create tmp folder: '.$sTmpFolder, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
}
@\unlink($sTmp);
}
return $bResult;
}
}

View file

@ -230,16 +230,7 @@ class Service
$sResult .= '<!--';
$sResult .= '[time:'.\substr(\microtime(true) - APP_START, 0, 6);
// $sResult .= '][version:'.APP_VERSION;
if ($this->oActions->IsOpen())
{
$sResult .= '][AGPLv3';
}
$sResult .= '][cached:'.($bCached ? 'true' : 'false');
// $sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}'];
// $sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken());
if ($bMobile)
{