Backup tools disabled when the demo mode is active

SVN:trunk[3406]
This commit is contained in:
Romain Quetiez
2014-11-03 15:12:47 +00:00
parent e83e1262a5
commit 50ca6cdd0f
4 changed files with 87 additions and 41 deletions

View File

@@ -46,6 +46,12 @@ try
$oPage->no_cache(); $oPage->no_cache();
$oPage->SetContentType('text/html'); $oPage->SetContentType('text/html');
if (utils::GetConfig()->Get('demo_mode'))
{
$oPage->add("<div data-error-stimulus=\"Error\">Sorry, iTop is in <b>demonstration mode</b>: the feature is disabled.</div>");
}
else
{
try try
{ {
set_time_limit(0); set_time_limit(0);
@@ -56,6 +62,7 @@ try
{ {
$oPage->p('Error: '.$e->getMessage()); $oPage->p('Error: '.$e->getMessage());
} }
}
$oPage->output(); $oPage->output();
break; break;
@@ -104,6 +111,12 @@ EOF
$oPage->no_cache(); $oPage->no_cache();
$oPage->SetContentType('text/html'); $oPage->SetContentType('text/html');
if (utils::GetConfig()->Get('demo_mode'))
{
$oPage->add("<div data-error-stimulus=\"Error\">Sorry, iTop is in <b>demonstration mode</b>: the feature is disabled.</div>");
}
else
{
$sEnvironment = utils::ReadParam('environment', 'production', false, 'raw_data'); $sEnvironment = utils::ReadParam('environment', 'production', false, 'raw_data');
$oRestoreMutex = new iTopMutex('restore.'.$sEnvironment); $oRestoreMutex = new iTopMutex('restore.'.$sEnvironment);
$oRestoreMutex->Lock(); $oRestoreMutex->Lock();
@@ -138,6 +151,7 @@ EOF
$oRestoreMutex->Unlock(); $oRestoreMutex->Unlock();
$oPage->p('Error: '.$e->getMessage()); $oPage->p('Error: '.$e->getMessage());
} }
}
$oPage->output(); $oPage->output();
break; break;
@@ -146,6 +160,10 @@ EOF
require_once(APPROOT.'/application/loginwebpage.class.inc.php'); require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin) LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
if (utils::GetConfig()->Get('demo_mode'))
{
throw new Exception('iTop is in demonstration mode: the feature is disabled');
}
$sFile = utils::ReadParam('file', '', false, 'raw_data'); $sFile = utils::ReadParam('file', '', false, 'raw_data');
$oBackup = new DBBackupScheduled(); $oBackup = new DBBackupScheduled();
$sBackupDir = APPROOT.'data/backups/'; $sBackupDir = APPROOT.'data/backups/';

View File

@@ -184,6 +184,10 @@ if ($bSimulate)
{ {
$oP->p("Simulate: would create file '$sZipArchiveFile'"); $oP->p("Simulate: would create file '$sZipArchiveFile'");
} }
elseif (MetaModel::GetConfig()->Get('demo_mode'))
{
$oP->p("Sorry, iTop is in demonstration mode: the feature is disabled");
}
else else
{ {
$oBackup->CreateZip($sZipArchiveFile); $oBackup->CreateZip($sZipArchiveFile);

View File

@@ -3,7 +3,7 @@
SetupWebPage::AddModule( SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file __FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'itop-backup/2.1.0', 'itop-backup/2.1.1',
array( array(
// Identification // Identification
// //

View File

@@ -50,6 +50,11 @@ try
{ {
$oP->add("<h1>".Dict::S('bkp-status-title')."</h1>"); $oP->add("<h1>".Dict::S('bkp-status-title')."</h1>");
if (MetaModel::GetConfig()->Get('demo_mode'))
{
$oP->add("<div class=\"header_message message_info\">iTop is in <b>demonstration mode</b>: the feature is disabled.</div>");
}
$sImgOk = '<img src="../images/validation_ok.png"> '; $sImgOk = '<img src="../images/validation_ok.png"> ';
$sImgError = '<img src="../images/validation_error.png"> '; $sImgError = '<img src="../images/validation_error.png"> ';
@@ -181,8 +186,15 @@ try
{ {
$sFileName = basename($sBackupFile); $sFileName = basename($sBackupFile);
$sFilePath = 'auto/'.$sFileName; $sFilePath = 'auto/'.$sFileName;
if (MetaModel::GetConfig()->Get('demo_mode'))
{
$sName = $sFileName;
}
else
{
$sAjax = utils::GetAbsoluteUrlModulePage('itop-backup', 'ajax.backup.php', array('operation' => 'download', 'file' => $sFilePath)); $sAjax = utils::GetAbsoluteUrlModulePage('itop-backup', 'ajax.backup.php', array('operation' => 'download', 'file' => $sFilePath));
$sName = "<a href=\"$sAjax\">".$sFileName.'</a>'; $sName = "<a href=\"$sAjax\">".$sFileName.'</a>';
}
$sSize = SetupUtils::HumanReadableSize(filesize($sBackupFile)); $sSize = SetupUtils::HumanReadableSize(filesize($sBackupFile));
$sConfirmRestore = addslashes(Dict::Format('bkp-confirm-restore', $sFileName)); $sConfirmRestore = addslashes(Dict::Format('bkp-confirm-restore', $sFileName));
$sFileEscaped = addslashes($sFilePath); $sFileEscaped = addslashes($sFilePath);
@@ -222,8 +234,15 @@ try
{ {
$sFileName = basename($sBackupFile); $sFileName = basename($sBackupFile);
$sFilePath = 'manual/'.$sFileName; $sFilePath = 'manual/'.$sFileName;
if (MetaModel::GetConfig()->Get('demo_mode'))
{
$sName = $sFileName;
}
else
{
$sAjax = utils::GetAbsoluteUrlModulePage('itop-backup', 'ajax.backup.php', array('operation' => 'download', 'file' => $sFilePath)); $sAjax = utils::GetAbsoluteUrlModulePage('itop-backup', 'ajax.backup.php', array('operation' => 'download', 'file' => $sFilePath));
$sName = "<a href=\"$sAjax\">".$sFileName.'</a>'; $sName = "<a href=\"$sAjax\">".$sFileName.'</a>';
}
$sSize = SetupUtils::HumanReadableSize(filesize($sBackupFile)); $sSize = SetupUtils::HumanReadableSize(filesize($sBackupFile));
$sConfirmRestore = addslashes(Dict::Format('bkp-confirm-restore', $sFileName)); $sConfirmRestore = addslashes(Dict::Format('bkp-confirm-restore', $sFileName));
$sFileEscaped = addslashes($sFilePath); $sFileEscaped = addslashes($sFilePath);
@@ -376,6 +395,11 @@ function LaunchRestoreNow(sBackupFile, sConfirmationMessage)
} }
EOF EOF
); );
if (MetaModel::GetConfig()->Get('demo_mode'))
{
$oP->add_ready_script("$('button').attr('disabled', 'disabled').attr('title', 'Disabled in demonstration mode')");
}
} }
catch(Exception $e) catch(Exception $e)
{ {