Merge pull request #393 from nmav/no-group-match
[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
6 m = Map("dhcp", translate("DHCP and DNS"),
7         translate("Dnsmasq is a combined <abbr title=\"Dynamic Host Configuration Protocol" ..
8                 "\">DHCP</abbr>-Server and <abbr title=\"Domain Name System\">DNS</abbr>-" ..
9                 "Forwarder for <abbr title=\"Network Address Translation\">NAT</abbr> " ..
10                 "firewalls"))
11
12 s = m:section(TypedSection, "dnsmasq", translate("Server Settings"))
13 s.anonymous = true
14 s.addremove = false
15
16 s:tab("general", translate("General Settings"))
17 s:tab("files", translate("Resolv and Hosts Files"))
18 s:tab("tftp", translate("TFTP Settings"))
19 s:tab("advanced", translate("Advanced Settings"))
20
21 s:taboption("general", Flag, "domainneeded",
22         translate("Domain required"),
23         translate("Don't forward <abbr title=\"Domain Name System\">DNS</abbr>-Requests without " ..
24                 "<abbr title=\"Domain Name System\">DNS</abbr>-Name"))
25
26 s:taboption("general", Flag, "authoritative",
27         translate("Authoritative"),
28         translate("This is the only <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
29                 "abbr> in the local network"))
30
31
32 s:taboption("files", Flag, "readethers",
33         translate("Use <code>/etc/ethers</code>"),
34         translate("Read <code>/etc/ethers</code> to configure the <abbr title=\"Dynamic Host " ..
35                 "Configuration Protocol\">DHCP</abbr>-Server"))
36
37 s:taboption("files", Value, "leasefile",
38         translate("Leasefile"),
39         translate("file where given <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</" ..
40                 "abbr>-leases will be stored"))
41
42 s:taboption("files", Flag, "noresolv",
43         translate("Ignore resolve file")).optional = true
44
45 rf = s:taboption("files", Value, "resolvfile",
46         translate("Resolve file"),
47         translate("local <abbr title=\"Domain Name System\">DNS</abbr> file"))
48
49 rf:depends("noresolv", "")
50 rf.optional = true
51
52
53 s:taboption("files", Flag, "nohosts",
54         translate("Ignore Hosts files")).optional = true
55
56 hf = s:taboption("files", DynamicList, "addnhosts",
57         translate("Additional Hosts files"))
58
59 hf:depends("nohosts", "")
60 hf.optional = true
61
62
63 s:taboption("advanced", Flag, "boguspriv",
64         translate("Filter private"),
65         translate("Do not forward reverse lookups for local networks"))
66
67 s:taboption("advanced", Flag, "filterwin2k",
68         translate("Filter useless"),
69         translate("Do not forward requests that cannot be answered by public name servers"))
70
71
72 s:taboption("advanced", Flag, "localise_queries",
73         translate("Localise queries"),
74         translate("Localise hostname depending on the requesting subnet if multiple IPs are available"))
75
76 s:taboption("general", Value, "local",
77         translate("Local server"),
78         translate("Local domain specification. Names matching this domain are never forwarded and are resolved from DHCP or hosts files only"))
79
80 s:taboption("general", Value, "domain",
81         translate("Local domain"),
82         translate("Local domain suffix appended to DHCP names and hosts file entries"))
83
84 s:taboption("advanced", Flag, "expandhosts",
85         translate("Expand hosts"),
86         translate("Add local domain suffix to names served from hosts files"))
87
88 s:taboption("advanced", Flag, "nonegcache",
89         translate("No negative cache"),
90         translate("Do not cache negative replies, e.g. for not existing domains"))
91
92 s:taboption("advanced", Value, "serversfile",
93         translate("Additional servers file"),
94         translate("This file may contain lines like 'server=/domain/1.2.3.4' or 'server=1.2.3.4' for"..
95                 "domain-specific or full upstream <abbr title=\"Domain Name System\">DNS</abbr> servers."))
96
97 s:taboption("advanced", Flag, "strictorder",
98         translate("Strict order"),
99         translate("<abbr title=\"Domain Name System\">DNS</abbr> servers will be queried in the " ..
100                 "order of the resolvfile")).optional = true
101
102
103 bn = s:taboption("advanced", DynamicList, "bogusnxdomain", translate("Bogus NX Domain Override"),
104         translate("List of hosts that supply bogus NX domain results"))
105
106 bn.optional = true
107 bn.placeholder = "67.215.65.132"
108
109
110 s:taboption("general", Flag, "logqueries",
111         translate("Log queries"),
112         translate("Write received DNS requests to syslog")).optional = true
113
114 df = s:taboption("general", DynamicList, "server", translate("DNS forwardings"),
115         translate("List of <abbr title=\"Domain Name System\">DNS</abbr> " ..
116                         "servers to forward requests to"))
117
118 df.optional = true
119 df.placeholder = "/example.org/10.1.2.3"
120
121
122 rp = s:taboption("general", Flag, "rebind_protection",
123         translate("Rebind protection"),
124         translate("Discard upstream RFC1918 responses"))
125
126 rp.rmempty = false
127
128
129 rl = s:taboption("general", Flag, "rebind_localhost",
130         translate("Allow localhost"),
131         translate("Allow upstream responses in the 127.0.0.0/8 range, e.g. for RBL services"))
132
133 rl:depends("rebind_protection", "1")
134
135
136 rd = s:taboption("general", DynamicList, "rebind_domain",
137         translate("Domain whitelist"),
138         translate("List of domains to allow RFC1918 responses for"))
139
140 rd:depends("rebind_protection", "1")
141 rd.datatype = "host"
142 rd.placeholder = "ihost.netflix.com"
143
144
145 pt = s:taboption("advanced", Value, "port",
146         translate("<abbr title=\"Domain Name System\">DNS</abbr> server port"),
147         translate("Listening port for inbound DNS queries"))
148
149 pt.optional = true
150 pt.datatype = "port"
151 pt.placeholder = 53
152
153
154 qp = s:taboption("advanced", Value, "queryport",
155         translate("<abbr title=\"Domain Name System\">DNS</abbr> query port"),
156         translate("Fixed source port for outbound DNS queries"))
157
158 qp.optional = true
159 qp.datatype = "port"
160 qp.placeholder = translate("any")
161
162
163 lm = s:taboption("advanced", Value, "dhcpleasemax",
164         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Dynamic Host Configuration " ..
165                 "Protocol\">DHCP</abbr> leases"),
166         translate("Maximum allowed number of active DHCP leases"))
167
168 lm.optional = true
169 lm.datatype = "uinteger"
170 lm.placeholder = translate("unlimited")
171
172
173 em = s:taboption("advanced", Value, "ednspacket_max",
174         translate("<abbr title=\"maximal\">Max.</abbr> <abbr title=\"Extension Mechanisms for " ..
175                 "Domain Name System\">EDNS0</abbr> packet size"),
176         translate("Maximum allowed size of EDNS.0 UDP packets"))
177
178 em.optional = true
179 em.datatype = "uinteger"
180 em.placeholder = 1280
181
182
183 cq = s:taboption("advanced", Value, "dnsforwardmax",
184         translate("<abbr title=\"maximal\">Max.</abbr> concurrent queries"),
185         translate("Maximum allowed number of concurrent DNS queries"))
186
187 cq.optional = true
188 cq.datatype = "uinteger"
189 cq.placeholder = 150
190
191
192 s:taboption("tftp", Flag, "enable_tftp",
193         translate("Enable TFTP server")).optional = true
194
195 tr = s:taboption("tftp", Value, "tftp_root",
196         translate("TFTP server root"),
197         translate("Root directory for files served via TFTP"))
198
199 tr.optional = true
200 tr:depends("enable_tftp", "1")
201 tr.placeholder = "/"
202
203
204 db = s:taboption("tftp", Value, "dhcp_boot",
205         translate("Network boot image"),
206         translate("Filename of the boot image advertised to clients"))
207
208 db.optional = true
209 db:depends("enable_tftp", "1")
210 db.placeholder = "pxelinux.0"
211
212
213 m:section(SimpleSection).template = "admin_network/lease_status"
214
215 s = m:section(TypedSection, "host", translate("Static Leases"),
216         translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
217                 "DHCP clients. They are also required for non-dynamic interface configurations where " ..
218                 "only hosts with a corresponding lease are served.") .. "<br />" ..
219         translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
220                 "indentifies the host, the <em>IPv4-Address</em> specifies to the fixed address to " ..
221                 "use and the <em>Hostname</em> is assigned as symbolic name to the requesting host."))
222
223 s.addremove = true
224 s.anonymous = true
225 s.template = "cbi/tblsection"
226
227 name = s:option(Value, "name", translate("Hostname"))
228 name.datatype = "hostname"
229 name.rmempty  = true
230
231 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
232 mac.datatype = "list(macaddr)"
233 mac.rmempty  = true
234
235 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
236 ip.datatype = "or(ip4addr,'ignore')"
237
238 hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
239
240 ipc.neighbors({ family = 4 }, function(n)
241         if n.mac and n.dest then
242                 ip:value(n.dest:string())
243                 mac:value(n.mac, "%s (%s)" %{ n.mac, n.dest:string() })
244         end
245 end)
246
247 function ip.validate(self, value, section)
248         local m = mac:formvalue(section) or ""
249         local n = name:formvalue(section) or ""
250         if value and #n == 0 and #m == 0 then
251                 return nil, translate("One of hostname or mac address must be specified!")
252         end
253         return Value.validate(self, value, section)
254 end
255
256
257 return m