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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. $ENV = ENV::go();
  3. if (!$UserCount = $Cache->get_value('stats_user_count')) {
  4. $DB->query("
  5. SELECT COUNT(ID)
  6. FROM users_main
  7. WHERE Enabled = '1'");
  8. list($UserCount) = $DB->next_record();
  9. $Cache->cache_value('stats_user_count', $UserCount, 0);
  10. }
  11. $UserID = $LoggedUser['ID'];
  12. if (!apcu_exists('DBKEY')) {
  13. error('Invites disabled until database decrypted');
  14. header('Location: user.php?action=invite');
  15. error();
  16. }
  17. // This is where we handle things passed to us
  18. authorize();
  19. $DB->query("
  20. SELECT can_leech
  21. FROM users_main
  22. WHERE ID = $UserID");
  23. list($CanLeech) = $DB->next_record();
  24. if ($LoggedUser['RatioWatch']
  25. || !$CanLeech
  26. || $LoggedUser['DisableInvites'] == '1'
  27. || $LoggedUser['Invites'] == 0
  28. && !check_perms('site_send_unlimited_invites')
  29. || (
  30. $UserCount >= USER_LIMIT
  31. && USER_LIMIT != 0
  32. && !check_perms('site_can_invite_always')
  33. )
  34. ) {
  35. error(403);
  36. }
  37. $Email = trim($_POST['email']);
  38. $Username = $LoggedUser['Username'];
  39. $SiteName = $ENV->SITE_NAME ;
  40. $SiteURL = site_url();
  41. $InviteExpires = time_plus(60 * 60 * 24 * 3); // 3 days
  42. $InviteReason = check_perms('users_invite_notes') ? db_string($_POST['reason']) : '';
  43. //MultiInvite
  44. if (strpos($Email, '|') !== false && check_perms('site_send_unlimited_invites')) {
  45. $Emails = explode('|', $Email);
  46. } else {
  47. $Emails = array($Email);
  48. }
  49. foreach ($Emails as $CurEmail) {
  50. if (!preg_match("/^".EMAIL_REGEX."$/i", $CurEmail)) {
  51. if (count($Emails) > 1) {
  52. continue;
  53. } else {
  54. error('Invalid email.');
  55. header('Location: user.php?action=invite');
  56. error();
  57. }
  58. }
  59. $DB->query("
  60. SELECT Email
  61. FROM invites
  62. WHERE InviterID = ".$LoggedUser['ID']);
  63. if ($DB->has_results()) {
  64. while (list($MaybeEmail) = $DB->next_record()) {
  65. if (Crypto::decrypt($MaybeEmail) == $CurEmail) {
  66. error('You already have a pending invite to that address!');
  67. header('Location: user.php?action=invite');
  68. error();
  69. }
  70. }
  71. }
  72. $InviteKey = db_string(Users::make_secret());
  73. $DisabledChan = DISABLED_CHAN;
  74. $IRCServer = BOT_SERVER;
  75. $Message = <<<EOT
  76. 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.
  77. 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.
  78. 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.
  79. To confirm your invite, click on the following link:
  80. {$SiteURL}register.php?invite=$InviteKey
  81. 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.
  82. Thank you,
  83. $SiteName Staff
  84. EOT;
  85. $DB->query("
  86. INSERT INTO invites
  87. (InviterID, InviteKey, Email, Expires, Reason)
  88. VALUES
  89. ('$LoggedUser[ID]', '$InviteKey', '".Crypto::encrypt($CurEmail)."', '$InviteExpires', '$InviteReason')");
  90. if (!check_perms('site_send_unlimited_invites')) {
  91. $DB->query("
  92. UPDATE users_main
  93. SET Invites = GREATEST(Invites, 1) - 1
  94. WHERE ID = '$LoggedUser[ID]'");
  95. $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
  96. $Cache->update_row(false, array('Invites' => '-1'));
  97. $Cache->commit_transaction(0);
  98. }
  99. Misc::send_email($CurEmail, "You have been invited to $ENV->SITE_NAME", $Message, 'noreply');
  100. }
  101. header('Location: user.php?action=invite');