luci-mod-admin-full: automatically set dns=1 for static leases with hostname
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / dhcp.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local ipc = require "luci.ip"
5 local o
6 require "luci.util"
7
8 m = Map("dhcp", translate("DHCP and DNS"),
9 translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" ..
10 "\">DHCP</abbr>-Server and <abbr title=\"Domain Name System\">DNS</abbr>-" ..
11 "Forwarder for <abbr title=\"Network Address Translation\">NAT</abbr> " ..
12 "firewalls"))
13
14 s = m:section(TypedSection, "dnsmasq", translate("Server Settings"))
15 s.anonymous = true
16 s.addremove = false
17
18 s:tab("general", translate("General Settings"))
19 s:tab("files", translate("Resolv and Hosts Files"))
20 s:tab("tftp", translate("TFTP Settings"))
21 s:tab("advanced", translate("Advanced Settings"))
22
23 s:taboption("general", Flag, "domainneeded",
24 translate("Domain required"),
25 translate("Don't forward <abbr title=\"Domain Name System\">DNS</abbr>-Requests without " ..
26 "<abbr title=\"Domain Name System\">DNS</abbr>-Name"))
27
28 s:taboption("general", Flag, "authoritative",
29 translate("Authoritative"),
30 translate("This is the only <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
31 "abbr> in the local network"))
32
33
34 s:taboption("files", Flag, "readethers",
35 translate("Use <code>/etc/ethers</code>"),
36 translate("Read <code>/etc/ethers</code> to configure the <abbr title=\"Dynamic Host " ..
37 "Configuration Protocol\">DHCP</abbr>-Server"))
38
39 s:taboption("files", Value, "leasefile",
40 translate("Leasefile"),
41 translate("file where given <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
42 "abbr>-leases will be stored"))
43
44 s:taboption("files", Flag, "noresolv",
45 translate("Ignore resolve file")).optional = true
46
47 rf = s:taboption("files", Value, "resolvfile",
48 translate("Resolve file"),
49 translate("local <abbr title=\"Domain Name System\">DNS</abbr> file"))
50
51 rf:depends("noresolv", "")
52 rf.optional = true
53
54
55 s:taboption("files", Flag, "nohosts",
56 translate("Ignore <code>/etc/hosts</code>")).optional = true
57
58 s:taboption("files", DynamicList, "addnhosts",
59 translate("Additional Hosts files")).optional = true
60
61 qu = s:taboption("advanced", Flag, "quietdhcp",
62 translate("Suppress logging"),
63 translate("Suppress logging of the routine operation of these protocols"))
64 qu.optional = true
65
66 se = s:taboption("advanced", Flag, "sequential_ip",
67 translate("Allocate IP sequentially"),
68 translate("Allocate IP addresses sequentially, starting from the lowest available address"))
69 se.optional = true
70
71 bp = s:taboption("advanced", Flag, "boguspriv",
72 translate("Filter private"),
73 translate("Do not forward reverse lookups for local networks"))
74 bp.default = bp.enabled
75
76 s:taboption("advanced", Flag, "filterwin2k",
77 translate("Filter useless"),
78 translate("Do not forward requests that cannot be answered by public name servers"))
79
80
81 s:taboption("advanced", Flag, "localise_queries",
82 translate("Localise queries"),
83 translate("Localise hostname depending on the requesting subnet if multiple IPs are available"))
84
85 local have_dnssec_support = luci.util.checklib("/usr/sbin/dnsmasq", "libhogweed.so")
86
87 if have_dnssec_support then
88 o = s:taboption("advanced", Flag, "dnssec",
89 translate("DNSSEC"))
90 o.optional = true
91
92 o = s:taboption("advanced", Flag, "dnsseccheckunsigned",
93 translate("DNSSEC check unsigned"),
94 translate("Requires upstream supports DNSSEC; verify unsigned domain responses really come from unsigned domains"))
95 o.optional = true
96 end
97
98 s:taboption("general", Value, "local",
99 translate("Local server"),
100 translate("Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only"))
101
102 s:taboption("general", Value, "domain",
103 translate("Local domain"),
104 translate("Local domain suffix appended to DHCP names and hosts file entries"))
105
106 s:taboption("advanced", Flag, "expandhosts",
107 translate("Expand hosts"),
108 translate("Add local domain suffix to names served from hosts files"))
109
110 s:taboption("advanced", Flag, "nonegcache",
111 translate("No negative cache"),
112 translate("Do not cache negative replies, e.g. for not existing domains"))
113
114 s:taboption("advanced", Value, "serversfile",
115 translate("Additional servers file"),
116 translate("This file may contain lines like 'server=/domain/1.2.3.4' or 'server=1.2.3.4' for"..
117 "domain-specific or full upstream <abbr title=\"Domain Name System\">DNS</abbr> servers."))
118
119 s:taboption("advanced", Flag, "strictorder",
120 translate("Strict order"),
121 translate("<abbr title=\"Domain Name System\">DNS</abbr> servers will be queried in the " ..
122 "order of the resolvfile")).optional = true
123
124
125 bn = s:taboption("advanced", DynamicList, "bogusnxdomain", translate("Bogus NX Domain Override"),
126 translate("List of hosts that supply bogus NX domain results"))
127
128 bn.optional = true
129 bn.placeholder = "67.215.65.132"
130
131
132 s:taboption("general", Flag, "logqueries",
133 translate("Log queries"),
134 translate("Write received DNS requests to syslog")).optional = true
135
136 df = s:taboption("general", DynamicList, "server", translate("DNS forwardings"),
137 translate("List of <abbr title=\"Domain Name System\">DNS</abbr> " ..
138 "servers to forward requests to"))
139
140 df.optional = true
141 df.placeholder = "/example.org/10.1.2.3"
142
143
144 rp = s:taboption("general", Flag, "rebind_protection",
145 translate("Rebind protection"),
146 translate("Discard upstream RFC1918 responses"))
147
148 rp.rmempty = false
149
150
151 rl = s:taboption("general", Flag, "rebind_localhost",
152 translate("Allow localhost"),
153 translate("Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services"))
154
155 rl:depends("rebind_protection", "1")
156
157
158 rd = s:taboption("general", DynamicList, "rebind_domain",
159 translate("Domain whitelist"),
160 translate("List of domains to allow RFC1918 responses for"))
161 rd.optional = true
162
163 rd:depends("rebind_protection", "1")
164 rd.datatype = "host(1)"
165 rd.placeholder = "ihost.netflix.com"
166
167
168 pt = s:taboption("advanced", Value, "port",
169 translate("<abbr title=\"Domain Name System\">DNS</abbr> server port"),
170 translate("Listening port for inbound DNS queries"))
171
172 pt.optional = true
173 pt.datatype = "port"
174 pt.placeholder = 53
175
176
177 qp = s:taboption("advanced", Value, "queryport",
178 translate("<abbr title=\"Domain Name System\">DNS</abbr> query port"),
179 translate("Fixed source port for outbound DNS queries"))
180
181 qp.optional = true
182 qp.datatype = "port"
183 qp.placeholder = translate("any")
184
185
186 lm = s:taboption("advanced", Value, "dhcpleasemax",
187 translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Dynamic Host Configuration " ..
188 "Protocol\">DHCP</abbr> leases"),
189 translate("Maximum allowed number of active DHCP leases"))
190
191 lm.optional = true
192 lm.datatype = "uinteger"
193 lm.placeholder = translate("unlimited")
194
195
196 em = s:taboption("advanced", Value, "ednspacket_max",
197 translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Extension Mechanisms for " ..
198 "Domain Name System\">EDNS0</abbr> packet size"),
199 translate("Maximum allowed size of EDNS.0 UDP packets"))
200
201 em.optional = true
202 em.datatype = "uinteger"
203 em.placeholder = 1280
204
205
206 cq = s:taboption("advanced", Value, "dnsforwardmax",
207 translate("<abbr title=\"maximal\">Max.</abbr> concurrent queries"),
208 translate("Maximum allowed number of concurrent DNS queries"))
209
210 cq.optional = true
211 cq.datatype = "uinteger"
212 cq.placeholder = 150
213
214
215 s:taboption("tftp", Flag, "enable_tftp",
216 translate("Enable TFTP server")).optional = true
217
218 tr = s:taboption("tftp", Value, "tftp_root",
219 translate("TFTP server root"),
220 translate("Root directory for files served via TFTP"))
221
222 tr.optional = true
223 tr:depends("enable_tftp", "1")
224 tr.placeholder = "/"
225
226
227 db = s:taboption("tftp", Value, "dhcp_boot",
228 translate("Network boot image"),
229 translate("Filename of the boot image advertised to clients"))
230
231 db.optional = true
232 db:depends("enable_tftp", "1")
233 db.placeholder = "pxelinux.0"
234
235 o = s:taboption("general", Flag, "localservice",
236 translate("Local Service Only"),
237 translate("Limit DNS service to subnets interfaces on which we are serving DNS."))
238 o.optional = false
239 o.rmempty = false
240
241 o = s:taboption("general", Flag, "nonwildcard",
242 translate("Non-wildcard"),
243 translate("Bind only to specific interfaces rather than wildcard address."))
244 o.optional = false
245 o.rmempty = false
246
247 o = s:taboption("general", DynamicList, "interface",
248 translate("Listen Interfaces"),
249 translate("Limit listening to these interfaces, and loopback."))
250 o.optional = true
251 o:depends("nonwildcard", true)
252
253 o = s:taboption("general", DynamicList, "notinterface",
254 translate("Exclude interfaces"),
255 translate("Prevent listening on these interfaces."))
256 o.optional = true
257 o:depends("nonwildcard", true)
258
259 m:section(SimpleSection).template = "admin_network/lease_status"
260
261 s = m:section(TypedSection, "host", translate("Static Leases"),
262 translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
263 "DHCP clients. They are also required for non-dynamic interface configurations where " ..
264 "only hosts with a corresponding lease are served.") .. "<br />" ..
265 translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
266 "indentifies the host, the <em>IPv4-Address</em> specifies to the fixed address to " ..
267 "use and the <em>Hostname</em> is assigned as symbolic name to the requesting host. " ..
268 "The optional <em>Lease time</em> can be used to set non-standard host-specific " ..
269 "lease time, e.g. 12h, 3d or infinite."))
270
271 s.addremove = true
272 s.anonymous = true
273 s.template = "cbi/tblsection"
274
275 name = s:option(Value, "name", translate("Hostname"))
276 name.datatype = "hostname"
277 name.rmempty = true
278
279 function name.write(self, section, value)
280 Value.write(self, section, value)
281 m:set(section, "dns", "1")
282 end
283
284 function name.remove(self, section)
285 Value.remove(self, section)
286 m:del(section, "dns")
287 end
288
289 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
290 mac.datatype = "list(macaddr)"
291 mac.rmempty = true
292
293 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
294 ip.datatype = "or(ip4addr,'ignore')"
295
296 time = s:option(Value, "leasetime", translate("Lease time"))
297 time.rmempty = true
298
299 hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
300
301 ipc.neighbors({ family = 4 }, function(n)
302 if n.mac and n.dest then
303 ip:value(n.dest:string())
304 mac:value(n.mac, "%s (%s)" %{ n.mac, n.dest:string() })
305 end
306 end)
307
308 function ip.validate(self, value, section)
309 local m = mac:formvalue(section) or ""
310 local n = name:formvalue(section) or ""
311 if value and #n == 0 and #m == 0 then
312 return nil, translate("One of hostname or mac address must be specified!")
313 end
314 return Value.validate(self, value, section)
315 end
316
317
318 return m