1
0

check-cli.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #!/usr/bin/env php
  2. <?php
  3. /* $Id: check-cli.php 3081 2007-06-08 19:08:42Z warion $ */
  4. /*******************************************************************************
  5. LICENSE
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License (GPL)
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  15. *******************************************************************************/
  16. // prevent invocation from web
  17. if (empty($argv[0])) die();
  18. if (isset($_REQUEST['argv'])) die();
  19. /******************************************************************************/
  20. // defines
  21. define('_NAME', 'torrentflux-b4rt 1.0');
  22. preg_match('|.* (\d+) .*|', '$Revision: 3081 $', $revisionMatches);
  23. define('_REVISION', $revisionMatches[1]);
  24. define('_TITLE', _NAME.' - check-cli - Revision '._REVISION);
  25. // fields
  26. $errors = 0;
  27. $warnings = 0;
  28. $dbsupported = 0;
  29. $errorsMessages = array();
  30. $warningsMessages = array();
  31. // -----------------------------------------------------------------------------
  32. // Main
  33. // -----------------------------------------------------------------------------
  34. // title
  35. echo _TITLE."\n";
  36. // PHP-Version
  37. echo '1. PHP-Version'."\n";
  38. // version
  39. $phpVersion = 'PHP-Version : '.PHP_VERSION.' ';
  40. if (PHP_VERSION < 4.3) {
  41. $phpVersion .= 'Failed';
  42. $errors++;
  43. array_push($errorsMessages, "PHP-Version : 4.3 or higher required.");
  44. } else {
  45. $phpVersion .= 'Passed';
  46. }
  47. echo $phpVersion."\n";
  48. // cli
  49. $phpcli = 'PHP-SAPI : ';
  50. $phpsapi = php_sapi_name();
  51. if ($phpsapi != 'cli') {
  52. $phpcli .= $phpsapi . ' Failed';
  53. $errors++;
  54. array_push($errorsMessages, "PHP-SAPI : CLI version of PHP required.");
  55. } else {
  56. $phpcli .= $phpsapi . ' Passed';
  57. }
  58. echo $phpcli."\n";
  59. // PHP-Extensions
  60. echo '2. PHP-Extensions'."\n";
  61. $loadedExtensions = get_loaded_extensions();
  62. // pcre
  63. $pcre = 'pcre ';
  64. if (in_array("pcre", $loadedExtensions)) {
  65. $pcre .= 'Passed';
  66. } else {
  67. $pcre .= 'Failed';
  68. $errors++;
  69. array_push($errorsMessages, "PHP-Extensions : pcre required.");
  70. }
  71. echo $pcre."\n";
  72. // sockets
  73. $sockets = 'sockets ';
  74. if (in_array("sockets", $loadedExtensions)) {
  75. $sockets .= 'Passed';
  76. } else {
  77. $sockets .= 'Failed';
  78. $warnings++;
  79. array_push($warningsMessages, "PHP-Extensions : sockets required for communication with fluxd. fluxd cannot work without sockets.");
  80. }
  81. echo $sockets."\n";
  82. //
  83. // PHP-Configuration
  84. echo '3. PHP-Configuration'."\n";
  85. // safe_mode
  86. $safe_mode = 'safe_mode ';
  87. if ((ini_get("safe_mode")) == 0) {
  88. $safe_mode .= 'Passed';
  89. } else {
  90. $safe_mode .= 'Failed';
  91. $errors++;
  92. array_push($errorsMessages, "PHP-Configuration : safe_mode must be turned off.");
  93. }
  94. echo $safe_mode."\n";
  95. // allow_url_fopen
  96. $allow_url_fopen = 'allow_url_fopen ';
  97. if ((ini_get("allow_url_fopen")) == 1) {
  98. $allow_url_fopen .= 'Passed';
  99. } else {
  100. $allow_url_fopen .= 'Failed';
  101. array_push($warningsMessages, "PHP-Configuration : allow_url_fopen must be turned on. some features wont work if it is turned off.");
  102. $warnings++;
  103. }
  104. echo $allow_url_fopen."\n";
  105. // register_globals
  106. $register_globals = 'register_globals ';
  107. if ((ini_get("register_globals")) == 0) {
  108. $register_globals .= 'Passed';
  109. } else {
  110. $register_globals .= 'Failed';
  111. $errors++;
  112. array_push($errorsMessages, "PHP-Configuration : register_globals must be turned off.");
  113. }
  114. echo $register_globals."\n";
  115. //
  116. // PHP-Database-Support
  117. echo '4. PHP-Database-Support'."\n";
  118. // define valid db-types
  119. $databaseTypes = array();
  120. $databaseTypes['mysql'] = 'mysql_connect';
  121. $databaseTypes['mysqli'] = 'mysqli_connect';
  122. $databaseTypes['sqlite'] = 'sqlite_open';
  123. $databaseTypes['postgres'] = 'pg_connect';
  124. // test db-types
  125. foreach ($databaseTypes as $databaseTypeName => $databaseTypeFunction) {
  126. $dbtest = $databaseTypeName.' ';
  127. if (function_exists($databaseTypeFunction)) {
  128. $dbtest .= 'Passed';
  129. $dbsupported++;
  130. } else {
  131. $dbtest .= 'Failed';
  132. }
  133. echo $dbtest."\n";
  134. }
  135. // db-state
  136. if ($dbsupported == 0) {
  137. $errors++;
  138. array_push($errorsMessages, "PHP-Database-Support : no supported database-type found.");
  139. }
  140. // OS-Specific
  141. // get os
  142. $osString = php_uname('s');
  143. if (isset($osString)) {
  144. if (!(stristr($osString, 'linux') === false)) /* linux */
  145. define('_OS', 1);
  146. else if (!(stristr($osString, 'bsd') === false)) /* bsd */
  147. define('_OS', 2);
  148. else
  149. define('_OS', 0);
  150. } else {
  151. define('_OS', 0);
  152. }
  153. echo '5. OS-Specific ('.$osString.' '.php_uname('r').')'."\n";
  154. switch (_OS) {
  155. case 1: // linux
  156. echo 'No Special Requirements on Linux-OS. Passed'."\n";
  157. break;
  158. case 2: // bsd
  159. // posix
  160. $posix = 'posix ';
  161. if ((function_exists('posix_geteuid')) && (function_exists('posix_getpwuid'))) {
  162. $posix .= 'Passed';
  163. } else {
  164. $posix .= 'Failed';
  165. $warnings++;
  166. array_push($warningsMessages, "OS-Specific : PHP-extension posix missing. some netstat-features wont work without.");
  167. }
  168. echo $posix."\n";
  169. break;
  170. case 0: // unknown
  171. default:
  172. echo "OS not supported.\n";
  173. $errors++;
  174. array_push($errorsMessages, "OS-Specific : ".$osString." not supported.");
  175. break;
  176. }
  177. // summary
  178. echo '----- Summary -----'."\n";
  179. // state
  180. $state = "State : ";
  181. if (($warnings + $errors) == 0) {
  182. // good
  183. $state .= 'Ok'."\n";
  184. echo $state;
  185. echo _NAME." should run on this system.\n";
  186. } else {
  187. if (($errors == 0) && ($warnings > 0)) {
  188. // may run with flaws
  189. $state .= 'Warning'."\n";
  190. echo $state;
  191. echo _NAME." may run on this system, but there may be problems.\n";
  192. } else {
  193. // not ok
  194. $state .= 'Failed'."\n";
  195. echo $state;
  196. echo _NAME." cannot run on this system.\n";
  197. }
  198. }
  199. // errors
  200. if (count($errorsMessages) > 0) {
  201. echo ('Errors :'."\n");
  202. foreach ($errorsMessages as $errorsMessage) {
  203. echo " - ".$errorsMessage."\n";
  204. }
  205. }
  206. // warnings
  207. if (count($warningsMessages) > 0) {
  208. echo ('Warnings :'."\n");
  209. foreach ($warningsMessages as $warningsMessage) {
  210. echo " - ".$warningsMessage."\n";
  211. }
  212. }
  213. // exit
  214. exit();
  215. ?>