forked from Jackysi/advancedtomato-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools-trace.asp
204 lines (176 loc) · 5.38 KB
/
tools-trace.asp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!--
Tomato GUI
Copyright (C) 2006-2010 Jonathan Zarate
http://www.polarcloud.com/tomato/
For use with Tomato Firmware only.
No part of this file may be used without permission.
--><title>Trace</title>
<content>
<style type="text/css">
#ttr-grid .co1, #ttr-grid .co3 {
text-align: right;
}
#ttr-grid .co1 {
width: 30px;
}
#ttr-grid .co2 {
width: 410px;
}
#ttr-grid .co4, #ttr-grid .co5, #ttr-grid .co6 {
text-align: right;
width: 70px;
}
#ttr-grid .header .co1 {
text-align: left;
}
</style>
<script type="text/javascript">
var tracedata = '';
var tg = new TomatoGrid();
tg.setup = function() {
this.init('ttr-grid');
this.headerSet(['Hop', 'Address', 'Min (ms)', 'Max (ms)', 'Avg (ms)', '+/- (ms)']);
}
tg.populate = function() {
var seq = 1;
var buf = tracedata.split('\n');
var i, j, k;
var s, f;
var addr, emsg, min, max, avg;
var time;
var last = -1;
this.removeAllData();
for (i = 0; i < buf.length; ++i) {
if (!buf[i].match(/^\s*(\d+)\s+(.+)$/)) continue;
if (RegExp.$1 != seq) continue;
s = RegExp.$2;
if (s.match(/^([\w\.:\-]+)\s+\(([\d\.:A-Fa-f]+)\)/)) {
addr = RegExp.$1;
if (addr != RegExp.$2) addr += ' (' + RegExp.$2 + ')';
}
else addr = '*';
min = max = avg = '';
change = '';
if (time = s.match(/(\d+\.\d+) ms/g)) { // odd: captures 'ms'
min = 0xFFFF;
avg = max = 0;
k = 0;
for (j = 0; j < time.length; ++j) {
f = parseFloat(time[j]);
if (isNaN(f)) continue;
if (f < min) min = f;
if (f > max) max = f;
avg += f;
++k
}
if (k) {
avg /= k;
if (last >= 0) {
change = avg - last;
change = change.toFixed(2);
}
last = avg;
min = min.toFixed(2);
max = max.toFixed(2);
avg = avg.toFixed(2);
}
else {
min = max = avg = '';
last = -1;
}
}
else last = -1;
if (s.match(/ (![<>\w+-]+)/)) emsg = RegExp.$1;
else emsg = null;
this.insertData(-1, [seq, addr, min, max, avg, change])
++seq;
}
E('debug').value = tracedata;
tracedata = '';
spin(0);
}
function verifyFields(focused, quiet)
{
var s;
var e;
e = E('_f_addr');
s = e.value.trim();
if (!s.match(/^[\w\-\.\:]+$/)) {
ferror.set(e, 'Invalid hostname/address', quiet);
return 0;
}
ferror.clear(e);
return v_range('_f_hops', quiet, 2, 40) && v_range('_f_wait', quiet, 2, 10);
}
var tracer = null;
function spin(x)
{
E('traceb').disabled = x;
E('_f_addr').disabled = x;
E('_f_hops').disabled = x;
E('_f_wait').disabled = x;
E('wait').style.visibility = x ? 'visible' : 'hidden';
if (!x) tracer = null;
}
function trace()
{
// Opera 8 sometimes sends 2 clicks
if (tracer) return;
if (!verifyFields(null, 0)) return;
spin(1);
E('trace-error').style.visibility = 'hidden';
tracer = new XmlHttp();
tracer.onCompleted = function(text, xml) {
eval(text);
tg.populate();
}
tracer.onError = function(x) {
spin(0);
E('trace-error').innerHTML = 'ERROR: ' + E('_f_addr').value + ' - ' + x;
E('trace-error').style.visibility = 'visible';
}
var addr = E('_f_addr').value;
var hops = E('_f_hops').value;
var wait = E('_f_wait').value;
tracer.post('trace.cgi', 'addr=' + addr + '&hops=' + hops + '&wait=' + wait);
cookie.set('traceaddr', addr);
cookie.set('tracehops', hops);
cookie.set('tracewait', wait);
}
function init() {
var s;
if ((s = cookie.get('traceaddr')) != null) E('_f_addr').value = s;
if ((s = cookie.get('tracehops')) != null) E('_f_hops').value = s;
if ((s = cookie.get('tracewait')) != null) E('_f_wait').value = s;
tg.setup();
E('_f_addr').onkeypress = function(ev) { if (checkEvent(ev).keyCode == 13) trace(); }
}
</script>
<ul class="nav-tabs">
<li><a class="ajaxload" href="tools-ping.asp"><i class="icon-ping"></i> Ping</a></li>
<li><a class="active"><i class="icon-gauge"></i> Trace</a></li>
<li><a class="ajaxload" href="tools-shell.asp"><i class="icon-cmd"></i> System Commands</a></li>
<li><a class="ajaxload" href="tools-survey.asp"><i class="icon-signal"></i> Wireless Survey</a></li>
<li><a class="ajaxload" href="tools-wol.asp"><i class="icon-forward"></i> WOL</a></li>
</ul>
<div class="box">
<div class="heading">Trace Route</div>
<div class="content">
<div id="tracert-form"></div><hr>
<script type="text/javascript">
$('#tracert-form').forms([
{ title: 'Address', name: 'f_addr', type: 'text', maxlen: 64, size: 32, value: '',
suffix: ' <button type="submit" value="Trace" onclick="trace()" id="traceb" class="btn">Trace <i class="icon-gauge"></i></button>' },
{ title: 'Maximum Hops', name: 'f_hops', type: 'text', maxlen: 2, size: 4, value: '20' },
{ title: 'Maximum Wait Time', name: 'f_wait', type: 'text', maxlen: 2, size: 4, value: '3', suffix: ' <small>(seconds per hop)</small>' }
]);
</script>
<div style="visibility:hidden" id="trace-error"></div>
<div style="visibility:hidden;text-align:right" id="wait">Please wait... <div class="spinner"></div></div>
<table id="ttr-grid" class="line-table"></table>
<div style="height:10px;" onclick="javascript:E('debug').style.display=''"></div>
<textarea id="debug" style="width:99%;height:300px;display:none"></textarea>
</div>
</div>
<script type="text/javascript">init();</script>
</content>