From 2c07499a83392d25be43e1d4a278c316ee1962ec Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Thu, 18 Feb 2010 20:19:03 +0200 Subject: [PATCH] Feature #272 - Adding a simple protection against re-installing the system. --- main/inc/global_error_message.inc.php | 11 ++++++++++ main/install/index.php | 8 +++++++ main/install/install.lib.php | 30 +++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/main/inc/global_error_message.inc.php b/main/inc/global_error_message.inc.php index 63691c9aae..6d650de474 100755 --- a/main/inc/global_error_message.inc.php +++ b/main/inc/global_error_message.inc.php @@ -23,6 +23,7 @@ $SectionSystemRequirementsProblem = 'System requirements problem'; $SectionInstallation = 'Installation'; $SectionDatabaseUnavailable = 'Database is unavailable'; $SectionTechnicalIssues = 'Technical issues'; +$SectionProtection = 'Protection measure'; // Error code. $ErrorCode = 'Error code'; @@ -41,6 +42,10 @@ $InstallationDescription = 'Click to INSTALL Chamilo %s or read the installation $DatabaseUnavailableTitle = 'Database is unavailable'; $DatabaseUnavailableDescription = 'This portal is currently experiencing database issues. Please report this to the portal administrator. Thank you for your help.'; +// Error code 6. +$AlreadyInstalledTitle = 'Chamilo has already been installed'; +$AlreadyInstalledDescription = 'The system has already been installed. In order its content to be protected you are not allowed to start the installation script again.'; + // Unspecified error. $TechnicalIssuesTitle = 'Technical issues'; $TechnicalIssuesDescription = 'This portal is currently experiencing technical issues. Please report this to the portal administrator. Thank you for your help.'; @@ -128,6 +133,12 @@ if (is_int($global_error_code) && $global_error_code > 0) { $global_error_message['description'] = $DatabaseUnavailableDescription; break; + case 6: + $global_error_message['section'] = $SectionProtection; + $global_error_message['title'] = $AlreadyInstalledTitle; + $global_error_message['description'] = $AlreadyInstalledDescription; + break; + default: $global_error_message['section'] = $SectionTechnicalIssues; $global_error_message['title'] = $TechnicalIssuesTitle; diff --git a/main/install/index.php b/main/install/index.php index e816c49b79..d26b22966d 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -132,6 +132,14 @@ $new_version = '1.8.7'; $new_version_stable = false; $new_version_major = true; +// A protection measure for already installed systems. +if (is_already_installed_system()) { + // The system has already been installed, so block re-installation. + $global_error_code = 6; + require '../inc/global_error_message.inc.php'; + die(); +} + /* ============================================================================== STEP 1 : INITIALIZES FORM VARIABLES IF IT IS THE FIRST VISIT diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 26775ec8ee..829642c537 100644 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -29,6 +29,32 @@ define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php'); ============================================================================== */ +/** + * This function detects whether the system has been already installed. + * It should be used for prevention from second running the installation + * script and as a result - destroying a production system. + * @return bool The detected result; + * @author Ivan Tcholakov, 2010; + */ +function is_already_installed_system() { + global $new_version; + + if (empty($new_version)) { + return true; + } + + $current_config_file = str_replace('\\', '/', realpath('../inc/conf/configuration.php')); + if (!file_exists($current_config_file)) { + return false; + } + require $current_config_file; + + // Careful, if/when the name 'dokeos_version' is changed. Check this then. + $current_version = $_configuration['dokeos_version']; + + return empty($current_version) ? false : ($new_version == $current_version); +} + /** * This function checks if a php extension exists or not and returns an HTML status string. * @@ -396,7 +422,7 @@ function get_config_param($param, $updatePath = '') { if (empty($updatePath) && !empty($_POST['updatePath'])) { $updatePath = $_POST['updatePath']; } - $updatePath = realpath($updatePath).'/'; + $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath))); $updateFromInstalledVersionFile = ''; if (empty($updateFromConfigFile)) { @@ -1696,7 +1722,7 @@ function display_after_install_message($installType, $nbr_courses) { - MAX_COURSE_TRANSFER): ?> + MAX_COURSE_TRANSFER): ?>

: ', ''); ?>