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")
9 local dnsFile2 = sys.exec("find '/var/lib/unbound' -maxdepth 1 -type f -name 'adb_list*' -print")
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 if data.adblock ~= nil and (dnsFile1 ~= "" or dnsFile2 ~= "") then
28 btn = s:option( Button, "_btn", translate("Suspend adblock"))
29 btn.inputstyle = "reset"
31 luci.sys.call("/etc/init.d/adblock suspend")
34 btn = s:option( Button, "_btn", translate("Resume adblock"))
35 btn.inputstyle = "apply"
37 luci.sys.call("/etc/init.d/adblock resume")
41 o2 = s:option(Flag, "adb_debug", translate("Enable verbose debug logging"))
42 o2.default = o2.disabled
45 o3 = s:option(Value, "adb_iface", translate("Restrict interface reload trigger to certain interface(s)"),
46 translate("Space separated list of interfaces that trigger a reload action. "..
47 "To disable reload trigger at all set it to 'false'."))
50 -- Runtime information
52 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
53 ds.template = "cbi/nullsection"
55 dv1 = s:option(DummyValue, "adblock_version", translate("Adblock version"))
56 if data.adblock ~= nil then
57 dv1.value = data.adblock.adblock.adblock_version or "?"
61 dv1.template = "adblock/runtime"
63 dv2 = s:option(DummyValue, "status", translate("Status"))
64 if dnsFile1 ~= "" or dnsFile2 ~= "" then
67 dv2.value = "suspended"
69 dv2.template = "adblock/runtime"
71 dv3 = s:option(DummyValue, "dns_backend", translate("DNS backend"))
72 if data.adblock ~= nil then
73 dv3.value = data.adblock.adblock.dns_backend or "?"
77 dv3.template = "adblock/runtime"
79 dv4 = s:option(DummyValue, "blocked_domains", translate("Blocked domains (overall)"))
80 if data.adblock ~= nil then
81 dv4.value = data.adblock.adblock.blocked_domains or "?"
85 dv4.template = "adblock/runtime"
87 dv5 = s:option(DummyValue, "last_rundate", translate("Last rundate"))
88 if data.adblock ~= nil then
89 dv5.value = data.adblock.adblock.last_rundate or "?"
93 dv5.template = "adblock/runtime"
97 bl = m:section(TypedSection, "source", translate("Blocklist sources"),
98 translate("Available blocklist sources. ")
99 .. translate("Note that list URLs and Shallalist category selections are configurable in the 'Advanced' section."))
100 bl.template = "cbi/tblsection"
102 name = bl:option(Flag, "enabled", translate("Enabled"))
105 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
109 s = m:section(NamedSection, "global", "adblock", translate("Backup options"))
111 o4 = s:option(Flag, "adb_backup", translate("Enable blocklist backup"))
115 o5 = s:option(Value, "adb_backupdir", translate("Backup directory"))
117 o5.datatype = "directory"