summaryrefslogtreecommitdiff
path: root/httemplate/misc/ping.html
blob: 4f0360e8b2ab2e75526a4eeb73cc7fa333114509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<% 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>