Skip to content

Commit

Permalink
Change ping interval to 0.2 seconds from 1 second to make it faster. …
Browse files Browse the repository at this point in the history
…Also allow use to select how many pings they want
  • Loading branch information
vvuksan committed Apr 15, 2016
1 parent 23ba9f0 commit 203d835
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
38 changes: 25 additions & 13 deletions get_mtr.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
die("Address is not an IP and I can't resolve it. Doing nothing");
}

# Cap ping count to 20
if ( isset($_REQUEST['ping_count']) and is_numeric($_REQUEST['ping_count']) and $_REQUEST['ping_count'] > 0 and $_REQUEST['ping_count'] <= 20 ) {
$ping_count = intval($_REQUEST['ping_count']);
} else {
$ping_count = 10;
}

$site_id = is_numeric($_REQUEST['site_id']) ? $_REQUEST['site_id'] : -1;

$conf['remote_exe'] = "get_mtr.php";
Expand All @@ -45,9 +52,9 @@
<pre>
<?php
if ( filter_var($user['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) ) {
passthru($conf['ping6_bin'] . " -c 4 " . $user['ip']);
passthru($conf['ping6_bin'] . " -i 0.2 -c " . $ping_count . " " . $user['ip']);
} else {
passthru($conf['ping_bin'] . " -c 4 " . $user['ip']);
passthru($conf['ping_bin'] . " -i 0.2 -c " . $ping_count . " " . $user['ip']);
}
?>
</pre>
Expand All @@ -72,20 +79,23 @@

// Get results from all remotes
foreach ( $conf['remotes'] as $index => $remote ) {
print "<div id='remote_" . ${index} . "'>
<button onClick='$(\"#mtrping_results_" . ${index} . "\").toggle();'>" .$conf['remotes'][$index]['name']. "</button></div>";
print "<div id='mtrping_results_" . ${index} ."'>";

print "<div id='remote_" . $index . "'>
<button onClick='$(\"#mtrping_results_" . $index . "\").toggle();'>" .$conf['remotes'][$index]['name']. "</button></div>";

print "<div id='mtrping_results_" . $index ."'>";

#print (file_get_contents($conf['remotes'][$index]['base_url'] . "get_mtr.php?site_id=-1" .
#"&hostname=" . $_REQUEST['hostname'] ));
print "<img src=\"img/spinner.gif\"></div>";


$args[] = 'hostname=' . htmlentities($_REQUEST['hostname']);
$args[] = 'ping_count=' . $ping_count;

print '
<script>
$.get("' . $conf['remote_exe'] . '", "site_id=' . $index . '&hostname=' . htmlentities($_REQUEST['hostname']) . '", function(data) {
$("#mtrping_results_' . ${index} .'").html(data);
$.get("' . $conf['remote_exe'] . '", "site_id=' . $index . '&' . join("&", $args) . '", function(data) {
$("#mtrping_results_' . $index .'").html(data);
});
</script>
<p></p>';
Expand All @@ -100,8 +110,10 @@

print "<div><h3>" .$conf['remotes'][$site_id]['name']. "</h3></div>";
print "<div class=dns_results>";
print (file_get_contents($conf['remotes'][$site_id]['base_url'] . $conf['remote_exe'] . "?site_id=-1" .
"&hostname=" . $_REQUEST['hostname'] ));
$args[] = 'hostname=' . htmlentities($_REQUEST['hostname']);
$args[] = 'ping_count=' . $ping_count;
$url = $conf['remotes'][$site_id]['base_url'] . $conf['remote_exe'] . "?site_id=-1&" . join("&", $args);
print (file_get_contents($url));
print "</div>";


Expand Down
5 changes: 3 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ function getSSLCert() {
print "<input type=\"hidden\" name=\"site_id\" value=\"-1\">";
}
?>
Host name <input id="hostname" name="hostname" size=100>
<button class="query_buttons" id="dns_querybutton" onclick="getPingMtr(); return false;">Ping/MTR</button>
Host name <input id="hostname" name="hostname" size=80>
# Pings <input id="ping_count" name="ping_count" value=5 size=4>
<button class="query_buttons" id="ping_querybutton" onclick="getPingMtr(); return false;">Ping/MTR</button>
<br />
</form>
</div>
Expand Down

0 comments on commit 203d835

Please sign in to comment.