3 require_once('../config.php');
5 define('SEVERITY_NOTICE', 'notice');
6 define('SEVERITY_ANNOYANCE', 'annoyance');
7 define('SEVERITY_SIGNIFICANT', 'significant');
8 define('SEVERITY_CRITICAL', 'critical');
12 error('Only the admin can use this page');
16 $stradmin = get_string('administration');
17 $strhealthcenter = get_string('healthcenter');
19 print_header($site->shortname
.': '.$strhealthcenter, $site->fullname
,
20 '<a href="index.php">'.$stradmin.'</a> -> '.$strhealthcenter);
23 <style type="text/css">
24 div#healthnoproblemsfound {
28 border: 1px black solid;
29 -moz-border-radius: 6px;
35 dl.critical dt, dl.critical dd {
36 background-color: #a71501;
38 dl.significant dt, dl.significant dd {
39 background-color: #d36707;
41 dl.annoyance dt, dl.annoyance dd {
42 background-color: #dba707;
44 dl.notice dt, dl.notice dd {
45 background-color: #e5db36;
47 dt.solution, dd.solution, div#healthnoproblemsfound {
48 background-color: #5BB83E !important;
50 dl.healthissues dt, dl.healthissues dd {
53 border: 1px black solid;
58 padding-bottom: 0.5em;
65 dl.healthissues dd form {
69 form#healthformreturn {
84 $solution = optional_param('solution', NULL);
86 if(!empty($solution) && class_exists($solution)) {
87 health_print_solution($solution);
90 health_find_problems();
97 function health_find_problems() {
99 print_heading(get_string('healthcenter'));
102 SEVERITY_CRITICAL
=> array(),
103 SEVERITY_SIGNIFICANT
=> array(),
104 SEVERITY_ANNOYANCE
=> array(),
105 SEVERITY_NOTICE
=> array(),
109 for($i = 1; $i < 1000000; ++
$i) {
110 $classname = sprintf('problem_%06d', $i);
111 if(!class_exists($classname)) {
114 $problem = new $classname;
115 if($problem->exists()) {
116 $severity = $problem->severity();
117 $issues[$severity][$classname] = array(
118 'severity' => $severity,
119 'description' => $problem->description(),
120 'title' => $problem->title()
128 echo '<div id="healthnoproblemsfound">';
129 echo get_string('healthnoproblemsfound');
133 print_heading(get_string('healthproblemsdetected'));
134 $severities = array(SEVERITY_CRITICAL
, SEVERITY_SIGNIFICANT
, SEVERITY_ANNOYANCE
, SEVERITY_NOTICE
);
135 foreach($severities as $severity) {
136 if(!empty($issues[$severity])) {
137 echo '<dl class="healthissues '.$severity.'">';
138 foreach($issues[$severity] as $classname => $data) {
139 echo '<dt id="'.$classname.'">'.$data['title'].'</dt>';
140 echo '<dd>'.$data['description'];
141 echo '<form action="health.php#solution" method="get">';
142 echo '<input type="hidden" name="solution" value="'.$classname.'" /><input type="submit" value="'.get_string('viewsolution').'" />';
151 function health_print_solution($classname) {
152 $problem = new $classname;
154 'title' => $problem->title(),
155 'severity' => $problem->severity(),
156 'description' => $problem->description(),
157 'solution' => $problem->solution()
160 print_heading(get_string('healthcenter'));
161 print_heading(get_string('healthproblemsolution'));
162 echo '<dl class="healthissues '.$data['severity'].'">';
163 echo '<dt>'.$data['title'].'</dt>';
164 echo '<dd>'.$data['description'].'</dd>';
165 echo '<dt id="solution" class="solution">'.get_string('healthsolution').'</dt>';
166 echo '<dd class="solution">'.$data['solution'].'</dd></dl>';
167 echo '<form id="healthformreturn" action="health.php#'.$classname.'" method="get">';
168 echo '<input type="submit" value="'.get_string('healthreturntomain').'" />';
179 function severity() {
180 return SEVERITY_NOTICE
;
182 function description() {
185 function solution() {
190 class problem_000001
extends problem_base
{
192 return 'Invalid value for $CFG->dirroot';
196 $dirroot = dirname(realpath('../index.php'));
197 if (!empty($dirroot) && $dirroot != $CFG->dirroot
) {
202 function severity() {
203 return SEVERITY_CRITICAL
;
205 function description() {
207 return 'Your <strong>config.php</strong> file contains the setting <strong>$CFG->dirroot = "'.$CFG->dirroot
.'"</strong>, which is incorrect. Unless you correct this problem, Moodle will not function correctly, if at all.';
209 function solution() {
211 $dirroot = dirname(realpath('../index.php'));
212 return 'You need to edit your <strong>config.php</strong> file. Find the line which reads <pre>$CFG->dirroot = \''.$CFG->dirroot
.'\';</pre> and change it to read <pre>$CFG->dirroot = \''.$dirroot.'\'</pre>';
216 class problem_000002
extends problem_base
{
218 return 'Extra characters at the end of config.php';
221 // [pj] When the requirements are raised to PHP 4.3.0 this will be file_get_contents()
222 if($fp = @fopen
('../config.php', 'r')) {
223 $contents = fread($fp, 16384); // 16K should be enough
224 $ending = substr($contents, -2);
226 if($ending == '?>') {
233 function severity() {
234 return SEVERITY_SIGNIFICANT
;
236 function description() {
237 return 'Your Moodle configuration file, config.php, contains some characters after the closing PHP tag (?>). This could cause Moodle to exhibit several kinds of problems and should be fixed.';
239 function solution() {
241 return 'You need to edit <strong>'.$CFG->dirroot
.'/config.php</strong> and remove all characters (including spaces and returns) after the ending ?> tag. These two characters should be the very last in that file.';
245 class problem_000003
extends problem_base
{
247 return '$CFG->dataroot does not exist or does not have write permissions';
251 if(!is_dir($CFG->dataroot
) ||
!is_writable($CFG->dataroot
)) {
256 function severity() {
257 return SEVERITY_SIGNIFICANT
;
259 function description() {
261 return 'Your <strong>config.php</strong> says that your "data root" directory is <strong>'.$CFG->dataroot
.'</strong>. However, this directory either does not exist or cannot be written to by Moodle. This means that a variety of problems will be present, such as users not being able to log in and not being able to upload any files. It is imperative that you address this problem for Moodle to work correctly.';
263 function solution() {
265 return 'First of all, make sure that the directory <strong>'.$CFG->dataroot
.'</strong> exists. If the directory does exist, then you must make sure that Moodle is able to write to it. Contact your web server administrator and request that he gives write permissions for that directory to the user that the web server process is running as.';
269 class problem_000004
extends problem_base
{
271 return 'cron.php is not set up to run automatically';
275 $lastcron = get_field_sql('SELECT max(lastcron) FROM '.$CFG->prefix
.'modules');
276 return (time() - $lastcron > 3600 * 24);
278 function severity() {
279 return SEVERITY_SIGNIFICANT
;
281 function description() {
282 return 'The cron.php mainenance script has not been run in the past 24 hours. This probably means that your server is not configured to automatically run this script in regular time intervals. If this is the case, then Moodle will mostly work as it should but some operations (notably sending email to users) will not be carried out at all.';
284 function solution() {
286 return 'For detailed instructions on how to enable cron, see <a href="'.$CFG->wwwroot
.'/doc/?file=install.html#cron">this section</a> of the installation manual.';
290 class problem_000005
extends problem_base
{
292 return 'PHP: session.auto_start is enabled';
295 return ini_get_bool('session.auto_start');
297 function severity() {
298 return SEVERITY_CRITICAL
;
300 function description() {
301 return 'Your PHP configuration includes an enabled setting, session.auto_start, that <strong>must be disabled</strong> in order for Moodle to work correctly. Notable symptoms arising from this misconfiguration include fatal errors and/or blank pages when trying to log in.';
303 function solution() {
305 return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>session.auto_start = 1</pre> and change it to <pre>session.auto_start = 0</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot
.'/.htaccess</strong> to contain this line: <pre>php_value session.auto_start "0"</pre></li></ol>';
309 class problem_000006
extends problem_base
{
311 return 'PHP: magic_quotes_runtime is enabled';
314 return (ini_get_bool('magic_quotes_runtime'));
316 function severity() {
317 return SEVERITY_SIGNIFICANT
;
319 function description() {
320 return 'Your PHP configuration includes an enabled setting, magic_quotes_runtime, that <strong>must be disabled</strong> in order for Moodle to work correctly. Notable symptoms arising from this misconfiguration include strange display errors whenever a text field that includes single or double quotes is processed.';
322 function solution() {
324 return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>magic_quotes_runtime = On</pre> and change it to <pre>magic_quotes_runtime = Off</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot
.'/.htaccess</strong> to contain this line: <pre>php_value magic_quotes_runtime "Off"</pre></li></ol>';
328 class problem_000007
extends problem_base
{
330 return 'PHP: file_uploads is disabled';
333 return !ini_get_bool('file_uploads');
335 function severity() {
336 return SEVERITY_SIGNIFICANT
;
338 function description() {
339 return 'Your PHP configuration includes a disabled setting, file_uploads, that <strong>must be enabled</strong> to let Moodle offer its full functionality. Until this setting is enabled, it will not be possible to upload any files into Moodle. This includes, for example, course content and user pictures.';
341 function solution() {
343 return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>file_uploads = Off</pre> and change it to <pre>file_uploads = On</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot
.'/.htaccess</strong> to contain this line: <pre>php_value file_uploads "On"</pre></li></ol>';
347 class problem_000008
extends problem_base
{
349 return 'PHP: memory_limit cannot be controlled by Moodle';
352 $memlimit = @ini_get
('memory_limit');
353 if(empty($memlimit)) {
354 // PHP not compiled with memory limits, this means that it's
355 // probably limited to 8M so we have a problem...
358 // Otherwise, raise_memory_limit in setup.php will do the trick
361 function severity() {
362 return SEVERITY_ANNOYANCE
;
364 function description() {
365 return 'The settings for PHP on your server do not allow a script to request more memory during its execution. This means that most likely there is a hard limit of 8MB for each script. It is possible that certain operations within Moodle will require more than this amount in order to complete successfully, especially if there are lots of data to be processed. Therefore, it is recommended that you contact your server administrator to address this issue.';
367 function solution() {
369 return 'We need a good solution here. Enabling memory limit control means recompiling PHP... maybe this should be SEVERITY_NOTICE instead of SEVERITY_ANNOYANCE?';
373 class problem_000009
extends problem_base
{
375 return 'SQL: using account without password';
379 return empty($CFG->dbpass
);
381 function severity() {
382 return SEVERITY_CRITICAL
;
384 function description() {
386 return 'The user account your are connecting to the database server with is set up without a password. This is a very big security risk and is only somewhat lessened if your database is configured to not accept connections from any hosts other than the server Moodle is running on. Unless you use a strong password to connect to the database, you risk unauthorized access to and manipulation of your data.'.($CFG->dbuser
!= 'root'?
'':' <strong>This is especially alarming because such access to the database would be as the superuser (root)!</strong>');
388 function solution() {
390 return 'You should change the password of the user <strong>'.$CFG->dbuser
.'</strong> both in your database and in your Moodle <strong>config.php</strong> immediately!'.($CFG->dbuser
!= 'root'?
'':' It would also be a good idea to change the user account from root to something else, because this would lessen the impact in the event that your database is compromised anyway.');
394 class problem_000010
extends problem_base
{
396 return 'Uploaded files: slasharguments disabled or not working';
399 if (!$this->is_enabled()) {
402 if ($this->status() < 1) {
407 function severity() {
408 if ($this->is_enabled() and $this->status() == 0) {
409 return SEVERITY_SIGNIFICANT
;
411 return SEVERITY_ANNOYANCE
;
414 function description() {
416 $desc = 'Slasharguments are needed for relative linking in uploaded resources:<ul>';
417 if (!$this->is_enabled()) {
418 $desc .= '<li>slasharguments are <strong>disabled</strong> in Moodle configuration</li>';
420 $desc .= '<li>slasharguments are enabled in Moodle configuration</li>';
422 if ($this->status() == -1) {
423 $desc .= '<li>can not run automatic test, you can verify it <a href="'.$CFG->wwwroot
.'/file.php/testslasharguments" target="_blank">here</a></li>';
424 } else if ($this->status() == 0) {
425 $desc .= '<li>slashargument test <strong>failed</strong>, please check server configuration</li>';
427 $desc .= '<li>slashargument test passed</li>';
432 function solution() {
434 $enabled = $this->is_enabled();
435 $status = $this->status();
437 if ($enabled and ($status == 0)) {
438 $solution .= 'Slasharguments are enabled, but the test failed. Please disable slasharguments in Moodle configuration or fix the server configuration.<hr />';
439 } else if ((!$enabled) and ($status == 0)) {
440 $solution .= 'Slasharguments are disabled and the test failed. You may try to fix the server configuration.<hr />';
441 } else if ($enabled and ($status == -1)) {
442 $solution .= 'Slasharguments are enabled, <a href="'.$CFG->wwwroot
.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
443 } else if ((!$enabled) and ($status == -1)) {
444 $solution .= 'Slasharguments are disabled, <a href="'.$CFG->wwwroot
.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
445 } else if ((!$enabled) and ($status > 0)) {
446 $solution .= 'Slasharguments are disabled though the iternal test is OK. You should enable slasharguments in Moodle configuration.';
447 } else if ($enabled and ($status > 0)) {
448 $solution .= 'Congratulations - everything seems OK now :-D';
451 $solution .= '<p>IIS:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li><li>do NOT enable AllowPathInfoForScriptMappings !!!</li><li>slasharguments may not work when using ISAPI and PHP 4.3.10 and older</li></ul></p>';
452 $solution .= '<p>Apache 1:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
453 $solution .= '<p>Apache 2:<ul><li>you must add <code>AcceptPathInfo on</code> to php.ini or .htaccess</li><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
457 function is_enabled() {
459 return !empty($CFG->slasharguments
);
463 $handle = @fopen
($CFG->wwwroot
.'/file.php?file=/testslasharguments', "r");
464 $contents = trim(@fread
($handle, 7));
466 if ($contents != 'test -1') {
469 $handle = @fopen
($CFG->wwwroot
.'/file.php/testslasharguments', "r");
470 $contents = trim(@fread
($handle, 6));
473 case 'test 1': return 1;
474 case 'test 2': return 2;
480 class problem_000011
extends problem_base
{
482 return 'Session errors detected';
486 return isset($CFG->session_error_counter
);
488 function severity() {
489 return SEVERITY_ANNOYANCE
;
491 function description() {
493 if (isset($CFG->session_error_counter
)) {
494 return 'Session problems were detected. Total count: '.$CFG->session_error_counter
;
496 return 'No session errors detected.';
499 function solution() {
501 if (isset($_GET['resetsesserrorcounter'])) {
502 if (get_field('config', 'name', 'name', 'session_error_counter')) {
503 delete_records('config', 'name', 'session_error_counter');
505 return 'Error counter was cleared.';
507 return '<p>Session errors can be caused by:<ul><li>unresolved problem in server software (aka random switching of users),</li><li>blocked or modified cookies,</li><li>deleting of active session files.</li></ul></p><p><a href="'.me().'&resetsesserrorcounter=1">Reset counter.</a></p>';
513 class problem_00000x
extends problem_base
{
520 function severity() {
521 return SEVERITY_SIGNIFICANT
;
523 function description() {
526 function solution() {
536 session.save_path -- it doesn't really matter because we are already IN a session, right?