log('Info - CheckPHPVersion'); if (version_compare(phpversion(), PHP_MIN_VERSION, '>=')) { $oP->ok("The current PHP Version (".phpversion().") is greater than the minimum required version (".PHP_MIN_VERSION.")"); } else { $oP->error("Error: The current PHP Version (".phpversion().") is lower than the minimum required version (".PHP_MIN_VERSION.")"); return false; } $aMandatoryExtensions = array('mysql', 'iconv', 'simplexml'); asort($aMandatoryExtensions); // Sort the list to look clean ! $aExtensionsOk = array(); $aMissingExtensions = array(); $aMissingExtensionsLinks = array(); foreach($aMandatoryExtensions as $sExtension) { if (extension_loaded($sExtension)) { $aExtensionsOk[] = $sExtension; } else { $aMissingExtensions[] = $sExtension; $aMissingExtensionsLinks[] = "$sExtension"; } } if (count($aExtensionsOk) > 0) { $oP->ok("Required PHP extension(s): ".implode(', ', $aExtensionsOk)."."); } if (count($aMissingExtensions) > 0) { $oP->error("Missing PHP extension(s): ".implode(', ', $aMissingExtensionsLinks)."."); return false; } return true; } /** * Helper function check the connection to the database and (if connected) to enumerate * the existing databases * @return Array The list of databases found in the server */ function CheckServerConnection(setup_web_page $oP, $sDBServer, $sDBUser, $sDBPwd) { $aResult = array(); $oP->log('Info - CheckServerConnection'); try { $oDBSource = new CMDBSource; $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd); $oP->ok("Connection to '$sDBServer' as '$sDBUser' successful."); $sDBVersion = $oDBSource->GetDBVersion(); if (version_compare($sDBVersion, MYSQL_MIN_VERSION, '>=')) { $oP->ok("Current MySQL version ($sDBVersion), greater than minimum required version (".MYSQL_MIN_VERSION.")"); } else { $oP->error("Error: Current MySQL version is ($sDBVersion), minimum required version (".MYSQL_MIN_VERSION.")"); return false; } try { $aResult = $oDBSource->ListDB(); } catch(Exception $e) { $oP->warning("Warning: unable to enumerate the current databases."); $aResult = true; // Not an array to differentiate with an empty array } } catch(Exception $e) { $oP->error("Error: Connection to '$sDBServer' as '$sDBUser' failed."); $oP->p($e->GetHtmlDesc()); $aResult = false; } return $aResult; } /** * Helper function to initialize the ORM and load the data model * from the given file * @param $sConfigFileName string The name of the configuration file to load * @param $bAllowMissingDatabase boolean Whether or not to allow loading a data model with no corresponding DB * @return none */ function InitDataModel(setup_web_page $oP, $sConfigFileName, $bAllowMissingDatabase = true) { require_once('../core/coreexception.class.inc.php'); require_once('../core/attributedef.class.inc.php'); require_once('../core/filterdef.class.inc.php'); require_once('../core/stimulus.class.inc.php'); require_once('../core/MyHelpers.class.inc.php'); require_once('../core/expression.class.inc.php'); require_once('../core/cmdbsource.class.inc.php'); require_once('../core/sqlquery.class.inc.php'); require_once('../core/dbobject.class.php'); require_once('../core/dbobjectsearch.class.php'); require_once('../core/dbobjectset.class.php'); require_once('../core/userrights.class.inc.php'); $oP->log("Info - MetaModel::Startup from file '$sConfigFileName' (AllowMissingDB = $bAllowMissingDatabase)"); MetaModel::Startup($sConfigFileName, $bAllowMissingDatabase); } /** * Helper function to create the database structure * @return boolean true on success, false otherwise */ function CreateDatabaseStructure(setup_web_page $oP, Config $oConfig, $sDBName, $sDBPrefix) { InitDataModel($oP, TMP_CONFIG_FILE, true); // Allow the DB to NOT exist since we're about to create it ! $oP->log('Info - CreateDatabaseStructure'); $oP->info("Creating the structure in '$sDBName' (prefix = '$sDBPrefix')."); //MetaModel::CheckDefinitions(); if (!MetaModel::DBExists()) { MetaModel::DBCreate(); $oP->ok("Database structure created in '$sDBName' (prefix = '$sDBPrefix')."); } else { $oP->error("Error: database '$sDBName' (prefix = '$sDBPrefix') already exists."); $oP->p("Tables with conflicting names already exist in the database. Try selecting another database instance or specifiy a prefix to prevent conflicting table names."); return false; } return true; } /** * Helper function to create and administrator account for iTop * @return boolean true on success, false otherwise */ function CreateAdminAccount(setup_web_page $oP, Config $oConfig, $sAdminUser, $sAdminPwd) { $oP->log('Info - CreateAdminAccount'); InitDataModel($oP, TMP_CONFIG_FILE, true); // allow missing DB if (UserRights::CreateAdministrator($sAdminUser, $sAdminPwd)) { $oP->ok("Administrator account '$sAdminUser' created."); return true; } else { $oP->error("Failed to create the administrator account '$sAdminUser'."); return false; } } //aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus function ListDataFiles($sDirectory, setup_web_page $oP) { $aFilesToLoad = array(); if ($hDir = @opendir($sDirectory)) { // This is the correct way to loop over the directory. (according to the documentation) while (($sFile = readdir($hDir)) !== false) { $sExtension = pathinfo($sFile, PATHINFO_EXTENSION ); if (strcasecmp($sExtension, 'xml') == 0) { $aFilesToLoad[] = $sDirectory.'/'.$sFile; } } closedir($hDir); // Load order is important we expect the files to be ordered // like numbered 1.Organizations.xml 2.Locations.xml , etc. asort($aFilesToLoad); } else { $oP->error("Data directory (".$sDirectory.") not found or not readable."); } return $aFilesToLoad; } /** * Scans the ./data directory for XML files and output them as a Javascript array */ function PopulateDataFilesList(setup_web_page $oP) { $oP->add("\n"); } /** * Display the form for the first step of the configuration wizard * which consists in the database server selection */ function DisplayStep1(setup_web_page $oP) { $sNextOperation = 'step2'; $oP->add("