BWM and static ARP optimizations
[tomato.git] / release / src / router / www / tools-ping.asp
blobd2253eec198fc03d76d96ae292bac2cb59e0b505
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
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.
9 -->
10 <html>
11 <head>
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>
19 <!-- / / / -->
21 <style type='text/css'>
22 #tp-grid .co1 {
23 text-align: right;
24 width: 30px;
26 #tp-grid .co2 {
27 width: 440px;
29 #tp-grid .co3, #tp-grid .co4, #tp-grid .co5, #tp-grid .co6 {
30 text-align: right;
31 width: 70px;
33 #tp-grid .header .co1 {
34 text-align: left;
36 </style>
38 <script type='text/javascript' src='debug.js'></script>
40 <script type='text/javascript'>
42 // <% nvram(''); %> // http_id
44 var pingdata = '';
46 var pg = new TomatoGrid();
47 pg.setup = function() {
48 this.init('tp-grid');
49 this.headerSet(['Seq', 'Address', 'RX Bytes', 'TTL', 'RTT (ms)', '+/- (ms)']);
51 pg.populate = function()
53 var buf = pingdata.split('\n');
54 var i;
55 var r, s, t;
56 var last = -1;
57 var resolv = [];
58 var stats = '';
60 /* REMOVE-BEGIN
61 1.9
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
74 1.2
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
85 REMOVE-END */
87 this.removeAllData();
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/)) {
90 r.splice(0, 1);
91 t = r[0];
92 r[0] = r[2];
93 r[2] = t;
94 if (resolv[r[1]]) r[1] = resolv[r[1]] + ' (' + r[1] + ')';
95 r[4] *= 1;
96 r[5] = (last > 0) ? (r[4] - last).toFixed(2) : '';
97 r[4] = r[4].toFixed(2);
98 this.insertData(-1, r)
99 last = r[4];
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;
114 pingdata = '';
115 spin(0);
118 function verifyFields(focused, quiet)
120 var s;
121 var e;
123 e = E('_f_addr');
124 s = e.value.trim();
125 if (!s.match(/^[\w\.-]+$/)) {
126 ferror.set(e, 'Invalid address', quiet);
127 return 0;
129 ferror.clear(e);
131 return v_range('_f_count', quiet, 1, 50) && v_range('_f_size', quiet, 1, 10240);
135 var pinger = null;
137 function spin(x)
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;
147 function ping()
149 // Opera 8 sometimes sends 2 clicks
150 if (pinger) return;
152 if (!verifyFields(null, 0)) return;
154 spin(1);
156 pinger = new XmlHttp();
157 pinger.onCompleted = function(text, xml) {
158 eval(text);
159 pg.populate();
161 pinger.onError = function(x) {
162 alert('error: ' + x);
163 spin(0);
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);
176 function init()
178 var s;
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(); }
186 </script>
188 </head>
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>
195 </td></tr>
196 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
197 <td id='content'>
198 <div id='ident'><% ident(); %></div>
200 <!-- / / / -->
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>' }
211 </script>
212 </div>
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>
222 <!-- / / / -->
224 </td></tr>
225 <tr><td id='footer' colspan=2>&nbsp;</td></tr>
226 </table>
227 </form>
228 <script type='text/javascript'>pg.setup()</script>
229 </body>
230 </html>