[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 源代码 curltester.php

Zen Cart 源代码 curltester.php




下载文件

文件名: curltester.php
文件类型: PHP文件
文件大小: 8.95 KiB
MD5: 08d21921c04134ce36d43babd01b8ae3

curltester.php - 关闭高亮
  1. <?php
  2. /**
  3.  * Standalone Diagnostics/Debug tool for testing CURL communications to common 3rd party services such as USPS and PayPal and Authorize.net and more.
  4.  * Accepted parameters:
  5.  *   d=1 or details=1 -- show CURL connection details -- useful for determining cause of communications problems
  6.  *   r=1 -- show Response obtained from destination server -- this may contain an error message, but usually means communication was okay
  7.  *
  8.  * @package utilities
  9.  * @copyright Copyright 2003-2014 Zen Cart Development Team
  10.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  11.  * @version GIT: $Id: Author: DrByte Wed Oct 22 2014 Modified in v1.5.4 $
  12.  */
  13. // no caching
  14. header('Cache-Control: no-cache, no-store, must-revalidate');
  15. ?>
  16. <html><head><meta name="robots" content="noindex, nofollow" /><title>Communications Test</title></head>
  17. <body>
  18. <p>Testing communications to various destinations. This is a simple diagnostic to determine whether your server can connect to common destinations.<br>
  19. <em>For advanced "details" mode, add </em><strong>?details=on</strong><em> to the URL.</em></p>
  20.  
  21. <?php
  22. ini_set('display_errors', 1);
  23. $showDetails = (isset($_GET['d']) && $_GET['d'] != '0') || (isset($_GET['details']) && $_GET['details'] != '0'); // supports ?d= or ?details= and any value other than '0' turns it on.
  24. $errorMessage = '<span style="color:red;font-weight:bold">Error </span>';
  25. $goodMessage = '<span style="color:green;font-weight:bold">GOOD: </span>';
  26.  
  27. echo 'Connecting to Zen Cart Support Server (http) ...<br>';
  28. doCurlTest('http://www.zen-cart.com/testcurl.php');
  29.  
  30. echo 'Connecting to Zen Cart Support Server (https) ...<br>';
  31. doCurlTest('https://www.zen-cart.com/testcurl.php');
  32.  
  33. echo 'Connecting to USPS (port 80)...<br>';
  34. doCurlTest('http://production.shippingapis.com/shippingapi.dll');
  35. if (isset($_GET['old']) && $_GET['old'] == '1') {
  36.   echo '2nd test, using old method: ';
  37.   dofsockTest('production.shippingapis.com', 80);
  38. }
  39.  
  40. echo 'Connecting to USPS Test/Staging/Sandbox Server (port 80)...<br>';
  41. doCurlTest('http://stg-production.shippingapis.com/ShippingApi.dll');
  42. if (isset($_GET['old']) && $_GET['old'] == '1') {
  43.   echo '2nd test, using old method: ';
  44.   dofsockTest('stg-production.shippingapis.com', 80);
  45. }
  46.  
  47. echo 'Connecting to UPS (port 80)...<br>';
  48. dofsockTest('www.ups.com', 80);
  49.  
  50. echo 'Connecting to UPSXML (SSL) (wwwcie.ups.com) ...<br>';
  51. doCurlTest('https://wwwcie.ups.com/ups.app/xml/Rate');
  52.  
  53. echo 'Connecting to UPSXML (SSL) (www.ups.com) ...<br>';
  54. doCurlTest('https://www.ups.com/ups.app/xml/Rate');
  55.  
  56. echo 'Connecting to UPSXML (SSL) (onlinetools.ups.com) ...<br>';
  57. doCurlTest('https://onlinetools.ups.com/ups.app/xml/Rate');
  58.  
  59. echo 'Connecting to FedEx (port 80)...<br>';
  60. dofsockTest('fedex.com', 80);
  61.  
  62. echo 'Connecting to PayPal IPN (port 443)...<br>';
  63. dofsockTest('www.paypal.com', 443);
  64. doCurlTest('https://www.paypal.com/cgi-bin/webscr');
  65.  
  66. echo 'Connecting to PayPal IPN (port 443) Sandbox ...<br>';
  67. dofsockTest('www.sandbox.paypal.com', 443);
  68. doCurlTest('https://www.sandbox.paypal.com/cgi-bin/webscr');
  69.  
  70. // echo 'Connecting to PayPal IPN (port 443) Sandbox ...<br>';
  71. // dofsockTest('ipnpb.paypal.com', 443);
  72. // doCurlTest('https://ipnpb.paypal.com');
  73.  
  74. echo 'Connecting to PayPal Express/Pro Server ...<br>';
  75. doCurlTest('https://api-3t.paypal.com/nvp');
  76.  
  77. echo 'Connecting to PayPal Express/Pro Sandbox ...<br>';
  78. doCurlTest('https://api-3t.sandbox.paypal.com/nvp');
  79.  
  80. echo 'Connecting to PayPal Payflowpro Server ...<br>';
  81. doCurlTest('https://payflowpro.paypal.com/transaction');
  82.  
  83. echo 'Connecting to AuthorizeNet Production Server ...<br>';
  84. doCurlTest('https://secure.authorize.net/gateway/transact.dll');
  85.  
  86. echo 'Connecting to AuthorizeNet Developer/Sandbox Server ...<br>';
  87. doCurlTest('https://test.authorize.net/gateway/transact.dll');
  88.  
  89. echo 'Connecting to First Data GGe4 server (SSL)...<br>';
  90. doCurlTest('https://checkout.globalgatewaye4.firstdata.com/payment');
  91.  
  92. echo 'Connecting to LinkPointAPI server (port 1129)...<br>';
  93. doCurlTest('https://secure.linkpt.net/LSGSXML:1129');
  94.  
  95. ?>
  96.  
  97. <em>Testing completed. See results above.</em>
  98. </body>
  99. </html>
  100.  
  101. <?php
  102. die();
  103. //////// Processing logic ///////
  104.  
  105. function doCurlTest($url = 'http://www.zen-cart.com/testcurl.php', $postdata = "field1=This is a test&statuskey=ready") {
  106.   global $goodMessage, $errorMessage, $showDetails;
  107.   $extraMessage = '';
  108.   $showResult = FALSE;
  109.   if (strpos($url, 'zen-cart.com') && isset($_GET['z']) && $_GET['z'] != '0') $showResult = TRUE;
  110.   if (!strpos($url, 'zen-cart.com') && isset($_GET['r']) && $_GET['r'] != '0') $showResult = TRUE;
  111.  
  112.   $ch = curl_init();
  113.   curl_setopt($ch, CURLOPT_URL, $url);
  114.   if ($postdata != '') {
  115.     curl_setopt($ch, CURLOPT_POST, 1);
  116.     curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  117.   }
  118.   $val = preg_match('/(.*):([0-9]*)$/', $url, $regs);
  119.   if ($val) {
  120.     curl_setopt($ch, CURLOPT_PORT, $regs[2]);
  121.     curl_setopt($ch, CURLOPT_URL, $regs[1]);
  122.   }
  123.  
  124.   curl_setopt($ch, CURLOPT_VERBOSE, 1);
  125.   curl_setopt($ch, CURLOPT_HEADER, 0);
  126.   curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  127.   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  128.   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  129.   curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
  130.   curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
  131.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  132.   curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  133.   curl_setopt($ch, CURLOPT_USERAGENT, 'Zen Cart(tm) - CURL TEST');
  134.  
  135. //  curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  136. //  curl_setopt($ch, CURLOPT_CAINFO, '/local/path/to/cacert.pem'); // for offline testing, this file can be obtained from http://curl.haxx.se/docs/caextract.html ... should never be used in production!
  137.  
  138.  
  139.   $result = curl_exec($ch);
  140.   $errtext = curl_error($ch);
  141.   $errnum = curl_errno($ch);
  142.   // check for common certificate errors, and resubmit
  143.   if (in_array($errnum, array(60,61))) {
  144.     echo $errorMessage . $errnum . ': ' . $errtext;
  145.     echo '<br><p style="color:red;"><strong>IMPORTANT NOTE: Error 60 or 61 means that this server has an SSL certificate configuration problem. YOU NEED TO ASK YOUR HOSTING COMPANY SERVER ADMIN FOR ASSISTANCE with fixing the server\'s OpenSSL certificate chain. <br>This error has nothing to do with Zen Cart. It is a server configuration issue.</strong><br><br>(If you are running this test on a localhost/PC/dev/standlone server then you can either ignore this until you put the site on a live production server, or temporarily override things by manually configuring the CURLOPT_CAINFO value with a legitimate CA bundle. If you don\'t know what that means, just defer your CURL testing until you are on a live production webserver!)</p>';
  146.     echo 'Testing again with less security...<br>';
  147.     $extraMessage = ' (but without being able to verify certificate chain. Again: this is a <u>server</u> issue, not a Zen Cart issue.)';
  148.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  149.     $result = curl_exec($ch);
  150.     $errtext = curl_error($ch);
  151.     $errnum = curl_errno($ch);
  152.   }
  153.   $commInfo = @curl_getinfo($ch);
  154.   curl_close ($ch);
  155.  
  156.   // enclose URL in quotes so it doesn't get converted to a clickable link if posted on the forum
  157.   if (isset($commInfo['url'])) $commInfo['url'] = '"' . $commInfo['url'] . '"';
  158.  
  159.   // Handle results
  160.   if ($errnum != 0) {
  161.     echo $errorMessage . $errnum . ': ' . $errtext . '<br><br>';
  162.   } else {
  163.     echo $goodMessage . 'CURL Connection successful.' . $extraMessage . '<br><br>';
  164.     if ($showResult && $commInfo['http_code'] == 200) echo '<strong>COMMUNICATIONS TEST OKAY.</strong><br>You may see error information below, but that information simply confirms that the server actually responded, which means communications is open.<br>';
  165.     if ($showResult) echo '<br>' . $result . '<br>';
  166.   }
  167.   if ($showDetails) echo '<pre>Connection Details:' . "\n" . print_r($commInfo, true) . '</pre><br /><br />';
  168.  
  169.   if ($showDetails) echo '<hr>';
  170.  
  171. }
  172.  
  173. function dofsockTest($url = 'www.zen-cart.com/testcurl.php', $port = 80, $timeout = 5) {
  174.   global $goodMessage, $errorMessage, $showDetails;
  175.   /* in case it's not set, set 10-second timeout for fsockopen */
  176.   ini_set("default_socket_timeout", "10");
  177.   $socket = fsockopen($url, $port, $errnum, $errtext, $timeout);
  178.   if ($socket) echo $goodMessage . 'Socket established<br><br>';
  179.   else echo '<br>' .$errorMessage .' Num: ' . $errnum . ', Message: ' . $errtext . '<br><br>';
  180.   if ($showDetails) echo '<hr>';
  181. }
  182.  
  183.  
  184. /**
  185.  * FOR DEVELOPERS ONLY:
  186.  * Additional tip about CURLOPT_CAINFO in Development environments  (NOTE: THIS IS NOT SAFE FOR LIVE PRODUCTION SERVERS!!!!!)
  187.  * 1. obtain the cacert.pem file from http://curl.haxx.se/docs/caextract.html
  188.  * 2. place the file on your development server
  189.  * 3. edit your php.ini and set curl.cainfo = '/your/full/path/to/cacert.pem' ... or manually add CURLOPT_CAINFO to every CURL call you do in every php file.
  190.  * NOTE: this opens you up to MITM risks, so should NEVER be done on a live server!!!!!
  191.  */
  192.  


cron