Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <?php
  2. /*
  3. * This is a PayPal IPN (Instant Payment Notification) broadcaster
  4. * Since PayPal does not provide any straightforward way to add
  5. * multiple IPN listeners we'll have to create a central IPN
  6. * listener that will broadcast (or filter and dispatch) Instant
  7. * Payment Notifications to different destinations (IPN listeners)
  8. *
  9. * Destination IPN listeners must not panic and recognize IPNs sent
  10. * by this central broadcast as valid ones in terms of source IP
  11. * and any other fingerprints. Any IP filtering must add this host,
  12. * other adjustments made as necessary.
  13. *
  14. * IPNs are logged into files for debugging and maintenance purposes
  15. *
  16. * this code comes with absolutely no warranty
  17. * https://codeseekah.com
  18. */
  19.  
  20. ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
  21. ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
  22. $urls = array(); /* The broadcast session queue */
  23.  
  24. /* List of IPN listener points */
  25. $ipns = array(
  26. 'ogretiyor' => 'http://mydomain.com/myipnlistener.php',
  27. 'surprizkutu' => 'http://myotherdomain.com/?wc-api=WC_Gateway_Paypal',
  28. );
  29.  
  30. /* Fingerprints */
  31.  
  32. /* ... */
  33.  
  34.  
  35. /* Broadcast */
  36.  
  37. if ( !sizeof($urls) ) $urls = $ipns; /* No URLs have been matched */
  38. $urls = array_unique( $urls ); /* Unique, just in case */
  39.  
  40. /* Broadcast (excluding IPNs from the list according to filter is possible */
  41. foreach ( $urls as $url ) broadcast( $url );
  42.  
  43. header( 'HTTP/1.1 200 OK', true, 200 );
  44. exit(); /* Thank you, bye */
  45.  
  46. /* Perform a simple cURL-powered proxy request to broadcast */
  47. function broadcast( $url ) {
  48.  
  49. /* Format POST data accordingly */
  50. $data = array();
  51. foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
  52. $data = implode('&', $data);
  53.  
  54. /* Log the broadcast */
  55. file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
  56.  
  57. $ch = curl_init(); /* Initialize */
  58.  
  59. curl_setopt($ch, CURLOPT_URL, $url);
  60. curl_setopt($ch, CURLOPT_POST, count($data));
  61. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  62. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  63.  
  64. curl_exec($ch); /* Execute HTTP request */
  65.  
  66. curl_close($ch); /* Close */
  67. }
  68.  
  69. function reverse_lookup( $url ) {
  70. global $ipns;
  71. foreach ( $ipns as $tag => $_url ) {
  72. if ( $url == $_url ) return $tag;
  73. }
  74. return 'unknown';
  75. }
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement