[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 ipncheck.php

Zen Cart 源代码 ipncheck.php




下载文件

文件名: ipncheck.php
文件类型: PHP文件
文件大小: 11.01 KiB
MD5: d949ed2a938c5f967be8ba1b8c856ad1

ipncheck.php - 关闭高亮
  1. <?php
  2. /**
  3.  * ipncheck.php diagnostic tool
  4.  *
  5.  * @package utility
  6.  * @copyright Copyright 2007-2012 Zen Cart Development Team
  7.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  8.  * @version GIT: $Id: Author: Ian Wilson  Fri Aug 31 11:51:59 2012 +0100 Modified in v1.5.1 $
  9.  *
  10.  * This utility is intended to be used to check whether a Zen Cart store is able to connect TO PayPal in order to RESPOND to an incoming IPN notification.
  11.  * Unfortunately it cannot test whether PayPal's servers can successfully post an IPN *to* your store.  To do that one should test a live transaction.
  12.  *
  13.  * USAGE INSTRUCTIONS:
  14.  * 1. Open your browser
  15.  * 2. Enter the URL for your store, followed by /extras/ipncheck.php
  16.  * 3. ... and press Enter
  17.  * 4. Review the results. If the results are not positive (ie: "OKAY" response), post the results AND the full URL to your /extras/ipncheck.php script of your site ... into a support ticket on the Zen Cart forum.
  18.  */
  19.  
  20. if (!function_exists('curl_setopt_array')) {
  21.    function curl_setopt_array(&$ch, $curl_options)
  22.    {
  23.        foreach ($curl_options as $option => $value) {
  24.            if (!curl_setopt($ch, $option, $value)) {
  25.                return false;
  26.            }
  27.        }
  28.        return true;
  29.    }
  30. }
  31.  
  32. $verboseMode = (isset($_GET['verbose']) ? TRUE : FALSE);
  33. $headerMode = (isset($_GET['headers']) ? TRUE : FALSE);
  34. $testBoth = (isset($_GET['both']) && $_GET['both'] == '0') ? FALSE : TRUE;
  35. $checkNoChex = (isset($_GET['nochex'])) ? TRUE : FALSE;
  36. $testSandbox = (isset($_GET['sandbox'])) ? TRUE : FALSE;
  37.  
  38. $_POST = array();
  39. if (isset($GLOBALS)) unset($GLOBALS);
  40. if (isset($_GET)) unset($_GET);
  41. if (isset($_REQUEST)) unset($_REQUEST);
  42. $_POST['ipn_mode'] = 'communication_test';
  43. if ($testSandbox) $_POST['test_ipn'] = 1;
  44. define('ENABLE_SSL','true');
  45. define('MODULE_PAYMENT_PAYPAL_HANDLER', 'www.paypal.com/cgi-bin/webscr');
  46.  
  47.  
  48. echo 'IPNCHECK.PHP - Version 1.3.9';
  49. echo '<br /><br /><pre>';
  50.     $defaultMethod = $altMethod = '';
  51.     $info = '';
  52.     $postdata = '';
  53.     $postback = '';
  54.     $postback_array = array();
  55.  
  56.     //build post string
  57.     foreach($_POST as $key=>$value) {
  58.       $postdata .= $key . "=" . urlencode(stripslashes($value)) . "&";
  59.       $postback .= $key . "=" . urlencode(stripslashes($value)) . "&";
  60.       $postback_array[$key] = $value;
  61.     }
  62.     $postback .= "cmd=_notify-validate";
  63.     $postback_array['cmd'] = "_notify-validate";
  64.     if ($postdata == '=&') {
  65.       die('IPN NOTICE :: No POST data to process -- Bad IPN data<br /><pre>' . print_r($_POST, true));
  66.     }
  67.     $postdata_array = $_POST;
  68.     ksort($postdata_array);
  69.  
  70.     if (sizeof($postdata_array) == 0) die('Nothing to process. Please return to home page.');
  71.  
  72.     // send received data back to PayPal for validation
  73.       $scheme = 'https://';
  74.       //Parse url
  75.       $web = parse_url($scheme . MODULE_PAYMENT_PAYPAL_HANDLER);
  76.       if ($checkNoChex == TRUE) $web = parse_url('https://www.nochex.com/nochex.dll/apc/apc');
  77.       if (isset($_POST['test_ipn']) && $_POST['test_ipn'] == 1) {
  78.         $web = parse_url($scheme . 'www.sandbox.paypal.com/cgi-bin/webscr');
  79.       }
  80.       //Set the port number
  81.       if($web['scheme'] == "https") {
  82.         $web['port']="443";  $web['protocol'] = "ssl://";
  83.       } else {
  84.         $web['port']="80";   $web['protocol'] = "";
  85.       }
  86.  
  87.  
  88.       $result = '';
  89.       $data = '';
  90.       if (function_exists('curl_init')) {
  91.         $result = doPayPalIPNCurlPostback($web, $postback, $verboseMode, $headerMode);
  92.         if (in_array($result, array('VERIFIED', 'SUCCESS', 'INVALID'))) {
  93.           echo nl2br('IPN TESTING - Response Received via CURL -- <strong>COMMUNICATIONS OKAY</strong>' . "\n<!--" . $data . '-->');
  94.           $defaultMethod = 'CURL';
  95.           $altMethod = 'FSOCKOPEN';
  96.         }
  97.       } else {
  98.         echo nl2br('CURL not available. Will attempt to connect using fsockopen() instead.' . "\n");
  99.       }
  100.  
  101.       if (!in_array($result, array('VERIFIED', 'SUCCESS', 'INVALID')) || $testBoth === TRUE) {
  102.         $result = doPayPalIPNFsockopenPostback($web, $postback);
  103.         echo nl2br('IPN TESTING - Confirmation/Validation response with fsockopen(): <strong>' .$result . "</strong>\n<!--" . $info . '-->');
  104.         if ($defaultMethod == '' && $result != 'FAILED') {
  105.           $defaultMethod = 'FSOCKOPEN';
  106.           $altMethod = 'CURL';
  107.         }
  108.       }
  109. if ($defaultMethod != '') {
  110.   echo '<br><br>Default method likely to be used for communications is: <strong>' . $defaultMethod . '</strong>, with the fallback method being <strong>' . $altMethod . '</strong> if possible.';
  111. }
  112. echo '<br><br>Script finished.';
  113.  
  114.  
  115. /************************************/
  116.  
  117.   function doPayPalIPNFsockopenPostback($web, $postback) {
  118.     global $info;
  119.     $header  = "POST " . $web['path'] . " HTTP/1.1\r\n";
  120.     $header .= "Host: " . $web['host'] . "\r\n";
  121.     $header .= "Content-type: application/x-www-form-urlencoded\r\n";
  122.     $header .= "Content-length: " . strlen($postback) . "\r\n";
  123.     $header .= "Connection: close\r\n\r\n";
  124.     $errnum = 0;
  125.     $errstr = '';
  126.     $ssl = $web['protocol'];
  127.     //Create paypal connection
  128.     $fp=fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
  129.  
  130.     if(!$fp && $ssl == 'ssl://') {
  131.       echo nl2br("\n" . 'IPN ERROR :: Could not establish fsockopen: ' . "\n" . 'Host Details = ' . $ssl . $web['host'] . ':' . $web['port'] . ' (' . $errnum . ') ' . $errstr . "\n Trying again with HTTPS over 443 ...");
  132.       $ssl = 'https://';
  133.       $web['port'] = '443';
  134.       $fp=fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
  135.     }
  136.     if(!$fp && $ssl == 'https://') {
  137.       echo nl2br("\n" . 'IPN ERROR :: Could not establish fsockopen: ' . "\n" . 'Host Details = ' . $ssl . $web['host'] . ':' . $web['port'] . ' (' . $errnum . ') ' . $errstr . "\n Trying again directly over 443 ...");
  138.       $ssl = '';
  139.       $web['port'] = '443';
  140.       $fp=fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
  141.     }
  142.     if(!$fp) {
  143.       echo nl2br("\n" . 'IPN ERROR :: Could not establish fsockopen: ' . "\n" . 'Host Details = ' . $ssl . $web['host'] . ':' . $web['port'] . ' (' . $errnum . ') ' . $errstr . "\n Trying again with HTTP over port 80 ...");
  144.       $ssl = 'http';
  145.       $web['port'] = '80';
  146.       $fp=fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
  147.     }
  148.     if(!$fp) {
  149.       echo nl2br("\n" . 'IPN ERROR :: Could not establish fsockopen: ' . "\n" . 'Host Details = ' . $ssl . $web['host'] . ':' . $web['port'] . ' (' . $errnum . ') ' . $errstr . "\n Trying again without any specified protocol, using port 80 ...");
  150.       $ssl = '';
  151.       $web['port'] = '80';
  152.       $fp=fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);
  153.     }
  154.     if(!$fp) {
  155.       echo nl2br("\n" . 'IPN FATAL ERROR :: Could not establish fsockopen. ' . "\n" . 'Host Details = ' . $ssl . $web['host'] . ':' . $web['port'] . ' (' . $errnum . ') ' . $errstr . "\n");
  156.       die();
  157.     }
  158.  
  159.     fputs($fp, $header . $postback . "\r\n\r\n");
  160.     $header_data = '';
  161.     $headerdone = false;
  162.     //loop through the response from the server
  163.     while(!feof($fp)) {
  164.       $line = @fgets($fp, 1024);
  165.       if (strcmp($line, "\r\n") == 0) {
  166.         // this is a header row
  167.         $headerdone = true;
  168.         $header_data .= $line;
  169.       } else if ($headerdone) {
  170.         // header has been read. now read the contents
  171.         $info[] = $line;
  172.       }
  173.     }
  174.     //close fp - we are done with it
  175.     fclose($fp);
  176.     //break up results into a string
  177.     $info = implode("", $info);
  178.     $status = (strstr($info,'VERIFIED')) ? 'VERIFIED' : (strstr($info,'SUCCESS')) ? 'SUCCESS' : (strstr($info,'INVALID')) ? 'FSOCKOPEN() RESPONSE RECEIVED - Communications OKAY' : 'FAILED';
  179.     echo "\n\n" . '<!-- IPN INFO - Confirmation/Validation response ' . "\n-------------\n" . $header_data . $info . "\n--------------\n -->";
  180.  
  181.     return $status;
  182.   }
  183.  
  184.  
  185.   function doPayPalIPNCurlPostback($web, $vars, $verboseMode = FALSE, $headerMode = FALSE) {
  186.     $status = 'Attempted connection on: ' .$web['scheme'] . '://' . $web['host'] . $web['path'];
  187.     $ch = curl_init($web['scheme'] . '://' . $web['host'] . $web['path']);
  188.     $curlOpts = array(CURLOPT_URL => $web['scheme'] . '://' . $web['host'] . $web['path'],
  189.                       CURLOPT_POST => TRUE,
  190.                       CURLOPT_POSTFIELDS => $vars,
  191.                       CURLOPT_TIMEOUT => 45,
  192.                       CURLOPT_CONNECTTIMEOUT => 30,
  193.                       CURLOPT_VERBOSE => ($verboseMode ? TRUE : FALSE),
  194.                       CURLOPT_HEADER => ($headerMode ? TRUE : FALSE),
  195.                       CURLOPT_FOLLOWLOCATION => FALSE,
  196.                       CURLOPT_RETURNTRANSFER => TRUE,
  197.                       CURLOPT_SSL_VERIFYPEER => FALSE,
  198.                       CURLOPT_SSL_VERIFYHOST => 2,
  199.                       CURLOPT_FORBID_REUSE => TRUE,
  200.                       CURLOPT_FRESH_CONNECT => TRUE,
  201.                       CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  202.                       CURLOPT_USERAGENT => 'Zen Cart(tm) - IPN Postback TEST',
  203.                       );
  204.     if ($web['port'] != '80') {
  205.       $curlOpts[CURLOPT_PORT] = $web['port'];
  206.     }
  207. /*    if (CURL_PROXY_REQUIRED == 'True') {
  208.       $proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
  209.       curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
  210.       curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  211.       curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
  212.     }
  213. */
  214.     curl_setopt_array($ch, $curlOpts);
  215.     $response = curl_exec($ch);
  216.     $commError = curl_error($ch);
  217.     $commErrNo = curl_errno($ch);
  218.     $errors = ($commErrNo != 0 ? "\n(" . $commErrNo . ') ' . $commError : '');
  219.  
  220.     if (($response == '' || $errors != '') && ($web['scheme'] != 'http')) {
  221.       if ($verboseMode) echo nl2br("\n\n" . 'VERBOSE output:' . "\n-------------\n<pre>" . htmlspecialchars($response, ENT_COMPAT, 'UTF-8', TRUE) . "</pre>\n--------------\n");
  222.       echo nl2br('CURL ERROR: ' . $status . $errors . "\n" . 'Trying direct HTTP on port 80 instead ...' . "\n");
  223.       $web['scheme'] = 'http';
  224.       $web['port'] = '80';
  225.       $status = 'Attempted alternate connection on: ' .$web['scheme'] . '://' . $web['host'] . $web['path'] . "\n<br />";
  226.       curl_setopt($ch, CURLOPT_URL, $web['scheme'] . '://' . $web['host'] . $web['path']);
  227.       curl_setopt($ch, CURLOPT_PORT, $web['port']);
  228.       $response = curl_exec($ch);
  229.       $commError = curl_error($ch);
  230.       $commErrNo = curl_errno($ch);
  231.     }
  232.     //$commInfo = @curl_getinfo($ch);
  233.     curl_close($ch);
  234.     //die("\n\n".'data:'.$response);
  235.     if ($verboseMode) echo nl2br("\n\n" . 'VERBOSE output: ' . "\n-------------\n<pre>" . htmlspecialchars($response, ENT_COMPAT, 'UTF-8', TRUE) . "</pre>\n--------------\n");
  236.     $errors = ($commErrNo != 0 ? "\n(" . $commErrNo . ') ' . $commError : '');
  237.     if ($errors != '') {
  238.       echo nl2br('CURL ERROR: ' . $status . $errors . "\n" . 'ABORTING CURL METHOD ...' . "\n\n");
  239.     }
  240.  
  241.     $status = (strstr($response,'VERIFIED')) ? 'VERIFIED' : (strstr($response,'SUCCESS')) ? 'SUCCESS' : (strstr($response,'INVALID')) ? 'CURL RESPONSE RECEIVED - Communications OKAY' : 'FAILED';
  242.     echo  $status . '<br />';
  243.  
  244.  
  245.     return $response;
  246.   }
  247.  
  248.  


cron