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.

security.class.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * Security
  5. *
  6. * Designed to hold common authentication functions from various sources:
  7. * - classes/script_start.php
  8. */
  9. class Security
  10. {
  11. /**
  12. * Setup pitfalls
  13. *
  14. * A series of quick sanity checks during app init.
  15. * Previously in classes/script_start.php.
  16. */
  17. public function setupPitfalls()
  18. {
  19. # short_open_tag
  20. if (!ini_get('short_open_tag')) {
  21. error('short_open_tag != On in php.ini');
  22. }
  23. # apcu
  24. if (!extension_loaded('apcu')) {
  25. error('APCu extension not loaded');
  26. }
  27. # Deal with dumbasses
  28. if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) {
  29. error(
  30. 'd14:failure reason40:Invalid .torrent, try downloading again.e',
  31. $NoHTML = true,
  32. $Debug = false
  33. );
  34. }
  35. return;
  36. }
  37. /**
  38. * UserID checks
  39. *
  40. * @param array $Permissions Permission string
  41. * @param int $UserID Defaults to $_GET['userid'] if none supplied.
  42. * @return int $UserID The working $UserID.
  43. */
  44. public function checkUser($Permissions = [], $UserID = null)
  45. {
  46. /*
  47. if (!$UserID) {
  48. error('$UserID is required.');
  49. }
  50. */
  51. # No Gazelle args passed
  52. if ($_GET['userid'] && empty($UserID)) {
  53. $UserID = $_GET['userid'];
  54. } else {
  55. $UserID = G::$LoggedUser['ID'];
  56. }
  57. # NaN
  58. if (!is_int($UserID) && not_null($UserID)) {
  59. error('$UserID must be an integer.');
  60. }
  61. # $Permissions: string fallback as in View::show_header()
  62. if (is_string($Permissions) && !empty($Permissions)) {
  63. $Permissions = explode(',', $Permissions);
  64. }
  65. # Check each permission and error out if necessary
  66. foreach ($Permissions as $Permission) {
  67. if (!check_perms($Permissions)) {
  68. error(403);
  69. break;
  70. }
  71. }
  72. # If all tests pass
  73. return (int) $UserID;
  74. }
  75. }