10 var callHostHints
, callDUIDHints
, callDHCPLeases
, CBILeaseStatus
, CBILease6Status
;
12 callHostHints
= rpc
.declare({
14 method
: 'getHostHints',
18 callDUIDHints
= rpc
.declare({
20 method
: 'getDUIDHints',
24 callDHCPLeases
= rpc
.declare({
26 method
: 'getDHCPLeases',
30 CBILeaseStatus
= form
.DummyValue
.extend({
31 renderWidget: function(section_id
, option_id
, cfgvalue
) {
33 E('h4', _('Active DHCP Leases')),
34 E('div', { 'id': 'lease_status_table', 'class': 'table' }, [
35 E('div', { 'class': 'tr table-titles' }, [
36 E('div', { 'class': 'th' }, _('Hostname')),
37 E('div', { 'class': 'th' }, _('IPv4-Address')),
38 E('div', { 'class': 'th' }, _('MAC-Address')),
39 E('div', { 'class': 'th' }, _('Lease time remaining'))
41 E('div', { 'class': 'tr placeholder' }, [
42 E('div', { 'class': 'td' }, E('em', _('Collecting data...')))
49 CBILease6Status
= form
.DummyValue
.extend({
50 renderWidget: function(section_id
, option_id
, cfgvalue
) {
52 E('h4', _('Active DHCPv6 Leases')),
53 E('div', { 'id': 'lease6_status_table', 'class': 'table' }, [
54 E('div', { 'class': 'tr table-titles' }, [
55 E('div', { 'class': 'th' }, _('Host')),
56 E('div', { 'class': 'th' }, _('IPv6-Address')),
57 E('div', { 'class': 'th' }, _('DUID')),
58 E('div', { 'class': 'th' }, _('Lease time remaining'))
60 E('div', { 'class': 'tr placeholder' }, [
61 E('div', { 'class': 'td' }, E('em', _('Collecting data...')))
68 function validateHostname(sid
, s
) {
70 return _('Expecting: %s').format(_('valid hostname'));
72 var labels
= s
.replace(/^\.+|\.$/g, '').split(/\./);
74 for (var i
= 0; i
< labels
.length
; i
++)
75 if (!labels
[i
].match(/^[a-z0-9_](?:[a-z0-9-]{0,61}[a-z0-9])?$/i))
76 return _('Expecting: %s').format(_('valid hostname'));
81 function validateAddressList(sid
, s
) {
82 if (s
== null || s
== '')
85 var m
= s
.match(/^\/(.+)\/$/),
86 names
= m
? m
[1].split(/\//) : [ s
];
88 for (var i
= 0; i
< names
.length
; i
++) {
89 var res
= validateHostname(sid
, names
[i
]);
98 function validateServerSpec(sid
, s
) {
99 if (s
== null || s
== '')
102 var m
= s
.match(/^\/(.+)\/(.*)$/);
104 return _('Expecting: %s').format(_('valid hostname'));
106 var res
= validateAddressList(sid
, m
[1]);
110 if (m
[2] == '' || m
[2] == '#')
113 // ipaddr%scopeid#srvport@source@interface#srcport
115 m
= m
[2].match(/^([0-9a-f:.]+)(?:%[^#@]+)?(?:#(\d+))?(?:@([0-9a-f:.]+)(?:@[^#]+)?(?:#(\d+))?)?$/);
118 return _('Expecting: %s').format(_('valid IP address'));
119 else if (validation
.parseIPv4(m
[1]) && m
[3] != null && !validation
.parseIPv4(m
[3]))
120 return _('Expecting: %s').format(_('valid IPv4 address'));
121 else if (validation
.parseIPv6(m
[1]) && m
[3] != null && !validation
.parseIPv6(m
[3]))
122 return _('Expecting: %s').format(_('valid IPv6 address'));
123 else if ((m
[2] != null && +m
[2] > 65535) || (m
[4] != null && +m
[4] > 65535))
124 return _('Expecting: %s').format(_('valid port value'));
137 render: function(hosts_duids
) {
138 var has_dhcpv6
= L
.hasSystemFeature('dnsmasq', 'dhcpv6') || L
.hasSystemFeature('odhcpd'),
139 hosts
= hosts_duids
[0],
140 duids
= hosts_duids
[1],
143 m
= new form
.Map('dhcp', _('DHCP and DNS'), _('Dnsmasq is a combined <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>-Server and <abbr title="Domain Name System">DNS</abbr>-Forwarder for <abbr title="Network Address Translation">NAT</abbr> firewalls'));
145 s
= m
.section(form
.TypedSection
, 'dnsmasq', _('Server Settings'));
149 s
.tab('general', _('General Settings'));
150 s
.tab('files', _('Resolv and Hosts Files'));
151 s
.tab('tftp', _('TFTP Settings'));
152 s
.tab('advanced', _('Advanced Settings'));
153 s
.tab('leases', _('Static Leases'));
155 s
.taboption('general', form
.Flag
, 'domainneeded',
156 _('Domain required'),
157 _('Don\'t forward <abbr title="Domain Name System">DNS</abbr>-Requests without <abbr title="Domain Name System">DNS</abbr>-Name'));
159 s
.taboption('general', form
.Flag
, 'authoritative',
161 _('This is the only <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr> in the local network'));
164 s
.taboption('files', form
.Flag
, 'readethers',
165 _('Use <code>/etc/ethers</code>'),
166 _('Read <code>/etc/ethers</code> to configure the <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>-Server'));
168 s
.taboption('files', form
.Value
, 'leasefile',
170 _('file where given <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>-leases will be stored'));
172 s
.taboption('files', form
.Flag
, 'noresolv',
173 _('Ignore resolve file')).optional
= true;
175 o
= s
.taboption('files', form
.Value
, 'resolvfile',
177 _('local <abbr title="Domain Name System">DNS</abbr> file'));
179 o
.depends('noresolv', '0');
180 o
.placeholder
= '/tmp/resolv.conf.d/resolv.conf.auto';
184 s
.taboption('files', form
.Flag
, 'nohosts',
185 _('Ignore <code>/etc/hosts</code>')).optional
= true;
187 s
.taboption('files', form
.DynamicList
, 'addnhosts',
188 _('Additional Hosts files')).optional
= true;
190 o
= s
.taboption('advanced', form
.Flag
, 'quietdhcp',
191 _('Suppress logging'),
192 _('Suppress logging of the routine operation of these protocols'));
195 o
= s
.taboption('advanced', form
.Flag
, 'sequential_ip',
196 _('Allocate IP sequentially'),
197 _('Allocate IP addresses sequentially, starting from the lowest available address'));
200 o
= s
.taboption('advanced', form
.Flag
, 'boguspriv',
202 _('Do not forward reverse lookups for local networks'));
203 o
.default = o
.enabled
;
205 s
.taboption('advanced', form
.Flag
, 'filterwin2k',
207 _('Do not forward requests that cannot be answered by public name servers'));
210 s
.taboption('advanced', form
.Flag
, 'localise_queries',
211 _('Localise queries'),
212 _('Localise hostname depending on the requesting subnet if multiple IPs are available'));
214 if (L
.hasSystemFeature('dnsmasq', 'dnssec')) {
215 o
= s
.taboption('advanced', form
.Flag
, 'dnssec',
219 o
= s
.taboption('advanced', form
.Flag
, 'dnsseccheckunsigned',
220 _('DNSSEC check unsigned'),
221 _('Requires upstream supports DNSSEC; verify unsigned domain responses really come from unsigned domains'));
222 o
.default = o
.enabled
;
226 s
.taboption('general', form
.Value
, 'local',
228 _('Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only'));
230 s
.taboption('general', form
.Value
, 'domain',
232 _('Local domain suffix appended to DHCP names and hosts file entries'));
234 s
.taboption('advanced', form
.Flag
, 'expandhosts',
236 _('Add local domain suffix to names served from hosts files'));
238 s
.taboption('advanced', form
.Flag
, 'nonegcache',
239 _('No negative cache'),
240 _('Do not cache negative replies, e.g. for not existing domains'));
242 s
.taboption('advanced', form
.Value
, 'serversfile',
243 _('Additional servers file'),
244 _('This file may contain lines like \'server=/domain/1.2.3.4\' or \'server=1.2.3.4\' for domain-specific or full upstream <abbr title="Domain Name System">DNS</abbr> servers.'));
246 s
.taboption('advanced', form
.Flag
, 'strictorder',
248 _('<abbr title="Domain Name System">DNS</abbr> servers will be queried in the order of the resolvfile')).optional
= true;
250 s
.taboption('advanced', form
.Flag
, 'allservers',
252 _('Query all available upstream <abbr title="Domain Name System">DNS</abbr> servers')).optional
= true;
254 o
= s
.taboption('advanced', form
.DynamicList
, 'bogusnxdomain', _('Bogus NX Domain Override'),
255 _('List of hosts that supply bogus NX domain results'));
258 o
.placeholder
= '67.215.65.132';
261 s
.taboption('general', form
.Flag
, 'logqueries',
263 _('Write received DNS requests to syslog')).optional
= true;
265 o
= s
.taboption('general', form
.DynamicList
, 'server', _('DNS forwardings'),
266 _('List of <abbr title="Domain Name System">DNS</abbr> servers to forward requests to'));
269 o
.placeholder
= '/example.org/10.1.2.3';
270 o
.validate
= validateServerSpec
;
273 o
= s
.taboption('general', form
.Flag
, 'rebind_protection',
274 _('Rebind protection'),
275 _('Discard upstream RFC1918 responses'));
280 o
= s
.taboption('general', form
.Flag
, 'rebind_localhost',
281 _('Allow localhost'),
282 _('Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services'));
284 o
.depends('rebind_protection', '1');
287 o
= s
.taboption('general', form
.DynamicList
, 'rebind_domain',
288 _('Domain whitelist'),
289 _('List of domains to allow RFC1918 responses for'));
292 o
.depends('rebind_protection', '1');
293 o
.placeholder
= 'ihost.netflix.com';
294 o
.validate
= validateAddressList
;
297 o
= s
.taboption('advanced', form
.Value
, 'port',
298 _('<abbr title="Domain Name System">DNS</abbr> server port'),
299 _('Listening port for inbound DNS queries'));
306 o
= s
.taboption('advanced', form
.Value
, 'queryport',
307 _('<abbr title="Domain Name System">DNS</abbr> query port'),
308 _('Fixed source port for outbound DNS queries'));
312 o
.placeholder
= _('any');
315 o
= s
.taboption('advanced', form
.Value
, 'dhcpleasemax',
316 _('<abbr title="maximal">Max.</abbr> <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr> leases'),
317 _('Maximum allowed number of active DHCP leases'));
320 o
.datatype
= 'uinteger';
321 o
.placeholder
= _('unlimited');
324 o
= s
.taboption('advanced', form
.Value
, 'ednspacket_max',
325 _('<abbr title="maximal">Max.</abbr> <abbr title="Extension Mechanisms for Domain Name System">EDNS0</abbr> packet size'),
326 _('Maximum allowed size of EDNS.0 UDP packets'));
329 o
.datatype
= 'uinteger';
330 o
.placeholder
= 1280;
333 o
= s
.taboption('advanced', form
.Value
, 'dnsforwardmax',
334 _('<abbr title="maximal">Max.</abbr> concurrent queries'),
335 _('Maximum allowed number of concurrent DNS queries'));
338 o
.datatype
= 'uinteger';
341 o
= s
.taboption('advanced', form
.Value
, 'cachesize',
342 _('Size of DNS query cache'),
343 _('Number of cached DNS entries (max is 10000, 0 is no caching)'));
345 o
.datatype
= 'range(0,10000)';
348 s
.taboption('tftp', form
.Flag
, 'enable_tftp',
349 _('Enable TFTP server')).optional
= true;
351 o
= s
.taboption('tftp', form
.Value
, 'tftp_root',
352 _('TFTP server root'),
353 _('Root directory for files served via TFTP'));
356 o
.depends('enable_tftp', '1');
360 o
= s
.taboption('tftp', form
.Value
, 'dhcp_boot',
361 _('Network boot image'),
362 _('Filename of the boot image advertised to clients'));
365 o
.depends('enable_tftp', '1');
366 o
.placeholder
= 'pxelinux.0';
368 o
= s
.taboption('general', form
.Flag
, 'localservice',
369 _('Local Service Only'),
370 _('Limit DNS service to subnets interfaces on which we are serving DNS.'));
374 o
= s
.taboption('general', form
.Flag
, 'nonwildcard',
376 _('Bind dynamically to interfaces rather than wildcard address (recommended as linux default)'));
377 o
.default = o
.enabled
;
381 o
= s
.taboption('general', form
.DynamicList
, 'interface',
382 _('Listen Interfaces'),
383 _('Limit listening to these interfaces, and loopback.'));
386 o
= s
.taboption('general', form
.DynamicList
, 'notinterface',
387 _('Exclude interfaces'),
388 _('Prevent listening on these interfaces.'));
391 o
= s
.taboption('leases', form
.SectionValue
, '__leases__', form
.GridSection
, 'host', null,
392 _('Static leases are used to assign fixed IP addresses and symbolic hostnames to DHCP clients. They are also required for non-dynamic interface configurations where only hosts with a corresponding lease are served.') + '<br />' +
393 _('Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> identifies the host, the <em>IPv4-Address</em> specifies the fixed address to use, and the <em>Hostname</em> is assigned as a symbolic name to the requesting host. The optional <em>Lease time</em> can be used to set non-standard host-specific lease time, e.g. 12h, 3d or infinite.'));
400 so
= ss
.option(form
.Value
, 'name', _('Hostname'));
401 so
.validate
= validateHostname
;
403 so
.write = function(section
, value
) {
404 uci
.set('dhcp', section
, 'name', value
);
405 uci
.set('dhcp', section
, 'dns', '1');
407 so
.remove = function(section
) {
408 uci
.unset('dhcp', section
, 'name');
409 uci
.unset('dhcp', section
, 'dns');
412 so
= ss
.option(form
.Value
, 'mac', _('<abbr title="Media Access Control">MAC</abbr>-Address'));
413 so
.datatype
= 'list(unique(macaddr))';
415 so
.cfgvalue = function(section
) {
416 var macs
= uci
.get('dhcp', section
, 'mac'),
419 if (!Array
.isArray(macs
))
420 macs
= (macs
!= null && macs
!= '') ? macs
.split(/\ss+/) : [];
422 for (var i
= 0, mac
; (mac
= macs
[i
]) != null; i
++)
423 if (/^([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2}):([0-9a-fA-F]{1,2})$/.test(mac
))
424 result
.push('%02X:%02X:%02X:%02X:%02X:%02X'.format(
425 parseInt(RegExp
.$1, 16), parseInt(RegExp
.$2, 16),
426 parseInt(RegExp
.$3, 16), parseInt(RegExp
.$4, 16),
427 parseInt(RegExp
.$5, 16), parseInt(RegExp
.$6, 16)));
429 return result
.length
? result
.join(' ') : null;
431 so
.renderWidget = function(section_id
, option_index
, cfgvalue
) {
432 var node
= form
.Value
.prototype.renderWidget
.apply(this, [section_id
, option_index
, cfgvalue
]),
433 ipopt
= this.section
.children
.filter(function(o
) { return o
.option
== 'ip' })[0];
435 node
.addEventListener('cbi-dropdown-change', L
.bind(function(ipopt
, section_id
, ev
) {
436 var mac
= ev
.detail
.value
.value
;
437 if (mac
== null || mac
== '' || !hosts
[mac
] || !hosts
[mac
].ipv4
)
440 var ip
= ipopt
.formvalue(section_id
);
441 if (ip
!= null && ip
!= '')
444 var node
= ipopt
.map
.findElement('id', ipopt
.cbid(section_id
));
446 dom
.callClassMethod(node
, 'setValue', hosts
[mac
].ipv4
);
447 }, this, ipopt
, section_id
));
451 Object
.keys(hosts
).forEach(function(mac
) {
452 var hint
= hosts
[mac
].name
|| hosts
[mac
].ipv4
;
453 so
.value(mac
, hint
? '%s (%s)'.format(mac
, hint
) : mac
);
456 so
= ss
.option(form
.Value
, 'ip', _('<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address'));
457 so
.datatype
= 'or(ip4addr,"ignore")';
458 so
.validate = function(section
, value
) {
459 var mac
= this.map
.lookupOption('mac', section
),
460 name
= this.map
.lookupOption('name', section
),
461 m
= mac
? mac
[0].formvalue(section
) : null,
462 n
= name
? name
[0].formvalue(section
) : null;
464 if ((m
== null || m
== '') && (n
== null || n
== ''))
465 return _('One of hostname or mac address must be specified!');
469 Object
.keys(hosts
).forEach(function(mac
) {
470 if (hosts
[mac
].ipv4
) {
471 var hint
= hosts
[mac
].name
;
472 so
.value(hosts
[mac
].ipv4
, hint
? '%s (%s)'.format(hosts
[mac
].ipv4
, hint
) : hosts
[mac
].ipv4
);
476 so
= ss
.option(form
.Value
, 'leasetime', _('Lease time'));
479 so
= ss
.option(form
.Value
, 'duid', _('<abbr title="The DHCP Unique Identifier">DUID</abbr>'));
480 so
.datatype
= 'and(rangelength(20,36),hexstring)';
481 Object
.keys(duids
).forEach(function(duid
) {
482 so
.value(duid
, '%s (%s)'.format(duid
, duids
[duid
].hostname
|| duids
[duid
].macaddr
|| duids
[duid
].ip6addr
|| '?'));
485 so
= ss
.option(form
.Value
, 'hostid', _('<abbr title="Internet Protocol Version 6">IPv6</abbr>-Suffix (hex)'));
487 o
= s
.taboption('leases', CBILeaseStatus
, '__status__');
490 o
= s
.taboption('leases', CBILease6Status
, '__status6__');
492 return m
.render().then(function(mapEl
) {
493 poll
.add(function() {
494 return callDHCPLeases().then(function(leaseinfo
) {
495 var leases
= Array
.isArray(leaseinfo
.dhcp_leases
) ? leaseinfo
.dhcp_leases
: [],
496 leases6
= Array
.isArray(leaseinfo
.dhcp6_leases
) ? leaseinfo
.dhcp6_leases
: [];
498 cbi_update_table(mapEl
.querySelector('#lease_status_table'),
499 leases
.map(function(lease
) {
502 if (lease
.expires
=== false)
503 exp
= E('em', _('unlimited'));
504 else if (lease
.expires
<= 0)
505 exp
= E('em', _('expired'));
507 exp
= '%t'.format(lease
.expires
);
510 lease
.hostname
|| '?',
516 E('em', _('There are no active leases')));
519 cbi_update_table(mapEl
.querySelector('#lease6_status_table'),
520 leases6
.map(function(lease
) {
523 if (lease
.expires
=== false)
524 exp
= E('em', _('unlimited'));
525 else if (lease
.expires
<= 0)
526 exp
= E('em', _('expired'));
528 exp
= '%t'.format(lease
.expires
);
530 var hint
= lease
.macaddr
? hosts
[lease
.macaddr
] : null,
531 name
= hint
? (hint
.name
|| hint
.ipv4
|| hint
.ipv6
) : null,
534 if (name
&& lease
.hostname
&& lease
.hostname
!= name
&& lease
.ip6addr
!= name
)
535 host
= '%s (%s)'.format(lease
.hostname
, name
);
536 else if (lease
.hostname
)
537 host
= lease
.hostname
;
543 lease
.ip6addrs
? lease
.ip6addrs
.join(' ') : lease
.ip6addr
,
548 E('em', _('There are no active leases')));