git.cweiske.de
/
paste
/
332.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
73af925
)
(no commit message)
master
author
Christian Weiske
<cweiske@cweiske.de>
Wed, 4 May 2016 11:14:33 +0000
(13:14 +0200)
committer
www-cweiske
<www-cweiske@localhost.localdomain>
Wed, 4 May 2016 11:14:33 +0000
(13:14 +0200)
ping.php
patch
|
blob
|
history
diff --git
a/ping.php
b/ping.php
index ca5a562ac742956a9463bc68f49561ed8c01eaea..f1df4b1eddfb6d2840f6d053b6a3d0a12f40a6f0 100644
(file)
--- a/
ping.php
+++ b/
ping.php
@@
-3,6
+3,16
@@
* Pings a given host and returns a red or green image.
\r
* Green when the host is online, red when offline.
\r
*
\r
* Pings a given host and returns a red or green image.
\r
* Green when the host is online, red when offline.
\r
*
\r
+ * Error: ping: socket: Operation not permitted
\r
+ * (raw socket required by specified options).
\r
+ *
\r
+ * Solution:
\r
+ * $ chmod +s /path/to/ping
\r
+ * Alternative:
\r
+ * $ setcap cap_net_raw+ep /path/to/ping
\r
+ * Alternative:
\r
+ * make it passwordless sudo
\r
+ *
\r
* Keywords: http image ping online check
\r
*
\r
* @author Christian Weiske <weiske@mogic.com>
\r
* Keywords: http image ping online check
\r
*
\r
* @author Christian Weiske <weiske@mogic.com>
\r
@@
-21,13
+31,18
@@
if (!isset($_GET['size'])) {
$size = intval($_GET['size']);
\r
}
\r
\r
$size = intval($_GET['size']);
\r
}
\r
\r
-exec('ping -c 1 -w 1 -W 1 ' . escapeshellarg($host), $output, $retval);
\r
+exec('ping -c 1 -w 1 -W 1 ' . escapeshellarg($host)
. ' 2>&1'
, $output, $retval);
\r
if ($retval == 0) {
\r
//all fine
\r
sendSvg($size, 'fill: green');
\r
if ($retval == 0) {
\r
//all fine
\r
sendSvg($size, 'fill: green');
\r
-} else {
\r
- //
error
\r
+} else
if ($retval == 1)
{
\r
+ //
no reply
\r
sendSvg($size, 'fill: red');
\r
sendSvg($size, 'fill: red');
\r
+} else {
\r
+ //some other error, e.g. permissions
\r
+ header('HTTP/1.0 500 Internal server error');
\r
+ header('Content-type: text/plain');
\r
+ echo implode("\n", $output) . "\n";
\r
}
\r
\r
function sendSvg($size, $style)
\r
}
\r
\r
function sendSvg($size, $style)
\r
@@
-35,8
+50,8
@@
function sendSvg($size, $style)
$half = intval($size / 2);
\r
header('HTTP/1.0 200 OK');
\r
header('Content-type: image/svg+xml');
\r
$half = intval($size / 2);
\r
header('HTTP/1.0 200 OK');
\r
header('Content-type: image/svg+xml');
\r
+ echo '<' . '?xml version="1.0"?>' . "\n";
\r
echo <<<XML
\r
echo <<<XML
\r
-<?xml version="1.0"?>
\r
<svg xmlns="http://www.w3.org/2000/svg" width="$size" height="$size">
\r
<circle cx="$half" cy="$half" r="$half" style="$style"/>
\r
</svg>
\r
<svg xmlns="http://www.w3.org/2000/svg" width="$size" height="$size">
\r
<circle cx="$half" cy="$half" r="$half" style="$style"/>
\r
</svg>
\r