configure.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.
  5. local m1, s1
  6. local ena, mcf, lci, lsv
  7. local rlh, rpv, vld, nvd, eds, prt, tlm
  8. local ctl, dlk, dom, dty, lfq, wfq, exa
  9. local dp6, d64, pfx, qry, qrs
  10. local pro, rsc, rsn, ag2, stt
  11. local tgr, ifc, wfc
  12. local rpn, din, ath
  13. local ut = require "luci.util"
  14. local sy = require "luci.sys"
  15. local ht = require "luci.http"
  16. local ds = require "luci.dispatcher"
  17. local ucl = luci.model.uci.cursor()
  18. local valman = ucl:get_first("unbound", "unbound", "manual_conf")
  19. local dhcplk = ucl:get_first("unbound", "unbound", "dhcp_link")
  20. local lstrig = ucl:get_first("dhcp", "odhcpd", "leasetrigger") or "undefined"
  21. m1 = Map("unbound")
  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"))
  28. s1.addremove = false
  29. s1.anonymous = true
  30. if (valman == "0") and (dhcplk == "odhcpd") and (lstrig ~= "/usr/lib/unbound/odhcpd.sh") then
  31. m1.message = translatef( "Note: local DNS is configured to look at odhpcd, "
  32. .. "but odhpcd UCI lease trigger is incorrectly set: ")
  33. .. "dhcp.odhcpd.leasetrigger='" .. lstrig .. "'"
  34. end
  35. --LuCI, Unbound, or Not
  36. s1:tab("basic", translate("Basic"))
  37. if (valman == "0") then
  38. -- Not in manual configuration mode; show UCI
  39. s1:tab("advanced", translate("Advanced"))
  40. s1:tab("DHCP", translate("DHCP"))
  41. s1:tab("resource", translate("Resource"))
  42. end
  43. --Basic Tab, unconditional pieces
  44. ena = s1:taboption("basic", Flag, "enabled", translate("Enable Unbound"),
  45. translate("Enable the initialization scripts for Unbound"))
  46. ena.rmempty = false
  47. mcf = s1:taboption("basic", Flag, "manual_conf", translate("Manual Conf"),
  48. translate("Skip UCI and use /etc/unbound/unbound.conf"))
  49. mcf.rmempty = false
  50. if (valman == "0") then
  51. -- Not in manual configuration mode; show UCI
  52. --Basic Tab
  53. lsv = s1:taboption("basic", Flag, "localservice",
  54. translate("Local Service"),
  55. translate("Accept queries only from local subnets"))
  56. lsv.rmempty = false
  57. vld = s1:taboption("basic", Flag, "validator",
  58. translate("Enable DNSSEC"),
  59. translate("Enable the DNSSEC validator module"))
  60. vld.rmempty = false
  61. nvd = s1:taboption("basic", Flag, "validator_ntp",
  62. translate("DNSSEC NTP Fix"),
  63. translate("Break the loop where DNSSEC needs NTP and NTP needs DNS"))
  64. nvd.optional = true
  65. nvd.default = true
  66. nvd:depends("validator", true)
  67. prt = s1:taboption("basic", Value, "listen_port",
  68. translate("Listening Port"),
  69. translate("Choose Unbounds listening port"))
  70. prt.datatype = "port"
  71. prt.placeholder = "53"
  72. --Avanced Tab
  73. rlh = s1:taboption("advanced", Flag, "rebind_localhost",
  74. translate("Filter Localhost Rebind"),
  75. translate("Protect against upstream response of 127.0.0.0/8"))
  76. rlh.rmempty = false
  77. rpv = s1:taboption("advanced", ListValue, "rebind_protection",
  78. translate("Filter Private Rebind"),
  79. translate("Protect against upstream responses within local subnets"))
  80. rpv:value("0", translate("No Filter"))
  81. rpv:value("1", translate("Filter Private Address"))
  82. rpv:value("2", translate("Filter Entire Subnet"))
  83. rpv.rmempty = false
  84. d64 = s1:taboption("advanced", Flag, "dns64", translate("Enable DNS64"),
  85. translate("Enable the DNS64 module"))
  86. d64.rmempty = false
  87. pfx = s1:taboption("advanced", Value, "dns64_prefix",
  88. translate("DNS64 Prefix"),
  89. translate("Prefix for generated DNS64 addresses"))
  90. pfx.datatype = "ip6addr"
  91. pfx.placeholder = "64:ff9b::/96"
  92. pfx.optional = true
  93. pfx:depends("dns64", true)
  94. din = s1:taboption("advanced", DynamicList, "domain_insecure",
  95. translate("Domain Insecure"),
  96. translate("List domains to bypass checks of DNSSEC"))
  97. din:depends("validator", true)
  98. ag2 = s1:taboption("advanced", Value, "root_age",
  99. translate("Root DSKEY Age"),
  100. translate("Limit days between RFC5011 copies to reduce flash writes"))
  101. ag2.datatype = "and(uinteger,min(1),max(99))"
  102. ag2:value("3", "3")
  103. ag2:value("9", "9 ("..translate("default")..")")
  104. ag2:value("12", "12")
  105. ag2:value("24", "24")
  106. ag2:value("99", "99 ("..translate("never")..")")
  107. ifc = s1:taboption("advanced", Value, "iface_lan",
  108. translate("LAN Networks"),
  109. translate("Networks to consider LAN (served) beyond those served by DHCP"))
  110. ifc.template = "cbi/network_netlist"
  111. ifc.widget = "checkbox"
  112. ifc.rmempty = true
  113. ifc.cast = "string"
  114. ifc.nocreate = true
  115. wfc = s1:taboption("advanced", Value, "iface_wan",
  116. translate("WAN Networks"),
  117. translate("Networks to consider WAN (unserved)"))
  118. wfc.template = "cbi/network_netlist"
  119. wfc.widget = "checkbox"
  120. wfc.rmempty = true
  121. wfc.cast = "string"
  122. wfc.nocreate = true
  123. tgr = s1:taboption("advanced", Value, "iface_trig",
  124. translate("Trigger Networks"),
  125. translate("Networks that may trigger Unbound to reload (avoid wan6)"))
  126. tgr.template = "cbi/network_netlist"
  127. tgr.widget = "checkbox"
  128. tgr.rmempty = true
  129. tgr.cast = "string"
  130. tgr.nocreate = true
  131. --DHCP Tab
  132. dlk = s1:taboption("DHCP", ListValue, "dhcp_link",
  133. translate("DHCP Link"),
  134. translate("Link to supported programs to load DHCP into DNS"))
  135. dlk:value("none", translate("(none)"))
  136. dlk:value("dnsmasq", "dnsmasq")
  137. dlk:value("odhcpd", "odhcpd")
  138. dlk.rmempty = false
  139. dp6 = s1:taboption("DHCP", Flag, "dhcp4_slaac6",
  140. translate("DHCPv4 to SLAAC"),
  141. translate("Use DHCPv4 MAC to discover IP6 hosts SLAAC (EUI64)"))
  142. dp6.optional = true
  143. 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"
  148. dom.optional = true
  149. dty = s1:taboption("DHCP", ListValue, "domain_type",
  150. translate("Local Domain Type"),
  151. translate("How to treat queries of this local domain"))
  152. dty.optional = true
  153. dty:value("deny", translate("Denied (nxdomain)"))
  154. dty:value("refuse", translate("Refused"))
  155. dty:value("static", translate("Static (local only)"))
  156. dty:value("transparent", translate("Transparent (local/global)"))
  157. dty:depends("dhcp_link", "none")
  158. dty:depends("dhcp_link", "odhcpd")
  159. lfq = s1:taboption("DHCP", ListValue, "add_local_fqdn",
  160. translate("LAN DNS"),
  161. translate("How to enter the LAN or local network router in DNS"))
  162. lfq.optional = true
  163. lfq:value("0", translate("No Entry"))
  164. lfq:value("1", translate("Hostname, Primary Address"))
  165. lfq:value("2", translate("Hostname, All Addresses"))
  166. lfq:value("3", translate("Host FQDN, All Addresses"))
  167. lfq:value("4", translate("Interface FQDN, All Addresses"))
  168. lfq:depends("dhcp_link", "none")
  169. lfq:depends("dhcp_link", "odhcpd")
  170. wfq = s1:taboption("DHCP", ListValue, "add_wan_fqdn",
  171. translate("WAN DNS"),
  172. translate("Override the WAN side router entry in DNS"))
  173. wfq.optional = true
  174. wfq:value("0", translate("Use Upstream"))
  175. wfq:value("1", translate("Hostname, Primary Address"))
  176. wfq:value("2", translate("Hostname, All Addresses"))
  177. wfq:value("3", translate("Host FQDN, All Addresses"))
  178. wfq:value("4", translate("Interface FQDN, All Addresses"))
  179. wfq:depends("dhcp_link", "none")
  180. wfq:depends("dhcp_link", "odhcpd")
  181. exa = s1:taboption("DHCP", ListValue, "add_extra_dns",
  182. translate("Extra DNS"),
  183. translate("Use extra DNS entries found in /etc/config/dhcp"))
  184. exa.optional = true
  185. exa:value("0", translate("Ignore"))
  186. exa:value("1", translate("Host Records"))
  187. exa:value("2", translate("Host/MX/SRV RR"))
  188. exa:value("3", translate("Host/MX/SRV/CNAME RR"))
  189. exa:depends("dhcp_link", "none")
  190. exa:depends("dhcp_link", "odhcpd")
  191. --TODO: dnsmasq needs to not reference resolve-file and get off port 53.
  192. --Resource Tuning Tab
  193. ctl = s1:taboption("resource", ListValue, "unbound_control",
  194. translate("Unbound Control App"),
  195. translate("Enable access for unbound-control"))
  196. ctl.rmempty = false
  197. ctl:value("0", translate("No Remote Control"))
  198. ctl:value("1", translate("Local Host, No Encryption"))
  199. ctl:value("2", translate("Local Host, Encrypted"))
  200. ctl:value("3", translate("Local Subnet, Encrypted"))
  201. ctl:value("4", translate("Local Subnet, Static Encryption"))
  202. pro = s1:taboption("resource", ListValue, "protocol",
  203. translate("Recursion Protocol"),
  204. translate("Choose the IP versions used upstream and downstream"))
  205. pro:value("default", translate("Default"))
  206. pro:value("ip4_only", translate("IP4 Only"))
  207. pro:value("ip6_local", translate("IP4 All and IP6 Local"))
  208. pro:value("ip6_only", translate("IP6 Only*"))
  209. pro:value("ip6_prefer", translate("IP6 Preferred"))
  210. pro:value("mixed", translate("IP4 and IP6"))
  211. pro.rmempty = false
  212. rsc = s1:taboption("resource", ListValue, "resource",
  213. translate("Memory Resource"),
  214. translate("Use menu System/Processes to observe any memory growth"))
  215. rsc:value("default", translate("Default"))
  216. rsc:value("tiny", translate("Tiny"))
  217. rsc:value("small", translate("Small"))
  218. rsc:value("medium", translate("Medium"))
  219. rsc:value("large", translate("Large"))
  220. rsc.rmempty = false
  221. rsn = s1:taboption("resource", ListValue, "recursion",
  222. translate("Recursion Strength"),
  223. translate("Recursion activity affects memory growth and CPU load"))
  224. rsn:value("default", translate("Default"))
  225. rsn:value("passive", translate("Passive"))
  226. rsn:value("aggressive", translate("Aggressive"))
  227. rsn.rmempty = false
  228. qry = s1:taboption("resource", Flag, "query_minimize",
  229. translate("Query Minimize"),
  230. translate("Break down query components for limited added privacy"))
  231. qry.optional = true
  232. qry:depends("recursion", "passive")
  233. qry:depends("recursion", "aggressive")
  234. qrs = s1:taboption("resource", Flag, "query_min_strict",
  235. translate("Strict Minimize"),
  236. translate("Strict version of 'query minimize' but it can break DNS"))
  237. qrs.optional = true
  238. qrs:depends("query_minimize", true)
  239. eds = s1:taboption("resource", Value, "edns_size",
  240. translate("EDNS Size"),
  241. translate("Limit extended DNS packet size"))
  242. eds.datatype = "and(uinteger,min(512),max(4096))"
  243. eds.placeholder = "1280"
  244. tlm = s1:taboption("resource", Value, "ttl_min",
  245. translate("TTL Minimum"),
  246. translate("Prevent excessively short cache periods"))
  247. tlm.datatype = "and(uinteger,min(0),max(1200))"
  248. tlm.placeholder = "120"
  249. rtt = s1:taboption("resource", Value, "rate_limit",
  250. translate("Query Rate Limit"),
  251. translate("Prevent client query overload; zero is off"))
  252. rtt.datatype = "and(uinteger,min(0),max(5000))"
  253. rtt.placeholder = "0"
  254. stt = s1:taboption("resource", Flag, "extended_stats",
  255. translate("Extended Statistics"),
  256. translate("Extended statistics are printed from unbound-control"))
  257. stt.rmempty = false
  258. else
  259. ag2 = s1:taboption("basic", Value, "root_age",
  260. translate("Root DSKEY Age"),
  261. translate("Limit days between RFC5011 copies to reduce flash writes"))
  262. ag2.datatype = "and(uinteger,min(1),max(99))"
  263. ag2:value("3", "3")
  264. ag2:value("9", "9 ("..translate("default")..")")
  265. ag2:value("12", "12")
  266. ag2:value("24", "24")
  267. ag2:value("99", "99 ("..translate("never")..")")
  268. tgr = s1:taboption("basic", Value, "trigger_interface",
  269. translate("Trigger Networks"),
  270. translate("Networks that may trigger Unbound to reload (avoid wan6)"))
  271. tgr.template = "cbi/network_netlist"
  272. tgr.widget = "checkbox"
  273. tgr.rmempty = true
  274. tgr.cast = "string"
  275. tgr.nocreate = true
  276. end
  277. function ena.cfgvalue(self, section)
  278. return sy.init.enabled("unbound") and self.enabled or self.disabled
  279. end
  280. function ena.write(self, section, value)
  281. if (value == "1") then
  282. sy.init.enable("unbound")
  283. sy.call("/etc/init.d/unbound start >/dev/null 2>&1")
  284. else
  285. sy.call("/etc/init.d/unbound stop >/dev/null 2>&1")
  286. sy.init.disable("unbound")
  287. end
  288. return Flag.write(self, section, value)
  289. end
  290. function m1.on_commit(self)
  291. if sy.init.enabled("unbound") then
  292. -- Restart Unbound with configuration
  293. sy.call("/etc/init.d/unbound restart >/dev/null 2>&1")
  294. else
  295. sy.call("/etc/init.d/unbound stop >/dev/null 2>&1")
  296. end
  297. end
  298. function m1.on_apply(self)
  299. -- reload the page because some options hide
  300. ht.redirect(ds.build_url("admin", "services", "unbound", "configure"))
  301. end
  302. return m1