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.

take_invite.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. #declare(strict_types=1);
  3. $ENV = ENV::go();
  4. if (!$UserCount = $Cache->get_value('stats_user_count')) {
  5. $DB->query("
  6. SELECT COUNT(ID)
  7. FROM users_main
  8. WHERE Enabled = '1'");
  9. list($UserCount) = $DB->next_record();
  10. $Cache->cache_value('stats_user_count', $UserCount, 0);
  11. }
  12. $UserID = $LoggedUser['ID'];
  13. if (!apcu_exists('DBKEY')) {
  14. error('Invites disabled until database decrypted');
  15. header('Location: user.php?action=invite');
  16. error();
  17. }
  18. // This is where we handle things passed to us
  19. authorize();
  20. $DB->query("
  21. SELECT can_leech
  22. FROM users_main
  23. WHERE ID = $UserID");
  24. list($CanLeech) = $DB->next_record();
  25. if ($LoggedUser['RatioWatch']
  26. || !$CanLeech
  27. || $LoggedUser['DisableInvites'] == '1'
  28. || $LoggedUser['Invites'] == 0
  29. && !check_perms('site_send_unlimited_invites')
  30. || (
  31. $UserCount >= USER_LIMIT
  32. && USER_LIMIT != 0
  33. && !check_perms('site_can_invite_always')
  34. )
  35. ) {
  36. error(403);
  37. }
  38. $Email = trim($_POST['email']);
  39. $Username = $LoggedUser['Username'];
  40. $SiteName = $ENV->SITE_NAME ;
  41. $SiteURL = site_url();
  42. $InviteExpires = time_plus(60 * 60 * 24 * 3); // 3 days
  43. $InviteReason = check_perms('users_invite_notes') ? db_string($_POST['reason']) : '';
  44. //MultiInvite
  45. if (strpos($Email, '|') !== false && check_perms('site_send_unlimited_invites')) {
  46. $Emails = explode('|', $Email);
  47. } else {
  48. $Emails = array($Email);
  49. }
  50. foreach ($Emails as $CurEmail) {
  51. if (!preg_match("/^".EMAIL_REGEX."$/i", $CurEmail)) {
  52. if (count($Emails) > 1) {
  53. continue;
  54. } else {
  55. error('Invalid email.');
  56. header('Location: user.php?action=invite');
  57. error();
  58. }
  59. }
  60. $DB->query("
  61. SELECT Email
  62. FROM invites
  63. WHERE InviterID = ".$LoggedUser['ID']);
  64. if ($DB->has_results()) {
  65. while (list($MaybeEmail) = $DB->next_record()) {
  66. if (Crypto::decrypt($MaybeEmail) == $CurEmail) {
  67. error('You already have a pending invite to that address!');
  68. header('Location: user.php?action=invite');
  69. error();
  70. }
  71. }
  72. }
  73. $InviteKey = db_string(Users::make_secret());
  74. $DisabledChan = DISABLED_CHAN;
  75. $IRCServer = BOT_SERVER;
  76. $Message = <<<EOT
  77. The user $Username has invited you to join $SiteName and has specified this address ($CurEmail) as your email address. If you do not know this person, please ignore this email, and do not reply.
  78. Please note that selling invites, trading invites, and giving invites away publicly (e.g. on a forum) is strictly forbidden. If you have received your invite as a result of any of these things, do not bother signing up - you will be banned and lose your chances of ever signing up legitimately.
  79. If you have previously had an account at $SiteName, do not use this invite. Instead, please join $DisabledChan on $IRCServer and ask for your account to be reactivated.
  80. To confirm your invite, click on the following link:
  81. {$SiteURL}register.php?invite=$InviteKey
  82. After you register, you will be able to use your account. Please take note that if you do not use this invite in the next 3 days, it will expire. We urge you to read the RULES and the wiki immediately after you join.
  83. Thank you,
  84. $SiteName Staff
  85. EOT;
  86. $DB->query("
  87. INSERT INTO invites
  88. (InviterID, InviteKey, Email, Expires, Reason)
  89. VALUES
  90. ('$LoggedUser[ID]', '$InviteKey', '".Crypto::encrypt($CurEmail)."', '$InviteExpires', '$InviteReason')");
  91. if (!check_perms('site_send_unlimited_invites')) {
  92. $DB->query("
  93. UPDATE users_main
  94. SET Invites = GREATEST(Invites, 1) - 1
  95. WHERE ID = '$LoggedUser[ID]'");
  96. $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
  97. $Cache->update_row(false, array('Invites' => '-1'));
  98. $Cache->commit_transaction(0);
  99. }
  100. Misc::send_email($CurEmail, "You have been invited to $ENV->SITE_NAME", $Message, 'noreply');
  101. }
  102. header('Location: user.php?action=invite');