PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/include/sanity_check.php

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