Skip to content

Commit 203d835

Browse files
committed
Change ping interval to 0.2 seconds from 1 second to make it faster. Also allow use to select how many pings they want
1 parent 23ba9f0 commit 203d835

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

get_mtr.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
die("Address is not an IP and I can't resolve it. Doing nothing");
2929
}
3030

31+
# Cap ping count to 20
32+
if ( isset($_REQUEST['ping_count']) and is_numeric($_REQUEST['ping_count']) and $_REQUEST['ping_count'] > 0 and $_REQUEST['ping_count'] <= 20 ) {
33+
$ping_count = intval($_REQUEST['ping_count']);
34+
} else {
35+
$ping_count = 10;
36+
}
37+
3138
$site_id = is_numeric($_REQUEST['site_id']) ? $_REQUEST['site_id'] : -1;
3239

3340
$conf['remote_exe'] = "get_mtr.php";
@@ -45,9 +52,9 @@
4552
<pre>
4653
<?php
4754
if ( filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
48-
passthru($conf['ping6_bin'] . " -c 4 " . $user['ip']);
55+
passthru($conf['ping6_bin'] . " -i 0.2 -c " . $ping_count . " " . $user['ip']);
4956
} else {
50-
passthru($conf['ping_bin'] . " -c 4 " . $user['ip']);
57+
passthru($conf['ping_bin'] . " -i 0.2 -c " . $ping_count . " " . $user['ip']);
5158
}
5259
?>
5360
</pre>
@@ -72,20 +79,23 @@
7279

7380
// Get results from all remotes
7481
foreach ( $conf['remotes'] as $index => $remote ) {
75-
76-
print "<div id='remote_" . ${index} . "'>
77-
<button onClick='$(\"#mtrping_results_" . ${index} . "\").toggle();'>" .$conf['remotes'][$index]['name']. "</button></div>";
78-
79-
print "<div id='mtrping_results_" . ${index} ."'>";
80-
82+
83+
print "<div id='remote_" . $index . "'>
84+
<button onClick='$(\"#mtrping_results_" . $index . "\").toggle();'>" .$conf['remotes'][$index]['name']. "</button></div>";
85+
86+
print "<div id='mtrping_results_" . $index ."'>";
87+
8188
#print (file_get_contents($conf['remotes'][$index]['base_url'] . "get_mtr.php?site_id=-1" .
8289
#"&hostname=" . $_REQUEST['hostname'] ));
8390
print "<img src=\"img/spinner.gif\"></div>";
84-
91+
92+
$args[] = 'hostname=' . htmlentities($_REQUEST['hostname']);
93+
$args[] = 'ping_count=' . $ping_count;
94+
8595
print '
8696
<script>
87-
$.get("' . $conf['remote_exe'] . '", "site_id=' . $index . '&hostname=' . htmlentities($_REQUEST['hostname']) . '", function(data) {
88-
$("#mtrping_results_' . ${index} .'").html(data);
97+
$.get("' . $conf['remote_exe'] . '", "site_id=' . $index . '&' . join("&", $args) . '", function(data) {
98+
$("#mtrping_results_' . $index .'").html(data);
8999
});
90100
</script>
91101
<p></p>';
@@ -100,8 +110,10 @@
100110

101111
print "<div><h3>" .$conf['remotes'][$site_id]['name']. "</h3></div>";
102112
print "<div class=dns_results>";
103-
print (file_get_contents($conf['remotes'][$site_id]['base_url'] . $conf['remote_exe'] . "?site_id=-1" .
104-
"&hostname=" . $_REQUEST['hostname'] ));
113+
$args[] = 'hostname=' . htmlentities($_REQUEST['hostname']);
114+
$args[] = 'ping_count=' . $ping_count;
115+
$url = $conf['remotes'][$site_id]['base_url'] . $conf['remote_exe'] . "?site_id=-1&" . join("&", $args);
116+
print (file_get_contents($url));
105117
print "</div>";
106118

107119

index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ function getSSLCert() {
319319
print "<input type=\"hidden\" name=\"site_id\" value=\"-1\">";
320320
}
321321
?>
322-
Host name <input id="hostname" name="hostname" size=100>
323-
<button class="query_buttons" id="dns_querybutton" onclick="getPingMtr(); return false;">Ping/MTR</button>
322+
Host name <input id="hostname" name="hostname" size=80>
323+
# Pings <input id="ping_count" name="ping_count" value=5 size=4>
324+
<button class="query_buttons" id="ping_querybutton" onclick="getPingMtr(); return false;">Ping/MTR</button>
324325
<br />
325326
</form>
326327
</div>

0 commit comments

Comments
 (0)