BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * AJAX switch center
  5. *
  6. * This page acts as an AJAX "switch" - it's called by scripts, and it includes the required pages.
  7. * The required page is determined by $_GET['action'].
  8. */
  9. $ENV = ENV::go();
  10. # $_POST login cookie
  11. if (!isset($FullToken)) {
  12. enforce_login();
  13. }
  14. /**
  15. * These users aren't rate limited.
  16. * This array should contain user IDs.
  17. */
  18. # Get people with Donor permissions
  19. $Donors = $DB->query("
  20. SELECT
  21. `ID`
  22. FROM
  23. `users_main`
  24. WHERE
  25. `PermissionID` = 20
  26. ");
  27. # Add Donors to $UserExceptions or define manually
  28. if ($DB->record_count()) {
  29. $UserExceptions = array_unique($DB->collect('ID'));
  30. } else {
  31. $UserExceptions = array(
  32. # 1, 2, 3, etc.
  33. );
  34. }
  35. # System and admin fix
  36. array_push($UserExceptions, 0, 1);
  37. /**
  38. * $AjaxLimit = array($x, $y) = $x requests every $y seconds,
  39. * e.g., array(5, 10) = 5 requests every 10 seconds.
  40. */
  41. $AjaxLimit = array(1, 6);
  42. $UserID = $LoggedUser['ID'];
  43. # Set proper headers for JSON output
  44. # https://github.com/OPSnet/Gazelle/blob/master/sections/api/index.php
  45. if (!empty($_SERVER['CONTENT_TYPE']) && substr($_SERVER['CONTENT_TYPE'], 0, 16) === 'application/json') {
  46. $_POST = json_decode(file_get_contents('php://input'), true);
  47. }
  48. header('Content-Type: application/json; charset=utf-8');
  49. # Enforce rate limiting everywhere
  50. if (!in_array($UserID, $UserExceptions) && isset($_GET['action'])) {
  51. if (!$UserRequests = $Cache->get_value("ajax_requests_$UserID")) {
  52. $UserRequests = 0;
  53. $Cache->cache_value("ajax_requests_$UserID", '0', $AjaxLimit[1]);
  54. }
  55. if ($UserRequests > $AjaxLimit[0]) {
  56. json_die('failure', 'rate limit exceeded');
  57. } else {
  58. $Cache->increment_value("ajax_requests_$UserID");
  59. }
  60. }
  61. /**
  62. * Actions
  63. */
  64. switch ($_GET['action']) {
  65. /**
  66. * Torrents
  67. */
  68. case 'torrent':
  69. require_once "$ENV->SERVER_ROOT/sections/api/torrents/torrent.php";
  70. break;
  71. case 'group':
  72. require_once "$ENV->SERVER_ROOT/sections/api/torrents/group.php";
  73. break;
  74. // So the album art script can function without breaking the rate limit
  75. case 'torrentgroupalbumart':
  76. require_once "$ENV->SERVER_ROOT/sections/api/torrentgroupalbumart.php";
  77. break;
  78. case 'browse':
  79. require_once "$ENV->SERVER_ROOT/sections/api/browse.php";
  80. break;
  81. case 'tcomments':
  82. require_once "$ENV->SERVER_ROOT/sections/api/tcomments.php";
  83. break;
  84. /**
  85. * Features
  86. */
  87. case 'collage':
  88. require_once "$ENV->SERVER_ROOT/sections/api/collage.php";
  89. break;
  90. case 'artist':
  91. require_once "$ENV->SERVER_ROOT/sections/api/artist.php";
  92. break;
  93. case 'request':
  94. require_once "$ENV->SERVER_ROOT/sections/api/request.php";
  95. break;
  96. case 'requests':
  97. require_once "$ENV->SERVER_ROOT/sections/api/requests.php";
  98. break;
  99. case 'top10':
  100. require_once "$ENV->SERVER_ROOT/sections/api/top10/index.php";
  101. break;
  102. /**
  103. * Users
  104. */
  105. case 'user':
  106. require_once "$ENV->SERVER_ROOT/sections/api/user.php";
  107. break;
  108. case 'usersearch':
  109. require_once "$ENV->SERVER_ROOT/sections/api/usersearch.php";
  110. break;
  111. case 'community_stats':
  112. require_once "$ENV->SERVER_ROOT/sections/api/community_stats.php";
  113. break;
  114. case 'user_recents':
  115. require_once "$ENV->SERVER_ROOT/sections/api/user_recents.php";
  116. break;
  117. case 'userhistory':
  118. require_once "$ENV->SERVER_ROOT/sections/api/userhistory/index.php";
  119. break;
  120. /**
  121. * Account
  122. */
  123. case 'inbox':
  124. require_once "$ENV->SERVER_ROOT/sections/api/inbox/index.php";
  125. break;
  126. case 'bookmarks':
  127. require_once "$ENV->SERVER_ROOT/sections/api/bookmarks/index.php";
  128. break;
  129. case 'notifications':
  130. require_once "$ENV->SERVER_ROOT/sections/api/notifications.php";
  131. break;
  132. case 'get_user_notifications':
  133. require_once "$ENV->SERVER_ROOT/sections/api/get_user_notifications.php";
  134. break;
  135. case 'clear_user_notification':
  136. require_once "$ENV->SERVER_ROOT/sections/api/clear_user_notification.php";
  137. break;
  138. /**
  139. * Forums
  140. */
  141. case 'forum':
  142. require_once "$ENV->SERVER_ROOT/sections/api/forum/index.php";
  143. break;
  144. case 'subscriptions':
  145. require_once "$ENV->SERVER_ROOT/sections/api/subscriptions.php";
  146. break;
  147. case 'raw_bbcode':
  148. require_once "$ENV->SERVER_ROOT/sections/api/raw_bbcode.php";
  149. break;
  150. /**
  151. * Meta
  152. */
  153. case 'index':
  154. require_once "$ENV->SERVER_ROOT/sections/api/info.php";
  155. break;
  156. case 'manifest':
  157. require_once "$ENV->SERVER_ROOT/manifest.php";
  158. json_die('success', manifest());
  159. break;
  160. case 'stats':
  161. require_once "$ENV->SERVER_ROOT/sections/api/stats.php";
  162. break;
  163. case 'loadavg':
  164. require_once "$ENV->SERVER_ROOT/sections/api/loadavg.php";
  165. break;
  166. case 'announcements':
  167. require_once "$ENV->SERVER_ROOT/sections/api/announcements.php";
  168. break;
  169. case 'wiki':
  170. require_once "$ENV->SERVER_ROOT/sections/api/wiki.php";
  171. break;
  172. case 'ontology':
  173. require_once "$ENV->SERVER_ROOT/sections/api/ontology.php";
  174. break;
  175. /**
  176. * Under construction
  177. */
  178. case 'preview':
  179. require_once "$ENV->SERVER_ROOT/sections/api/preview.php";
  180. break;
  181. case 'better':
  182. require_once "$ENV->SERVER_ROOT/sections/api/better/index.php";
  183. break;
  184. case 'get_friends':
  185. require_once "$ENV->SERVER_ROOT/sections/api/get_friends.php";
  186. break;
  187. case 'news_ajax':
  188. require_once "$ENV->SERVER_ROOT/sections/api/news_ajax.php";
  189. break;
  190. case 'send_recommendation':
  191. require_once "$ENV->SERVER_ROOT/sections/api/send_recommendation.php";
  192. break;
  193. /*
  194. case 'similar_artists':
  195. require_once "$ENV->SERVER_ROOT/sections/api/similar_artists.php";
  196. break;
  197. */
  198. /*
  199. case 'votefavorite':
  200. require_once "$ENV->SERVER_ROOT/sections/api/takevote.php";
  201. break;
  202. */
  203. /*
  204. case 'torrent_info':
  205. require_once "$ENV->SERVER_ROOT/sections/api/torrent_info.php";
  206. break;
  207. */
  208. /*
  209. case 'checkprivate':
  210. include "$ENV->SERVER_ROOT/sections/api/checkprivate.php";
  211. break;
  212. */
  213. case 'autofill':
  214. /*
  215. if ($_GET['cat'] === 'anime') {
  216. require_once "$ENV->SERVER_ROOT/sections/api/autofill/anime.php";
  217. }
  218. if ($_GET['cat'] === 'jav') {
  219. require_once "$ENV->SERVER_ROOT/sections/api/autofill/jav.php";
  220. }
  221. if ($_GET['cat'] === 'manga') {
  222. require_once "$ENV->SERVER_ROOT/sections/api/autofill/manga.php";
  223. }
  224. */
  225. break;
  226. default:
  227. // If they're screwing around with the query string
  228. json_die('failure');
  229. }