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.1KB

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