backend.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. set_include_path(get_include_path() . PATH_SEPARATOR .
  3. dirname(__FILE__) . "/include");
  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 "functions.php";
  31. require_once "sessions.php";
  32. require_once "sanity_check.php";
  33. require_once "config.php";
  34. require_once "db.php";
  35. require_once "db-prefs.php";
  36. no_cache_incantation();
  37. startup_gettext();
  38. $script_started = getmicrotime();
  39. $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  40. if (!init_connection($link)) return;
  41. header("Content-Type: text/plain; charset=utf-8");
  42. if (ENABLE_GZIP_OUTPUT) {
  43. ob_start("ob_gzhandler");
  44. }
  45. if (SINGLE_USER_MODE) {
  46. authenticate_user($link, "admin", null);
  47. }
  48. // TODO remove and handle within Handlers
  49. if (!($_SESSION["uid"] && validate_session($link))) {
  50. if ($op == 'pref-feeds' && $method == 'add') {
  51. header("Content-Type: text/html");
  52. login_sequence($link);
  53. render_login_form($link);
  54. } else {
  55. header("Content-Type: text/plain");
  56. print json_encode(array("error" => array("code" => 6)));
  57. }
  58. return;
  59. }
  60. $purge_intervals = array(
  61. 0 => __("Use default"),
  62. -1 => __("Never purge"),
  63. 5 => __("1 week old"),
  64. 14 => __("2 weeks old"),
  65. 31 => __("1 month old"),
  66. 60 => __("2 months old"),
  67. 90 => __("3 months old"));
  68. $update_intervals = array(
  69. 0 => __("Default interval"),
  70. -1 => __("Disable updates"),
  71. 15 => __("Each 15 minutes"),
  72. 30 => __("Each 30 minutes"),
  73. 60 => __("Hourly"),
  74. 240 => __("Each 4 hours"),
  75. 720 => __("Each 12 hours"),
  76. 1440 => __("Daily"),
  77. 10080 => __("Weekly"));
  78. $update_intervals_nodefault = array(
  79. -1 => __("Disable updates"),
  80. 15 => __("Each 15 minutes"),
  81. 30 => __("Each 30 minutes"),
  82. 60 => __("Hourly"),
  83. 240 => __("Each 4 hours"),
  84. 720 => __("Each 12 hours"),
  85. 1440 => __("Daily"),
  86. 10080 => __("Weekly"));
  87. $update_methods = array(
  88. 0 => __("Default"),
  89. 1 => __("Magpie"),
  90. 2 => __("SimplePie"),
  91. 3 => __("Twitter OAuth"));
  92. if (DEFAULT_UPDATE_METHOD == "1") {
  93. $update_methods[0] .= ' (SimplePie)';
  94. } else {
  95. $update_methods[0] .= ' (Magpie)';
  96. }
  97. $access_level_names = array(
  98. 0 => __("User"),
  99. 5 => __("Power User"),
  100. 10 => __("Administrator"));
  101. $error = sanity_check($link);
  102. if ($error['code'] != 0 && $op != "logout") {
  103. print json_encode(array("error" => $error));
  104. return;
  105. }
  106. function __autoload($class) {
  107. $file = "classes/".strtolower(basename($class)).".php";
  108. if (file_exists($file)) {
  109. require $file;
  110. }
  111. }
  112. $op = str_replace("-", "_", $op);
  113. if (class_exists($op)) {
  114. $handler = new $op($link, $_REQUEST);
  115. if ($handler) {
  116. if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
  117. if ($handler->before($method)) {
  118. if ($method && method_exists($handler, $method)) {
  119. $handler->$method();
  120. }
  121. $handler->after();
  122. return;
  123. }
  124. } else {
  125. header("Content-Type: text/plain");
  126. print json_encode(array("error" => array("code" => 6)));
  127. return;
  128. }
  129. }
  130. }
  131. header("Content-Type: text/plain");
  132. print json_encode(array("error" => array("code" => 7)));
  133. // We close the connection to database.
  134. db_close($link);
  135. ?>