es5 -> es2015 (last stage)

Signature plugin fixes
Add view decorator
A large number of fixes
This commit is contained in:
RainLoop Team 2016-08-17 01:01:20 +03:00
parent e88c193334
commit 17669b7be0
153 changed files with 21193 additions and 21115 deletions

View file

@ -1,2 +0,0 @@
/Prem/**
/_Prem/**

View file

@ -820,9 +820,9 @@ class Actions
{
if (null === $this->oPremProvider)
{
if (\file_exists(APP_VERSION_ROOT_PATH.'app/libraries/RainLoop/Prem/Provider.php'))
if (\file_exists(APP_VERSION_ROOT_PATH.'app/libraries/RainLoop/Providers/Prem.php'))
{
$this->oPremProvider = new \RainLoop\Prem\Provider(
$this->oPremProvider = new \RainLoop\Providers\Prem(
$this->Config(), $this->Logger(), $this->Cacher(null, true)
);
}
@ -1466,8 +1466,7 @@ class Actions
'themes' => $this->GetThemes($bMobile, false),
'languages' => $this->GetLanguages(false),
'languagesAdmin' => $this->GetLanguages(true),
'attachmentsActions' => $aAttachmentsActions,
'openpgpPublicKeyServer' => $oConfig->Get('security', 'openpgp_public_key_server', '')
'attachmentsActions' => $aAttachmentsActions
), $bAdmin ? array(
'adminHostUse' => '' !== $oConfig->Get('security', 'admin_panel_host', ''),
'adminPath' => \strtolower($oConfig->Get('security', 'admin_panel_key', 'admin')),
@ -2357,7 +2356,8 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
$this->Logger()->AddSecret($sPassword);
if ('sleep@sleep.dev' === $sEmail && 0 < \strlen($sPassword) &&
\is_numeric($sPassword) && $this->Config()->Get('debug', 'enable', false)
\is_numeric($sPassword) && $this->Config()->Get('debug', 'enable', false) &&
0 < (int) $sPassword && 30 > (int) $sPassword
)
{
\sleep((int) $sPassword);
@ -5179,8 +5179,11 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
$aCache = array(
'Sent' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Send' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Outbox' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Out box' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Sent Item' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Sent Items' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Send Item' => \MailSo\Imap\Enumerations\FolderType::SENT,
@ -5199,6 +5202,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
'Drafts Mails' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
'Spam' => \MailSo\Imap\Enumerations\FolderType::JUNK,
'Spams' => \MailSo\Imap\Enumerations\FolderType::JUNK,
'Junk' => \MailSo\Imap\Enumerations\FolderType::JUNK,
'Bulk Mail' => \MailSo\Imap\Enumerations\FolderType::JUNK,
@ -5209,14 +5213,22 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
'Bin' => \MailSo\Imap\Enumerations\FolderType::TRASH,
'Archive' => \MailSo\Imap\Enumerations\FolderType::ALL,
'Archives' => \MailSo\Imap\Enumerations\FolderType::ALL,
'All' => \MailSo\Imap\Enumerations\FolderType::ALL,
'All Mail' => \MailSo\Imap\Enumerations\FolderType::ALL,
'All Mails' => \MailSo\Imap\Enumerations\FolderType::ALL,
'AllMail' => \MailSo\Imap\Enumerations\FolderType::ALL,
'AllMails' => \MailSo\Imap\Enumerations\FolderType::ALL,
);
$aNewCache = array();
foreach ($aCache as $sKey => $iType)
{
$aNewCache[$sKey] = $iType;
$aNewCache[\str_replace(' ', '', $sKey)] = $iType;
}
$aCache = $aNewCache;
$this->Plugins()->RunHook('filter.system-folders-names', array($oAccount, &$aCache));
}
@ -8416,35 +8428,35 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
case 1:
break;
case 2: // horizontal flip
case 2: // flip horizontal
$oImage->flipHorizontally();
break;
case 3: // 180 rotate left
case 3: // rotate 180
$oImage->rotate(180);
break;
case 4: // vertical flip
case 4: // flip vertical
$oImage->flipVertically();
break;
case 5: // vertical flip + 90 rotate right
case 5: // vertical flip + 90 rotate
$oImage->flipVertically();
$oImage->rotate(-90);
break;
case 6: // 90 rotate right
$oImage->rotate(-90);
break;
case 7: // horizontal flip + 90 rotate right
$oImage->flipHorizontally();
$oImage->rotate(-90);
break;
case 8: // 90 rotate left
$oImage->rotate(90);
break;
case 6: // rotate 90
$oImage->rotate(90);
break;
case 7: // horizontal flip + 90 rotate
$oImage->flipHorizontally();
$oImage->rotate(90);
break;
case 8: // rotate 270
$oImage->rotate(270);
break;
}
}
}
@ -8586,8 +8598,6 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
$self->cacheByKey($sRawKey);
$sLoadedData = null;
$bDetectImageOrientation = false;
if (!$bDownload)
{
if ($bThumbnail)
@ -9606,7 +9616,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
private function hashFolderFullName($sFolderFullName)
{
return \in_array(\strtolower($sFolderFullName), array('inbox', 'sent', 'send', 'drafts',
'spam', 'junk', 'bin', 'trash', 'archive', 'allmail')) ?
'spam', 'junk', 'bin', 'trash', 'archive', 'allmail', 'all')) ?
$sFolderFullName : \md5($sFolderFullName);
}

View file

@ -1,273 +1,273 @@
<?php
namespace RainLoop;
class Api
{
/**
* @return void
*/
private function __construct()
{
}
/**
* @return bool
*/
public static function RunResult()
{
return true;
}
/**
* @staticvar bool $bOne
* @return bool
*/
public static function Handle()
{
static $bOne = null;
if (null === $bOne)
{
$bOne = \class_exists('MailSo\Version');
if ($bOne)
{
\RainLoop\Api::SetupDefaultMailSoConfig();
$bOne = \RainLoop\Api::RunResult();
}
}
return $bOne;
}
/**
* @return \RainLoop\Actions
*/
public static function Actions()
{
static $oActions = null;
if (null === $oActions)
{
$oActions = \RainLoop\Actions::NewInstance();
}
return $oActions;
}
/**
* @return \RainLoop\Application
*/
public static function Config()
{
return \RainLoop\Api::Actions()->Config();
}
/**
* @return \MailSo\Log\Logger
*/
public static function Logger()
{
return \RainLoop\Api::Actions()->Logger();
}
/**
* @return string
*/
public static function SetupDefaultMailSoConfig()
{
if (\class_exists('MailSo\Config'))
{
if (\RainLoop\Api::Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
\MailSo\Base\Utils::IsMbStringSupported() && \MailSo\Config::$MBSTRING)
{
\MailSo\Config::$ICONV = false;
}
\MailSo\Config::$MessageListFastSimpleSearch =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
\MailSo\Config::$MessageListCountLimitTrigger =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
\MailSo\Config::$MessageListDateFilter =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
\MailSo\Config::$MessageListPermanentFilter =
\trim(\RainLoop\Api::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
\MailSo\Config::$MessageAllHeaders =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_all_headers', false);
\MailSo\Config::$LargeThreadLimit =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_large_thread_limit', 50);
\MailSo\Config::$ImapTimeout =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_timeout', 300);
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
$sSslCafile = \RainLoop\Api::Config()->Get('ssl', 'cafile', '');
$sSslCapath = \RainLoop\Api::Config()->Get('ssl', 'capath', '');
\RainLoop\Utils::$CookieDefaultPath = \RainLoop\Api::Config()->Get('labs', 'cookie_default_path', '');
if (\RainLoop\Api::Config()->Get('labs', 'cookie_default_secure', false))
{
\RainLoop\Utils::$CookieDefaultSecure = true;
}
if (!empty($sSslCafile) || !empty($sSslCapath))
{
\MailSo\Hooks::Add('Net.NetClient.StreamContextSettings/Filter', function (&$aStreamContextSettings) use ($sSslCafile, $sSslCapath) {
if (isset($aStreamContextSettings['ssl']) && \is_array($aStreamContextSettings['ssl']))
{
if (empty($aStreamContextSettings['ssl']['cafile']) && !empty($sSslCafile))
{
$aStreamContextSettings['ssl']['cafile'] = $sSslCafile;
}
if (empty($aStreamContextSettings['ssl']['capath']) && !empty($sSslCapath))
{
$aStreamContextSettings['ssl']['capath'] = $sSslCapath;
}
}
});
}
\MailSo\Config::$HtmlStrictDebug = !!\RainLoop\Api::Config()->Get('debug', 'enable', false);
if (\RainLoop\Api::Config()->Get('labs', 'strict_html_parser', true))
{
\MailSo\Config::$HtmlStrictAllowedAttributes = array(
// rainloop
'data-wrp',
// defaults
'name',
'dir', 'lang', 'style', 'title',
'background', 'bgcolor', 'alt', 'height', 'width', 'src', 'href',
'border', 'bordercolor', 'charset', 'direction', 'language',
// a
'coords', 'download', 'hreflang', 'shape',
// body
'alink', 'bgproperties', 'bottommargin', 'leftmargin', 'link', 'rightmargin', 'text', 'topmargin', 'vlink',
'marginwidth', 'marginheight', 'offset',
// button,
'disabled', 'type', 'value',
// col
'align', 'valign',
// font
'color', 'face', 'size',
// form
'novalidate',
// hr
'noshade',
// img
'hspace', 'sizes', 'srcset', 'vspace', 'usemap',
// input, textarea
'checked', 'max', 'min', 'maxlength', 'multiple', 'pattern', 'placeholder', 'readonly', 'required', 'step', 'wrap',
// label
'for',
// meter
'low', 'high', 'optimum',
// ol
'reversed', 'start',
// option
'selected', 'label',
// table
'cols', 'rows', 'frame', 'rules', 'summary', 'cellpadding', 'cellspacing',
// td
'abbr', 'axis', 'colspan', 'rowspan', 'headers', 'nowrap'
);
}
}
}
/**
* @return string
*/
public static function Version()
{
return APP_VERSION;
}
/**
* @param string $sEmail
* @param string $sPassword
* @param array $aAdditionalOptions = array()
* @param bool $bUseTimeout = true
*
* @return string
*/
public static function GetUserSsoHash($sEmail, $sPassword, $aAdditionalOptions = array(), $bUseTimeout = true)
{
$sSsoHash = \MailSo\Base\Utils::Sha1Rand($sEmail.$sPassword);
return \RainLoop\Api::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
\RainLoop\Utils::EncodeKeyValuesQ(array(
'Email' => $sEmail,
'Password' => $sPassword,
'AdditionalOptions' => $aAdditionalOptions,
'Time' => $bUseTimeout ? \time() : 0
))) ? $sSsoHash : '';
}
/**
* @param string $sSsoHash
*
* @return bool
*/
public static function ClearUserSsoHash($sSsoHash)
{
return \RainLoop\Api::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
}
/**
* @param string $sEmail
*
* @return bool
*/
public static function ClearUserData($sEmail)
{
if (0 < \strlen($sEmail))
{
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
$oStorageProvider = \RainLoop\Api::Actions()->StorageProvider();
if ($oStorageProvider && $oStorageProvider->IsActive())
{
$oStorageProvider->DeleteStorage($sEmail);
}
if (\RainLoop\Api::Actions()->AddressBookProvider() &&
\RainLoop\Api::Actions()->AddressBookProvider()->IsActive())
{
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
}
return true;
}
return false;
}
/**
* @return bool
*/
public static function LogoutCurrentLogginedUser()
{
\RainLoop\Utils::ClearCookie('rlsession');
return true;
}
/**
* @return void
*/
public static function ExitOnEnd()
{
if (!\defined('RAINLOOP_EXIT_ON_END'))
{
\define('RAINLOOP_EXIT_ON_END', true);
}
}
}
<?php
namespace RainLoop;
class Api
{
/**
* @return void
*/
private function __construct()
{
}
/**
* @return bool
*/
public static function RunResult()
{
return true;
}
/**
* @staticvar bool $bOne
* @return bool
*/
public static function Handle()
{
static $bOne = null;
if (null === $bOne)
{
$bOne = \class_exists('MailSo\Version');
if ($bOne)
{
\RainLoop\Api::SetupDefaultMailSoConfig();
$bOne = \RainLoop\Api::RunResult();
}
}
return $bOne;
}
/**
* @return \RainLoop\Actions
*/
public static function Actions()
{
static $oActions = null;
if (null === $oActions)
{
$oActions = \RainLoop\Actions::NewInstance();
}
return $oActions;
}
/**
* @return \RainLoop\Application
*/
public static function Config()
{
return \RainLoop\Api::Actions()->Config();
}
/**
* @return \MailSo\Log\Logger
*/
public static function Logger()
{
return \RainLoop\Api::Actions()->Logger();
}
/**
* @return string
*/
public static function SetupDefaultMailSoConfig()
{
if (\class_exists('MailSo\Config'))
{
if (\RainLoop\Api::Config()->Get('labs', 'disable_iconv_if_mbstring_supported', false) &&
\MailSo\Base\Utils::IsMbStringSupported() && \MailSo\Config::$MBSTRING)
{
\MailSo\Config::$ICONV = false;
}
\MailSo\Config::$MessageListFastSimpleSearch =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
\MailSo\Config::$MessageListCountLimitTrigger =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
\MailSo\Config::$MessageListDateFilter =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
\MailSo\Config::$MessageListPermanentFilter =
\trim(\RainLoop\Api::Config()->Get('labs', 'imap_message_list_permanent_filter', ''));
\MailSo\Config::$MessageAllHeaders =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_all_headers', false);
\MailSo\Config::$LargeThreadLimit =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_large_thread_limit', 50);
\MailSo\Config::$ImapTimeout =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_timeout', 300);
\MailSo\Config::$BoundaryPrefix = '_RainLoop_';
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
$sSslCafile = \RainLoop\Api::Config()->Get('ssl', 'cafile', '');
$sSslCapath = \RainLoop\Api::Config()->Get('ssl', 'capath', '');
\RainLoop\Utils::$CookieDefaultPath = \RainLoop\Api::Config()->Get('labs', 'cookie_default_path', '');
if (\RainLoop\Api::Config()->Get('labs', 'cookie_default_secure', false))
{
\RainLoop\Utils::$CookieDefaultSecure = true;
}
if (!empty($sSslCafile) || !empty($sSslCapath))
{
\MailSo\Hooks::Add('Net.NetClient.StreamContextSettings/Filter', function (&$aStreamContextSettings) use ($sSslCafile, $sSslCapath) {
if (isset($aStreamContextSettings['ssl']) && \is_array($aStreamContextSettings['ssl']))
{
if (empty($aStreamContextSettings['ssl']['cafile']) && !empty($sSslCafile))
{
$aStreamContextSettings['ssl']['cafile'] = $sSslCafile;
}
if (empty($aStreamContextSettings['ssl']['capath']) && !empty($sSslCapath))
{
$aStreamContextSettings['ssl']['capath'] = $sSslCapath;
}
}
});
}
\MailSo\Config::$HtmlStrictDebug = !!\RainLoop\Api::Config()->Get('debug', 'enable', false);
if (\RainLoop\Api::Config()->Get('labs', 'strict_html_parser', true))
{
\MailSo\Config::$HtmlStrictAllowedAttributes = array(
// rainloop
'data-wrp',
// defaults
'name',
'dir', 'lang', 'style', 'title',
'background', 'bgcolor', 'alt', 'height', 'width', 'src', 'href',
'border', 'bordercolor', 'charset', 'direction', 'language',
// a
'coords', 'download', 'hreflang', 'shape',
// body
'alink', 'bgproperties', 'bottommargin', 'leftmargin', 'link', 'rightmargin', 'text', 'topmargin', 'vlink',
'marginwidth', 'marginheight', 'offset',
// button,
'disabled', 'type', 'value',
// col
'align', 'valign',
// font
'color', 'face', 'size',
// form
'novalidate',
// hr
'noshade',
// img
'hspace', 'sizes', 'srcset', 'vspace', 'usemap',
// input, textarea
'checked', 'max', 'min', 'maxlength', 'multiple', 'pattern', 'placeholder', 'readonly', 'required', 'step', 'wrap',
// label
'for',
// meter
'low', 'high', 'optimum',
// ol
'reversed', 'start',
// option
'selected', 'label',
// table
'cols', 'rows', 'frame', 'rules', 'summary', 'cellpadding', 'cellspacing',
// td
'abbr', 'axis', 'colspan', 'rowspan', 'headers', 'nowrap'
);
}
}
}
/**
* @return string
*/
public static function Version()
{
return APP_VERSION;
}
/**
* @param string $sEmail
* @param string $sPassword
* @param array $aAdditionalOptions = array()
* @param bool $bUseTimeout = true
*
* @return string
*/
public static function GetUserSsoHash($sEmail, $sPassword, $aAdditionalOptions = array(), $bUseTimeout = true)
{
$sSsoHash = \MailSo\Base\Utils::Sha1Rand(\md5($sEmail).\md5($sPassword));
return \RainLoop\Api::Actions()->Cacher()->Set(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash),
\RainLoop\Utils::EncodeKeyValuesQ(array(
'Email' => $sEmail,
'Password' => $sPassword,
'AdditionalOptions' => $aAdditionalOptions,
'Time' => $bUseTimeout ? \time() : 0
))) ? $sSsoHash : '';
}
/**
* @param string $sSsoHash
*
* @return bool
*/
public static function ClearUserSsoHash($sSsoHash)
{
return \RainLoop\Api::Actions()->Cacher()->Delete(\RainLoop\KeyPathHelper::SsoCacherKey($sSsoHash));
}
/**
* @param string $sEmail
*
* @return bool
*/
public static function ClearUserData($sEmail)
{
if (0 < \strlen($sEmail))
{
$sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail);
$oStorageProvider = \RainLoop\Api::Actions()->StorageProvider();
if ($oStorageProvider && $oStorageProvider->IsActive())
{
$oStorageProvider->DeleteStorage($sEmail);
}
if (\RainLoop\Api::Actions()->AddressBookProvider() &&
\RainLoop\Api::Actions()->AddressBookProvider()->IsActive())
{
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
}
return true;
}
return false;
}
/**
* @return bool
*/
public static function LogoutCurrentLogginedUser()
{
\RainLoop\Utils::ClearCookie('rlsession');
return true;
}
/**
* @return void
*/
public static function ExitOnEnd()
{
if (!\defined('RAINLOOP_EXIT_ON_END'))
{
\define('RAINLOOP_EXIT_ON_END', true);
}
}
}

View file

@ -200,7 +200,6 @@ class Application extends \RainLoop\Config\AbstractConfig
'x_frame_options_header' => array(''),
'openpgp' => array(false),
'openpgp_public_key_server' => array(''),
'admin_login' => array('admin', 'Login and password for web admin panel'),
'admin_password' => array('12345'),

View file

@ -1,404 +1,410 @@
<?php
namespace RainLoop\Providers\Domain;
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{
/**
* @var string
*/
protected $sDomainPath;
/**
* @var \MailSo\Cache\CacheClient
*/
protected $oCacher;
/**
* @param string $sDomainPath
* @param \MailSo\Cache\CacheClient $oCacher = null
*
* @return void
*/
public function __construct($sDomainPath, $oCacher = null)
{
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
$this->oCacher = $oCacher;
}
/**
* @param string $sName
* @param bool $bBack = false
*
* @return string
*/
public function codeFileName($sName, $bBack = false)
{
if ($bBack && 'default' === $sName)
{
return '*';
}
else if (!$bBack && '*' === $sName)
{
return 'default';
}
if ($bBack)
{
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
}
else
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
}
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
}
/**
* @return string
*/
private function wildcardDomainsCacheKey()
{
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
}
/**
* @return string
*/
private function getWildcardDomainsLine()
{
if ($this->oCacher)
{
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
if (0 < \strlen($sResult))
{
return $sResult;
}
}
$sResult = '';
$aNames = array();
$aList = \glob($this->sDomainPath.'/*.ini');
foreach ($aList as $sFile)
{
$sName = \substr(\basename($sFile), 0, -4);
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
{
$aNames[] = $this->codeFileName($sName, true);
}
}
if (0 < \count($aNames))
{
\rsort($aNames, SORT_STRING);
$sResult = \implode(' ', $aNames);
}
if ($this->oCacher)
{
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
}
return $sResult;
}
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
* @param bool $bCheckAliases = true
*
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
{
$mResult = null;
$sDisabled = '';
$sFoundedValue = '';
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
// if ($bCheckAliases && !empty($aDomain['alias']))
// {
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
// {
// $oDomain->SetAliasName($sName);
// }
//
// return $oDomain;
// }
// fix misspellings (#119)
if (\is_array($aDomain))
{
if (isset($aDomain['smpt_host']))
{
$aDomain['smtp_host'] = $aDomain['smpt_host'];
}
if (isset($aDomain['smpt_port']))
{
$aDomain['smtp_port'] = $aDomain['smpt_port'];
}
if (isset($aDomain['smpt_secure']))
{
$aDomain['smtp_secure'] = $aDomain['smpt_secure'];
}
if (isset($aDomain['smpt_auth']))
{
$aDomain['smtp_auth'] = $aDomain['smpt_auth'];
}
}
//---
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
}
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
if (!empty($sAlias))
{
$oDomain = $this->Load($sAlias, false, false, false);
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{
$oDomain->SetAliasName($sName);
}
return $oDomain;
}
}
else if ($bFindWithWildCard)
{
$sNames = $this->getWildcardDomainsLine();
if (0 < \strlen($sNames))
{
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
{
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
}
return $mResult;
}
/**
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Model\Domain $oDomain)
{
$sRealFileName = $this->codeFileName($oDomain->Name());
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param string $sAlias
*
* @return bool
*/
public function SaveAlias($sName, $sAlias)
{
$sRealFileName = $this->codeFileName($sName);
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable)
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
$sFile = '';
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
}
$aResult = array();
$aNames = \explode(',', $sFile);
if ($bDisable)
{
\array_push($aNames, $sName);
$aResult = $aNames;
}
else
{
foreach ($aNames as $sItem)
{
if ($sName !== $sItem)
{
$aResult[] = $sItem;
}
}
}
$aResult = \array_unique($aResult);
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
{
$bResult = true;
$sRealFileName = $this->codeFileName($sName);
if (0 < \strlen($sName))
{
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
}
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
}
}
if ($bResult)
{
$this->Disable($sName, false);
}
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
return $bResult;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param int $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
{
$aResult = array();
$aWildCards = array();
$aAliases = array();
$aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
foreach ($aList as $sFile)
{
$sName = \basename($sFile);
$bAlias = '.alias' === \substr($sName, -6);
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
$sName = $this->codeFileName($sName, true);
if ($bAlias)
{
if ($bIncludeAliases)
{
$aAliases[] = $sName;
}
}
else if (false !== \strpos($sName, '*'))
{
$aWildCards[] = $sName;
}
else
{
$aResult[] = $sName;
}
}
\sort($aResult, SORT_STRING);
\sort($aAliases, SORT_STRING);
\rsort($aWildCards, SORT_STRING);
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aDisabledNames = array();
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
if (false !== $sDisabled && 0 < strlen($sDisabled))
{
$aDisabledNames = \explode(',', $sDisabled);
$aDisabledNames = \array_unique($aDisabledNames);
foreach ($aDisabledNames as $iIndex => $sValue)
{
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
}
}
}
$aReturn = array();
foreach ($aResult as $sName)
{
$aReturn[$sName] = array(
!\in_array($sName, $aDisabledNames),
\in_array($sName, $aAliases)
);
}
return $aReturn;
}
/**
* @param string $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return int
*/
public function Count($sSearch = '', $bIncludeAliases = true)
{
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
}
<?php
namespace RainLoop\Providers\Domain;
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{
/**
* @var string
*/
protected $sDomainPath;
/**
* @var \MailSo\Cache\CacheClient
*/
protected $oCacher;
/**
* @param string $sDomainPath
* @param \MailSo\Cache\CacheClient $oCacher = null
*
* @return void
*/
public function __construct($sDomainPath, $oCacher = null)
{
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
$this->oCacher = $oCacher;
}
/**
* @param string $sName
* @param bool $bBack = false
*
* @return string
*/
public function codeFileName($sName, $bBack = false)
{
if ($bBack && 'default' === $sName)
{
return '*';
}
else if (!$bBack && '*' === $sName)
{
return 'default';
}
if ($bBack)
{
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
}
else
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
}
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
}
/**
* @return string
*/
private function wildcardDomainsCacheKey()
{
return '/WildCard/DomainCache/'.\md5(APP_VERSION.APP_PRIVATE_DATA_NAME).'/';
}
/**
* @return string
*/
private function getWildcardDomainsLine()
{
if ($this->oCacher)
{
$sResult = $this->oCacher->Get($this->wildcardDomainsCacheKey());
if (0 < \strlen($sResult))
{
return $sResult;
}
}
$sResult = '';
$aNames = array();
$aList = \glob($this->sDomainPath.'/*.ini');
foreach ($aList as $sFile)
{
$sName = \substr(\basename($sFile), 0, -4);
if ('default' === $sName || false !== \strpos($sName, '_wildcard_'))
{
$aNames[] = $this->codeFileName($sName, true);
}
}
if (0 < \count($aNames))
{
\rsort($aNames, SORT_STRING);
$sResult = \implode(' ', $aNames);
}
if ($this->oCacher)
{
$this->oCacher->Set($this->wildcardDomainsCacheKey(), $sResult);
}
return $sResult;
}
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
* @param bool $bCheckDisabled = true
* @param bool $bCheckAliases = true
*
* @return \RainLoop\Model\Domain|null
*/
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
{
$mResult = null;
$sDisabled = '';
$sFoundedValue = '';
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
// if ($bCheckAliases && !empty($aDomain['alias']))
// {
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
// {
// $oDomain->SetAliasName($sName);
// }
//
// return $oDomain;
// }
// fix misspellings (#119)
if (\is_array($aDomain))
{
if (isset($aDomain['smpt_host']))
{
$aDomain['smtp_host'] = $aDomain['smpt_host'];
}
if (isset($aDomain['smpt_port']))
{
$aDomain['smtp_port'] = $aDomain['smpt_port'];
}
if (isset($aDomain['smpt_secure']))
{
$aDomain['smtp_secure'] = $aDomain['smpt_secure'];
}
if (isset($aDomain['smpt_auth']))
{
$aDomain['smtp_auth'] = $aDomain['smpt_auth'];
}
}
//---
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
}
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
{
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
if (!empty($sAlias))
{
$oDomain = $this->Load($sAlias, false, false, false);
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
{
$oDomain->SetAliasName($sName);
}
return $oDomain;
}
}
else if ($bFindWithWildCard)
{
$sNames = $this->getWildcardDomainsLine();
if (0 < \strlen($sNames))
{
if (\RainLoop\Plugins\Helper::ValidateWildcardValues(
\MailSo\Base\Utils::IdnToUtf8($sName, true), $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
{
if (!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.$sFoundedValue.','))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
}
return $mResult;
}
/**
* @param \RainLoop\Model\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Model\Domain $oDomain)
{
$sRealFileName = $this->codeFileName($oDomain->Name());
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param string $sAlias
*
* @return bool
*/
public function SaveAlias($sName, $sAlias)
{
$sRealFileName = $this->codeFileName($sName);
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
return \is_int($mResult) && 0 < $mResult;
}
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable)
{
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
$sFile = '';
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
}
$aResult = array();
$aNames = \explode(',', $sFile);
if ($bDisable)
{
\array_push($aNames, $sName);
$aResult = $aNames;
}
else
{
foreach ($aNames as $sItem)
{
if ($sName !== $sItem)
{
$aResult[] = $sItem;
}
}
}
$aResult = \array_unique($aResult);
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
{
$bResult = true;
$sRealFileName = $this->codeFileName($sName);
if (0 < \strlen($sName))
{
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
}
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
{
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
}
}
if ($bResult)
{
$this->Disable($sName, false);
}
if ($this->oCacher)
{
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
}
return $bResult;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param int $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
{
$aResult = array();
$aWildCards = array();
$aAliases = array();
// $aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
$aList = @\array_diff(\scandir($this->sDomainPath), array('.', '..'));
if (\is_array($aList))
{
foreach ($aList as $sFile)
{
$sName = $sFile;
if ('.ini' === \substr($sName, -4) || '.alias' === \substr($sName, -6))
{
$bAlias = '.alias' === \substr($sName, -6);
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
$sName = $this->codeFileName($sName, true);
if ($bAlias)
{
if ($bIncludeAliases)
{
$aAliases[] = $sName;
}
}
else if (false !== \strpos($sName, '*'))
{
$aWildCards[] = $sName;
}
else
{
$aResult[] = $sName;
}
}
}
}
\sort($aResult, SORT_STRING);
\sort($aAliases, SORT_STRING);
\rsort($aWildCards, SORT_STRING);
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aDisabledNames = array();
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
if (false !== $sDisabled && 0 < strlen($sDisabled))
{
$aDisabledNames = \explode(',', $sDisabled);
$aDisabledNames = \array_unique($aDisabledNames);
foreach ($aDisabledNames as $iIndex => $sValue)
{
$aDisabledNames[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sValue, true);
}
}
}
$aReturn = array();
foreach ($aResult as $sName)
{
$aReturn[$sName] = array(
!\in_array($sName, $aDisabledNames),
\in_array($sName, $aAliases)
);
}
return $aReturn;
}
/**
* @param string $sSearch = ''
* @param bool $bIncludeAliases = true
*
* @return int
*/
public function Count($sSearch = '', $bIncludeAliases = true)
{
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
}
}

View file

@ -0,0 +1,392 @@
<?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['LoginPowered'] = !!$oConfig->Get('branding', 'login_powered', true);
$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', 'LoginPowered',
'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, 'LoginPowered', 'branding', 'login_powered', 'bool');
$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;
}
}