1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML
4.0//EN'
>
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.
12 <meta http-equiv='content-type' content='text/html;charset=utf-
8'
>
13 <meta name='robots' content='noindex,nofollow'
>
14 <title>[<%
ident(); %>] Basic: Static DHCP
</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>
20 <style type='text/css'
>
33 <script type='text/javascript' src='debug.js'
></script>
35 <script type='text/javascript'
>
37 // <% nvram("lan_ipaddr,lan_netmask,dhcpd_static,dhcpd_startip"); %>
39 if (nvram
.lan_ipaddr
.match(/^(\d+\.\d+\.\d+)\.(\d+)$/)) ipp
= RegExp
.$1 + '.';
42 autonum
= aton(nvram
.lan_ipaddr
) & aton(nvram
.lan_netmask
);
44 var sg
= new TomatoGrid();
46 sg
.exist = function(f
, v
)
48 var data
= this.getAllData();
49 for (var i
= 0; i
< data
.length
; ++i
) {
50 if (data
[i
][f
] == v
) return true;
55 sg
.existMAC = function(mac
)
57 if (isMAC0(mac
)) return false;
58 return this.exist(0, mac
) || this.exist(1, mac
);
61 sg
.existName = function(name
)
63 return this.exist(3, name
);
66 sg
.inStatic = function(n
)
68 return this.exist(2, n
);
71 sg
.dataToView = function(data
) {
75 if (!isMAC0(data
[1])) s
+= '<br>' + data
[1];
78 for (var i
= 2; i
< data
.length
; ++i
)
79 v
.push(escapeHTML('' + data
[i
]));
84 sg
.sortCompare = function(a
, b
) {
85 var da
= a
.getRowData();
86 var db
= b
.getRowData();
88 switch (this.sortColumn
) {
90 r
= cmpText(da
[0], db
[0]);
93 r
= cmpIP(da
[2], db
[2]);
96 if (r
== 0) r
= cmpText(da
[3], db
[3]);
97 return this.sortAscending
? r
: -r
;
100 sg
.verifyFields = function(row
, quiet
)
104 f
= fields
.getAll(row
);
106 if (!v_macz(f
[0], quiet
)) return 0;
107 if (!v_macz(f
[1], quiet
)) return 0;
108 if (isMAC0(f
[0].value
)) {
109 f
[0].value
= f
[1].value
;
110 f
[1].value
= '00:00:00:00:00:00';
112 else if (f
[0].value
== f
[1].value
) {
113 f
[1].value
= '00:00:00:00:00:00';
115 else if ((!isMAC0(f
[1].value
)) && (f
[0].value
> f
[1].value
)) {
117 f
[1].value
= f
[0].value
;
120 for (i
= 0; i
< 2; ++i
) {
121 if (this.existMAC(f
[i
].value
)) {
122 ferror
.set(f
[i
], 'Duplicate MAC address', quiet
);
127 if (f
[2].value
.indexOf('.') == -1) {
128 s
= parseInt(f
[2].value
, 10)
129 if (isNaN(s
) || (s
<= 0) || (s
>= 255)) {
130 ferror
.set(f
[2], 'Invalid IP address', quiet
);
133 f
[2].value
= ipp
+ s
;
136 if ((!isMAC0(f
[0].value
)) && (this.inStatic(f
[2].value
))) {
137 ferror
.set(f
[2], 'Duplicate IP address', quiet
);
141 s
= f
[3].value
.trim().replace(/\s+/g, ' ');
143 if (s
.search(/^[.a-zA-Z0-9_\- ]+$/) == -1) {
144 ferror
.set(f
[3], 'Invalid name. Only characters "A-Z 0-9 . - _" are allowed.', quiet
);
147 if (this.existName(s
)) {
148 ferror
.set(f
[3], 'Duplicate name.', quiet
);
154 if (isMAC0(f
[0].value
)) {
156 s
= 'Both MAC address and name fields must not be empty.';
157 ferror
.set(f
[0], s
, 1);
158 ferror
.set(f
[3], s
, quiet
);
166 sg
.resetNewEditor = function() {
169 f
= fields
.getAll(this.newEditor
);
172 if ((c
= cookie
.get('addstatic')) != null) {
173 cookie
.set('addstatic', '', 0);
177 f
[1].value
= '00:00:00:00:00:00';
184 f
[0].value
= '00:00:00:00:00:00';
185 f
[1].value
= '00:00:00:00:00:00';
195 } while (((c
= fixIP(ntoa(autonum
), 1)) == null) || (c
== nvram
.lan_ipaddr
) || (this.inStatic(c
)));
200 sg
.setup = function()
202 this.init('bs-grid', 'sort', 100, [
203 { multi
: [ { type
: 'text', maxlen
: 17 }, { type
: 'text', maxlen
: 17 } ] },
204 { type
: 'text', maxlen
: 15 },
205 { type
: 'text', maxlen
: 50 } ] );
207 this.headerSet(['MAC Address', 'IP Address', 'Hostname']);
208 var s
= nvram
.dhcpd_static
.split('>');
209 for (var i
= 0; i
< s
.length
; ++i
) {
210 var t
= s
[i
].split('<');
212 var d
= t
[0].split(',');
213 this.insertData(-1, [d
[0], (d
.length
>= 2) ? d
[1] : '00:00:00:00:00:00',
214 (t
[1].indexOf('.') == -1) ? (ipp
+ t
[1]) : t
[1], t
[2]]);
218 this.showNewEditor();
219 this.resetNewEditor();
224 if (sg
.isEditing()) return;
226 var data
= sg
.getAllData();
230 for (i
= 0; i
< data
.length
; ++i
) {
233 if (!isMAC0(d
[1])) sdhcp
+= ',' + d
[1];
234 sdhcp
+= '<' + d
[2] + '<' + d
[3] + '>';
238 fom
.dhcpd_static
.value
= sdhcp
;
248 <body onload='init()'
>
249 <form id='_fom' method='post' action='tomato.cgi'
>
250 <table id='container' cellspacing=
0>
251 <tr><td colspan=
2 id='header'
>
252 <div class='title'
>Tomato
</div>
253 <div class='version'
>Version <%
version(); %></div>
255 <tr id='body'
><td id='navi'
><script type='text/javascript'
>navi()</script></td>
257 <div id='ident'
><%
ident(); %></div>
261 <input type='hidden' name='_nextpage' value='basic-static.asp'
>
262 <input type='hidden' name='_service' value='dhcpd-restart'
>
264 <input type='hidden' name='dhcpd_static'
>
266 <div class='section-title'
>Static DHCP
</div>
267 <div class='section'
>
268 <table class='tomato-grid' id='bs-grid'
></table>
275 <tr><td id='footer' colspan=
2>
276 <span id='footer-msg'
></span>
277 <input type='button' value='Save' id='save-button' onclick='save()'
>
278 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'
>
282 <script type='text/javascript'
>sg
.setup();</script>