PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/frontend/php/testconfig.php

#
PHP | 293 lines | 215 code | 35 blank | 43 comment | 30 complexity | afaf4e73d884229cfac32dbd2aef7eb1 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. # Check your configuration against recommended values
  3. #
  4. # Copyright 2006 (c) Mathieu Roy <yeupou--gnu.org>
  5. # Copyright (C) 2007 Sylvain Beucler
  6. #
  7. # This file is part of Savane.
  8. #
  9. # Savane is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU Affero General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # Savane is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. function return_bytes($val)
  22. {
  23. $val = trim($val);
  24. $last = strtolower($val{strlen($val)-1});
  25. switch($last) {
  26. // The 'G' modifier is available since PHP 5.1.0
  27. case 'g':
  28. $val *= 1024;
  29. case 'm':
  30. $val *= 1024;
  31. case 'k':
  32. $val *= 1024;
  33. }
  34. return $val;
  35. }
  36. print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  37. print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
  38. \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n\n";
  39. print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en_US\">\n";
  40. print "<head>\n";
  41. print "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
  42. print "<title>Basic PHP tests</title>\n";
  43. print "<style type=\"text/css\">\n";
  44. print "<!--\n";
  45. print ".different { background-color: #ffadad; color: black; }\n";
  46. print ".unset { background-color: #ffdada; color: black; }\n";
  47. print "-->\n";
  48. print "</style>\n";
  49. print "</head>\n\n";
  50. print "<body>\n";
  51. print "<h1>Basic PHP pre-tests for Savane installation</h1>\n";
  52. if (empty($inside_siteadmin))
  53. {
  54. print "<p>This page should help you to check whether your installation is properly configured. Once your installation is running, you should remove this file or restrict its access, since it could give details about your setup to anybody.</p>";
  55. }
  56. #==============================================================================
  57. print "<h2>Base PHP configuration</h2>\n";
  58. # cf. http://php.net/manual/en/ini.php
  59. $phptags = array (
  60. 'register_globals' => 0,
  61. 'file_uploads' => 1,
  62. 'magic_quotes_gpc' => 0,
  63. );
  64. // Get all php.ini values:
  65. $all_inis = ini_get_all();
  66. // Define missing constant to interpret the 'access' field
  67. define('PHP_INI_SYSTEM', 4);
  68. // Cf. http://www.php.net/manual/en/ini.core.php
  69. print "<table border=\"1\" summary=\"PHP configuration\">\n";
  70. print "<tr><th>PHP Tag name</th><th>Local value</th><th>Suggested/Required value</th></tr>\n";
  71. $unset = 0;
  72. ksort($phptags);
  73. foreach ( $phptags as $tag => $goodval ) {
  74. if ((htmlentities(ini_get($tag)) == htmlentities($goodval))
  75. or ($goodval==0 and !(bool)ini_get($tag)))
  76. {
  77. # OK
  78. printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  79. }
  80. else if (isset($all_inis[$tag]))
  81. {
  82. # Different
  83. printf ("<tr><td>%s</td><td class=\"different\">%s</td><td>%s",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  84. if ($all_inis[$tag]['access'] > PHP_INI_SYSTEM) {
  85. echo " (can be set in php.ini, .htaccess or httpd.conf)";
  86. } else {
  87. echo " (can be set in php.ini or httpd.conf - but not in .htaccess)";
  88. }
  89. echo "</td></tr>\n";
  90. }
  91. else
  92. {
  93. # Non existing ini value
  94. printf ("<tr><td>%s</td><td class=\"unset\">Unknown</td><td>%s</td></tr>\n",$tag,htmlentities($goodval));
  95. $unset = 1;
  96. }
  97. }
  98. # Check against minimum sizes
  99. $phptags = array (
  100. 'post_max_size' => '3M',
  101. 'upload_max_filesize' => '2M',
  102. );
  103. ksort($phptags);
  104. foreach ( $phptags as $tag => $goodval ) {
  105. if (return_bytes(ini_get($tag)) >= return_bytes($goodval))
  106. {
  107. # OK
  108. printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  109. }
  110. else if (isset($all_inis[$tag]))
  111. {
  112. # Different
  113. printf ("<tr><td>%s</td><td class=\"different\">%s</td><td>%s</td></tr>\n",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  114. }
  115. else
  116. {
  117. # Non existing ini value
  118. printf ("<tr><td>%s</td><td class=\"unset\">Unknown*</td><td>%s</td></tr>\n",$tag,htmlentities($goodval));
  119. $unset = 1;
  120. }
  121. }
  122. print "</table>\n";
  123. if ($unset)
  124. {
  125. echo "<blockquote>* This tag was not found at all. It is probably irrelevant to your PHP version so you may ignore this entry.</blockquote>";
  126. }
  127. #==============================================================================
  128. print "<h2>PHP functions</h2>\n";
  129. $phpfunctions = array (
  130. 'mysql_connect' => 'You must install/configure php-mysql ! [REQUIRED]',
  131. 'gettext' => 'You should install/configure php with gettext support ! [RECOMMENDED]',
  132. 'ctype_digit' => 'You must have a PHP version supporting ctype (--enable-ctype) ! [REQUIRED]',
  133. 'pam_auth' => 'You must have a PHP version supporting pam_auth only if you set up authentification via PAM (kerberos, AFS, etc)',
  134. );
  135. foreach ( $phpfunctions as $func => $comment ) {
  136. if (function_exists($func)) {
  137. print "function <strong>".$func."()</strong> exist.<br />\n";
  138. } else {
  139. print "function <strong>".$func."()</strong> does not exist. $comment <br />\n";
  140. }
  141. }
  142. #==============================================================================
  143. print "<h2>Apache environment vars</h2>\n";
  144. $configfile = '/etc/savane/';
  145. if ( getenv('SAVANE_CONF') ) {
  146. $configfile = getenv('SAVANE_CONF');
  147. print "SAVANE_CONF configured to ".$configfile."<br />\n";
  148. } elseif ( getenv('SV_LOCAL_INC_PREFIX') ) {
  149. $configfile = getenv('SV_LOCAL_INC_PREFIX');
  150. print "SV_LOCAL_INC_PREFIX configured to ".$configfile."<br />\n";
  151. } else {
  152. print "SAVANE_CONF or SV_LOCAL_INC_PREFIX are not set, falling back to default <strong>".$configfile."</strong>) <br />\n";
  153. }
  154. # add a trailing slash
  155. if (!ereg('/$', $configfile))
  156. $configfile .= '/';
  157. $configfile .= '.savane.conf.php';
  158. if (is_readable($configfile)) {
  159. print "File <strong>$configfile</strong> exists and is readable.";
  160. } else {
  161. print "File <strong>$configfile</strong> does not exist or is not readable!";
  162. }
  163. #==============================================================================
  164. print "<h2>Savane configuration:</h2>\n";
  165. if (!is_readable($configfile))
  166. {
  167. print "Since $configfile does not exist or is not readable, this part cannot be checked.";
  168. }
  169. else
  170. {
  171. include $configfile;
  172. $variables = array (
  173. # Name / required
  174. 'sys_default_domain',
  175. 'sys_https_host',
  176. 'sys_dbhost',
  177. 'sys_dbname',
  178. 'sys_dbuser',
  179. 'sys_dbpasswd',
  180. 'sys_www_topdir',
  181. 'sys_url_topdir',
  182. 'sys_incdir',
  183. 'sys_name',
  184. 'sys_unix_group_name',
  185. 'sys_themedefault',
  186. 'sys_mail_domain',
  187. 'sys_mail_admin',
  188. 'sys_mail_replyto',
  189. 'sys_upload_max',
  190. );
  191. print "<table border=\"1\">\n";
  192. print "<tr><th>Conf variable</th><th>Current value</th></tr>\n";
  193. unset($unset);
  194. foreach ($variables as $tag) {
  195. if (isset($GLOBALS[$tag]))
  196. $value = $GLOBALS[$tag];
  197. else
  198. $value = '';
  199. // Is set
  200. if ($tag == "sys_dbpasswd")
  201. $value = "**************";
  202. printf ("<tr><td>%s</td><td>%s</td></tr>\n", $tag, htmlentities($value));
  203. }
  204. print "</table>\n";
  205. print "Savane uses safe defaults values when variables are not set in the
  206. configuration file.";
  207. }
  208. #=============================================================================
  209. print "<h2>Optional PHP configuration</h2>\n";
  210. print "The following is not required to run Savane but could enhance security
  211. of your production server. Displaying errors is recommended: they may
  212. annoy the user with warnings but allow you to spot and report
  213. potentially harmful bugs (concerns about \"security\" or information
  214. leak are void since this is free software and the source code is
  215. available to all).";
  216. $phptags = array (
  217. 'display_errors' => '1',
  218. 'log_errors' => '1',
  219. 'error_reporting' => E_ALL|E_STRICT,
  220. 'allow_url_fopen' => '0',
  221. 'disable_functions' => 'exec,passthru,popen,shell_exec,system',
  222. );
  223. print "<table border=\"1\">\n";
  224. print "<tr><th>PHP Tag name</th><th>Local value</th><th>Suggested/Required value</th></tr>\n";
  225. $unset = 0;
  226. ksort($phptags);
  227. foreach ( $phptags as $tag => $goodval ) {
  228. if (htmlentities(ini_get($tag)) == htmlentities($goodval))
  229. {
  230. # OK
  231. printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  232. }
  233. else if (isset($all_inis[$tag]))
  234. {
  235. # Different
  236. printf ("<tr><td>%s</td><td class=\"different\">%s</td><td><code>%s</code>",$tag,htmlentities(ini_get($tag)),htmlentities($goodval));
  237. if ($all_inis[$tag]['access'] > PHP_INI_SYSTEM) {
  238. echo " (can be set in php.ini, .htaccess or httpd.conf)";
  239. } else {
  240. echo " (can be set in php.ini or httpd.conf - but not in .htaccess)";
  241. }
  242. echo "</td></tr>\n";
  243. }
  244. else
  245. {
  246. # Non existing ini value
  247. printf ("<tr><td>%s</td><td class=\"unset\">Unknown*</td><td>%s</td></tr>\n",$tag,htmlentities($goodval));
  248. $unset = 1;
  249. }
  250. }
  251. print "</table>\n";
  252. if ($unset)
  253. {
  254. echo "<blockquote>* This tag was not found at all. It is probably irrelevant to your PHP version so you may ignore this entry.</blockquote>";
  255. }
  256. #==============================================================================
  257. print "<h2>That's it!</h2>";
  258. print "</body>\n<html>\n";