Merge pull request #680 from cshore/pull-request-dnsmasq-options
[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
62 s:taboption("advanced", Flag, "boguspriv",
63         translate("Filter private"),
64         translate("Do not forward reverse lookups for local networks"))
65
66 s:taboption("advanced", Flag, "filterwin2k",
67         translate("Filter useless"),
68         translate("Do not forward requests that cannot be answered by public name servers"))
69
70
71 s:taboption("advanced", Flag, "localise_queries",
72         translate("Localise queries"),
73         translate("Localise hostname depending on the requesting subnet if multiple IPs are available"))
74
75 local have_dnssec_support = luci.util.checklib("/usr/sbin/dnsmasq", "libhogweed.so")
76
77 if have_dnssec_support then
78         o = s:taboption("advanced", Flag, "dnssec",
79                 translate("DNSSEC"))
80         o.optional = true
81
82         o = s:taboption("advanced", Flag, "dnsseccheckunsigned",
83                 translate("DNSSEC check unsigned"),
84                 translate("Requires upstream supports DNSSEC; verify unsigned domain responses really come from unsigned domains"))
85         o.optional = true
86 end
87
88 s:taboption("general", Value, "local",
89         translate("Local server"),
90         translate("Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only"))
91
92 s:taboption("general", Value, "domain",
93         translate("Local domain"),
94         translate("Local domain suffix appended to DHCP names and hosts file entries"))
95
96 s:taboption("advanced", Flag, "expandhosts",
97         translate("Expand hosts"),
98         translate("Add local domain suffix to names served from hosts files"))
99
100 s:taboption("advanced", Flag, "nonegcache",
101         translate("No negative cache"),
102         translate("Do not cache negative replies, e.g. for not existing domains"))
103
104 s:taboption("advanced", Value, "serversfile",
105         translate("Additional servers file"),
106         translate("This file may contain lines like 'server=/domain/1.2.3.4' or 'server=1.2.3.4' for"..
107                 "domain-specific or full upstream <abbr title=\"Domain Name System\">DNS</abbr> servers."))
108
109 s:taboption("advanced", Flag, "strictorder",
110         translate("Strict order"),
111         translate("<abbr title=\"Domain Name System\">DNS</abbr> servers will be queried in the " ..
112                 "order of the resolvfile")).optional = true
113
114
115 bn = s:taboption("advanced", DynamicList, "bogusnxdomain", translate("Bogus NX Domain Override"),
116         translate("List of hosts that supply bogus NX domain results"))
117
118 bn.optional = true
119 bn.placeholder = "67.215.65.132"
120
121
122 s:taboption("general", Flag, "logqueries",
123         translate("Log queries"),
124         translate("Write received DNS requests to syslog")).optional = true
125
126 df = s:taboption("general", DynamicList, "server", translate("DNS forwardings"),
127         translate("List of <abbr title=\"Domain Name System\">DNS</abbr> " ..
128                         "servers to forward requests to"))
129
130 df.optional = true
131 df.placeholder = "/example.org/10.1.2.3"
132
133
134 rp = s:taboption("general", Flag, "rebind_protection",
135         translate("Rebind protection"),
136         translate("Discard upstream RFC1918 responses"))
137
138 rp.rmempty = false
139
140
141 rl = s:taboption("general", Flag, "rebind_localhost",
142         translate("Allow localhost"),
143         translate("Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services"))
144
145 rl:depends("rebind_protection", "1")
146
147
148 rd = s:taboption("general", DynamicList, "rebind_domain",
149         translate("Domain whitelist"),
150         translate("List of domains to allow RFC1918 responses for"))
151 rd.optional = true
152
153 rd:depends("rebind_protection", "1")
154 rd.datatype = "host(1)"
155 rd.placeholder = "ihost.netflix.com"
156
157
158 pt = s:taboption("advanced", Value, "port",
159         translate("<abbr title=\"Domain Name System\">DNS</abbr> server port"),
160         translate("Listening port for inbound DNS queries"))
161
162 pt.optional = true
163 pt.datatype = "port"
164 pt.placeholder = 53
165
166
167 qp = s:taboption("advanced", Value, "queryport",
168         translate("<abbr title=\"Domain Name System\">DNS</abbr> query port"),
169         translate("Fixed source port for outbound DNS queries"))
170
171 qp.optional = true
172 qp.datatype = "port"
173 qp.placeholder = translate("any")
174
175
176 lm = s:taboption("advanced", Value, "dhcpleasemax",
177         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Dynamic Host Configuration " ..
178                 "Protocol\">DHCP</abbr> leases"),
179         translate("Maximum allowed number of active DHCP leases"))
180
181 lm.optional = true
182 lm.datatype = "uinteger"
183 lm.placeholder = translate("unlimited")
184
185
186 em = s:taboption("advanced", Value, "ednspacket_max",
187         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Extension Mechanisms for " ..
188                 "Domain Name System\">EDNS0</abbr> packet size"),
189         translate("Maximum allowed size of EDNS.0 UDP packets"))
190
191 em.optional = true
192 em.datatype = "uinteger"
193 em.placeholder = 1280
194
195
196 cq = s:taboption("advanced", Value, "dnsforwardmax",
197         translate("<abbr title=\"maximal\">Max.</abbr> concurrent queries"),
198         translate("Maximum allowed number of concurrent DNS queries"))
199
200 cq.optional = true
201 cq.datatype = "uinteger"
202 cq.placeholder = 150
203
204
205 s:taboption("tftp", Flag, "enable_tftp",
206         translate("Enable TFTP server")).optional = true
207
208 tr = s:taboption("tftp", Value, "tftp_root",
209         translate("TFTP server root"),
210         translate("Root directory for files served via TFTP"))
211
212 tr.optional = true
213 tr:depends("enable_tftp", "1")
214 tr.placeholder = "/"
215
216
217 db = s:taboption("tftp", Value, "dhcp_boot",
218         translate("Network boot image"),
219         translate("Filename of the boot image advertised to clients"))
220
221 db.optional = true
222 db:depends("enable_tftp", "1")
223 db.placeholder = "pxelinux.0"
224
225 o = s:taboption("general", Flag, "localservice",
226         translate("Local Service Only"),
227         translate("Limit DNS service to subnets interfaces on which we are serving DNS."))
228 o.optional = false
229 o.rmempty = false
230
231 o = s:taboption("general", Flag, "nonwildcard",
232         translate("Non-wildcard"),
233         translate("Bind only to specific interfaces rather than wildcard address."))
234 o.optional = false
235 o.rmempty = false
236
237 o = s:taboption("general", DynamicList, "interface",
238         translate("Listen Interfaces"),
239         translate("Limit listening to these interfaces, and loopback."))
240 o.optional = true
241 o:depends("nonwildcard", true)
242
243 o = s:taboption("general", DynamicList, "notinterface",
244         translate("Exclude interfaces"),
245         translate("Prevent listening on thise interfaces."))
246 o.optional = true
247 o:depends("nonwildcard", true)
248
249 m:section(SimpleSection).template = "admin_network/lease_status"
250
251 s = m:section(TypedSection, "host", translate("Static Leases"),
252         translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
253                 "DHCP clients. They are also required for non-dynamic interface configurations where " ..
254                 "only hosts with a corresponding lease are served.") .. "<br />" ..
255         translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
256                 "indentifies the host, the <em>IPv4-Address</em> specifies to the fixed address to " ..
257                 "use and the <em>Hostname</em> is assigned as symbolic name to the requesting host. " ..
258                 "The optional <em>Lease time</em> can be used to set non-standard host-specific " ..
259                 "lease time, e.g. 12h, 3d or infinite."))
260
261 s.addremove = true
262 s.anonymous = true
263 s.template = "cbi/tblsection"
264
265 name = s:option(Value, "name", translate("Hostname"))
266 name.datatype = "hostname"
267 name.rmempty  = true
268
269 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
270 mac.datatype = "list(macaddr)"
271 mac.rmempty  = true
272
273 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
274 ip.datatype = "or(ip4addr,'ignore')"
275
276 time = s:option(Value, "leasetime", translate("Lease time"))
277 time.rmempty  = true
278
279 hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
280
281 ipc.neighbors({ family = 4 }, function(n)
282         if n.mac and n.dest then
283                 ip:value(n.dest:string())
284                 mac:value(n.mac, "%s (%s)" %{ n.mac, n.dest:string() })
285         end
286 end)
287
288 function ip.validate(self, value, section)
289         local m = mac:formvalue(section) or ""
290         local n = name:formvalue(section) or ""
291         if value and #n == 0 and #m == 0 then
292                 return nil, translate("One of hostname or mac address must be specified!")
293         end
294         return Value.validate(self, value, section)
295 end
296
297
298 return m