Skip to content

Instantly share code, notes, and snippets.

@JRMorris77
Last active January 3, 2018 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRMorris77/7195456f5f4494f3d3da89aa4a57d93c to your computer and use it in GitHub Desktop.
Save JRMorris77/7195456f5f4494f3d3da89aa4a57d93c to your computer and use it in GitHub Desktop.
Standalone script for gathering WordPress site and server info with cURL test
<?php
/**
* Script Name: WPMU DEV SLS Diagnostics
* Script URI: https://premium.wpmudev.org/
* Description: Misc diagnostic tools used by WPMU DEV SLS Tech Support
* Author: WPMU DEV
* Version: 0.5.2
* Author URI: https://premium.wpmudev.org/
*
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<!DOCTYPE html>
<head>
<meta name="robots" content="noindex, nofollow" />
<title>Quick Diagnostics</title>
<style type="text/css" media="screen">
body{
padding:0px;
margin:0px;
text-align:left;
font-size:12px;
font-family:"Lucida Console", Monaco, monospace;
}
#content{
padding:1em 2em;
}
pre{
height:250px;
overflow:scroll;
background:#efefef;
border:1px solid silver;
padding:0 1em;
}
</style>
</head>
<body>
<!-- cURL Test 3 - Uncomment to run. //-->
<!--
<?php
$ch = curl_init("https://premium.wpmudev.org/api/dashboard/v1/"); // initialize curl handle
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
print($data);
?>
<style type="text/css" media="all">
body{
background: black;
color: white;
}
#content{
display:none !important;
}
</style>
//-->
<div id="content">
<h1>Quick Diagnostics</h1>
<hr />
<?php
$du = shell_exec('du -hs .');
$ls = shell_exec('ls -al .');
$cat = shell_exec('cat ./wp-content/debug.log');
?>
<h2>Current Disk Usage</h2>
<p><?php echo $du; ?></p>
<h2>Current Directory Listing</h2>
<pre><?php echo $ls; ?></pre>
<h2>cURL Test 1</h2>
<pre><?php
if (isDEVAvailible('https://premium.wpmudev.org'))
{
echo "<h2>premium.wpmudev.org is Up and running!</h2>";
}
else
{
echo "<h2>Whoops, nothing found at premium.wpmudev.org.</h2>";
}
//returns true, if domain is availible, false if not
function isDEVAvailible($domain)
{
//check, if a valid url is provided
if(!filter_var($domain, FILTER_VALIDATE_URL))
{
return false;
}
//initialize curl
$curlInit = curl_init($domain);
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
//get answer
$response = curl_exec($curlInit);
curl_close($curlInit);
if ($response) return true;
return false;
}
if (isGoogleAvailible('https://google.com'))
{
echo "<h2>google.com is Up and running!</h2>";
}
else
{
echo "<h2>Whoops, nothing found at google.com.</h2>";
}
//returns true, if domain is availible, false if not
function isGoogleAvailible($domain)
{
//check, if a valid url is provided
if(!filter_var($domain, FILTER_VALIDATE_URL))
{
return false;
}
//initialize curl
$curlInit = curl_init($domain);
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
//get answer
$response = curl_exec($curlInit);
curl_close($curlInit);
if ($response) return true;
return false;
}?></pre>
<h2>cURL Test 2</h2>
<pre><?php
$ch = curl_init('https://premium.wpmudev.org/api/dashboard/v1/');
curl_setopt($ch, CURLOPT_CONNECT_ONLY, true);
curl_exec($ch);
$getinfo = curl_getinfo($ch);
$out = '';
foreach($getinfo as $key => $value) {
$title = "<strong>" . $key . "</strong>";
if( is_array( $value ) ){
$content = '';
if( ! empty( $value ) ){
foreach( $value as $k => $v ){
$sub_title = '<strong>' . $k . '</strong>';
$content .= "<span style=''padding-left: 20px'>\n";
$content .= $sub_title .' : ';
$content .= $v;
$content .= "</span>\n";
}
}
}
else{
$content = $value;
}
$out .= $title . ': ' . $content . "\n";
}
echo $out;
curl_close($ch);
?></pre>
<h2>debug.log output</h2>
<pre><?php echo $cat; ?></pre>
<h2>PHPInfo</h2>
<pre><?php phpinfo(); ?></pre>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment