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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. if (!check_perms('site_proxy_images')) {
  3. img_error('forbidden');
  4. }
  5. $URL = isset($_GET['i']) ? htmlspecialchars_decode($_GET['i']) : null;
  6. if (!extension_loaded('openssl') && strtoupper($URL[4]) === 'S') {
  7. img_error('badprotocol');
  8. }
  9. /*
  10. if (!(preg_match('/^'.IMAGE_REGEX.'/is', $URL, $Matches) || preg_match('/^'.VIDEO_REGEX.'/is', $URL, $Matches))) {
  11. img_error('invalid');
  12. }
  13. */
  14. if (isset($_GET['c'])) {
  15. list($Data, $FileType) = $Cache->get_value('image_cache_'.md5($URL));
  16. $Cached = true;
  17. }
  18. if (!isset($Data) || !$Data) {
  19. $Cached = false;
  20. $Data = @file_get_contents($URL, 0, stream_context_create(array('http' => array('timeout' => 15), 'ssl' => array('verify_peer' => false))));
  21. if (!$Data || empty($Data)) {
  22. img_error('timeout');
  23. }
  24. $FileType = image_type($Data);
  25. if ($FileType && function_exists("imagecreatefrom$FileType")) {
  26. $Image = imagecreatefromstring($Data);
  27. if (invisible($Image)) {
  28. img_error('invisible');
  29. }
  30. if (verysmall($Image)) {
  31. img_error('small');
  32. }
  33. }
  34. if (isset($_GET['c']) && strlen($Data) < 524288 && substr($Data, 0, 1) != '<') {
  35. $Cache->cache_value('image_cache_'.md5($URL), array($Data, $FileType), 3600 * 24 * 7);
  36. }
  37. }
  38. // Reset avatar, add mod note
  39. function reset_image($UserID, $Type, $AdminComment, $PrivMessage)
  40. {
  41. $ENV = ENV::go();
  42. if ($Type === 'avatar') {
  43. $CacheKey = "user_info_$UserID";
  44. $DBTable = 'users_info';
  45. $DBColumn = 'Avatar';
  46. $PMSubject = 'Your avatar has been automatically reset';
  47. } elseif ($Type === 'avatar2') {
  48. $CacheKey = "donor_info_$UserID";
  49. $DBTable = 'donor_rewards';
  50. $DBColumn = 'SecondAvatar';
  51. $PMSubject = 'Your second avatar has been automatically reset';
  52. } elseif ($Type === 'donoricon') {
  53. $CacheKey = "donor_info_$UserID";
  54. $DBTable = 'donor_rewards';
  55. $DBColumn = 'CustomIcon';
  56. $PMSubject = 'Your donor icon has been automatically reset';
  57. }
  58. $UserInfo = G::$Cache->get_value($CacheKey, true);
  59. if ($UserInfo !== false) {
  60. if ($UserInfo[$DBColumn] === '') {
  61. // This image has already been reset
  62. return;
  63. }
  64. $UserInfo[$DBColumn] = '';
  65. G::$Cache->cache_value($CacheKey, $UserInfo, 2592000); // cache for 30 days
  66. }
  67. // Reset the avatar or donor icon URL
  68. G::$DB->query("
  69. UPDATE $DBTable
  70. SET $DBColumn = ''
  71. WHERE UserID = '$UserID'");
  72. // Write comment to staff notes
  73. G::$DB->query("
  74. UPDATE users_info
  75. SET AdminComment = CONCAT('".sqltime().' - '.db_string($AdminComment)."\n\n', AdminComment)
  76. WHERE UserID = '$UserID'");
  77. // Clear cache keys
  78. G::$Cache->delete_value($CacheKey);
  79. Misc::send_pm($UserID, 0, $PMSubject, $PrivMessage);
  80. }
  81. // Enforce avatar rules
  82. if (isset($_GET['type']) && isset($_GET['userid'])) {
  83. $ValidTypes = array('avatar', 'avatar2', 'donoricon');
  84. if (!is_number($_GET['userid']) || !in_array($_GET['type'], $ValidTypes)) {
  85. error();
  86. }
  87. $UserID = $_GET['userid'];
  88. $Type = $_GET['type'];
  89. if ($Type === 'avatar' || $Type === 'avatar2') {
  90. $MaxFileSize = 512 * 1024; // 512 kiB
  91. $MaxImageHeight = 600; // pixels
  92. $TypeName = $Type === 'avatar' ? 'avatar' : 'second avatar';
  93. } elseif ($Type === 'donoricon') {
  94. $MaxFileSize = 128 * 1024; // 128 kiB
  95. $MaxImageHeight = 100; // pixels
  96. $TypeName = 'donor icon';
  97. }
  98. $Height = image_height($FileType, $Data);
  99. if (strlen($Data) > $MaxFileSize || $Height > $MaxImageHeight) {
  100. // Sometimes the cached image we have isn't the actual image
  101. if ($Cached) {
  102. $Data2 = file_get_contents($URL, 0, stream_context_create(array('http' => array('timeout' => 60), 'ssl' => array('verify_peer' => false))));
  103. } else {
  104. $Data2 = $Data;
  105. }
  106. if ((strlen($Data2) > $MaxFileSize || image_height($FileType, $Data2) > $MaxImageHeight) && $UserID !== 1 && $UserID !== 2) {
  107. require_once SERVER_ROOT.'/classes/mysql.class.php';
  108. require_once SERVER_ROOT.'/classes/time.class.php';
  109. $DBURL = db_string($URL);
  110. $AdminComment = ucfirst($TypeName)." reset automatically (Size: ".number_format((strlen($Data)) / 1024)." kB, Height: ".$Height."px). Used to be $DBURL";
  111. $PrivMessage = "$ENV->SITE_NAME has the following requirements for {$TypeName}s:\n\n".
  112. "[b]".ucfirst($TypeName)."s must not exceed ".($MaxFileSize / 1024)." kB or be vertically longer than {$MaxImageHeight}px.[/b]\n\n".
  113. "Your $TypeName at $DBURL has been found to exceed these rules. As such, it has been automatically reset. You are welcome to reinstate your $TypeName once it has been resized down to an acceptable size.";
  114. reset_image($UserID, $Type, $AdminComment, $PrivMessage);
  115. }
  116. }
  117. }
  118. if (!isset($FileType)) {
  119. img_error('timeout');
  120. }
  121. if ($FileType === 'webm') {
  122. header("Content-type: video/$FileType");
  123. } else {
  124. header("Content-type: image/$FileType");
  125. }
  126. echo $Data;