summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-unbound/luasrc/controller/unbound.lua
blob: 296d020cdbf8a4abb1d4883db87cd8c25278eda2 (plain)
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
-- Copyright 2008 Steven Barth <steven@midlink.org>
-- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
-- Copyright 2017 Eric Luehrsen <ericluehrsen@hotmail.com>
-- Licensed to the public under the Apache License 2.0.

module("luci.controller.unbound", package.seeall)


function index()
  local ucl = luci.model.uci.cursor()
  local valexp = ucl:get_first("unbound", "unbound", "luci_expanded")
  local valman = ucl:get_first("unbound", "unbound", "manual_conf")


  if not nixio.fs.access("/etc/config/unbound") then
    return
  end


  if valexp == "1" then
    -- Expanded View
    entry({"admin", "services", "unbound"}, firstchild(), _("Recursive DNS")).dependent = false

    -- UCI Tab(s)
    entry({"admin", "services", "unbound", "configure"}, cbi("unbound/configure"), _("Settings"), 10)

    -- Status Tab(s)
    entry({"admin", "services", "unbound", "status"}, firstchild(), _("Status"), 20)
    entry({"admin", "services", "unbound", "status", "syslog"}, call("QuerySysLog"), _("Log"), 50).leaf = true


    if nixio.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

    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 ~= "1" then
      entry({"admin", "services", "unbound", "files", "base"}, call("ShowUnboundConf"), _("UCI: Unbound"), 10).leaf = true
    else
      entry({"admin", "services", "unbound", "files", "base"}, cbi("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
    end


    entry({"admin", "services", "unbound", "files", "server"}, cbi("unbound/server"), _("Edit: Server"), 20).leaf = true
    entry({"admin", "services", "unbound", "files", "extended"}, cbi("unbound/extended"), _("Edit: Extended"), 30).leaf = true


    if nixio.fs.access("/var/lib/unbound/unbound_dhcp.conf") then
      entry({"admin", "services", "unbound", "files", "dhcp"}, call("ShowDHCPConf"), _("Include: DHCP"), 40).leaf = true
    end


    if nixio.fs.access("/var/lib/unbound/adb_list.overall") then
      entry({"admin", "services", "unbound", "files", "adblock"}, call("ShowAdblock"), _("Include: Adblock"), 50).leaf = true
    end

  else
    -- Simple View to UCI only
    entry({"admin", "services", "unbound"}, cbi("unbound/configure"), _("Recursive DNS")).dependent = false
  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 lclhead = "System Log"
  local lcldata = luci.util.exec("logread | grep -i unbound")
  local lcldesc = luci.i18n.translate("This shows syslog filtered for events involving Unbound.")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function QueryStatistics()
  local lclhead = "Unbound Control Stats"
  local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
  local lcldesc = luci.i18n.translate("This shows some performances statistics tracked by Unbound.")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function QueryLocalData()
  local lclhead = "Unbound Control Local Data"
  local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
  local lcldesc = luci.i18n.translate("This shows local RR including this router, DHCP assignments, and RFC1918 SOA stubs.")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function QueryLocalZone()
  local lclhead = "Unbound Control Local Zones"
  local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
  local lcldesc = luci.i18n.translate("This shows local zones including LAN, adblock, forwarding, and RFC1918 in-arpa. ")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function ShowUnboundConf()
  local lclhead = "Unbound Conf"
  local lcldata = luci.util.exec("cat /var/lib/unbound/unbound.conf")
  local lcldesc = luci.i18n.translate("This shows '/var/lib/unbound/unbound.conf' generated by UCI.")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function ShowDHCPConf()
  local lclhead = "DHCP Conf"
  local lcldata = luci.util.exec("cat /var/lib/unbound/unbound_dhcp.conf")
  local lcldesc = luci.i18n.translate("This shows '/var/lib/unbound/unbound_dhcp.conf' generated by DHCP hook script(s).")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end


function ShowAdblock()
  local lclhead = "Adblock Conf"
  local lcldata = luci.util.exec("cat /var/lib/unbound/adb_list.overall")
  local lcldesc = luci.i18n.translate("This shows '/var/lib/unbound/adb_list.overall' provided by Adblock script(s).")
  luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
end