luci-app-adblock: sync with adblock 2.7.0
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / overview_tab.lua
1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
4 local fs = require("nixio.fs")
5 local uci = require("uci")
6 local sys = require("luci.sys")
7 local json = require("luci.jsonc")
8 local adbinput = uci.get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
9 local parse = json.parse(fs.readfile(adbinput) or "")
10 local dnsFile1 = sys.exec("find '/tmp/dnsmasq.d/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
11 local dnsFile2 = sys.exec("find '/var/lib/unbound/.adb_hidden' -maxdepth 1 -type f -name 'adb_list*' -print 2>/dev/null")
12
13 m = Map("adblock", translate("Adblock"),
14 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
15 .. translatef("For further information "
16 .. "<a href=\"%s\" target=\"_blank\">"
17 .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
18
19 function m.on_after_commit(self)
20 luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
21 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
22 end
23
24 -- Main adblock options
25
26 s = m:section(NamedSection, "global", "adblock")
27
28 o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
29 o1.default = o1.enabled
30 o1.rmempty = false
31
32 btn = s:option(Button, "", translate("Suspend / Resume adblock"))
33 if dnsFile1 ~= "" or dnsFile2 ~= "" then
34 btn.inputtitle = translate("Resume adblock")
35 btn.inputstyle = "apply"
36 btn.disabled = false
37 function btn.write()
38 luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
39 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
40 end
41 else
42 btn.inputtitle = translate("Suspend adblock")
43 btn.inputstyle = "reset"
44 btn.disabled = false
45 function btn.write()
46 luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
47 luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
48 end
49 end
50
51 o2 = s:option(Value, "adb_iface", translate("Restrict interface trigger to certain interface(s)"),
52 translate("Space separated list of interfaces that trigger adblock processing. "..
53 "To disable event driven (re-)starts remove all entries."))
54 o2.rmempty = true
55
56 o3 = s:option(Value, "adb_triggerdelay", translate("Trigger delay"),
57 translate("Additional trigger delay in seconds before adblock processing begins."))
58 o3.default = 2
59 o3.datatype = "range(1,90)"
60 o3.rmempty = false
61
62 o4 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
63 o4.default = o4.disabled
64 o4.rmempty = false
65
66 -- Runtime information
67
68 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
69 ds.template = "cbi/nullsection"
70
71 dv1 = s:option(DummyValue, "status", translate("Status"))
72 dv1.template = "adblock/runtime"
73 if parse == nil then
74 dv1.value = translate("n/a")
75 elseif parse.data.blocked_domains == "0" then
76 dv1.value = translate("no domains blocked")
77 elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
78 dv1.value = translate("suspended")
79 else
80 dv1.value = translate("active")
81 end
82 dv2 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
83 dv2.template = "adblock/runtime"
84 if parse ~= nil then
85 dv2.value = parse.data.adblock_version or translate("n/a")
86 else
87 dv2.value = translate("n/a")
88 end
89
90 dv3 = s:option(DummyValue, "fetch_info", translate("Download Utility (SSL Library)"),
91 translate("For SSL protected blocklist sources you need a suitable SSL library, e.g. 'libustream-ssl' or the wget 'built-in'."))
92 dv3.template = "adblock/runtime"
93 if parse ~= nil then
94 dv3.value = parse.data.fetch_info or translate("n/a")
95 else
96 dv3.value = translate("n/a")
97 end
98
99 dv4 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
100 dv4.template = "adblock/runtime"
101 if parse ~= nil then
102 dv4.value = parse.data.dns_backend or translate("n/a")
103 else
104 dv4.value = translate("n/a")
105 end
106
107 dv5 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
108 dv5.template = "adblock/runtime"
109 if parse ~= nil then
110 dv5.value = parse.data.blocked_domains or translate("n/a")
111 else
112 dv5.value = translate("n/a")
113 end
114
115 dv6 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
116 dv6.template = "adblock/runtime"
117 if parse ~= nil then
118 dv6.value = parse.data.last_rundate or translate("n/a")
119 else
120 dv6.value = translate("n/a")
121 end
122
123 -- Blocklist table
124
125 bl = m:section(TypedSection, "source", translate("Blocklist sources"),
126 translate("Available blocklist sources. ")
127 .. translate("Note that list URLs and Shallalist category selections are configurable in the 'Advanced' section."))
128 bl.template = "cbi/tblsection"
129
130 name = bl:option(Flag, "enabled", translate("Enabled"))
131 name.rmempty = false
132
133 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
134 function ssl.cfgvalue(self, section)
135 local source = self.map:get(section, "adb_src")
136 if source and source:match("https://") then
137 return translate("Yes")
138 else
139 return translate("No")
140 end
141 end
142
143 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
144
145 -- Extra options
146
147 e = m:section(NamedSection, "global", "adblock", translate("Extra options"),
148 translate("Options for further tweaking in case the defaults are not suitable for you."))
149
150 e1 = e:option(Flag, "adb_forcedns", translate("Force local DNS"),
151 translate("Redirect all DNS queries to the local resolver."))
152 e1.default = e1.disabled
153 e1.rmempty = false
154
155 e2 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
156 translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB RAM)"))
157 e2.default = e2.disabled
158 e2.rmempty = false
159
160 e3 = e:option(Flag, "adb_manmode", translate("Manual mode"),
161 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
162 e3.default = e3.disabled
163 e3.rmempty = false
164
165 e4 = e:option(Flag, "adb_backup", translate("Enable blocklist backup"),
166 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in manual mode."))
167 e4.default = e4.disabled
168 e4.rmempty = false
169
170 e5 = e:option(Value, "adb_backupdir", translate("Backup directory"))
171 e5.datatype = "directory"
172 e5.rmempty = false
173
174 return m