Nullified courseimages.php, and made some of the security improvements
[moodle.git] / lib / compatible.php
blobc9afec1e53f9d8c1c2dbc9d93d02a631deec4845
1 <?php // $Id$ ?>
3 <html>
4 <head>
5 <title>Moodle Environment Test</title>
6 </head>
7 <body bgcolor=white>
9 <?php
11 function print_row($name, $value, $badcomment='') {
12 echo "<tr>";
13 echo "<th align=\"right\">$name</th>";
14 echo "<td align=\"left\">$value</td>";
15 if ($badcomment) {
16 echo "<td align=\"left\"><font color=red>$badcomment</font></td>";
17 } else {
18 echo "<td align=\"left\"><font color=green>Looks good</font></td>";
20 echo "</tr>";
23 function ini_get_bool($ini_get_arg) {
24 /// This function makes the return value of ini_get consistent if you are
25 /// setting server directives through the .htaccess file in apache.
26 /// Current behavior for value set from php.ini On = 1, Off = [blank]
27 /// Current behavior for value set from .htaccess On = On, Off = Off
28 /// Contributed by jdell@unr.edu
30 $temp = ini_get($ini_get_arg);
32 if ($temp == "1" or strtolower($temp) == "on") {
33 return true;
35 return false;
38 function check_php_version($version="4.1.0") {
39 /// Returns true is the current version of PHP is greater that the specified one
40 $minversion = intval(str_replace(".", "", $version));
41 $curversion = intval(str_replace(".", "", phpversion()));
42 return ($curversion >= $minversion);
45 function check_gd_version() {
46 /// Hack to find out the GD version by parsing phpinfo output
47 $gdversion = 0;
49 if (function_exists('gd_info')){
50 $gd_info = gd_info();
51 if (substr_count($gd_info['GD Version'], "2.")) {
52 $gdversion = 2;
53 } else if (substr_count($gd_info['GD Version'], "1.")) {
54 $gdversion = 1;
57 } else {
58 ob_start();
59 phpinfo(8);
60 $phpinfo = ob_get_contents();
61 ob_end_clean();
63 $phpinfo = explode("\n",$phpinfo);
66 foreach ($phpinfo as $text) {
67 $parts = explode('</td>',$text);
68 foreach ($parts as $key => $val) {
69 $parts[$key] = trim(strip_tags($val));
71 if ($parts[0] == "GD Version") {
72 if (substr_count($parts[1], "2.0")) {
73 $parts[1] = "2.0";
75 $gdversion = intval($parts[1]);
80 return $gdversion; // 1, 2 or 0
85 /////////////////////////////////////////////////////////////////////////////////////
87 $error = 0;
89 echo "<h2 align=\"center\">Moodle compatibility tester</h2>";
91 echo "<table align=\"center\" border=1>";
93 /// Check that PHP is of a sufficient version
95 if (!check_php_version("4.1.0")) {
96 print_row("PHP Version", "Old", "Moodle requires PHP 4.1.0 or later");
97 } else {
98 print_row("PHP Version", "OK");
101 /// Check some PHP server settings
103 if (ini_get_bool('safe_mode')) {
104 print_row("safe_mode", "On", "Moodle can not handle files properly with safe mode on");
105 $error++;
106 } else {
107 print_row("safe_mode", "Off");
110 if (ini_get_bool('session.auto_start')) {
111 print_row("session.auto_start", "On", "This should be Off");
112 $error++;
113 } else {
114 print_row("session.auto_start", "Off");
117 if (ini_get_bool('magic_quotes_runtime')) {
118 print_row("magic_quotes_runtime", "On", "This should be Off");
119 $error++;
120 } else {
121 print_row("magic_quotes_runtime", "Off");
124 if (!ini_get_bool('file_uploads')) {
125 print_row("file_uploads", "Off", "This should be On");
126 $error++;
127 } else {
128 print_row("file_uploads", "On");
131 if (!is_readable(ini_get('session.save_path'))) {
132 print_row("session.save_path", "Broken", "It seems your server does not support sessions");
133 $error++;
134 } else {
135 print_row("session.save_path", "Works");
138 if (!$gdversion = check_gd_version()) {
139 print_row("GD Library", "No", "The GD library should be present to process and create images");
140 $error++;
141 } else {
142 print_row("GD Library", $gdversion);
146 echo "</table>";
148 if ($error == 1) {
149 echo "<h2 align=\"center\"><font color=red>$error error was found. See <a href=\"http://moodle.org/doc\">http://moodle.org/doc</a></font></h2>";
150 } else if ($error) {
151 echo "<h2 align=\"center\"><font color=red>$error errors were found. See <a href=\"http://moodle.org/doc\">http://moodle.org/doc</a></font></h2>";
152 } else {
153 echo "<h2 align=\"center\"><font color=green>Server looks good - clear to install!</font></a></h2>";