[freeside-commits] freeside/httemplate/misc ping.html, NONE, 1.1 xmlhttp-ping.html, NONE, 1.1
Ivan,,,
ivan at wavetail.420.am
Mon Sep 14 16:52:03 PDT 2009
Update of /home/cvs/cvsroot/freeside/httemplate/misc
In directory wavetail.420.am:/tmp/cvs-serv24976/httemplate/misc
Added Files:
ping.html xmlhttp-ping.html
Log Message:
ping tool, RT#5845
--- NEW FILE: xmlhttp-ping.html ---
<% objToJson($return) %>
<%init>
my $conf = new FS::Conf;
my $sub = $cgi->param('sub');
die "$sub not supported" unless $sub eq 'ping';
my $ip = $cgi->param('arg');
my $ping = new Net::Ping('external', 5);
$ping->hires(1);
#my $a=time; warn "pinging\n";
my ($ret, $duration, $ip2) = $ping->ping($ip);
#warn "done pinging (". int(time-$a). "s)\n";
my $return = [ $ret, $duration ];
</%init>
--- NEW FILE: ping.html ---
<% include('/elements/header-popup.html', "Ping $ip" ) %>
<% include('/elements/xmlhttp.html',
'url' => $p. 'misc/xmlhttp-ping.html',
'subs' => [ 'ping' ],
)
%>
%# <img src="<%$p%>images/bullet_red.png" border=0>
<%ntable("#cccccc", 2)%>
<TR>
<TD>Status</TD>
<TD BGCOLOR="#ffffff" ID="ping_status">Checking...</TD>
</TR>
<TR>
<TD>Packet loss</TD>
<TD BGCOLOR="#ffffff" ID="ping_packetloss"></TD>
</TR>
<TR>
<TD>Latency</TD>
<TD BGCOLOR="#ffffff" ID="ping_latency"></TD>
</TR>
<TR>
<TD>Packets</TD>
<TD BGCOLOR="#ffffff" ID="ping_packets"></TD>
</TR>
</TABLE>
<BR>
<CENTER>
<INPUT TYPE="button" VALUE="Close" onClick="parent.nd(1);">
</CENTER>
<SCRIPT TYPE="text/javascript">
var fails = 0;
var pongs = 0;
var totaltime = 0;
var avg = 0;
function ping_update ( updatetext ) {
var pingArray = eval('(' + updatetext + ')');
var status = pingArray[0];
var rtt = pingArray[1];
if ( status == 0 ) {
fails++;
} else if ( status == 1 ) {
pongs++;
totaltime = totaltime + rtt;
avg = totaltime / pongs;
}
var loss = 100 * fails / ( fails + pongs );
var statusCell = document.getElementById('ping_status');
var packetlossCell = document.getElementById('ping_packetloss');
var latencyCell = document.getElementById('ping_latency');
var packetsCell = document.getElementById('ping_packets');
var status = '';
// red conditions
if ( loss == 100 ) {
status = '<FONT COLOR="#ff0000">Unreachable</FONT>';
} else
// yellow conditions
if ( loss > 50 ) {
status = '<FONT COLOR="#ff9900">High packet loss</FONT>';
} else
if ( avg > 1 ) {
status = '<FONT COLOR="#ff9900">High latency</FONT>';
} else {
status = '<FONT COLOR="#00cc00">Up</FONT>';
}
statusCell.innerHTML = '<B>' + status + '</B>';
packetlossCell.innerHTML = '<B>' + Math.round(loss) + '%</B>';
if ( avg > 0 ) {
latencyCell.innerHTML = '<B>' + Math.round( avg*1000 ) + 'ms</B>';
}
var packets = fails + pongs;
packetsCell.innerHTML = '<B>' + packets + '</B>';
setTimeout( "ping('<%$ip%>', ping_update)", 1000 );
}
ping( '<%$ip%>', ping_update );
</SCRIPT>
<%init>
my($query) = $cgi->keywords;
$query =~ /^([\d\.]+)$/ or die 'Illegal IP';
my $ip = $1;
</%init>
More information about the freeside-commits
mailing list