Skip to content

Commit

Permalink
MDL-10275 added fatal PHP config setting test on each page, replaces …
Browse files Browse the repository at this point in the history
…some tests done in installer
  • Loading branch information
skodak committed Feb 1, 2009
1 parent b3d960e commit fbf2c91
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
11 changes: 3 additions & 8 deletions admin/index.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/admin.php
Expand Up @@ -396,6 +396,8 @@
$string['experimentalsettings'] = 'Experimental settings';
$string['extendedusernamechars'] = 'Allow extended characters in usernames';
$string['extrauserselectorfields'] = 'When selecting users, search and display';
$string['fatalsessionautostart'] = '<p>Serious configuration error detected, please notify server administrator.<p><p> To operate properly, Moodle requires that administrator changes PHP settings.</p><p><code>session.auto_start</code> must be set to <code>off</code>.</p><p>This setting is controlled by editing <code>php.ini</code>, Apache/IIS <br />configuration or <code>.htaccess</code> file on the server.</p>';
$string['fatalmagicquotesruntime'] = '<p>Serious configuration error detected, please notify server administrator.<p><p> To operate properly, Moodle requires that administrator changes PHP settings.</p><p><code>magic_quotes_runtime</code> must be set to <code>off</code>.</p><p>This setting is controlled by editing <code>php.ini</code>, Apache/IIS <br />configuration or <code>.htaccess</code> file on the server.</p>';
$string['filecreated'] = 'New file created';
$string['filestoredin'] = 'Save file into folder :';
$string['filestoredinhelp'] = 'Where the file will be stored';
Expand Down
4 changes: 1 addition & 3 deletions lib/adminlib.php
Expand Up @@ -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;
}
}
Expand Down
9 changes: 3 additions & 6 deletions lib/setup.php
Expand Up @@ -86,12 +86,6 @@
/** 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;
Expand Down Expand Up @@ -170,6 +164,9 @@
/// 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();

Expand Down
18 changes: 18 additions & 0 deletions lib/setuplib.php
Expand Up @@ -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
Expand Down

0 comments on commit fbf2c91

Please sign in to comment.