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