From: skodak Date: Sun, 1 Feb 2009 13:37:42 +0000 (+0000) Subject: MDL-10275 added fatal PHP config setting test on each page, replaces some tests done... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fbf2c91e439b570f1f78990953227348da385452;p=moodle.git MDL-10275 added fatal PHP config setting test on each page, replaces some tests done in installer --- diff --git a/admin/index.php b/admin/index.php index 6400fb399c..2419c3ede1 100644 --- a/admin/index.php +++ b/admin/index.php @@ -8,9 +8,9 @@ /// Check that PHP is of a sufficient version /// Moved here because older versions do not allow while(@ob_end_clean()); - if (version_compare(phpversion(), "5.2.4") < 0) { + if (version_compare(phpversion(), "5.2.8") < 0) { $phpversion = phpversion(); - echo "Sorry, Moodle requires PHP 5.2.4 or later (currently using version $phpversion)"; + echo "Sorry, Moodle requires PHP 5.2.8 or later (currently using version $phpversion)"; die; } @@ -405,9 +405,8 @@ /// setup critical warnings before printing admin tree block $insecuredataroot = is_dataroot_insecure(true); - $register_globals_enabled = ini_get_bool('register_globals'); - $SESSION->admin_critical_warning = ($register_globals_enabled || $insecuredataroot==INSECURE_DATAROOT_ERROR); + $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); $adminroot = admin_get_root(); @@ -433,10 +432,6 @@ print_box(get_string("upgrade$CFG->upgrade", "admin", "$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php")); } - if ($register_globals_enabled) { - print_box(get_string('globalswarning', 'admin'), 'generalbox adminerror'); - } - if ($insecuredataroot == INSECURE_DATAROOT_WARNING) { print_box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'generalbox adminwarning'); } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) { diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index a8937cbe7e..9ceadd5f44 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -396,6 +396,8 @@ $string['experimental'] = 'Experimental'; $string['experimentalsettings'] = 'Experimental settings'; $string['extendedusernamechars'] = 'Allow extended characters in usernames'; $string['extrauserselectorfields'] = 'When selecting users, search and display'; +$string['fatalsessionautostart'] = '

Serious configuration error detected, please notify server administrator.

To operate properly, Moodle requires that administrator changes PHP settings.

session.auto_start must be set to off.

This setting is controlled by editing php.ini, Apache/IIS
configuration or .htaccess file on the server.

'; +$string['fatalmagicquotesruntime'] = '

Serious configuration error detected, please notify server administrator.

To operate properly, Moodle requires that administrator changes PHP settings.

magic_quotes_runtime must be set to off.

This setting is controlled by editing php.ini, Apache/IIS
configuration or .htaccess file on the server.

'; $string['filecreated'] = 'New file created'; $string['filestoredin'] = 'Save file into folder :'; $string['filestoredinhelp'] = 'Where the file will be stored'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 874c3b4919..8ce7df206c 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -244,9 +244,7 @@ function admin_critical_warnings_present() { if (!isset($SESSION->admin_critical_warning)) { $SESSION->admin_critical_warning = 0; - if (ini_get_bool('register_globals')) { - $SESSION->admin_critical_warning = 1; - } else if (is_dataroot_insecure(true) === INSECURE_DATAROOT_ERROR) { + if (is_dataroot_insecure(true) === INSECURE_DATAROOT_ERROR) { $SESSION->admin_critical_warning = 1; } } diff --git a/lib/setup.php b/lib/setup.php index 84d303e033..12cbb1eee2 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -86,12 +86,6 @@ global $FULLSCRIPT; /** Relative moodle script path "/course/view.php" */ global $SCRIPT; -/// First try to detect some attacks on older buggy PHP versions - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) { - die('Fatal: Illegal GLOBALS overwrite attempt detected!'); - } - - if (!isset($CFG->wwwroot)) { trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.'); die; @@ -170,6 +164,9 @@ global $SCRIPT; /// set handler for uncought exceptions - equivalent to print_error() call set_exception_handler('default_exception_handler'); +/// make sure PHP is not severly misconfigured + setup_validate_php_configuration(); + /// Connect to the database setup_DB(); diff --git a/lib/setuplib.php b/lib/setuplib.php index d5def40508..fd92ed0c79 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -84,6 +84,24 @@ function default_exception_handler($ex) { } } +/** + * This function verifies the sanity of PHP configuration + * and stops execution if anything critical found. + */ +function setup_validate_php_configuration() { + // this must be very fast - no slow checks here!!! + + if (ini_get_bool('register_globals')) { + print_error('globalswarning', 'admin'); + } + if (ini_get_bool('session.auto_start')) { + print_error('sessionautostartwarning', 'admin'); + } + if (ini_get_bool('magic_quotes_runtime')) { + print_error('fatalmagicquotesruntime', 'admin'); + } +} + /** * Initialises $FULLME and friends. * @return void