1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2016 Eric Luehrsen <ericluehrsen@gmail.com>
3 -- Copyright 2016 Dan Luedtke <mail@danrl.com>
4 -- Licensed to the public under the Apache License 2.0.
7 local ena, mcf, lci, lsv
8 local rlh, rpv, vld, nvd, eds, prt, tlm
9 local ctl, dlk, dom, dty, lfq, wfq, exa
10 local dp6, d64, pfx, qry, qrs
11 local pro, tgr, rsc, rsn, ag2, stt
14 local ut = require "luci.util"
15 local sy = require "luci.sys"
16 local ht = require "luci.http"
17 local ds = require "luci.dispatcher"
18 local ucl = luci.model.uci.cursor()
19 local valman = ucl:get_first("unbound", "unbound", "manual_conf")
22 s1 = m1:section(TypedSection, "unbound", translate("Recursive DNS"),
23 translatef("Unbound <a href=\"%s\" target=\"_blank\">(NLnet Labs)</a>"
24 .. " is a validating, recursive, and caching DNS resolver"
25 .. " <a href=\"%s\" target=\"_blank\">(help)</a>.",
26 "https://www.unbound.net/",
27 "https://github.com/openwrt/packages/blob/master/net/unbound/files/README.md"))
32 --LuCI, Unbound, or Not
33 s1:tab("basic", translate("Basic"))
36 if (valman == "0") then
37 -- Not in manual configuration mode; show UCI
38 s1:tab("advanced", translate("Advanced"))
39 s1:tab("DHCP", translate("DHCP"))
40 s1:tab("resource", translate("Resource"))
44 --Basic Tab, unconditional pieces
45 ena = s1:taboption("basic", Flag, "enabled", translate("Enable Unbound"),
46 translate("Enable the initialization scripts for Unbound"))
49 mcf = s1:taboption("basic", Flag, "manual_conf", translate("Manual Conf"),
50 translate("Skip UCI and use /etc/unbound/unbound.conf"))
54 if (valman == "0") then
55 -- Not in manual configuration mode; show UCI
57 lsv = s1:taboption("basic", Flag, "localservice",
58 translate("Local Service"),
59 translate("Accept queries only from local subnets"))
62 vld = s1:taboption("basic", Flag, "validator",
63 translate("Enable DNSSEC"),
64 translate("Enable the DNSSEC validator module"))
67 nvd = s1:taboption("basic", Flag, "validator_ntp",
68 translate("DNSSEC NTP Fix"),
69 translate("Break the loop where DNSSEC needs NTP and NTP needs DNS"))
71 nvd:depends("validator", true)
73 prt = s1:taboption("basic", Value, "listen_port",
74 translate("Listening Port"),
75 translate("Choose Unbounds listening port"))
77 prt.placeholder = "53"
80 rlh = s1:taboption("advanced", Flag, "rebind_localhost",
81 translate("Filter Localhost Rebind"),
82 translate("Protect against upstream response of 127.0.0.0/8"))
85 rpv = s1:taboption("advanced", ListValue, "rebind_protection",
86 translate("Filter Private Rebind"),
87 translate("Protect against upstream responses within local subnets"))
88 rpv:value("0", translate("No Filter"))
89 rpv:value("1", translate("Filter Private Address"))
90 rpv:value("2", translate("Filter Entire Subnet"))
93 d64 = s1:taboption("advanced", Flag, "dns64", translate("Enable DNS64"),
94 translate("Enable the DNS64 module"))
97 pfx = s1:taboption("advanced", Value, "dns64_prefix",
98 translate("DNS64 Prefix"),
99 translate("Prefix for generated DNS64 addresses"))
100 pfx.datatype = "ip6addr"
101 pfx.placeholder = "64:ff9b::/96"
103 pfx:depends("dns64", true)
105 din = s1:taboption("advanced", DynamicList, "domain_insecure",
106 translate("Domain Insecure"),
107 translate("List domains to bypass checks of DNSSEC"))
108 din:depends("validator", true)
110 ag2 = s1:taboption("advanced", Value, "root_age",
111 translate("Root DSKEY Age"),
112 translate("Limit days between RFC5011 copies to reduce flash writes"))
113 ag2.datatype = "and(uinteger,min(1),max(99))"
115 ag2:value("9", "9 ("..translate("default")..")")
116 ag2:value("12", "12")
117 ag2:value("24", "24")
118 ag2:value("99", "99 ("..translate("never")..")")
120 tgr = s1:taboption("advanced", Value, "trigger_interface",
121 translate("Trigger Networks"),
122 translate("Networks that may trigger Unbound to reload (avoid wan6)"))
123 tgr.template = "cbi/network_netlist"
124 tgr.widget = "checkbox"
130 dlk = s1:taboption("DHCP", ListValue, "dhcp_link",
131 translate("DHCP Link"),
132 translate("Link to supported programs to load DHCP into DNS"))
133 dlk:value("none", translate("No Link"))
134 dlk:value("dnsmasq", "dnsmasq")
135 dlk:value("odhcpd", "odhcpd")
138 dp6 = s1:taboption("DHCP", Flag, "dhcp4_slaac6",
139 translate("DHCPv4 to SLAAC"),
140 translate("Use DHCPv4 MAC to discover IP6 hosts SLAAC (EUI64)"))
142 dp6:depends("dhcp_link", "odhcpd")
144 dom = s1:taboption("DHCP", Value, "domain",
145 translate("Local Domain"),
146 translate("Domain suffix for this router and DHCP clients"))
147 dom.placeholder = "lan"
149 dom:depends("dhcp_link", "none")
150 dom:depends("dhcp_link", "odhcpd")
152 dty = s1:taboption("DHCP", ListValue, "domain_type",
153 translate("Local Domain Type"),
154 translate("How to treat queries of this local domain"))
156 dty:value("deny", translate("Denied (nxdomain)"))
157 dty:value("refuse", translate("Refused"))
158 dty:value("static", translate("Static (local only)"))
159 dty:value("transparent", translate("Transparent (local/global)"))
160 dty:depends("dhcp_link", "none")
161 dty:depends("dhcp_link", "odhcpd")
163 lfq = s1:taboption("DHCP", ListValue, "add_local_fqdn",
164 translate("LAN DNS"),
165 translate("How to enter the LAN or local network router in DNS"))
167 lfq:value("0", translate("No Entry"))
168 lfq:value("1", translate("Hostname, Primary Address"))
169 lfq:value("2", translate("Hostname, All Addresses"))
170 lfq:value("3", translate("Host FQDN, All Addresses"))
171 lfq:value("4", translate("Interface FQDN, All Addresses"))
172 lfq:depends("dhcp_link", "none")
173 lfq:depends("dhcp_link", "odhcpd")
175 wfq = s1:taboption("DHCP", ListValue, "add_wan_fqdn",
176 translate("WAN DNS"),
177 translate("Override the WAN side router entry in DNS"))
179 wfq:value("0", translate("Use Upstream"))
180 wfq:value("1", translate("Hostname, Primary Address"))
181 wfq:value("2", translate("Hostname, All Addresses"))
182 wfq:value("3", translate("Host FQDN, All Addresses"))
183 wfq:value("4", translate("Interface FQDN, All Addresses"))
184 wfq:depends("dhcp_link", "none")
185 wfq:depends("dhcp_link", "odhcpd")
187 exa = s1:taboption("DHCP", ListValue, "add_extra_dns",
188 translate("Extra DNS"),
189 translate("Use extra DNS entries found in /etc/config/dhcp"))
191 exa:value("0", translate("Ignore"))
192 exa:value("1", translate("Host Records"))
193 exa:value("2", translate("Host/MX/SRV RR"))
194 exa:value("3", translate("Host/MX/SRV/CNAME RR"))
195 exa:depends("dhcp_link", "none")
196 exa:depends("dhcp_link", "odhcpd")
198 --TODO: dnsmasq needs to not reference resolve-file and get off port 53.
200 --Resource Tuning Tab
201 ctl = s1:taboption("resource", ListValue, "unbound_control",
202 translate("Unbound Control App"),
203 translate("Enable access for unbound-control"))
205 ctl:value("0", translate("No Remote Control"))
206 ctl:value("1", translate("Local Host, No Encryption"))
207 ctl:value("2", translate("Local Host, Encrypted"))
208 ctl:value("3", translate("Local Subnet, Encrypted"))
209 ctl:value("4", translate("Local Subnet, Static Encryption"))
211 pro = s1:taboption("resource", ListValue, "protocol",
212 translate("Recursion Protocol"),
213 translate("Chose the protocol recursion queries leave on"))
214 pro:value("default", translate("Default"))
215 pro:value("ip4_only", translate("IP4 Only"))
216 pro:value("ip6_only", translate("IP6 Only"))
217 pro:value("ip6_prefer", translate("IP6 Preferred"))
218 pro:value("mixed", translate("IP4 and IP6"))
221 rsc = s1:taboption("resource", ListValue, "resource",
222 translate("Memory Resource"),
223 translate("Use menu System/Processes to observe any memory growth"))
224 rsc:value("default", translate("Default"))
225 rsc:value("tiny", translate("Tiny"))
226 rsc:value("small", translate("Small"))
227 rsc:value("medium", translate("Medium"))
228 rsc:value("large", translate("Large"))
231 rsn = s1:taboption("resource", ListValue, "recursion",
232 translate("Recursion Strength"),
233 translate("Recursion activity affects memory growth and CPU load"))
234 rsn:value("default", translate("Default"))
235 rsn:value("passive", translate("Passive"))
236 rsn:value("aggressive", translate("Aggressive"))
239 qry = s1:taboption("resource", Flag, "query_minimize",
240 translate("Query Minimize"),
241 translate("Break down query components for limited added privacy"))
243 qry:depends("recursion", "passive")
244 qry:depends("recursion", "aggressive")
246 qrs = s1:taboption("resource", Flag, "query_min_strict",
247 translate("Strict Minimize"),
248 translate("Strict version of 'query minimize' but it can break DNS"))
250 qrs:depends("query_minimize", true)
252 eds = s1:taboption("resource", Value, "edns_size",
253 translate("EDNS Size"),
254 translate("Limit extended DNS packet size"))
255 eds.datatype = "and(uinteger,min(512),max(4096))"
256 eds.placeholder = "1280"
258 tlm = s1:taboption("resource", Value, "ttl_min",
259 translate("TTL Minimum"),
260 translate("Prevent excessively short cache periods"))
261 tlm.datatype = "and(uinteger,min(0),max(1200))"
262 tlm.placeholder = "120"
264 stt = s1:taboption("resource", Flag, "extended_stats",
265 translate("Extended Statistics"),
266 translate("Extended statistics are printed from unbound-control"))
270 ag2 = s1:taboption("basic", Value, "root_age",
271 translate("Root DSKEY Age"),
272 translate("Limit days between RFC5011 copies to reduce flash writes"))
273 ag2.datatype = "and(uinteger,min(1),max(99))"
275 ag2:value("9", "9 ("..translate("default")..")")
276 ag2:value("12", "12")
277 ag2:value("24", "24")
278 ag2:value("99", "99 ("..translate("never")..")")
280 tgr = s1:taboption("basic", Value, "trigger_interface",
281 translate("Trigger Networks"),
282 translate("Networks that may trigger Unbound to reload (avoid wan6)"))
283 tgr.template = "cbi/network_netlist"
284 tgr.widget = "checkbox"
291 function ena.cfgvalue(self, section)
292 return sy.init.enabled("unbound") and self.enabled or self.disabled
296 function ena.write(self, section, value)
297 if (value == "1") then
298 sy.init.enable("unbound")
299 sy.call("/etc/init.d/unbound start >/dev/null 2>&1")
302 sy.call("/etc/init.d/unbound stop >/dev/null 2>&1")
303 sy.init.disable("unbound")
307 return Flag.write(self, section, value)
311 function m1.on_commit(self)
312 if sy.init.enabled("unbound") then
313 -- Restart Unbound with configuration
314 sy.call("/etc/init.d/unbound restart >/dev/null 2>&1")
317 sy.call("/etc/init.d/unbound stop >/dev/null 2>&1")
322 function m1.on_apply(self)
323 -- reload the page because some options hide
324 ht.redirect(ds.build_url("admin", "services", "unbound", "configure"))