Oppaitime'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 2.7KB

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