2
0

unbound.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Copyright 2017 Eric Luehrsen <ericluehrsen@gmail.com>
  4. -- Licensed to the public under the Apache License 2.0.
  5. module("luci.controller.unbound", package.seeall)
  6. function index()
  7. local fs = require "nixio.fs"
  8. local ucl = luci.model.uci.cursor()
  9. local valman = ucl:get_first("unbound", "unbound", "manual_conf")
  10. if not fs.access("/etc/config/unbound") then
  11. return
  12. end
  13. -- Expanded View
  14. local e = entry({"admin", "services", "unbound"}, firstchild(), _("Recursive DNS"))
  15. e.dependent = false
  16. e.acl_depends = { "luci-app-unbound" }
  17. -- UCI Tab(s)
  18. entry({"admin", "services", "unbound", "configure"},
  19. cbi("unbound/configure"), _("Unbound"), 10)
  20. if (valman == "0") then
  21. entry({"admin", "services", "unbound", "zones"},
  22. arcombine(cbi("unbound/zones"), cbi("unbound/zone-details")),
  23. _("Zones"), 15).leaf = true
  24. end
  25. -- Status Tab(s)
  26. entry({"admin", "services", "unbound", "status"},
  27. firstchild(), _("Status"), 20)
  28. entry({"admin", "services", "unbound", "status", "syslog"},
  29. call("QuerySysLog"), _("Log"), 50).leaf = true
  30. if fs.access("/usr/sbin/unbound-control") then
  31. -- Require unbound-control to execute
  32. entry({"admin", "services", "unbound", "status", "statistics"},
  33. call("QueryStatistics"), _("Statistics"), 10).leaf = true
  34. entry({"admin", "services", "unbound", "status", "localdata"},
  35. call("QueryLocalData"), _("Local Data"), 20).leaf = true
  36. entry({"admin", "services", "unbound", "status", "localzone"},
  37. call("QueryLocalZone"), _("Local Zones"), 30).leaf = true
  38. entry({"admin", "services", "unbound", "status", "dumpcache"},
  39. call("QueryDumpCache"), _("DNS Cache"), 40).leaf = true
  40. else
  41. entry({"admin", "services", "unbound", "status", "statistics"},
  42. call("ShowEmpty"), _("Statistics"), 10).leaf = true
  43. end
  44. -- Raw File Tab(s)
  45. entry({"admin", "services", "unbound", "files"},
  46. firstchild(), _("Files"), 30)
  47. if (valman == "0") then
  48. entry({"admin", "services", "unbound", "files", "uci"},
  49. form("unbound/uciedit"), _("Edit: UCI"), 5).leaf = true
  50. entry({"admin", "services", "unbound", "files", "base"},
  51. call("ShowUnboundConf"), _("Show: Unbound"), 10).leaf = true
  52. else
  53. entry({"admin", "services", "unbound", "files", "base"},
  54. form("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
  55. end
  56. entry({"admin", "services", "unbound", "files", "server"},
  57. form("unbound/server"), _("Edit: Server"), 20).leaf = true
  58. entry({"admin", "services", "unbound", "files", "extended"},
  59. form("unbound/extended"), _("Edit: Extended"), 30).leaf = true
  60. if fs.access("/var/lib/unbound/dhcp.conf") then
  61. entry({"admin", "services", "unbound", "files", "dhcp"},
  62. call("ShowDHCPConf"), _("Show: DHCP"), 40).leaf = true
  63. end
  64. if fs.access("/var/lib/unbound/adb_list.overall") then
  65. entry({"admin", "services", "unbound", "files", "adblock"},
  66. call("ShowAdblock"), _("Show: Adblock"), 50).leaf = true
  67. end
  68. end
  69. function ShowEmpty()
  70. local lclhead = "Unbound Control"
  71. local lcldesc = luci.i18n.translate(
  72. "This could display more statistics with the unbound-control package.")
  73. luci.template.render("unbound/show-empty",
  74. {heading = lclhead, description = lcldesc})
  75. end
  76. function QuerySysLog()
  77. local lcldata = luci.util.exec("logread -e 'unbound'")
  78. local lcldesc = luci.i18n.translate(
  79. "This shows syslog filtered for events involving Unbound.")
  80. luci.template.render("unbound/show-textbox",
  81. {heading = "", description = lcldesc, content = lcldata})
  82. end
  83. function QueryStatistics()
  84. local lcldata = luci.util.exec(
  85. "unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
  86. local lcldesc = luci.i18n.translate(
  87. "This shows Unbound self reported performance statistics.")
  88. luci.template.render("unbound/show-textbox",
  89. {heading = "", description = lcldesc, content = lcldata})
  90. end
  91. function QueryLocalData()
  92. local lcldata = luci.util.exec(
  93. "unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
  94. local lcldesc = luci.i18n.translate(
  95. "This shows Unbound 'local-data:' entries from default, .conf, or control.")
  96. luci.template.render("unbound/show-textbox",
  97. {heading = "", description = lcldesc, content = lcldata})
  98. end
  99. function QueryLocalZone()
  100. local lcldata = luci.util.exec(
  101. "unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
  102. local lcldesc = luci.i18n.translate(
  103. "This shows Unbound 'local-zone:' entries from default, .conf, or control.")
  104. luci.template.render("unbound/show-textbox",
  105. {heading = "", description = lcldesc, content = lcldata})
  106. end
  107. function QueryDumpCache()
  108. local tp = require "luci.template"
  109. local tr = require "luci.i18n"
  110. local lcldesc
  111. local lcldata = luci.util.exec(
  112. "unbound-control -c /var/lib/unbound/unbound.conf dump_cache")
  113. if #lcldata > 262144 then
  114. lcldesc = tr.translate(
  115. "Unbound cache is too large to display in LuCI.")
  116. tp.render("unbound/show-empty",
  117. {heading = "", description = lcldesc})
  118. else
  119. lcldesc = tr.translate(
  120. "This shows 'ubound-control dump_cache' for auditing records including DNSSEC.")
  121. tp.render("unbound/show-textbox",
  122. {heading = "", description = lcldesc, content = lcldata})
  123. end
  124. end
  125. function ShowUnboundConf()
  126. local unboundfile = "/var/lib/unbound/unbound.conf"
  127. local lcldata = nixio.fs.readfile(unboundfile)
  128. local lcldesc = luci.i18n.translate(
  129. "This shows '" .. unboundfile .. "' generated from UCI configuration.")
  130. luci.template.render("unbound/show-textbox",
  131. {heading = "", description = lcldesc, content = lcldata})
  132. end
  133. function ShowDHCPConf()
  134. local dhcpfile = "/var/lib/unbound/dhcp.conf"
  135. local lcldata = nixio.fs.readfile(dhcpfile)
  136. local lcldesc = luci.i18n.translate(
  137. "This shows '" .. dhcpfile .. "' list of hosts from DHCP hook scripts.")
  138. luci.template.render("unbound/show-textbox",
  139. {heading = "", description = lcldesc, content = lcldata})
  140. end
  141. function ShowAdblock()
  142. local fs = require "nixio.fs"
  143. local tp = require "luci.template"
  144. local tr = require "luci.i18n"
  145. local adblockfile = "/var/lib/unbound/adb_list.overall"
  146. local lcldata, lcldesc
  147. if fs.stat(adblockfile).size > 262144 then
  148. lcldesc = tr.translate(
  149. "Adblock domain list is too large to display in LuCI.")
  150. tp.render("unbound/show-empty",
  151. {heading = "", description = lcldesc})
  152. else
  153. lcldata = fs.readfile(adblockfile)
  154. lcldesc = tr.translate(
  155. "This shows '" .. adblockfile .. "' list of adblock domains." )
  156. tp.render("unbound/show-textbox",
  157. {heading = "", description = lcldesc, content = lcldata})
  158. end
  159. end