/** * The standardized result of any pass/fail check performed by the setup * @copyright Copyright (C) 2010-2012 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ class CheckResult { // Severity levels const ERROR = 0; const WARNING = 1; const INFO = 2; public $iSeverity; public $sLabel; public $sDescription; public function __construct($iSeverity, $sLabel, $sDescription = '') { $this->iSeverity = $iSeverity; $this->sLabel = $sLabel; $this->sDescription = $sDescription; } } /** * Namespace for storing all the functions/utilities needed by both * the setup wizard and the installation process * @copyright Copyright (C) 2010-2012 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ class SetupUtils { const PHP_MIN_VERSION = '5.2.0'; const MYSQL_MIN_VERSION = '5.0.0'; const MIN_MEMORY_LIMIT = 33554432; // = 32*1024*1024 Beware: Computations are not allowed in defining constants const SUHOSIN_GET_MAX_VALUE_LENGTH = 2048; /** * Check the version of PHP, the needed PHP extension and a number * of configuration parameters (memory_limit, max_upload_file_size, etc...) * @param SetupPage $oP The page used only for its 'log' method * @return array An array of CheckResults objects */ static function CheckPHPVersion() { $aResult = array(); // For log file(s) if (!is_dir(APPROOT.'log')) { @mkdir(APPROOT.'log'); } SetupPage::log('Info - CheckPHPVersion'); if (version_compare(phpversion(), self::PHP_MIN_VERSION, '>=')) { $aResult[] = new CheckResult(CheckResult::INFO, "The current PHP Version (".phpversion().") is greater than the minimum version required to run ".ITOP_APPLICATION.", which is (".self::PHP_MIN_VERSION.")"); } else { $aResult[] = new CheckResult(CheckResult::ERROR, "Error: The current PHP Version (".phpversion().") is lower than the minimum version required to run ".ITOP_APPLICATION.", which is (".self::PHP_MIN_VERSION.")"); } // Check the common directories $aWritableDirsErrors = self::CheckWritableDirs(array('log', 'env-production', 'conf', 'data')); $aResult = array_merge($aResult, $aWritableDirsErrors); $aMandatoryExtensions = array('mysqli', 'iconv', 'simplexml', 'soap', 'hash', 'json', 'session', 'pcre', 'dom', 'zip'); $aOptionalExtensions = array('mcrypt' => 'Strong encryption will not be used.', 'ldap' => 'LDAP authentication will be disabled.'); asort($aMandatoryExtensions); // Sort the list to look clean ! ksort($aOptionalExtensions); // Sort the list to look clean ! $aExtensionsOk = array(); $aMissingExtensions = array(); $aMissingExtensionsLinks = array(); // First check the mandatory extensions foreach($aMandatoryExtensions as $sExtension) { if (extension_loaded($sExtension)) { $aExtensionsOk[] = $sExtension; } else { $aMissingExtensions[] = $sExtension; $aMissingExtensionsLinks[] = "$sExtension"; } } if (count($aExtensionsOk) > 0) { $aResult[] = new CheckResult(CheckResult::INFO, "Required PHP extension(s): ".implode(', ', $aExtensionsOk)."."); } if (count($aMissingExtensions) > 0) { $aResult[] = new CheckResult(CheckResult::ERROR, "Missing PHP extension(s): ".implode(', ', $aMissingExtensionsLinks)."."); } // Next check the optional extensions $aExtensionsOk = array(); $aMissingExtensions = array(); foreach($aOptionalExtensions as $sExtension => $sMessage) { if (extension_loaded($sExtension)) { $aExtensionsOk[] = $sExtension; } else { $aMissingExtensions[$sExtension] = $sMessage; } } if (count($aExtensionsOk) > 0) { $aResult[] = new CheckResult(CheckResult::INFO, "Optional PHP extension(s): ".implode(', ', $aExtensionsOk)."."); } if (count($aMissingExtensions) > 0) { foreach($aMissingExtensions as $sExtension => $sMessage) { $aResult[] = new CheckResult(CheckResult::WARNING, "Missing optional PHP extension: $sExtension. ".$sMessage); } } // Check some ini settings here if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4 { $sPhpIniFile = php_ini_loaded_file(); // Other included/scanned files if ($sFileList = php_ini_scanned_files()) { if (strlen($sFileList) > 0) { $aFiles = explode(',', $sFileList); foreach ($aFiles as $sFile) { $sPhpIniFile .= ', '.trim($sFile); } } } SetupPage::log("Info - php.ini file(s): '$sPhpIniFile'"); } else { $sPhpIniFile = 'php.ini'; } if (!ini_get('file_uploads')) { $aResult[] = new CheckResult(CheckResult::ERROR, "Files upload is not allowed on this server (file_uploads = ".ini_get('file_uploads').")."); } $sUploadTmpDir = self::GetUploadTmpDir(); if (empty($sUploadTmpDir)) { $sUploadTmpDir = '/tmp'; $aResult[] = new CheckResult(CheckResult::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)) { $aResult[] = new CheckResult(CheckResult::ERROR, "Temporary directory for files upload ($sUploadTmpDir) does not exist or cannot be read by PHP."); } else if (!is_writable($sUploadTmpDir)) { $aResult[] = new CheckResult(CheckResult::ERROR, "Temporary directory for files upload ($sUploadTmpDir) is not writable."); } else { SetupPage::log("Info - Temporary directory for files upload ($sUploadTmpDir) is writable."); } } if (!ini_get('upload_max_filesize')) { $aResult[] = new CheckResult(CheckResult::ERROR, "File upload is not allowed on this server (upload_max_filesize = ".ini_get('upload_max_filesize').")."); } $iMaxFileUploads = ini_get('max_file_uploads'); if (!empty($iMaxFileUploads) && ($iMaxFileUploads < 1)) { $aResult[] = new CheckResult(CheckResult::ERROR, "File upload is not allowed on this server (max_file_uploads = ".ini_get('max_file_uploads').")."); } $iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); $iMaxPostSize = utils::ConvertToBytes(ini_get('post_max_size')); if ($iMaxPostSize <= $iMaxUploadSize) { $aResult[] = new CheckResult(CheckResult::WARNING, "post_max_size (".ini_get('post_max_size').") in php.ini should be strictly greater than upload_max_filesize (".ini_get('upload_max_filesize').") otherwise you cannot upload files of the maximum size."); } SetupPage::log("Info - upload_max_filesize: ".ini_get('upload_max_filesize')); SetupPage::log("Info - post_max_size: ".ini_get('post_max_size')); SetupPage::log("Info - max_file_uploads: ".ini_get('max_file_uploads')); // Check some more ini settings here, needed for file upload if (function_exists('get_magic_quotes_gpc')) { if (@get_magic_quotes_gpc()) { $aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_gpc' is set to On. Please turn it Off in php.ini before continuing."); } } if (function_exists('magic_quotes_runtime')) { if (@magic_quotes_runtime()) { $aResult[] = new CheckResult(CheckResult::ERROR, "'magic_quotes_runtime' is set to On. Please turn it Off in php.ini before continuing."); } } $sMemoryLimit = trim(ini_get('memory_limit')); if (empty($sMemoryLimit)) { // On some PHP installations, memory_limit does not exist as a PHP setting! // (encountered on a 5.2.0 under Windows) // In that case, ini_set will not work, let's keep track of this and proceed anyway $aResult[] = new CheckResult(CheckResult::WARNING, "No memory limit has been defined in this instance of PHP"); } else { // Check that the limit will allow us to load the data // $iMemoryLimit = utils::ConvertToBytes($sMemoryLimit); if ($iMemoryLimit < self::MIN_MEMORY_LIMIT) { $aResult[] = new CheckResult(CheckResult::ERROR, "memory_limit ($iMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT."."); } else { SetupPage::log("Info - memory_limit is $iMemoryLimit, ok."); } } // Special case for APC if (extension_loaded('apc')) { $sAPCVersion = phpversion('apc'); $aResult[] = new CheckResult(CheckResult::INFO, "APC detected (version $sAPCVersion). The APC cache will be used to speed-up ".ITOP_APPLICATION."."); } // Special case Suhosin extension if (extension_loaded('suhosin')) { $sSuhosinVersion = phpversion('suhosin'); $aOk[] = "Suhosin extension detected (version $sSuhosinVersion)."; $iGetMaxValueLength = ini_get('suhosin.get.max_value_length'); if ($iGetMaxValueLength < self::SUHOSIN_GET_MAX_VALUE_LENGTH) { $aResult[] = new CheckResult(CheckResult::WARNING, "suhosin.get.max_value_length ($iGetMaxValueLength) is too small, the minimum value recommended to run the application is ".self::SUHOSIN_GET_MAX_VALUE_LENGTH."."); } else { SetupPage::log("Info - suhosin.get.max_value_length = $iGetMaxValueLength, ok."); } } if (function_exists('php_ini_loaded_file')) // PHP >= 5.2.4 { $sPhpIniFile = php_ini_loaded_file(); // Other included/scanned files if ($sFileList = php_ini_scanned_files()) { if (strlen($sFileList) > 0) { $aFiles = explode(',', $sFileList); foreach ($aFiles as $sFile) { $sPhpIniFile .= ', '.trim($sFile); } } } $aResult[] = new CheckResult(CheckResult::INFO, "Loaded php.ini files: $sPhpIniFile"); } // Check the configuration of the sessions persistence, since this is critical for the authentication if (ini_get('session.save_handler') == 'files') { $sSavePath = ini_get('session.save_path'); SetupPage::log("Info - session.save_path is: '$sSavePath'."); // According to the PHP documentation, the format can be /path/where/to_save_sessions or "N;/path/where/to_save_sessions" or "N;MODE;/path/where/to_save_sessions" $sSavePath = ltrim(rtrim($sSavePath, '"'), '"'); // remove surrounding quotes (if any) if (!empty($sSavePath)) { if (($iPos = strrpos($sSavePath, ';', 0)) !== false) { // The actual path is after the last semicolon $sSavePath = substr($sSavePath, $iPos+1); } if (!is_writable($sSavePath)) { $aResult[] = new CheckResult(CheckResult::ERROR, "The value for session.save_path ($sSavePath) is not writable for the web server. Make sure that PHP can actually save session variables. (Refer to the PHP documentation: http://php.net/manual/en/session.configuration.php#ini.session.save-path)"); } else { $aResult[] = new CheckResult(CheckResult::INFO, "The value for session.save_path ($sSavePath) is writable for the web server."); } } else { $aResult[] = new CheckResult(CheckResult::WARNING, "Empty path for session.save_path. Make sure that PHP can actually save session variables. (Refer to the PHP documentation: http://php.net/manual/en/session.configuration.php#ini.session.save-path)"); } } else { $aResult[] = new CheckResult(CheckResult::INFO, "session.save_handler is: '".ini_get('session.save_handler')."' (different from 'files')."); } return $aResult; } /** * Check that the selected modules meet their dependencies */ static function CheckSelectedModules($sSourceDir, $sExtensionDir, $aSelectedModules) { $aResult = array(); SetupPage::log('Info - CheckSelectedModules'); $aDirsToScan = array(APPROOT.$sSourceDir); $sExtensionsPath = APPROOT.$sExtensionDir; if (is_dir($sExtensionsPath)) { // if the extensions dir exists, scan it for additional modules as well $aDirsToScan[] = $sExtensionsPath; } require_once(APPROOT.'setup/modulediscovery.class.inc.php'); try { ModuleDiscovery::GetAvailableModules($aDirsToScan, true, $aSelectedModules); } catch(MissingDependencyException $e) { $aResult[] = new CheckResult(CheckResult::ERROR, $e->getMessage()); } return $aResult; } /** * Check that the backup could be executed * @param Page $oP The page used only for its 'log' method * @return array An array of CheckResults objects */ static function CheckBackupPrerequisites($sDestDir) { $aResult = array(); SetupPage::log('Info - CheckBackupPrerequisites'); // zip extension // if (!extension_loaded('zip')) { $sMissingExtensionLink = "zip"; $aResult[] = new CheckResult(CheckResult::ERROR, "Missing PHP extension: zip", $sMissingExtensionLink); } // availability of exec() // $aDisabled = explode(', ', ini_get('disable_functions')); SetupPage::log('Info - PHP functions disabled: '.implode(', ', $aDisabled)); if (in_array('exec', $aDisabled)) { $aResult[] = new CheckResult(CheckResult::ERROR, "The PHP exec() function has been disabled on this server"); } // availability of mysqldump $sMySQLBinDir = utils::ReadParam('mysql_bindir', '', true); if (empty($sMySQLBinDir)) { $sMySQLDump = 'mysqldump'; } else { SetupPage::log('Info - Found mysql_bindir: '.$sMySQLBinDir); $sMySQLDump = '"'.$sMySQLBinDir.'/mysqldump"'; } $sCommand = "$sMySQLDump -V 2>&1"; $aOutput = array(); $iRetCode = 0; exec($sCommand, $aOutput, $iRetCode); if ($iRetCode == 0) { $aResult[] = new CheckResult(CheckResult::INFO, "mysqldump is present: ".$aOutput[0]); } elseif ($iRetCode == 1) { $aResult[] = new CheckResult(CheckResult::ERROR, "mysqldump could not be found: ".implode(' ', $aOutput)." - Please make sure it is installed and in the path."); } else { $aResult[] = new CheckResult(CheckResult::ERROR, "mysqldump could not be executed (retcode=$iRetCode): Please make sure it is installed and in the path"); } foreach($aOutput as $sLine) { SetupPage::log('Info - mysqldump -V said: '.$sLine); } // check disk space // to do... evaluate how we can correlate the DB size with the size of the dump (and the zip!) // E.g. 2,28 Mb after a full install, giving a zip of 26 Kb (data = 26 Kb) // Example of query (DB without a suffix) //$sDBSize = "SELECT SUM(ROUND(DATA_LENGTH/1024/1024, 2)) AS size_mb FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = `$sDBName`"; return $aResult; } /** * Helper function to retrieve the system's temporary directory * Emulates sys_get_temp_dir if neeed (PHP < 5.2.1) * @return string Path to the system's temp directory */ static function GetTmpDir() { // try to figure out what is the temporary directory // prior to PHP 5.2.1 the function sys_get_temp_dir // did not exist if ( !function_exists('sys_get_temp_dir')) { if( $temp=getenv('TMP') ) return realpath($temp); if( $temp=getenv('TEMP') ) return realpath($temp); if( $temp=getenv('TMPDIR') ) return realpath($temp); $temp=tempnam(__FILE__,''); if (file_exists($temp)) { unlink($temp); return realpath(dirname($temp)); } return null; } else { return realpath(sys_get_temp_dir()); } } /** * Helper function to retrieve the directory where files are to be uploaded * @return string Path to the temp directory used for uploading files */ static function GetUploadTmpDir() { $sPath = ini_get('upload_tmp_dir'); if (empty($sPath)) { $sPath = self::GetTmpDir(); } return $sPath; } /** * Helper to recursively remove a directory */ public static function rrmdir($dir) { if ((strlen(trim($dir)) == 0) || ($dir == '/') || ($dir == '\\')) { throw new Exception("Attempting to delete directory: '$dir'"); } self::tidydir($dir); rmdir($dir); } /** * Helper to recursively cleanup a directory */ public static function tidydir($dir) { if ((strlen(trim($dir)) == 0) || ($dir == '/') || ($dir == '\\')) { throw new Exception("Attempting to delete directory: '$dir'"); } $aFiles = scandir($dir); // Warning glob('.*') does not seem to return the broken symbolic links, thus leaving a non-empty directory if ($aFiles !== false) { foreach($aFiles as $file) { if (($file != '.') && ($file != '..')) { if(is_dir($dir.'/'.$file)) { self::tidydir($dir.'/'.$file); rmdir($dir.'/'.$file); } else { if (!unlink($dir.'/'.$file)) { SetupPage::log("Warning - FAILED to remove file '$dir/$file'"); } else if (file_exists($dir.'/'.$file)) { SetupPage::log("Warning - FAILED to remove file '$dir/.$file'"); } } } } } } /** * Helper to build the full path of a new directory */ public static function builddir($dir) { $parent = dirname($dir); if(!is_dir($parent)) { self::builddir($parent); } if (!is_dir($dir)) { mkdir($dir); } } /** * Helper to copy a directory to a target directory, skipping .SVN files (for developer's comfort!) * Returns true if successfull */ public static function copydir($sSource, $sDest, $bUseSymbolicLinks = false) { if (is_dir($sSource)) { if (!is_dir($sDest)) { mkdir($sDest); } $aFiles = scandir($sSource); if(sizeof($aFiles) > 0 ) { foreach($aFiles as $sFile) { if ($sFile == '.' || $sFile == '..' || $sFile == '.svn') { // Skip continue; } if (is_dir($sSource.'/'.$sFile)) { // Recurse self::copydir($sSource.'/'.$sFile, $sDest.'/'.$sFile, $bUseSymbolicLinks); } else { if ($bUseSymbolicLinks) { if (function_exists('symlink')) { if (file_exists($sDest.'/'.$sFile)) { unlink($sDest.'/'.$sFile); } symlink($sSource.'/'.$sFile, $sDest.'/'.$sFile); } else { throw(new Exception("Error, cannot *copy* '$sSource/$sFile' to '$sDest/$sFile' using symbolic links, 'symlink' is not supported on this system.")); } } else { if (is_link($sDest.'/'.$sFile)) { unlink($sDest.'/'.$sFile); } copy($sSource.'/'.$sFile, $sDest.'/'.$sFile); } } } } return true; } elseif (is_file($sSource)) { if ($bUseSymbolicLinks) { if (function_exists('symlink')) { return symlink($sSource, $sDest); } else { throw(new Exception("Error, cannot *copy* '$sSource' to '$sDest' using symbolic links, 'symlink' is not supported on this system.")); } } else { return copy($sSource, $sDest); } } else { return false; } } /** * Helper to move a directory when the parent directory of the target dir cannot be written * To be used as alternative to rename() * Files/Subdirs of the source directory are moved one by one * Returns void */ public static function movedir($sSource, $sDest) { if (!is_dir($sSource)) { throw new Exception("movedir: the source directory '$sSource' is not a valid directory or cannot be read"); } if (!is_dir($sDest)) { self::builddir($sDest); } else { self::tidydir($sDest); } self::copydir($sSource, $sDest); self::tidydir($sSource); rmdir($sSource); /** * We have tried the following implementation (based on a rename/mv) * But this does not work on some OSes. * More info: https://bugs.php.net/bug.php?id=54097 * $aFiles = scandir($sSource); if(sizeof($aFiles) > 0) { foreach($aFiles as $sFile) { if ($sFile == '.' || $sFile == '..') { // Skip continue; } rename($sSource.'/'.$sFile, $sDest.'/'.$sFile); } } rmdir($sSource); */ } static function GetPreviousInstance($sDir) { $bFound = false; $sSourceDir = ''; $sSourceEnvironement = ''; $sConfigFile = ''; $aResult = array( 'found' => false, ); if (file_exists($sDir.'/config-itop.php')) { $sSourceDir = $sDir; $sSourceEnvironment = ''; $sConfigFile = $sDir.'/config-itop.php'; $aResult['found'] = true; } else if (file_exists($sDir.'/conf/production/config-itop.php')) { $sSourceDir = $sDir; $sSourceEnvironment = 'production'; $sConfigFile = $sDir.'/conf/production/config-itop.php'; $aResult['found'] = true; } if ($aResult['found']) { $oPrevConf = new Config($sConfigFile); $aResult = array( 'found' => true, 'source_dir' => $sSourceDir, 'source_environment' => $sSourceEnvironment, 'configuration_file' => $sConfigFile, 'db_server' => $oPrevConf->GetDBHost(), 'db_user' => $oPrevConf->GetDBUser(), 'db_pwd' => $oPrevConf->GetDBPwd(), 'db_name' => $oPrevConf->GetDBName(), 'db_prefix' => $oPrevConf->GetDBSubname(), ); } return $aResult; } static function CheckDiskSpace($sDir) { while(($f = @disk_free_space($sDir)) == false) { if ($sDir == dirname($sDir)) break; if ($sDir == '.') break; $sDir = dirname($sDir); } return $f; } static function HumanReadableSize($fBytes) { $aSizes = array('bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Hb'); $index = 0; while (($fBytes > 1000) && ($index < count($aSizes))) { $index++; $fBytes = $fBytes / 1000; } return sprintf('%.2f %s', $fBytes, $aSizes[$index]); } static function DisplayDBParameters($oPage, $bAllowDBCreation, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName = '') { $oPage->add('
Comparison of ".dirname($sBaseDir)."/modules against $sManifestFile:\n".print_r($aResults, true).""; return $aResults; } public static function CheckPortalFiles($sManifestFile, $sBaseDir) { $oXML = simplexml_load_file($sManifestFile); $aManifest = array(); foreach($oXML as $oFileInfo) { $aManifest[] = array('path' => (string)$oFileInfo->path, 'size' => (int)$oFileInfo->size, 'md5' => (string)$oFileInfo->md5); } $aResults = self::CheckDirAgainstManifest($sBaseDir, 'portal', $aManifest); // echo "
Comparison of ".dirname($sBaseDir)."/portal:\n".print_r($aResults, true).""; return $aResults; } public static function CheckApplicationFiles($sManifestFile, $sBaseDir) { $oXML = simplexml_load_file($sManifestFile); $aManifest = array(); foreach($oXML as $oFileInfo) { $aManifest[] = array('path' => (string)$oFileInfo->path, 'size' => (int)$oFileInfo->size, 'md5' => (string)$oFileInfo->md5); } $aResults = array('added' => array(), 'removed' => array(), 'modified' => array()); foreach(array('addons', 'core', 'dictionaries', 'js', 'application', 'css', 'pages', 'synchro', 'webservices') as $sDir) { $aTmp = self::CheckDirAgainstManifest($sBaseDir, $sDir, $aManifest); $aResults['added'] = array_merge($aResults['added'], $aTmp['added']); $aResults['modified'] = array_merge($aResults['modified'], $aTmp['modified']); $aResults['removed'] = array_merge($aResults['removed'], $aTmp['removed']); } // echo "
Comparison of ".dirname($sBaseDir)."/portal:\n".print_r($aResults, true).""; return $aResults; } public static function CheckVersion($sInstalledVersion, $sSourceDir) { $sManifestFilePath = self::GetVersionManifest($sInstalledVersion); if ($sSourceDir != '') { if (file_exists($sManifestFilePath)) { $aDMchanges = self::CheckDataModelFiles($sManifestFilePath, $sSourceDir); //$aPortalChanges = self::CheckPortalFiles($sManifestFilePath, $sSourceDir); //$aCodeChanges = self::CheckApplicationFiles($sManifestFilePath, $sSourceDir); //echo("Changes detected compared to $sInstalledVersion:
".print_r($aDMchanges, true).""); //echo("Changes detected compared to $sInstalledVersion:
".print_r($aDMchanges, true)."
".print_r($aPortalChanges, true)."
".print_r($aCodeChanges, true).""); return $aDMchanges; } else { return false; } } else { throw(new Exception("Cannot check version '$sInstalledVersion', no source directory provided to check the files.")); } } public static function GetVersionManifest($sInstalledVersion) { if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches)) { return APPROOT.'datamodels/'.$aMatches[1].'.x/manifest-'.$sInstalledVersion.'.xml'; } return false; } public static function CheckWritableDirs($aWritableDirs) { $aNonWritableDirs = array(); foreach($aWritableDirs as $sDir) { $sFullPath = APPROOT.$sDir; if (is_dir($sFullPath) && !is_writable($sFullPath)) { $aNonWritableDirs[APPROOT.$sDir] = new CheckResult(CheckResult::ERROR, "The directory '".APPROOT.$sDir."' exists but is not writable for the application."); } else if (file_exists($sFullPath) && !is_dir($sFullPath)) { $aNonWritableDirs[APPROOT.$sDir] = new CheckResult(CheckResult::ERROR, ITOP_APPLICATION." needs the directory '".APPROOT.$sDir."' to be writable. However file named '".APPROOT.$sDir."' already exists."); } else if (!is_dir($sFullPath) && !is_writable(APPROOT)) { $aNonWritableDirs[APPROOT.$sDir] = new CheckResult(CheckResult::ERROR, ITOP_APPLICATION." needs the directory '".APPROOT.$sDir."' to be writable. The directory '".APPROOT.$sDir."' does not exist and '".APPROOT."' is not writable, the application cannot create the directory '$sDir' inside it."); } } return $aNonWritableDirs; } public static function GetLatestDataModelDir() { $sBaseDir = APPROOT.'datamodels'; $aDirs = glob($sBaseDir.'/*', GLOB_MARK | GLOB_ONLYDIR); if ($aDirs !== false) { sort($aDirs); // Windows: there is a backslash at the end (though the path is made of slashes!!!) $sDir = basename(array_pop($aDirs)); $sRes = $sBaseDir.'/'.$sDir.'/'; return $sRes; } return false; } public static function GetCompatibleDataModelDir($sInstalledVersion) { if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches)) { $sMajorVersion = $aMatches[1]; $sDir = APPROOT.'datamodels/'.$sMajorVersion.'.x/'; if (is_dir($sDir)) { return $sDir; } } return false; } static public function GetDataModelVersion($sDatamodelDir) { $sVersionFile = $sDatamodelDir.'version.xml'; if (file_exists($sVersionFile)) { $oParams = new XMLParameters($sVersionFile); return $oParams->Get('version'); } return false; } /** * Returns an array of xml nodes describing the licences */ static public function GetLicenses() { $aLicenses = array(); foreach (glob(APPROOT.'setup/licenses/*.xml') as $sFile) { $oXml = simplexml_load_file($sFile); foreach($oXml->license as $oLicense) { $aLicenses[] = $oLicense; } } return $aLicenses; } } /** * Helper class to write rules (as PHP expressions) in the 'auto_select' field of the 'module' */ class SetupInfo { static $aSelectedModules = array(); /** * Called by the setup process to initializes the list of selected modules. Do not call this method * from an 'auto_select' rule * @param hash $aModules * @return void */ static function SetSelectedModules($aModules) { self::$aSelectedModules = $aModules; } /** * Returns true if a module is selected (as a consequence of the end-user's choices, * or because the module is hidden, or mandatory, or because of a previous auto_select rule) * @param string $sModuleId The identifier of the module (without the version number. Example: itop-config-mgmt) * @return boolean True if the module is already selected, false otherwise */ static function ModuleIsSelected($sModuleId) { return (array_key_exists($sModuleId, self::$aSelectedModules)); } }