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

/www/checker.php

https://bitbucket.org/iiic/iszp
PHP | 303 lines | 217 code | 49 blank | 37 comment | 23 complexity | 833774b38e1bfe1ebff3aabc30a44724 MD5 | raw file
  1. <?php
  2. /**
  3. * Requirements Checker: This script will check if your system meets
  4. * the requirements for running Nette Framework.
  5. *
  6. * This file is part of the Nette Framework (http://nette.org)
  7. *
  8. * For the full copyright and license information, please view
  9. * the file license.txt that was distributed with this source code.
  10. */
  11. /**
  12. * Check PHP configuration.
  13. */
  14. foreach (array('function_exists', 'version_compare', 'extension_loaded', 'ini_get') as $function) {
  15. if (!function_exists($function)) {
  16. die("Error: function '$function' is required by Nette Framework and this Requirements Checker.");
  17. }
  18. }
  19. /**
  20. * Check assets folder, template file must be readable
  21. */
  22. define('TEMPLATE_FILE', __DIR__ . '/assets/checker.phtml');
  23. if (!is_readable(TEMPLATE_FILE)) {
  24. die("Error: template file is not readable. Check assets folder (part of distribution), it should be present, readable and contain readable template file.");
  25. }
  26. /**
  27. * Check Nette Framework requirements.
  28. */
  29. define('CHECKER_VERSION', '1.5');
  30. $tests[] = array(
  31. 'title' => 'Web server',
  32. 'message' => $_SERVER['SERVER_SOFTWARE'],
  33. );
  34. $tests[] = array(
  35. 'title' => 'PHP version',
  36. 'required' => TRUE,
  37. 'passed' => version_compare(PHP_VERSION, '5.3.0', '>='),
  38. 'message' => PHP_VERSION,
  39. 'description' => 'Your PHP version is too old. Nette Framework requires at least PHP 5.3.0 or higher.',
  40. );
  41. $tests[] = array(
  42. 'title' => 'Memory limit',
  43. 'message' => ini_get('memory_limit'),
  44. );
  45. $tests['hf'] = array(
  46. 'title' => '.htaccess file protection',
  47. 'required' => FALSE,
  48. 'description' => 'File protection by <code>.htaccess</code> is not present. You must be careful to put files into document_root folder.',
  49. 'script' => '<script src="assets/denied/checker.js"></script> <script>displayResult("hf", typeof fileProtectionChecker == "undefined")</script>',
  50. );
  51. $tests['hr'] = array(
  52. 'title' => '.htaccess mod_rewrite',
  53. 'required' => FALSE,
  54. 'description' => 'Mod_rewrite is probably not present. You will not be able to use Cool URL.',
  55. 'script' => '<script src="assets/rewrite/checker"></script> <script>displayResult("hr", typeof modRewriteChecker == "boolean")</script>',
  56. );
  57. $tests[] = array(
  58. 'title' => 'Function ini_set()',
  59. 'required' => FALSE,
  60. 'passed' => function_exists('ini_set'),
  61. 'description' => 'Function <code>ini_set()</code> is disabled. Some parts of Nette Framework may not work properly.',
  62. );
  63. $tests[] = array(
  64. 'title' => 'Function error_reporting()',
  65. 'required' => TRUE,
  66. 'passed' => function_exists('error_reporting'),
  67. 'description' => 'Function <code>error_reporting()</code> is disabled. Nette Framework requires this to be enabled.',
  68. );
  69. $tests[] = array(
  70. 'title' => 'Function flock()',
  71. 'required' => TRUE,
  72. 'passed' => flock(fopen(__FILE__, 'r'), LOCK_SH),
  73. 'description' => 'Function <code>flock()</code> is not supported on this filesystem. Nette Framework requires this to process atomic file operations.',
  74. );
  75. $tests[] = array(
  76. 'title' => 'Register_globals',
  77. 'required' => TRUE,
  78. 'passed' => !iniFlag('register_globals'),
  79. 'message' => 'Disabled',
  80. 'errorMessage' => 'Enabled',
  81. 'description' => 'Configuration directive <code>register_globals</code> is enabled. Nette Framework requires this to be disabled.',
  82. );
  83. $tests[] = array(
  84. 'title' => 'Zend.ze1_compatibility_mode',
  85. 'required' => TRUE,
  86. 'passed' => !iniFlag('zend.ze1_compatibility_mode'),
  87. 'message' => 'Disabled',
  88. 'errorMessage' => 'Enabled',
  89. 'description' => 'Configuration directive <code>zend.ze1_compatibility_mode</code> is enabled. Nette Framework requires this to be disabled.',
  90. );
  91. $tests[] = array(
  92. 'title' => 'Variables_order',
  93. 'required' => TRUE,
  94. 'passed' => strpos(ini_get('variables_order'), 'G') !== FALSE && strpos(ini_get('variables_order'), 'P') !== FALSE && strpos(ini_get('variables_order'), 'C') !== FALSE,
  95. 'description' => 'Configuration directive <code>variables_order</code> is missing. Nette Framework requires this to be set.',
  96. );
  97. $tests[] = array(
  98. 'title' => 'Session auto-start',
  99. 'required' => FALSE,
  100. 'passed' => session_id() === '' && !defined('SID'),
  101. 'description' => 'Session auto-start is enabled. Nette Framework recommends not to use this directive for security reasons.',
  102. );
  103. $tests[] = array(
  104. 'title' => 'Reflection extension',
  105. 'required' => TRUE,
  106. 'passed' => class_exists('ReflectionFunction'),
  107. 'description' => 'Reflection extension is required.',
  108. );
  109. $tests[] = array(
  110. 'title' => 'SPL extension',
  111. 'required' => TRUE,
  112. 'passed' => extension_loaded('SPL'),
  113. 'description' => 'SPL extension is required.',
  114. );
  115. $tests[] = array(
  116. 'title' => 'PCRE extension',
  117. 'required' => TRUE,
  118. 'passed' => extension_loaded('pcre') && @preg_match('/pcre/u', 'pcre'),
  119. 'message' => 'Enabled and works properly',
  120. 'errorMessage' => 'Disabled or without UTF-8 support',
  121. 'description' => 'PCRE extension is required and must support UTF-8.',
  122. );
  123. $tests[] = array(
  124. 'title' => 'ICONV extension',
  125. 'required' => TRUE,
  126. 'passed' => extension_loaded('iconv') && (ICONV_IMPL !== 'unknown') && @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', 'test')) === 'test',
  127. 'message' => 'Enabled and works properly',
  128. 'errorMessage' => 'Disabled or does not work properly',
  129. 'description' => 'ICONV extension is required and must work properly.',
  130. );
  131. $tests[] = array(
  132. 'title' => 'PHP tokenizer',
  133. 'required' => TRUE,
  134. 'passed' => extension_loaded('tokenizer'),
  135. 'description' => 'PHP tokenizer is required.',
  136. );
  137. $tests[] = array(
  138. 'title' => 'PDO extension',
  139. 'required' => FALSE,
  140. 'passed' => $pdo = extension_loaded('pdo') && PDO::getAvailableDrivers(),
  141. 'message' => $pdo ? 'Available drivers: ' . implode(' ', PDO::getAvailableDrivers()) : NULL,
  142. 'description' => 'PDO extension or PDO drivers are absent. You will not be able to use <code>Nette\Database</code>.',
  143. );
  144. $tests[] = array(
  145. 'title' => 'Multibyte String extension',
  146. 'required' => FALSE,
  147. 'passed' => extension_loaded('mbstring'),
  148. 'description' => 'Multibyte String extension is absent. Some internationalization components may not work properly.',
  149. );
  150. $tests[] = array(
  151. 'title' => 'Multibyte String function overloading',
  152. 'required' => TRUE,
  153. 'passed' => !extension_loaded('mbstring') || !(mb_get_info('func_overload') & 2),
  154. 'message' => 'Disabled',
  155. 'errorMessage' => 'Enabled',
  156. 'description' => 'Multibyte String function overloading is enabled. Nette Framework requires this to be disabled. If it is enabled, some string function may not work properly.',
  157. );
  158. $tests[] = array(
  159. 'title' => 'Memcache extension',
  160. 'required' => FALSE,
  161. 'passed' => extension_loaded('memcache'),
  162. 'description' => 'Memcache extension is absent. You will not be able to use <code>Nette\Caching\Storages\MemcachedStorage</code>.',
  163. );
  164. $tests[] = array(
  165. 'title' => 'GD extension',
  166. 'required' => FALSE,
  167. 'passed' => extension_loaded('gd'),
  168. 'description' => 'GD extension is absent. You will not be able to use <code>Nette\Image</code>.',
  169. );
  170. $tests[] = array(
  171. 'title' => 'Bundled GD extension',
  172. 'required' => FALSE,
  173. 'passed' => extension_loaded('gd') && GD_BUNDLED,
  174. 'description' => 'Bundled GD extension is absent. You will not be able to use some functions such as <code>Nette\Image::filter()</code> or <code>Nette\Image::rotate()</code>.',
  175. );
  176. $tests[] = array(
  177. 'title' => 'Fileinfo extension or mime_content_type()',
  178. 'required' => FALSE,
  179. 'passed' => extension_loaded('fileinfo') || function_exists('mime_content_type'),
  180. 'description' => 'Fileinfo extension or function <code>mime_content_type()</code> are absent. You will not be able to determine mime type of uploaded files.',
  181. );
  182. /*5.2*
  183. $tests[] = array(
  184. 'title' => 'HTTP extension',
  185. 'required' => FALSE,
  186. 'passed' => !extension_loaded('http'),
  187. 'message' => 'Disabled',
  188. 'errorMessage' => 'Enabled',
  189. 'description' => 'HTTP extension has naming conflict with Nette Framework. You have to disable this extension or use „prefixed“ version.',
  190. );*/
  191. $tests[] = array(
  192. 'title' => 'HTTP_HOST or SERVER_NAME',
  193. 'required' => TRUE,
  194. 'passed' => isset($_SERVER["HTTP_HOST"]) || isset($_SERVER["SERVER_NAME"]),
  195. 'message' => 'Present',
  196. 'errorMessage' => 'Absent',
  197. 'description' => 'Either <code>$_SERVER["HTTP_HOST"]</code> or <code>$_SERVER["SERVER_NAME"]</code> must be available for resolving host name.',
  198. );
  199. $tests[] = array(
  200. 'title' => 'REQUEST_URI or ORIG_PATH_INFO',
  201. 'required' => TRUE,
  202. 'passed' => isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["ORIG_PATH_INFO"]),
  203. 'message' => 'Present',
  204. 'errorMessage' => 'Absent',
  205. 'description' => 'Either <code>$_SERVER["REQUEST_URI"]</code> or <code>$_SERVER["ORIG_PATH_INFO"]</code> must be available for resolving request URL.',
  206. );
  207. $tests[] = array(
  208. 'title' => 'DOCUMENT_ROOT & SCRIPT_FILENAME or SCRIPT_NAME',
  209. 'required' => TRUE,
  210. 'passed' => isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME']) || isset($_SERVER['SCRIPT_NAME']),
  211. 'message' => 'Present',
  212. 'errorMessage' => 'Absent',
  213. 'description' => '<code>$_SERVER["DOCUMENT_ROOT"]</code> and <code>$_SERVER["SCRIPT_FILENAME"]</code> or <code>$_SERVER["SCRIPT_NAME"]</code> must be available for resolving script file path.',
  214. );
  215. $tests[] = array(
  216. 'title' => 'SERVER_ADDR or LOCAL_ADDR',
  217. 'required' => TRUE,
  218. 'passed' => isset($_SERVER["SERVER_ADDR"]) || isset($_SERVER["LOCAL_ADDR"]),
  219. 'message' => 'Present',
  220. 'errorMessage' => 'Absent',
  221. 'description' => '<code>$_SERVER["SERVER_ADDR"]</code> or <code>$_SERVER["LOCAL_ADDR"]</code> must be available for detecting development / production mode.',
  222. );
  223. paint($tests);
  224. /**
  225. * Paints checker.
  226. * @param array
  227. * @return void
  228. */
  229. function paint($requirements)
  230. {
  231. $errors = $warnings = FALSE;
  232. foreach ($requirements as $id => $requirement)
  233. {
  234. $requirements[$id] = $requirement = (object) $requirement;
  235. if (isset($requirement->passed) && !$requirement->passed) {
  236. if ($requirement->required) {
  237. $errors = TRUE;
  238. } else {
  239. $warnings = TRUE;
  240. }
  241. }
  242. }
  243. require TEMPLATE_FILE;
  244. }
  245. /**
  246. * Gets the boolean value of a configuration option.
  247. * @param string configuration option name
  248. * @return bool
  249. */
  250. function iniFlag($var)
  251. {
  252. $status = strtolower(ini_get($var));
  253. return $status === 'on' || $status === 'true' || $status === 'yes' || (int) $status;
  254. }