PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/install/checkForRequirements.php

https://code.google.com/p/yapeal/
PHP | 241 lines | 198 code | 0 blank | 43 comment | 9 complexity | b3a9a1938ebc9d633b511c0d910f9147 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1
  1. #!/usr/bin/php -Cq
  2. <?php
  3. /**
  4. * Used to check installation meets basic requirements.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENSE: This file is part of Yet Another Php Eve Api library also know
  9. * as Yapeal which will be used to refer to it in the rest of this license.
  10. *
  11. * Yapeal is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * Yapeal is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with Yapeal. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @author Michael Cummings <mgcummings@yahoo.com>
  24. * @copyright Copyright (c) 2008-2012, Michael Cummings
  25. * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
  26. * @package Yapeal
  27. * @link http://code.google.com/p/yapeal/
  28. * @link http://www.eveonline.com/
  29. */
  30. /**
  31. * @internal Allow viewing of the source code in web browser.
  32. */
  33. if (isset($_REQUEST['viewSource'])) {
  34. highlight_file(__FILE__);
  35. exit();
  36. };
  37. /**
  38. * @internal Only let this code be ran in CLI.
  39. */
  40. if (PHP_SAPI != 'cli') {
  41. header('HTTP/1.0 403 Forbidden', TRUE, 403);
  42. $mess = basename(__FILE__) . ' only works with CLI version of PHP but tried'
  43. . ' to run it using ' . PHP_SAPI . ' instead.' . PHP_EOL;
  44. die($mess);
  45. };
  46. /**
  47. * @internal Only let this code be ran directly.
  48. */
  49. $included = get_included_files();
  50. if (count($included) > 1 || $included[0] != __FILE__) {
  51. $mess = basename(__FILE__)
  52. . ' must be called directly and can not be included.' . PHP_EOL;
  53. fwrite(STDERR, $mess);
  54. exit(1);
  55. };
  56. /**
  57. * Define short name for directory separator which always uses unix '/'.
  58. * @ignore
  59. */
  60. define('DS', '/');
  61. // Check if the base path for Yapeal has been set in the environment.
  62. $dir = @getenv('YAPEAL_BASE');
  63. if ($dir === FALSE) {
  64. // Used to overcome path issues caused by how script is ran.
  65. $dir = str_replace('\\', DS, realpath(dirname(__FILE__) . DS. '..')) . DS;
  66. };
  67. // Get path constants so they can be used.
  68. require_once $dir . 'inc' . DS . 'common_paths.php';
  69. require_once YAPEAL_BASE . 'revision.php';
  70. require_once YAPEAL_INC . 'parseCommandLineOptions.php';
  71. require_once YAPEAL_INC . 'getSettingsFromIniFile.php';
  72. require_once YAPEAL_INC . 'usage.php';
  73. require_once YAPEAL_INC . 'showVersion.php';
  74. $shortOpts = array('c:');
  75. $longOpts = array('config:');
  76. // Parser command line options first in case user just wanted to see help.
  77. $options = parseCommandLineOptions($shortOpts, $longOpts);
  78. if (isset($options['help'])) {
  79. usage(__FILE__, $shortOpts, $longOpts);
  80. exit(0);
  81. };
  82. if (isset($options['version'])) {
  83. showVersion(__FILE__);
  84. exit(0);
  85. };
  86. // Insure minimum version of PHP we need to run.
  87. if (version_compare(PHP_VERSION, '5.2.4', '<')) {
  88. $mess = 'Need minimum of PHP 5.2.4 to use this software!' . PHP_EOL;
  89. fwrite(STDERR, $mess);
  90. exit(2);
  91. };
  92. // Check for some required extensions
  93. $required = array('curl', 'date', 'hash', 'mysqli', 'SimpleXML', 'SPL', 'xmlreader');
  94. $exts = get_loaded_extensions();
  95. $missing = array_diff($required, $exts);
  96. if (count($missing) > 0) {
  97. $mess = 'The required PHP extensions: ';
  98. $mess .= implode(', ', $missing) . ' are missing!' . PHP_EOL;
  99. fwrite(STDERR, $mess);
  100. exit(2);
  101. };
  102. // Check on cURL version and features.
  103. $cv = curl_version();
  104. if (version_compare($cv['version'], '7.15.0', '<')) {
  105. $mess = 'Need minimum of cURL 7.15.0 to use this software!' . PHP_EOL;
  106. fwrite(STDERR, $mess);
  107. exit(2);
  108. };
  109. if (($cv['features'] & CURL_VERSION_SSL) != CURL_VERSION_SSL) {
  110. $mess = 'cURL was built without SSL please check it.';
  111. fwrite(STDERR, $mess);
  112. exit(2);
  113. };
  114. // Check for minimum MySQL client.
  115. if (mysqli_get_client_version() < 50000) {
  116. $mess = 'MySQL client version is older than 5.0.' . PHP_EOL;
  117. fwrite(STDERR, $mess);
  118. exit(2);
  119. };
  120. // Must have getopt() to get command line parameters.
  121. if (!function_exists('getopt')) {
  122. $mess = 'getopt() not available can not perform checks!' . PHP_EOL;
  123. fwrite(STDERR, $mess);
  124. exit(2);
  125. };
  126. // Check the custom settings file if it can be found else check the default.
  127. if (!empty($options['config'])) {
  128. $iniVars = getSettingsFromIniFile($options['config']);
  129. } else {
  130. $iniVars = getSettingsFromIniFile();
  131. };
  132. if (empty($iniVars)) {
  133. $mess = 'Had one or more problems accessing configuration file.';
  134. $mess .= ' See any other error messages above for more help.' . PHP_EOL;
  135. fwrite(STDERR, $mess);
  136. exit(2);
  137. };
  138. // Check for required sections.
  139. $required = array('Cache', 'Database', 'Logging');
  140. $mess = '';
  141. foreach ($required as $section) {
  142. if (!isset($iniVars[$section])) {
  143. $mess .= 'Required section [' . $section;
  144. $mess .= '] is missing.' . PHP_EOL;
  145. }; // if isset ...
  146. };// foreach $required ...
  147. if (!empty($mess)) {
  148. fwrite(STDERR, $mess);
  149. exit(2);
  150. };
  151. // Check if log directory is writable.
  152. if (!is_writable(YAPEAL_LOG)) {
  153. $mess = YAPEAL_LOG . ' is not writable.' . PHP_EOL;
  154. fwrite(STDERR, $mess);
  155. exit(2);
  156. };
  157. // Check for required Logging section settings.
  158. $required = array('log_config', 'trace_enabled');
  159. $mess = '';
  160. foreach ($required as $setting) {
  161. if (!isset($iniVars['Logging'][$setting])) {
  162. $mess .= 'Missing required setting ' . $setting;
  163. $mess .= ' in section [Logging].' . PHP_EOL;
  164. };// if isset $iniVars...
  165. };// foreach $required ...
  166. if (!empty($mess)) {
  167. fwrite(STDERR, $mess);
  168. exit(2);
  169. };
  170. // Check if cache directory is writable.
  171. if (!is_writable(YAPEAL_CACHE)) {
  172. $mess = YAPEAL_CACHE . ' is not writable.' . PHP_EOL;
  173. fwrite(STDERR, $mess);
  174. exit(2);
  175. };
  176. // Check for required Cache section settings.
  177. $required = array('cache_length', 'cache_output');
  178. $mess = '';
  179. foreach ($required as $setting) {
  180. if (!isset($iniVars['Cache'][$setting])) {
  181. $mess .= 'Missing required setting ' . $setting;
  182. $mess .= ' in section [Cache].' . PHP_EOL;
  183. };// if isset $iniVars...
  184. };// foreach $required ...
  185. if (!empty($mess)) {
  186. fwrite(STDERR, $mess);
  187. exit(2);
  188. };
  189. // Check if required cache directories exist and are writable.
  190. if ($iniVars['Cache']['cache_output'] == 'file' ||
  191. $iniVars['Cache']['cache_output'] == 'both') {
  192. $required = array('account', 'ADOdb', 'char', 'corp', 'eve', 'map', 'server');
  193. foreach ($required as $section) {
  194. if (!is_dir(YAPEAL_CACHE . $section)) {
  195. $mess = 'Missing required directory ' . YAPEAL_CACHE . $section . PHP_EOL;
  196. fwrite(STDERR, $mess);
  197. exit(2);
  198. };
  199. if (!is_writable(YAPEAL_CACHE . $section)) {
  200. $mess = YAPEAL_CACHE . $section . ' is not writable.' . PHP_EOL;
  201. fwrite(STDERR, $mess);
  202. exit(2);
  203. };
  204. };// foreach $required ...
  205. };// if $iniVars['Cache']['cache_output'] == 'file' || ...
  206. // Check for required Database section settings.
  207. $required = array('database', 'driver', 'host', 'suffix', 'table_prefix',
  208. 'username', 'password');
  209. $mess = '';
  210. foreach ($required as $setting) {
  211. if (!isset($iniVars['Database'][$setting])) {
  212. $mess .= 'Missing required setting ' . $setting;
  213. $mess .= ' in section [Database].' . PHP_EOL;
  214. };
  215. };// foreach $required ...
  216. if (!empty($mess)) {
  217. fwrite(STDERR, $mess);
  218. exit(2);
  219. };
  220. // Check for the required non-section general settings.
  221. if (!isset($iniVars['application_agent'])) {
  222. $mess = 'Configuration file is outdated and "application_agent" is not set.' . PHP_EOL;
  223. fwrite(STDERR, $mess);
  224. exit(2);
  225. };// if isset $iniVars['application_agent'] ...
  226. if (!isset($iniVars['registered_mode'])) {
  227. $mess = 'Configuration file is outdated and "registered_mode" is not set.' . PHP_EOL;
  228. fwrite(STDERR, $mess);
  229. exit(2);
  230. };
  231. $required = array('ignored','optional','required');
  232. if (!in_array($iniVars['registered_mode'], $required)) {
  233. $mess = 'Unknown value ' . $iniVars['registered_mode'];
  234. $mess .= ' for "registered_mode" in configuration file.' . PHP_EOL;
  235. fwrite(STDERR, $mess);
  236. exit(2);
  237. };
  238. $mess = 'All tests passed!!!' . PHP_EOL;
  239. fwrite(STDOUT, $mess);
  240. exit(0);
  241. ?>