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 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. #declare(strict_types=1);
  3. $ENV = ENV::go();
  4. // Function used for pagination of peer/snatch/download lists on details.php
  5. function js_pages($Action, $TorrentID, $NumResults, $CurrentPage)
  6. {
  7. $NumPages = ceil($NumResults / 100);
  8. $PageLinks = [];
  9. for ($i = 1; $i <= $NumPages; $i++) {
  10. if ($i === $CurrentPage) {
  11. $PageLinks[] = $i;
  12. } else {
  13. $PageLinks[] = "<a href='#' onclick='$Action($TorrentID, $i)'>$i</a>";
  14. }
  15. }
  16. return implode(' | ', $PageLinks);
  17. }
  18. /**
  19. * Main switchboard
  20. */
  21. if (!empty($_REQUEST['action'])) {
  22. switch ($_REQUEST['action']) {
  23. case 'edit':
  24. enforce_login();
  25. require_once "$ENV->SERVER_ROOT/sections/torrents/edit.php";
  26. break;
  27. case 'editgroup':
  28. enforce_login();
  29. require_once "$ENV->SERVER_ROOT/sections/torrents/editgroup.php";
  30. break;
  31. case 'editgroupid':
  32. enforce_login();
  33. require_once "$ENV->SERVER_ROOT/sections/torrents/editgroupid.php";
  34. break;
  35. case 'changecategory':
  36. enforce_login();
  37. require_once "$ENV->SERVER_ROOT/sections/torrents/takechangecategory.php";
  38. break;
  39. case 'grouplog':
  40. enforce_login();
  41. require_once "$ENV->SERVER_ROOT/sections/torrents/grouplog.php";
  42. break;
  43. case 'takeedit':
  44. enforce_login();
  45. require_once "$ENV->SERVER_ROOT/sections/torrents/takeedit.php";
  46. break;
  47. case 'newgroup':
  48. enforce_login();
  49. require_once "$ENV->SERVER_ROOT/sections/torrents/takenewgroup.php";
  50. break;
  51. case 'peerlist':
  52. enforce_login();
  53. require_once "$ENV->SERVER_ROOT/sections/torrents/peerlist.php";
  54. break;
  55. case 'snatchlist':
  56. enforce_login();
  57. require_once "$ENV->SERVER_ROOT/sections/torrents/snatchlist.php";
  58. break;
  59. case 'downloadlist':
  60. enforce_login();
  61. require_once "$ENV->SERVER_ROOT/sections/torrents/downloadlist.php";
  62. break;
  63. case 'redownload':
  64. enforce_login();
  65. require_once "$ENV->SERVER_ROOT/sections/torrents/redownload.php";
  66. break;
  67. case 'revert':
  68. case 'takegroupedit':
  69. enforce_login();
  70. require_once "$ENV->SERVER_ROOT/sections/torrents/takegroupedit.php";
  71. break;
  72. case 'screenshotedit':
  73. enforce_login();
  74. require_once "$ENV->SERVER_ROOT/sections/torrents/screenshotedit.php";
  75. break;
  76. case 'nonwikiedit':
  77. enforce_login();
  78. require_once "$ENV->SERVER_ROOT/sections/torrents/nonwikiedit.php";
  79. break;
  80. case 'rename':
  81. enforce_login();
  82. require_once "$ENV->SERVER_ROOT/sections/torrents/rename.php";
  83. break;
  84. case 'merge':
  85. enforce_login();
  86. require_once "$ENV->SERVER_ROOT/sections/torrents/merge.php";
  87. break;
  88. case 'add_alias':
  89. enforce_login();
  90. require_once "$ENV->SERVER_ROOT/sections/torrents/add_alias.php";
  91. break;
  92. case 'delete_alias':
  93. enforce_login();
  94. authorize();
  95. require_once "$ENV->SERVER_ROOT/sections/torrents/delete_alias.php";
  96. break;
  97. case 'history':
  98. enforce_login();
  99. require_once "$ENV->SERVER_ROOT/sections/torrents/history.php";
  100. break;
  101. case 'delete':
  102. enforce_login();
  103. require_once "$ENV->SERVER_ROOT/sections/torrents/delete.php";
  104. break;
  105. case 'takedelete':
  106. enforce_login();
  107. require_once "$ENV->SERVER_ROOT/sections/torrents/takedelete.php";
  108. break;
  109. case 'masspm':
  110. enforce_login();
  111. require_once "$ENV->SERVER_ROOT/sections/torrents/masspm.php";
  112. break;
  113. case 'reseed':
  114. enforce_login();
  115. require_once "$ENV->SERVER_ROOT/sections/torrents/reseed.php";
  116. break;
  117. case 'takemasspm':
  118. enforce_login();
  119. require_once "$ENV->SERVER_ROOT/sections/torrents/takemasspm.php";
  120. break;
  121. case 'add_tag':
  122. enforce_login();
  123. require_once "$ENV->SERVER_ROOT/sections/torrents/add_tag.php";
  124. break;
  125. case 'delete_tag':
  126. enforce_login();
  127. authorize();
  128. require_once "$ENV->SERVER_ROOT/sections/torrents/delete_tag.php";
  129. break;
  130. case 'notify':
  131. enforce_login();
  132. require_once "$ENV->SERVER_ROOT/sections/torrents/notify.php";
  133. break;
  134. case 'manage_artists':
  135. enforce_login();
  136. require_once "$ENV->SERVER_ROOT/sections/torrents/manage_artists.php";
  137. break;
  138. case 'notify_clear':
  139. case 'notify_clear_item':
  140. case 'notify_clear_items':
  141. case 'notify_clearitem':
  142. case 'notify_clear_filter':
  143. case 'notify_cleargroup':
  144. case 'notify_catchup':
  145. case 'notify_catchup_filter':
  146. enforce_login();
  147. authorize();
  148. require_once "$ENV->SERVER_ROOT/sections/torrents/notify_actions.php";
  149. break;
  150. case 'download':
  151. require_once "$ENV->SERVER_ROOT/sections/torrents/download.php";
  152. break;
  153. case 'regen_filelist':
  154. if (check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
  155. Torrents::regenerate_filelist($_GET['torrentid']);
  156. header('Location: torrents.php?torrentid='.$_GET['torrentid']);
  157. error();
  158. } else {
  159. error(403);
  160. }
  161. break;
  162. case 'fix_group':
  163. if ((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
  164. $DB->prepare_query("
  165. SELECT
  166. COUNT(`ID`)
  167. FROM
  168. `torrents`
  169. WHERE
  170. `GroupID` = '$_GET[groupid]'
  171. ");
  172. $DB->exec_prepared_query();
  173. list($Count) = $DB->next_record();
  174. if ($Count === 0) {
  175. Torrents::delete_group($_GET['groupid']);
  176. }
  177. if (!empty($_GET['artistid']) && is_number($_GET['artistid'])) {
  178. header('Location: artist.php?id='.$_GET['artistid']);
  179. } else {
  180. header('Location: torrents.php?id='.$_GET['groupid']);
  181. }
  182. } else {
  183. error(403);
  184. }
  185. break;
  186. case 'add_cover_art':
  187. require_once "$ENV->SERVER_ROOT/sections/torrents/add_cover_art.php";
  188. break;
  189. case 'remove_cover_art':
  190. require_once "$ENV->SERVER_ROOT/sections/torrents/remove_cover_art.php";
  191. break;
  192. case 'autocomplete_tags':
  193. require_once "$ENV->SERVER_ROOT/sections/torrents/autocomplete_tags.php";
  194. break;
  195. default:
  196. enforce_login();
  197. if (!empty($_GET['id'])) {
  198. require_once "$ENV->SERVER_ROOT/sections/torrents/details.php";
  199. } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
  200. $DB->query("
  201. SELECT
  202. `GroupID`
  203. FROM
  204. `torrents`
  205. WHERE
  206. `ID` = '$_GET[torrentid]'
  207. ");
  208. list($GroupID) = $DB->next_record();
  209. if ($GroupID) {
  210. header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid']);
  211. }
  212. } else {
  213. require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
  214. }
  215. break;
  216. } # switch
  217. }
  218. # If $_REQUEST['action'] is empty
  219. else {
  220. enforce_login();
  221. if (!empty($_GET['id'])) {
  222. require_once "$ENV->SERVER_ROOT/sections/torrents/details.php";
  223. } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
  224. $DB->query("
  225. SELECT
  226. `GroupID`
  227. FROM
  228. `torrents`
  229. WHERE
  230. `ID` = '$_GET[torrentid]'
  231. ");
  232. list($GroupID) = $DB->next_record();
  233. if ($GroupID) {
  234. header("Location: torrents.php?id=$GroupID&torrentid=".$_GET['torrentid'].'#torrent'.$_GET['torrentid']);
  235. } else {
  236. header("Location: log.php?search=Torrent+$_GET[torrentid]");
  237. }
  238. } elseif (!empty($_GET['type'])) {
  239. require_once "$ENV->SERVER_ROOT/sections/torrents/user.php";
  240. } elseif (!empty($_GET['groupname']) && !empty($_GET['forward'])) {
  241. $DB->prepare_query("
  242. SELECT
  243. `id`
  244. FROM
  245. `torrents_group`
  246. WHERE
  247. `title` LIKE '$_GET[groupname]'
  248. ");
  249. list($GroupID) = $DB->next_record();
  250. if ($GroupID) {
  251. header("Location: torrents.php?id=$GroupID");
  252. } else {
  253. require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
  254. }
  255. } else {
  256. require_once "$ENV->SERVER_ROOT/sections/torrents/browse.php";
  257. }
  258. }