3 Copyright (C) 2006-2010 Jonathan Zarate
4 http://www.polarcloud.com/tomato/
6 For use with Tomato Firmware only.
7 No part of this file may be used without permission.
10 // -----------------------------------------------------------------------------
12 Array.prototype.find = function(v) {
13 for (var i = 0; i < this.length; ++i)
14 if (this[i] == v) return i;
18 Array.prototype.remove = function(v) {
19 for (var i = 0; i < this.length; ++i) {
28 // -----------------------------------------------------------------------------
30 String.prototype.trim = function() {
31 return this.replace(/^\s+/, '').replace(/\s+$/, '');
34 // -----------------------------------------------------------------------------
36 Number.prototype.pad = function(min) {
37 var s = this.toString();
38 while (s.length < min) s = '0' + s;
42 Number.prototype.hex = function(min)
44 var h = '0123456789ABCDEF';
48 s = h.charAt(n & 15) + s;
50 } while ((--min > 0) || (n > 0));
54 // -----------------------------------------------------------------------------
56 // ---- Element.protoype. doesn't work with all browsers
59 getOffset: function(e) {
60 var r = { x: 0, y: 0 };
62 while (e.offsetParent) {
70 addClass: function(e, name) {
71 if ((e = E(e)) == null) return;
72 var a = e.className.split(/\s+/);
74 for (var i = 1; i < arguments.length; ++i) {
75 if (a.find(arguments[i]) == -1) {
80 if (k) e.className = a.join(' ');
83 removeClass: function(e, name) {
84 if ((e = E(e)) == null) return;
85 var a = e.className.split(/\s+/);
87 for (var i = 1; i < arguments.length; ++i)
88 k |= a.remove(arguments[i]);
89 if (k) e.className = a.join(' ');
93 if ((e = E(e)) != null) e.parentNode.removeChild(e);
96 parentElem: function(e, tagName) {
98 tagName = tagName.toUpperCase();
99 while (e.parentNode) {
101 if (e.tagName == tagName) return e;
106 display: function() {
107 var enable = arguments[arguments.length - 1];
108 for (var i = 0; i < arguments.length - 1; ++i) {
109 E(arguments[i]).style.display = enable ? '' : 'none';
113 isVisible: function(e) {
116 if ((e.style.visibility != 'visible') || (e.style.display == 'none')) return false;
122 setInnerHTML: function(e, html) {
124 if (e.innerHTML != html) e.innerHTML = html; // reduce flickering
128 // -----------------------------------------------------------------------------
131 getViewSize: function() {
132 if (window.innerHeight) {
133 return { width: window.innerWidth, height: window.innerHeight };
135 else if (document.documentElement && document.documentElement.clientHeight) {
136 return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
138 return { width: document.body.clientWidth, height: document.body.clientHeight };
141 getPageOffset: function()
143 if (typeof(window.pageYOffset) != 'undefined') {
144 return { x: window.pageXOffset, y: window.pageYOffset };
146 else if ((document.documentElement) && (typeof(document.documentElement.scrollTop) != 'undefined')) {
147 return { x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop };
149 return { x: document.body.scrollLeft, y: document.body.scrollTop };
153 // -----------------------------------------------------------------------------
156 getAll: function(e) {
165 for (var i = 0; i < e.childNodes.length; ++i) {
166 a = a.concat(fields.getAll(e.childNodes[i]));
172 disableAll: function(e, d) {
175 if ((typeof(e.tagName) == 'undefined') && (typeof(e) != 'string')) {
176 for (i = e.length - 1; i >= 0; --i) {
181 var a = this.getAll(E(e));
182 for (var i = a.length - 1; i >= 0; --i) {
188 selected: function(e) {
189 for (var i = 0; i < e.length; ++i) {
190 if (e[i].checked) return e[i];
194 find: function(e, value) {
195 for (var i = 0; i < e.length; ++i) {
196 if (e[i].value == value) return e[i];
203 // -----------------------------------------------------------------------------
206 submitHidden: function(url, fields) {
209 fom = document.createElement('FORM');
212 for (var f in fields) {
213 var e = document.createElement('INPUT');
219 body = document.getElementsByTagName('body')[0];
220 fom = body.appendChild(fom);
222 body.removeChild(fom);
225 submit: function(fom, async, url) {
226 var e, v, f, i, wait, msg, sb, cb;
231 this.dump(fom, async, url);
235 if (this.xhttp) return;
237 if ((sb = E('save-button')) != null) sb.disabled = 1;
238 if ((cb = E('cancel-button')) != null) cb.disabled = 1;
240 if ((!async) || (!useAjax())) {
242 if (url) fom.action = url;
249 for (var i = 0; i < fom.elements.length; ++i) {
251 if ((f.disabled) || (f.name == '') || (f.name.substr(0, 2) == 'f_')) continue;
252 if ((f.tagName == 'INPUT') && ((f.type == 'CHECKBOX') || (f.type == 'RADIO')) && (!f.checked)) continue;
253 if (f.name == '_nextwait') {
255 if (isNaN(wait)) wait = 5;
256 else wait = Math.abs(wait);
258 v.push(escapeCGI(f.name) + '=' + escapeCGI(f.value));
261 if ((msg = E('footer-msg')) != null) {
262 msg.innerHTML = 'Saving...';
263 msg.style.visibility = 'visible';
266 this.xhttp = new XmlHttp();
267 this.xhttp.onCompleted = function(text, xml) {
269 if (text.match(/@msg:(.+)/)) msg.innerHTML = escapeHTML(RegExp.$1);
270 else msg.innerHTML = 'Saved';
274 if (sb) sb.disabled = 0;
275 if (cb) cb.disabled = 0;
276 if (msg) msg.style.visibility = 'hidden';
277 if (typeof(submit_complete) != 'undefined') submit_complete();
281 this.xhttp.onError = function(x) {
282 if (url) fom.action = url;
286 this.xhttp.post(url ? url : fom.action, v.join('&'));
289 addId: function(fom) {
292 if (typeof(fom._http_id) == 'undefined') {
293 e = document.createElement('INPUT');
296 e.value = nvram.http_id;
300 fom._http_id.value = nvram.http_id;
304 addIdAction: function(fom) {
305 if (fom.action.indexOf('?') != -1) fom.action += '&_http_id=' + nvram.http_id;
306 else fom.action += '?_http_id=' + nvram.http_id;
309 dump: function(fom, async, url) {
313 // -----------------------------------------------------------------------------
316 set: function(e, message, quiet) {
317 if ((e = E(e)) == null) return;
318 e._error_msg = message;
319 e._error_org = e.title;
321 elem.addClass(e, 'error');
322 if (!quiet) this.show(e);
326 if ((e = E(e)) == null) return;
327 e.title = e._error_org || '';
328 elem.removeClass(e, 'error');
333 clearAll: function(e) {
334 for (var i = 0; i < e.length; ++i)
339 if ((e = E(e)) == null) return;
340 if (!e._error_msg) return;
341 elem.addClass(e, 'error-focused');
344 elem.removeClass(e, 'error-focused');
348 if ((e = E(e)) == null) return 0;
349 return !e._error_msg;
353 // -----------------------------------------------------------------------------
355 function fixFile(name)
358 if (((i = name.lastIndexOf('/')) > 0) || ((i = name.lastIndexOf('\\')) > 0))
359 name = name.substring(i + 1, name.length);
363 function _v_range(e, quiet, min, max, name)
365 if ((e = E(e)) == null) return 0;
367 if ((!v.match(/^ *[-\+]?\d+ *$/)) || (v < min) || (v > max)) {
368 ferror.set(e, 'Invalid ' + name + '. Valid range: ' + min + '-' + max, quiet);
376 function v_range(e, quiet, min, max)
378 return _v_range(e, quiet, min, max, 'number');
381 function v_port(e, quiet)
383 return _v_range(e, quiet, 1, 0xFFFF, 'port');
386 function v_octet(e, quiet)
388 return _v_range(e, quiet, 1, 254, 'address');
391 function v_mins(e, quiet, min, max)
395 if ((e = E(e)) == null) return 0;
396 if (e.value.match(/^\s*(.+?)([mhd])?\s*$/)) {
398 if (RegExp.$2 == 'h') m = 60;
399 else if (RegExp.$2 == 'd') m = 60 * 24;
400 v = Math.round(RegExp.$1 * m);
403 return _v_range(e, quiet, min, max, 'minutes');
406 ferror.set(e, 'Invalid number of minutes.', quiet);
410 function v_macip(e, quiet, bok, lan_ipaddr, lan_netmask)
412 var s, a, b, c, d, i;
413 var ipp, first_match, temp;
415 ipp = ntoa(aton(lan_ipaddr) & aton(lan_netmask));
416 temp = ipp.split('.');
427 for (i=0;i<=first_match;i++)
428 ipp = ipp + temp[i] + '.';
430 if ((e = E(e)) == null) return 0;
431 s = e.value.replace(/\s+/g, '');
433 if ((a = fixMAC(s)) != null) {
439 ferror.set(e, 'Invalid MAC or IP address');
450 ferror.set(e, 'Invalid IP address range', quiet);
454 for (i = 0; i < a.length; ++i) {
456 if (b.match(/^\d+$/)) b = ipp + b;
460 ferror.set(e, 'Invalid IP address', quiet);
464 if ((aton(b) & aton(lan_netmask))!=(aton(lan_ipaddr) & aton(lan_netmask))) {
465 ferror.set(e, 'IP address outside of LAN', quiet);
469 d = (b.split('.'))[3];
471 ferror.set(e, 'Invalid IP address range', quiet);
477 e.value = b.split('.')[0] + '.' + b.split('.')[1] + '.' + b.split('.')[2] + '.' + a.join('-');
481 function fixIP(ip, x)
486 if (a.length != 4) return null;
487 for (i = 0; i < 4; ++i) {
489 if ((isNaN(n)) || (n < 0) || (n > 255)) return null;
492 if ((x) && ((a[3] == 0) || (a[3] == 255))) return null;
496 function v_ip(e, quiet, x)
500 if ((e = E(e)) == null) return 0;
501 ip = fixIP(e.value, x);
503 ferror.set(e, 'Invalid IP address', quiet);
511 function v_ipz(e, quiet)
513 if ((e = E(e)) == null) return 0;
514 if (e.value == '') e.value = '0.0.0.0';
515 return v_ip(e, quiet);
518 function v_dns(e, quiet)
520 if ((e = E(e)) == null) return 0;
525 var s = e.value.split(':');
529 else if (s.length != 2) {
530 ferror.set(e, 'Invalid IP address or port', quiet);
534 if ((s[0] = fixIP(s[0])) == null) {
535 ferror.set(e, 'Invalid IP address', quiet);
539 if ((s[1] = fixPort(s[1], -1)) == -1) {
540 ferror.set(e, 'Invalid port', quiet);
548 e.value = s.join(':');
560 // ---- this is goofy because << mangles numbers as signed
563 for (i = 0; i < 4; ++i) x += (o[i] * 1).hex(2);
564 return parseInt(x, 16);
569 return ((ip >> 24) & 255) + '.' + ((ip >> 16) & 255) + '.' + ((ip >> 8) & 255) + '.' + (ip & 255);
573 // ---- 1.2.3.4, 1.2.3.4/24, 1.2.3.4/255.255.255.0, 1.2.3.4-1.2.3.5
574 function _v_iptip(e, ip, quiet)
576 var ma, x, y, z, oip;
582 if (ip.match(/^(.*)-(.*)$/)) {
583 a = fixIP(RegExp.$1);
584 b = fixIP(RegExp.$2);
585 if ((a == null) || (b == null)) {
586 ferror.set(e, oip + ' - invalid IP address range', quiet);
591 if (aton(a) > aton(b)) return b + '-' + a;
599 if (ip.match(/^(.*)\/(.*)$/)) {
606 if ((ma == null) || (!_v_netmask(ma))) {
607 ferror.set(e, oip + ' - invalid netmask', quiet);
612 if ((ma < 0) || (ma > 32)) {
613 ferror.set(e, oip + ' - invalid netmask', quiet);
621 ferror.set(e, oip + ' - invalid IP address', quiet);
626 return ip + ((ma != '') ? ('/' + ma) : '');
629 function v_iptip(e, quiet, multi)
633 if ((e = E(e)) == null) return 0;
634 v = e.value.split(',');
636 if (v.length > multi) {
637 ferror.set(e, 'Too many IP addresses', quiet);
643 ferror.set(e, 'Invalid IP address', quiet);
647 for (i = 0; i < v.length; ++i) {
648 if ((v[i] = _v_iptip(e, v[i], quiet)) == null) return 0;
650 e.value = v.join(', ');
654 function _v_domain(e, dom, quiet)
658 s = dom.replace(/\s+/g, ' ').trim();
660 s = _v_hostname(e, s, 1, 1, 7, '.', true);
662 ferror.set(e, "Invalid name. Only characters \"A-Z 0-9 . -\" are allowed.", quiet);
670 function v_domain(e, quiet)
674 if ((e = E(e)) == null) return 0;
675 if ((v = _v_domain(e, e.value, quiet)) == null) return 0;
682 function ExpandIPv6Address(ip)
684 var a, pre, n, i, fill, post;
686 ip = ip.toLowerCase();
687 if (!ip.match(/^(::)?([a-f0-9]{1,4}::?){0,7}([a-f0-9]{1,4})(::)?$/)) return null;
692 if (a[0] == '') return null;
693 pre = a[0].split(':');
694 if (pre.length != 8) return null;
698 pre = a[0].split(':');
699 post = a[1].split(':');
700 n = 8 - pre.length - post.length;
701 for (i=0; i<2; i++) {
704 if (n < 0) return null;
706 while (n-- > 0) fill += ':0';
707 ip = pre.join(':') + fill + ':' + post.join(':');
708 ip = ip.replace(/^:/, '').replace(/:$/, '');
714 ip = ip.replace(/([a-f0-9]{1,4})/ig, '000$1');
715 ip = ip.replace(/0{0,3}([a-f0-9]{4})/ig, '$1');
719 function CompressIPv6Address(ip)
723 ip = ExpandIPv6Address(ip);
724 if (!ip) return null;
726 // if (ip.match(/(?:^00)|(?:^fe[8-9a-b])|(?:^ff)/)) return null; // not valid routable unicast address
728 ip = ip.replace(/(^|:)0{1,3}/g, '$1');
729 ip = ip.replace(/(:0)+$/, '::');
730 ip = ip.replace(/(?:(?:^|:)0){2,}(?!.*(?:::|(?::0){3,}))/, ':');
734 function ZeroIPv6PrefixBits(ip, prefix_length)
737 ip = ExpandIPv6Address(ip);
738 ip = ip.replace(/:/g,'');
739 n = Math.floor(prefix_length/4);
740 m = 32 - Math.ceil(prefix_length/4);
741 b = prefix_length % 4;
743 c = (parseInt(ip.charAt(n), 16) & (0xf << 4-b)).toString(16);
747 ip = ip.substring(0, n) + c + Array((m%4)+1).join('0') + (m>=4 ? '::' : '');
748 ip = ip.replace(/([a-f0-9]{4})(?=[a-f0-9])/g,'$1:');
749 ip = ip.replace(/(^|:)0{1,3}/g, '$1');
757 ip = ExpandIPv6Address(ip);
762 for (i = 0; i < 8; ++i) x += (('0x' + o[i]) * 1).hex(4);
763 return parseInt(x, 16);
766 function _v_ipv6_addr(e, ip, ipt, quiet)
774 if ((ipt) && ip.match(/^(.*)-(.*)$/)) {
777 a = CompressIPv6Address(a);
778 b = CompressIPv6Address(b);
779 if ((a == null) || (b == null)) {
780 ferror.set(e, oip + ' - invalid IPv6 address range', quiet);
785 if (ipv6ton(a) > ipv6ton(b)) return b + '-' + a;
789 if ((ipt) && ip.match(/^([A-Fa-f0-9:]+)\/(\d+)$/)) {
791 b = parseInt(RegExp.$2, 10);
792 a = ExpandIPv6Address(a);
793 if ((a == null) || (b == null)) {
794 ferror.set(e, oip + ' - invalid IPv6 address', quiet);
797 if (b < 0 || b > 128) {
798 ferror.set(e, oip + ' - invalid CIDR notation on IPv6 address', quiet);
803 ip = ZeroIPv6PrefixBits(a, b);
804 return ip + '/' + b.toString(10);
807 ip = CompressIPv6Address(oip);
809 ferror.set(e, oip + ' - invalid IPv6 address', quiet);
817 function v_ipv6_addr(e, quiet)
819 if ((e = E(e)) == null) return 0;
821 ip = _v_ipv6_addr(e, e.value, false, quiet);
822 if (ip) e.value = ip;
827 function fixPort(p, def)
829 if (def == null) def = -1;
830 if (p == null) return def;
832 if ((isNaN(p) || (p < 1) || (p > 65535) || (('' + p).indexOf('.') != -1))) return def;
836 function _v_portrange(e, quiet, v)
838 if (v.match(/^(.*)[-:](.*)$/)) {
844 if ((x == -1) || (y == -1)) {
845 ferror.set(e, 'Invalid port range: ' + v, quiet);
854 if (x == y) return x;
860 ferror.set(e, 'Invalid port', quiet);
868 function v_portrange(e, quiet)
872 if ((e = E(e)) == null) return 0;
873 v = _v_portrange(e, quiet, e.value);
874 if (v == null) return 0;
879 function v_iptport(e, quiet)
883 if ((e = E(e)) == null) return 0;
885 a = e.value.split(/[,\.]/);
888 ferror.set(e, 'Expecting a list of ports or port range.', quiet);
892 ferror.set(e, 'Only 10 ports/range sets are allowed.', quiet);
897 for (i = 0; i < a.length; ++i) {
898 v = _v_portrange(e, quiet, a[i]);
899 if (v == null) return 0;
903 e.value = q.join(',');
908 function _v_netmask(mask)
910 var v = aton(mask) ^ 0xFFFFFFFF;
911 return (((v + 1) & v) == 0);
914 function v_netmask(e, quiet)
918 if ((e = E(e)) == null) return 0;
927 else if (e.value.match(/^\s*\/\s*(\d+)\s*$/)) {
929 if ((b >= 1) && (b <= 32)) {
930 if (b == 32) n = 0xFFFFFFFF; // js quirk
931 else n = (0xFFFFFFFF >>> b) ^ 0xFFFFFFFF;
932 e.value = (n >>> 24) + '.' + ((n >>> 16) & 0xFF) + '.' + ((n >>> 8) & 0xFF) + '.' + (n & 0xFF);
937 ferror.set(e, 'Invalid netmask', quiet);
945 mac = mac.replace(/\s+/g, '').toUpperCase();
946 if (mac.length == 0) {
949 else if (mac.length == 12) {
950 mac = mac.match(/../g);
953 mac = mac.split(/[:\-]/);
954 if (mac.length != 6) return null;
956 for (i = 0; i < 6; ++i) {
958 if (t.search(/^[0-9A-F]+$/) == -1) return null;
959 if ((t = parseInt(t, 16)) > 255) return null;
962 return mac.join(':');
965 function v_mac(e, quiet)
969 if ((e = E(e)) == null) return 0;
970 mac = fixMAC(e.value);
971 if ((!mac) || (isMAC0(mac))) {
972 ferror.set(e, 'Invalid MAC address', quiet);
980 function v_macz(e, quiet)
984 if ((e = E(e)) == null) return 0;
985 mac = fixMAC(e.value);
987 ferror.set(e, 'Invalid MAC address', quiet);
995 function v_length(e, quiet, min, max)
999 if ((e = E(e)) == null) return 0;
1002 if (min == undefined) min = 1;
1004 ferror.set(e, 'Invalid length. Please enter at least ' + min + ' character' + (min == 1 ? '.' : 's.'), quiet);
1007 max = max || e.maxlength;
1009 ferror.set(e, 'Invalid length. Please reduce the length to ' + max + ' characters or less.', quiet);
1017 function _v_iptaddr(e, quiet, multi, ipv4, ipv6)
1021 if ((e = E(e)) == null) return 0;
1022 v = e.value.split(',');
1024 if (v.length > multi) {
1025 ferror.set(e, 'Too many addresses', quiet);
1031 ferror.set(e, 'Invalid domain name or IP address', quiet);
1036 for (i = 0; i < v.length; ++i) {
1037 if ((t = _v_domain(e, v[i], 1)) == null) {
1039 if ((!ipv6) && (!ipv4)) {
1040 if (!quiet) ferror.show(e);
1043 if ((!ipv6) || ((t = _v_ipv6_addr(e, v[i], 1, 1)) == null)) {
1046 if (!quiet) ferror.show(e);
1049 if ((t = _v_iptip(e, v[i], 1)) == null) {
1050 ferror.set(e, e._error_msg + ', or invalid domain name', quiet);
1060 e.value = v.join(', ');
1065 function v_iptaddr(e, quiet, multi)
1067 return _v_iptaddr(e, quiet, multi, 1, 0);
1070 function _v_hostname(e, h, quiet, required, multi, delim, cidr)
1076 v = (typeof(delim) == 'undefined') ? h.split(/\s+/) : h.split(delim);
1079 if (v.length > multi) {
1080 ferror.set(e, 'Too many hostnames.', quiet);
1086 ferror.set(e, 'Invalid hostname.', quiet);
1091 re = /^[a-zA-Z0-9](([a-zA-Z0-9\-]{0,61})[a-zA-Z0-9]){0,1}$/;
1093 for (i = 0; i < v.length; ++i) {
1094 s = v[i].replace(/_+/g, '-').replace(/\s+/g, '-');
1096 if (cidr && i == v.length-1)
1097 re = /^[a-zA-Z0-9](([a-zA-Z0-9\-]{0,61})[a-zA-Z0-9]){0,1}(\/\d{1,3})?$/;
1098 if (s.search(re) == -1 || s.search(/^\d+$/) != -1) {
1099 ferror.set(e, 'Invalid hostname. Only "A-Z 0-9" and "-" in the middle are allowed (up to 63 characters).', quiet);
1102 } else if (required) {
1103 ferror.set(e, 'Invalid hostname.', quiet);
1110 return v.join((typeof(delim) == 'undefined') ? ' ' : delim);
1113 function v_hostname(e, quiet, multi, delim)
1117 if ((e = E(e)) == null) return 0;
1119 v = _v_hostname(e, e.value, quiet, 0, multi, delim, false);
1121 if (v == null) return 0;
1127 function v_nodelim(e, quiet, name, checklist)
1129 if ((e = E(e)) == null) return 0;
1131 e.value = e.value.trim();
1132 if (e.value.indexOf('<') != -1 ||
1133 (checklist && e.value.indexOf('>') != -1)) {
1134 ferror.set(e, 'Invalid ' + name + ': \"<\" ' + (checklist ? 'or \">\" are' : 'is') + ' not allowed.', quiet);
1141 function v_path(e, quiet, required)
1143 if ((e = E(e)) == null) return 0;
1144 if (required && !v_length(e, quiet, 1)) return 0;
1146 if (!required && e.value.trim().length == 0) {
1150 if (e.value.substr(0, 1) != '/') {
1151 ferror.set(e, 'Please start at the / root directory.', quiet);
1158 function isMAC0(mac)
1160 return (mac == '00:00:00:00:00:00');
1163 // -----------------------------------------------------------------------------
1165 function cmpIP(a, b)
1167 if ((a = fixIP(a)) == null) a = '255.255.255.255';
1168 if ((b = fixIP(b)) == null) b = '255.255.255.255';
1169 return aton(a) - aton(b);
1172 function cmpText(a, b)
1174 if (a == '') a = '\xff';
1175 if (b == '') b = '\xff';
1176 return (a < b) ? -1 : ((a > b) ? 1 : 0);
1179 function cmpInt(a, b)
1181 a = parseInt(a, 10);
1182 b = parseInt(b, 10);
1183 return ((isNaN(a)) ? -0x7FFFFFFF : a) - ((isNaN(b)) ? -0x7FFFFFFF : b);
1186 function cmpFloat(a, b)
1190 return ((isNaN(a)) ? -Number.MAX_VALUE : a) - ((isNaN(b)) ? -Number.MAX_VALUE : b);
1193 function cmpDate(a, b)
1195 return b.getTime() - a.getTime();
1198 // -----------------------------------------------------------------------------
1200 // ---- todo: cleanup this mess
1204 return elem.parentElem(e, 'TABLE').gridObj;
1207 function tgHideIcons()
1210 while ((e = document.getElementById('tg-row-panel')) != null) e.parentNode.removeChild(e);
1213 // ---- options = sort, move, delete
1214 function TomatoGrid(tb, options, maxAdd, editorFields)
1216 this.init(tb, options, maxAdd, editorFields);
1220 TomatoGrid.prototype = {
1221 init: function(tb, options, maxAdd, editorFields) {
1224 this.tb.gridObj = this;
1229 if (!options) options = '';
1233 this.canSort = options.indexOf('sort') != -1;
1234 this.canMove = options.indexOf('move') != -1;
1235 this.maxAdd = maxAdd || 140;
1236 this.canEdit = (editorFields != null);
1237 this.canDelete = this.canEdit || (options.indexOf('delete') != -1);
1238 this.editorFields = editorFields;
1239 this.sortColumn = -1;
1240 this.sortAscending = true;
1243 _insert: function(at, cells, escCells) {
1247 tr = this.tb.insertRow(at);
1248 for (i = 0; i < cells.length; ++i) {
1250 if (typeof(c) == 'string') {
1251 td = tr.insertCell(i);
1252 td.className = 'co' + (i + 1);
1253 if (escCells) td.appendChild(document.createTextNode(c));
1254 else td.innerHTML = c;
1265 headerClick: function(cell) {
1267 this.sort(cell.cellN);
1271 headerSet: function(cells, escCells) {
1274 elem.remove(this.header);
1275 this.header = e = this._insert(0, cells, escCells);
1276 e.className = 'header';
1278 for (i = 0; i < e.cells.length; ++i) {
1279 e.cells[i].cellN = i; // cellIndex broken in Safari
1280 e.cells[i].onclick = function() { return TGO(this).headerClick(this); };
1287 footerClick: function(cell) {
1290 footerSet: function(cells, escCells) {
1293 elem.remove(this.footer);
1294 this.footer = e = this._insert(-1, cells, escCells);
1295 e.className = 'footer';
1296 for (i = 0; i < e.cells.length; ++i) {
1297 e.cells[i].cellN = i;
1298 e.cells[i].onclick = function() { TGO(this).footerClick(this) };
1309 TGO(e).moving = null;
1310 i = e.previousSibling;
1311 if (i == this.header) return;
1312 e.parentNode.removeChild(e);
1313 i.parentNode.insertBefore(e, i);
1323 TGO(e).moving = null;
1325 if (i == this.footer) return;
1326 e.parentNode.removeChild(e);
1327 i.parentNode.insertBefore(e, i.nextSibling);
1333 rpMo: function(img, e) {
1338 if (me.moving == e) {
1344 img.style.border = "1px dotted red";
1347 rpDel: function(e) {
1349 TGO(e).moving = null;
1350 e.parentNode.removeChild(e);
1355 rpMouIn: function(evt) {
1356 var e, x, ofs, me, s, n;
1358 if ((evt = checkEvent(evt)) == null) return;
1360 me = TGO(evt.target);
1361 if (me.isEditing()) return;
1362 if (me.moving) return;
1365 e = document.createElement('div');
1368 e.setAttribute('id', 'tg-row-panel');
1373 s = '<img src="rpu.gif" onclick="this.parentNode.tgo.rpUp(this.parentNode.ref)" title="Move Up"><img src="rpd.gif" onclick="this.parentNode.tgo.rpDn(this.parentNode.ref)" title="Move Down"><img src="rpm.gif" onclick="this.parentNode.tgo.rpMo(this,this.parentNode.ref)" title="Move">';
1377 s += '<img src="rpx.gif" onclick="this.parentNode.tgo.rpDel(this.parentNode.ref)" title="Delete">';
1381 x = x.cells[x.cells.length - 1];
1382 ofs = elem.getOffset(x);
1384 e.style.left = (ofs.x + x.offsetWidth - n) + 'px';
1385 e.style.top = ofs.y + 'px';
1386 e.style.width = n + 'px';
1389 document.body.appendChild(e);
1392 rpHide: tgHideIcons,
1396 onClick: function(cell) {
1399 var p = this.moving.parentNode;
1401 if (this.moving != q) {
1402 var v = this.moving.rowIndex > q.rowIndex;
1403 p.removeChild(this.moving);
1404 if (v) p.insertBefore(this.moving, q);
1405 else p.insertBefore(this.moving, q.nextSibling);
1416 insert: function(at, data, cells, escCells) {
1419 if ((this.footer) && (at == -1)) at = this.footer.rowIndex;
1420 e = this._insert(at, cells, escCells);
1421 e.className = (e.rowIndex & 1) ? 'even' : 'odd';
1423 for (i = 0; i < e.cells.length; ++i) {
1424 e.cells[i].onclick = function() { return TGO(this).onClick(this); };
1428 e.getRowData = function() { return this._data; }
1429 e.setRowData = function(data) { this._data = data; }
1431 if ((this.canMove) || (this.canEdit) || (this.canDelete)) {
1432 e.onmouseover = this.rpMouIn;
1433 // ---- e.onmouseout = this.rpMouOut;
1434 if (this.canEdit) e.title = 'Click to edit';
1442 insertData: function(at, data) {
1443 return this.insert(at, data, this.dataToView(data), false);
1446 dataToView: function(data) {
1448 for (var i = 0; i < data.length; ++i) {
1449 var s = escapeHTML('' + data[i]);
1450 if (this.editorFields && this.editorFields.length > i) {
1451 var ef = this.editorFields[i].multi;
1452 if (!ef) ef = [this.editorFields[i]];
1453 var f = (ef && ef.length > 0 ? ef[0] : null);
1454 if (f && f.type == 'password') {
1455 if (!f.peekaboo || get_config('web_pb', '1') != '0')
1456 s = s.replace(/./g, '●');
1464 dataToFieldValues: function(data) {
1468 fieldValuesToData: function(row) {
1472 e = fields.getAll(row);
1473 for (i = 0; i < e.length; ++i) data.push(e[i].value);
1479 edit: function(cell) {
1482 if (this.isEditing()) return;
1485 sr.style.display = 'none';
1486 elem.removeClass(sr, 'hover');
1489 er = this.createEditor('edit', sr.rowIndex, sr);
1490 er.className = 'editor';
1493 c = er.cells[cell.cellIndex || 0];
1494 e = c.getElementsByTagName('input');
1495 if ((e) && (e.length > 0)) {
1503 this.controls = this.createControls('edit', sr.rowIndex);
1505 this.disableNewEditor(true);
1507 this.verifyFields(this.editor, true);
1510 createEditor: function(which, rowIndex, source) {
1513 if (which == 'edit') values = this.dataToFieldValues(source.getRowData());
1515 var row = this.tb.insertRow(rowIndex);
1516 row.className = 'editor';
1518 var common = ' onkeypress="return TGO(this).onKey(\'' + which + '\', event)" onchange="TGO(this).onChange(\'' + which + '\', this)"';
1521 for (var i = 0; i < this.editorFields.length; ++i) {
1523 var ef = this.editorFields[i].multi;
1524 if (!ef) ef = [this.editorFields[i]];
1526 for (var j = 0; j < ef.length; ++j) {
1529 if (f.prefix) s += f.prefix;
1530 var attrib = ' class="fi' + (vi + 1) + '" ' + (f.attrib || '');
1531 var id = (this.tb ? ('_' + this.tb + '_' + (vi + 1)) : null);
1532 if (id) attrib += ' id="' + id + '"';
1536 switch (get_config('web_pb', '1')) {
1544 attrib += ' autocomplete="off"';
1545 if (f.peekaboo && id) attrib += ' onfocus=\'peekaboo("' + id + '",1)\'';
1548 s += '<input type="' + f.type + '" maxlength=' + f.maxlen + common + attrib;
1549 if (which == 'edit') s += ' value="' + escapeHTML('' + values[vi]) + '">';
1553 s += '<select' + common + attrib + '>';
1554 for (var k = 0; k < f.options.length; ++k) {
1556 if (which == 'edit') {
1557 s += '<option value="' + a[0] + '"' + ((a[0] == values[vi]) ? ' selected>' : '>') + a[1] + '</option>';
1560 s += '<option value="' + a[0] + '">' + a[1] + '</option>';
1566 s += '<input type="checkbox"' + common + attrib;
1567 if ((which == 'edit') && (values[vi])) s += ' checked';
1571 s += f.custom.replace(/\$which\$/g, which);
1573 if (f.suffix) s += f.suffix;
1577 var c = row.insertCell(i);
1579 if (this.editorFields[i].vtop) c.vAlign = 'top';
1585 createControls: function(which, rowIndex) {
1588 r = this.tb.insertRow(rowIndex);
1589 r.className = 'controls';
1591 c = r.insertCell(0);
1592 c.colSpan = this.header.cells.length;
1593 if (which == 'edit') {
1595 '<input type=button value="Delete" onclick="TGO(this).onDelete()"> ' +
1596 '<input type=button value="OK" onclick="TGO(this).onOK()"> ' +
1597 '<input type=button value="Cancel" onclick="TGO(this).onCancel()">';
1601 '<input type=button value="Add" onclick="TGO(this).onAdd()">';
1606 removeEditor: function() {
1609 elem.remove(this.editor);
1612 if (this.controls) {
1613 elem.remove(this.controls);
1614 this.controls = null;
1618 showSource: function() {
1620 this.source.style.display = '';
1625 onChange: function(which, cell) {
1626 return this.verifyFields((which == 'new') ? this.newEditor : this.editor, true);
1629 onKey: function(which, ev) {
1630 switch (ev.keyCode) {
1632 if (which == 'edit') this.onCancel();
1635 if (((ev.srcElement) && (ev.srcElement.tagName == 'SELECT')) ||
1636 ((ev.target) && (ev.target.tagName == 'SELECT'))) return true;
1637 if (which == 'edit') this.onOK();
1644 onDelete: function() {
1645 this.removeEditor();
1646 elem.remove(this.source);
1648 this.disableNewEditor(false);
1651 onCancel: function() {
1652 this.removeEditor();
1654 this.disableNewEditor(false);
1660 if (!this.verifyFields(this.editor, false)) return;
1662 data = this.fieldValuesToData(this.editor);
1663 view = this.dataToView(data);
1665 this.source.setRowData(data);
1666 for (i = 0; i < this.source.cells.length; ++i) {
1667 this.source.cells[i].innerHTML = view[i];
1670 this.removeEditor();
1672 this.disableNewEditor(false);
1681 if (!this.verifyFields(this.newEditor, false)) return;
1683 data = this.fieldValuesToData(this.newEditor);
1684 this.insertData(-1, data);
1686 this.disableNewEditor(false);
1687 this.resetNewEditor();
1690 verifyFields: function(row, quiet) {
1694 showNewEditor: function() {
1697 r = this.createEditor('new', -1, null);
1698 this.footer = this.newEditor = r;
1700 r = this.createControls('new', -1);
1701 this.newControls = r;
1703 this.disableNewEditor(false);
1706 disableNewEditor: function(disable) {
1707 if (this.getDataCount() >= this.maxAdd) disable = true;
1708 if (this.newEditor) fields.disableAll(this.newEditor, disable);
1709 if (this.newControls) fields.disableAll(this.newControls, disable);
1712 resetNewEditor: function() {
1715 e = fields.getAll(this.newEditor);
1717 for (i = 0; i < e.length; ++i) {
1719 if (f.selectedIndex) f.selectedIndex = 0;
1722 try { if (e.length) e[0].focus(); } catch (er) { }
1725 getDataCount: function() {
1727 n = this.tb.rows.length;
1728 if (this.footer) n = this.footer.rowIndex;
1729 if (this.header) n -= this.header.rowIndex + 1;
1733 sortCompare: function(a, b) {
1735 var col = obj.sortColumn;
1736 var r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
1737 return obj.sortAscending ? r : -r;
1740 sort: function(column) {
1741 if (this.editor) return;
1743 if (this.sortColumn >= 0) {
1744 elem.removeClass(this.header.cells[this.sortColumn], 'sortasc', 'sortdes');
1746 if (column == this.sortColumn) {
1747 this.sortAscending = !this.sortAscending;
1750 this.sortAscending = true;
1751 this.sortColumn = column;
1753 elem.addClass(this.header.cells[column], this.sortAscending ? 'sortasc' : 'sortdes');
1758 resort: function() {
1759 if ((this.sortColumn < 0) || (this.getDataCount() == 0) || (this.editor)) return;
1761 var p = this.header.parentNode;
1763 var i, j, max, e, p;
1768 top = this.header ? this.header.rowIndex + 1 : 0;
1769 max = this.footer ? this.footer.rowIndex : this.tb.rows.length;
1770 for (i = top; i < max; ++i) a.push(p.rows[i]);
1771 a.sort(THIS(this, this.sortCompare));
1772 this.removeAllData();
1774 for (i = 0; i < a.length; ++i) {
1775 e = p.insertBefore(a[i], this.footer);
1776 e.className = (j & 1) ? 'even' : 'odd';
1781 recolor: function() {
1784 i = this.header ? this.header.rowIndex + 1 : 0;
1785 e = this.footer ? this.footer.rowIndex : this.tb.rows.length;
1786 for (; i < e; ++i) {
1787 o = this.tb.rows[i];
1788 o.className = (o.rowIndex & 1) ? 'even' : 'odd';
1792 removeAllData: function() {
1795 i = this.header ? this.header.rowIndex + 1 : 0;
1796 count = (this.footer ? this.footer.rowIndex : this.tb.rows.length) - i;
1797 while (count-- > 0) elem.remove(this.tb.rows[i]);
1800 getAllData: function() {
1801 var i, max, data, r;
1804 max = this.footer ? this.footer.rowIndex : this.tb.rows.length;
1805 for (i = this.header ? this.header.rowIndex + 1 : 0; i < max; ++i) {
1806 r = this.tb.rows[i];
1807 if ((r.style.display != 'none') && (r._data)) data.push(r._data);
1812 isEditing: function() {
1813 return (this.editor != null);
1818 // -----------------------------------------------------------------------------
1821 function xmlHttpObj()
1825 ob = new XMLHttpRequest();
1830 ob = new ActiveXObject('Microsoft.XMLHTTP');
1838 var _holdAjax = null;
1842 if (_useAjax == -1) _useAjax = ((_holdAjax = xmlHttpObj()) != null);
1848 if ((!useAjax()) || ((this.xob = xmlHttpObj()) == null)) return null;
1852 XmlHttp.prototype = {
1853 addId: function(vars) {
1854 if (vars) vars += '&';
1856 vars += '_http_id=' + escapeCGI(nvram.http_id);
1860 get: function(url, vars) {
1862 vars = this.addId(vars);
1865 this.xob.onreadystatechange = THIS(this, this.onReadyStateChange);
1866 this.xob.open('GET', url, true);
1867 this.xob.send(null);
1874 post: function(url, vars) {
1876 vars = this.addId(vars);
1878 this.xob.onreadystatechange = THIS(this, this.onReadyStateChange);
1879 this.xob.open('POST', url, true);
1880 this.xob.send(vars);
1889 this.xob.onreadystatechange = function () { }
1896 onReadyStateChange: function() {
1898 if (typeof(E) == 'undefined') return; // oddly late? testing for bug...
1900 if (this.xob.readyState == 4) {
1901 if (this.xob.status == 200) {
1902 this.onCompleted(this.xob.responseText, this.xob.responseXML);
1905 this.onError('' + (this.xob.status || 'unknown'));
1914 onCompleted: function(text, xml) { },
1915 onError: function(ex) { }
1919 // -----------------------------------------------------------------------------
1922 function TomatoTimer(func, ms)
1925 this.onTimer = func;
1926 if (ms) this.start(ms);
1930 TomatoTimer.prototype = {
1931 start: function(ms) {
1933 this.tid = setTimeout(THIS(this, this._onTimer), ms);
1937 clearTimeout(this.tid);
1942 isRunning: function() {
1943 return (this.tid != null);
1946 _onTimer: function() {
1951 onTimer: function() {
1956 // -----------------------------------------------------------------------------
1959 function TomatoRefresh(actionURL, postData, refreshTime, cookieTag)
1961 this.setup(actionURL, postData, refreshTime, cookieTag);
1962 this.timer = new TomatoTimer(THIS(this, this.start));
1965 TomatoRefresh.prototype = {
1968 setup: function(actionURL, postData, refreshTime, cookieTag) {
1971 this.actionURL = actionURL;
1972 this.postData = postData;
1973 this.refreshTime = refreshTime * 1000;
1974 this.cookieTag = cookieTag;
1980 if ((e = E('refresh-time')) != null) {
1981 if (this.cookieTag) cookie.set(this.cookieTag, e.value);
1982 this.refreshTime = e.value * 1000;
1986 this.updateUI('start');
1989 if ((this.http = new XmlHttp()) == null) {
1994 this.http.parent = this;
1996 this.http.onCompleted = function(text, xml) {
1997 var p = this.parent;
1999 if (p.cookieTag) cookie.unset(p.cookieTag + '-error');
2007 if ((p.refreshTime > 0) && (!p.once)) {
2009 p.timer.start(Math.round(p.refreshTime));
2018 this.http.onError = function(ex) {
2019 var p = this.parent;
2020 if ((!p) || (!p.running)) return;
2024 if (++p.errors <= 3) {
2026 p.timer.start(3000);
2031 var e = cookie.get(p.cookieTag + '-error') * 1;
2032 if (isNaN(e)) e = 0;
2034 cookie.unset(p.cookieTag);
2035 cookie.set(p.cookieTag + '-error', e, 1);
2037 alert('XMLHTTP: ' + ex);
2042 setTimeout(reloadPage, 2000);
2046 this.http.post(this.actionURL, this.postData);
2050 if (this.cookieTag) cookie.set(this.cookieTag, -(this.refreshTime / 1000));
2052 this.updateUI('stop');
2055 this.once = undefined;
2058 toggle: function(delay) {
2059 if (this.running) this.stop();
2060 else this.start(delay);
2063 updateUI: function(mode) {
2066 if (typeof(E) == 'undefined') return; // for a bizzare bug...
2068 b = (mode != 'stop') && (this.refreshTime > 0);
2069 if ((e = E('refresh-button')) != null) {
2070 e.value = b ? 'Stop' : 'Refresh';
2071 e.disabled = ((mode == 'start') && (!b));
2073 if ((e = E('refresh-time')) != null) e.disabled = b;
2074 if ((e = E('refresh-spinner')) != null) e.style.visibility = b ? 'visible' : 'hidden';
2077 initPage: function(delay, def) {
2080 e = E('refresh-time');
2081 if (((this.cookieTag) && (e != null)) &&
2082 ((v = cookie.get(this.cookieTag)) != null) && (!isNaN(v *= 1))) {
2083 e.value = Math.abs(v);
2084 if (v > 0) v = (v * 1000) + (delay || 0);
2088 if (e) e.value = def;
2099 this.refreshTime = v;
2100 this.timer.start(v);
2101 this.updateUI('wait');
2106 function genStdTimeList(id, zero, min)
2109 var t = [3,4,5,10,15,30,60,120,180,240,300,10*60,15*60,20*60,30*60];
2113 b.push('<select id="' + id + '"><option value=0>' + zero);
2114 for (i = 0; i < t.length; ++i) {
2116 if (v < min) continue;
2117 b.push('<option value=' + v + '>');
2118 if (v == 60) b.push('1 minute');
2119 else if (v > 60) b.push((v / 60) + ' minutes');
2120 else b.push(v + ' seconds');
2122 b.push('</select> ');
2124 document.write(b.join(''));
2127 function genStdRefresh(spin, min, exec)
2129 W('<div style="text-align:right">');
2130 if (spin) W('<img src="spin.gif" id="refresh-spinner"> ');
2131 genStdTimeList('refresh-time', 'Auto Refresh', min);
2132 W('<input type="button" value="Refresh" onclick="' + (exec ? exec : 'refreshClick()') + '" id="refresh-button"></div>');
2136 // -----------------------------------------------------------------------------
2139 function _tabCreate(tabs)
2142 buf.push('<ul id="tabs">');
2143 for (var i = 0; i < arguments.length; ++i)
2144 buf.push('<li><a href="javascript:tabSelect(\'' + arguments[i][0] + '\')" id="' + arguments[i][0] + '">' + arguments[i][1] + '</a>');
2145 buf.push('</ul><div id="tabs-bottom"></div>');
2146 return buf.join('');
2149 function tabCreate(tabs)
2151 document.write(_tabCreate.apply(this, arguments));
2154 function tabHigh(id)
2156 var a = E('tabs').getElementsByTagName('A');
2157 for (var i = 0; i < a.length; ++i) {
2158 if (id != a[i].id) elem.removeClass(a[i], 'active');
2160 elem.addClass(id, 'active');
2163 // -----------------------------------------------------------------------------
2166 set: function(key, value, days) {
2167 document.cookie = 'tomato_' + key + '=' + value + '; expires=' +
2168 (new Date(new Date().getTime() + ((days ? days : 14) * 86400000))).toUTCString() + '; path=/';
2171 get: function(key) {
2172 var r = ('; ' + document.cookie + ';').match('; tomato_' + key + '=(.*?);');
2173 return r ? r[1] : null;
2176 unset: function(key) {
2177 document.cookie = 'tomato_' + key + '=; expires=' +
2178 (new Date(1)).toUTCString() + '; path=/';
2182 // -----------------------------------------------------------------------------
2184 function checkEvent(evt)
2186 if (typeof(evt) == 'undefined') {
2189 evt.target = evt.srcElement;
2190 evt.relatedTarget = evt.toElement;
2202 return (typeof(e) == 'string') ? document.getElementById(e) : e;
2207 return elem.parentElem(e, 'TR');
2210 function THIS(obj, func)
2212 return function() { return func.apply(obj, arguments); }
2217 return (typeof(v) == 'undefined') ? '' : '' + v;
2220 function escapeHTML(s)
2223 return '&#' + c.charCodeAt(0) + ';';
2225 return s.replace(/[&"'<>\r\n]/g, esc);
2228 function escapeCGI(s)
2230 return escape(s).replace(/\+/g, '%2B'); // escape() doesn't handle +
2236 return '%' + c.charCodeAt(0).hex(2);
2238 return s.replace(/[<>|%]/g, esc);
2241 function ellipsis(s, max) {
2242 return (s.length <= max) ? s : s.substr(0, max - 3) + '...';
2247 return a < b ? a : b;
2252 return a > b ? a : b;
2255 function fixInt(n, min, max, def)
2257 if (n === null) return def;
2259 if (isNaN(n)) return def;
2260 if (n < min) return min;
2261 if (n > max) return max;
2269 while ((n = n.replace(/(\d+)(\d{3})/g, '$1,$2')) != p) p = n;
2273 function doScaleSize(n, sm)
2275 if (isNaN(n *= 1)) return '-';
2276 if (n <= 9999) return '' + n;
2281 } while ((n > 9999) && (s < 2));
2282 return comma(n.toFixed(2)) + (sm ? '<small> ' : ' ') + (['KB', 'MB', 'GB'])[s] + (sm ? '</small>' : '');
2285 function scaleSize(n)
2287 return doScaleSize(n, 1);
2290 function timeString(mins)
2292 var h = Math.floor(mins / 60);
2293 if ((new Date(2000, 0, 1, 23, 0, 0, 0)).toLocaleString().indexOf('23') != -1)
2294 return h + ':' + (mins % 60).pad(2);
2295 return ((h == 0) ? 12 : ((h > 12) ? h - 12 : h)) + ':' + (mins % 60).pad(2) + ((h >= 12) ? ' PM' : ' AM');
2298 function features(s)
2300 var features = ['ses','brau','aoss','wham','hpamp','!nve','11n','1000et'];
2303 for (i = features.length - 1; i >= 0; --i) {
2304 if (features[i] == s) return (parseInt(nvram.t_features) & (1 << i)) != 0;
2309 function get_config(name, def)
2311 return ((typeof(nvram) != 'undefined') && (typeof(nvram[name]) != 'undefined')) ? nvram[name] : def;
2318 // -----------------------------------------------------------------------------
2320 function show_notice1(s)
2322 // ---- !!TB - USB Support: multi-line notices
2323 if (s.length) document.write('<div id="notice1">' + s.replace(/\n/g, '<br>') + '</div><br style="clear:both">');
2326 // -----------------------------------------------------------------------------
2332 name = document.location.pathname;
2333 name = name.replace(/\\/g, '/'); // IE local testing
2334 if ((i = name.lastIndexOf('/')) != -1) name = name.substring(i + 1, name.length);
2335 if (name == '') name = 'status-overview.asp';
2342 ['Status', 'status', 0, [
2343 ['Overview', 'overview.asp'],
2344 ['Device List', 'devices.asp'],
2345 ['Web Usage', 'webmon.asp'],
2346 ['Logs', 'log.asp'] ] ],
2347 ['Bandwidth', 'bwm', 0, [
2348 ['Real-Time', 'realtime.asp'],
2349 ['Last 24 Hours', '24.asp'],
2350 ['Daily', 'daily.asp'],
2351 ['Weekly', 'weekly.asp'],
2352 ['Monthly', 'monthly.asp'] ] ],
2353 ['Tools', 'tools', 0, [
2354 ['Ping', 'ping.asp'],
2355 ['Trace', 'trace.asp'],
2356 ['System', 'shell.asp'],
2357 ['Wireless Survey', 'survey.asp'],
2358 ['WOL', 'wol.asp'] ] ],
2360 ['Basic', 'basic', 0, [
2361 ['Network', 'network.asp'],
2363 ['IPv6', 'ipv6.asp'],
2365 ['Identification', 'ident.asp'],
2366 ['Time', 'time.asp'],
2367 ['DDNS', 'ddns.asp'],
2368 ['Static DHCP', 'static.asp'],
2369 ['Wireless Filter', 'wfilter.asp'] ] ],
2370 ['Advanced', 'advanced', 0, [
2371 ['Conntrack / Netfilter', 'ctnf.asp'],
2372 ['DHCP / DNS', 'dhcpdns.asp'],
2373 ['Firewall', 'firewall.asp'],
2374 ['MAC Address', 'mac.asp'],
2375 ['Miscellaneous', 'misc.asp'],
2376 ['Routing', 'routing.asp'],
2377 ['Wireless', 'wireless.asp'] ] ],
2378 ['Port Forwarding', 'forward', 0, [
2379 ['Basic', 'basic.asp'],
2381 ['Basic IPv6', 'basic-ipv6.asp'],
2384 ['Triggered', 'triggered.asp'],
2385 ['UPnP / NAT-PMP', 'upnp.asp'] ] ],
2387 ['Basic Settings', 'settings.asp'],
2388 ['Classification', 'classify.asp'],
2389 ['View Graphs', 'graphs.asp'],
2390 ['View Details', 'detailed.asp'],
2391 ['Transfer Rates', 'ctrate.asp']
2393 ['QOS/Bandwidth Limiter', 'new-qoslimit.asp'],
2394 ['Access Restriction', 'restrict.asp'],
2396 ['Scripts', 'sc', 0, [
2397 ['Startup', 'startup.asp'],
2398 ['Shutdown', 'shutdown.asp'],
2399 ['Firewall', 'firewall.asp'],
2400 ['WAN Up', 'wanup.asp']
2404 // ---- !!TB - USB, FTP, Samba, Media Server
2405 ['USB and NAS', 'nas', 0, [
2406 ['USB Support', 'usb.asp']
2408 ,['FTP Server', 'ftp.asp']
2411 ,['File Sharing', 'samba.asp']
2413 /* MEDIA-SRV-BEGIN */
2414 ,['Media Server', 'media.asp']
2419 ['VPN Tunneling', 'vpn', 0, [
2420 ['Server', 'server.asp'],
2421 ['Client', 'client.asp'] ] ],
2424 ['Administration', 'admin', 0, [
2425 ['Admin Access', 'access.asp'],
2426 ['Bandwidth Monitoring','bwm.asp'],
2427 ['Buttons / LED', 'buttons.asp'],
2429 ['CIFS Client', 'cifs.asp'],
2431 ['Configuration', 'config.asp'],
2432 ['Debugging', 'debug.asp'],
2434 ['JFFS', 'jffs2.asp'],
2436 ['Logging', 'log.asp'],
2437 ['Scheduler', 'sched.asp'],
2438 ['Scripts', 'scripts.asp'],
2439 ['Upgrade', 'upgrade.asp'] ] ],
2441 ['About', 'about.asp'],
2442 ['Reboot...', 'javascript:reboot()'],
2443 ['Shutdown...', 'javascript:shutdown()'],
2444 ['Logout', 'javascript:logout()']
2452 var cexp = get_config('web_mx', '').toLowerCase();
2455 if (name == 'restrict-edit.asp') name = 'restrict.asp';
2456 if ((i = name.indexOf('-')) != -1) {
2457 base = name.substring(0, i);
2458 name = name.substring(i + 1, name.length);
2462 for (i = 0; i < menu.length; ++i) {
2468 if (m.length == 2) {
2469 buf.push('<a href="' + m[1] + '" class="indent1' + (((base == '') && (name == m[1])) ? ' active' : '') + '">' + m[0] + '</a>');
2476 a = cookie.get('menu_' + m[1]);
2478 for (j = 0; j < m[3].length; ++j) {
2479 if (m[3][j][1] == a) {
2486 if (a == 'status-overview.asp') a = '/';
2487 on1 = (base == m[1]);
2488 buf.push('<a href="' + a + '" class="indent1' + (on1 ? ' active' : '') + '">' + m[0] + '</a>');
2489 if ((!on1) && (m[2] == 0) && (cexp.indexOf(m[1]) == -1)) continue;
2491 for (j = 0; j < m[3].length; ++j) {
2493 a = m[1] + '-' + sm[1];
2494 if (a == 'status-overview.asp') a = '/';
2495 buf.push('<a href="' + a + '" class="indent2' + (((on1) && (name == sm[1])) ? ' active' : '') + '">' + sm[0] + '</a>');
2499 document.write(buf.join(''));
2502 if ((base == 'qos') && (name == 'detailed.asp')) name = 'view.asp';
2503 cookie.set('menu_' + base, name);
2507 function createFieldTable(flags, desc)
2521 if ((flags.indexOf('noopen') == -1)) buf.push('<table class="fields">');
2522 for (desci = 0; desci < desc.length; ++desci) {
2523 var v = desc[desci];
2526 buf.push('<tr><td colspan=2 class="spacer"> </td></tr>');
2530 if (v.ignore) continue;
2533 if (v.rid) buf.push(' id="' + v.rid + '"');
2534 if (v.hidden) buf.push(' style="display:none"');
2539 buf.push('<td class="title indent' + (v.indent || 1) + '">' + v.title + '</td><td class="content">' + v.text + '</td></tr>');
2542 buf.push('<td colspan=2>' + v.text + '</td></tr>');
2549 buf2.push('<td class="content">');
2551 if (v.multi) fields = v.multi;
2554 for (n = 0; n < fields.length; ++n) {
2556 if (f.prefix) buf2.push(f.prefix);
2558 if ((f.type == 'radio') && (!f.id)) id = '_' + f.name + '_' + i;
2559 else id = (f.id ? f.id : ('_' + f.name));
2561 if (id1 == '') id1 = id;
2563 common = ' onchange="verifyFields(this, 1)" id="' + id + '"';
2564 if (f.attrib) common += ' ' + f.attrib;
2565 name = f.name ? (' name="' + f.name + '"') : '';
2569 buf2.push('<input type="checkbox"' + name + (f.value ? ' checked' : '') + ' onclick="verifyFields(this, 1)"' + common + '>');
2572 buf2.push('<input type="radio"' + name + (f.value ? ' checked' : '') + ' onclick="verifyFields(this, 1)"' + common + '>');
2576 switch (get_config('web_pb', '1')) {
2584 if (f.type == 'password') {
2585 common += ' autocomplete="off"';
2586 if (f.peekaboo) common += ' onfocus=\'peekaboo("' + id + '",1)\'';
2590 buf2.push('<input type="' + f.type + '"' + name + ' value="' + escapeHTML(UT(f.value)) + '" maxlength=' + f.maxlen + (f.size ? (' size=' + f.size) : '') + common + '>');
2593 buf2.push('<select' + name + common + '>');
2594 for (i = 0; i < f.options.length; ++i) {
2596 if (a.length == 1) a.push(a[0]);
2597 buf2.push('<option value="' + a[0] + '"' + ((a[0] == f.value) ? ' selected' : '') + '>' + a[1] + '</option>');
2599 buf2.push('</select>');
2602 buf2.push('<textarea' + name + common + (f.wrap ? (' wrap=' + f.wrap) : '') + '>' + escapeHTML(UT(f.value)) + '</textarea>');
2605 if (f.custom) buf2.push(f.custom);
2608 if (f.suffix) buf2.push(f.suffix);
2612 buf.push('<td class="title indent' + (v.indent ? v.indent : 1) + '">');
2613 if (id1 != '') buf.push('<label for="' + id + '">' + v.title + '</label></td>');
2614 else buf.push(+ v.title + '</td>');
2616 buf.push(buf2.join(''));
2619 if ((!flags) || (flags.indexOf('noclose') == -1)) buf.push('</table>');
2620 document.write(buf.join(''));
2623 function peekaboo(id, show)
2626 var o = document.createElement('INPUT');
2629 o.type = show ? 'text' : 'password';
2632 o.maxLength = e.maxLength;
2633 o.autocomplete = e.autocomplete;
2635 o.disabled = e.disabled;
2636 o.onchange = e.onchange;
2637 e.parentNode.replaceChild(o, e);
2643 o.onblur = function(ev) { setTimeout('peekaboo("' + this.id + '", 0)', 0) };
2644 setTimeout('try { E("' + id + '").focus() } catch (ex) { }', 0)
2647 o.onfocus = function(ev) { peekaboo(this.id, 1); };
2656 - e.type= doesn't work in IE, ok in FF
2657 - may mess keyboard tabing (bad: IE; ok: FF, Opera)... setTimeout() delay seems to help a little.
2661 // -----------------------------------------------------------------------------
2663 function reloadPage()
2665 document.location.reload(1);
2670 if (confirm("Reboot?")) form.submitHidden('tomato.cgi', { _reboot: 1, _commit: 0, _nvset: 0 });
2675 if (confirm("Shutdown?")) form.submitHidden('shutdown.cgi', { });
2680 form.submitHidden('logout.asp', { });
2683 // -----------------------------------------------------------------------------
2691 return location.href.search('file://') == 0;