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.

ipn.php 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // Paypal hits this page once a donation has gone through.
  3. // This may appear to be light on the input validation, but the vast majority of that is handled through paypal confirmation
  4. // $_POST['txn_id'] centains the unique identifier if anyone ever needs it
  5. if (!is_number($_POST['custom'])) {
  6. error(); // Seems too stupid a mistake to bother banning
  7. }
  8. $ENV = ENV::go();
  9. // Create request to return to paypal
  10. $Request = 'cmd=_notify-validate';
  11. foreach ($_POST as $Key => $Value) {
  12. $Value = urlencode(stripslashes($Value));
  13. $Request .= "&$Key=$Value";
  14. }
  15. // Headers
  16. $Headers = "POST /cgi-bin/webscr HTTP/1.1\r\n";
  17. $Headers .= "Host: www.paypal.com\r\n";
  18. $Headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
  19. $Headers .= "Content-Length: ".strlen($Request)."\r\n";
  20. $Headers .= "Connection: close\r\n\r\n";
  21. // Socket
  22. $Socket = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
  23. // Send and process reply
  24. fwrite($Socket, $Headers.$Request);
  25. $Result = '';
  26. while (!feof($Socket)) {
  27. $Result .= fgets($Socket, 1024);
  28. }
  29. if (strpos($Result, 'VERIFIED') !== false || check_perms('site_debug')) {
  30. if ($_POST['mc_gross'] >= PAYPAL_MINIMUM) {
  31. if ($_POST['mc_currency'] == PAYPAL_CURRENCY) {
  32. if ($_POST['business'] == PAYPAL_ADDRESS) {
  33. if (($_POST['payment_status'] == 'Completed') || ($_POST['payment_status'] == 'Pending')) {
  34. $DB->query('
  35. SELECT Donor
  36. FROM users_info
  37. WHERE UserID = \''.$_POST['custom'].'\'');
  38. list($Donor) = $DB->next_record();
  39. if ($Donor == 0) {
  40. //First time donor
  41. $DB->query('
  42. UPDATE users_main
  43. SET Invites = Invites + \''.DONOR_INVITES.'\'
  44. WHERE ID = \''.$_POST['custom'].'\'');
  45. $DB->query('
  46. UPDATE users_info
  47. SET Donor = \'1\'
  48. WHERE UserID = \''.$_POST['custom'].'\'');
  49. $DB->query('
  50. SELECT Invites
  51. FROM users_main
  52. WHERE ID = \''.$_POST['custom'].'\'');
  53. list($Invites) = $DB->next_record();
  54. $Cache->begin_transaction('user_info_'.$_POST['custom']);
  55. $Cache->update_row(false, array('Donor' => 1));
  56. $Cache->commit_transaction(0);
  57. $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
  58. $Cache->update_row(false, array('Invites' => $Invites));
  59. $Cache->commit_transaction(0);
  60. Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Because this is your first time donating, you have now been awarded Donor status as represented by the <3 found on your profile and next to your username where it appears. This has entitled you to a additional site features which you can now explore, and has granted you '.DONOR_INVITES." invitations to share with others. Thank you for supporting $ENV->SITE_NAME.");
  61. } else {
  62. // Repeat donor
  63. Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Your continued support is highly appreciated and helps to make this place possible.');
  64. }
  65. }
  66. }
  67. }
  68. } else {
  69. if ($_POST['mc_gross'] > 0) {
  70. // Donation less than minimum
  71. Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Unfortunately however this donation was less than the specified minimum donation of '.PAYPAL_MINIMUM.' '.PAYPAL_CURRENCY.' and while we are grateful, no special privileges have been awarded to you.');
  72. } else {
  73. // Failed pending donation
  74. $Message = "User ".site_url()."user.php?id=".$_POST['custom']." had donation of $TotalDonated ".PAYPAL_CURRENCY." at $DonationTime UTC from ".$_POST['payer_email'].' returned.';
  75. $DB->query('
  76. SELECT SUM(Amount), MIN(Time)
  77. FROM donations
  78. WHERE UserID = \''.$_POST['custom'].'\';');
  79. list($TotalDonated, $DonationTime) = $DB->next_record();
  80. if ($TotalDonated + $_POST['mc_gross'] == 0) {
  81. $DB->query("
  82. SELECT Invites
  83. FROM users_main
  84. WHERE ID = '".$_POST['custom']."'");
  85. list($Invites) = $DB->next_record();
  86. if (($Invites - DONOR_INVITES) >= 0) {
  87. $NewInvites = $Invites - DONOR_INVITES;
  88. } else {
  89. $NewInvites = 0;
  90. $Message .= ' They had already used at least one of their donation gained invites.';
  91. }
  92. $DB->query("
  93. UPDATE users_main
  94. SET Invites = $NewInvites
  95. WHERE ID = '".$_POST['custom']."'");
  96. $DB->query('
  97. UPDATE users_info
  98. SET Donor = \'0\'
  99. WHERE UserID = \''.$_POST['custom'].'\'');
  100. $Cache->begin_transaction('user_info_'.$_POST['custom']);
  101. $Cache->update_row(false, array('Donor' => 0));
  102. $Cache->commit_transaction(0);
  103. $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
  104. $Cache->update_row(false, array('Invites' => $Invites));
  105. $Cache->commit_transaction(0);
  106. Misc::send_pm($_POST['custom'], 0, 'Notice of donation failure', 'PapPal has just notified us that the donation you sent from '.$_POST['payer_email'].' of '.$TotalDonated.' '.PAYPAL_CURRENCY.' at '.$DonationTime.' UTC has been revoked. Because of this your special privileges have been revoked, and your invites removed.');
  107. send_irc(STAFF_CHAN, $Message);
  108. }
  109. }
  110. }
  111. $DB->query("
  112. UPDATE users_info
  113. SET AdminComment = CONCAT('".sqltime()." - User donated ".db_string($_POST['mc_gross'])." ".db_string(PAYPAL_CURRENCY)." from ".db_string($_POST['payer_email']).".\n',AdminComment)
  114. WHERE UserID = '".$_POST['custom']."'");
  115. $DB->query("
  116. INSERT INTO donations
  117. (UserID, Amount, Email, Time)
  118. VALUES
  119. ('".$_POST['custom']."', '".db_string($_POST['mc_gross'])."', '".db_string($_POST['payer_email'])."', NOW())");
  120. } else {
  121. $DB->query("
  122. INSERT INTO ip_bans
  123. (FromIP, ToIP, Reason)
  124. VALUES
  125. ('".Tools::ip_to_unsigned($_SERVER['REMOTE_ADDR'])."', '".ip2long($_SERVER['REMOTE_ADDR'])."', 'Attempted to exploit donation system.')");
  126. }
  127. fclose($Socket);
  128. if (check_perms('site_debug')) {
  129. include SERVER_ROOT.'/sections/donate/donate.php';
  130. }
  131. $Cache->cache_value('debug_donate', array($Result, $_POST), 0);