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