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.

takereport.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * This page handles the backend from when a user submits a report.
  4. * It checks for (in order):
  5. * 1. The usual POST injections, then checks that things.
  6. * 2. Things that are required by the report type are filled
  7. * ('1' in the report_fields array).
  8. * 3. Things that are filled are filled with correct things.
  9. * 4. That the torrent you're reporting still exists.
  10. *
  11. * Then it just inserts the report to the DB and increments the counter.
  12. */
  13. authorize();
  14. $TorrentID = (int) $_POST['torrentid'];
  15. $CategoryID = (int) $_POST['categoryid'];
  16. Security::checkInt($TorrentID, $CategoryID);
  17. if (!isset($_POST['type'])) {
  18. error(404);
  19. } elseif (array_key_exists($_POST['type'], $Types[$CategoryID])) {
  20. $Type = $_POST['type'];
  21. $ReportType = $Types[$CategoryID][$Type];
  22. } elseif (array_key_exists($_POST['type'], $Types['master'])) {
  23. $Type = $_POST['type'];
  24. $ReportType = $Types['master'][$Type];
  25. } else {
  26. // There was a type but it wasn't an option!
  27. error(403);
  28. }
  29. foreach ($ReportType['report_fields'] as $Field => $Value) {
  30. if ($Value === '1') {
  31. if (empty($_POST[$Field])) {
  32. $Err = "You are missing a required field ($Field) for a ".$ReportType['title'].' report.';
  33. }
  34. }
  35. }
  36. if (!empty($_POST['sitelink'])) {
  37. if (preg_match_all('/'.TORRENT_REGEX.'/i', $_POST['sitelink'], $Matches)) {
  38. $ExtraIDs = implode(' ', $Matches[4]);
  39. if (in_array($TorrentID, $Matches[4])) {
  40. $Err = "The extra permalinks you gave included the link to the torrent you're reporting!";
  41. }
  42. } else {
  43. $Err = 'The permalink was incorrect. It should look like '.site_url().'torrents.php?torrentid=12345';
  44. }
  45. }
  46. if (!empty($_POST['link'])) {
  47. // resource_type://domain:port/filepathname?query_string#anchor
  48. if (preg_match_all('/'.URL_REGEX.'/is', $_POST['link'], $Matches)) {
  49. $Links = implode(' ', $Matches[0]);
  50. } else {
  51. $Err = "The extra links you provided weren't links...";
  52. }
  53. } else {
  54. $Links = '';
  55. }
  56. if (!empty($_POST['image'])) {
  57. if (preg_match("/^(".IMAGE_REGEX.")( ".IMAGE_REGEX.")*$/is", trim($_POST['image']), $Matches)) {
  58. $Images = $Matches[0];
  59. } else {
  60. $Err = "The extra image links you provided weren't links to images...";
  61. }
  62. } else {
  63. $Images = '';
  64. }
  65. if (!empty($_POST['track'])) {
  66. if (preg_match('/([0-9]+( [0-9]+)*)|All/is', $_POST['track'], $Matches)) {
  67. $Tracks = $Matches[0];
  68. } else {
  69. $Err = 'Tracks should be given in a space-separated list of numbers with no other characters.';
  70. }
  71. } else {
  72. $Tracks = '';
  73. }
  74. if (!empty($_POST['extra'])) {
  75. $Extra = db_string($_POST['extra']);
  76. } else {
  77. $Err = 'As useful as blank reports are, could you be a tiny bit more helpful? (Leave a comment)';
  78. }
  79. $DB->prepared_query("
  80. SELECT `GroupID`
  81. FROM `torrents`
  82. WHERE `ID` = '$TorrentID'
  83. ");
  84. if (!$DB->has_results()) {
  85. $Err = "A torrent with that ID doesn't exist!";
  86. }
  87. list($GroupID) = $DB->next_record();
  88. if (!empty($Err)) {
  89. error($Error = $Err, $Debug = false);
  90. include(SERVER_ROOT.'/sections/reportsv2/report.php');
  91. error();
  92. }
  93. $DB->prepared_query("
  94. SELECT `ID`
  95. FROM `reportsv2`
  96. WHERE `TorrentID` = '$TorrentID'
  97. AND `ReporterID` = ".db_string($LoggedUser['ID'])."
  98. AND `ReportedTime` > '".time_minus(3)."'");
  99. if ($DB->has_results()) {
  100. header("Location: torrents.php?torrentid=$TorrentID");
  101. error();
  102. }
  103. $DB->prepared_query("
  104. INSERT INTO `reportsv2`
  105. (`ReporterID`, `TorrentID`, `Type`, `UserComment`, `Status`, `ReportedTime`, `Track`, `Image`, `ExtraID`, `Link`)
  106. VALUES
  107. (".db_string($LoggedUser['ID']).", $TorrentID, '".db_string($Type)."', '$Extra', 'New', NOW(), '".db_string($Tracks)."', '".db_string($Images)."', '".db_string($ExtraIDs)."', '".db_string($Links)."')");
  108. $ReportID = $DB->inserted_id();
  109. $DB->prepared_query("
  110. SELECT `UserID`
  111. FROM `torrents`
  112. WHERE `ID` = $TorrentID");
  113. list($UploaderID) = $DB->next_record();
  114. $DB->prepared_query("
  115. SELECT `title`, `subject`, `object`
  116. FROM `torrents_group`
  117. WHERE `id` = '$GroupID'
  118. ");
  119. list($GroupNameEng, $GroupTitle2, $GroupNameJP) = $DB->next_record();
  120. $GroupName = $GroupNameEng ? $GroupNameEng : ($GroupTitle2 ? $GroupTitle2 : $GroupNameJP);
  121. Misc::send_pm($UploaderID, 0, "Torrent Reported: $GroupName", "Your torrent, \"[url=".site_url()."torrents.php?torrentid=$TorrentID]".$GroupName."[/url]\", was reported for the reason \"".$ReportType['title']."\".\n\nThe reporter also said: \"$Extra\"\n\nIf you think this report was in error, please contact staff. Failure to challenge some types of reports in a timely manner will be regarded as a lack of defense and may result in the torrent being deleted.");
  122. $Cache->delete_value("reports_torrent_$TorrentID");
  123. $Cache->increment('num_torrent_reportsv2');
  124. header("Location: torrents.php?torrentid=$TorrentID");