Skip to content

Commit

Permalink
N°2249 - Supportability - Updater module (Allow to run setup in case …
Browse files Browse the repository at this point in the history
…of failure)
  • Loading branch information
eespie committed Jan 16, 2020
1 parent 8024aad commit cc3e6d6
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 10 deletions.
Expand Up @@ -35,6 +35,7 @@
'iTopUpdate:UI:Back' => 'Back',
'iTopUpdate:UI:Cancel' => 'Cancel',
'iTopUpdate:UI:Continue' => 'Continue',
'iTopUpdate:UI:RunSetup' => 'Run Setup',
'iTopUpdate:UI:WithDBBackup' => 'Database backup',
'iTopUpdate:UI:WithFilesBackup' => 'Application files backup',
'iTopUpdate:UI:WithoutBackup' => 'No backup is planned',
Expand Down
3 changes: 2 additions & 1 deletion datamodels/2.x/itop-core-update/fr.dict.itop-core-update.php
Expand Up @@ -35,7 +35,8 @@
'iTopUpdate:UI:Back' => 'Annuler',
'iTopUpdate:UI:Cancel' => 'Annuler',
'iTopUpdate:UI:Continue' => 'Continuer',
'iTopUpdate:UI:WithDBBackup' => 'Sauvegarde de la base de données',
'iTopUpdate:UI:RunSetup' => 'Lancer le Setup',
'iTopUpdate:UI:WithDBBackup' => 'Sauvegarde de la base de données',
'iTopUpdate:UI:WithFilesBackup' => 'Archive des fichiers de l\'application',
'iTopUpdate:UI:WithoutBackup' => 'Pas de sauvegarde',
'iTopUpdate:UI:Backup' => 'Sauvegarde effectuée avant la mise à jour',
Expand Down
Expand Up @@ -79,6 +79,7 @@ public function OperationEnterMaintenance()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
SetupUtils::EnterReadOnlyMode(MetaModel::GetConfig());
$iResponseCode = 200;
} catch (Exception $e)
Expand All @@ -95,6 +96,7 @@ public function OperationExitMaintenance()
$aParams = array();
try
{
SetupUtils::CheckSetupToken(true);
SetupUtils::ExitReadOnlyMode();
$iResponseCode = 200;
} catch (Exception $e)
Expand All @@ -111,6 +113,7 @@ public function OperationBackup()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::Backup();
$iResponseCode = 200;
} catch (Exception $e)
Expand All @@ -127,6 +130,7 @@ public function OperationFilesArchive()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::CreateItopArchive();
$iResponseCode = 200;
} catch (Exception $e)
Expand All @@ -143,6 +147,7 @@ public function OperationCopyFiles()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::CopyCoreFiles();
$iResponseCode = 200;
} catch (Exception $e)
Expand All @@ -160,6 +165,7 @@ public function OperationCheckCompile()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::CheckCompile();
$iResponseCode = 200;
}
Expand All @@ -178,6 +184,7 @@ public function OperationCompile()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::Compile();
$iResponseCode = 200;
}
Expand All @@ -196,6 +203,7 @@ public function OperationUpdateDatabase()
$aParams = array();
try
{
SetupUtils::CheckSetupToken();
CoreUpdater::UpdateDatabase();
$iResponseCode = 200;
}
Expand Down
Expand Up @@ -140,6 +140,15 @@ public function OperationUpdateCoreFiles()
$this->DisplayPage($aParams);
}

public function OperationRunSetup()
{
SetupUtils::CheckSetupToken(true);
$sConfigFile = APPCONF.'production/'.ITOP_CONFIG_FILE;
@chmod($sConfigFile, 0770);
$sRedirectURL = utils::GetAbsoluteUrlAppRoot().'setup/index.php';
header("Location: $sRedirectURL");
}

private function GetPreviousInstallations()
{
return DBToolsUtils::GetPreviousInstallations();
Expand Down
Expand Up @@ -78,6 +78,11 @@
<span>{{ 'iTopUpdate:UI:RestoreBackup'|dict_format(sBackupFile) }}</span>
</div>
{% endif %}
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="operation" value="RunSetup"/>
<input type="hidden" name="authent" value="{{ sSetupToken }}">
<p><input id="run_setup" type="submit" value="{{ 'iTopUpdate:UI:RunSetup'|dict_s }}" disabled/></p>
</form>
</div>

<form enctype="multipart/form-data" method="post">
Expand Down
Expand Up @@ -91,7 +91,6 @@ function ExecNextStep() {
setTimeout(ExecNextStep, 500);
})
.fail(function ( jqXHR) {
$("#setup_continue").removeAttr("disabled");
if (jqXHR && jqXHR.responseJSON) {
$("#setup_error").html({{ 'iTopUpdate:Error:UpdateFailed'|dict_s|json_encode|raw }}+" "+jqXHR.responseJSON.sError);
}
Expand All @@ -101,6 +100,7 @@ function ExecNextStep() {
}
$('.progress').css("background-image", "none").css("background-color", "#fcc");
$("#setup_error_outer").show();
$("#setup_continue").hide();
})
;
}
Expand Down
15 changes: 12 additions & 3 deletions index.php
Expand Up @@ -17,9 +17,18 @@
}
else if (is_writable($sConfigFile))
{
echo "<p><b>Security Warning</b>: the configuration file '$sConfigFile' should be read-only.</p>";
echo "<p>Please modify the access rights to this file.</p>";
echo "<p>Click <a href=\"$sStartPage\">here</a> to ignore this warning and continue to run iTop.</p>";
require_once (APPROOT.'setup/setuputils.class.inc.php');
if (SetupUtils::IsInReadOnlyMode())
{
echo "<p><b>Warning</b>: the application is currently in maintenance, please wait.</p>";
echo "<p>Click <a href=\"$sStartPage\">here</a> to ignore this warning and continue to run iTop in read-only mode.</p>";
}
else
{
echo "<p><b>Security Warning</b>: the configuration file '$sConfigFile' should be read-only.</p>";
echo "<p>Please modify the access rights to this file.</p>";
echo "<p>Click <a href=\"$sStartPage\">here</a> to ignore this warning and continue to run iTop.</p>";
}
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions setup/index.php
Expand Up @@ -26,8 +26,6 @@
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');

clearstatcache(); // Make sure we know what we are doing !
SetupUtils::ExitMaintenanceMode(false); // Reset maintenance mode in case of problem
SetupUtils::ExitReadOnlyMode(false); // Reset readonly mode in case of problem
// Set a long (at least 4 minutes) execution time for the setup to avoid timeouts during this phase
ini_set('max_execution_time', max(240, ini_get('max_execution_time')));
// While running the setup it is desirable to see any error that may happen
Expand Down
11 changes: 9 additions & 2 deletions setup/setuputils.class.inc.php
Expand Up @@ -2030,15 +2030,22 @@ public final static function CreateSetupToken()
/**
* Verify Setup authentication token (from the request parameter 'authent')
*
* @param bool $bRemoveToken
*
* @throws \SecurityException
*/
public final static function CheckSetupToken()
public final static function CheckSetupToken($bRemoveToken = false)
{
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
if (!file_exists(APPROOT.'data/setup/authent') || $sAuthent !== file_get_contents(APPROOT.'data/setup/authent'))
$sTokenFile = APPROOT.'data/setup/authent';
if (!file_exists($sTokenFile) || $sAuthent !== file_get_contents($sTokenFile))
{
throw new SecurityException('Setup operations are not allowed outside of the setup');
}
if ($bRemoveToken)
{
@unlink($sTokenFile);
}
}

private final static function Log($sText)
Expand Down
5 changes: 4 additions & 1 deletion setup/wizardcontroller.class.inc.php
Expand Up @@ -173,6 +173,9 @@ protected function DisplayStep(WizardStep $oStep)
// The configuration file already exists
if (!is_writable($sConfigFile))
{
SetupUtils::ExitMaintenanceMode(false); // Reset maintenance mode in case of problem
SetupUtils::ExitReadOnlyMode(false); // Reset readonly mode in case of problem

$sRelativePath = utils::GetConfigFilePathRelative();
$oP = new SetupPage('Installation Cannot Continue');
$oP->add("<h2>Fatal error</h2>\n");
Expand Down Expand Up @@ -643,4 +646,4 @@ public function CanMoveForward()
}
}
End of the example */
End of the example */

0 comments on commit cc3e6d6

Please sign in to comment.