Improve package install validation

This commit is contained in:
RainLoop Team 2013-11-27 23:10:59 +04:00
parent 790a867674
commit 838d231752

View file

@ -2553,7 +2553,7 @@ class Actions
$this->Logger()->Write($sUrl.' -> '.$sTmp, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); $this->Logger()->Write($sUrl.' -> '.$sTmp, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
} }
@fclose($pDest); @\fclose($pDest);
} }
else else
{ {
@ -2572,8 +2572,8 @@ class Actions
$sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp); $sTmpFolder = APP_PRIVATE_DATA.\md5($sTmp);
mkdir($sTmpFolder); \mkdir($sTmpFolder);
if (is_dir($sTmpFolder)) if (\is_dir($sTmpFolder))
{ {
$bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder); $bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
if (!$bResult) if (!$bResult)
@ -2581,27 +2581,35 @@ class Actions
$this->Logger()->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); $this->Logger()->Write('Cannot extract package files: '.$oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
} }
if ($bResult && file_exists($sTmpFolder.'/index.php') && if ($bResult && \file_exists($sTmpFolder.'/index.php') &&
is_writable(APP_INDEX_ROOT_PATH.'rainloop/') && \is_writable(APP_INDEX_ROOT_PATH.'rainloop/') &&
file_exists($sTmpFolder.'/data/VERSION') && \file_exists($sTmpFolder.'/data/VERSION') &&
is_dir($sTmpFolder.'/rainloop/')) \is_dir($sTmpFolder.'/rainloop/'))
{ {
$sNewVersion = file_get_contents($sTmpFolder.'/data/VERSION'); $sNewVersion = \file_get_contents($sTmpFolder.'/data/VERSION');
if ($sNewVersion && !is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion)) if ($sNewVersion && !\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion))
{ {
\MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/'); \MailSo\Base\Utils::CopyDir($sTmpFolder.'/rainloop/', APP_INDEX_ROOT_PATH.'rainloop/');
copy($sTmpFolder.'/data/VERSION', APP_DATA_FOLDER_PATH.'VERSION'); if (!\is_dir(APP_INDEX_ROOT_PATH.'rainloop/v/'.$sNewVersion) &&
if (md5_file($sTmpFolder.'/index.php') !== md5_file(APP_INDEX_ROOT_PATH.'index.php')) \copy($sTmpFolder.'/data/VERSION', APP_DATA_FOLDER_PATH.'VERSION'))
{ {
copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php'); if (\md5_file($sTmpFolder.'/index.php') !== \md5_file(APP_INDEX_ROOT_PATH.'index.php'))
} {
\copy($sTmpFolder.'/index.php', APP_INDEX_ROOT_PATH.'index.php');
}
$bResult = true; $bResult = true;
}
else
{
$this->Logger()->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
$this->Logger()->Write($sTmpFolder.'/rainloop/ -> '.APP_INDEX_ROOT_PATH.'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
}
} }
else else
{ {
$this->Logger()->WriteDump($sNewVersion.' version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); $this->Logger()->Write($sNewVersion.' version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
} }
} }
else if ($bResult) else if ($bResult)
@ -2619,7 +2627,7 @@ class Actions
else else
{ {
$bResult = true; $bResult = true;
if (is_dir(APP_PLUGINS_PATH.$sId)) if (\is_dir(APP_PLUGINS_PATH.$sId))
{ {
$bResult = \MailSo\Base\Utils::RecRmDir(APP_PLUGINS_PATH.$sId); $bResult = \MailSo\Base\Utils::RecRmDir(APP_PLUGINS_PATH.$sId);
if (!$bResult) if (!$bResult)
@ -2638,12 +2646,11 @@ class Actions
} }
} }
@unlink($sTmp); @\unlink($sTmp);
} }
return $this->DefaultResponse(__FUNCTION__, $bResult ? ( return $this->DefaultResponse(__FUNCTION__, $bResult ?
'plugin' !== $sType ? array('Reload' => true) : true ('plugin' !== $sType ? array('Reload' => true) : true) : false);
) : false);
} }
/** /**