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
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")
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")
19 -- Main adblock options
21 s = m:section(NamedSection, "global", "adblock")
23 o1 = s:option(Flag, "adb_enabled", translate("Enable adblock"))
27 btn = s:option(Button, "", translate("Suspend / Resume adblock"))
28 if data.adblock == nil then
29 btn.inputtitle = "n/a"
32 elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
33 btn.inputtitle = translate("Suspend adblock")
34 btn.inputstyle = "reset"
37 luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
40 btn.inputtitle = translate("Resume adblock")
41 btn.inputstyle = "apply"
44 luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
48 o2 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
49 o2.default = o2.disabled
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."))
57 -- Runtime information
59 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
60 ds.template = "cbi/nullsection"
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"
70 dv2 = s:option(DummyValue, "status", translate("Status"))
71 dv2.template = "adblock/runtime"
72 if data.adblock == nil then
74 elseif dnsFile1 ~= "" or dnsFile2 ~= "" then
77 dv2.value = "suspended"
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"
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"
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"
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"
111 name = bl:option(Flag, "enabled", translate("Enabled"))
114 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
118 s = m:section(NamedSection, "global", "adblock", translate("Backup options"))
120 o4 = s:option(Flag, "adb_backup", translate("Enable blocklist backup"))
124 o5 = s:option(Value, "adb_backupdir", translate("Backup directory"))
126 o5.datatype = "directory"