backend.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "autoload.php";
  31. require_once "sessions.php";
  32. require_once "functions.php";
  33. require_once "config.php";
  34. require_once "db.php";
  35. require_once "db-prefs.php";
  36. startup_gettext();
  37. $script_started = microtime(true);
  38. if (!init_plugins()) 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( "admin", null);
  45. }
  46. if ($_SESSION["uid"]) {
  47. if (!validate_session()) {
  48. header("Content-Type: text/json");
  49. print error_json(6);
  50. return;
  51. }
  52. load_user_plugins( $_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 => __("15 minutes"),
  66. 30 => __("30 minutes"),
  67. 60 => __("Hourly"),
  68. 240 => __("4 hours"),
  69. 720 => __("12 hours"),
  70. 1440 => __("Daily"),
  71. 10080 => __("Weekly"));
  72. $update_intervals_nodefault = array(
  73. -1 => __("Disable updates"),
  74. 15 => __("15 minutes"),
  75. 30 => __("30 minutes"),
  76. 60 => __("Hourly"),
  77. 240 => __("4 hours"),
  78. 720 => __("12 hours"),
  79. 1440 => __("Daily"),
  80. 10080 => __("Weekly"));
  81. $access_level_names = array(
  82. 0 => __("User"),
  83. 5 => __("Power User"),
  84. 10 => __("Administrator"));
  85. $op = str_replace("-", "_", $op);
  86. $override = PluginHost::getInstance()->lookup_handler($op, $method);
  87. if (class_exists($op) || $override) {
  88. if ($override) {
  89. $handler = $override;
  90. } else {
  91. $handler = new $op($_REQUEST);
  92. }
  93. if ($handler && implements_interface($handler, 'IHandler')) {
  94. if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
  95. if ($handler->before($method)) {
  96. if ($method && method_exists($handler, $method)) {
  97. $handler->$method();
  98. } else {
  99. if (method_exists($handler, "catchall")) {
  100. $handler->catchall($method);
  101. }
  102. }
  103. $handler->after();
  104. return;
  105. } else {
  106. header("Content-Type: text/json");
  107. print error_json(6);
  108. return;
  109. }
  110. } else {
  111. header("Content-Type: text/json");
  112. print error_json(6);
  113. return;
  114. }
  115. }
  116. }
  117. header("Content-Type: text/json");
  118. print error_json(13);
  119. ?>