Cosmetics - Basic-Network page (change "Check Interval" to "Redial Interval")
[tomato/davidwu.git] / release / src / router / www / basic-network.asp
blob2bcbdf561b155484e97606cf254c874e584a3fa8
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(); %>] Basic: Network</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <% css(); %>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <style type='text/css'>
22 #lan-grid .co1,
23 #lan-grid .co2,
24 #lan-grid .co3,
25 #lan-grid .co4,
26 #lan-grid .co5,
27 #lan-grid .co6,
28 #lan-grid .co7 {
29 text-align: center;
32 #lan-grid .centered {
33 text-align: center;
36 #spin {
37 visibility: hidden;
38 vertical-align: middle;
40 </style>
42 <script type='text/javascript' src='debug.js'></script>
44 <script type='text/javascript' src='md5.js'></script>
45 <script type='text/javascript' src='wireless.jsx?_http_id=<% nv(http_id); %>'></script>
46 <script type='text/javascript' src='interfaces.js'></script>
47 <script type='text/javascript'>
49 // <% nvram("dhcp_lease,dhcp_num,dhcp_start,dhcpd_startip,dhcpd_endip,l2tp_server_ip,lan_gateway,lan_ipaddr,lan_netmask,lan_proto,mtu_enable,ppp_demand,ppp_idletime,ppp_passwd,ppp_redialperiod,ppp_service,ppp_username,ppp_custom,pptp_server_ip,pptp_dhcp,wl_security_mode,wan_dns,wan_gateway,wan_ipaddr,wan_mtu,wan_netmask,wan_proto,wan_wins,wl_wds_enable,wl_channel,wl_closed,wl_crypto,wl_key,wl_key1,wl_key2,wl_key3,wl_key4,wl_lazywds,wl_mode,wl_net_mode,wl_passphrase,wl_radio,wl_radius_ipaddr,wl_radius_port,wl_ssid,wl_wds,wl_wep_bit,wl_wpa_gtk_rekey,wl_wpa_psk,wl_radius_key,wl_auth,wl_hwaddr,wan_islan,t_features,wl_nbw_cap,wl_nctrlsb,wl_nband,wl_phytype,lan_ifname,lan_stp,lan1_ifname,lan1_ipaddr,lan1_netmask,lan1_proto,lan1_stp,dhcp1_start,dhcp1_num,dhcp1_lease,dhcpd1_startip,dhcpd1_endip,lan2_ifname,lan2_ipaddr,lan2_netmask,lan2_proto,lan2_stp,dhcp2_start,dhcp2_num,dhcp2_lease,dhcpd2_startip,dhcpd2_endip,lan3_ifname,lan3_ipaddr,lan3_netmask,lan3_proto,lan3_stp,dhcp3_start,dhcp3_num,dhcp3_lease,dhcpd3_startip,dhcpd3_endip,ppp_mlppp,modem_ipaddr,modem_pin,modem_dev,modem_init,modem_apn,cstats_enable"); %>
51 /* VLAN-BEGIN */
52 var lg = new TomatoGrid();
53 lg.setup = function() {
54 this.init('lan-grid', '', 4, [
55 { type: 'select', options: [[0, '0'],[1, '1'],[2, '2'],[3, '3']], prefix: '<div class="centered">', suffix: '</div>' },
56 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
57 { type: 'text', maxlen: 15, size: 17 },
58 { type: 'text', maxlen: 15, size: 17 },
59 { type: 'checkbox', prefix: '<div class="centered">', suffix: '</div>' },
60 { multi: [ { type: 'text', maxlen: 15, size: 17}, { type: 'text', maxlen: 15, size: 17 } ] },
61 { type: 'text', maxlen: 6, size: 8 }] );
62 this.headerSet(['Bridge', 'STP', 'IP Address', 'Netmask', 'DHCP', 'IP&nbsp;Range&nbsp;<i>(first/last)</i>', 'Lease&nbsp;Time&nbsp;<i>(mins)</i>']);
64 var numBridges = 0;
65 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
66 var j = (i == 0) ? '' : i.toString();
67 if (nvram['lan' + j + '_ifname'].length > 0) {
68 if ((!fixIP(nvram['dhcpd' + j + '_startip'])) || (!fixIP(nvram['dhcpd' + j + '_endip']))) {
69 if ((fixIP(nvram['lan' + j + '_ipaddr'])) && (fixIP(nvram['lan' + j + '_netmask'])) && (nvram['dhcp' + j + '_start'] != '')) {
70 var n = getNetworkAddress(nvram['lan' + j + '_ipaddr'], nvram['lan' + j + '_netmask']);
71 nvram['dhcpd' + j + '_startip'] = getAddress(('0.0.0.' + nvram['dhcp' + j + '_start'] * 1), n);
72 nvram['dhcpd' + j + '_endip'] = getAddress(('0.0.0.' + ((nvram['dhcp' + j + '_start'] * 1) + (nvram['dhcp' + j + '_num'] *1) - 1)), n);
75 lg.insertData(-1, [
76 i.toString(),
77 nvram['lan' + j + '_stp'],
78 nvram['lan' + j + '_ipaddr'],
79 nvram['lan' + j + '_netmask'],
80 (nvram['lan' + j + '_proto'] == 'dhcp') ? '1' : '0',
81 nvram['dhcpd' + j + '_startip'],
82 nvram['dhcpd' + j + '_endip'],
83 (nvram['lan' + j + '_proto'] == 'dhcp') ? (((nvram['dhcp' + j + '_lease'])*1 == 0) ? '1440' : (nvram['dhcp' + j + '_lease']).toString()) : ''
84 ] ) ;
85 numBridges++;
88 lg.canDelete = false;
89 lg.sort(0);
90 elem.removeClass(lg.header.cells[lg.sortColumn], 'sortasc', 'sortdes');
91 lg.showNewEditor();
92 lg.resetNewEditor();
95 lg.dataToView = function(data) {
96 return ['br' + data[0],
97 (data[1].toString() == '1') ? '<small><i>Enabled</i></small>' : '<small><i>Disabled</i></small>',
98 data[2],
99 data[3],
100 (data[4].toString() == '1') ? '<small><i>Enabled</i></small>' : '<small><i>Disabled</i></small>',
101 (data[5].toString() + ((numberOfBitsOnNetMask(data[3])>=24) ? (' - ' + data[6].split('.').splice(3, 1).toString()) : ('<br>' + data[6].toString()) )),
102 (((data[7] != null) && (data[7] != '')) ? data[7] : '') ];
105 lg.dataToFieldValues = function (data) {
106 return [data[0],
107 (data[1] != 0) ? 'checked' : '',
108 data[2].toString(),
109 data[3].toString(),
110 (data[4].toString() == '1') ? 'checked' : '',
111 data[5].toString(),
112 data[6].toString(),
113 data[7].toString() ];
116 lg.fieldValuesToData = function(row) {
117 var f = fields.getAll(row);
118 return [f[0].value,
119 f[1].checked ? 1 : 0,
120 f[2].value,
121 f[3].value,
122 f[4].checked ? 1 : 0,
123 f[5].value,
124 f[6].value,
125 f[7].value ];
128 lg.resetNewEditor = function() {
129 var f = fields.getAll(this.newEditor);
130 f[0].selectedIndex=0;
131 var t = MAX_BRIDGE_ID;
132 while((this.countBridge(f[0].selectedIndex) > 0) && (t > 0)) {
133 f[0].selectedIndex = (f[0].selectedIndex%(MAX_BRIDGE_ID))+1;
134 t--;
136 for(var j=0; j<= MAX_BRIDGE_ID ; j++) {
137 f[0].options[j].disabled = (this.countBridge(j) > 0);
139 f[1].checked = 0;
140 f[2].value = '';
141 f[3].value = '';
142 f[5].value = '';
143 f[6].value = '';
144 f[7].value = '';
145 f[4].checked = 0;
146 f[4].disabled = 1;
147 f[5].disabled = 1;
148 f[6].disabled = 1;
149 f[7].disabled = 1;
150 ferror.clearAll(fields.getAll(this.newEditor));
153 lg.onCancel = function() {
154 this.removeEditor();
155 this.showSource();
156 this.disableNewEditor(false);
158 this.resetNewEditor();
161 lg.onAdd = function() {
162 var data;
164 this.moving = null;
165 this.rpHide();
167 if (!this.verifyFields(this.newEditor, false)) return;
169 data = this.fieldValuesToData(this.newEditor);
170 this.insertData(-1, data);
172 this.disableNewEditor(false);
173 this.resetNewEditor();
175 this.resort();
178 lg.onOK = function() {
179 var i, data, view;
181 if (!this.verifyFields(this.editor, false)) return;
183 data = this.fieldValuesToData(this.editor);
184 view = this.dataToView(data);
186 this.source.setRowData(data);
187 for (i = 0; i < this.source.cells.length; ++i) {
188 this.source.cells[i].innerHTML = view[i];
191 this.removeEditor();
192 this.showSource();
193 this.disableNewEditor(false);
195 this.resort();
196 this.resetNewEditor();
199 lg.onDelete = function() {
200 this.removeEditor();
201 elem.remove(this.source);
202 this.source = null;
203 this.disableNewEditor(false);
205 this.resetNewEditor();
208 lg.countElem = function(f, v) {
209 var data = this.getAllData();
210 var total = 0;
211 for (var i = 0; i < data.length; ++i) {
212 total += (data[i][f] == v) ? 1 : 0;
214 return total;
217 lg.countBridge = function (v) {
218 return this.countElem(0,v);
221 lg.countOverlappingNetworks = function (ip) {
222 var data = this.getAllData();
223 var total = 0;
224 for (var i = 0; i < data.length; ++i) {
225 var net = getNetworkAddress(data[i][2], data[i][3]);
226 var brd = getBroadcastAddress(net, data[i][3]);
227 total += ((aton(ip) <= aton(brd)) && (aton(ip) >= aton(net))) ? 1 : 0;
229 return total;
232 lg.verifyFields = function(row, quiet) {
233 var ok=1;
234 var f;
236 f = fields.getAll(row);
238 for(var j=0; j<= MAX_BRIDGE_ID ; j++) {
239 f[0].options[j].disabled = (this.countBridge(j) > 0);
242 if(this.countBridge(f[0].selectedIndex) > 0) {
243 ferror.set(f[0], 'Cannot add another entry for bridge br' + f[0].selectedIndex, quiet);
244 ok = 0;
245 } else {
246 ferror.clear(f[0]);
248 // valid IP address?
249 if(!v_ip(f[2], quiet || !ok))
250 ok = 0;
251 // if we have a properly defined IP address - 0.0.0.0 is NOT a valid IP address for our intents/purposes!
252 if ((f[2].value != '') && (f[2].value != '0.0.0.0')) {
253 // allow DHCP to be enabled
254 f[4].disabled = 0;
255 // validate netmask
256 if(!v_netmask(f[3], quiet || !ok)) {
257 return 0;
258 } else {
259 // should be 22 bits or smaller network
260 if ((numberOfBitsOnNetMask(f[3].value) < 22) && (nvram.cstats_enable == '1' )) {
261 if (!confirm("Netmask should have at least 22 bits (255.255.252.0). You may continue anyway but remember - you were warned!")) return;
262 } else {
263 ferror.clear(f[3]);
266 if(f[2].value == getNetworkAddress(f[2].value, f[3].value)) {
267 var s = 'Invalid IP address or subnet mask (the address of the network cannot be used)';
268 ferror.set(f[2], s, quiet);
269 ferror.set(f[3], s, quiet);
270 return 0;
271 } else
272 if(f[2].value == getBroadcastAddress(getNetworkAddress(f[2].value, f[3].value), f[3].value)) {
273 var s = 'Invalid IP address or subnet mask (the broadcast address cannot be used)';
274 ferror.set(f[2], s, quiet);
275 ferror.set(f[3], s, quiet);
276 return 0;
277 } else
278 if (this.countOverlappingNetworks(f[2].value) > 0) {
279 var s = 'Invalid IP address or subnet mask (conflicts/overlaps with another LAN bridge)';
280 ferror.set(f[2], s, quiet);
281 ferror.set(f[3], s, quiet);
282 return 0;
283 } else {
284 ferror.clear(f[2]);
285 ferror.clear(f[3]);
287 } else {
288 f[4].checked = 0;
289 f[4].disabled = 1;
291 // dhcp enabled?
292 if( (f[4].checked) && (v_ip(f[2], 1)) && (v_netmask(f[3],1)) ) {
293 f[5].disabled = 0;
294 f[6].disabled = 0;
295 f[7].disabled = 0;
296 // first/last IP still unset?
297 if (f[5].value == '') {
298 var l;
299 var m = aton(f[2].value) & aton(f[3].value);
300 var o = (m) ^ (~ aton(f[3].value))
301 var n = o - m;
302 do {
303 if (--n < 0) {
304 f[5].value = '';
305 return;
307 m++;
308 } while (((l = fixIP(ntoa(m), 1)) == null) || (l == f[2].value) );
309 f[5].value = l;
311 if (f[6].value == '') {
312 var l;
313 var m = aton(f[2].value) & aton(f[3].value);
314 var o = (m) ^ (~ aton(f[3].value));
315 var n = o - m;
316 do {
317 if (--n < 0) {
318 f[6].value = '';
319 return;
321 o--;
322 } while (((l = fixIP(ntoa(o), 1)) == null) || (l == f[2].value) );
323 f[6].value = l;
325 // first IP valid?
326 if ((getNetworkAddress(f[5].value, f[3].value) != getNetworkAddress(f[2].value, f[3].value)) ||
327 (f[5].value == getBroadcastAddress(getNetworkAddress(f[2].value, f[3].value), f[3].value)) ||
328 (f[5].value == getNetworkAddress(f[2].value, f[3].value)) ||
329 (f[2].value == f[5].value)) {
330 ferror.set(f[5], 'Invalid first IP address or subnet mask', quiet || !ok);
331 return 0;
332 } else {
333 ferror.clear(f[5]);
335 // last IP valid?
336 if ((getNetworkAddress(f[6].value, f[3].value) != getNetworkAddress(f[2].value, f[3].value)) ||
337 (f[6].value == getBroadcastAddress(getNetworkAddress(f[2].value, f[3].value), f[3].value)) ||
338 (f[6].value == getNetworkAddress(f[2].value, f[3].value)) ||
339 (f[2].value == f[6].value)) {
340 ferror.set(f[6], 'Invalid last IP address or subnet mask', quiet || !ok);
341 return 0;
342 } else {
343 ferror.clear(f[6]);
345 // validate range, swap first/last IP if needed
346 if (aton(f[6].value) < aton(f[5].value)) {
347 var t = f[5].value;
348 f[5].value = f[6].value;
349 f[6].value = t;
351 // lease time
352 if (parseInt(f[7].value*1) == 0)
353 f[7].value = 1440; // from nvram/defaults.c
354 if(!v_mins(f[7], quiet || !ok, 1, 10080))
355 ok = 0;
356 } else {
357 f[5].disabled = 1;
358 f[6].disabled = 1;
359 f[7].disabled = 1;
360 ferror.clear(f[5]);
361 ferror.clear(f[6]);
362 ferror.clear(f[7]);
364 return ok;
366 /* VLAN-END */
368 W('<style type=\'text/css\'>');
369 for (var u = 0; u < wl_ifaces.length; ++u) {
370 W('#spin'+wl_unit(u)+', ');
372 W('#spin {');
373 W(' visibility: hidden;');
374 W(' vertical-align: middle;');
375 W('}');
376 W('</style>');
378 var xob = null;
379 var refresher = [];
380 var nphy = features('11n');
382 /* NOVLAN-BEGIN */
383 if ((!fixIP(nvram.dhcpd_startip)) || (!fixIP(nvram.dhcpd_endip))) {
384 var x = nvram.lan_ipaddr.split('.').splice(0, 3).join('.') + '.';
385 nvram.dhcpd_startip = x + nvram.dhcp_start;
386 nvram.dhcpd_endip = x + ((nvram.dhcp_start * 1) + (nvram.dhcp_num * 1) - 1);
388 /* NOVLAN-END */
390 var ghz = [];
391 var bands = [];
392 var nm_loaded = [], ch_loaded = [], max_channel = [];
394 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
395 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
396 if (wl_sunit(uidx)<0) {
397 var b;
398 b = [];
399 for (var i = 0; i < wl_bands[uidx].length; ++i) {
400 b.push([wl_bands[uidx][i] + '', (wl_bands[uidx][i] == '1') ? '5 GHz' : '2.4 GHz']);
402 bands.push(b);
404 b = [];
405 ghz.push(b);
407 nm_loaded.push(0);
408 ch_loaded.push(0);
409 max_channel.push(0);
410 refresher.push(null);
414 function selectedBand(uidx)
416 if (bands[uidx].length > 1) {
417 var e = E('_f_wl'+u+'_nband');
418 return (e.value + '' == '' ? eval('nvram.wl'+u+'_nband') : e.value);
419 } else if (bands[uidx].length > 0) {
420 return bands[uidx][0][0] || '0';
421 } else {
422 return '0';
426 function refreshNetModes(uidx)
428 var e, i, buf, val;
430 if (uidx >= wl_ifaces.length) return;
431 var u = wl_unit(uidx);
433 var m = [['mixed','Auto']];
434 if (selectedBand(uidx) == '1') {
435 m.push(['a-only','A Only']);
436 if (nphy) {
437 m.push(['n-only','N Only']);
440 else {
441 m.push(['b-only','B Only']);
442 m.push(['g-only','G Only']);
443 if (nphy) {
444 m.push(['bg-mixed','B/G Mixed']);
445 m.push(['n-only','N Only']);
449 e = E('_wl'+u+'_net_mode');
450 buf = '';
451 val = (!nm_loaded[uidx] || (e.value + '' == '')) ? eval('nvram.wl'+u+'_net_mode') : e.value;
452 if (val == 'disabled') val = 'mixed';
453 for (i = 0; i < m.length; ++i)
454 buf += '<option value="' + m[i][0] + '"' + ((m[i][0] == val) ? ' selected' : '') + '>' + m[i][1] + '</option>';
456 e = E('__wl'+u+'_net_mode');
457 buf = '<select name="wl'+u+'_net_mode" onchange="verifyFields(this, 1)" id = "_wl'+u+'_net_mode">' + buf + '</select>';
458 elem.setInnerHTML(e, buf);
459 nm_loaded[uidx] = 1;
462 function refreshChannels(uidx)
464 if (refresher[uidx] != null) return;
465 if (u >= wl_ifaces.length) return;
466 var u = wl_unit(uidx);
468 refresher[uidx] = new XmlHttp();
469 refresher[uidx].onCompleted = function(text, xml) {
470 try {
471 var e, i, buf, val;
473 var wl_channels = [];
474 eval(text);
476 ghz[uidx] = [];
477 max_channel[uidx] = 0;
478 for (i = 0; i < wl_channels.length; ++i) {
479 ghz[uidx].push([wl_channels[i][0] + '',
480 (wl_channels[i][0]) ? ((wl_channels[i][1]) ? wl_channels[i][0] + ' - ' + (wl_channels[i][1] / 1000.0).toFixed(3) + ' GHz' : wl_channels[i][0] + '') : 'Auto']);
481 max_channel[uidx] = wl_channels[i][0] * 1;
484 e = E('_wl'+u+'_channel');
485 buf = '';
486 val = (!ch_loaded[uidx] || (e.value + '' == '')) ? eval('nvram.wl'+u+'_channel') : e.value;
487 for (i = 0; i < ghz[uidx].length; ++i)
488 buf += '<option value="' + ghz[uidx][i][0] + '"' + ((ghz[uidx][i][0] == val) ? ' selected' : '') + '>' + ghz[uidx][i][1] + '</option>';
490 e = E('__wl'+u+'_channel');
491 buf = '<select name="wl'+u+'_channel" onchange="verifyFields(this, 1)" id = "_wl'+u+'_channel">' + buf + '</select>';
492 elem.setInnerHTML(e, buf);
493 ch_loaded[uidx] = 1;
495 refresher[uidx] = null;
496 verifyFields(null, 1);
498 catch (x) {
500 refresher[uidx] = null;
503 var bw, sb, e;
505 e = E('_f_wl'+u+'_nctrlsb');
506 sb = (e.value + '' == '' ? eval('nvram.wl'+u+'_nctrlsb') : e.value);
507 e = E('_wl'+u+'_nbw_cap');
508 bw = (e.value + '' == '' ? eval('nvram.wl'+u+'_nbw_cap') : e.value) == '0' ? '20' : '40';
510 refresher[uidx].onError = function(ex) { alert(ex); refresher[uidx] = null; reloadPage(); }
511 refresher[uidx].post('update.cgi', 'exec=wlchannels&arg0=' + u + '&arg1=' + (nphy ? '1' : '0') +
512 '&arg2=' + bw + '&arg3=' + selectedBand(uidx) + '&arg4=' + sb);
515 function spin(x, unit)
517 for (var u = 0; u < wl_ifaces.length; ++u) {
518 E('_f_wl'+wl_unit(u)+'_scan').disabled = x;
520 var e = E('_f_wl'+unit+'_scan');
521 if (x) e.value = 'Scan ' + (wscan.tries + 1);
522 else e.value = 'Scan';
523 E('spin'+unit).style.visibility = x ? 'visible' : 'hidden';
526 function scan()
528 if (xob) return;
530 var unit = wscan.unit;
531 var uidx = wl_uidx(unit);
533 xob = new XmlHttp();
534 xob.onCompleted = function(text, xml) {
535 try {
536 var i;
538 wlscandata = [];
539 eval(text);
541 for (i = 0; i < wlscandata.length; ++i) {
542 var data = wlscandata[i];
543 var ch = data[2];
544 var mac = data[0];
546 if (!wscan.inuse[ch]) {
547 wscan.inuse[ch] = {
548 count: 0,
549 rssi: -999,
550 ssid: ''
554 if (!wscan.seen[mac]) {
555 wscan.seen[mac] = 1;
556 ++wscan.inuse[ch].count;
559 if (data[4] > wscan.inuse[ch].rssi) {
560 wscan.inuse[ch].rssi = data[4];
561 wscan.inuse[ch].ssid = data[1];
564 var e = E('_wl'+unit+'_channel');
565 for (i = 1; i < ghz[uidx].length; ++i) {
566 var s = ghz[uidx][i][1];
567 var u = wscan.inuse[ghz[uidx][i][0]];
568 if (u) s += ' (' + u.count + ' AP' + (u.count == 1 ? '' : 's') + ' / strongest: "' + escapeHTML(ellipsis(u.ssid, 15)) + '" ' + u.rssi + ' dBm)';
569 e.options[i].innerHTML = s;
571 e.style.width = '400px';
573 xob = null;
575 if (wscan.tries < 4) {
576 ++wscan.tries;
577 setTimeout(scan, 1000);
578 return;
581 catch (x) {
583 spin(0, unit);
585 xob.onError = function(x) {
586 alert('error: ' + x);
587 spin(0, unit);
588 xob = null;
591 spin(1, unit);
592 xob.post('update.cgi', 'exec=wlscan&arg0='+unit);
595 function scanButton(u)
597 if (xob) return;
599 wscan = {
600 unit: u,
601 seen: [],
602 inuse: [],
603 tries: 0
606 scan();
609 function joinAddr(a) {
610 var r, i, s;
612 r = [];
613 for (i = 0; i < a.length; ++i) {
614 s = a[i];
615 if ((s != '00:00:00:00:00:00') && (s != '0.0.0.0')) r.push(s);
617 return r.join(' ');
620 function random_x(max)
622 var c = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
623 var s = '';
624 while (max-- > 0) s += c.substr(Math.floor(c.length * Math.random()), 1);
625 return s;
628 function random_psk(id)
630 var e = E(id);
631 e.value = random_x(63);
632 verifyFields(null, 1);
635 function random_wep(u)
637 E('_wl'+u+'_passphrase').value = random_x(16);
638 generate_wep(u);
641 function v_wep(e, quiet)
643 var s = e.value;
645 if (((s.length == 5) || (s.length == 13)) && (s.length == (e.maxLength >> 1))) {
646 // no checking
648 else {
649 s = s.toUpperCase().replace(/[^0-9A-F]/g, '');
650 if (s.length != e.maxLength) {
651 ferror.set(e, 'Invalid WEP key. Expecting ' + e.maxLength + ' hex or ' + (e.maxLength >> 1) + ' ASCII characters.', quiet);
652 return 0;
656 e.value = s;
657 ferror.clear(e);
658 return 1;
661 // compatible w/ Linksys' and Netgear's (key 1) method for 128-bits
662 function generate_wep(u)
664 function _wepgen(pass, i)
666 while (pass.length < 64) pass += pass;
667 return hex_md5(pass.substr(0, 64)).substr(i, (E('_wl'+u+'_wep_bit').value == 128) ? 26 : 10);
670 var e = E('_wl'+u+'_passphrase');
671 var pass = e.value;
672 if (!v_length(e, false, 3)) return;
673 E('_wl'+u+'_key1').value = _wepgen(pass, 0);
674 pass += '#$%';
675 E('_wl'+u+'_key2').value = _wepgen(pass, 2);
676 pass += '!@#';
677 E('_wl'+u+'_key3').value = _wepgen(pass, 4);
678 pass += '%&^';
679 E('_wl'+u+'_key4').value = _wepgen(pass, 6);
680 verifyFields(null, 1);
683 function verifyFields(focused, quiet)
685 var i;
686 var ok = 1;
687 var a, b, c, d, e;
688 var u, uidx;
689 var wmode, sm2;
691 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
692 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
693 if (wl_sunit(uidx)<0) {
694 u = wl_unit(uidx);
695 if (focused == E('_f_wl'+u+'_nband')) {
696 refreshNetModes(uidx);
697 refreshChannels(uidx);
699 else if (focused == E('_f_wl'+u+'_nctrlsb') || focused == E('_wl'+u+'_nbw_cap')) {
700 refreshChannels(uidx);
705 // --- visibility ---
707 var vis = {
708 _wan_proto: 1,
709 _ppp_username: 1,
710 _ppp_passwd: 1,
711 _ppp_service: 1,
712 _ppp_custom: 1,
713 _l2tp_server_ip: 1,
714 _wan_ipaddr: 1,
715 _wan_netmask: 1,
716 _wan_gateway: 1,
717 _pptp_server_ip: 1,
718 _f_pptp_dhcp: 1,
719 _ppp_demand: 1,
720 _ppp_idletime: 1,
721 _ppp_redialperiod: 1,
722 _mtu_enable: 1,
723 _f_wan_mtu: 1,
724 _f_wan_islan: 0,
725 _f_ppp_mlppp: 1,
726 _modem_ipaddr: 1,
728 /* NOVLAN-BEGIN */
729 _dhcp_lease: 1,
730 _f_dhcpd_enable: 1,
731 _dhcpd_startip: 1,
732 _dhcpd_endip: 1,
733 _lan_ipaddr: 1,
734 _lan_netmask: 1,
735 /* NOVLAN-END */
736 _f_dns_1: 1,
737 _f_dns_2: 1,
738 _f_dns_3: 1,
739 _lan_gateway: 1,
740 _wan_wins: 1,
741 _modem_pin: 1,
742 _modem_dev: 1,
743 _modem_init: 1,
744 _modem_apn: 1
747 var wl_vis = [];
748 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
749 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
750 if (wl_sunit(uidx)<0) {
751 a = {
752 _f_wl_radio: 1,
753 _f_wl_mode: 1,
754 _f_wl_nband: (bands[uidx].length > 1) ? 1 : 0,
755 _wl_net_mode: 1,
756 _wl_ssid: 1,
757 _f_wl_bcast: 1,
758 _wl_channel: 1,
759 _wl_nbw_cap: nphy ? 1 : 0,
760 _f_wl_nctrlsb: nphy ? 1 : 0,
761 _f_wl_scan: 1,
763 _wl_security_mode: 1,
764 _wl_crypto: 1,
765 _wl_wpa_psk: 1,
766 _f_wl_psk_random1: 1,
767 _f_wl_psk_random2: 1,
768 _wl_wpa_gtk_rekey: 1,
769 _wl_radius_key: 1,
770 _wl_radius_ipaddr: 1,
771 _wl_radius_port: 1,
772 _wl_wep_bit: 1,
773 _wl_passphrase: 1,
774 _f_wl_wep_gen: 1,
775 _f_wl_wep_random: 1,
776 _wl_key1: 1,
777 _wl_key2: 1,
778 _wl_key3: 1,
779 _wl_key4: 1,
781 _f_wl_lazywds: 1,
782 _f_wl_wds_0: 1
784 wl_vis.push(a);
788 var wan = E('_wan_proto').value;
790 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
791 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
792 if (wl_sunit(uidx)<0) {
793 wmode = E('_f_wl'+wl_unit(uidx)+'_mode').value;
795 if (wmode == 'wet') {
796 wan = 'disabled';
797 vis._wan_proto = 0;
798 /* NOVLAN-BEGIN */
799 vis._f_dhcpd_enable = 0;
800 vis._dhcp_lease = 0;
801 /* NOVLAN-END */
804 if ((wan == 'disabled') || (wmode == 'sta') || (wmode == 'wet')) {
805 vis._f_wan_islan = 1;
810 switch (wan) {
811 case 'disabled':
812 vis._ppp_username = 0;
813 vis._ppp_service = 0;
814 vis._ppp_custom = 0;
815 vis._l2tp_server_ip = 0;
816 vis._wan_ipaddr = 0;
817 vis._wan_netmask = 0;
818 vis._wan_gateway = 0;
819 vis._pptp_server_ip = 0;
820 vis._f_pptp_dhcp = 0;
821 vis._ppp_demand = 0;
822 vis._mtu_enable = 0;
823 vis._f_wan_mtu = 0;
824 vis._f_ppp_mlppp = 0;
825 vis._modem_ipaddr = 0;
826 vis._modem_pin = 0;
827 vis._modem_dev = 0;
828 vis._modem_init = 0;
829 vis._modem_apn = 0;
830 break;
831 case 'dhcp':
832 vis._l2tp_server_ip = 0;
833 vis._ppp_demand = 0;
834 vis._ppp_service = 0;
835 vis._ppp_username = 0;
836 vis._ppp_custom = 0;
837 vis._pptp_server_ip = 0;
838 vis._f_pptp_dhcp = 0;
839 vis._wan_gateway = 0;
840 vis._wan_ipaddr = 0;
841 vis._wan_netmask = 0;
842 vis._f_ppp_mlppp = 0;
843 vis._modem_ipaddr = 1;
845 vis._lan_gateway = 0;
846 vis._modem_pin = 0;
847 vis._modem_dev = 0;
848 vis._modem_init = 0;
849 vis._modem_apn = 0;
850 break;
851 case 'pppoe':
852 vis._l2tp_server_ip = 0;
853 vis._pptp_server_ip = 0;
854 vis._f_pptp_dhcp = 0;
855 vis._wan_gateway = 0;
856 vis._wan_ipaddr = 0;
857 vis._wan_netmask = 0;
858 vis._modem_ipaddr = 1;
860 vis._lan_gateway = 0;
861 vis._modem_pin = 0;
862 vis._modem_dev = 0;
863 vis._modem_init = 0;
864 vis._modem_apn = 0;
865 break;
866 case 'ppp3g':
867 vis._ppp_service = 0;
868 vis._l2tp_server_ip = 0;
869 vis._pptp_server_ip = 0;
870 vis._f_pptp_dhcp = 0;
871 vis._wan_gateway = 0;
872 vis._wan_ipaddr = 0;
873 vis._wan_netmask = 0;
874 vis._lan_gateway = 0;
875 vis._modem_ipaddr = 0;
876 vis._f_ppp_mlppp = 0;
877 break;
878 case 'static':
879 vis._l2tp_server_ip = 0;
880 vis._ppp_demand = 0;
881 vis._ppp_service = 0;
882 vis._ppp_username = 0;
883 vis._ppp_custom = 0;
884 vis._pptp_server_ip = 0;
885 vis._f_pptp_dhcp = 0;
886 vis._f_ppp_mlppp = 0;
887 vis._modem_ipaddr = 1;
889 vis._lan_gateway = 0;
890 vis._modem_pin = 0;
891 vis._modem_dev = 0;
892 vis._modem_init = 0;
893 vis._modem_apn = 0;
894 break;
895 case 'pptp':
896 vis._l2tp_server_ip = 0;
897 vis._ppp_service = 0;
898 vis._wan_gateway = (!E('_f_pptp_dhcp').checked);
899 vis._wan_ipaddr = (!E('_f_pptp_dhcp').checked);
900 vis._modem_ipaddr = 0;
902 vis._lan_gateway = 0;
903 vis._modem_pin = 0;
904 vis._modem_dev = 0;
905 vis._modem_init = 0;
906 vis._modem_apn = 0;
907 break;
908 case 'l2tp':
909 vis._pptp_server_ip = 0;
910 vis._ppp_service = 0;
911 vis._wan_gateway = (!E('_f_pptp_dhcp').checked);
912 vis._wan_ipaddr = (!E('_f_pptp_dhcp').checked);
913 vis._modem_ipaddr = 0;
915 vis._lan_gateway = 0;
916 vis._modem_pin = 0;
917 vis._modem_dev = 0;
918 vis._modem_init = 0;
919 vis._modem_apn = 0;
920 break;
923 vis._ppp_idletime = (E('_ppp_demand').value == 1) && vis._ppp_demand
924 vis._ppp_redialperiod = !vis._ppp_idletime && vis._ppp_demand;
926 if (vis._mtu_enable) {
927 if (E('_mtu_enable').value == 0) {
928 vis._f_wan_mtu = 2;
929 a = E('_f_wan_mtu');
930 switch (E('_wan_proto').value) {
931 case 'pppoe':
932 a.value = 1492;
933 break;
934 case 'pptp':
935 case 'l2tp':
936 a.value = 1460;
937 break;
938 default:
939 a.value = 1500;
940 break;
945 /* NOVLAN-BEGIN */
946 if (!E('_f_dhcpd_enable').checked) vis._dhcp_lease = 0;
947 /* NOVLAN-END */
949 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
950 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
951 if (wl_sunit(uidx)<0) {
952 u = wl_unit(uidx);
953 wmode = E('_f_wl'+u+'_mode').value;
955 if (!E('_f_wl'+u+'_radio').checked) {
956 for (a in wl_vis[uidx]) {
957 wl_vis[uidx][a] = 2;
959 wl_vis[uidx]._f_wl_radio = 1;
960 wl_vis[uidx]._wl_nbw_cap = nphy ? 2 : 0;
961 wl_vis[uidx]._f_wl_nband = (bands[uidx].length > 1) ? 2 : 0;
964 switch (wmode) {
965 case 'apwds':
966 case 'wds':
967 break;
968 case 'wet':
969 case 'sta':
970 wl_vis[uidx]._f_wl_bcast = 0;
971 wl_vis[uidx]._wl_channel = 0;
972 wl_vis[uidx]._wl_nbw_cap = 0;
973 vis._modem_ipaddr = 0;
974 default:
975 wl_vis[uidx]._f_wl_lazywds = 0;
976 wl_vis[uidx]._f_wl_wds_0 = 0;
977 break;
980 sm2 = E('_wl'+u+'_security_mode').value;
981 switch (sm2) {
982 case 'disabled':
983 wl_vis[uidx]._wl_crypto = 0;
984 wl_vis[uidx]._wl_wep_bit = 0;
985 wl_vis[uidx]._wl_wpa_psk = 0;
986 wl_vis[uidx]._wl_radius_key = 0;
987 wl_vis[uidx]._wl_radius_ipaddr = 0;
988 wl_vis[uidx]._wl_wpa_gtk_rekey = 0;
989 break;
990 case 'wep':
991 wl_vis[uidx]._wl_crypto = 0;
992 wl_vis[uidx]._wl_wpa_psk = 0;
993 wl_vis[uidx]._wl_radius_key = 0;
994 wl_vis[uidx]._wl_radius_ipaddr = 0;
995 wl_vis[uidx]._wl_wpa_gtk_rekey = 0;
996 break;
997 case 'radius':
998 wl_vis[uidx]._wl_crypto = 0;
999 wl_vis[uidx]._wl_wpa_psk = 0;
1000 break;
1001 default: // wpa*
1002 wl_vis[uidx]._wl_wep_bit = 0;
1003 if (sm2.indexOf('personal') != -1) {
1004 wl_vis[uidx]._wl_radius_key = 0;
1005 wl_vis[uidx]._wl_radius_ipaddr = 0;
1007 else {
1008 wl_vis[uidx]._wl_wpa_psk = 0;
1010 break;
1013 if ((E('_f_wl'+u+'_lazywds').value == 1) && (wl_vis[uidx]._f_wl_wds_0 == 1)) {
1014 wl_vis[uidx]._f_wl_wds_0 = 2;
1017 if (wl_vis[uidx]._wl_nbw_cap != 0) {
1018 switch (E('_wl'+u+'_net_mode').value) {
1019 case 'b-only':
1020 case 'g-only':
1021 case 'a-only':
1022 case 'bg-mixed':
1023 wl_vis[uidx]._wl_nbw_cap = 2;
1024 if (E('_wl'+u+'_nbw_cap').value != '0') {
1025 E('_wl'+u+'_nbw_cap').value = 0;
1026 refreshChannels(uidx);
1028 break;
1030 // avoid Enterprise-TKIP with 40MHz
1031 if ((sm2 == 'wpa_enterprise') && (E('_wl'+u+'_crypto').value == 'tkip')) {
1032 wl_vis[uidx]._wl_nbw_cap = 2;
1033 if (E('_wl'+u+'_nbw_cap').value != '0') {
1034 E('_wl'+u+'_nbw_cap').value = 0;
1035 refreshChannels(uidx);
1040 wl_vis[uidx]._f_wl_nctrlsb = (E('_wl'+u+'_nbw_cap').value == 0) ? 0 : wl_vis[uidx]._wl_nbw_cap;
1042 /* REMOVE-BEGIN
1043 This is ugly...
1044 Special case - 2.4GHz band, currently running in B/G-only mode,
1045 with N/Auto and 40MHz selected in the GUI.
1046 Channel list is not filtered in this case by the wl driver,
1047 and includes all channels available with 20MHz channel width.
1048 REMOVE-END */
1049 b = selectedBand(uidx);
1050 if (wl_vis[uidx]._wl_channel == 1 && wl_vis[uidx]._f_wl_nctrlsb != 0 &&
1051 ((b == '2') || (wl_vis[uidx]._f_wl_nband == 0 && b == '0'))) {
1052 switch (eval('nvram.wl'+u+'_net_mode')) {
1053 case 'b-only':
1054 case 'g-only':
1055 case 'bg-mixed':
1056 i = E('_wl'+u+'_channel').value * 1;
1057 if (i > 0 && i < 5) {
1058 E('_f_wl'+u+'_nctrlsb').value = 'lower';
1059 wl_vis[uidx]._f_wl_nctrlsb = 2;
1061 else if (i > max_channel[uidx] - 4) {
1062 E('_f_wl'+u+'_nctrlsb').value = 'upper';
1063 wl_vis[uidx]._f_wl_nctrlsb = 2;
1065 break;
1069 wl_vis[uidx]._f_wl_scan = wl_vis[uidx]._wl_channel;
1070 wl_vis[uidx]._f_wl_psk_random1 = wl_vis[uidx]._wl_wpa_psk;
1071 wl_vis[uidx]._f_wl_psk_random2 = wl_vis[uidx]._wl_radius_key;
1072 wl_vis[uidx]._wl_radius_port = wl_vis[uidx]._wl_radius_ipaddr;
1073 wl_vis[uidx]._wl_key1 = wl_vis[uidx]._wl_key2 = wl_vis[uidx]._wl_key3 = wl_vis[uidx]._wl_key4 = wl_vis[uidx]._f_wl_wep_gen = wl_vis[uidx]._f_wl_wep_random = wl_vis[uidx]._wl_passphrase = wl_vis[uidx]._wl_wep_bit;
1075 for (i = 1; i < 10; ++i) {
1076 wl_vis[uidx]['_f_wl_wds_' + i] = wl_vis[uidx]._f_wl_wds_0;
1079 } // for each wl_iface
1081 vis._ppp_passwd = vis._ppp_username;
1082 /* NOVLAN-BEGIN */
1083 vis._dhcpd_startip = vis._dhcpd_endip = vis._wan_wins = vis._dhcp_lease;
1084 /* NOVLAN-END */
1086 for (a in vis) {
1087 b = E(a);
1088 c = vis[a];
1089 /* REMOVE-BEGIN
1090 // if (b != null)
1091 REMOVE-END */
1092 b.disabled = (c != 1);
1093 PR(b).style.display = c ? '' : 'none';
1096 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1097 if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1098 for (a in wl_vis[uidx]) {
1099 i = 3;
1100 if (a.substr(0, 6) == '_f_wl_') i = 5;
1101 b = E(a.substr(0, i) + wl_unit(uidx) + a.substr(i, a.length));
1102 c = wl_vis[uidx][a];
1103 b.disabled = (c != 1);
1104 PR(b).style.display = c ? '' : 'none';
1109 // --- verify ---
1111 ferror.clear('_wan_proto');
1113 var wlclnt = 0;
1114 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1115 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1116 if (wl_sunit(uidx)<0) {
1117 u = wl_unit(uidx);
1118 wmode = E('_f_wl'+u+'_mode').value;
1119 sm2 = E('_wl'+u+'_security_mode').value;
1121 /* REMOVE-BEGIN
1122 if ((wl_vis[uidx]._f_wl_mode == 1) && (wmode != 'ap') && (sm2.substr(0, 4) == 'wpa2')) {
1123 ferror.set('_wl'+u+'_security_mode', 'WPA2 is supported only in AP mode.', quiet || !ok);
1124 ok = 0;
1126 else ferror.clear('_wl'+u+'_security_mode');
1127 REMOVE-END */
1129 // --- N standard does not support WPA+TKIP ---
1130 a = E('_wl'+u+'_crypto');
1131 switch (E('_wl'+u+'_net_mode').value) {
1132 case 'mixed':
1133 case 'n-only':
1134 if (nphy && (a.value == 'tkip') && (sm2.indexOf('wpa') != -1)) {
1135 ferror.set(a, 'TKIP encryption is not supported with WPA / WPA2 in N mode.', quiet || !ok);
1136 ok = 0;
1138 else ferror.clear(a);
1139 break;
1142 a = E('_wl'+u+'_net_mode');
1143 ferror.clear(a);
1144 b = E('_f_wl'+u+'_mode');
1145 ferror.clear(b);
1146 if ((wmode == 'sta') || (wmode == 'wet')) {
1147 ++wlclnt;
1148 if (wlclnt > 1) {
1149 ferror.set(b, 'Only one wireless interface can be configured in client mode.', quiet || !ok);
1150 ok = 0;
1152 else if (a.value == 'n-only') {
1153 ferror.set(a, 'N-only is not supported in wireless client modes, use Auto.', quiet || !ok);
1154 ok = 0;
1158 a = E('_wl'+u+'_wpa_psk');
1159 ferror.clear(a);
1160 if (wl_vis[uidx]._wl_wpa_psk == 1) {
1161 if ((a.value.length < 8) || ((a.value.length == 64) && (a.value.search(/[^0-9A-Fa-f]/) != -1))) {
1162 ferror.set('_wl'+u+'_wpa_psk', 'Invalid pre-shared key. Please enter at least 8 characters or 64 hexadecimal digits.', quiet || !ok);
1163 ok = 0;
1167 // wl channel
1168 if (((wmode == 'wds') || (wmode == 'apwds')) && (wl_vis[uidx]._wl_channel == 1) && (E('_wl'+u+'_channel').value == '0')) {
1169 ferror.set('_wl'+u+'_channel', 'Fixed wireless channel required in WDS mode.', quiet || !ok);
1170 ok = 0;
1172 else ferror.clear('_wl'+u+'_channel');
1174 if (E('_f_wl'+u+'_mode').value == 'sta') {
1175 if (((wan == 'disabled') || (wan == 'ppp3g')) && (E('_f_wl'+u+'_radio').checked)) {
1176 ferror.set('_wan_proto', 'Wireless Client mode requires a valid WAN setting (usually DHCP).', quiet || !ok);
1177 ok = 0;
1183 // domain name or IP address
1184 a = ['_l2tp_server_ip', '_pptp_server_ip'];
1185 for (i = a.length - 1; i >= 0; --i)
1186 if ((vis[a[i]]) && ((!v_length(a[i], 1, 1)) || ((!v_ip(a[i], 1)) && (!v_domain(a[i], 1))))) {
1187 if (!quiet && ok) ferror.show(a[i]);
1188 ok = 0;
1191 // IP address
1192 /* NOVLAN-BEGIN */
1193 a = ['_wan_gateway','_wan_ipaddr','_lan_ipaddr', '_dhcpd_startip', '_dhcpd_endip'];
1194 /* NOVLAN-END */
1195 /* VLAN-BEGIN */
1196 a = ['_wan_gateway','_wan_ipaddr'];
1197 /* VLAN-END */
1198 for (i = a.length - 1; i >= 0; --i)
1199 if ((vis[a[i]]) && (!v_ip(a[i], quiet || !ok))) ok = 0;
1201 // IP address, blank -> 0.0.0.0
1202 a = ['_f_dns_1', '_f_dns_2', '_f_dns_3','_wan_wins','_lan_gateway', '_modem_ipaddr'];
1203 for (i = a.length - 1; i >= 0; --i)
1204 if ((vis[a[i]]) && (!v_dns(a[i], quiet || !ok))) ok = 0;
1206 // netmask
1207 /* NOVLAN-BEGIN */
1208 a = ['_wan_netmask','_lan_netmask'];
1209 /* NOVLAN-END */
1210 /* VLAN-BEGIN */
1211 a = ['_wan_netmask'];
1212 /* VLAN-END */
1213 for (i = a.length - 1; i >= 0; --i)
1214 if ((vis[a[i]]) && (!v_netmask(a[i], quiet || !ok))) ok = 0;
1216 // range
1217 /* NOVLAN-BEGIN */
1218 a = [['_ppp_idletime', 3, 1440],['_ppp_redialperiod', 1, 86400],['_f_wan_mtu', 576, 1500],
1219 ['_dhcp_lease', 1, 10080]];
1220 /* NOVLAN-END */
1221 /* VLAN-BEGIN */
1222 a = [['_ppp_idletime', 3, 1440],['_ppp_redialperiod', 1, 86400],['_f_wan_mtu', 576, 1500]];
1223 /* VLAN-END */
1224 for (i = a.length - 1; i >= 0; --i) {
1225 v = a[i];
1226 if ((vis[v[0]]) && (!v_range(v[0], quiet || !ok, v[1], v[2]))) ok = 0;
1229 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1230 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1231 if (wl_sunit(uidx)<0) {
1232 u = wl_unit(uidx);
1234 // IP address
1235 a = ['_radius_ipaddr'];
1236 for (i = a.length - 1; i >= 0; --i) {
1237 if ((wl_vis[uidx]['_wl'+a[i]]) && (!v_ip('_wl'+u+a[i], quiet || !ok))) ok = 0;
1240 // range
1241 a = [['_wpa_gtk_rekey', 60, 7200], ['_radius_port', 1, 65535]];
1242 for (i = a.length - 1; i >= 0; --i) {
1243 v = a[i];
1244 if ((wl_vis[uidx]['_wl'+v[0]]) && (!v_range('_wl'+u+v[0], quiet || !ok, v[1], v[2]))) ok = 0;
1247 // length
1248 a = [['_ssid', 1], ['_radius_key', 1]];
1249 for (i = a.length - 1; i >= 0; --i) {
1250 v = a[i];
1251 if ((wl_vis[uidx]['_wl'+v[0]]) && (!v_length('_wl'+u+v[0], quiet || !ok, v[1], E('_wl'+u+v[0]).maxlength))) ok = 0;
1254 if (wl_vis[uidx]._wl_key1) {
1255 a = (E('_wl'+u+'_wep_bit').value == 128) ? 26 : 10;
1256 for (i = 1; i <= 4; ++i) {
1257 b = E('_wl'+u+'_key' + i);
1258 b.maxLength = a;
1259 if ((b.value.length > 0) || (E('_f_wl'+u+'_wepidx_' + i).checked)) {
1260 if (!v_wep(b, quiet || !ok)) ok = 0;
1262 else ferror.clear(b);
1266 ferror.clear('_f_wl'+u+'_wds_0');
1267 if (wl_vis[uidx]._f_wl_wds_0 == 1) {
1268 b = 0;
1269 for (i = 0; i < 10; ++i) {
1270 a = E('_f_wl'+u+'_wds_' + i);
1271 if (!v_macz(a, quiet || !ok)) ok = 0;
1272 else if (!isMAC0(a.value)) b = 1;
1274 if (!b) {
1275 ferror.set('_f_wl'+u+'_wds_0', 'WDS MAC address required.', quiet || !ok);
1276 ok = 0;
1282 /* NOVLAN-BEGIN */
1283 a = E('_dhcpd_startip');
1284 b = E('_dhcpd_endip');
1285 ferror.clear(a);
1286 ferror.clear(b);
1288 if ((vis._dhcp_lease) && (!a._error_msg) && (!b._error_msg)) {
1289 c = aton(E('_lan_netmask').value);
1290 d = aton(E('_lan_ipaddr').value) & c;
1291 e = 'Invalid IP address or subnet mask';
1292 if ((aton(a.value) & c) != d) {
1293 ferror.set(a, e, quiet || !ok);
1294 ok = 0;
1296 if ((aton(b.value) & c) != d) {
1297 ferror.set(b, e, quiet || !ok);
1298 ok = 0;
1302 if ((vis._dhcp_lease) && (!a._error_msg) && (!b._error_msg)) {
1303 if (aton(a.value) > aton(b.value)) {
1304 c = a.value;
1305 a.value = b.value;
1306 b.value = c;
1309 elem.setInnerHTML('dhcp_count', '(' + ((aton(b.value) - aton(a.value)) + 1) + ')');
1312 /* REMOVE-BEGIN */
1313 /* TODO: same validation for builds with VLAN-GUI enabled */
1314 /* REMOVE-END */
1315 ferror.clear('_modem_ipaddr');
1316 a = E('_modem_ipaddr');
1317 b = E('_lan_ipaddr');
1318 c = E('_lan_netmask');
1319 if ( vis['_modem_ipaddr'] && !(a._error_msg || b._error_msg || c._error_msg) && a.value != "0.0.0.0" ) {
1320 c = aton(c.value);
1321 if ( (aton(a.value) & c) == (aton(b.value) & c) ) {
1322 ferror.set('_modem_ipaddr', 'Modem IP address may not be within your local address space.', quiet);
1323 ok = 0;
1326 /* NOVLAN-END */
1328 return ok;
1331 function earlyInit()
1333 verifyFields(null, 1);
1336 function save()
1338 /* VLAN-BEGIN */
1339 if (lg.isEditing()) return;
1340 lg.resetNewEditor();
1341 /* VLAN-END */
1343 var a, b, c;
1344 var i;
1345 var u, uidx, wmode, sm2, wradio;
1347 if (!verifyFields(null, false)) return;
1349 var fom = E('_fom');
1351 fom.wan_mtu.value = fom.f_wan_mtu.value;
1352 fom.wan_mtu.disabled = fom.f_wan_mtu.disabled;
1354 /* NOVLAN-BEGIN */
1355 fom.lan_proto.value = fom.f_dhcpd_enable.checked ? 'dhcp' : 'static';
1356 /* NOVLAN-END */
1358 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1359 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1360 if (wl_sunit(uidx)<0) {
1361 u = wl_unit(uidx);
1362 wmode = E('_f_wl'+u+'_mode').value;
1363 sm2 = E('_wl'+u+'_security_mode').value;
1364 wradio = E('_f_wl'+u+'_radio').checked;
1366 E('_wl'+u+'_nband').value = selectedBand(uidx);
1368 if (wmode == 'apwds') E('_wl'+u+'_mode').value = 'ap';
1369 else E('_wl'+u+'_mode').value = wmode;
1371 if (wmode == 'wet') {
1372 fom.wan_proto.value = 'disabled';
1373 fom.wan_proto.disabled = 0;
1374 /* NOVLAN-BEGIN */
1375 fom.lan_proto.value = 'static';
1376 /* NOVLAN-END */
1377 /* VLAN-BEGIN */
1378 /* REMOVE-BEGIN */
1379 // TODO - what's required ? integrate with tomatogrid?
1380 /* REMOVE-END */
1381 /* VLAN-END */
1384 a = [];
1385 for (i = 0; i < 10; ++i) a.push(E('_f_wl'+u+'_wds_' + i).value);
1386 E('_wl'+u+'_wds').value = joinAddr(a);
1388 if (wmode.indexOf('wds') != -1) {
1389 E('_wl'+u+'_wds_enable').value = 1;
1390 E('_wl'+u+'_lazywds').value = E('_f_wl'+u+'_lazywds').value;
1391 if (E('_wl'+u+'_lazywds').value == 1) E('_wl'+u+'_wds').value = '';
1393 else {
1394 E('_wl'+u+'_wds_enable').value = 0;
1395 E('_wl'+u+'_wds').value = '';
1396 E('_wl'+u+'_lazywds').value = 0;
1399 E('_wl'+u+'_radio').value = wradio ? 1 : 0;
1400 E('_wl'+u+'_auth').value = eval('nvram.wl'+u+'_auth');
1402 e = E('_wl'+u+'_akm');
1403 switch (sm2) {
1404 case 'disabled':
1405 case 'radius':
1406 case 'wep':
1407 e.value = '';
1408 break;
1409 default:
1410 c = [];
1412 if (sm2.indexOf('personal') != -1) {
1413 if (sm2.indexOf('wpa2_') == -1) c.push('psk');
1414 if (sm2.indexOf('wpa_') == -1) c.push('psk2');
1416 else {
1417 if (sm2.indexOf('wpa2_') == -1) c.push('wpa');
1418 if (sm2.indexOf('wpa_') == -1) c.push('wpa2');
1420 c = c.join(' ');
1421 e.value = c;
1422 break;
1424 E('_wl'+u+'_auth_mode').value = (sm2 == 'radius') ? 'radius' : 'none';
1425 E('_wl'+u+'_wep').value = ((sm2 == 'radius') || (sm2 == 'wep')) ? 'enabled': 'disabled';
1427 if (sm2.indexOf('wpa') != -1) E('_wl'+u+'_auth').value = 0;
1429 E('_wl'+u+'_nreqd').value = 0;
1430 E('_wl'+u+'_gmode').value = 1;
1431 E('_wl'+u+'_nmode').value = 0;
1432 E('_wl'+u+'_nmcsidx').value = -2; // Legacy Rate
1433 E('_wl'+u+'_nbw').value = 0;
1434 switch (E('_wl'+u+'_net_mode').value) {
1435 case 'b-only':
1436 E('_wl'+u+'_gmode').value = 0;
1437 break;
1438 case 'g-only':
1439 E('_wl'+u+'_gmode').value = 4;
1440 break;
1441 case 'bg-mixed':
1442 break;
1443 case 'a-only':
1444 E('_wl'+u+'_nmcsidx').value = -1; // Auto
1445 break;
1446 case 'n-only':
1447 if (selectedBand(uidx) == '1') { // 5 GHz
1448 E('_wl'+u+'_nmode').value = -1;
1449 E('_wl'+u+'_nmcsidx').value = -1;
1450 } else {
1451 E('_wl'+u+'_nmode').value = 1;
1452 E('_wl'+u+'_nmcsidx').value = 32;
1454 E('_wl'+u+'_nreqd').value = 1;
1455 break;
1456 default: // Auto
1457 E('_wl'+u+'_nmode').value = -1;
1458 E('_wl'+u+'_nmcsidx').value = -1;
1459 break;
1462 E('_wl'+u+'_nctrlsb').value = eval('nvram.wl'+u+'_nctrlsb');
1463 if (E('_wl'+u+'_nmode').value != 0) {
1464 E('_wl'+u+'_nctrlsb').value = E('_f_wl'+u+'_nctrlsb').value;
1465 E('_wl'+u+'_nbw').value = (E('_wl'+u+'_nbw_cap').value == 0) ? 20 : 40;
1468 E('_wl'+u+'_closed').value = E('_f_wl'+u+'_bcast').checked ? 0 : 1;
1470 a = fields.radio.selected(eval('fom.f_wl'+u+'_wepidx'));
1471 if (a) E('_wl'+u+'_key').value = a.value;
1475 fom.wan_islan.value = fom.f_wan_islan.checked ? 1 : 0;
1476 fom.pptp_dhcp.value = fom.f_pptp_dhcp.checked ? 1 : 0;
1478 fom.wan_dns.value = joinAddr([fom.f_dns_1.value, fom.f_dns_2.value, fom.f_dns_3.value]);
1480 /* VLAN-BEGIN */
1481 // initialize/wipe out relevant fields
1482 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
1483 var j = (i == 0) ? '' : i.toString();
1484 fom['lan' + j + '_ifname'].value = '';
1485 fom['lan' + j + '_ipaddr'].value = '';
1486 fom['lan' + j + '_netmask'].value = '';
1487 fom['lan' + j + '_proto'].value = '';
1488 fom['lan' + j + '_stp'].value = '';
1489 fom['dhcp' + j + '_start'].value = '';
1490 fom['dhcp' + j + '_num'].value = '';
1491 fom['dhcp' + j + '_lease'].value = '';
1492 fom['dhcpd' + j + '_startip'].value = '';
1493 fom['dhcpd' + j + '_endip'].value = '';
1496 var d = lg.getAllData();
1497 for (var i = 0; i < d.length; ++i) {
1499 if (lg.countOverlappingNetworks(d[i][2]) > 1) {
1500 var s = 'Cannot proceed: two or more LAN bridges have conflicting IP addresses or overlapping subnets';
1501 alert(s);
1502 var e = E('footer-msg');
1503 e.innerHTML = s;
1504 e.style.visibility = 'visible';
1505 setTimeout(
1506 function() {
1507 e.innerHTML = '';
1508 e.style.visibility = 'hidden';
1509 }, 5000);
1510 return;
1513 var j = (parseInt(d[i][0]) == 0) ? '' : d[i][0].toString();
1514 fom['lan' + j + '_ifname'].value = 'br' + d[i][0];
1515 fom['lan' + j + '_stp'].value = d[i][1];
1516 fom['lan' + j + '_ipaddr'].value = d[i][2];
1517 fom['lan' + j + '_netmask'].value = d[i][3];
1518 fom['lan' + j + '_proto'].value = (d[i][4] != '0') ? 'dhcp' : 'static';
1519 fom['dhcp' + j + '_start'].value = (d[i][4] != '0') ? (d[i][5]).split('.').splice(3, 1) : '';
1520 fom['dhcp' + j + '_num'].value = (d[i][4] != '0') ? d[i][6].split('.').splice(3, 1) - (d[i][5]).split('.').splice(3, 1) + 1 : ''; // presuming /24 subnet (legacy)
1521 fom['dhcp' + j + '_lease'].value = (d[i][4] != '0') ? d[i][7] : '';
1522 fom['dhcpd' + j + '_startip'].value = (d[i][4] != '0') ? d[i][5] : '';
1523 fom['dhcpd' + j + '_endip'].value = (d[i][4] != '0') ? d[i][6] : '';
1525 /* REMOVE-BEGIN */
1526 alert('lan' + j + '_ifname=' + fom['lan' + j + '_ifname'].value + '\n' +
1527 'lan' + j + '_stp=' + fom['lan' + j + '_stp'].value + '\n' +
1528 'lan' + j + '_ipaddr=' + fom['lan' + j + '_ipaddr'].value + '\n' +
1529 'lan' + j + '_netmask=' + fom['lan' + j + '_netmask'].value + '\n' +
1530 'lan' + j + '_proto=' + fom['lan' + j + '_proto'].value + '\n' +
1531 'dhcp' + j + '_start=' + fom['dhcp' + j + '_start'].value + '\n' +
1532 'dhcp' + j + '_num=' + fom['dhcp' + j + '_num'].value + '\n' +
1533 'dhcp' + j + '_lease=' + fom['dhcp' + j + '_lease'].value + '\n' +
1534 'dhcpd' + j + '_startip=' + fom['dhcpd' + j + '_startip'].value + '\n' +
1535 'dhcpd' + j + '_endip=' + fom['dhcpd' + j + '_endip'].value);
1536 /* REMOVE-END */
1539 var e = E('footer-msg');
1540 var t = fixIP(fom['lan_ipaddr'].value);
1541 if ((fom['lan_ifname'].value != 'br0') || (fom['lan_ipaddr'].value == '0.0.0.0') || (!t)) {
1542 e.innerHTML = 'Bridge br0 must be always defined and have a valid IP address set.';
1543 e.style.visibility = 'visible';
1544 setTimeout(
1545 function() {
1546 e.innerHTML = '';
1547 e.style.visibility = 'hidden';
1548 }, 5000);
1549 return;
1551 /* VLAN-END */
1553 /* REMOVE-BEGIN
1554 // if ((nvram.lan_ipaddr != fom.lan_ipaddr.value) || (nvram.lan1_ipaddr != fom.lan1_ipaddr.value) ||
1555 // (nvram.lan2_ipaddr != fom.lan2_ipaddr.value) || (nvram.lan3_ipaddr != fom.lan3_ipaddr.value)){
1556 REMOVE-END */
1558 fom.ppp_mlppp.value = fom.f_ppp_mlppp.checked ? 1 : 0;
1560 if (nvram.lan_ipaddr != fom.lan_ipaddr.value) {
1561 fom._moveip.value = 1;
1562 form.submit(fom);
1564 else {
1565 form.submit(fom, 1);
1569 function init()
1571 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1572 // if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1573 if (wl_sunit(uidx)<0) {
1574 refreshNetModes(uidx);
1575 refreshChannels(uidx);
1579 </script>
1581 </head>
1582 <body onload='init()'>
1583 <form id='_fom' method='post' action='tomato.cgi'>
1584 <table id='container' cellspacing=0>
1585 <tr><td colspan=2 id='header'>
1586 <div class='title'>Tomato</div>
1587 <div class='version'>Version <% version(); %></div>
1588 </td></tr>
1589 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
1590 <td id='content'>
1591 <div id='ident'><% ident(); %></div>
1593 <!-- / / / -->
1595 <input type='hidden' name='_nextpage' value='basic-network.asp'>
1596 <input type='hidden' name='_nextwait' value='10'>
1597 <input type='hidden' name='_service' value='*'>
1598 <input type='hidden' name='_moveip' value='0'>
1600 <input type='hidden' name='wan_mtu'>
1601 <input type='hidden' name='wan_islan'>
1602 <input type='hidden' name='pptp_dhcp'>
1603 <!-- NOVLAN-BEGIN -->
1604 <input type='hidden' name='lan_proto'>
1605 <!-- NOVLAN-END -->
1606 <input type='hidden' name='wan_dns'>
1607 <input type='hidden' name='ppp_mlppp'>
1609 <!-- VLAN-BEGIN -->
1610 <script type='text/javascript'>
1612 for (var i = 0 ; i <= MAX_BRIDGE_ID ; i++) {
1613 var j = (i == 0) ? '' : i.toString();
1614 W('<input type=\'hidden\' id=\'lan' + j + '_ifname\' name=\'lan' + j + '_ifname\'>');
1615 W('<input type=\'hidden\' id=\'lan' + j + '_ipaddr\' name=\'lan' + j + '_ipaddr\'>');
1616 W('<input type=\'hidden\' id=\'lan' + j + '_netmask\' name=\'lan' + j + '_netmask\'>');
1617 W('<input type=\'hidden\' id=\'lan' + j + '_proto\' name=\'lan' + j + '_proto\'>');
1618 W('<input type=\'hidden\' id=\'lan' + j + '_stp\' name=\'lan' + j + '_stp\'>');
1619 W('<input type=\'hidden\' id=\'dhcp' + j + '_start\' name=\'dhcp' + j + '_start\'>');
1620 W('<input type=\'hidden\' id=\'dhcp' + j + '_num\' name=\'dhcp' + j + '_num\'>');
1621 W('<input type=\'hidden\' id=\'dhcp' + j + '_lease\' name=\'dhcp' + j + '_lease\'>');
1622 W('<input type=\'hidden\' id=\'dhcpd' + j + '_startip\' name=\'dhcpd' + j + '_startip\'>');
1623 W('<input type=\'hidden\' id=\'dhcpd' + j + '_endip\' name=\'dhcpd' + j + '_endip\'>');
1625 </script>
1626 <!-- VLAN-END -->
1628 <div class='section-title'>WAN / Internet</div>
1629 <div class='section'>
1630 <script type='text/javascript'>
1631 createFieldTable('', [
1632 { title: 'Type', name: 'wan_proto', type: 'select', options: [['dhcp','DHCP'],['pppoe','PPPoE'],['static','Static'],['pptp','PPTP'],['l2tp','L2TP'],
1633 /* LINUX26-BEGIN */
1634 /* USB-BEGIN */
1635 ['ppp3g','3G Modem'],
1636 /* USB-END */
1637 /* LINUX26-END */
1638 ['disabled','Disabled']],
1639 value: nvram.wan_proto },
1640 { title: 'Modem device', name: 'modem_dev', type: 'select', options: [['ttyUSB0', '/dev/ttyUSB0'],['ttyUSB1', '/dev/ttyUSB1'],['ttyUSB2', '/dev/ttyUSB2'],['ttyUSB3', '/dev/ttyUSB3'],['ttyACM0', '/dev/ttyACM0']], value: nvram.modem_dev },
1641 { title: 'PIN Code', name: 'modem_pin', type: 'text', maxlen: 6, size: 8, value: nvram.modem_pin },
1642 { title: 'Modem init string', name: 'modem_init', type: 'text', maxlen: 25, size: 32, value: nvram.modem_init },
1643 { title: 'APN', name: 'modem_apn', type: 'text', maxlen: 25, size: 32, value: nvram.modem_apn },
1644 { title: 'Username', name: 'ppp_username', type: 'text', maxlen: 60, size: 64, value: nvram.ppp_username },
1645 { title: 'Password', name: 'ppp_passwd', type: 'password', maxlen: 60, size: 64, peekaboo: 1, value: nvram.ppp_passwd },
1646 { title: 'Service Name', name: 'ppp_service', type: 'text', maxlen: 50, size: 64, value: nvram.ppp_service },
1647 { title: 'L2TP Server', name: 'l2tp_server_ip', type: 'text', maxlen: 128, size: 64, value: nvram.l2tp_server_ip },
1648 { title: 'Use DHCP', name: 'f_pptp_dhcp', type: 'checkbox', value: (nvram.pptp_dhcp == 1) },
1649 { title: 'IP Address', name: 'wan_ipaddr', type: 'text', maxlen: 15, size: 17, value: nvram.wan_ipaddr },
1650 { title: 'Subnet Mask', name: 'wan_netmask', type: 'text', maxlen: 15, size: 17, value: nvram.wan_netmask },
1651 { title: 'Gateway', name: 'wan_gateway', type: 'text', maxlen: 15, size: 17, value: nvram.wan_gateway },
1652 { title: 'PPTP Gateway', name: 'pptp_server_ip', type: 'text', maxlen: 128, size: 64, value: nvram.pptp_server_ip },
1653 { title: 'Options', name: 'ppp_custom', type: 'text', maxlen: 256, size: 64, value: nvram.ppp_custom },
1654 { title: 'Connect Mode', name: 'ppp_demand', type: 'select', options: [['1', 'Connect On Demand'],['0', 'Keep Alive']],
1655 value: nvram.ppp_demand },
1656 { title: 'Max Idle Time', indent: 2, name: 'ppp_idletime', type: 'text', maxlen: 5, size: 7, suffix: ' <i>(minutes)</i>',
1657 value: nvram.ppp_idletime },
1658 { title: 'Redial Interval', indent: 2, name: 'ppp_redialperiod', type: 'text', maxlen: 5, size: 7, suffix: ' <i>(seconds)</i>',
1659 value: nvram.ppp_redialperiod },
1660 { title: 'MTU', multi: [
1661 { name: 'mtu_enable', type: 'select', options: [['0', 'Default'],['1','Manual']], value: nvram.mtu_enable },
1662 { name: 'f_wan_mtu', type: 'text', maxlen: 4, size: 6, value: nvram.wan_mtu } ] },
1663 { title: 'Single Line MLPPP', name: 'f_ppp_mlppp', type: 'checkbox', value: (nvram.ppp_mlppp == 1) },
1665 { title: 'Route Modem IP', name: 'modem_ipaddr', type: 'text', maxlen: 15, size: 17, suffix: ' <i>(must be in different subnet to router, 0.0.0.0 to disable)</i>', value: nvram.modem_ipaddr },
1667 /* NOVLAN-BEGIN */
1668 { title: 'Use WAN port for LAN', name: 'f_wan_islan', type: 'checkbox', value: (nvram.wan_islan == 1) }
1669 /* NOVLAN-END */
1670 /* VLAN-BEGIN */
1671 { title: 'Bridge WAN port to primary LAN (br0)', name: 'f_wan_islan', type: 'checkbox', value: (nvram.wan_islan == 1) }
1672 /* VLAN-END */
1675 </script>
1676 </div>
1678 <div class='section-title'>LAN</div>
1679 <div class='section'>
1680 <!-- VLAN-BEGIN -->
1681 <table class='tomato-grid' cellspacing=1 id='lan-grid'></table>
1683 <script type='text/javascript'>lg.setup();</script>
1684 <!-- VLAN-END -->
1686 <script type='text/javascript'>
1687 dns = nvram.wan_dns.split(/\s+/);
1688 /* REMOVE-BEGIN
1689 //ipp = nvram.lan_ipaddr.split('.').splice(0, 3).join('.');
1690 REMOVE-END */
1691 createFieldTable('', [
1692 /* NOVLAN-BEGIN */
1693 { title: 'Router IP Address', name: 'lan_ipaddr', type: 'text', maxlen: 15, size: 17, value: nvram.lan_ipaddr },
1694 { title: 'Subnet Mask', name: 'lan_netmask', type: 'text', maxlen: 15, size: 17, value: nvram.lan_netmask },
1695 /* NOVLAN-END */
1696 { title: 'Default Gateway', name: 'lan_gateway', type: 'text', maxlen: 15, size: 17, value: nvram.lan_gateway },
1697 { title: 'Static DNS', suffix: '&nbsp; <i>(IP:port)</i>', name: 'f_dns_1', type: 'text', maxlen: 21, size: 25, value: dns[0] || '0.0.0.0' },
1698 { title: '', name: 'f_dns_2', type: 'text', maxlen: 21, size: 25, value: dns[1] || '0.0.0.0' },
1699 { title: '', name: 'f_dns_3', type: 'text', maxlen: 21, size: 25, value: dns[2] || '0.0.0.0' },
1700 /* NOVLAN-BEGIN */
1701 { title: 'DHCP Server', name: 'f_dhcpd_enable', type: 'checkbox', value: (nvram.lan_proto == 'dhcp') },
1702 { title: 'IP Address Range', indent: 2, multi: [
1703 { name: 'dhcpd_startip', type: 'text', maxlen: 15, size: 17, value: nvram.dhcpd_startip, suffix: ' - ' },
1704 { name: 'dhcpd_endip', type: 'text', maxlen: 15, size: 17, value: nvram.dhcpd_endip, suffix: ' <i id="dhcp_count"></i>' }
1705 ] },
1707 { title: 'Lease Time', indent: 2, name: 'dhcp_lease', type: 'text', maxlen: 6, size: 8, suffix: ' <i>(minutes)</i>',
1708 value: (nvram.dhcp_lease > 0) ? nvram.dhcp_lease : 1440 },
1709 { title: 'WINS', indent: 2, name: 'wan_wins', type: 'text', maxlen: 15, size: 17, value: nvram.wan_wins }
1710 /* NOVLAN-END */
1711 /* VLAN-BEGIN */
1712 { title: 'WINS <i>(for DHCP)</i>', name: 'wan_wins', type: 'text', maxlen: 15, size: 17, value: nvram.wan_wins }
1713 /* VLAN-END */
1715 </script>
1716 </div>
1718 <script type='text/javascript'>
1720 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
1721 //if(wl_ifaces[uidx][0].indexOf('.') < 0) {
1722 if (wl_sunit(uidx)<0) {
1723 var u = wl_unit(uidx);
1725 W('<input type=\'hidden\' id=\'_wl'+u+'_mode\' name=\'wl'+u+'_mode\'>');
1726 W('<input type=\'hidden\' id=\'_wl'+u+'_nband\' name=\'wl'+u+'_nband\'>');
1727 W('<input type=\'hidden\' id=\'_wl'+u+'_wds_enable\' name=\'wl'+u+'_wds_enable\'>');
1728 W('<input type=\'hidden\' id=\'_wl'+u+'_wds\' name=\'wl'+u+'_wds\'>');
1729 W('<input type=\'hidden\' id=\'_wl'+u+'_radio\' name=\'wl'+u+'_radio\'>');
1730 W('<input type=\'hidden\' id=\'_wl'+u+'_closed\' name=\'wl'+u+'_closed\'>');
1731 W('<input type=\'hidden\' id=\'_wl'+u+'_key\' name=\'wl'+u+'_key\'>');
1732 W('<input type=\'hidden\' id=\'_wl'+u+'_gmode\' name=\'wl'+u+'_gmode\'>');
1733 W('<input type=\'hidden\' id=\'_wl'+u+'_akm\' name=\'wl'+u+'_akm\'>');
1734 W('<input type=\'hidden\' id=\'_wl'+u+'_auth\' name=\'wl'+u+'_auth\'>');
1735 W('<input type=\'hidden\' id=\'_wl'+u+'_auth_mode\' name=\'wl'+u+'_auth_mode\'>');
1736 W('<input type=\'hidden\' id=\'_wl'+u+'_wep\' name=\'wl'+u+'_wep\'>');
1737 W('<input type=\'hidden\' id=\'_wl'+u+'_lazywds\' name=\'wl'+u+'_lazywds\'>');
1738 W('<input type=\'hidden\' id=\'_wl'+u+'_nmode\' name=\'wl'+u+'_nmode\'>');
1739 W('<input type=\'hidden\' id=\'_wl'+u+'_nmcsidx\' name=\'wl'+u+'_nmcsidx\'>');
1740 W('<input type=\'hidden\' id=\'_wl'+u+'_nreqd\' name=\'wl'+u+'_nreqd\'>');
1741 W('<input type=\'hidden\' id=\'_wl'+u+'_nctrlsb\' name=\'wl'+u+'_nctrlsb\'>');
1742 W('<input type=\'hidden\' id=\'_wl'+u+'_nbw\' name=\'wl'+u+'_nbw\'>');
1744 W('<div class=\'section-title\'>Wireless');
1745 // if (wl_ifaces.length > 1)
1746 W(' (' + wl_display_ifname(uidx) + ')');
1747 W('</div>');
1749 W('<div class=\'section\'>');
1751 f = [
1752 { title: 'Enable Wireless', name: 'f_wl'+u+'_radio', type: 'checkbox',
1753 value: (eval('nvram.wl'+u+'_radio') == '1') && (eval('nvram.wl'+u+'_net_mode') != 'disabled') },
1754 { title: 'MAC Address', text: '<a href="advanced-mac.asp">' + eval('nvram.wl'+u+'_hwaddr') + '</a>' },
1755 { title: 'Wireless Mode', name: 'f_wl'+u+'_mode', type: 'select',
1756 options: [['ap', 'Access Point'],['apwds', 'Access Point + WDS'],['sta', 'Wireless Client'],['wet', 'Wireless Ethernet Bridge'],['wds', 'WDS']],
1757 value: ((eval('nvram.wl'+u+'_mode') == 'ap') && (eval('nvram.wl'+u+'_wds_enable') == '1')) ? 'apwds' : eval('nvram.wl'+u+'_mode') },
1758 { title: 'Radio Band', name: 'f_wl'+u+'_nband', type: 'select', options: bands[uidx],
1759 value: eval('nvram.wl'+u+'_nband') || '0' == '0' ? bands[uidx][0][0] : eval('nvram.wl'+u+'_nband') },
1760 { title: 'Wireless Network Mode', name: 'wl'+u+'_net_mode', type: 'select',
1761 value: (eval('nvram.wl'+u+'_net_mode') == 'disabled') ? 'mixed' : eval('nvram.wl'+u+'_net_mode'),
1762 options: [], prefix: '<span id="__wl'+u+'_net_mode">', suffix: '</span>' },
1763 { title: 'SSID', name: 'wl'+u+'_ssid', type: 'text', maxlen: 32, size: 34, value: eval('nvram.wl'+u+'_ssid') },
1764 { title: 'Broadcast', indent: 2, name: 'f_wl'+u+'_bcast', type: 'checkbox', value: (eval('nvram.wl'+u+'_closed') == '0') },
1765 { title: 'Channel', name: 'wl'+u+'_channel', type: 'select', options: ghz[uidx], prefix: '<span id="__wl'+u+'_channel">', suffix: '</span> <input type="button" id="_f_wl'+u+'_scan" value="Scan" onclick="scanButton('+u+')"> <img src="spin.gif" id="spin'+u+'">',
1766 value: eval('nvram.wl'+u+'_channel') },
1767 { title: 'Channel Width', name: 'wl'+u+'_nbw_cap', type: 'select', options: [['0','20 MHz'],['1','40 MHz']],
1768 value: eval('nvram.wl'+u+'_nbw_cap') },
1769 { title: 'Control Sideband', name: 'f_wl'+u+'_nctrlsb', type: 'select', options: [['lower','Lower'],['upper','Upper']],
1770 value: eval('nvram.wl'+u+'_nctrlsb') == 'none' ? 'lower' : eval('nvram.wl'+u+'_nctrlsb') },
1771 null,
1772 { title: 'Security', name: 'wl'+u+'_security_mode', type: 'select',
1773 options: [['disabled','Disabled'],['wep','WEP'],['wpa_personal','WPA Personal'],['wpa_enterprise','WPA Enterprise'],['wpa2_personal','WPA2 Personal'],['wpa2_enterprise','WPA2 Enterprise'],['wpaX_personal','WPA / WPA2 Personal'],['wpaX_enterprise','WPA / WPA2 Enterprise'],['radius','Radius']],
1774 value: eval('nvram.wl'+u+'_security_mode') },
1775 { title: 'Encryption', indent: 2, name: 'wl'+u+'_crypto', type: 'select',
1776 options: [['tkip','TKIP'],['aes','AES'],['tkip+aes','TKIP / AES']], value: eval('nvram.wl'+u+'_crypto') },
1777 { title: 'Shared Key', indent: 2, name: 'wl'+u+'_wpa_psk', type: 'password', maxlen: 64, size: 66, peekaboo: 1,
1778 suffix: ' <input type="button" id="_f_wl'+u+'_psk_random1" value="Random" onclick="random_psk(\'_wl'+u+'_wpa_psk\')">',
1779 value: eval('nvram.wl'+u+'_wpa_psk') },
1780 { title: 'Shared Key', indent: 2, name: 'wl'+u+'_radius_key', type: 'password', maxlen: 80, size: 32, peekaboo: 1,
1781 suffix: ' <input type="button" id="_f_wl'+u+'_psk_random2" value="Random" onclick="random_psk(\'_wl'+u+'_radius_key\')">',
1782 value: eval('nvram.wl'+u+'_radius_key') },
1783 { title: 'Group Key Renewal', indent: 2, name: 'wl'+u+'_wpa_gtk_rekey', type: 'text', maxlen: 4, size: 6, suffix: ' <i>(seconds)</i>',
1784 value: eval('nvram.wl'+u+'_wpa_gtk_rekey') },
1785 { title: 'Radius Server', indent: 2, multi: [
1786 { name: 'wl'+u+'_radius_ipaddr', type: 'text', maxlen: 15, size: 17, value: eval('nvram.wl'+u+'_radius_ipaddr') },
1787 { name: 'wl'+u+'_radius_port', type: 'text', maxlen: 5, size: 7, prefix: ' : ', value: eval('nvram.wl'+u+'_radius_port') } ] },
1788 { title: 'Encryption', indent: 2, name: 'wl'+u+'_wep_bit', type: 'select', options: [['128','128-bits'],['64','64-bits']],
1789 value: eval('nvram.wl'+u+'_wep_bit') },
1790 { title: 'Passphrase', indent: 2, name: 'wl'+u+'_passphrase', type: 'text', maxlen: 16, size: 20,
1791 suffix: ' <input type="button" id="_f_wl'+u+'_wep_gen" value="Generate" onclick="generate_wep('+u+')"> <input type="button" id="_f_wl'+u+'_wep_random" value="Random" onclick="random_wep('+u+')">',
1792 value: eval('nvram.wl'+u+'_passphrase') }
1795 for (i = 1; i <= 4; ++i) {
1796 f.push(
1797 { title: ('Key ' + i), indent: 2, name: ('wl'+u+'_key' + i), type: 'text', maxlen: 26, size: 34,
1798 suffix: '<input type="radio" onchange="verifyFields(this,1)" onclick="verifyFields(this,1)" name="f_wl'+u+'_wepidx" id="_f_wl'+u+'_wepidx_' + i + '" value="' + i + '"' + ((eval('nvram.wl'+u+'_key') == i) ? ' checked>' : '>'),
1799 value: nvram['wl'+u+'_key' + i] });
1802 f.push(null,
1803 { title: 'WDS', name: 'f_wl'+u+'_lazywds', type: 'select',
1804 options: [['0','Link With...'],['1','Automatic']], value: nvram['wl'+u+'_lazywds'] } );
1805 wds = eval('nvram.wl'+u+'_wds').split(/\s+/);
1806 for (i = 0; i < 10; i += 2) {
1807 f.push({ title: (i ? '' : 'MAC Address'), indent: 2, multi: [
1808 { name: 'f_wl'+u+'_wds_' + i, type: 'text', maxlen: 17, size: 20, value: wds[i] || '00:00:00:00:00:00' },
1809 { name: 'f_wl'+u+'_wds_' + (i + 1), type: 'text', maxlen: 17, size: 20, value: wds[i + 1] || '00:00:00:00:00:00' } ] } );
1812 createFieldTable('', f);
1813 W('</div>');
1816 // for each wlif
1817 </script>
1819 <!-- / / / -->
1821 </td></tr>
1822 <tr><td id='footer' colspan=2>
1823 <span id='footer-msg'></span>
1824 <input type='button' value='Save' id='save-button' onclick='save()'>
1825 <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
1826 </td></tr>
1827 </table>
1828 </form>
1829 <script type='text/javascript'>earlyInit()</script>
1830 <div style='height:100px'></div>
1831 </body>
1832 </html>