Skip to content

Instantly share code, notes, and snippets.

@renekreijveld
Last active February 22, 2018 00:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renekreijveld/d4505ebcfd2f29afe48b7c0e6dad8fba to your computer and use it in GitHub Desktop.
Save renekreijveld/d4505ebcfd2f29afe48b7c0e6dad8fba to your computer and use it in GitHub Desktop.
Watchful.li site overview through API
<?php
/**
* @package Watchful.li siteoverzicht
* @author Rene Kreijveld, based on the original work of Watchful.li
* @authorUrl https://about.me/renekreijveld
* @copyright (c) 2016, Rene Kreijveld
*/
//Config
define('API_KEY', 'plaats-jouw-watchful.li-api-key-hier');
define('BASE_URL', 'https://watchful.li/api/v1');
// setup curl call, request json format
$ch = curl_init(BASE_URL . '/sites?limit=100&order=access_url+');
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'api_key: ' . API_KEY,
'Content-type: application/json',
'Accept: application/json'
),
);
curl_setopt_array($ch, ($options));
// retrieve data
$watchful = json_decode(curl_exec($ch));
// if no error proceed
if (!$watchful->error) :
$sitesdata = $watchful->msg->data;
$SitesData = '<table class="table">';
$SitesData .= '<tr>';
$SitesData .= '<th>site id</th>';
$SitesData .= '<th>url</th>';
$SitesData .= '<th>joomla</th>';
$SitesData .= '<th>ip</th>';
$SitesData .= '<th>php</th>';
$SitesData .= '<th>mysql</th>';
$SitesData .= '</tr>';
// process all sites, build HTML table of site data
foreach ($sitesdata as $site) :
$SitesData .= '<tr>';
$SitesData .= '<td>' . $site->siteid . '</td>';
$SitesData .= '<td>' . $site->access_url . '</td>';
$SitesData .= '<td>' . $site->j_version . '</td>';
$SitesData .= '<td>' . $site->ip . '</td>';
$SitesData .= '<td>' . $site->php_version . '</td>';
$SitesData .= '<td>' . $site->mysql_version . '</td>';
$SitesData .= '</tr>';
endforeach;
$SitesData .= '</table>';
endif;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="René Kreijveld">
<title>Watchful.li siteoverzicht</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Font Awesome -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<style type="text/css">
.jumbotron {padding: 16px 0}
.jumbotron h1 {margin-top: 10px}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container">
<h1>Watchful.li siteoverzicht</h1>
</div>
</div>
<div class="container">
<?php echo $SitesData; ?>
<hr>
<footer>
<p style="font-size: 12px;">Data verzameld <i class="fa fa-calendar"></i> <?php echo date("d-m-Y"); ?> <i class="fa fa-clock-o"></i> <?php echo date("H:i:s"); ?>, Geschreven door <a href="http://about.me/renekreijveld" target="_blank">René Kreijveld</a>. Alle data verzameld via <a href="https://watchful.li/support-services/kb/article/watchful-rest-api" target="_blank">Watchful REST API</a>.</p>
</footer>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment