暫無描述

test-connection.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. if (isset($_GET['provider'])) {
  3. $providerID = $_GET['provider'];
  4. if (isset(NextendSocialLogin::$allowedProviders[$providerID])) {
  5. $provider = NextendSocialLogin::$allowedProviders[$providerID];
  6. ?>
  7. <div class="nsl-admin-content">
  8. <h1>Debug: <?php echo $provider->getLabel(); ?></h1>
  9. <?php
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_URL, $provider->getTestUrl());
  12. curl_setopt($ch, CURLOPT_POST, 1);
  13. curl_setopt($ch, CURLOPT_POSTFIELDS, "");
  14. curl_setopt($ch, CURLOPT_VERBOSE, true);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  17. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  18. $cacert = ABSPATH . WPINC . '/certificates/ca-bundle.crt';
  19. if (file_exists($cacert)) {
  20. curl_setopt($ch, CURLOPT_CAINFO, $cacert);
  21. }
  22. $file = tempnam(sys_get_temp_dir(), 'nsl-test');
  23. $temporaryHandle = fopen($file, 'w+');
  24. curl_setopt($ch, CURLOPT_STDERR, $temporaryHandle);
  25. $output = curl_exec($ch);
  26. curl_close($ch);
  27. rewind($temporaryHandle);
  28. $verboseLog = stream_get_contents($temporaryHandle);
  29. if (preg_match('/connected/i', $verboseLog)) {
  30. ?>
  31. <div class="updated"><p>
  32. <b><?php printf(__('Network connection successful: %1$s', 'nextend-facebook-connect'), $provider->getTestUrl()); ?></b>
  33. </p></div>
  34. <?php
  35. } else {
  36. ?>
  37. <div class="error">
  38. <p>
  39. <b><?php printf(__('Network connection failed: %1$s', 'nextend-facebook-connect'), $provider->getTestUrl()); ?></b>
  40. </p>
  41. <p>
  42. <?php _e('Please contact with your hosting provider to resolve the network issue between your server and the provider.', 'nextend-facebook-connect'); ?>
  43. </p>
  44. </div>
  45. <?php
  46. }
  47. echo "<pre>", htmlspecialchars($verboseLog), "</pre>\n";
  48. fclose($temporaryHandle);
  49. echo "<pre>", htmlspecialchars($output), "</pre>\n";
  50. @unlink($file);
  51. ?>
  52. </div>
  53. <?php
  54. }
  55. }