backend.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. startup_gettext();
  36. $script_started = microtime(true);
  37. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  38. if (!init_connection($link)) return;
  39. header("Content-Type: text/json; charset=utf-8");
  40. if (ENABLE_GZIP_OUTPUT && function_exists("ob_gzhandler")) {
  41. ob_start("ob_gzhandler");
  42. }
  43. if (SINGLE_USER_MODE) {
  44. authenticate_user($link, "admin", null);
  45. }
  46. if ($_SESSION["uid"]) {
  47. if (!validate_session($link)) {
  48. header("Content-Type: text/json");
  49. print json_encode(array("error" => array("code" => 6)));
  50. return;
  51. }
  52. load_user_plugins($link, $_SESSION["uid"]);
  53. }
  54. $purge_intervals = array(
  55. 0 => __("Use default"),
  56. -1 => __("Never purge"),
  57. 5 => __("1 week old"),
  58. 14 => __("2 weeks old"),
  59. 31 => __("1 month old"),
  60. 60 => __("2 months old"),
  61. 90 => __("3 months old"));
  62. $update_intervals = array(
  63. 0 => __("Default interval"),
  64. -1 => __("Disable updates"),
  65. 15 => __("Each 15 minutes"),
  66. 30 => __("Each 30 minutes"),
  67. 60 => __("Hourly"),
  68. 240 => __("Each 4 hours"),
  69. 720 => __("Each 12 hours"),
  70. 1440 => __("Daily"),
  71. 10080 => __("Weekly"));
  72. $update_intervals_nodefault = array(
  73. -1 => __("Disable updates"),
  74. 15 => __("Each 15 minutes"),
  75. 30 => __("Each 30 minutes"),
  76. 60 => __("Hourly"),
  77. 240 => __("Each 4 hours"),
  78. 720 => __("Each 12 hours"),
  79. 1440 => __("Daily"),
  80. 10080 => __("Weekly"));
  81. $access_level_names = array(
  82. 0 => __("User"),
  83. 5 => __("Power User"),
  84. 10 => __("Administrator"));
  85. #$error = sanity_check($link);
  86. #if ($error['code'] != 0 && $op != "logout") {
  87. # print json_encode(array("error" => $error));
  88. # return;
  89. #}
  90. $op = str_replace("-", "_", $op);
  91. global $pluginhost;
  92. $override = $pluginhost->lookup_handler($op, $method);
  93. if (class_exists($op) || $override) {
  94. if ($override) {
  95. $handler = $override;
  96. } else {
  97. $handler = new $op($link, $_REQUEST);
  98. }
  99. if ($handler && implements_interface($handler, 'IHandler')) {
  100. if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
  101. if ($handler->before($method)) {
  102. if ($method && method_exists($handler, $method)) {
  103. $handler->$method();
  104. } else {
  105. if (method_exists($handler, "catchall")) {
  106. $handler->catchall($method);
  107. }
  108. }
  109. $handler->after();
  110. return;
  111. } else {
  112. header("Content-Type: text/json");
  113. print json_encode(array("error" => array("code" => 6)));
  114. return;
  115. }
  116. } else {
  117. header("Content-Type: text/json");
  118. print json_encode(array("error" => array("code" => 6)));
  119. return;
  120. }
  121. }
  122. }
  123. header("Content-Type: text/json");
  124. print json_encode(array("error" => array("code" => 7)));
  125. // We close the connection to database.
  126. db_close($link);
  127. ?>