set_title(Dict::S('iTopHub:Landing:Status')); $oPage->add(''); $sBannerUrl = utils::GetAbsoluteUrlModulesRoot().'/itop-hub-connector/images/landing-extension.png'; $oPage->add('
'); $oPage->add('

'.Dict::S('iTopHub:LandingWelcome').'

'); $oPage->add('
'); $oPage->add('
'); // Now scan the extensions and display a report of the extensions brought by the hub $sPath = utils::GetDataPath().'downloaded-extensions/'; $aExtraDirs = []; if (is_dir($sPath)) { $aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory } $oExtensionsMap = new iTopExtensionsMap('production', $aExtraDirs); $oExtensionsMap->LoadChoicesFromDatabase(MetaModel::GetConfig()); foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) { if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) { $aCSSClasses = ['landing-extension']; if ($oExtension->sInstalledVersion === '') { $aCSSClasses[] = 'landing-installation'; $sInstallation = Dict::Format('iTopHub:InstallationStatus:Version_NotInstalled', $oExtension->sVersion); } else { $aCSSClasses[] = 'landing-no-change'; $sBadge = ''.Dict::S('iTopHub:InstallationStatus:Installed').''; $sInstallation = Dict::Format('iTopHub:InstallationStatus:Installed_Version', $sBadge, $oExtension->sInstalledVersion); } $oPage->add('
'); $sCode = $oExtension->sCode; $sDir = basename($oExtension->sSourceDir); $oPage->add(' '); $oPage->add(''); $oPage->add('
'); $oPage->add('

'); if ($oExtension->sDescription != '') { $oPage->add(utils::EscapeHtml($oExtension->sDescription).'
'); } $oPage->add('

'); $oPage->add('
'); $oPage->add('
'); } } $oPage->add('
'); $oPage->add('
'); } function DoLanding(WebPage $oPage) { $oPage->LinkStylesheetFromModule('itop-hub-connector/css/hub.css'); $oPage->add(''); $sBannerUrl = utils::GetAbsoluteUrlModulesRoot().'/itop-hub-connector/images/landing-extension.png'; $oPage->add('
'); $oPage->add('

'.Dict::S('iTopHub:InstallationWelcome').'

'); $oPage->add('
'); $oPage->set_title(Dict::S('iTopHub:Landing:Status')); $oPage->add('

'.Dict::S('iTopHub:Uncompressing').'

'); $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', [], false, 'raw_data'); // Basic consistency validation if ($sProduct != ITOP_APPLICATION) { throw new Exception("Inconsistent product '$sProduct', expecting '".ITOP_APPLICATION."'"); } if ($sVersion != ITOP_VERSION) { throw new Exception("Inconsistent version '$sVersion', expecting ".ITOP_VERSION."'"); } $sFileUUID = (string)trim(@file_get_contents(utils::GetDataPath()."instance.txt"), "{} \n"); if ($sInstanceUUID != $sFileUUID) { throw new Exception("Inconsistent file UUID '$sInstanceUUID', expecting ".$sFileUUID."'"); } $sDBUUID = (string)trim(DBProperty::GetProperty('database_uuid', ''), '{}'); if ($sDatabaseUUID != $sDBUUID) { throw new Exception("Inconsistent database UUID '$sDatabaseUUID', expecting ".$sDBUUID."'"); } // Uncompression of extensions in data/downloaded-extensions // only newly downloaded extensions reside in this folder $i = 0; $sPath = utils::GetDataPath().'downloaded-extensions/'; if (!is_dir($sPath)) { if (!mkdir($sPath)) { throw new Exception("ERROR: Unable to create the directory '$sPath'. Cannot download any extension. Check the access rights on '".dirname('data/downloaded-extensions/')."'"); } } else { // Make sure that the directory is empty SetupUtils::tidydir($sPath); } foreach ($aExtensions as $sBase64Archive) { $sArchive = base64_decode($sBase64Archive); $sZipArchiveFile = $sPath."/extension-{$i}.zip"; file_put_contents($sZipArchiveFile, $sArchive); // Expand the content of extension-x.zip into utils::GetDataPath().'downloaded-extensions/' // where the installation will load the extension automatically $oZip = new ZipArchive(); if (!$oZip->open($sZipArchiveFile)) { throw new Exception('Unable to open "'.$sZipArchiveFile.'" for extraction. Make sure that the directory "'.'data/downloaded-extensions/'.'" is writable for the web server.'); } for ($idx = 0; $idx < $oZip->numFiles; $idx++) { $sCompressedFile = $oZip->getNameIndex($idx); $oZip->extractTo($sPath, $sCompressedFile); } @$oZip->close(); @unlink($sZipArchiveFile); // Get rid of the temporary file $i++; } // Now scan the extensions and display a report of the extensions brought by the hub $sNextPage = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', ['operation' => 'install']); $oPage->add_ready_script("window.location.href='$sNextPage'"); } function DoInstall(WebPage $oPage) { $sUID = hash('sha256', rand()); file_put_contents(utils::GetDataPath().'hub/compile_authent', $sUID); $oPage->LinkStylesheetFromModule('itop-hub-connector/css/hub.css'); $oPage->add(''); $sBannerUrl = utils::GetAbsoluteUrlModulesRoot().'/itop-hub-connector/images/landing-extension.png'; $oPage->add('
'); $oPage->add('

'.Dict::S('iTopHub:InstallationWelcome').'

'); $oPage->add('
'); $oPage->set_title(Dict::S('iTopHub:Landing:Install')); $oPage->add('
'); // 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 = []; if (is_dir($sPath)) { $aExtraDirs[] = $sPath; // Also read the extra downloaded-modules directory } $oExtensionsMap = new iTopExtensionsMap('production', $aExtraDirs); $oExtensionsMap->LoadChoicesFromDatabase(MetaModel::GetConfig()); foreach ($oExtensionsMap->GetAllExtensions() as $oExtension) { if ($oExtension->sSource == iTopExtension::SOURCE_REMOTE) { if (count($oExtension->aMissingDependencies) > 0) { $oPage->add('
'); $oPage->add(' '); $sTitle = Dict::Format('iTopHub:InstallationEffect:MissingDependencies_Details', implode(', ', $oExtension->aMissingDependencies)); $oPage->add(''); $oPage->add('
'); $oPage->add('

'); if ($oExtension->sDescription != '') { $oPage->add(utils::EscapeHtml($oExtension->sDescription).'
'); } $oPage->add('

'); $oPage->add('
'); $oPage->add('
'); } else { $aCSSClasses = ['landing-extension']; if ($oExtension->sInstalledVersion === '') { $aCSSClasses[] = 'landing-installation'; $sInstallation = Dict::Format('iTopHub:InstallationEffect:Install', $oExtension->sVersion); } elseif ($oExtension->sInstalledVersion == $oExtension->sVersion) { $aCSSClasses[] = 'landing-no-change'; $sInstallation = Dict::Format('iTopHub:InstallationEffect:NoChange', $oExtension->sVersion); } elseif (version_compare($oExtension->sInstalledVersion, $oExtension->sVersion, '<')) { $aCSSClasses[] = 'landing-upgrade'; $sInstallation = Dict::Format('iTopHub:InstallationEffect:Upgrade', $oExtension->sInstalledVersion, $oExtension->sVersion); } else { $aCSSClasses[] = 'landing-downgrade'; $sInstallation = Dict::Format('iTopHub:InstallationEffect:Downgrade', $oExtension->sInstalledVersion, $oExtension->sVersion); } $oPage->add('
'); $sCode = $oExtension->sCode; $sDir = basename($oExtension->sSourceDir); $oPage->add(' '); $oPage->add(''); $oPage->add('
'); $oPage->add('

'); if ($oExtension->sDescription != '') { $oPage->add(utils::EscapeHtml($oExtension->sDescription).'
'); } $oPage->add('

'); $oPage->add('
'); $oPage->add('
'); } } } $oPage->add('
'); $oPage->add('
'); $oPage->add('
'.Dict::S('iTopHub:DatabaseBackupProgress').'
'); $oPage->add('
'); $oPage->add('
'); // module-selection-body $oPage->LinkStylesheetFromAppRoot('css/font-awesome/css/all.min.css'); $oPage->add('
'); $oPage->add('
'.Dict::S('iTopHub:DBBackupLabel').''); $oPage->add('
'); $oPage->add('
'); $oPage->add('
'); $oPage->add('

'); $sIframeUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'launch.php', ['target' => 'inform_after_setup']); $sStatusPageUrl = utils::GetAbsoluteUrlModulePage('itop-hub-connector', 'land.php', ['operation' => 'done']); $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' => [ '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); $oPage->add_ready_script("$('#hub_installation_widget').hub_installation($sWidgetParams);"); $oPage->add_ready_script("$('#hub_start_installation').on('click', function() { $('#hub_installation_widget').hub_installation('start_installation');} );"); $oPage->add_ready_script("$('#hub_installation_widget').hub_installation('check_before_backup');"); $oPage->add('
'); } try { require_once(APPROOT.'/application/application.inc.php'); require_once(APPROOT.'/setup/setuppage.class.inc.php'); require_once(APPROOT.'/setup/extensionsmap.class.inc.php'); require_once(APPROOT.'/application/startup.inc.php'); require_once(APPROOT.'/application/loginwebpage.class.inc.php'); LoginWebPage::DoLoginEx(null, true /* $bMustBeAdmin */); // Check user rights and prompt if needed if (MetaModel::GetConfig()->Get('demo_mode')) { throw new Exception('Sorry the installation of extensions is not allowed in demo mode'); } $oPage = new SetupPage(''); // Title will be set later, depending on $sOperation $oPage->LinkScriptFromModule('itop-hub-connector/js/hub.js'); $oPage->LinkStylesheetFromAppRoot('css/font-combodo/font-combodo.css'); $oPage->add_style( <<output(); } catch (Exception $e) { require_once(APPROOT.'/setup/setuppage.class.inc.php'); $oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("

".Dict::S('UI:FatalErrorMessage')."

\n"); $oP->error(Dict::Format('UI:Error_Details', $e->getMessage())); $oP->output(); if (MetaModel::IsLogEnabledIssue()) { if (MetaModel::IsValidClass('EventIssue')) { $oLog = new EventIssue(); $oLog->Set('message', $e->getMessage()); $oLog->Set('userinfo', ''); $oLog->Set('issue', 'PHP Exception'); $oLog->Set('impact', 'Page could not be displayed'); $oLog->Set('callstack', $e->getTrace()); $oLog->Set('data', []); $oLog->DBInsertNoReload(); } IssueLog::Error($e->getMessage()); } }