1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
12 <meta http-equiv='content-type' content='text/html;charset=utf-
8'
>
13 <meta name='robots' content='noindex,nofollow'
>
14 <title>[<%
ident(); %>] Tools: Ping
</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'
>
16 <link rel='stylesheet' type='text/css' href='color.css'
>
17 <script type='text/javascript' src='tomato.js'
></script>
21 <style type='text/css'
>
29 #tp-grid .co3
, #tp-grid
.co4
, #tp-grid
.co5
, #tp-grid
.co6
{
33 #tp-grid .header
.co1
{
38 <script type='text/javascript' src='debug.js'
></script>
40 <script type='text/javascript'
>
42 // <% nvram(''); %> // http_id
46 var pg
= new TomatoGrid();
47 pg
.setup = function() {
49 this.headerSet(['Seq', 'Address', 'RX Bytes', 'TTL', 'RTT (ms)', '+/- (ms)']);
51 pg
.populate = function()
53 var buf
= pingdata
.split('\n');
62 PING 192.168.1.3 (192.168.1.3): 56 data bytes
63 64 bytes from 192.168.1.3: seq=0 ttl=64 time=1.165 ms
64 64 bytes from 192.168.1.3: seq=1 ttl=64 time=0.675 ms
65 64 bytes from 192.168.1.3: seq=2 ttl=64 time=0.683 ms
66 64 bytes from 192.168.1.3: seq=3 ttl=64 time=0.663 ms
67 64 bytes from 192.168.1.3: seq=4 ttl=64 time=0.682 ms
69 --- 192.168.1.3 ping statistics ---
70 5 packets transmitted, 5 packets received, 0% packet loss
71 round-trip min/avg/max = 0.663/0.773/1.165 ms
75 PING 192.168.5.5 (192.168.1.5): 56 data bytes
76 64 bytes from 192.168.1.5: icmp_seq=0 ttl=64 time=1.2 ms
77 64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=0.7 ms
78 64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=0.7 ms
79 64 bytes from 192.168.1.5: icmp_seq=3 ttl=64 time=0.7 ms
80 64 bytes from 192.168.1.5: icmp_seq=4 ttl=64 time=0.8 ms
82 --- 192.168.5.5 ping statistics ---
83 5 packets transmitted, 5 packets received, 0% packet loss
84 round-trip min/avg/max = 0.7/0.8/1.2 ms
88 for (i
= 0; i
< buf
.length
; ++i
) {
89 if (r
= buf
[i
].match(/^(\d+) bytes from (.+): .*seq=(\d+) ttl=(\d+) time=(\d+\.\d+) ms/)) {
94 if (resolv
[r
[1]]) r
[1] = resolv
[r
[1]] + ' (' + r
[1] + ')';
96 r
[5] = (last
> 0) ? (r
[4] - last
).toFixed(2) : '';
97 r
[4] = r
[4].toFixed(2);
98 this.insertData(-1, r
)
101 else if (buf
[i
].match(/^PING (.+) \((.+)\)/)) {
102 resolv
[RegExp
.$2] = RegExp
.$1;
104 else if (buf
[i
].match(/^(\d+) packets.+, (\d+) packets.+, (\d+%)/)) {
105 stats
= ' Packets: ' + RegExp
.$1 + ' transmitted, ' + RegExp
.$2 + ' received, ' + RegExp
.$3 + ' lost<br>';
107 else if (buf
[i
].match(/^round.+ (\d+\.\d+)\/(\d+\.\d+)\/(\d+\.\d+)/)) {
108 stats
= 'Round-Trip: ' + RegExp
.$1 + ' min, ' + RegExp
.$2 + ' avg, ' + RegExp
.$3 + ' max (ms)<br>' + stats
;
112 E('stats').innerHTML
= stats
;
113 E('debug').value
= pingdata
;
118 function verifyFields(focused
, quiet
)
125 if (!s
.match(/^[\w\.-:]+$/)) {
126 ferror
.set(e
, 'Invalid hostname/address', quiet
);
131 return v_range('_f_count', quiet
, 1, 50) && v_range('_f_size', quiet
, 1, 10240);
139 E('pingb').disabled
= x
;
140 E('_f_addr').disabled
= x
;
141 E('_f_count').disabled
= x
;
142 E('_f_size').disabled
= x
;
143 E('wait').style
.visibility
= x
? 'visible' : 'hidden';
144 if (!x
) pinger
= null;
149 // Opera 8 sometimes sends 2 clicks
152 if (!verifyFields(null, 0)) return;
156 pinger
= new XmlHttp();
157 pinger
.onCompleted = function(text
, xml
) {
161 pinger
.onError = function(x
) {
162 alert('error: ' + x
);
166 var addr
= E('_f_addr').value
;
167 var count
= E('_f_count').value
;
168 var size
= E('_f_size').value
;
169 pinger
.post('ping.cgi', 'addr=' + addr
+ '&count=' + count
+ '&size=' + size
);
171 cookie
.set('pingaddr', addr
);
172 cookie
.set('pingcount', count
);
173 cookie
.set('pingsize', size
);
180 if ((s
= cookie
.get('pingaddr')) != null) E('_f_addr').value
= s
;
181 if ((s
= cookie
.get('pingcount')) != null) E('_f_count').value
= s
;
182 if ((s
= cookie
.get('pingsize')) != null) E('_f_size').value
= s
;
184 E('_f_addr').onkeypress = function(ev
) { if (checkEvent(ev
).keyCode
== 13) ping(); }
189 <body onload='init()'
>
190 <form action='javascript:{}'
>
191 <table id='container' cellspacing=
0>
192 <tr><td colspan=
2 id='header'
>
193 <div class='title'
>Tomato
</div>
194 <div class='version'
>Version <%
version(); %></div>
196 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
198 <div id='ident'
><%
ident(); %></div>
202 <div class='section-title'
>Ping
</div>
203 <div class='section'
>
204 <script type='text/javascript'
>
205 createFieldTable('', [
206 { title
: 'Address', name
: 'f_addr', type
: 'text', maxlen
: 64, size
: 32, value
: '',
207 suffix
: ' <input type="button" value="Ping" onclick="ping()" id="pingb">' },
208 { title
: 'Ping Count', name
: 'f_count', type
: 'text', maxlen
: 2, size
: 7, value
: '5' },
209 { title
: 'Packet Size', name
: 'f_size', type
: 'text', maxlen
: 5, size
: 7, value
: '56', suffix
: ' <small>(bytes)</small>' }
214 <div style=
"visibility:hidden;text-align:right" id=
"wait">Please wait...
<img src='spin.gif'
style=
"vertical-align:top"></div>
216 <table id='tp-grid' class='tomato-grid' cellspacing=
1></table>
217 <pre id='stats'
></pre>
219 <div style='height:
10px;' onclick='javascript:E(
"debug").style.
display=
""'
></div>
220 <textarea id='debug' style='width:
99%;height:
300px;display:none'
></textarea>
225 <tr><td id='footer' colspan=
2> </td></tr>
228 <script type='text/javascript'
>pg
.setup()</script>