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.
6 module("luci.controller.unbound", package.seeall)
10 local fs = require "nixio.fs"
11 local ucl = luci.model.uci.cursor()
12 local valman = ucl:get_first("unbound", "unbound", "manual_conf")
15 if not fs.access("/etc/config/unbound") then
21 local e = entry({"admin", "services", "unbound"}, firstchild(), _("Recursive DNS"))
23 e.acl_depends = { "luci-app-unbound" }
26 entry({"admin", "services", "unbound", "configure"},
27 cbi("unbound/configure"), _("Unbound"), 10)
30 if (valman == "0") then
31 entry({"admin", "services", "unbound", "zones"},
32 arcombine(cbi("unbound/zones"), cbi("unbound/zone-details")),
33 _("Zones"), 15).leaf = true
38 entry({"admin", "services", "unbound", "status"},
39 firstchild(), _("Status"), 20)
41 entry({"admin", "services", "unbound", "status", "syslog"},
42 call("QuerySysLog"), _("Log"), 50).leaf = true
45 if fs.access("/usr/sbin/unbound-control") then
46 -- Require unbound-control to execute
47 entry({"admin", "services", "unbound", "status", "statistics"},
48 call("QueryStatistics"), _("Statistics"), 10).leaf = true
50 entry({"admin", "services", "unbound", "status", "localdata"},
51 call("QueryLocalData"), _("Local Data"), 20).leaf = true
53 entry({"admin", "services", "unbound", "status", "localzone"},
54 call("QueryLocalZone"), _("Local Zones"), 30).leaf = true
56 entry({"admin", "services", "unbound", "status", "dumpcache"},
57 call("QueryDumpCache"), _("DNS Cache"), 40).leaf = true
59 entry({"admin", "services", "unbound", "status", "statistics"},
60 call("ShowEmpty"), _("Statistics"), 10).leaf = true
65 entry({"admin", "services", "unbound", "files"},
66 firstchild(), _("Files"), 30)
69 if (valman == "0") then
70 entry({"admin", "services", "unbound", "files", "uci"},
71 form("unbound/uciedit"), _("Edit: UCI"), 5).leaf = true
73 entry({"admin", "services", "unbound", "files", "base"},
74 call("ShowUnboundConf"), _("Show: Unbound"), 10).leaf = true
77 entry({"admin", "services", "unbound", "files", "base"},
78 form("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
82 entry({"admin", "services", "unbound", "files", "server"},
83 form("unbound/server"), _("Edit: Server"), 20).leaf = true
85 entry({"admin", "services", "unbound", "files", "extended"},
86 form("unbound/extended"), _("Edit: Extended"), 30).leaf = true
89 if fs.access("/var/lib/unbound/dhcp.conf") then
90 entry({"admin", "services", "unbound", "files", "dhcp"},
91 call("ShowDHCPConf"), _("Show: DHCP"), 40).leaf = true
95 if fs.access("/var/lib/unbound/adb_list.overall") then
96 entry({"admin", "services", "unbound", "files", "adblock"},
97 call("ShowAdblock"), _("Show: Adblock"), 50).leaf = true
103 local lclhead = "Unbound Control"
104 local lcldesc = luci.i18n.translate(
105 "This could display more statistics with the unbound-control package.")
107 luci.template.render("unbound/show-empty",
108 {heading = lclhead, description = lcldesc})
112 function QuerySysLog()
113 local lcldata = luci.util.exec("logread -e 'unbound'")
114 local lcldesc = luci.i18n.translate(
115 "This shows syslog filtered for events involving Unbound.")
117 luci.template.render("unbound/show-textbox",
118 {heading = "", description = lcldesc, content = lcldata})
122 function QueryStatistics()
123 local lcldata = luci.util.exec(
124 "unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
126 local lcldesc = luci.i18n.translate(
127 "This shows Unbound self reported performance statistics.")
129 luci.template.render("unbound/show-textbox",
130 {heading = "", description = lcldesc, content = lcldata})
134 function QueryLocalData()
135 local lcldata = luci.util.exec(
136 "unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
138 local lcldesc = luci.i18n.translate(
139 "This shows Unbound 'local-data:' entries from default, .conf, or control.")
141 luci.template.render("unbound/show-textbox",
142 {heading = "", description = lcldesc, content = lcldata})
146 function QueryLocalZone()
147 local lcldata = luci.util.exec(
148 "unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
150 local lcldesc = luci.i18n.translate(
151 "This shows Unbound 'local-zone:' entries from default, .conf, or control.")
153 luci.template.render("unbound/show-textbox",
154 {heading = "", description = lcldesc, content = lcldata})
158 function QueryDumpCache()
159 local tp = require "luci.template"
160 local tr = require "luci.i18n"
162 local lcldata = luci.util.exec(
163 "unbound-control -c /var/lib/unbound/unbound.conf dump_cache")
166 if #lcldata > 262144 then
167 lcldesc = tr.translate(
168 "Unbound cache is too large to display in LuCI.")
170 tp.render("unbound/show-empty",
171 {heading = "", description = lcldesc})
174 lcldesc = tr.translate(
175 "This shows 'ubound-control dump_cache' for auditing records including DNSSEC.")
177 tp.render("unbound/show-textbox",
178 {heading = "", description = lcldesc, content = lcldata})
184 function ShowUnboundConf()
185 local unboundfile = "/var/lib/unbound/unbound.conf"
186 local lcldata = nixio.fs.readfile(unboundfile)
187 local lcldesc = luci.i18n.translate(
188 "This shows '" .. unboundfile .. "' generated from UCI configuration.")
190 luci.template.render("unbound/show-textbox",
191 {heading = "", description = lcldesc, content = lcldata})
195 function ShowDHCPConf()
196 local dhcpfile = "/var/lib/unbound/dhcp.conf"
197 local lcldata = nixio.fs.readfile(dhcpfile)
198 local lcldesc = luci.i18n.translate(
199 "This shows '" .. dhcpfile .. "' list of hosts from DHCP hook scripts.")
201 luci.template.render("unbound/show-textbox",
202 {heading = "", description = lcldesc, content = lcldata})
206 function ShowAdblock()
207 local fs = require "nixio.fs"
208 local tp = require "luci.template"
209 local tr = require "luci.i18n"
210 local adblockfile = "/var/lib/unbound/adb_list.overall"
211 local lcldata, lcldesc
214 if fs.stat(adblockfile).size > 262144 then
215 lcldesc = tr.translate(
216 "Adblock domain list is too large to display in LuCI.")
218 tp.render("unbound/show-empty",
219 {heading = "", description = lcldesc})
222 lcldata = fs.readfile(adblockfile)
223 lcldesc = tr.translate(
224 "This shows '" .. adblockfile .. "' list of adblock domains." )
226 tp.render("unbound/show-textbox",
227 {heading = "", description = lcldesc, content = lcldata})