configure.lua 11 KB

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