Skip to content

Commit

Permalink
MDL-25314 improved prevention of output buffering + detection of misc…
Browse files Browse the repository at this point in the history
…onfigured servers

Scripts that do not want buffered output just define NO_OUTPUT_BUFFERING before including config.php.
The fileserving code now checks if the headers are already sent which detects misconfigured servers.
  • Loading branch information
skodak committed Nov 19, 2010
1 parent 6e4453f commit cbad562
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 255 deletions.
6 changes: 3 additions & 3 deletions admin/bloglevelupgrade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/// Create "blog" forums in each course and copy blog entries from these courses' participants in these forums

define('NO_OUTPUT_BUFFERING', true);

require_once('../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/blog/lib.php');
Expand Down Expand Up @@ -28,9 +30,7 @@

/// Turn off time limits, sometimes upgrades can be slow.

@set_time_limit(0);
@ob_implicit_flush(true);
while(@ob_end_flush());
set_time_limit(0);

$i = 0;

Expand Down
14 changes: 1 addition & 13 deletions admin/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@
// CLI via web interface, please do not use this hack elsewhere
define('CLI_SCRIPT', true);
define('WEB_CRON_EMULATED_CLI', 'defined'); // ugly ugly hack, do not use elsewhere please
define('NO_OUTPUT_BUFFERING', true);

require('../config.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->libdir.'/cronlib.php');

// disable compression, it would prevent closing of buffers
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
// no more headers and buffers
ob_implicit_flush(true);
while(ob_get_level()) {
if (!ob_end_clean()) {
// prevent infinite loop
break;
}
}

// extra safety
session_get_instance()->write_close();

Expand Down
14 changes: 1 addition & 13 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@
die;
}

// disable compression, it would prevent closing of buffers
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

// try to flush everything all the time
ob_implicit_flush(true);
while(ob_get_level()) {
if (!ob_end_clean()) {
// prevent infinite loop
break;
}
}
define('NO_OUTPUT_BUFFERING', true);

require('../config.php');
require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
Expand Down
4 changes: 2 additions & 2 deletions admin/multilangupgrade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/// Search and replace strings throughout all texts in the whole database

define('NO_OUTPUT_BUFFERING', true);

require_once('../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/adminlib.php');
Expand Down Expand Up @@ -33,8 +35,6 @@
/// Turn off time limits, sometimes upgrades can be slow.

@set_time_limit(0);
@ob_implicit_flush(true);
while(@ob_end_flush());

echo '<strong>Progress:</strong>';
$i = 0;
Expand Down
7 changes: 2 additions & 5 deletions admin/replace.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php
/// Search and replace strings throughout all texts in the whole database

define('NO_OUTPUT_BUFFERING', true);

require_once('../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/adminlib.php');

// workaround for problems with compression
if (ini_get('zlib.output_compression')) {
@ini_set('zlib.output_compression', 'Off');
}

admin_externalpage_setup('replace');

$search = optional_param('search', '', PARAM_RAW);
Expand Down
4 changes: 2 additions & 2 deletions admin/report/security/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// //
///////////////////////////////////////////////////////////////////////////

define('NO_OUTPUT_BUFFERING', true);

require_once('../../../config.php');
require_once($CFG->dirroot.'/'.$CFG->admin.'/report/security/lib.php');
require_once($CFG->libdir.'/adminlib.php');
Expand All @@ -49,8 +51,6 @@
echo $OUTPUT->heading(get_string('pluginname', 'report_security'));

echo '<div id="timewarning">'.get_string('timewarning', 'report_security').'</div>';
while(@ob_end_flush());
@flush();

$strok = '<span class="statusok">'.get_string('statusok', 'report_security').'</span>';
$strinfo = '<span class="statusinfo">'.get_string('statusinfo', 'report_security').'</span>';
Expand Down
17 changes: 2 additions & 15 deletions admin/report/unittest/dbtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@
* @package SimpleTestEx
*/

/** */
define('NO_OUTPUT_BUFFERING', true);

require_once(dirname(__FILE__).'/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/simpletestcoveragelib.php');
require_once('ex_simple_test.php');
require_once('ex_reporter.php');

// disable compression, it would prevent closing of buffers
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

// try to flush everything all the time
ob_implicit_flush(true);
while(ob_get_level()) {
if (!ob_end_clean()) {
// prevent infinite loop
break;
}
}

$showpasses = optional_param('showpasses', false, PARAM_BOOL);
$codecoverage = optional_param('codecoverage', false, PARAM_BOOL);
$selected = optional_param('selected', array(), PARAM_INT);
Expand Down
17 changes: 2 additions & 15 deletions admin/report/unittest/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@
* @package SimpleTestEx
*/

/** */
define('NO_OUTPUT_BUFFERING', true);

require_once(dirname(__FILE__).'/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/simpletestcoveragelib.php');
require_once('ex_simple_test.php');
require_once('ex_reporter.php');

// disable compression, it would prevent closing of buffers
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

// try to flush everything all the time
ob_implicit_flush(true);
while(ob_get_level()) {
if (!ob_end_clean()) {
// prevent infinite loop
break;
}
}

// Always run the unit tests in developer debug mode.
$CFG->debug = DEBUG_DEVELOPER;
error_reporting($CFG->debug);
Expand Down
2 changes: 1 addition & 1 deletion calendar/export_execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
}

//IE compatibility HACK!
if(ini_get('zlib.output_compression')) {
if (ini_get_bool('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
$string['cannotsavefile'] = 'Cannot save the file "{$a}"!';
$string['cannotsavemd5file'] = 'Cannot save md5 file';
$string['cannotsavezipfile'] = 'Cannot save ZIP file';
$string['cannotservefile'] = 'Can not serve file - server configuration problem.';
$string['cannotsetparentforcatoritem'] = 'Cannot set parent for category or course item!';
$string['cannotsetpassword'] = 'Could not set user password!';
$string['cannotsetprefgrade'] = 'Could not set preference aggregationview to {$a} for this grade category';
Expand Down
2 changes: 0 additions & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5919,8 +5919,6 @@ function db_replace($search, $replace) {

/// Turn off time limits, sometimes upgrades can be slow.
@set_time_limit(0);
@ob_implicit_flush(true);
while(@ob_end_flush());

if (!$tables = $DB->get_tables() ) { // No tables yet at all.
return false;
Expand Down
Loading

0 comments on commit cbad562

Please sign in to comment.