function RebuildToolkitEnvironment() { define('TOOLKITENV', 'toolkit'); $oConfig = new Config(APPCONF . 'production' . '/' . ITOP_CONFIG_FILE); $oToolkitConfig = clone $oConfig; $oToolkitConfig->ChangeModulesPath('production', TOOLKITENV); if (file_exists(APPROOT . 'data/production.delta.xml')) { copy(APPROOT . 'data/production.delta.xml', APPROOT . 'data/toolkit.delta.xml'); } $oEnvironment = new RunTimeEnvironment(TOOLKITENV); $oEnvironment->WriteConfigFileSafe($oToolkitConfig); $oEnvironment->CompileFrom('production'); }
$sPHPVersion = phpversion(); $sOSVersion = PHP_OS; $sWebServerVersion = $_SERVER["SERVER_SOFTWARE"]; $sModules = implode(', ', get_loaded_extensions()); // Get the datamodel directory $oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation WHERE name="datamodel"'); $oSet = new DBObjectSet($oFilter, array('installed' => false)); // Most recent first $oLastInstall = $oSet->Fetch(); $sLastInstallDate = $oLastInstall->Get('installed'); $sDataModelVersion = $oLastInstall->Get('version'); $aDataModelInfo = json_decode($oLastInstall->Get('comment'), true); $sDataModelSourceDir = $aDataModelInfo['source_dir']; require_once APPROOT . 'setup/runtimeenv.class.inc.php'; $sCurrEnv = utils::GetCurrentEnvironment(); $oRuntimeEnv = new RunTimeEnvironment($sCurrEnv); $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation(MetaModel::GetConfig(), array(APPROOT . $sDataModelSourceDir, APPROOT . 'extensions')); require_once APPROOT . 'setup/setuputils.class.inc.php'; $aLicenses = SetupUtils::GetLicenses(); $aItopSettings = array('cron_max_execution_time', 'timezone'); $aPHPSettings = array('memory_limit', 'max_execution_time', 'upload_max_filesize', 'post_max_size'); $aMySQLSettings = array('max_allowed_packet', 'key_buffer_size', 'query_cache_size'); $aMySQLStatuses = array('Key_read_requests', 'Key_reads'); if (extension_loaded('suhosin')) { $aPHPSettings[] = 'suhosin.post.max_vars'; $aPHPSettings[] = 'suhosin.get.max_value_length'; } $aMySQLVars = array(); foreach (CMDBSource::QueryToArray('SHOW VARIABLES') as $aRow) { $aMySQLVars[$aRow['Variable_name']] = $aRow['Value']; }
public static function GetApplicationVersion($oWizard) { require_once APPROOT . '/setup/moduleinstaller.class.inc.php'; $oConfig = new Config(); $aParamValues = array('db_server' => $oWizard->GetParameter('db_server', ''), 'db_user' => $oWizard->GetParameter('db_user', ''), 'db_pwd' => $oWizard->GetParameter('db_pwd', ''), 'db_name' => $oWizard->GetParameter('db_name', ''), 'db_prefix' => $oWizard->GetParameter('db_prefix', ''), 'source_dir' => ''); $oConfig->UpdateFromParams($aParamValues, null); $oProductionEnv = new RunTimeEnvironment(); return $oProductionEnv->GetApplicationVersion($oConfig); }
\t\t);\t\t \t} EOF ); $oP->add("<h1>Data Model Toolkit</h1>\n"); define('TOOLKITENV', 'toolkit'); // Compile the current code into the environment 'toolkit' // The environment will be rebuilt in case of refresh (if refreshing a view relying on this environment) // $oConfig = new Config(APPCONF . 'production/' . ITOP_CONFIG_FILE); if ($oConfig->Get('source_dir') == '') { throw new Exception('Missing entry source_dir from the config file'); } $oToolkitConfig = clone $oConfig; $oToolkitConfig->ChangeModulesPath('production', TOOLKITENV); $oEnvironment = new RunTimeEnvironment(TOOLKITENV); $oEnvironment->WriteConfigFileSafe($oToolkitConfig); $oEnvironment->CompileFrom('production'); $oP->add("<!-- tabs -->\n<div id=\"tabbedContent\" class=\"light\">\n"); $oP->add("<ul>\n"); $oP->add("<li><a href=\"#tab_0\" class=\"tab\"><span>Data Model Consistency</span></a></li>\n"); $oP->add("<li><a href=\"#tab_1\" class=\"tab\"><span>iTop update</span></a></li>\n"); $oP->add("<li><a href=\"#tab_2\" class=\"tab\"><span>Data Integrity</span></a></li>\n"); $oP->add("<li><a href=\"#tab_3\" class=\"tab\"><span>Translations / Dictionnary</span></a></li>\n"); $oP->add("</ul>\n"); $oP->add("<div id=\"tab_0\">"); CheckConsistency($oP); $oP->add("</div>\n"); $oP->add("<div id=\"tab_1\">"); CheckDBSchema($oP); $oP->add("</div>\n");
public function RestoreFromZip($sZipFile, $sEnvironment = 'production') { $this->LogInfo("Starting restore of " . basename($sZipFile)); $oZip = new ZipArchiveEx(); $res = $oZip->open($sZipFile); // Load the database // $sDataDir = tempnam(SetupUtils::GetTmpDir(), 'itop-'); unlink($sDataDir); // I need a directory, not a file... SetupUtils::builddir($sDataDir); // Here is the directory $oZip->extractTo($sDataDir, 'itop-dump.sql'); $sDataFile = $sDataDir . '/itop-dump.sql'; $this->LoadDatabase($sDataFile); unlink($sDataFile); // Update the code // $sDeltaFile = APPROOT . 'data/' . $sEnvironment . '.delta.xml'; if ($oZip->locateName('delta.xml') !== false) { // Extract and rename delta.xml => <env>.delta.xml; file_put_contents($sDeltaFile, $oZip->getFromName('delta.xml')); } else { @unlink($sDeltaFile); } if (is_dir(APPROOT . 'data/production-modules/')) { SetupUtils::rrmdir(APPROOT . 'data/production-modules/'); } if ($oZip->locateName('production-modules/') !== false) { $oZip->extractDirTo(APPROOT . 'data/', 'production-modules/'); } $sConfigFile = APPROOT . 'conf/' . $sEnvironment . '/config-itop.php'; @chmod($sConfigFile, 0770); // Allow overwriting the file $oZip->extractTo(APPROOT . 'conf/' . $sEnvironment, 'config-itop.php'); @chmod($sConfigFile, 0444); // Read-only $oEnvironment = new RunTimeEnvironment($sEnvironment); $oEnvironment->CompileFrom($sEnvironment); }
/** * Get the installed modules (only the installed ones) */ protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir) { $sSourceDirFull = APPROOT . $sSourceDir; if (!is_dir($sSourceDirFull)) { throw new Exception("The source directory '{$sSourceDirFull}' does not exist (or could not be read)"); } $aDirsToCompile = array($sSourceDirFull); if (is_dir(APPROOT . 'extensions')) { $aDirsToCompile[] = APPROOT . 'extensions'; } $aRet = array(); // Determine the installed modules // $oSourceConfig = new Config(APPCONF . $sSourceEnv . '/' . ITOP_CONFIG_FILE); $oSourceEnv = new RunTimeEnvironment($sSourceEnv); $aAvailableModules = $oSourceEnv->AnalyzeInstallation($oSourceConfig, $aDirsToCompile); // Do load the required modules // $oFactory = new ModelFactory($aDirsToCompile); $aModules = $oFactory->FindModules(); foreach ($aModules as $foo => $oModule) { $sModule = $oModule->GetName(); if (array_key_exists($sModule, $aAvailableModules)) { if ($aAvailableModules[$sModule]['version_db'] != '') { $aRet[] = $oModule; } } } $sDeltaFile = APPROOT . 'data/' . $this->sTargetEnv . '.delta.xml'; if (file_exists($sDeltaFile)) { $oDelta = new MFDeltaModule($sDeltaFile); $aRet[] = $oDelta; } return $aRet; }
$sPHPVersion = phpversion(); $sOSVersion = PHP_OS; $sWebServerVersion = $_SERVER["SERVER_SOFTWARE"]; $sModules = implode(', ', get_loaded_extensions()); // Get the datamodel directory $oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation WHERE name="datamodel"'); $oSet = new DBObjectSet($oFilter, array('installed' => false)); // Most recent first $oLastInstall = $oSet->Fetch(); $sLastInstallDate = $oLastInstall->Get('installed'); $sDataModelVersion = $oLastInstall->Get('version'); $aDataModelInfo = json_decode($oLastInstall->Get('comment'), true); $sDataModelSourceDir = $aDataModelInfo['source_dir']; require_once APPROOT . 'setup/runtimeenv.class.inc.php'; $sCurrEnv = utils::GetCurrentEnvironment(); $oRuntimeEnv = new RunTimeEnvironment($sCurrEnv); $aSearchDirs = array(APPROOT . $sDataModelSourceDir); if (file_exists(APPROOT . 'extensions')) { $aSearchDirs[] = APPROOT . 'extensions'; } $sExtraDir = APPROOT . 'data/' . $sCurrEnv . '-modules/'; if (file_exists($sExtraDir)) { $aSearchDirs[] = $sExtraDir; } $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation(MetaModel::GetConfig(), $aSearchDirs); require_once APPROOT . 'setup/setuputils.class.inc.php'; $aLicenses = SetupUtils::GetLicenses(); $aItopSettings = array('cron_max_execution_time', 'timezone'); $aPHPSettings = array('memory_limit', 'max_execution_time', 'upload_max_filesize', 'post_max_size'); $aMySQLSettings = array('max_allowed_packet', 'key_buffer_size', 'query_cache_size'); $aMySQLStatuses = array('Key_read_requests', 'Key_reads');
protected static function DoCreateConfig($sMode, $sModulesDir, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sUrl, $sLanguage, $aSelectedModules, $sTargetEnvironment, $bOldAddon, $sSourceDir, $sPreviousConfigFile, $sDataModelVersion, $sGraphvizPath) { $aParamValues = array('mode' => $sMode, 'db_server' => $sDBServer, 'db_user' => $sDBUser, 'db_pwd' => $sDBPwd, 'db_name' => $sDBName, 'new_db_name' => $sDBName, 'db_prefix' => $sDBPrefix, 'application_path' => $sUrl, 'language' => $sLanguage, 'graphviz_path' => $sGraphvizPath, 'selected_modules' => implode(',', $aSelectedModules)); $bPreserveModuleSettings = false; if ($sMode == 'upgrade') { try { $oOldConfig = new Config($sPreviousConfigFile); $oConfig = clone $oOldConfig; $bPreserveModuleSettings = true; } catch (Exception $e) { // In case the previous configuration is corrupted... start with a blank new one $oConfig = new Config(); } } else { $oConfig = new Config(); // To preserve backward compatibility while upgrading to 2.0.3 (when tracking_level_linked_set_default has been introduced) // the default value on upgrade differs from the default value at first install $oConfig->Set('tracking_level_linked_set_default', LINKSET_TRACKING_NONE, 'first_install'); } // Migration: force utf8_unicode_ci as the collation to make the global search // NON case sensitive $oConfig->SetDBCollation('utf8_unicode_ci'); // Final config update: add the modules $oConfig->UpdateFromParams($aParamValues, $sModulesDir, $bPreserveModuleSettings); if ($bOldAddon) { // Old version of the add-on for backward compatibility with pre-2.0 data models $oConfig->SetAddons(array('user rights' => 'addons/userrights/userrightsprofile.db.class.inc.php')); } $oConfig->Set('source_dir', $sSourceDir); // Have it work fine even if the DB has been set in read-only mode for the users $iPrevAccessMode = $oConfig->Get('access_mode'); $oConfig->Set('access_mode', ACCESS_FULL); // Record which modules are installed... $oProductionEnv = new RunTimeEnvironment($sTargetEnvironment); $oProductionEnv->InitDataModel($oConfig, true); // load data model and connect to the database $aAvailableModules = $oProductionEnv->AnalyzeInstallation(MetaModel::GetConfig(), APPROOT . $sModulesDir); if (!$oProductionEnv->RecordInstallation($oConfig, $sDataModelVersion, $aSelectedModules, $sModulesDir)) { throw new Exception("Failed to record the installation information"); } // Restore the previous access mode $oConfig->Set('access_mode', $iPrevAccessMode); // Make sure the root configuration directory exists if (!file_exists(APPCONF)) { mkdir(APPCONF); chmod(APPCONF, 0770); // RWX for owner and group, nothing for others SetupPage::log_info("Created configuration directory: " . APPCONF); } // Write the final configuration file $sConfigFile = APPCONF . ($sTargetEnvironment == '' ? 'production' : $sTargetEnvironment) . '/' . ITOP_CONFIG_FILE; $sConfigDir = dirname($sConfigFile); @mkdir($sConfigDir); @chmod($sConfigDir, 0770); // RWX for owner and group, nothing for others $oConfig->WriteToFile($sConfigFile); // try to make the final config file read-only @chmod($sConfigFile, 0444); // Read-only for owner and group, nothing for others // Ready to go !! require_once APPROOT . 'core/dict.class.inc.php'; MetaModel::ResetCache(); }