mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2024 Combodo SAS
|
||||
//
|
||||
// This file is part of iTop.
|
||||
@@ -41,10 +42,9 @@ require_once(__DIR__.'/hubruntimeenvironment.class.inc.php');
|
||||
*/
|
||||
class DBBackupWithErrorReporting extends DBBackup
|
||||
{
|
||||
protected $aInfos = [];
|
||||
|
||||
protected $aInfos = array();
|
||||
|
||||
protected $aErrors = array();
|
||||
protected $aErrors = [];
|
||||
|
||||
protected function LogInfo($sMsg)
|
||||
{
|
||||
@@ -79,19 +79,16 @@ function DoBackup($sTargetFile)
|
||||
// Make sure the target directory exists
|
||||
$sBackupDir = dirname($sTargetFile);
|
||||
SetupUtils::builddir($sBackupDir);
|
||||
|
||||
|
||||
$oBackup = new DBBackupWithErrorReporting();
|
||||
$oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
|
||||
$sSourceConfigFile = APPCONF.utils::GetCurrentEnvironment().'/'.ITOP_CONFIG_FILE;
|
||||
|
||||
|
||||
$oMutex = new iTopMutex('backup.'.utils::GetCurrentEnvironment());
|
||||
$oMutex->Lock();
|
||||
try
|
||||
{
|
||||
try {
|
||||
$oBackup->CreateCompressedBackup($sTargetFile, $sSourceConfigFile);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
$oMutex->Unlock();
|
||||
throw $e;
|
||||
}
|
||||
@@ -101,22 +98,22 @@ function DoBackup($sTargetFile)
|
||||
|
||||
/**
|
||||
* Outputs the status of the current ajax execution (as a JSON structure)
|
||||
*
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param bool $bSuccess
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportStatus($sMessage, $bSuccess, $iErrorCode = 0, $aMoreFields = array())
|
||||
function ReportStatus($sMessage, $bSuccess, $iErrorCode = 0, $aMoreFields = [])
|
||||
{
|
||||
// Do not use AjaxPage during setup phases, because it uses InterfaceDiscovery in Twig compilation
|
||||
$oPage = new JsonPage();
|
||||
$aResult = array(
|
||||
$aResult = [
|
||||
'code' => $iErrorCode,
|
||||
'message' => $sMessage,
|
||||
'fields' => $aMoreFields
|
||||
);
|
||||
'fields' => $aMoreFields,
|
||||
];
|
||||
$oPage->SetData($aResult);
|
||||
$oPage->SetOutputDataOnly(true);
|
||||
$oPage->output();
|
||||
@@ -124,154 +121,137 @@ function ReportStatus($sMessage, $bSuccess, $iErrorCode = 0, $aMoreFields = arra
|
||||
|
||||
/**
|
||||
* Helper to output the status of a successful execution
|
||||
*
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportSuccess($sMessage, $aMoreFields = array())
|
||||
function ReportSuccess($sMessage, $aMoreFields = [])
|
||||
{
|
||||
ReportStatus($sMessage, true, 0, $aMoreFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the status of a failed execution
|
||||
*
|
||||
*
|
||||
* @param string $sMessage
|
||||
* @param number $iErrorCode
|
||||
* @param array $aMoreFields
|
||||
* Extra fields to pass to the caller, if needed
|
||||
*/
|
||||
function ReportError($sMessage, $iErrorCode, $aMoreFields = array())
|
||||
function ReportError($sMessage, $iErrorCode, $aMoreFields = [])
|
||||
{
|
||||
if ($iErrorCode==0)
|
||||
{
|
||||
if ($iErrorCode == 0) {
|
||||
// 0 means no error, so change it if no meaningful error code is supplied
|
||||
$iErrorCode = -1;
|
||||
}
|
||||
ReportStatus($sMessage, false, $iErrorCode, $aMoreFields);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
SetupUtils::ExitMaintenanceMode(false); // Reset maintenance mode in case of problem
|
||||
|
||||
utils::PushArchiveMode(false);
|
||||
|
||||
|
||||
ini_set('max_execution_time', max(3600, ini_get('max_execution_time'))); // Under Windows SQL/backup operations are part of the PHP timeout and require extra time
|
||||
ini_set('display_errors', 1); // Make sure that fatal errors remain visible from the end-user
|
||||
|
||||
|
||||
// Most of the ajax calls are done without the MetaModel being loaded
|
||||
// Therefore, the language must be passed as an argument,
|
||||
// and the dictionnaries be loaded here
|
||||
// Therefore, the language must be passed as an argument,
|
||||
// and the dictionnaries be loaded here
|
||||
$sLanguage = utils::ReadParam('language', '');
|
||||
if ($sLanguage!='')
|
||||
{
|
||||
foreach (glob(APPROOT.'env-production/dictionaries/*.dict.php') as $sFilePath)
|
||||
{
|
||||
require_once ($sFilePath);
|
||||
if ($sLanguage != '') {
|
||||
foreach (glob(APPROOT.'env-production/dictionaries/*.dict.php') as $sFilePath) {
|
||||
require_once($sFilePath);
|
||||
}
|
||||
|
||||
|
||||
$aLanguages = Dict::GetLanguages();
|
||||
if (array_key_exists($sLanguage, $aLanguages))
|
||||
{
|
||||
if (array_key_exists($sLanguage, $aLanguages)) {
|
||||
Dict::SetUserLanguage($sLanguage);
|
||||
}
|
||||
}
|
||||
$sOperation = utils::ReadParam('operation', '');
|
||||
switch ($sOperation)
|
||||
{
|
||||
switch ($sOperation) {
|
||||
case 'check_before_backup':
|
||||
require_once (APPROOT.'/application/startup.inc.php');
|
||||
require_once (APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
$sDBBackupPath = utils::GetDataPath().'backups/manual';
|
||||
$aChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath);
|
||||
$bFailed = false;
|
||||
foreach ($aChecks as $oCheckResult)
|
||||
{
|
||||
if ($oCheckResult->iSeverity==CheckResult::ERROR)
|
||||
{
|
||||
foreach ($aChecks as $oCheckResult) {
|
||||
if ($oCheckResult->iSeverity == CheckResult::ERROR) {
|
||||
$bFailed = true;
|
||||
ReportError($oCheckResult->sLabel, -2);
|
||||
}
|
||||
}
|
||||
if (!$bFailed)
|
||||
{
|
||||
if (!$bFailed) {
|
||||
// Continue the checks
|
||||
$fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
|
||||
if ($fFreeSpace!==false)
|
||||
{
|
||||
if ($fFreeSpace !== false) {
|
||||
$sMessage = Dict::Format('iTopHub:BackupFreeDiskSpaceIn', SetupUtils::HumanReadableSize($fFreeSpace), dirname($sDBBackupPath));
|
||||
ReportSuccess($sMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ReportError(Dict::S('iTopHub:FailedToCheckFreeDiskSpace'), -1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case 'do_backup':
|
||||
require_once (APPROOT.'/application/startup.inc.php');
|
||||
require_once (APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
|
||||
|
||||
try
|
||||
{
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
try {
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
SetupLog::Info('Backup starts...');
|
||||
set_time_limit(0);
|
||||
$sBackupPath = APPROOT.'/data/backups/manual/backup-';
|
||||
$iSuffix = 1;
|
||||
$sSuffix = '';
|
||||
// Generate a unique name...
|
||||
do
|
||||
{
|
||||
do {
|
||||
$sBackupFile = $sBackupPath.date('Y-m-d-His').$sSuffix;
|
||||
$sSuffix = '-'.$iSuffix;
|
||||
$iSuffix++ ;
|
||||
}
|
||||
while (file_exists($sBackupFile));
|
||||
} while (file_exists($sBackupFile));
|
||||
|
||||
$oBackup = DoBackup($sBackupFile);
|
||||
$aErrors = $oBackup->GetErrors();
|
||||
if (count($aErrors)>0)
|
||||
{
|
||||
if (count($aErrors) > 0) {
|
||||
SetupLog::Error('Backup failed.');
|
||||
SetupLog::Error(implode("\n", $aErrors));
|
||||
ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError(Dict::S('iTopHub:BackupFailed'), -1, $aErrors);
|
||||
} else {
|
||||
SetupLog::Info('Backup successfully completed.');
|
||||
ReportSuccess(Dict::S('iTopHub:BackupOk'));
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error($e->getMessage());
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case 'compile':
|
||||
SetupLog::Info('Deployment starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
// First step: prepare the datamodel, if it fails, roll-back
|
||||
$aSelectedExtensionCodes = utils::ReadParam('extension_codes', array());
|
||||
$aSelectedExtensionDirs = utils::ReadParam('extension_dirs', array());
|
||||
$aSelectedExtensionCodes = utils::ReadParam('extension_codes', []);
|
||||
$aSelectedExtensionDirs = utils::ReadParam('extension_dirs', []);
|
||||
|
||||
$oRuntimeEnv = new HubRunTimeEnvironment('production', false); // use a temp environment: production-build
|
||||
$oRuntimeEnv->MoveSelectedExtensions(APPROOT.'/data/downloaded-extensions/', $aSelectedExtensionDirs);
|
||||
|
||||
$oConfig = new Config(APPCONF.'production/'.ITOP_CONFIG_FILE);
|
||||
if ($oConfig->Get('demo_mode')) throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
if ($oConfig->Get('demo_mode')) {
|
||||
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
|
||||
}
|
||||
|
||||
$aSelectModules = $oRuntimeEnv->CompileFrom('production', false); // WARNING symlinks does not seem to be compatible with manual Commit
|
||||
|
||||
@@ -289,21 +269,19 @@ try
|
||||
$oRuntimeEnv->Commit();
|
||||
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Compilation completed...');
|
||||
SetupLog::Info('Compilation completed...');
|
||||
ReportSuccess('Ok'); // No access to Dict::S here
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case 'move_to_production':
|
||||
// Second step: update the schema and the data
|
||||
// Everything happening below is based on env-production
|
||||
$oRuntimeEnv = new RunTimeEnvironment('production', true);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
SetupLog::Info('Move to production starts...');
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
$sAuthent = utils::ReadParam('authent', '', false, 'raw_data');
|
||||
if (!file_exists(utils::GetDataPath().'hub/compile_authent') || $sAuthent !== file_get_contents(utils::GetDataPath().'hub/compile_authent')) {
|
||||
throw new SecurityException(Dict::S('iTopHub:FailAuthent'));
|
||||
}
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
@@ -315,15 +293,11 @@ try
|
||||
|
||||
$aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $oRuntimeEnv->GetBuildDir(), true);
|
||||
|
||||
$aSelectedModules = array();
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule)
|
||||
{
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE))
|
||||
{
|
||||
$aSelectedModules = [];
|
||||
foreach ($aAvailableModules as $sModuleId => $aModule) {
|
||||
if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$aSelectedModules[] = $sModuleId;
|
||||
}
|
||||
}
|
||||
@@ -349,17 +323,14 @@ try
|
||||
|
||||
// Default choices = as before
|
||||
$oExtensionsMap->LoadChoicesFromDatabase($oConfig);
|
||||
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension)
|
||||
{
|
||||
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) {
|
||||
// Plus all "remote" extensions
|
||||
if ($oExtension->sSource==iTopExtension::SOURCE_REMOTE)
|
||||
{
|
||||
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) {
|
||||
$oExtensionsMap->MarkAsChosen($oExtension->sCode);
|
||||
}
|
||||
}
|
||||
$aSelectedExtensionCodes = array();
|
||||
foreach ($oExtensionsMap->GetChoices() as $oExtension)
|
||||
{
|
||||
$aSelectedExtensionCodes = [];
|
||||
foreach ($oExtensionsMap->GetChoices() as $oExtension) {
|
||||
$aSelectedExtensionCodes[] = $oExtension->sCode;
|
||||
}
|
||||
$aSelectedExtensions = $oExtensionsMap->GetChoices();
|
||||
@@ -368,34 +339,27 @@ try
|
||||
// Report the success in a way that will be detected by the ajax caller
|
||||
SetupLog::Info('Deployment successfully completed.');
|
||||
ReportSuccess(Dict::S('iTopHub:CompiledOK'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if(file_exists(utils::GetDataPath().'hub/compile_authent'))
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
if (file_exists(utils::GetDataPath().'hub/compile_authent')) {
|
||||
unlink(utils::GetDataPath().'hub/compile_authent');
|
||||
}
|
||||
// Note: at this point, the dictionnary is not necessarily loaded
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
SetupLog::Error('Debug trace: '.$e->getTraceAsString());
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
SetupUtils::ExitReadOnlyMode();
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
ReportError("Invalid operation: '$sOperation'", -1);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
SetupLog::Error(get_class($e).': '.Dict::S('iTopHub:ConfigurationSafelyReverted')."\n".$e->getMessage());
|
||||
SetupLog::Error('Debug trace: '.$e->getTraceAsString());
|
||||
|
||||
|
||||
utils::PopArchiveMode();
|
||||
|
||||
|
||||
ReportError($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Localized data
|
||||
*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license https://opensource.org/licenses/AGPL-3.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Dict::Add('PT BR', 'Brazilian', 'Brazilian', array(
|
||||
Dict::Add('PT BR', 'Brazilian', 'Brazilian', [
|
||||
'Menu:iTopHub' => 'iTop Hub',
|
||||
'Menu:iTopHub:Register' => 'Conectar ao iTop Hub',
|
||||
'Menu:iTopHub:Register+' => 'Vá para o iTop Hub para atualizar sua instância '.ITOP_APPLICATION_SHORT,
|
||||
@@ -64,4 +65,4 @@ Dict::Add('PT BR', 'Brazilian', 'Brazilian', array(
|
||||
'iTopHub:InstallationStatus:Installed_Version' => '%1$s versão: %2$s',
|
||||
'iTopHub:InstallationStatus:Installed' => 'Instalado',
|
||||
'iTopHub:InstallationStatus:Version_NotInstalled' => 'Versão %1$s <b>NÃO</b> instalada',
|
||||
));
|
||||
]);
|
||||
|
||||
@@ -16,7 +16,7 @@ function DisplayStatus(WebPage $oPage)
|
||||
$oPage->add('<div class="module-selection-body">');
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
$sPath = utils::GetDataPath().'downloaded-extensions/';
|
||||
$aExtraDirs = array();
|
||||
$aExtraDirs = [];
|
||||
if (is_dir($sPath)) {
|
||||
$aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory
|
||||
}
|
||||
@@ -25,7 +25,7 @@ function DisplayStatus(WebPage $oPage)
|
||||
|
||||
foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) {
|
||||
if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) {
|
||||
$aCSSClasses = array('landing-extension');
|
||||
$aCSSClasses = ['landing-extension'];
|
||||
if ($oExtension->sInstalledVersion === '') {
|
||||
$aCSSClasses[] = 'landing-installation';
|
||||
$sInstallation = Dict::Format('iTopHub:InstallationStatus:Version_NotInstalled', $oExtension->sVersion);
|
||||
@@ -68,12 +68,11 @@ function DoLanding(WebPage $oPage)
|
||||
|
||||
$oPage->add('<div class="module-selection-body" style="text-align: center; line-height: 14em;"><h2>'.Dict::S('iTopHub:Uncompressing').'</h2></div>');
|
||||
|
||||
|
||||
$sProduct = utils::ReadParam('applicationName', '', false, 'raw_data');
|
||||
$sVersion = utils::ReadParam('applicationVersion', '', false, 'raw_data');
|
||||
$sInstanceUUID = utils::ReadParam('uuidFile', '', false, 'raw_data');
|
||||
$sDatabaseUUID = utils::ReadParam('uuidBdd', '', false, 'raw_data');
|
||||
$aExtensions = utils::ReadParam('extensions', array(), false, 'raw_data');
|
||||
$aExtensions = utils::ReadParam('extensions', [], false, 'raw_data');
|
||||
|
||||
// Basic consistency validation
|
||||
if ($sProduct != ITOP_APPLICATION) {
|
||||
@@ -128,7 +127,7 @@ function DoLanding(WebPage $oPage)
|
||||
}
|
||||
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
$sNextPage = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', array('operation' => 'install'));
|
||||
$sNextPage = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', ['operation' => 'install']);
|
||||
$oPage->add_ready_script("window.location.href='$sNextPage'");
|
||||
|
||||
}
|
||||
@@ -148,11 +147,10 @@ function DoInstall(WebPage $oPage)
|
||||
$oPage->set_title(Dict::S('iTopHub:Landing:Install'));
|
||||
$oPage->add('<div id="installation-summary" class="module-selection-body" style="position: relative">');
|
||||
|
||||
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
// Now scan the extensions and display a report of the extensions brought by the hub
|
||||
$sPath = utils::GetDataPath().'downloaded-extensions/';
|
||||
$aExtraDirs = array();
|
||||
$aExtraDirs = [];
|
||||
if (is_dir($sPath)) {
|
||||
$aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory
|
||||
}
|
||||
@@ -175,14 +173,14 @@ function DoInstall(WebPage $oPage)
|
||||
$oPage->add('</div>');
|
||||
$oPage->add('</div>');
|
||||
} else {
|
||||
$aCSSClasses = array('landing-extension');
|
||||
$aCSSClasses = ['landing-extension'];
|
||||
if ($oExtension->sInstalledVersion === '') {
|
||||
$aCSSClasses[] = 'landing-installation';
|
||||
$sInstallation = Dict::Format('iTopHub:InstallationEffect:Install', $oExtension->sVersion);
|
||||
} else if ($oExtension->sInstalledVersion == $oExtension->sVersion) {
|
||||
} elseif ($oExtension->sInstalledVersion == $oExtension->sVersion) {
|
||||
$aCSSClasses[] = 'landing-no-change';
|
||||
$sInstallation = Dict::Format('iTopHub:InstallationEffect:NoChange', $oExtension->sVersion);
|
||||
} else if (version_compare($oExtension->sInstalledVersion, $oExtension->sVersion, '<')) {
|
||||
} elseif (version_compare($oExtension->sInstalledVersion, $oExtension->sVersion, '<')) {
|
||||
$aCSSClasses[] = 'landing-upgrade';
|
||||
$sInstallation = Dict::Format('iTopHub:InstallationEffect:Upgrade', $oExtension->sInstalledVersion, $oExtension->sVersion);
|
||||
} else {
|
||||
@@ -213,10 +211,8 @@ function DoInstall(WebPage $oPage)
|
||||
|
||||
$oPage->add('</div>'); // module-selection-body
|
||||
|
||||
|
||||
$oPage->LinkStylesheetFromAppRoot('css/font-awesome/css/all.min.css');
|
||||
|
||||
|
||||
$oPage->add('<div id="hub_installation_widget"></div>');
|
||||
$oPage->add('<fieldset id="database-backup-fieldset"><legend>'.Dict::S('iTopHub:DBBackupLabel').'</legend>');
|
||||
$oPage->add('<div id="backup_form"><input id="backup_checkbox" type="checkbox" checked><label for="backup_checkbox"> '.Dict::S('iTopHub:DBBackupSentence').'</label></div>');
|
||||
@@ -224,22 +220,22 @@ function DoInstall(WebPage $oPage)
|
||||
$oPage->add('</fieldset>');
|
||||
$oPage->add('<p style="text-align: center"><input type="button" id="hub_start_installation" type="button" disabled value="'.Dict::S('iTopHub:DeployBtn').'"/></p>');
|
||||
|
||||
$sIframeUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'launch.php', array('target' => 'inform_after_setup'));
|
||||
$sStatusPageUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', array('operation' => 'done'));
|
||||
$sIframeUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'launch.php', ['target' => 'inform_after_setup']);
|
||||
$sStatusPageUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', ['operation' => 'done']);
|
||||
|
||||
$aWidgetParams = array(
|
||||
'self_url' => utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'ajax.php', array('maintenance' => true)),
|
||||
$aWidgetParams = [
|
||||
'self_url' => utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'ajax.php', ['maintenance' => true]),
|
||||
'iframe_url' => $sIframeUrl,
|
||||
'redirect_after_completion_url' => $sStatusPageUrl,
|
||||
'mysql_bindir' => MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''),
|
||||
'labels' => array(
|
||||
'labels' => [
|
||||
'database_backup' => Dict::S('iTopHub:InstallationProgress:DatabaseBackup'),
|
||||
'extensions_installation' => Dict::S('iTopHub:InstallationProgress:ExtensionsInstallation'),
|
||||
'installation_successful' => Dict::S('iTopHub:InstallationProgress:InstallationSuccessful'),
|
||||
'rollback' => Dict::S('iTopHub:ConfigurationSafelyReverted'),
|
||||
),
|
||||
],
|
||||
'authent' => $sUID,
|
||||
);
|
||||
];
|
||||
|
||||
$sWidgetParams = json_encode($aWidgetParams);
|
||||
|
||||
@@ -249,7 +245,6 @@ function DoInstall(WebPage $oPage)
|
||||
$oPage->add('<div id="debug"></div>');
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
require_once(APPROOT.'/application/application.inc.php');
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
@@ -266,7 +261,8 @@ try {
|
||||
$oPage->LinkScriptFromModule('itop-hub-connector/js/hub.js');
|
||||
$oPage->LinkStylesheetFromAppRoot('css/font-combodo/font-combodo.css');
|
||||
|
||||
$oPage->add_style(<<<CSS
|
||||
$oPage->add_style(
|
||||
<<<CSS
|
||||
div.choice { margin: 0.5em;}
|
||||
div.choice a { text-decoration:none; font-weight: bold; color: #1C94C4 }
|
||||
div.description { margin-left: 2em; }
|
||||
@@ -295,8 +291,7 @@ CSS
|
||||
}
|
||||
|
||||
$oPage->output();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
@@ -312,7 +307,7 @@ catch (Exception $e) {
|
||||
$oLog->Set('issue', 'PHP Exception');
|
||||
$oLog->Set('impact', 'Page could not be displayed');
|
||||
$oLog->Set('callstack', $e->getTrace());
|
||||
$oLog->Set('data', array());
|
||||
$oLog->Set('data', []);
|
||||
$oLog->DBInsertNoReload();
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ use Combodo\iTop\Application\WebPage\NiceWebPage;
|
||||
*/
|
||||
function CleanVersionNumber($sString)
|
||||
{
|
||||
$aMatches = array();
|
||||
$aMatches = [];
|
||||
if (preg_match("|^([0-9\\.]+)-|", $sString, $aMatches)) {
|
||||
return $aMatches[1];
|
||||
}
|
||||
@@ -124,11 +124,11 @@ function CleanVersionNumber($sString)
|
||||
|
||||
function collect_configuration()
|
||||
{
|
||||
$aConfiguration = array(
|
||||
'php' => array(),
|
||||
'mysql' => array(),
|
||||
'apache' => array(),
|
||||
);
|
||||
$aConfiguration = [
|
||||
'php' => [],
|
||||
'mysql' => [],
|
||||
'apache' => [],
|
||||
];
|
||||
|
||||
// Database information
|
||||
$m_oMysqli = CMDBSource::GetMysqli();
|
||||
@@ -170,7 +170,7 @@ function collect_configuration()
|
||||
|
||||
// PHP extensions
|
||||
if (!MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_extensions_enable', true)) {
|
||||
$aConfiguration['php_extensions'] = array();
|
||||
$aConfiguration['php_extensions'] = [];
|
||||
} else {
|
||||
foreach (get_loaded_extensions() as $extension) {
|
||||
$aConfiguration['php_extensions'][$extension] = $extension;
|
||||
@@ -178,8 +178,8 @@ function collect_configuration()
|
||||
}
|
||||
|
||||
// Collect some PHP settings having a known impact on iTop
|
||||
$aIniGet = MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_settings_array', array()); // by default, on the time of the writting, it values are : array('post_max_size', 'upload_max_filesize', 'apc.enabled', 'timezone', 'memory_limit', 'max_execution_time');
|
||||
$aConfiguration['php_settings'] = array();
|
||||
$aIniGet = MetaModel::GetConfig()->GetModuleSetting('itop-hub-connector', 'php_settings_array', []); // by default, on the time of the writting, it values are : array('post_max_size', 'upload_max_filesize', 'apc.enabled', 'timezone', 'memory_limit', 'max_execution_time');
|
||||
$aConfiguration['php_settings'] = [];
|
||||
foreach ($aIniGet as $iniGet) {
|
||||
$aConfiguration['php_settings'][$iniGet] = (string)ini_get($iniGet);
|
||||
}
|
||||
@@ -197,22 +197,22 @@ function collect_configuration()
|
||||
// iTop Installation Options, i.e. "Extensions"
|
||||
$oExtensionMap = new iTopExtensionsMap();
|
||||
$oExtensionMap->LoadChoicesFromDatabase($oConfig);
|
||||
$aConfiguration['itop_extensions'] = array();
|
||||
$aConfiguration['itop_extensions'] = [];
|
||||
foreach ($oExtensionMap->GetChoices() as $oExtension) {
|
||||
switch ($oExtension->sSource) {
|
||||
case iTopExtension::SOURCE_MANUAL:
|
||||
case iTopExtension::SOURCE_REMOTE:
|
||||
$aConfiguration['itop_extensions'][$oExtension->sCode] = array(
|
||||
$aConfiguration['itop_extensions'][$oExtension->sCode] = [
|
||||
'label' => $oExtension->sLabel,
|
||||
'value' => $oExtension->sInstalledVersion,
|
||||
);
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$aConfiguration['itop_installation_options'][$oExtension->sCode] = array(
|
||||
$aConfiguration['itop_installation_options'][$oExtension->sCode] = [
|
||||
'label' => $oExtension->sLabel,
|
||||
'value' => true,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,13 +223,13 @@ function MakeDataToPost($sTargetRoute)
|
||||
{
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) {
|
||||
// Don't expose such information in demo mode
|
||||
$aDataToPost = array('disabled' => true, 'reason' => 'demo_mode');
|
||||
$aDataToPost = ['disabled' => true, 'reason' => 'demo_mode'];
|
||||
} else {
|
||||
$aConfiguration = collect_configuration();
|
||||
|
||||
$aDataToPost = array(
|
||||
$aDataToPost = [
|
||||
'itop_hub_target_route' => $sTargetRoute,
|
||||
'itop_stack' => array(
|
||||
'itop_stack' => [
|
||||
"uuidBdd" => (string)trim(DBProperty::GetProperty('database_uuid', ''), '{}'), // TODO check if empty and... regenerate a new UUID ??
|
||||
"uuidFile" => (string)trim(@file_get_contents(utils::GetDataPath()."instance.txt"), "{} \n"), // TODO check if empty and... regenerate a new UUID ??
|
||||
'instance_friendly_name' => (string)$_SERVER['SERVER_NAME'],
|
||||
@@ -242,8 +242,8 @@ function MakeDataToPost($sTargetRoute)
|
||||
'itop_modules' => (object)$aConfiguration['itop_modules'],
|
||||
'itop_extensions' => (object)$aConfiguration['itop_extensions'],
|
||||
'itop_installation_options' => (object)$aConfiguration['itop_installation_options'],
|
||||
),
|
||||
'server_stack' => array(
|
||||
],
|
||||
'server_stack' => [
|
||||
'os_name' => (string)PHP_OS,
|
||||
'web_server_name' => (string)$aConfiguration['web_server_name'],
|
||||
'web_server_version' => (string)$aConfiguration['web_server_version'],
|
||||
@@ -253,8 +253,8 @@ function MakeDataToPost($sTargetRoute)
|
||||
'php_version' => (string)CleanVersionNumber(phpversion()),
|
||||
'php_settings' => (object)$aConfiguration['php_settings'],
|
||||
'php_extensions' => (object)$aConfiguration['php_extensions'],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $aDataToPost;
|
||||
@@ -282,21 +282,21 @@ try {
|
||||
|
||||
switch ($sTargetRoute) {
|
||||
case 'inform_after_setup':
|
||||
// Hidden IFRAME at the end of the setup
|
||||
$sParamToken = utils::ReadParam('setup_token');
|
||||
$oTokenValidation = new TokenValidation();
|
||||
$bIsTokenValid = $oTokenValidation->isSetupTokenValid($sParamToken);
|
||||
if (UserRights::IsAdministrator() || $bIsTokenValid) {
|
||||
$oPage = new NiceWebPage('');
|
||||
$aDataToPost = MakeDataToPost($sTargetRoute);
|
||||
$oPage->add('<form id="hub_launch_form" action="'.$sHubUrlStateless.'" method="post">');
|
||||
$oPage->add('<input type="hidden" name="json" value="'.utils::EscapeHtml(json_encode($aDataToPost)).'">');
|
||||
$oPage->add_ready_script('$("#hub_launch_form").trigger(\'submit\');');
|
||||
} else {
|
||||
IssueLog::Error('TokenValidation failed on inform_after_setup page');
|
||||
throw new Exception("Not allowed");
|
||||
}
|
||||
break;
|
||||
// Hidden IFRAME at the end of the setup
|
||||
$sParamToken = utils::ReadParam('setup_token');
|
||||
$oTokenValidation = new TokenValidation();
|
||||
$bIsTokenValid = $oTokenValidation->isSetupTokenValid($sParamToken);
|
||||
if (UserRights::IsAdministrator() || $bIsTokenValid) {
|
||||
$oPage = new NiceWebPage('');
|
||||
$aDataToPost = MakeDataToPost($sTargetRoute);
|
||||
$oPage->add('<form id="hub_launch_form" action="'.$sHubUrlStateless.'" method="post">');
|
||||
$oPage->add('<input type="hidden" name="json" value="'.utils::EscapeHtml(json_encode($aDataToPost)).'">');
|
||||
$oPage->add_ready_script('$("#hub_launch_form").trigger(\'submit\');');
|
||||
} else {
|
||||
IssueLog::Error('TokenValidation failed on inform_after_setup page');
|
||||
throw new Exception("Not allowed");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// All other cases, special "Hub like" web page
|
||||
@@ -335,7 +335,8 @@ try {
|
||||
$sButtonLabelClose = Dict::S('iTopHub:CloseBtn');
|
||||
$sButtonLabelGo = Dict::S('iTopHub:GoBtn');
|
||||
$sButtonLabelTooltip = Dict::S('iTopHub:GoBtn:Tooltip');
|
||||
$oPage->add(<<<HTML
|
||||
$oPage->add(
|
||||
<<<HTML
|
||||
<p>
|
||||
<button type="button" class="ibo-button" id="CancelBtn" title="Go back to iTop"><img src="$sCloseUrl"><span class="ibo-button--label">$sButtonLabelClose</span></button>
|
||||
<span class="horiz-spacer"></span>
|
||||
@@ -403,8 +404,7 @@ JS
|
||||
}
|
||||
|
||||
$oPage->output();
|
||||
}
|
||||
catch (CoreException $e) {
|
||||
} catch (CoreException $e) {
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
@@ -429,8 +429,7 @@ catch (CoreException $e) {
|
||||
|
||||
// For debugging only
|
||||
// throw $e;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
$oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError'));
|
||||
$oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
|
||||
@@ -446,11 +445,10 @@ catch (Exception $e) {
|
||||
$oLog->Set('issue', 'PHP Exception');
|
||||
$oLog->Set('impact', 'Page could not be displayed');
|
||||
$oLog->Set('callstack', $e->getTrace());
|
||||
$oLog->Set('data', array());
|
||||
$oLog->Set('data', []);
|
||||
$oLog->DBInsertNoReload();
|
||||
}
|
||||
|
||||
IssueLog::Error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// iTop module definition file
|
||||
//
|
||||
@@ -6,7 +7,7 @@
|
||||
SetupWebPage::AddModule(
|
||||
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
|
||||
'itop-hub-connector/3.3.0',
|
||||
array(
|
||||
[
|
||||
// Identification
|
||||
//
|
||||
'label' => 'iTop Hub Connector',
|
||||
@@ -14,31 +15,31 @@ SetupWebPage::AddModule(
|
||||
|
||||
// Setup
|
||||
//
|
||||
'dependencies' => array(
|
||||
'dependencies' => [
|
||||
'itop-config-mgmt/2.4.0', // Actually this module requires iTop 2.4.1 minimum
|
||||
),
|
||||
],
|
||||
'mandatory' => false,
|
||||
'visible' => true,
|
||||
|
||||
// Components
|
||||
//
|
||||
'datamodel' => array(
|
||||
'datamodel' => [
|
||||
'menus.php',
|
||||
'hubnewsroomprovider.class.inc.php',
|
||||
),
|
||||
'webservice' => array(
|
||||
|
||||
),
|
||||
'data.struct' => array(
|
||||
'hubnewsroomprovider.class.inc.php',
|
||||
],
|
||||
'webservice' => [
|
||||
|
||||
],
|
||||
'data.struct' => [
|
||||
// add your 'structure' definition XML files here,
|
||||
),
|
||||
'data.sample' => array(
|
||||
],
|
||||
'data.sample' => [
|
||||
// add your sample data XML files here,
|
||||
),
|
||||
|
||||
],
|
||||
|
||||
// Documentation
|
||||
//
|
||||
'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
|
||||
'doc.more_information' => '', // hyperlink to more information, if any
|
||||
)
|
||||
'doc.more_information' => '', // hyperlink to more information, if any
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user