First rough version of the "Health Center", so people can play around.
[moodle.git] / admin / health.php
CommitLineData
527d9cdd 1<?php // $Id$
2 // config.php - allows admin to edit all configuration variables
3
4 require_once('../config.php');
5
6 define('SEVERITY_NOTICE', 'notice');
7 define('SEVERITY_ANNOYANCE', 'annoyance');
8 define('SEVERITY_SIGNIFICANT', 'significant');
9 define('SEVERITY_CRITICAL', 'critical');
10
11 require_login();
12 if (!isadmin()) {
13 error('Only the admin can use this page');
14 }
15
16 $site = get_site();
17 $stradmin = get_string('administration');
18 $strhealthcenter = get_string('healthcenter');
19
20 print_header($site->shortname.': '.$strhealthcenter, $site->fullname,
21 '<a href="index.php">'.$stradmin.'</a> -> '.$strhealthcenter);
22
23echo <<<STYLES
24<style type="text/css">
25div#healthnoproblemsfound {
26 width: 60%;
27 margin: auto;
28 padding: 1em;
29 border: 1px black solid;
30 -moz-border-radius: 6px;
31}
32dl.healthissues {
33 width: 60%;
34 margin: auto;
35}
36dl.critical dt, dl.critical dd {
37 background-color: #a71501;
38}
39dl.significant dt, dl.significant dd {
40 background-color: #d36707;
41}
42dl.annoyance dt, dl.annoyance dd {
43 background-color: #dba707;
44}
45dl.notice dt, dl.notice dd {
46 background-color: #e5db36;
47}
48dt.solution, dd.solution, div#healthnoproblemsfound {
49 background-color: #5BB83E !important;
50}
51dl.healthissues dt, dl.healthissues dd {
52 margin: 0px;
53 padding: 1em;
54 border: 1px black solid;
55}
56dl.healthissues dt {
57 font-weight: bold;
58 border-bottom: none;
59 padding-bottom: 0.5em;
60}
61dl.healthissues dd {
62 border-top: none;
63 padding-top: 0.5em;
64 margin-bottom: 10px;
65}
66dl.healthissues dd form {
67 margin-top: 0.5em;
68 text-align: right;
69}
70form#healthformreturn {
71 text-align: center;
72 margin: 2em;
73}
74dd.solution p {
75 padding: 0px;
76 margin: 1em 0px;
77}
78dd.solution li {
79 margin-top: 1em;
80}
81
82</style>
83STYLES;
84
85 $solution = optional_param('solution', NULL);
86
87 if(!empty($solution) && class_exists($solution)) {
88 health_print_solution($solution);
89 }
90 else {
91 health_find_problems();
92 }
93
94
95 print_footer();
96
97
98function health_find_problems() {
99
100 print_heading(get_string('healthcenter'));
101
102 $issues = array(
103 SEVERITY_CRITICAL => array(),
104 SEVERITY_SIGNIFICANT => array(),
105 SEVERITY_ANNOYANCE => array(),
106 SEVERITY_NOTICE => array(),
107 );
108 $problems = 0;
109
110 for($i = 1; $i < 1000000; ++$i) {
111 $classname = sprintf('problem_%06d', $i);
112 if(!class_exists($classname)) {
113 break;
114 }
115 $problem = new $classname;
116 if($problem->exists()) {
117 $severity = $problem->severity();
118 $issues[$severity][$classname] = array(
119 'severity' => $severity,
120 'description' => $problem->description(),
121 'title' => $problem->title()
122 );
123 ++$problems;
124 }
125 unset($problem);
126 }
127
128 if($problems == 0) {
129 echo '<div id="healthnoproblemsfound">';
130 echo get_string('healthnoproblemsfound');
131 echo '</div>';
132 }
133 else {
134 print_heading(get_string('healthproblemsdetected'));
135 $severities = array(SEVERITY_CRITICAL, SEVERITY_SIGNIFICANT, SEVERITY_ANNOYANCE, SEVERITY_NOTICE);
136 foreach($severities as $severity) {
137 if(!empty($issues[$severity])) {
138 echo '<dl class="healthissues '.$severity.'">';
139 foreach($issues[$severity] as $classname => $data) {
140 echo '<dt id="'.$classname.'">'.$data['title'].'</dt>';
141 echo '<dd>'.$data['description'];
142 echo '<form action="health.php#solution" method="get">';
143 echo '<input type="hidden" name="solution" value="'.$classname.'" /><input type="submit" value="'.get_string('viewsolution').'" />';
144 echo '</form></dd>';
145 }
146 echo '</dl>';
147 }
148 }
149 }
150}
151
152function health_print_solution($classname) {
153 $problem = new $classname;
154 $data = array(
155 'title' => $problem->title(),
156 'severity' => $problem->severity(),
157 'description' => $problem->description(),
158 'solution' => $problem->solution()
159 );
160
161 print_heading(get_string('healthcenter'));
162 print_heading(get_string('healthproblemsolution'));
163 echo '<dl class="healthissues '.$data['severity'].'">';
164 echo '<dt>'.$data['title'].'</dt>';
165 echo '<dd>'.$data['description'].'</dd>';
166 echo '<dt id="solution" class="solution">'.get_string('healthsolution').'</dt>';
167 echo '<dd class="solution">'.$data['solution'].'</dd></dl>';
168 echo '<form id="healthformreturn" action="health.php#'.$classname.'" method="get">';
169 echo '<input type="submit" value="'.get_string('healthreturntomain').'" />';
170 echo '</form>';
171}
172
173class problem_base {
174 function exists() {
175 return false;
176 }
177 function title() {
178 return '???';
179 }
180 function severity() {
181 return SEVERITY_NOTICE;
182 }
183 function description() {
184 return '';
185 }
186 function solution() {
187 return '';
188 }
189}
190
191class problem_000001 extends problem_base {
192 function title() {
193 return 'Invalid value for $CFG->dirroot';
194 }
195 function exists() {
196 global $CFG;
197 $dirroot = dirname(realpath('../index.php'));
198 if (!empty($dirroot) && $dirroot != $CFG->dirroot) {
199 return true;
200 }
201 return false;
202 }
203 function severity() {
204 return SEVERITY_CRITICAL;
205 }
206 function description() {
207 global $CFG;
208 return 'Your <strong>config.php</strong> file contains the setting <strong>$CFG-&gt;dirroot = "'.$CFG->dirroot.'"</strong>, which is incorrect. Unless you correct this problem, Moodle will not function correctly, if at all.';
209 }
210 function solution() {
211 global $CFG;
212 $dirroot = dirname(realpath('../index.php'));
213 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>';
214 }
215}
216
217class problem_000002 extends problem_base {
218 function title() {
219 return 'Extra characters at the end of config.php';
220 }
221 function exists() {
222 // [pj] When the requirements are raised to PHP 4.3.0 this will be file_get_contents()
223 if($fp = @fopen('../config.php', 'r')) {
224 $contents = fread($fp, 16384); // 16K should be enough
225 $ending = substr($contents, -2);
226 unset($contents);
227 if($ending == '?>') {
228 return false;
229 }
230 fclose($fp);
231 }
232 return true;
233 }
234 function severity() {
235 return SEVERITY_SIGNIFICANT;
236 }
237 function description() {
238 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 }
240 function solution() {
241 global $CFG;
242 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.';
243 }
244}
245
246class problem_000003 extends problem_base {
247 function title() {
248 return '$CFG->dataroot does not exist or does not have write permissions';
249 }
250 function exists() {
251 global $CFG;
252 if(!is_dir($CFG->dataroot) || !is_writable($CFG->dataroot)) {
253 return true;
254 }
255 return false;
256 }
257 function severity() {
258 return SEVERITY_SIGNIFICANT;
259 }
260 function description() {
261 global $CFG;
262 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 }
264 function solution() {
265 global $CFG;
266 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.';
267 }
268}
269
270class problem_000004 extends problem_base {
271 function title() {
272 return 'cron.php is not set up to run automatically';
273 }
274 function exists() {
275 global $CFG;
276 $lastcron = get_field_sql('SELECT max(lastcron) FROM '.$CFG->prefix.'modules');
277 return (time() - $lastcron > 3600 * 24);
278 }
279 function severity() {
280 return SEVERITY_SIGNIFICANT;
281 }
282 function description() {
283 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 }
285 function solution() {
286 global $CFG;
287 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.';
288 }
289}
290
291class problem_000005 extends problem_base {
292 function title() {
293 return 'PHP: session.auto_start is enabled';
294 }
295 function exists() {
296 return ini_get_bool('session.auto_start');
297 }
298 function severity() {
299 return SEVERITY_CRITICAL;
300 }
301 function description() {
302 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 }
304 function solution() {
305 global $CFG;
306 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>';
307 }
308}
309
310class problem_000006 extends problem_base {
311 function title() {
312 return 'PHP: magic_quotes_runtime is enabled';
313 }
314 function exists() {
315 return (ini_get_bool('magic_quotes_runtime'));
316 }
317 function severity() {
318 return SEVERITY_SIGNIFICANT;
319 }
320 function description() {
321 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 }
323 function solution() {
324 global $CFG;
325 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>';
326 }
327}
328
329class problem_000007 extends problem_base {
330 function title() {
331 return 'PHP: file_uploads is disabled';
332 }
333 function exists() {
334 return !ini_get_bool('file_uploads');
335 }
336 function severity() {
337 return SEVERITY_SIGNIFICANT;
338 }
339 function description() {
340 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 }
342 function solution() {
343 global $CFG;
344 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>';
345 }
346}
347
348class problem_000008 extends problem_base {
349 function title() {
350 return 'PHP: memory_limit cannot be controlled by Moodle';
351 }
352 function exists() {
353 $memlimit = @ini_get('memory_limit');
354 if(empty($memlimit)) {
355 // PHP not compiled with memory limits, this means that it's
356 // probably limited to 8M so we have a problem...
357 return true;
358 }
359 // Otherwise, raise_memory_limit in setup.php will do the trick
360 return false;
361 }
362 function severity() {
363 return SEVERITY_ANNOYANCE;
364 }
365 function description() {
366 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 }
368 function solution() {
369 global $CFG;
370 return 'We need a good solution here. Enabling memory limit control means recompiling PHP... maybe this should be SEVERITY_NOTICE instead of SEVERITY_ANNOYANCE?';
371 }
372}
373
374
375class problem_00000x extends problem_base {
376 function exists() {
377 return false;
378 }
379 function severity() {
380 return SEVERITY_SIGNIFICANT;
381 }
382 function description() {
383 return '';
384 }
385 function solution() {
386 global $CFG;
387 return '';
388 }
389}
390
391/*
392
393TODO:
394
395 session.save_path -- it doesn't really matter because we are already IN a session, right?
396
397 slasharguments -- get_file_argument() in weblib.php
398*/
399
400?>