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', 'soap'); 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)."."); $bResult = false; } // Check some ini settings here if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4 { $sPhpIniFile = php_ini_loaded_file(); $oP->log("Info - php.ini path: '$sPhpIniFile'"); } else { $sPhpIniFile = 'php.ini'; } if (!ini_get('file_uploads')) { $oP->error("Files upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').")."); $bResult = false; } $sUploadTmpDir = GetUploadTmpDir(); if (empty($sUploadTmpDir)) { $sUploadTmpDir = '/tmp'; $oP->warning("Temporary directory for files upload is not defined (upload_tmp_dir), assuming that $sUploadTmpDir is used."); } // check that the upload directory is indeed writable from PHP if (!empty($sUploadTmpDir)) { if (!file_exists($sUploadTmpDir)) { $oP->error("Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP."); $bResult = false; } else if (!is_writable($sUploadTmpDir)) { $oP->error("Temporary directory for files upload ($sUploadTmpDir) is not writable."); $bResult = false; } else { $oP->log("Info - Temporary directory for files upload ($sUploadTmpDir) is writable."); } } if (!ini_get('upload_max_filesize')) { $oP->error("File upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').")."); } $iMaxFileUploads = ini_get('max_file_uploads'); if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1)) { $oP->error("File upload is not allowed on this server (max_file_uploads = ".ini_get('max_file_uploads').")."); $bResult = false; } $oP->log("Info - upload_max_filesize: ".ini_get('upload_max_filesize')); $oP->log("Info - max_file_uploads: ".ini_get('max_file_uploads')); // Check some more ini settings here, needed for file upload if (get_magic_quotes_gpc()) { $oP->error("'magic_quotes_gpc' is set to On in '$sPhpIniFile', please turn if Off before continuing."); $bResult = false; } return $bResult; } /** * 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(SetupWebPage $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."); $oP->log("Info - User privileges: ".($oDBSource->GetRawPrivileges())); $sDBVersion = $oDBSource->GetDBVersion(); if (version_compare($sDBVersion, MYSQL_MIN_VERSION, '>=')) { $oP->ok("Current MySQL version ($sDBVersion), greater than minimum required version (".MYSQL_MIN_VERSION.")"); // Check some server variables $iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet'); $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); if ($iMaxAllowedPacket >= (500 + $iMaxUploadSize)) // Allow some space for the query + the file to upload { $oP->ok("MySQL server's max_allowed_packet is big enough."); } else if($iMaxAllowedPacket < $iMaxUploadSize) { $oP->warning("MySQL server's max_allowed_packet ($iMaxAllowedPacket) is not big enough. Please, consider setting it to at least ".(500 + $iMaxUploadSize)."."); } $oP->log("Info - MySQL max_allowed_packet: $iMaxAllowedPacket"); $iMaxConnections = $oDBSource->GetServerVariable('max_connections'); if ($iMaxConnections < 5) { $oP->warning("MySQL server's max_connections ($iMaxConnections) is not enough. Please, consider setting it to at least 5."); } $oP->log("Info - MySQL max_connections: ".($oDBSource->GetServerVariable('max_connections'))); } 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(SetupWebPage $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(SetupWebPage $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'); if (strlen($sDBPrefix) > 0) { $oP->info("Creating the structure in '$sDBName' (table names prefixed by '$sDBPrefix')."); } else { $oP->info("Creating the structure in '$sDBName'."); } //MetaModel::CheckDefinitions(); if (!MetaModel::DBExists(/* bMustBeComplete */ false)) { MetaModel::DBCreate(); $oP->ok("Database structure successfuly created."); } else { if (strlen($sDBPrefix) > 0) { $oP->error("Error: found iTop tables into the database '$sDBName' (prefix: '$sDBPrefix'). Please, try selecting another database instance or specify another prefix to prevent conflicting table names."); } else { $oP->error("Error: found iTop tables into the database '$sDBName'. Please, try selecting another database instance or specify 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(SetupWebPage $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, SetupWebPage $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(SetupWebPage $oP) { $oP->add("\n"); } /** * Display the form for the first step of the configuration wizard * which consists in the database server selection */ function DisplayStep1(SetupWebPage $oP) { $sNextOperation = 'step2'; $oP->add("