PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/backend.php

https://github.com/krihal/Tiny-Tiny-RSS
PHP | 155 lines | 115 code | 32 blank | 8 comment | 23 complexity | 7e176b171cf6bd2fd3b4b124214f078d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-3.0, GPL-2.0
  1. <?php
  2. set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
  3. get_include_path());
  4. /* remove ill effects of magic quotes */
  5. if (get_magic_quotes_gpc()) {
  6. function stripslashes_deep($value) {
  7. $value = is_array($value) ?
  8. array_map('stripslashes_deep', $value) : stripslashes($value);
  9. return $value;
  10. }
  11. $_POST = array_map('stripslashes_deep', $_POST);
  12. $_GET = array_map('stripslashes_deep', $_GET);
  13. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  14. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  15. }
  16. $op = $_REQUEST["op"];
  17. @$method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"];
  18. if (!$method)
  19. $method = 'index';
  20. else
  21. $method = strtolower($method);
  22. /* Public calls compatibility shim */
  23. $public_calls = array("globalUpdateFeeds", "rss", "getUnread", "getProfiles", "share",
  24. "fbexport", "logout", "pubsub");
  25. if (array_search($op, $public_calls) !== false) {
  26. header("Location: public.php?" . $_SERVER['QUERY_STRING']);
  27. return;
  28. }
  29. @$csrf_token = $_REQUEST['csrf_token'];
  30. require_once "sessions.php";
  31. require_once "functions.php";
  32. require_once "config.php";
  33. require_once "db.php";
  34. require_once "db-prefs.php";
  35. no_cache_incantation();
  36. startup_gettext();
  37. $script_started = microtime(true);
  38. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  39. if (!init_connection($link)) return;
  40. header("Content-Type: text/json; charset=utf-8");
  41. if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
  42. ob_start("ob_gzhandler");
  43. }
  44. if (SINGLE_USER_MODE) {
  45. authenticate_user($link, "admin", null);
  46. }
  47. if ($_SESSION["uid"]) {
  48. load_user_plugins($link, $_SESSION["uid"]);
  49. }
  50. $purge_intervals = array(
  51. 0 => __("Use default"),
  52. -1 => __("Never purge"),
  53. 5 => __("1 week old"),
  54. 14 => __("2 weeks old"),
  55. 31 => __("1 month old"),
  56. 60 => __("2 months old"),
  57. 90 => __("3 months old"));
  58. $update_intervals = array(
  59. 0 => __("Default interval"),
  60. -1 => __("Disable updates"),
  61. 15 => __("Each 15 minutes"),
  62. 30 => __("Each 30 minutes"),
  63. 60 => __("Hourly"),
  64. 240 => __("Each 4 hours"),
  65. 720 => __("Each 12 hours"),
  66. 1440 => __("Daily"),
  67. 10080 => __("Weekly"));
  68. $update_intervals_nodefault = array(
  69. -1 => __("Disable updates"),
  70. 15 => __("Each 15 minutes"),
  71. 30 => __("Each 30 minutes"),
  72. 60 => __("Hourly"),
  73. 240 => __("Each 4 hours"),
  74. 720 => __("Each 12 hours"),
  75. 1440 => __("Daily"),
  76. 10080 => __("Weekly"));
  77. $access_level_names = array(
  78. 0 => __("User"),
  79. 5 => __("Power User"),
  80. 10 => __("Administrator"));
  81. #$error = sanity_check($link);
  82. #if ($error['code'] != 0 && $op != "logout") {
  83. # print json_encode(array("error" => $error));
  84. # return;
  85. #}
  86. $op = str_replace("-", "_", $op);
  87. global $pluginhost;
  88. $override = $pluginhost->lookup_handler($op, $method);
  89. if (class_exists($op) || $override) {
  90. if ($override) {
  91. $handler = $override;
  92. } else {
  93. $handler = new $op($link, $_REQUEST);
  94. }
  95. if ($handler && implements_interface($handler, 'IHandler')) {
  96. if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
  97. if ($handler->before($method)) {
  98. if ($method && method_exists($handler, $method)) {
  99. $handler->$method();
  100. } else {
  101. if (method_exists($handler, "catchall")) {
  102. $handler->catchall($method);
  103. }
  104. }
  105. $handler->after();
  106. return;
  107. } else {
  108. header("Content-Type: text/json");
  109. print json_encode(array("error" => array("code" => 6)));
  110. return;
  111. }
  112. } else {
  113. header("Content-Type: text/json");
  114. print json_encode(array("error" => array("code" => 6)));
  115. return;
  116. }
  117. }
  118. }
  119. header("Content-Type: text/json");
  120. print json_encode(array("error" => array("code" => 7)));
  121. // We close the connection to database.
  122. db_close($link);
  123. ?>