luci-app-unbound: add statistics and manual edit tabs
[project/luci.git] / applications / luci-app-unbound / luasrc / model / cbi / unbound / configure.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2016 Eric Luehrsen <ericluehrsen@hotmail.com>
3 -- Copyright 2016 Dan Luedtke <mail@danrl.com>
4 -- Licensed to the public under the Apache License 2.0.
5
6 local m1, s1
7 local ena, mcf, lci, lsv, rlh, rpv, vld, nvd, eds, prt, tlm
8 local ctl, dlk, dom, dty, lfq, wfq, exa, dp6, d64, pfx, qry, qrs
9 local pro, tgr, rsc, rsn, ag2
10 local ucl = luci.model.uci.cursor()
11 local valman = ucl:get_first("unbound", "unbound", "manual_conf")
12
13 m1 = Map("unbound")
14
15 s1 = m1:section(TypedSection, "unbound")
16 s1.addremove = false
17 s1.anonymous = true
18
19 --LuCI, Unbound, or Not
20 s1:tab("basic", translate("Basic"),
21   translatef("<h3>Unbound Basic Settings</h3>\n"
22   .. "<a href=\"%s\" target=\"_blank\">Unbound</a>"
23   .. " is a validating, recursive, and caching DNS resolver. "
24   .. "UCI help can be found on "
25   .. "<a href=\"%s\" target=\"_blank\">github</a>.",
26   "https://www.unbound.net/",
27   "https://github.com/openwrt/packages/blob/master/net/unbound/files/README.md"))
28
29 ena = s1:taboption("basic", Flag, "enabled", translate("Enable Unbound:"),
30   translate("Enable the initialization scripts for Unbound"))
31 ena.rmempty = false
32
33 mcf = s1:taboption("basic", Flag, "manual_conf", translate("Manual Conf:"),
34   translate("Skip UCI and use /etc/unbound/unbound.conf"))
35 mcf.rmempty = false
36
37 lci = s1:taboption("basic", Flag, "luci_expanded", translate("LuCI Expanded:"),
38   translate("See more detailed tabs for debug"))
39 lci.rmempty = false
40
41
42 function ena.cfgvalue(self, section)
43   return luci.sys.init.enabled("unbound") and self.enabled or self.disabled
44 end
45
46
47 function ena.write(self, section, value)
48   if value == "1" then
49     luci.sys.init.enable("unbound")
50     luci.sys.call("/etc/init.d/unbound start >/dev/null")
51   else
52     luci.sys.call("/etc/init.d/unbound stop >/dev/null")
53     luci.sys.init.disable("unbound")
54   end
55
56   return Flag.write(self, section, value)
57 end
58
59
60 if valman ~= "1" then
61   -- Not in manual configuration mode; show UCI
62   s1:tab("advanced", translate("Advanced"),
63     translatef("<h3>Unbound Advanced Settings</h3>\n"
64     .. "Advanced setttings and plugin modules for "
65     .. "<a href=\"%s\" target=\"_blank\">Unbound</a>"
66     .. " DNS resolver.", "https://www.unbound.net/"))
67
68   s1:tab("resource", translate("Resource"),
69     translatef("<h3>Unbound Resource Settings</h3>\n"
70     .. "Memory and protocol setttings for "
71     .. "<a href=\"%s\" target=\"_blank\">Unbound</a>"
72     .. " DNS resolver.", "https://www.unbound.net/"))
73
74   --Basic Tab
75   lsv = s1:taboption("basic", Flag, "localservice", translate("Local Service:"),
76     translate("Accept queries only from local subnets"))
77   lsv.rmempty = false
78
79   rlh = s1:taboption("basic", Flag, "rebind_localhost", translate("Block Localhost Rebind:"),
80     translate("Prevent upstream response of 127.0.0.0/8"))
81   rlh.rmempty = false
82
83   rpv = s1:taboption("basic", Flag, "rebind_protection", translate("Block Private Rebind:"),
84     translate("Prevent upstream response of RFC1918 ranges"))
85   rpv.rmempty = false
86
87   vld = s1:taboption("basic", Flag, "validator", translate("Enable DNSSEC:"),
88     translate("Enable the DNSSEC validator module"))
89   vld.rmempty = false
90
91   nvd = s1:taboption("basic", Flag, "validator_ntp", translate("DNSSEC NTP Fix:"),
92     translate("Break the loop where DNSSEC needs NTP and NTP needs DNS"))
93   nvd.rmempty = false
94   nvd:depends({ validator = true })
95
96   eds = s1:taboption("basic", Value, "edns_size", translate("EDNS Size:"),
97     translate("Limit extended DNS packet size"))
98   eds.datatype = "and(uinteger,min(512),max(4096))"
99   eds.rmempty = false
100
101   prt = s1:taboption("basic", Value, "listen_port", translate("Listening Port:"),
102     translate("Choose Unbounds listening port"))
103   prt.datatype = "port"
104   prt.rmempty = false
105
106   tlm = s1:taboption("basic", Value, "ttl_min", translate("TTL Minimum:"),
107     translate("Prevent excessively short cache periods"))
108   tlm.datatype = "and(uinteger,min(0),max(600))"
109   tlm.rmempty = false
110
111   --Advanced Tab
112   ctl = s1:taboption("advanced", Flag, "unbound_control", translate("Unbound Control App:"),
113     translate("Enable unecrypted localhost access for unbound-control"))
114   ctl.rmempty = false
115
116   dlk = s1:taboption("advanced", ListValue, "dhcp_link", translate("DHCP Link:"),
117     translate("Link to supported programs to load DHCP into DNS"))
118   dlk:value("none", translate("No Link"))
119   dlk:value("dnsmasq", "dnsmasq")
120   dlk:value("odhcpd", "odhcpd")
121   dlk.rmempty = false
122
123   dom = s1:taboption("advanced", Value, "domain", translate("Local Domain:"),
124     translate("Domain suffix for this router and DHCP clients"))
125   dom.placeholder = "lan"
126   dom:depends({ dhcp_link = "none" })
127   dom:depends({ dhcp_link = "odhcpd" })
128
129   dty = s1:taboption("advanced", ListValue, "domain_type", translate("Local Domain Type:"),
130     translate("How to treat queries of this local domain"))
131   dty:value("deny", translate("Ignored"))
132   dty:value("refuse", translate("Refused"))
133   dty:value("static", translate("Only Local"))
134   dty:value("transparent", translate("Also Forwarded"))
135   dty:depends({ dhcp_link = "none" })
136   dty:depends({ dhcp_link = "odhcpd" })
137
138   lfq = s1:taboption("advanced", ListValue, "add_local_fqdn", translate("LAN DNS:"),
139     translate("How to enter the LAN or local network router in DNS"))
140   lfq:value("0", translate("No DNS"))
141   lfq:value("1", translate("Hostname, Primary Address"))
142   lfq:value("2", translate("Hostname, All Addresses"))
143   lfq:value("3", translate("Host FQDN, All Addresses"))
144   lfq:value("4", translate("Interface FQDN, All Addresses"))
145   lfq:depends({ dhcp_link = "none" })
146   lfq:depends({ dhcp_link = "odhcpd" })
147
148   wfq = s1:taboption("advanced", ListValue, "add_wan_fqdn", translate("WAN DNS:"),
149     translate("Override the WAN side router entry in DNS"))
150   wfq:value("0", translate("Upstream"))
151   wfq:value("1", translate("Hostname, Primary Address"))
152   wfq:value("2", translate("Hostname, All Addresses"))
153   wfq:value("3", translate("Host FQDN, All Addresses"))
154   wfq:value("4", translate("Interface FQDN, All Addresses"))
155   wfq:depends({ dhcp_link = "none" })
156   wfq:depends({ dhcp_link = "odhcpd" })
157
158   exa = s1:taboption("advanced", ListValue, "add_extra_dns", translate("Extra DNS:"),
159     translate("Use extra DNS entries found in /etc/config/dhcp"))
160   exa:value("0", translate("Ignore"))
161   exa:value("1", translate("Include Network/Hostnames"))
162   exa:value("2", translate("Advanced MX/SRV RR"))
163   exa:value("3", translate("Advanced CNAME RR"))
164   exa:depends({ dhcp_link = "none" })
165   exa:depends({ dhcp_link = "odhcpd" })
166
167   dp6 = s1:taboption("advanced", Flag, "dhcp4_slaac6", translate("DHCPv4 to SLAAC:"),
168     translate("Use DHCPv4 MAC to discover IP6 hosts SLAAC (EUI64)"))
169   dp6.rmempty = false
170
171   d64 = s1:taboption("advanced", Flag, "dns64", translate("Enable DNS64:"),
172     translate("Enable the DNS64 module"))
173   d64.rmempty = false
174
175   pfx = s1:taboption("advanced", Value, "dns64_prefix", translate("DNS64 Prefix:"),
176     translate("Prefix for generated DNS64 addresses"))
177   pfx.datatype = "ip6addr"
178   pfx.placeholder = "64:ff9b::/96"
179   pfx.optional = true
180   pfx:depends({ dns64 = true })
181
182   qry = s1:taboption("advanced", Flag, "query_minimize", translate("Query Minimize:"),
183     translate("Break down query components for limited added privacy"))
184   qry.rmempty = false
185
186   qrs = s1:taboption("advanced", Flag, "query_min_strict", translate("Strict Minimize:"),
187     translate("Strict version of 'query minimize' but it can break DNS"))
188   qrs.rmempty = false
189   qrs:depends({ query_minimize = true })
190
191   --TODO: dnsmasq needs to not reference resolve-file and get off port 53.
192
193   --Resource Tuning Tab
194   pro = s1:taboption("resource", ListValue, "protocol", translate("Recursion Protocol:"),
195     translate("Chose the protocol recursion queries leave on"))
196   pro:value("mixed", translate("IP4 and IP6"))
197   pro:value("ip6_prefer", translate("IP6 Preferred"))
198   pro:value("ip4_only", translate("IP4 Only"))
199   pro:value("ip6_only", translate("IP6 Only"))
200   pro.rmempty = false
201
202   rsn = s1:taboption("resource", ListValue, "recursion", translate("Recursion Strength:"),
203     translate("Recursion activity affects memory growth and CPU load"))
204   rsn:value("aggressive", translate("Aggressive"))
205   rsn:value("default", translate("Default"))
206   rsn:value("passive", translate("Passive"))
207   rsn.rmempty = false
208
209   rsc = s1:taboption("resource", ListValue, "resource", translate("Memory Resource:"),
210     translate("Use menu System/Processes to observe any memory growth"))
211   rsc:value("large", translate("Large"))
212   rsc:value("medium", translate("Medium"))
213   rsc:value("small", translate("Small"))
214   rsc:value("tiny", translate("Tiny"))
215   rsc.rmempty = false
216
217   ag2 = s1:taboption("resource", Value, "root_age", translate("Root DSKEY Age:"),
218     translate("Limit days between RFC5011 to reduce flash writes"))
219   ag2.datatype = "and(uinteger,min(1),max(99))"
220   ag2:value("3", "3")
221   ag2:value("9", "9 ("..translate("default")..")")
222   ag2:value("12", "12")
223   ag2:value("24", "24")
224   ag2:value("99", "99 ("..translate("never")..")")
225
226   tgr = s1:taboption("resource", Value, "trigger", translate("Trigger Networks:"),
227     translate("Networks that may trigger Unbound to reload (avoid wan6)"))
228   tgr.template = "cbi/network_netlist"
229   tgr.widget = "checkbox"
230   tgr.cast = "string"
231
232 else
233   s1:tab("rfc5011", translate("RFC5011"),
234     translatef("<h3>Unbound RFC5011 Settings</h3>\n"
235     .. "RFC5011 copy scripts protect flash ROM even with UCI disabled."))
236
237   ag2 = s1:taboption("rfc5011", Value, "root_age", translate("Root DSKEY Age:"),
238     translate("Limit days to copy /var/->/etc/ to reduce flash writes"))
239   ag2.datatype = "and(uinteger,min(1),max(99))"
240   ag2:value("3", "3")
241   ag2:value("9", "9 ("..translate("default")..")")
242   ag2:value("12", "12")
243   ag2:value("24", "24")
244   ag2:value("99", "99 ("..translate("never")..")")
245 end
246
247
248 function m1.on_after_commit(self)
249   function ena.validate(self, value)
250     if value ~= "0" then
251       luci.sys.call("/etc/init.d/unbound restart >/dev/null 2>&1")
252     else
253       luci.sys.call("/etc/init.d/unbound stop >/dev/null 2>&1")
254     end
255   end
256
257
258   -- Restart Unbound with configuration and reload the page (some options hide)
259   luci.http.redirect(luci.dispatcher.build_url("admin", "services", "unbound"))
260 end
261
262
263 return m1
264