From 53ef280310580741bdde644c6e9a9bc65006459c Mon Sep 17 00:00:00 2001 From: Vladimir Radakovic Date: Tue, 7 Nov 2023 12:25:21 +0100 Subject: [PATCH] Add remote client IP to ping hosts Appended $_SERVER["REMOTE_ADDR"] to ping hosts Reversed order of $hosts array to place clinet IP on first postion String reformatted --- libs/ping.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/ping.php b/libs/ping.php index 9b40268..ea18709 100644 --- a/libs/ping.php +++ b/libs/ping.php @@ -5,11 +5,15 @@ $datas = array(); + if (count($Config->get('ping:hosts')) > 0) $hosts = $Config->get('ping:hosts'); else $hosts = array('google.com', 'wikipedia.org'); +array_push($hosts, $_SERVER["REMOTE_ADDR"]); +$hosts = array_reverse($hosts, true); + foreach ($hosts as $host) { exec('/bin/ping -qc 1 '.$host.' | awk -F/ \'/^(rtt|round-trip)/ { print $5 }\'', $result); @@ -18,7 +22,7 @@ { $result[0] = 0; } - + $datas[] = array( 'host' => $host, 'ping' => $result[0], @@ -27,4 +31,6 @@ unset($result); } -echo json_encode($datas); \ No newline at end of file +$datas[0]["host"] = "Station ({$_SERVER["REMOTE_ADDR"]})"; + +echo json_encode($datas);