Oppaitime'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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?
  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. die(); //Seems too stupid a mistake to bother banning
  7. }
  8. // Create request to return to paypal
  9. $Request = 'cmd=_notify-validate';
  10. foreach ($_POST as $Key => $Value) {
  11. $Value = urlencode(stripslashes($Value));
  12. $Request .= "&$Key=$Value";
  13. }
  14. // Headers
  15. $Headers = "POST /cgi-bin/webscr HTTP/1.1\r\n";
  16. $Headers .= "Host: www.paypal.com\r\n";
  17. $Headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
  18. $Headers .= "Content-Length: ".strlen($Request)."\r\n";
  19. $Headers .= "Connection: close\r\n\r\n";
  20. // Socket
  21. $Socket = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
  22. // Send and process reply
  23. fwrite ($Socket, $Headers.$Request);
  24. $Result = '';
  25. while (!feof($Socket)) {
  26. $Result .= fgets ($Socket, 1024);
  27. }
  28. if (strpos($Result, 'VERIFIED') !== false || check_perms('site_debug')) {
  29. if ($_POST['mc_gross'] >= PAYPAL_MINIMUM) {
  30. if ($_POST['mc_currency'] == PAYPAL_CURRENCY) {
  31. if ($_POST['business'] == PAYPAL_ADDRESS) {
  32. if (($_POST['payment_status'] == 'Completed') || ($_POST['payment_status'] == 'Pending')) {
  33. $DB->query('
  34. SELECT Donor
  35. FROM users_info
  36. WHERE UserID = \''.$_POST['custom'].'\'');
  37. list($Donor) = $DB->next_record();
  38. if ($Donor == 0) {
  39. //First time donor
  40. $DB->query('
  41. UPDATE users_main
  42. SET Invites = Invites + \''.DONOR_INVITES.'\'
  43. WHERE ID = \''.$_POST['custom'].'\'');
  44. $DB->query('
  45. UPDATE users_info
  46. SET Donor = \'1\'
  47. WHERE UserID = \''.$_POST['custom'].'\'');
  48. $DB->query('
  49. SELECT Invites
  50. FROM users_main
  51. WHERE ID = \''.$_POST['custom'].'\'');
  52. list($Invites) = $DB->next_record();
  53. $Cache->begin_transaction('user_info_'.$_POST['custom']);
  54. $Cache->update_row(false, array('Donor' => 1));
  55. $Cache->commit_transaction(0);
  56. $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
  57. $Cache->update_row(false, array('Invites' => $Invites));
  58. $Cache->commit_transaction(0);
  59. 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 '.SITE_NAME.'.');
  60. } else {
  61. //Repeat donor
  62. 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.');
  63. }
  64. }
  65. }
  66. }
  67. } else {
  68. if ($_POST['mc_gross'] > 0) {
  69. //Donation less than minimum
  70. 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.');
  71. } else {
  72. //Failed pending donation
  73. $Message = "User ".site_url()."user.php?id=".$_POST['custom']." had donation of $TotalDonated ".PAYPAL_CURRENCY." at $DonationTime UTC from ".$_POST['payer_email'].' returned.';
  74. $DB->query('
  75. SELECT SUM(Amount), MIN(Time)
  76. FROM donations
  77. WHERE UserID = \''.$_POST['custom'].'\';');
  78. list($TotalDonated, $DonationTime) = $DB->next_record();
  79. if ($TotalDonated + $_POST['mc_gross'] == 0) {
  80. $DB->query("
  81. SELECT Invites
  82. FROM users_main
  83. WHERE ID = '".$_POST['custom']."'");
  84. list($Invites) = $DB->next_record();
  85. if (($Invites - DONOR_INVITES) >= 0) {
  86. $NewInvites = $Invites - DONOR_INVITES;
  87. } else {
  88. $NewInvites = 0;
  89. $Message .= ' They had already used at least one of their donation gained invites.';
  90. }
  91. $DB->query("
  92. UPDATE users_main
  93. SET Invites = $NewInvites
  94. WHERE ID = '".$_POST['custom']."'");
  95. $DB->query('
  96. UPDATE users_info
  97. SET Donor = \'0\'
  98. WHERE UserID = \''.$_POST['custom'].'\'');
  99. $Cache->begin_transaction('user_info_'.$_POST['custom']);
  100. $Cache->update_row(false, array('Donor' => 0));
  101. $Cache->commit_transaction(0);
  102. $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
  103. $Cache->update_row(false, array('Invites' => $Invites));
  104. $Cache->commit_transaction(0);
  105. 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.');
  106. send_irc("PRIVMSG ".BOT_REPORT_CHAN." :$Message");
  107. }
  108. }
  109. }
  110. $DB->query("
  111. UPDATE users_info
  112. SET AdminComment = CONCAT('".sqltime()." - User donated ".db_string($_POST['mc_gross'])." ".db_string(PAYPAL_CURRENCY)." from ".db_string($_POST['payer_email']).".\n',AdminComment)
  113. WHERE UserID = '".$_POST['custom']."'");
  114. $DB->query("
  115. INSERT INTO donations
  116. (UserID, Amount, Email, Time)
  117. VALUES
  118. ('".$_POST['custom']."', '".db_string($_POST['mc_gross'])."', '".db_string($_POST['payer_email'])."', '".sqltime()."')");
  119. } else {
  120. $DB->query("
  121. INSERT INTO ip_bans
  122. (FromIP, ToIP, Reason)
  123. VALUES
  124. ('".Tools::ip_to_unsigned($_SERVER['REMOTE_ADDR'])."', '".ip2long($_SERVER['REMOTE_ADDR'])."', 'Attempted to exploit donation system.')");
  125. }
  126. fclose ($Socket);
  127. if (check_perms('site_debug')) {
  128. include(SERVER_ROOT.'/sections/donate/donate.php');
  129. }
  130. $Cache->cache_value('debug_donate', array($Result, $_POST), 0);
  131. ?>