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