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