Translated using Weblate (Japanese)
[oweals/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     local e = entry({"admin", "services", "unbound"}, firstchild(), _("Recursive DNS"))
22     e.dependent = false
23     e.acl_depends = { "luci-app-unbound" }
24
25     -- UCI Tab(s)
26     entry({"admin", "services", "unbound", "configure"},
27         cbi("unbound/configure"), _("Unbound"), 10)
28
29
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
34     end
35
36
37     -- Status Tab(s)
38     entry({"admin", "services", "unbound", "status"},
39         firstchild(), _("Status"), 20)
40
41     entry({"admin", "services", "unbound", "status", "syslog"},
42         call("QuerySysLog"), _("Log"), 50).leaf = true
43
44
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
49
50         entry({"admin", "services", "unbound", "status", "localdata"},
51             call("QueryLocalData"), _("Local Data"), 20).leaf = true
52
53         entry({"admin", "services", "unbound", "status", "localzone"},
54             call("QueryLocalZone"), _("Local Zones"), 30).leaf = true
55
56         entry({"admin", "services", "unbound", "status", "dumpcache"},
57             call("QueryDumpCache"), _("DNS Cache"), 40).leaf = true
58     else
59         entry({"admin", "services", "unbound", "status", "statistics"},
60             call("ShowEmpty"), _("Statistics"), 10).leaf = true
61     end
62
63
64     -- Raw File Tab(s)
65     entry({"admin", "services", "unbound", "files"},
66         firstchild(), _("Files"), 30)
67
68
69     if (valman == "0") then
70         entry({"admin", "services", "unbound", "files", "uci"},
71             form("unbound/uciedit"), _("Edit: UCI"), 5).leaf = true
72
73         entry({"admin", "services", "unbound", "files", "base"},
74             call("ShowUnboundConf"), _("Show: Unbound"), 10).leaf = true
75
76     else
77         entry({"admin", "services", "unbound", "files", "base"},
78             form("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
79     end
80
81
82     entry({"admin", "services", "unbound", "files", "server"},
83         form("unbound/server"), _("Edit: Server"), 20).leaf = true
84
85     entry({"admin", "services", "unbound", "files", "extended"},
86         form("unbound/extended"), _("Edit: Extended"), 30).leaf = true
87
88
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
92     end
93
94
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
98     end
99 end
100
101
102 function ShowEmpty()
103     local lclhead = "Unbound Control"
104     local lcldesc = luci.i18n.translate(
105         "This could display more statistics with the unbound-control package.")
106
107     luci.template.render("unbound/show-empty",
108         {heading = lclhead, description = lcldesc})
109 end
110
111
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.")
116
117     luci.template.render("unbound/show-textbox",
118         {heading = "", description = lcldesc, content = lcldata})
119 end
120
121
122 function QueryStatistics()
123     local lcldata = luci.util.exec(
124         "unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
125
126     local lcldesc = luci.i18n.translate(
127         "This shows Unbound self reported performance statistics.")
128
129     luci.template.render("unbound/show-textbox",
130         {heading = "", description = lcldesc, content = lcldata})
131 end
132
133
134 function QueryLocalData()
135     local lcldata = luci.util.exec(
136         "unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
137
138     local lcldesc = luci.i18n.translate(
139         "This shows Unbound 'local-data:' entries from default, .conf, or control.")
140
141     luci.template.render("unbound/show-textbox",
142         {heading = "", description = lcldesc, content = lcldata})
143 end
144
145
146 function QueryLocalZone()
147     local lcldata = luci.util.exec(
148         "unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
149
150     local lcldesc = luci.i18n.translate(
151         "This shows Unbound 'local-zone:' entries from default, .conf, or control.")
152
153     luci.template.render("unbound/show-textbox",
154         {heading = "", description = lcldesc, content = lcldata})
155 end
156
157
158 function QueryDumpCache()
159     local tp = require "luci.template"
160     local tr = require "luci.i18n"
161     local lcldesc 
162     local lcldata = luci.util.exec(
163         "unbound-control -c /var/lib/unbound/unbound.conf dump_cache")
164
165
166     if #lcldata > 262144 then
167         lcldesc = tr.translate(
168             "Unbound cache is too large to display in LuCI.")
169
170         tp.render("unbound/show-empty",
171             {heading = "", description = lcldesc})
172
173     else
174         lcldesc = tr.translate(
175             "This shows 'ubound-control dump_cache' for auditing records including DNSSEC.")
176
177         tp.render("unbound/show-textbox",
178             {heading = "", description = lcldesc, content = lcldata})
179     end
180
181 end
182
183
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.")
189
190     luci.template.render("unbound/show-textbox",
191         {heading = "", description = lcldesc, content = lcldata})
192 end
193
194
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.")
200
201     luci.template.render("unbound/show-textbox",
202         {heading = "", description = lcldesc, content = lcldata})
203 end
204
205
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
212
213
214     if fs.stat(adblockfile).size > 262144 then
215         lcldesc = tr.translate(
216             "Adblock domain list is too large to display in LuCI.")
217
218         tp.render("unbound/show-empty",
219             {heading = "", description = lcldesc})
220
221     else
222         lcldata = fs.readfile(adblockfile)
223         lcldesc = tr.translate(
224             "This shows '" .. adblockfile .. "' list of adblock domains." )
225
226         tp.render("unbound/show-textbox",
227             {heading = "", description = lcldesc, content = lcldata})
228     end
229 end
230