luci-app-adblock: sync with adblock 2.5.1
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / overview_tab.lua
1 -- Copyright 2016 Hannu Nyman
2 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
3 -- This is free software, licensed under the Apache License, Version 2.0
4
5 local sys = require("luci.sys")
6 local util = require("luci.util")
7 local data = util.ubus("service", "get_data", "name", "adblock") or { }
8 local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
9 local dnsFile2 = sys.exec("find '/var/lib/unbound' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
10
11 m = Map("adblock", translate("Adblock"),
12         translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
13         .. translate("For further information ")
14         .. [[<a href="https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md" target="_blank">]]
15         .. translate("see online documentation")
16         .. [[</a>]]
17         .. translate("."))
18
19 -- Main adblock options
20
21 s = m:section(NamedSection, "global", "adblock")
22
23 o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
24 o1.rmempty = false
25 o1.default = 0
26
27 btn = s:option(Button, "", translate("Suspend / Resume adblock"))
28 if data.adblock == nil then
29         btn.inputtitle = "n/a"
30         btn.inputstyle = nil
31         btn.disabled = true
32 elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
33         btn.inputtitle = translate("Suspend adblock")
34         btn.inputstyle = "reset"
35         btn.disabled = false
36         function btn.write()
37                 luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
38         end
39 else
40         btn.inputtitle = translate("Resume adblock")
41         btn.inputstyle = "apply"
42         btn.disabled = false
43         function btn.write()
44                 luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
45         end
46 end
47
48 o2 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
49 o2.default = o2.disabled
50 o2.rmempty = false
51
52 o3 = s:option(Value, "adb_iface", translate("Restrict interface reload trigger to certain interface(s)"),
53         translate("Space separated list of interfaces that trigger a reload action. "..
54         "To disable reload trigger at all remove all entries."))
55 o3.rmempty =true
56
57 -- Runtime information
58
59         ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
60         ds.template = "cbi/nullsection"
61
62         dv1 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
63         dv1.template = "adblock/runtime"
64         if data.adblock ~= nil then
65                 dv1.value = data.adblock.adblock.adblock_version or "n/a"
66         else
67                 dv1.value = "n/a"
68         end
69
70         dv2 = s:option(DummyValue, "status", translate("Status"))
71         dv2.template = "adblock/runtime"
72         if data.adblock == nil then
73                 dv2.value = "n/a"
74         elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
75                 dv2.value = "active"
76         else
77                 dv2.value = "suspended"
78         end
79
80         dv3 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
81         dv3.template = "adblock/runtime"
82         if data.adblock ~= nil then
83                 dv3.value = data.adblock.adblock.dns_backend or "n/a"
84         else
85                 dv3.value = "n/a"
86         end
87
88         dv4 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
89         dv4.template = "adblock/runtime"
90         if data.adblock ~= nil then
91                 dv4.value = data.adblock.adblock.blocked_domains or "n/a"
92         else
93                 dv4.value = "n/a"
94         end
95
96         dv5 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
97         dv5.template = "adblock/runtime"
98         if data.adblock ~= nil then
99                 dv5.value = data.adblock.adblock.last_rundate or "n/a"
100         else
101                 dv5.value = "n/a"
102         end
103
104 -- Blocklist options
105
106 bl = m:section(TypedSection, "source", translate("Blocklist sources"),
107         translate("Available blocklist sources. ")
108         .. translate("Note that list URLs and Shallalist category selections are configurable in the 'Advanced' section."))
109 bl.template = "cbi/tblsection"
110
111 name = bl:option(Flag, "enabled", translate("Enabled"))
112 name.rmempty  = false
113
114 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
115
116 -- Backup options
117
118 s = m:section(NamedSection, "global", "adblock", translate("Backup options"))
119
120 o4 = s:option(Flag, "adb_backup", translate("Enable blocklist backup"))
121 o4.rmempty = false
122 o4.default = 0
123
124 o5 = s:option(Value, "adb_backupdir", translate("Backup directory"))
125 o5.rmempty = false
126 o5.datatype = "directory"
127
128 return m