3 * Pings a given host and returns a red or green image.
\r
4 * Green when the host is online, red when offline.
\r
6 * Keywords: http image ping online check
\r
8 * @author Christian Weiske <weiske@mogic.com>
\r
10 if (!isset($_GET['host'])) {
\r
11 sendError('Host missing');
\r
13 $host = $_GET['host'];
\r
15 sendError('Empty host');
\r
18 if (!isset($_GET['size'])) {
\r
21 $size = intval($_GET['size']);
\r
24 exec('ping -c 1 -w 1 -W 1 ' . escapeshellarg($host), $output, $retval);
\r
27 sendSvg($size, 'fill: green');
\r
30 sendSvg($size, 'fill: red');
\r
33 function sendSvg($size, $style)
\r
35 $half = intval($size / 2);
\r
36 header('HTTP/1.0 200 OK');
\r
37 header('Content-type: image/svg+xml');
\r
39 <?xml version="1.0"?>
\r
40 <svg xmlns="http://www.w3.org/2000/svg" width="$size" height="$size">
\r
41 <circle cx="$half" cy="$half" r="$half" style="$style"/>
\r
47 function sendError($msg)
\r
49 header('HTTP/1.0 400 Bad Request');
\r
50 header('Content-type: text/plain');
\r