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 entry({"admin", "services", "unbound"},
22 firstchild(), _("Recursive DNS")).dependent = false
25 entry({"admin", "services", "unbound", "configure"},
26 cbi("unbound/configure"), _("Unbound"), 10)
29 if (valman == "0") then
30 entry({"admin", "services", "unbound", "zones"},
31 arcombine(cbi("unbound/zones"), cbi("unbound/zone-details")),
32 _("Zones"), 15).leaf = true
37 entry({"admin", "services", "unbound", "status"},
38 firstchild(), _("Status"), 20)
40 entry({"admin", "services", "unbound", "status", "syslog"},
41 call("QuerySysLog"), _("Log"), 50).leaf = true
44 if fs.access("/usr/sbin/unbound-control") then
45 -- Require unbound-control to execute
46 entry({"admin", "services", "unbound", "status", "statistics"},
47 call("QueryStatistics"), _("Statistics"), 10).leaf = true
49 entry({"admin", "services", "unbound", "status", "localdata"},
50 call("QueryLocalData"), _("Local Data"), 20).leaf = true
52 entry({"admin", "services", "unbound", "status", "localzone"},
53 call("QueryLocalZone"), _("Local Zones"), 30).leaf = true
55 entry({"admin", "services", "unbound", "status", "dumpcache"},
56 call("QueryDumpCache"), _("DNS Cache"), 40).leaf = true
58 entry({"admin", "services", "unbound", "status", "statistics"},
59 call("ShowEmpty"), _("Statistics"), 10).leaf = true
64 entry({"admin", "services", "unbound", "files"},
65 firstchild(), _("Files"), 30)
68 if (valman == "0") then
69 entry({"admin", "services", "unbound", "files", "uci"},
70 form("unbound/uciedit"), _("Edit: UCI"), 5).leaf = true
72 entry({"admin", "services", "unbound", "files", "base"},
73 call("ShowUnboundConf"), _("Show: Unbound"), 10).leaf = true
76 entry({"admin", "services", "unbound", "files", "base"},
77 form("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
81 entry({"admin", "services", "unbound", "files", "server"},
82 form("unbound/server"), _("Edit: Server"), 20).leaf = true
84 entry({"admin", "services", "unbound", "files", "extended"},
85 form("unbound/extended"), _("Edit: Extended"), 30).leaf = true
88 if fs.access("/var/lib/unbound/dhcp.conf") then
89 entry({"admin", "services", "unbound", "files", "dhcp"},
90 call("ShowDHCPConf"), _("Show: DHCP"), 40).leaf = true
94 if fs.access("/var/lib/unbound/adb_list.overall") then
95 entry({"admin", "services", "unbound", "files", "adblock"},
96 call("ShowAdblock"), _("Show: Adblock"), 50).leaf = true
102 local lclhead = "Unbound Control"
103 local lcldesc = luci.i18n.translate(
104 "This could display more statistics with the unbound-control package.")
106 luci.template.render("unbound/show-empty",
107 {heading = lclhead, description = lcldesc})
111 function QuerySysLog()
112 local lcldata = luci.util.exec("logread -e 'unbound'")
113 local lcldesc = luci.i18n.translate(
114 "This shows syslog filtered for events involving Unbound.")
116 luci.template.render("unbound/show-textbox",
117 {heading = "", description = lcldesc, content = lcldata})
121 function QueryStatistics()
122 local lcldata = luci.util.exec(
123 "unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
125 local lcldesc = luci.i18n.translate(
126 "This shows Unbound self reported performance statistics.")
128 luci.template.render("unbound/show-textbox",
129 {heading = "", description = lcldesc, content = lcldata})
133 function QueryLocalData()
134 local lcldata = luci.util.exec(
135 "unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
137 local lcldesc = luci.i18n.translate(
138 "This shows Unbound 'local-data:' entries from default, .conf, or control.")
140 luci.template.render("unbound/show-textbox",
141 {heading = "", description = lcldesc, content = lcldata})
145 function QueryLocalZone()
146 local lcldata = luci.util.exec(
147 "unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
149 local lcldesc = luci.i18n.translate(
150 "This shows Unbound 'local-zone:' entries from default, .conf, or control.")
152 luci.template.render("unbound/show-textbox",
153 {heading = "", description = lcldesc, content = lcldata})
157 function QueryDumpCache()
158 local tp = require "luci.template"
159 local tr = require "luci.i18n"
161 local lcldata = luci.util.exec(
162 "unbound-control -c /var/lib/unbound/unbound.conf dump_cache")
165 if #lcldata > 262144 then
166 lcldesc = tr.translate(
167 "Unbound cache is too large to display in LuCI.")
169 tp.render("unbound/show-empty",
170 {heading = "", description = lcldesc})
173 lcldesc = tr.translate(
174 "This shows 'ubound-control dump_cache' for auditing records including DNSSEC.")
176 tp.render("unbound/show-textbox",
177 {heading = "", description = lcldesc, content = lcldata})
183 function ShowUnboundConf()
184 local unboundfile = "/var/lib/unbound/unbound.conf"
185 local lcldata = nixio.fs.readfile(unboundfile)
186 local lcldesc = luci.i18n.translate(
187 "This shows '" .. unboundfile .. "' generated from UCI configuration.")
189 luci.template.render("unbound/show-textbox",
190 {heading = "", description = lcldesc, content = lcldata})
194 function ShowDHCPConf()
195 local dhcpfile = "/var/lib/unbound/dhcp.conf"
196 local lcldata = nixio.fs.readfile(dhcpfile)
197 local lcldesc = luci.i18n.translate(
198 "This shows '" .. dhcpfile .. "' list of hosts from DHCP hook scripts.")
200 luci.template.render("unbound/show-textbox",
201 {heading = "", description = lcldesc, content = lcldata})
205 function ShowAdblock()
206 local fs = require "nixio.fs"
207 local tp = require "luci.template"
208 local tr = require "luci.i18n"
209 local adblockfile = "/var/lib/unbound/adb_list.overall"
210 local lcldata, lcldesc
213 if fs.stat(adblockfile).size > 262144 then
214 lcldesc = tr.translate(
215 "Adblock domain list is too large to display in LuCI.")
217 tp.render("unbound/show-empty",
218 {heading = "", description = lcldesc})
221 lcldata = fs.readfile(adblockfile)
222 lcldesc = tr.translate(
223 "This shows '" .. adblockfile .. "' list of adblock domains." )
225 tp.render("unbound/show-textbox",
226 {heading = "", description = lcldesc, content = lcldata})