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.

paranoia.class.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. #declare(strict_types=1);
  3. // Note: at the time this file is loaded, check_perms is not defined.
  4. // Don't call check_paranoia in /classes/script_start.php without ensuring check_perms has been defined
  5. // The following are used throughout the site:
  6. // uploaded, ratio, downloaded: stats
  7. // lastseen: approximate time the user last used the site
  8. // uploads: the full list of the user's uploads
  9. // uploads+: just how many torrents the user has uploaded
  10. // snatched, seeding, leeching: the list of the user's snatched torrents, seeding torrents, and leeching torrents respectively
  11. // snatched+, seeding+, leeching+: the length of those lists respectively
  12. // uniquegroups, perfectflacs: the list of the user's uploads satisfying a particular criterion
  13. // uniquegroups+, perfectflacs+: the length of those lists
  14. // If "uploads+" is disallowed, so is "uploads". So if "uploads" is in the array, the user is a little paranoid, "uploads+", very paranoid.
  15. // The following are almost only used in /sections/user/user.php:
  16. // requiredratio
  17. // requestsfilled_count: the number of requests the user has filled
  18. // requestsfilled_bounty: the bounty thus earned
  19. // requestsfilled_list: the actual list of requests the user has filled
  20. // requestsvoted_...: similar
  21. // artistsadded: the number of artists the user has added
  22. // torrentcomments: the list of comments the user has added to torrents
  23. // +
  24. // collages: the list of collages the user has created
  25. // +
  26. // collagecontribs: the list of collages the user has contributed to
  27. // +
  28. // invitedcount: the number of users this user has directly invited
  29. /**
  30. * Return whether currently logged in user can see $Property on a user with $Paranoia, $UserClass and (optionally) $UserID
  31. * If $Property is an array of properties, returns whether currently logged in user can see *all* $Property ...
  32. *
  33. * @param $Property The property to check, or an array of properties.
  34. * @param $Paranoia The paranoia level to check against.
  35. * @param $UserClass The user class to check against (Staff can see through paranoia of lower classed staff)
  36. * @param $UserID Optional. The user ID of the person being viewed
  37. * @return mixed 1 representing the user has normal access
  38. * 2 representing that the paranoia was overridden,
  39. * false representing access denied.
  40. */
  41. define("PARANOIA_ALLOWED", 1);
  42. define("PARANOIA_OVERRIDDEN", 2);
  43. function check_paranoia($Property, $Paranoia = false, $UserClass = false, $UserID = false)
  44. {
  45. global $Classes;
  46. if ($Property == false) {
  47. return false;
  48. }
  49. if (!is_array($Paranoia)) {
  50. $Paranoia = json_decode($Paranoia, true);
  51. }
  52. if (!is_array($Paranoia)) {
  53. $Paranoia = [];
  54. }
  55. if (is_array($Property)) {
  56. $all = true;
  57. foreach ($Property as $P) {
  58. $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID);
  59. }
  60. return $all;
  61. } else {
  62. if (($UserID !== false) && (G::$LoggedUser['ID'] == $UserID)) {
  63. return PARANOIA_ALLOWED;
  64. }
  65. $May = !in_array($Property, $Paranoia) && !in_array($Property . '+', $Paranoia);
  66. if ($May) {
  67. return PARANOIA_ALLOWED;
  68. }
  69. if (check_perms('users_override_paranoia', $UserClass)) {
  70. return PARANOIA_OVERRIDDEN;
  71. }
  72. $Override=false;
  73. switch ($Property) {
  74. case 'downloaded':
  75. case 'ratio':
  76. case 'uploaded':
  77. case 'lastseen':
  78. if (check_perms('users_mod', $UserClass)) {
  79. return PARANOIA_OVERRIDDEN;
  80. }
  81. break;
  82. case 'snatched': case 'snatched+':
  83. if (check_perms('users_view_torrents_snatchlist', $UserClass)) {
  84. return PARANOIA_OVERRIDDEN;
  85. }
  86. break;
  87. case 'uploads': case 'uploads+':
  88. case 'seeding': case 'seeding+':
  89. case 'leeching': case 'leeching+':
  90. if (check_perms('users_view_seedleech', $UserClass)) {
  91. return PARANOIA_OVERRIDDEN;
  92. }
  93. break;
  94. case 'invitedcount':
  95. if (check_perms('users_view_invites', $UserClass)) {
  96. return PARANOIA_OVERRIDDEN;
  97. }
  98. break;
  99. }
  100. return false;
  101. }
  102. }