BWM and static ARP optimizations
[tomato.git] / release / src / router / www / advanced-mac.asp
blob9d1cf80b70d04088b92ca1c51b80ac010fd2aeca
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(); %>] Advanced: MAC Address</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <link rel='stylesheet' type='text/css' href='color.css'>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <script type='text/javascript' src='debug.js'></script>
23 <script type='text/javascript' src='wireless.jsx?_http_id=<% nv(http_id); %>'></script>
24 <script type='text/javascript'>
26 // <% nvram("et0macaddr,mac_wan,wl_macaddr,wl_hwaddr"); %>
28 function et0plus(plus)
30 var mac = nvram.et0macaddr.split(':');
31 if (mac.length != 6) return '';
32 while (plus-- > 0) {
33 for (var i = 5; i >= 3; --i) {
34 var n = (parseInt(mac[i], 16) + 1) & 0xFF;
35 mac[i] = n.hex(2);
36 if (n != 0) break;
39 return mac.join(':');
42 function defmac(which)
44 if (which == 'wan')
45 return et0plus(1);
46 else { // wlX
47 var u = which.substr(2, which.length) * 1;
48 return et0plus(2 + u);
52 function bdefault(which)
54 E('_f_' + which + '_macaddr').value = defmac(which);
55 verifyFields(null, true);
58 function brand(which)
60 var mac;
61 var i;
63 mac = ['00'];
64 for (i = 5; i > 0; --i)
65 mac.push(Math.floor(Math.random() * 255).hex(2));
66 E('_f_' + which + '_macaddr').value = mac.join(':');
67 verifyFields(null, true);
70 function bclone(which)
72 E('_f_' + which + '_macaddr').value = '<% compmac(); %>';
73 verifyFields(null, true);
76 function findPrevMAC(mac, maxidx)
78 if (E('_f_wan_macaddr').value == mac) return 1;
80 for (var uidx = 0; uidx < maxidx; ++uidx) {
81 if (E('_f_wl'+wl_unit(uidx)+'_macaddr').value == mac) return 1;
84 return 0;
87 function verifyFields(focused, quiet)
89 var uidx, u, a;
91 if (!v_mac('_f_wan_macaddr', quiet)) return 0;
93 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
94 u = wl_unit(uidx);
95 a = E('_f_wl'+u+'_macaddr');
96 if (!v_mac(a, quiet)) return 0;
98 if (findPrevMAC(a.value, uidx)) {
99 ferror.set(a, 'Addresses must be unique', quiet);
100 return 0;
104 return 1;
107 function save()
109 var u, uidx, v;
111 if (!verifyFields(null, false)) return;
112 if (!confirm("Warning: Changing the MAC address may require that you reboot all devices, computers or modem connected to this router. Continue anyway?")) return;
114 var fom = E('_fom');
115 fom.mac_wan.value = (fom._f_wan_macaddr.value == defmac('wan')) ? '' : fom._f_wan_macaddr.value;
117 for (uidx = 0; uidx < wl_ifaces.length; ++uidx) {
118 u = wl_unit(uidx);
119 v = E('_f_wl'+u+'_macaddr').value;
120 E('_wl'+u+'_macaddr').value = (v == defmac('wl' + u)) ? '' : v;
123 form.submit(fom, 1);
126 </script>
127 </head>
129 <body>
130 <form id='_fom' method='post' action='tomato.cgi'>
131 <table id='container' cellspacing=0>
132 <tr><td colspan=2 id='header'>
133 <div class='title'>Tomato</div>
134 <div class='version'>Version <% version(); %></div>
135 </td></tr>
136 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
137 <td id='content'>
138 <div id='ident'><% ident(); %></div>
140 <!-- / / / -->
142 <input type='hidden' name='_nextpage' value='advanced-mac.asp'>
143 <input type='hidden' name='_nextwait' value='10'>
144 <input type='hidden' name='_service' value='*'>
146 <input type='hidden' name='mac_wan'>
148 <script type='text/javascript'>
149 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
150 var u = wl_unit(uidx);
151 W('<input type=\'hidden\' id=\'_wl'+u+'_macaddr\' name=\'wl'+u+'_macaddr\'>');
153 </script>
155 <div class='section-title'>MAC Address</div>
156 <div class='section'>
157 <script type='text/javascript'>
159 f = [
160 { title: 'WAN Port', indent: 1, name: 'f_wan_macaddr', type: 'text', maxlen: 17, size: 20,
161 suffix: ' <input type="button" value="Default" onclick="bdefault(\'wan\')"> <input type="button" value="Random" onclick="brand(\'wan\')"> <input type="button" value="Clone PC" onclick="bclone(\'wan\')">',
162 value: nvram.mac_wan || defmac('wan') }
165 for (var uidx = 0; uidx < wl_ifaces.length; ++uidx) {
166 var u = wl_unit(uidx);
167 f.push(
168 { title: 'Wireless Interface ' + ((wl_ifaces.length > 1) ? wl_ifaces[uidx][0] : ''), indent: 1, name: 'f_wl'+u+'_macaddr', type: 'text', maxlen: 17, size: 20,
169 suffix:' <input type="button" value="Default" onclick="bdefault(\'wl'+u+'\')"> <input type="button" value="Random" onclick="brand(\'wl'+u+'\')"> <input type="button" value="Clone PC" onclick="bclone(\'wl'+u+'\')">',
170 value: nvram['wl'+u+'_macaddr'] || defmac('wl' + u) }
174 createFieldTable('', f);
176 </script>
177 <br>
178 <table border=0 cellpadding=1>
179 <tr><td>Router's LAN MAC Address:</td><td><b><% nv('et0macaddr'); %></b></td></tr>
180 <tr><td>Computer's MAC Address:</td><td><b><% compmac(); %></b></td></tr>
181 </table>
182 </div>
186 <!-- / / / -->
188 </td></tr>
189 <tr><td id='footer' colspan=2>
190 <span id='footer-msg'></span>
191 <input type='button' value='Save' id='save-button' onclick='save()'>
192 <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
193 </td></tr>
194 </table>
195 </form>
196 <script type='text/javascript'>verifyFields(null, 1);</script>
197 </body>
198 </html>