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.

file_checker.class.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. # todo: Leverage this class to parse file extensions
  3. # Work the expension parser on the upload form into this class
  4. $ComicsExtensions = array_fill_keys(array('cbr', 'cbz', 'gif', 'jpeg', 'jpg', 'pdf', 'png'), true);
  5. $MusicExtensions = array_fill_keys(
  6. array(
  7. 'ac3', 'accurip', 'azw3', 'chm', 'cue', 'djv', 'djvu', 'doc', 'dts', 'epub', 'ffp',
  8. 'flac', 'gif', 'htm', 'html', 'jpeg', 'jpg', 'lit', 'log', 'm3u', 'm3u8', 'm4a', 'm4b',
  9. 'md5', 'mobi', 'mp3', 'mp4', 'nfo', 'pdf', 'pls', 'png', 'rtf', 'sfv', 'txt'),
  10. true
  11. );
  12. $Keywords = array(
  13. 'ahashare.com', 'demonoid.com', 'demonoid.me', 'djtunes.com', 'h33t', 'housexclusive.net',
  14. 'limetorrents.com', 'mixesdb.com', 'mixfiend.blogstop', 'mixtapetorrent.blogspot',
  15. 'plixid.com', 'reggaeme.com' , 'scc.nfo', 'thepiratebay.org', 'torrentday');
  16. function check_file($Type, $Name)
  17. {
  18. check_name($Name);
  19. check_extensions($Type, $Name);
  20. }
  21. function check_name($Name)
  22. {
  23. global $Keywords;
  24. $NameLC = strtolower($Name);
  25. foreach ($Keywords as &$Value) {
  26. if (strpos($NameLC, $Value) !== false) {
  27. forbidden_error($Name);
  28. }
  29. }
  30. if (preg_match('/INCOMPLETE~\*/i', $Name)) {
  31. forbidden_error($Name);
  32. }
  33. /*
  34. * These characters are invalid in NTFS on Windows systems:
  35. * : ? / < > \ * | "
  36. *
  37. * todo: Add "/" to the blacklist. Adding "/" to the blacklist causes problems with nested dirs, apparently
  38. *
  39. * Only the following characters need to be escaped (see the link below):
  40. * \ - ^ ]
  41. *
  42. * http://www.php.net/manual/en/regexp.reference.character-classes.php
  43. */
  44. $AllBlockedChars = ' : ? < > \ * | " ';
  45. if (preg_match('/[\\:?<>*|"]/', $Name, $Matches)) {
  46. character_error($Matches[0], $AllBlockedChars);
  47. }
  48. }
  49. function check_extensions($Type, $Name)
  50. {
  51. global $MusicExtensions, $ComicsExtensions;
  52. if ($Type === 'Music' || $Type === 'Audiobooks' || $Type === 'Comedy' || $Type === 'E-Books') {
  53. if (!isset($MusicExtensions[get_file_extension($Name)])) {
  54. invalid_error($Name);
  55. }
  56. } elseif ($Type === 'Comics') {
  57. if (!isset($ComicsExtensions[get_file_extension($Name)])) {
  58. invalid_error($Name);
  59. }
  60. }
  61. }
  62. function get_file_extension($FileName)
  63. {
  64. return strtolower(substr(strrchr($FileName, '.'), 1));
  65. }
  66. function invalid_error($Name)
  67. {
  68. global $Err;
  69. $Err = 'The torrent contained one or more invalid files (' . display_str($Name) . ')';
  70. }
  71. function forbidden_error($Name)
  72. {
  73. global $Err;
  74. $Err = 'The torrent contained one or more forbidden files (' . display_str($Name) . ')';
  75. }
  76. function character_error($Character, $AllBlockedChars)
  77. {
  78. global $Err;
  79. $Err = "One or more of the files or folders in the torrent has a name that contains the forbidden character '$Character'. Please rename the files as necessary and recreate the torrent.<br /><br />\nNote: The complete list of characters that are disallowed are shown below:<br />\n\t\t$AllBlockedChars";
  80. }