1 -- Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
4 local fs = require("nixio.fs")
5 local uci = require("luci.model.uci").cursor()
6 local util = require("luci.util")
7 local dump = util.ubus("network.interface", "dump", {})
9 m = Map("adblock", translate("Adblock"),
10 translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
11 .. translatef("For further information "
12 .. "<a href=\"%s\" target=\"_blank\">"
13 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
15 -- Main adblock options
17 s = m:section(NamedSection, "global", "adblock")
19 o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
20 o1.default = o1.disabled
23 o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
24 translate("List of supported DNS backends with their default list export directory. ")
25 .. translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
26 o2:value("dnsmasq", "dnsmasq (/tmp)")
27 o2:value("unbound", "unbound (/var/lib/unbound)")
28 o2:value("named", "named (/var/lib/bind)")
29 o2:value("kresd", "kresd (/etc/kresd)")
30 o2:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
31 o2.default = "dnsmasq (/tmp)"
34 o3 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
35 translate("List of supported and fully pre-configured download utilities."))
36 o3:value("uclient-fetch")
40 o3:value("wget-nossl", "wget-nossl (noSSL)")
41 o3:value("busybox", "wget-busybox (noSSL)")
42 o3.default = "uclient-fetch"
45 o4 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
46 translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
47 .. translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
52 for i, v in ipairs(dump.interface) do
53 if v.interface ~= "loopback" then
60 -- Runtime information
62 ds = s:option(DummyValue, "_dummy")
63 ds.template = "adblock/runtime"
67 bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
68 translate("<b>Caution:</b> To prevent OOM exceptions on low memory devices with less than 64 MB free RAM, please only select a few of them!"))
69 bl.template = "adblock/blocklist"
71 name = bl:option(Flag, "enabled", translate("Enabled"))
74 ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
75 function ssl.cfgvalue(self, section)
76 local source = self.map:get(section, "adb_src")
77 if source and source:match("https://") then
78 return translate("Yes")
80 return translate("No")
84 des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
86 cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
87 cat.datatype = "uciname"
92 e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
93 translate("Options for further tweaking in case the defaults are not suitable for you."))
95 e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
96 translate("Enable verbose debug logging in case of any processing error."))
97 e1.default = e1.disabled
100 e2 = e:option(Flag, "adb_nice", translate("Low Priority Service"),
101 translate("Set the nice level to 'low priority' and the adblock background processing will take less resources from the system. ")
102 ..translate("This change requires a manual service stop/re-start to take effect."))
103 e2.default = e2.disabled
108 e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
109 translate("Redirect all DNS queries from 'lan' zone to the local resolver, apply to udp and tcp protocol on ports 53, 853 and 5353."))
110 e3.default = e3.disabled
113 e4 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
114 translate("Enable memory intense overall sort / duplicate removal on low memory devices (< 64 MB free RAM)"))
115 e4.default = e4.disabled
118 e5 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
119 translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in backup mode."))
120 e5.default = e5.disabled
123 e6 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
124 translate("Target directory for adblock backups. Please use only non-volatile disks, e.g. an external usb stick."))
125 e6:depends("adb_backup", 1)
126 e6.datatype = "directory"
130 e7 = e:option(Flag, "adb_backup_mode", translate("Backup Mode"),
131 translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
132 e7:depends("adb_backup", 1)
133 e7.default = e7.disabled
136 e8 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
137 translate("Size of the download queue to handle downloads & list processing in parallel (default '4'). ")
138 .. translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
140 e8.datatype = "range(1,32)"
143 e9 = e:option(Flag, "adb_jail", translate("'Jail' Blocklist Creation"),
144 translate("Builds an additional 'Jail' list (/tmp/adb_list.jail) to block access to all domains except those listed in the whitelist file. ")
145 .. translate("You can use this restrictive blocklist manually e.g. for guest wifi or kidsafe configurations."))
146 e9.default = e9.disabled
149 e9 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
150 translate("Flush DNS Cache after adblock processing."))
151 e9.default = e9.disabled
154 e10 = e:option(Flag, "adb_notify", translate("Email Notification"),
155 translate("Send notification emails in case of a processing error or if domain count is ≤ 0. ")
156 .. translate("Please note: this needs additional 'msmtp' package installation and setup."))
157 e10.default = e10.disabled
160 e11 = e:option(Value, "adb_notifycnt", translate("Email Notification Count"),
161 translate("Raise the minimum email notification count, to get emails if the overall count is less or equal to the given limit (default 0), ")
162 .. translate("e.g. to receive an email notification with every adblock update set this value to 150000."))
164 e11.datatype = "min(0)"
167 e12 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
168 translate("Target directory for the generated blocklist 'adb_list.overall'."))
169 e12.datatype = "directory"
172 e13 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
173 translate("Full path to the whitelist file."))
174 e13.datatype = "file"
175 e13.default = "/etc/adblock/adblock.whitelist"
178 e14 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
179 translate("Additional trigger delay in seconds before adblock processing begins."))
180 e14.datatype = "range(1,60)"