check-web.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /* $Id: check-web.php 2393 2007-01-25 00:38:02Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // defines
  16. define('_NAME', 'torrentflux-b4rt 1.0');
  17. preg_match('|.*\s(\d+)\s.*|', '$Revision: 2393 $', $revisionMatches);
  18. define('_REVISION', $revisionMatches[1]);
  19. define('_TITLE', _NAME.' - check-web - Revision '._REVISION);
  20. // fields
  21. $errors = 0;
  22. $warnings = 0;
  23. $dbsupported = 0;
  24. $errorsMessages = array();
  25. $warningsMessages = array();
  26. // -----------------------------------------------------------------------------
  27. // Main
  28. // -----------------------------------------------------------------------------
  29. // ob-start
  30. if (@ob_get_level() == 0)
  31. @ob_start();
  32. // head
  33. sendHead();
  34. // title
  35. send('<h1>'._TITLE.'</h1>');
  36. // PHP-Version
  37. send('<h2>1. PHP-Version</h2>');
  38. $phpVersion = 'PHP-Version : <em>'.PHP_VERSION.'</em> ';
  39. if (PHP_VERSION < 4.3) {
  40. $phpVersion .= '<font color="red">Failed</font>';
  41. $errors++;
  42. array_push($errorsMessages, "PHP-Version : 4.3 or higher required.");
  43. } else {
  44. $phpVersion .= '<font color="green">Passed</font>';
  45. }
  46. send($phpVersion);
  47. // PHP-Extensions
  48. send('<h2>2. PHP-Extensions</h2>');
  49. send("<ul>");
  50. $loadedExtensions = get_loaded_extensions();
  51. // session
  52. $session = '<li>session ';
  53. if (in_array("session", $loadedExtensions)) {
  54. $session .= '<font color="green">Passed</font>';
  55. } else {
  56. $session .= '<font color="red">Failed</font>';
  57. $errors++;
  58. array_push($errorsMessages, "PHP-Extensions : session required.");
  59. }
  60. send($session.'</li>');
  61. // pcre
  62. $pcre = '<li>pcre ';
  63. if (in_array("pcre", $loadedExtensions)) {
  64. $pcre .= '<font color="green">Passed</font>';
  65. } else {
  66. $pcre .= '<font color="red">Failed</font>';
  67. $errors++;
  68. array_push($errorsMessages, "PHP-Extensions : pcre required.");
  69. }
  70. send($pcre.'</li>');
  71. // sockets
  72. $sockets = '<li>sockets ';
  73. if (in_array("sockets", $loadedExtensions)) {
  74. $sockets .= '<font color="green">Passed</font>';
  75. } else {
  76. $sockets .= '<font color="red">Failed</font>';
  77. $warnings++;
  78. array_push($warningsMessages, "PHP-Extensions : sockets required for communication with fluxd. fluxd cannot work without sockets.");
  79. }
  80. send($sockets.'</li>');
  81. //
  82. send("</ul>");
  83. // PHP-Configuration
  84. send('<h2>3. PHP-Configuration</h2>');
  85. send("<ul>");
  86. // safe_mode
  87. $safe_mode = '<li>safe_mode ';
  88. if ((ini_get("safe_mode")) == 0) {
  89. $safe_mode .= '<font color="green">Passed</font>';
  90. } else {
  91. $safe_mode .= '<font color="red">Failed</font>';
  92. $errors++;
  93. array_push($errorsMessages, "PHP-Configuration : safe_mode must be turned off.");
  94. }
  95. send($safe_mode.'</li>');
  96. // allow_url_fopen
  97. $allow_url_fopen = '<li>allow_url_fopen ';
  98. if ((ini_get("allow_url_fopen")) == 1) {
  99. $allow_url_fopen .= '<font color="green">Passed</font>';
  100. } else {
  101. $allow_url_fopen .= '<font color="red">Failed</font>';
  102. array_push($warningsMessages, "PHP-Configuration : allow_url_fopen must be turned on. some features wont work if it is turned off.");
  103. $warnings++;
  104. }
  105. send($allow_url_fopen.'</li>');
  106. // register_globals
  107. $register_globals = '<li>register_globals ';
  108. if ((ini_get("register_globals")) == 0) {
  109. $register_globals .= '<font color="green">Passed</font>';
  110. } else {
  111. $register_globals .= '<font color="red">Failed</font>';
  112. $errors++;
  113. array_push($errorsMessages, "PHP-Configuration : register_globals must be turned off.");
  114. }
  115. send($register_globals.'</li>');
  116. //
  117. send("</ul>");
  118. // PHP-Database-Support
  119. send('<h2>4. PHP-Database-Support</h2>');
  120. send("<ul>");
  121. // define valid db-types
  122. $databaseTypes = array();
  123. $databaseTypes['mysql'] = 'mysql_connect';
  124. $databaseTypes['sqlite'] = 'sqlite_open';
  125. $databaseTypes['postgres'] = 'pg_connect';
  126. // test db-types
  127. foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
  128. $dbtest = '<li>'.$databaseTypeName.' ';
  129. if (function_exists($databaseTypeFunction)) {
  130. $dbtest .= '<font color="green">Passed</font>';
  131. $dbsupported++;
  132. } else {
  133. $dbtest .= '<font color="red">Failed</font>';
  134. }
  135. send($dbtest.'</li>');
  136. }
  137. send("</ul>");
  138. // db-state
  139. if ($dbsupported == 0) {
  140. $errors++;
  141. array_push($errorsMessages, "PHP-Database-Support : no supported database-type found.");
  142. }
  143. // OS-Specific
  144. // get os
  145. $osString = php_uname('s');
  146. if (isset($osString)) {
  147. if (!(stristr($osString, 'linux') === false)) /* linux */
  148. define('_OS', 1);
  149. else if (!(stristr($osString, 'bsd') === false)) /* bsd */
  150. define('_OS', 2);
  151. else
  152. define('_OS', 0);
  153. } else {
  154. define('_OS', 0);
  155. }
  156. send('<h2>5. OS-Specific ('.$osString.' '.php_uname('r').')</h2>');
  157. switch (_OS) {
  158. case 1: // linux
  159. send('No Special Requirements on Linux-OS. <font color="green">Passed</font>');
  160. break;
  161. case 2: // bsd
  162. send("<ul>");
  163. // posix
  164. $posix = '<li>posix ';
  165. if ((function_exists('posix_geteuid')) && (function_exists('posix_getpwuid'))) {
  166. $posix .= '<font color="green">Passed</font>';
  167. } else {
  168. $posix .= '<font color="red">Failed</font>';
  169. $warnings++;
  170. array_push($warningsMessages, "OS-Specific : PHP-extension posix missing. some netstat-features wont work without.");
  171. }
  172. send($posix.'</li>');
  173. send("</ul>");
  174. break;
  175. case 0: // unknown
  176. default:
  177. send("OS not supported.<br>");
  178. $errors++;
  179. array_push($errorsMessages, "OS-Specific : ".$osString." not supported.");
  180. break;
  181. }
  182. // summary
  183. send('<h1>Summary</h1>');
  184. // state
  185. $state = "<strong>State : ";
  186. if (($warnings + $errors) == 0) {
  187. // good
  188. $state .= '<font color="green">Ok</font>';
  189. $state .= "</strong><br>";
  190. send($state);
  191. send(_NAME." should run on this system.");
  192. } else {
  193. if (($errors == 0) && ($warnings > 0)) {
  194. // may run with flaws
  195. $state .= '<font color="orange">Warning</font>';
  196. $state .= "</strong><br>";
  197. send($state);
  198. send(_NAME." may run on this system, but there may be problems.");
  199. } else {
  200. // not ok
  201. $state .= '<font color="red">Failed</font>';
  202. $state .= "</strong><br>";
  203. send($state);
  204. send(_NAME." cannot run on this system.");
  205. }
  206. }
  207. // errors
  208. if (count($errorsMessages) > 0) {
  209. send('<p><strong><font color="red">Errors : </font></strong><br>');
  210. send("<ul>");
  211. foreach ($errorsMessages as $errorsMessage) {
  212. send("<li>".$errorsMessage."</li>");
  213. }
  214. send("</ul>");
  215. }
  216. // warnings
  217. if (count($warningsMessages) > 0) {
  218. send('<p><strong><font color="orange">Warnings : </font></strong><br>');
  219. send("<ul>");
  220. foreach ($warningsMessages as $warningsMessage) {
  221. send("<li>".$warningsMessage."</li>");
  222. }
  223. send("</ul>");
  224. }
  225. // foot
  226. sendFoot();
  227. // ob-end + exit
  228. @ob_end_flush();
  229. exit();
  230. // -----------------------------------------------------------------------------
  231. // functions
  232. // -----------------------------------------------------------------------------
  233. /**
  234. * send head-portion
  235. */
  236. function sendHead() {
  237. send('<html>');
  238. send('<head>');
  239. send('<title>'._TITLE.'</title>');
  240. send('<style type="text/css">');
  241. send('font {font-family: Verdana,Helvetica; font-size: 12px}');
  242. send('body {font-family: Verdana,Helvetica; font-size: 12px}');
  243. send('p {font-family: Verdana,Helvetica; font-size: 12px}');
  244. send('h1 {font-family: Verdana,Helvetica; font-size: 15px}');
  245. send('h2 {font-family: Verdana,Helvetica; font-size: 14px}');
  246. send('h3 {font-family: Verdana,Helvetica; font-size: 13px}');
  247. send('</style>');
  248. send('</head>');
  249. send('<body topmargin="8" leftmargin="5" bgcolor="#FFFFFF">');
  250. }
  251. /**
  252. * send foot-portion
  253. */
  254. function sendFoot() {
  255. send('</body>');
  256. send('</html>');
  257. }
  258. /**
  259. * send - sends a string to the client
  260. */
  261. function send($string = "") {
  262. echo $string;
  263. echo str_pad('', 4096)."\n";
  264. @ob_flush();
  265. @flush();
  266. }
  267. ?>