sanity_check.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. // WARNING: Don't ask for help on tt-rss.org forums or the bugtracker if you have
  3. // modified this file.
  4. function initial_sanity_check($link) {
  5. $errors = array();
  6. if (!file_exists("config.php")) {
  7. array_push($errors, "Configuration file not found. Looks like you forgot to copy config.php-dist to config.php and edit it.");
  8. } else {
  9. require_once "sanity_config.php";
  10. if (file_exists("install") && !file_exists("config.php")) {
  11. array_push($errors, "Please copy config.php-dist to config.php or run the installer in install/");
  12. }
  13. if (strpos(PLUGINS, "auth_") === FALSE) {
  14. array_push($errors, "Please enable at least one authentication module via PLUGINS constant in config.php");
  15. }
  16. if (function_exists('posix_getuid') && posix_getuid() == 0) {
  17. array_push($errors, "Please don't run this script as root.");
  18. }
  19. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  20. array_push($errors, "PHP version 5.3.0 or newer required.");
  21. }
  22. if (CONFIG_VERSION != EXPECTED_CONFIG_VERSION) {
  23. array_push($errors, "Configuration file (config.php) has incorrect version. Update it with new options from config.php-dist and set CONFIG_VERSION to the correct value.");
  24. }
  25. if (!is_writable(CACHE_DIR . "/images")) {
  26. array_push($errors, "Image cache is not writable (chmod -R 777 ".CACHE_DIR."/images)");
  27. }
  28. if (!is_writable(CACHE_DIR . "/export")) {
  29. array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)");
  30. }
  31. if (!is_writable(CACHE_DIR . "/js")) {
  32. array_push($errors, "Javascript cache is not writable (chmod -R 777 ".CACHE_DIR."/js)");
  33. }
  34. if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
  35. array_push($errors,
  36. "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh");
  37. }
  38. foreach ($requred_defines as $d) {
  39. if (!defined($d)) {
  40. array_push($errors,
  41. "Required configuration file parameter $d is not defined in config.php. You might need to copy it from config.php-dist.");
  42. }
  43. }
  44. if (SESSION_EXPIRE_TIME < 60) {
  45. array_push($errors, "SESSION_EXPIRE_TIME set in config.php is too low, please set it to an integer value >= 60");
  46. }
  47. if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME) {
  48. array_push($errors, "SESSION_EXPIRE_TIME set in config.php should be >= to SESSION_COOKIE_LIFETIME");
  49. }
  50. if (SINGLE_USER_MODE) {
  51. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  52. if ($link) {
  53. $result = db_query($link, "SELECT id FROM ttrss_users WHERE id = 1");
  54. if (db_num_rows($result) != 1) {
  55. array_push($errors, "SINGLE_USER_MODE is enabled in config.php but default admin account is not found.");
  56. }
  57. }
  58. }
  59. if (SELF_URL_PATH == "http://yourserver/tt-rss/") {
  60. if ($_SERVER['HTTP_REFERER']) {
  61. array_push($errors,
  62. "Please set SELF_URL_PATH to the correct value for your server (possible value: <b>" . $_SERVER['HTTP_REFERER'] . "</b>)");
  63. } else {
  64. array_push($errors, "Please set SELF_URL_PATH to the correct value for your server.");
  65. }
  66. }
  67. if (!is_writable(ICONS_DIR)) {
  68. array_push($errors, "ICONS_DIR defined in config.php is not writable (chmod -R 777 ".ICONS_DIR.").\n");
  69. }
  70. if (!is_writable(LOCK_DIRECTORY)) {
  71. array_push($errors, "LOCK_DIRECTORY defined in config.php is not writable (chmod -R 777 ".LOCK_DIRECTORY.").\n");
  72. }
  73. if (ini_get("open_basedir")) {
  74. array_push($errors, "PHP configuration option open_basedir is not supported. Please disable this in PHP settings file (php.ini).");
  75. }
  76. if (!function_exists("curl_init") && !ini_get("allow_url_fopen")) {
  77. array_push($errors, "PHP configuration option allow_url_fopen is disabled, and CURL functions are not present. Either enable allow_url_fopen or install PHP extension for CURL.");
  78. }
  79. if (!function_exists("json_encode")) {
  80. array_push($errors, "PHP support for JSON is required, but was not found.");
  81. }
  82. if (DB_TYPE == "mysql" && !function_exists("mysql_connect")) {
  83. array_push($errors, "PHP support for MySQL is required for configured DB_TYPE in config.php.");
  84. }
  85. if (DB_TYPE == "pgsql" && !function_exists("pg_connect")) {
  86. array_push($errors, "PHP support for PostgreSQL is required for configured DB_TYPE in config.php");
  87. }
  88. if (!function_exists("mb_strlen")) {
  89. array_push($errors, "PHP support for mbstring functions is required but was not found.");
  90. }
  91. if (!function_exists("hash")) {
  92. array_push($errors, "PHP support for hash() function is required but was not found.");
  93. }
  94. if (!function_exists("ctype_lower")) {
  95. array_push($errors, "PHP support for ctype functions are required by HTMLPurifier.");
  96. }
  97. if (!function_exists("iconv")) {
  98. array_push($errors, "PHP support for iconv is required to handle multiple charsets.");
  99. }
  100. /* if (ini_get("safe_mode")) {
  101. array_push($errors, "PHP safe mode setting is not supported.");
  102. } */
  103. if ((PUBSUBHUBBUB_HUB || PUBSUBHUBBUB_ENABLED) && !function_exists("curl_init")) {
  104. array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
  105. }
  106. if (!class_exists("DOMDocument")) {
  107. array_push($errors, "PHP support for DOMDocument is required, but was not found.");
  108. }
  109. }
  110. if (count($errors) > 0 && $_SERVER['REQUEST_URI']) { ?>
  111. <html>
  112. <head>
  113. <title>Startup failed</title>
  114. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  115. <link rel="stylesheet" type="text/css" href="utility.css">
  116. </head>
  117. <body>
  118. <div class="floatingLogo"><img src="images/logo_small.png"></div>
  119. <div class="content">
  120. <h1>Startup failed</h1>
  121. <p>Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade. Please fix
  122. errors indicated by the following messages:</p>
  123. <?php foreach ($errors as $error) { echo format_error($error); } ?>
  124. <p>You might want to check tt-rss <a href="http://tt-rss.org/wiki">wiki</a> or the
  125. <a href="http://tt-rss.org/forum">forums</a> for more information. Please search the forums before creating new topic
  126. for your question.</p>
  127. </div>
  128. </body>
  129. </html>
  130. <?php
  131. die;
  132. } else if (count($errors) > 0) {
  133. echo "Tiny Tiny RSS was unable to start properly. This usually means a misconfiguration or an incomplete upgrade.\n";
  134. echo "Please fix errors indicated by the following messages:\n\n";
  135. foreach ($errors as $error) {
  136. echo " * $error\n";
  137. }
  138. echo "\nYou might want to check tt-rss wiki or the forums for more information.\n";
  139. echo "Please search the forums before creating new topic for your question.\n";
  140. exit(-1);
  141. }
  142. }
  143. initial_sanity_check($link);
  144. ?>