Merge pull request #18400 from nmav/tmp-tang-self-contained
[feed/packages.git] / net / simple-adblock / files / simple-adblock.init
1 #!/bin/sh /etc/rc.common
2 # Copyright 2017-2022 Stan Grishin (stangri@melmac.ca)
3 # shellcheck disable=SC1091,SC2016,SC3043,SC3057,SC3060
4
5 # shellcheck disable=SC2034
6 START=94
7 # shellcheck disable=SC2034
8 USE_PROCD=1
9 LC_ALL=C
10
11 if type extra_command 1>/dev/null 2>&1; then
12 extra_command 'allow' 'Allows domain in current block-list and config'
13 extra_command 'check' 'Checks if specified domain is found in current block-list'
14 extra_command 'dl' 'Force-downloads all enabled block-list'
15 extra_command 'killcache' 'Delete all cached files'
16 extra_command 'sizes' 'Displays the file-sizes of enabled block-lists'
17 extra_command 'version' 'Show version information'
18 else
19 # shellcheck disable=SC2034
20 EXTRA_COMMANDS='allow check dl killcache sizes status_service version'
21 # shellcheck disable=SC2034
22 EXTRA_HELP=' allow Allows domain(s) in current block-list and config
23 check Checks if specified domain is found in current block-list
24 dl Force-downloads all enabled block-list
25 sizes Displays the file-sizes of enabled block-lists'
26 fi
27
28 readonly PKG_VERSION='dev-test'
29 readonly packageName='simple-adblock'
30 readonly serviceName="$packageName $PKG_VERSION"
31 readonly packageConfigFile="/etc/config/${packageName}"
32 readonly dnsmasqAddnhostsFile="/var/run/${packageName}/dnsmasq.addnhosts"
33 readonly dnsmasqAddnhostsCache="/var/run/${packageName}/dnsmasq.addnhosts.cache"
34 readonly dnsmasqAddnhostsGzip="${packageName}.dnsmasq.addnhosts.gz"
35 readonly dnsmasqAddnhostsFilter='s|^|127.0.0.1 |;s|$||'
36 readonly dnsmasqAddnhostsFilterIPv6='s|^|:: |;s|$||'
37 readonly dnsmasqConfFile="/tmp/dnsmasq.d/${packageName}"
38 readonly dnsmasqConfCache="/var/run/${packageName}/dnsmasq.conf.cache"
39 readonly dnsmasqConfGzip="${packageName}.dnsmasq.conf.gz"
40 readonly dnsmasqConfFilter='s|^|local=/|;s|$|/|'
41 readonly dnsmasqIpsetFile="/tmp/dnsmasq.d/${packageName}.ipset"
42 readonly dnsmasqIpsetCache="/var/run/${packageName}/dnsmasq.ipset.cache"
43 readonly dnsmasqIpsetGzip="${packageName}.dnsmasq.ipset.gz"
44 readonly dnsmasqIpsetFilter='s|^|ipset=/|;s|$|/adb|'
45 readonly dnsmasqNftsetFile="/tmp/dnsmasq.d/${packageName}.nftset"
46 readonly dnsmasqNftsetCache="/var/run/${packageName}/dnsmasq.nftset.cache"
47 readonly dnsmasqNftsetGzip="${packageName}.dnsmasq.nftset.gz"
48 readonly dnsmasqNftsetFilter='s|^|nftset=/|;s|$|/4#inet#fw4#adb4|'
49 readonly dnsmasqNftsetFilterIPv6='s|^|nftset=/|;s|$|/4#inet#fw4#adb4,6#inet#fw4#adb6|'
50 readonly dnsmasqServersFile="/var/run/${packageName}/dnsmasq.servers"
51 readonly dnsmasqServersCache="/var/run/${packageName}/dnsmasq.servers.cache"
52 readonly dnsmasqServersGzip="${packageName}.dnsmasq.servers.gz"
53 readonly dnsmasqServersFilter='s|^|server=/|;s|$|/|'
54 readonly unboundFile="/var/lib/unbound/adb_list.${packageName}"
55 readonly unboundCache="/var/run/${packageName}/unbound.cache"
56 readonly unboundGzip="${packageName}.unbound.gz"
57 readonly unboundFilter='s|^|local-zone: "|;s|$|" static|'
58 readonly A_TMP="/var/${packageName}.hosts.a.tmp"
59 readonly B_TMP="/var/${packageName}.hosts.b.tmp"
60 readonly jsonFile="/var/run/${packageName}/${packageName}.json"
61 readonly sharedMemoryError="/dev/shm/$packageName-error"
62 readonly hostsFilter='/localhost/d;/^#/d;/^[^0-9]/d;s/^0\.0\.0\.0.//;s/^127\.0\.0\.1.//;s/[[:space:]]*#.*$//;s/[[:cntrl:]]$//;s/[[:space:]]//g;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
63 readonly domainsFilter='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
64 readonly adBlockPlusFilter='/^#/d;/^!/d;s/[[:space:]]*#.*$//;s/^||//;s/\^$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
65 readonly dnsmasqFileFilter='\|^server=/[[:alnum:]_.-].*/|!d'
66 readonly _OK_='\033[0;32m\xe2\x9c\x93\033[0m'
67 readonly _FAIL_='\033[0;31m\xe2\x9c\x97\033[0m'
68 readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m'
69 readonly __FAIL__='\033[0;31m[\xe2\x9c\x97]\033[0m'
70 readonly _ERROR_='\033[0;31mERROR\033[0m'
71 readonly _WARNING_='\033[0;33mWARNING\033[0m'
72 # shellcheck disable=SC2155
73 readonly ipset="$(command -v ipset)"
74 # shellcheck disable=SC2155
75 readonly nft="$(command -v nft)"
76 readonly canaryDomainsMozilla='use-application-dns.net'
77 readonly canaryDomainsiCloud='mask.icloud.com mask-h2.icloud.com'
78
79 dl_command=
80 dl_flag=
81 isSSLSupported=
82 outputFilter=
83 outputFilterIPv6=
84 outputFile=
85 outputGzip=
86 outputCache=
87 awk='awk'
88 load_environment_flag=
89
90 debug() { local i j; for i in "$@"; do eval "j=\$$i"; echo "${i}: ${j} "; done; }
91
92 uci_add_list_if_new() {
93 local PACKAGE="$1"
94 local CONFIG="$2"
95 local OPTION="$3"
96 local VALUE="$4"
97 local i
98 [ -n "$PACKAGE" ] && [ -n "$CONFIG" ] && [ -n "$OPTION" ] && [ -n "$VALUE" ] || return 1
99 for i in $(uci_get "$PACKAGE" "$CONFIG" "$OPTION"); do
100 [ "$i" = "$VALUE" ] && return 0
101 done
102 uci_add_list "$PACKAGE" "$CONFIG" "$OPTION" "$VALUE"
103 }
104 uci_changes() {
105 local PACKAGE="$1"
106 local CONFIG="$2"
107 local OPTION="$3"
108 /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} changes "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
109 }
110
111 ipset() { "$ipset" "$@" >/dev/null 2>&1; }
112 nft() { "$nft" "$@" >/dev/null 2>&1; }
113
114 get_text() {
115 local r
116 case "$1" in
117 errorConfigValidationFail) r="$packageName config validation failed";;
118 errorServiceDisabled) r="$packageName is currently disabled";;
119 errorNoDnsmasqIpset)
120 r="dnsmasq ipset support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support ipset";;
121 errorNoIpset)
122 r="dnsmasq ipset support is enabled in $packageName, but ipset is either not installed or installed ipset does not support 'hash:net' type";;
123 errorNoDnsmasqNftset)
124 r="dnsmasq nft set support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support nft set";;
125 errorNoNft) r="dnsmasq nft sets support is enabled in $packageName, but nft is not installed";;
126 errorNoWanGateway) r="The ${serviceName} failed to discover WAN gateway";;
127 errorOutputDirCreate) r="failed to create directory for %s file";;
128 errorOutputFileCreate) r="failed to create $outputFile file";;
129 errorFailDNSReload) r="failed to restart/reload DNS resolver";;
130 errorSharedMemory) r="failed to access shared memory";;
131 errorSorting) r="failed to sort data file";;
132 errorOptimization) r="failed to optimize data file";;
133 errorAllowListProcessing) r="failed to process allow-list";;
134 errorDataFileFormatting) r="failed to format data file";;
135 errorMovingDataFile) r="failed to move data file '${A_TMP}' to '${outputFile}'";;
136 errorCreatingCompressedCache) r="failed to create compressed cache";;
137 errorRemovingTempFiles) r="failed to remove temporary files";;
138 errorRestoreCompressedCache) r="failed to unpack compressed cache";;
139 errorRestoreCache) r="failed to move '$outputCache' to '$outputFile'";;
140 errorOhSnap) r="failed to create block-list or restart DNS resolver";;
141 errorStopping) r="failed to stop $serviceName";;
142 errorDNSReload) r="failed to reload/restart DNS resolver";;
143 errorDownloadingConfigUpdate) r="failed to download Config Update file";;
144 errorDownloadingList) r="failed to download";;
145 errorParsingConfigUpdate) r="failed to parse Config Update file";;
146 errorParsingList) r="failed to parse";;
147 errorNoSSLSupport) r="no HTTPS/SSL support on device";;
148 errorCreatingDirectory) r="failed to create output/cache/gzip file directory";;
149
150 statusNoInstall) r="$serviceName is not installed or not found";;
151 statusStopped) r="Stopped";;
152 statusStarting) r="Starting";;
153 statusRestarting) r="Restarting";;
154 statusForceReloading) r="Force Reloading";;
155 statusDownloading) r="Downloading";;
156 statusProcessing) r="Processing";;
157 statusError) r="Error";;
158 statusWarning) r="Warning";;
159 statusFail) r="Fail";;
160 statusSuccess) r="Success";;
161
162 warningExternalDnsmasqConfig)
163 r="use of external dnsmasq config file detected, please set 'dns' option to 'dnsmasq.conf'";;
164 warningMissingRecommendedPackages) r="Some recommended packages are missing";;
165 warningInvalidCompressedCacheDir) r="invalid compressed cache directory '%s'";;
166 esac
167 echo "$r"
168 }
169
170 output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; }
171 output_okn() { output 1 "$_OK_\\n"; output 2 "$__OK__\\n"; }
172 output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n"; }
173 output_failn() { output 1 "$_FAIL_\\n"; output 2 "$__FAIL__\\n"; }
174 str_replace() { printf "%b" "$1" | sed -e "s/$(printf "%b" "$2")/$(printf "%b" "$3")/g"; }
175 str_contains() { test "$1" != "$(str_replace "$1" "$2" '')"; }
176 is_greater() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
177 is_greater_or_equal() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$2"; }
178 is_chaos_calmer() { ubus -S call system board | grep -q 'Chaos Calmer'; }
179 led_on(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'default-on' > "${1}/trigger" 2>&1; fi; }
180 led_off(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'none' > "${1}/trigger" 2>&1; fi; }
181 dnsmasq_hup() { killall -q -s HUP dnsmasq; }
182 dnsmasq_kill() { killall -q -s KILL dnsmasq; }
183 dnsmasq_restart() { /etc/init.d/dnsmasq restart >/dev/null 2>&1; }
184 unbound_restart() { /etc/init.d/unbound restart >/dev/null 2>&1; }
185 is_present() { command -v "$1" >/dev/null 2>&1; }
186 sanitize_dir() { [ -d "$(readlink -fn "$1")" ] && readlink -fn "$1"; }
187
188 output() {
189 # Can take a single parameter (text) to be output at any verbosity
190 # Or target verbosity level and text to be output at specifc verbosity
191 local msg memmsg logmsg
192 local sharedMemoryOutput="/dev/shm/$packageName-output"
193 verbosity="${verbosity:-2}"
194 if [ $# -ne 1 ]; then
195 if [ $((verbosity & $1)) -gt 0 ] || [ "$verbosity" = "$1" ]; then shift; else return 0; fi
196 fi
197 [ -t 1 ] && printf "%b" "$1"
198 msg="${1//$serviceName /service }";
199 if [ "$(printf "%b" "$msg" | wc -l)" -gt 0 ]; then
200 [ -s "$sharedMemoryOutput" ] && memmsg="$(cat "$sharedMemoryOutput")"
201 logmsg="$(printf "%b" "${memmsg}${msg}" | sed 's/\x1b\[[0-9;]*m//g')"
202 logger -t "${packageName:-service} [$$]" "$(printf "%b" "$logmsg")"
203 rm -f "$sharedMemoryOutput"
204 else
205 printf "%b" "$msg" >> "$sharedMemoryOutput"
206 fi
207 }
208
209 load_network() {
210 local param="$1"
211 local i j wan_if wan_gw wan_proto
212 local counter wan_if_timeout="$procd_boot_wan_timeout" wan_gw_timeout='5'
213 counter=0
214 while [ -z "$wan_if" ]; do
215 network_flush_cache
216 network_find_wan wan_if
217 if [ -n "$wan_if" ]; then
218 output "WAN interface found: '${wan_if}'.\\n"
219 break
220 fi
221 if [ "$counter" -gt "$wan_if_timeout" ]; then
222 output "WAN interface timeout, assuming 'wan'.\\n"
223 wan_if='wan'
224 break
225 fi
226 counter=$((counter+1))
227 output "Waiting to discover WAN Interface...\\n"
228 sleep 1
229 done
230
231 counter=0
232 wan_proto="$(uci -q get "network.${wan_if}.proto")"
233 if [ "$wan_proto" = 'pppoe' ]; then
234 wan_gw_timeout=$((wan_gw_timeout+10))
235 fi
236 while [ "$counter" -le "$wan_gw_timeout" ]; do
237 network_flush_cache
238 network_get_gateway wan_gw "$wan_if"
239 if [ -n "$wan_gw" ]; then
240 output "WAN gateway found: '${wan_gw}.'\\n"
241 return 0
242 fi
243 counter=$((counter+1))
244 output "Waiting to discover $wan_if gateway...\\n"
245 sleep 1
246 done
247 json add error "errorNoWanGateway"
248 output "${_ERROR_}: $(get_text 'errorNoWanGateway')!\\n"; return 1;
249 }
250
251 load_environment() {
252 local i j
253 local validation_result="$1" param="$2"
254
255 [ -z "$load_environment_flag" ] || return 0
256
257 if [ "$validation_result" != '0' ]; then
258 json add error "errorConfigValidationFail"
259 output "${_ERROR_}: $(get_text 'errorConfigValidationFail')!\\n"
260 output "Please check if the '$packageConfigFile' contains correct values for config options.\\n"
261 return 1
262 fi
263
264 if [ "$enabled" -eq 0 ]; then
265 json add error "errorServiceDisabled"
266 output "${_ERROR_}: $(get_text 'errorServiceDisabled')!\\n"
267 output "Run the following commands before starting service again:\\n"
268 output "uci set ${packageName}.config.enabled='1'; uci commit $packageName;\\n"
269 return 1
270 fi
271
272 if [ "$debug" -ne 0 ]; then
273 exec 1>>/tmp/simple-adblock.log
274 exec 2>&1
275 set -x
276 fi
277
278 if [ -n "$dnsmasq_config_file_url" ]; then
279 case "$dns" in
280 dnsmasq.conf) :;;
281 *)
282 if [ "$param" != 'quiet' ]; then
283 json add warning "warningExternalDnsmasqConfig"
284 output "${_WARNING_}: $(get_text 'warningExternalDnsmasqConfig')!\\n"
285 fi
286 ;;
287 esac
288 fi
289
290 case "$dns" in
291 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
292 if dnsmasq -v 2>/dev/null | grep -q 'no-IDN' || ! dnsmasq -v 2>/dev/null | grep -q -w 'IDN'; then
293 allow_non_ascii=0
294 fi
295 ;;
296 unbound.adb_list)
297 allow_non_ascii=1;;
298 esac
299
300 case "$dns" in
301 dnsmasq.ipset)
302 if dnsmasq -v 2>/dev/null | grep -q 'no-ipset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'ipset'; then
303 if [ "$param" != 'quiet' ]; then
304 json add error "errorNoDnsmasqIpset"
305 output "${_ERROR_}: $(get_text 'errorNoDnsmasqIpset')!\\n"
306 fi
307 dns='dnsmasq.servers'
308 fi
309 if ! ipset help hash:net; then
310 if [ "$param" != 'quiet' ]; then
311 json add error "errorNoIpset"
312 output "${_ERROR_}: $(get_text 'errorNoIpset')!\\n"
313 fi
314 dns='dnsmasq.servers'
315 fi
316 ;;
317 dnsmasq.nftset)
318 if dnsmasq -v 2>/dev/null | grep -q 'no-nftset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'nftset'; then
319 if [ "$param" != 'quiet' ]; then
320 json add error "errorNoDnsmasqNftset"
321 output "${_ERROR_}: $(get_text 'errorNoDnsmasqNftset')!\\n"
322 fi
323 dns='dnsmasq.servers'
324 fi
325 if [ -z "$nft" ]; then
326 if [ "$param" != 'quiet' ]; then
327 json add error "errorNoNft"
328 output "${_ERROR_}: $(get_text 'errorNoNft')!\\n"
329 fi
330 dns='dnsmasq.servers'
331 fi
332 ;;
333 esac
334
335 if [ "$(sanitize_dir "$compressed_cache_dir")" = '/' ]; then
336 compressed_cache_dir=''
337 elif [ -n "$(sanitize_dir "$compressed_cache_dir")" ]; then
338 compressed_cache_dir="$(sanitize_dir "$compressed_cache_dir")"
339 else
340 json add warning 'warningInvalidCompressedCacheDir' "$compressed_cache_dir"
341 compressed_cache_dir="/etc"
342 fi
343
344 case "$dns" in
345 dnsmasq.addnhosts)
346 outputFilter="$dnsmasqAddnhostsFilter"
347 outputFile="$dnsmasqAddnhostsFile"
348 outputCache="$dnsmasqAddnhostsCache"
349 outputGzip="${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
350 if [ "$ipv6_enabled" -ne 0 ]; then
351 outputFilterIPv6="$dnsmasqAddnhostsFilterIPv6"
352 fi
353 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
354 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
355 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
356 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
357 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
358 ;;
359 dnsmasq.conf)
360 outputFilter="$dnsmasqConfFilter"
361 outputFile="$dnsmasqConfFile"
362 outputCache="$dnsmasqConfCache"
363 outputGzip="${compressed_cache_dir}/${dnsmasqConfGzip}"
364 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
365 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
366 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
367 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
368 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
369 ;;
370 dnsmasq.ipset)
371 outputFilter="$dnsmasqIpsetFilter"
372 outputFile="$dnsmasqIpsetFile"
373 outputCache="$dnsmasqIpsetCache"
374 outputGzip="${compressed_cache_dir}/${dnsmasqIpsetGzip}"
375 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
376 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
377 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
378 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
379 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
380 ;;
381 dnsmasq.nftset)
382 if [ "$ipv6_enabled" -ne 0 ]; then
383 outputFilter="$dnsmasqNftsetFilterIPv6"
384 else
385 outputFilter="$dnsmasqNftsetFilter"
386 fi
387 outputFile="$dnsmasqNftsetFile"
388 outputCache="$dnsmasqNftsetCache"
389 outputGzip="${compressed_cache_dir}/${dnsmasqNftsetGzip}"
390 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
391 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
392 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
393 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
394 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
395 ;;
396 dnsmasq.servers)
397 outputFilter="$dnsmasqServersFilter"
398 outputFile="$dnsmasqServersFile"
399 outputCache="$dnsmasqServersCache"
400 outputGzip="${compressed_cache_dir}/${dnsmasqServersGzip}"
401 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
402 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
403 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
404 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
405 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
406 ;;
407 unbound.adb_list)
408 outputFilter="$unboundFilter"
409 outputFile="$unboundFile"
410 outputCache="$unboundCache"
411 outputGzip="$unboundGzip"
412 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
413 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
414 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
415 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
416 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
417 ;;
418 esac
419
420 for i in "$jsonFile" "$outputFile" "$outputCache" "$outputGzip"; do
421 if ! mkdir -p "$(dirname "$i")"; then
422 if [ "$param" != 'quiet' ]; then
423 json add error "errorOutputDirCreate" "$i"
424 output "${_ERROR_}: $(get_text 'errorOutputDirCreate' "$i")!\\n"
425 fi
426 fi
427 done
428
429 is_present 'gawk' && awk='gawk'
430 if ! is_present '/usr/libexec/grep-gnu' || ! is_present '/usr/libexec/sed-gnu' || \
431 ! is_present '/usr/libexec/sort-coreutils' || ! is_present 'gawk'; then
432 local s="opkg update; opkg --force-overwrite install"
433 is_present 'gawk' || s="$s gawk"
434 is_present '/usr/libexec/grep-gnu' || s="$s grep"
435 is_present '/usr/libexec/sed-gnu' || s="$s sed"
436 is_present '/usr/libexec/sort-coreutils' || s="$s coreutils-sort"
437 if [ "$param" != 'quiet' ]; then
438 json add warning "warningMissingRecommendedPackages" "${i}"
439 output "${_WARNING_}: $(get_text 'warningMissingRecommendedPackages'), install them by running:\\n"
440 output "$s;\\n"
441 fi
442 fi
443 # Prefer curl because it supports the file:// scheme.
444 if is_present 'curl'; then
445 dl_command="curl --silent --insecure"
446 dl_command="${dl_command}${curl_additional_param:+ $curl_additional_param}"
447 dl_command="${dl_command}${curl_max_file_size:+ --max-filesize $curl_max_file_size}"
448 dl_command="${dl_command}${curl_retry:+ --retry $curl_retry}"
449 dl_command="${dl_command}${download_timeout:+ --connect-timeout $download_timeout}"
450 dl_flag="-o"
451 elif is_present '/usr/libexec/wget-ssl'; then
452 dl_command="/usr/libexec/wget-ssl --no-check-certificate -q"
453 dl_command="${dl_command}${download_timeout:+ --timeout $download_timeout}"
454 dl_flag="-O"
455 elif is_present wget && wget --version 2>/dev/null | grep -q "+https"; then
456 dl_command="wget --no-check-certificate -q"
457 dl_command="${dl_command}${download_timeout:+ --timeout $download_timeout}"
458 dl_flag="-O"
459 else
460 dl_command="uclient-fetch --no-check-certificate -q"
461 dl_command="${dl_command}${download_timeout:+ --timeout $download_timeout}"
462 dl_flag="-O"
463 fi
464 led="${led:+/sys/class/leds/$led}"
465 if curl --version 2>/dev/null | grep -q "https" \
466 || wget --version 2>/dev/null | grep -q "+https" \
467 || grep -q "libustream-mbedtls" /usr/lib/opkg/status \
468 || grep -q "libustream-openssl" /usr/lib/opkg/status \
469 || grep -q "libustream-wolfssl" /usr/lib/opkg/status; then
470 isSSLSupported=1
471 else
472 unset isSSLSupported
473 fi
474 load_environment_flag=1
475 cache 'test' && return 0
476 cache 'test_gzip' && return 0
477 if [ "$param" = 'on_boot' ]; then
478 load_network "$param"
479 return "$?"
480 else
481 return 0
482 fi
483 }
484
485 resolver() {
486 local cfg="$1" param="$2"
487 case "$param" in
488 dnsmasq.addnhosts)
489 if [ "$(uci_get 'dhcp' "$cfg" 'serversfile')" = "$dnsmasqServersFile" ]; then
490 uci_remove 'dhcp' "$cfg" 'serversfile'
491 fi
492 uci_add_list_if_new 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
493 ;;
494 cleanup|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|unbound.adb_list)
495 uci_remove_list 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
496 if [ "$(uci_get 'dhcp' "$cfg" 'serversfile')" = "$dnsmasqServersFile" ]; then
497 uci_remove 'dhcp' "$cfg" 'serversfile'
498 fi
499 ;;
500 dnsmasq.servers)
501 uci_remove_list 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
502 if [ "$(uci_get 'dhcp' "$cfg" 'serversfile')" != "$dnsmasqServersFile" ]; then
503 uci_set 'dhcp' "$cfg" 'serversfile' "$dnsmasqServersFile"
504 fi
505 ;;
506 esac
507 }
508
509 dns() {
510 local param output_text i
511 case $1 in
512 on_start)
513 if [ ! -s "$outputFile" ]; then
514 json set status "statusFail"
515 json add error "errorOutputFileCreate"
516 output "${_ERROR_}: $(get_text 'errorOutputFileCreate')!\\n"
517 return 1
518 fi
519
520 config_load 'dhcp'
521 if [ "$dns_instance" = "*" ]; then
522 config_foreach resolver 'dnsmasq' "$dns"
523 elif [ -n "$dns_instance" ]; then
524 for i in $dns_instance; do
525 resolver "@dnsmasq[$i]" "$dns" || resolver "$i" "$dns"
526 done
527 fi
528
529 case "$dns" in
530 dnsmasq.addnhosts|dnsmasq.servers)
531 param=dnsmasq_restart
532 output_text='Reloading dnsmasq'
533 ;;
534 dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset)
535 param=dnsmasq_restart
536 output_text='Restarting dnsmasq'
537 ;;
538 unbound.adb_list)
539 param=unbound_restart
540 output_text='Restarting Unbound'
541 ;;
542 esac
543
544 if [ -n "$(uci_changes dhcp)" ]; then
545 uci_commit dhcp
546 if [ "$param" = 'unbound_restart' ]; then
547 param='dnsmasq_restart; unbound_restart;'
548 output_text='Restarting Unbound/dnsmasq'
549 else
550 param=dnsmasq_restart
551 output_text='Restarting dnsmasq'
552 fi
553 fi
554 output 1 "$output_text "
555 output 2 "$output_text "
556 json set message "$output_text"
557 if eval "$param"; then
558 json set status "statusSuccess"
559 led_on "$led"
560 output_okn
561 else
562 output_fail
563 json set status "statusFail"
564 json add error "errorDNSReload"
565 output "${_ERROR_}: $(get_text 'errorDNSReload')!\\n"
566 return 1
567 fi
568 ;;
569 on_stop)
570 case "$dns" in
571 dnsmasq.addnhosts|dnsmasq.servers)
572 param=dnsmasq_restart
573 ;;
574 dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset)
575 param=dnsmasq_restart
576 ;;
577 unbound.adb_list)
578 param=unbound_restart
579 ;;
580 esac
581 if [ -n "$(uci_changes dhcp)" ]; then
582 uci_commit dhcp
583 if [ "$param" = 'unbound_restart' ]; then
584 param='dnsmasq_restart; unbound_restart;'
585 else
586 param=dnsmasq_restart
587 fi
588 fi
589 eval "$param"
590 return $?
591 ;;
592 quiet)
593 case "$dns" in
594 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
595 param=dnsmasq_restart
596 ;;
597 unbound.adb_list)
598 param=unbound_restart
599 ;;
600 esac
601 eval "$param"
602 return $?
603 ;;
604 esac
605 }
606
607 json() {
608 # shellcheck disable=SC2034
609 local action="$1" param="$2" value="$3"
610 shift 3
611 # shellcheck disable=SC2124
612 local extras="$@" line
613 local status message error stats
614 local reload restart curReload curRestart ret i
615 if [ -s "$jsonFile" ]; then
616 json_load_file "$jsonFile" 2>/dev/null
617 json_select 'data' 2>/dev/null
618 for i in status message error stats reload restart; do
619 json_get_var $i "$i" 2>/dev/null
620 done
621 fi
622 case "$action" in
623 get)
624 case "$param" in
625 triggers)
626 curReload="$parallel_downloads $debug $download_timeout $allowed_domain $blocked_domain $allowed_domains_url \
627 $blocked_adblockplus_url $blocked_domains_url $blocked_hosts_url $dns $config_update_enabled $config_update_url \
628 $dnsmasq_config_file_url $curl_additional_param $curl_max_file_size $curl_retry"
629 curRestart="$compressed_cache $compressed_cache_dir $force_dns $led $force_dns_port"
630 if [ ! -s "$jsonFile" ]; then
631 ret='on_boot'
632 elif [ "$curReload" != "$reload" ]; then
633 ret='download'
634 elif [ "$curRestart" != "$restart" ]; then
635 ret='restart'
636 fi
637 printf "%b" "$ret"
638 return;;
639 *)
640 printf "%b" "$(eval echo "\$$param")"; return;;
641 esac
642 ;;
643 add)
644 line="$(eval echo "\$$param")"
645 eval "$param"='${line:+$line }${value}${extras:+|$extras}'
646 ;;
647 del)
648 case "$param" in
649 all)
650 unset status message error stats;;
651 triggers)
652 unset reload restart;;
653 *)
654 unset "$param";;
655 esac
656 ;;
657 set)
658 case "$param" in
659 triggers)
660 reload="$parallel_downloads $debug $download_timeout $allowed_domain $blocked_domain $allowed_domains_url \
661 $blocked_adblockplus_url $blocked_domains_url $blocked_hosts_url $dns $config_update_enabled $config_update_url \
662 $dnsmasq_config_file_url $curl_additional_param $curl_max_file_size $curl_retry"
663 restart="$compressed_cache $compressed_cache_dir $force_dns $led $force_dns_port"
664 ;;
665 *)
666 eval "$param"='${value}${extras:+|$extras}';;
667 esac
668 ;;
669 esac
670 json_init
671 json_add_object 'data'
672 json_add_string version "$PKG_VERSION"
673 json_add_string status "$status"
674 json_add_string message "$message"
675 json_add_string error "$error"
676 json_add_string stats "$stats"
677 json_add_string reload "$reload"
678 json_add_string restart "$restart"
679 json_close_object
680 mkdir -p "$(dirname "$jsonFile")"
681 json_dump > "$jsonFile"
682 sync
683 }
684
685 cache() {
686 local R_TMP
687 case "$1" in
688 create|backup)
689 [ -s "$outputFile" ] && { mv -f "$outputFile" "$outputCache"; true > "$outputFile"; } >/dev/null 2>/dev/null
690 return $?
691 ;;
692 restore|use)
693 [ -s "$outputCache" ] && mv "$outputCache" "$outputFile" >/dev/null 2>/dev/null
694 return $?
695 ;;
696 test)
697 [ -s "$outputCache" ]
698 return $?
699 ;;
700 test_gzip)
701 [ -s "$outputGzip" ] && gzip -t -c "$outputGzip"
702 return $?
703 ;;
704 create_gzip)
705 rm -f "$outputGzip" >/dev/null 2>/dev/null
706 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
707 if gzip < "$outputFile" > "$R_TMP"; then
708 if mv "$R_TMP" "$outputGzip"; then
709 rm -f "$R_TMP"
710 return 0
711 else
712 rm -f "$R_TMP"
713 return 1
714 fi
715 else
716 return 1
717 fi
718 ;;
719 expand|unpack|unpack_gzip)
720 [ -s "$outputGzip" ] && gzip -dc < "$outputGzip" > "$outputCache"
721 return $?
722 ;;
723 esac
724 }
725
726 process_url() {
727 local label type D_TMP R_TMP
728 if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then return 1; fi
729 label="${1##*//}"; label="${label%%/*}";
730 case "$2" in
731 adbp) label="ADBPlus: $label"; filter="$adBlockPlusFilter"
732 ;;
733 dnsmasq) label="Dnsmasq: $label"; filter="$dnsmasqFileFilter"
734 ;;
735 domains) label="Domains: $label"; filter="$domainsFilter"
736 ;;
737 hosts) label="Hosts: $label"; filter="$hostsFilter"
738 ;;
739 esac
740 case "$3" in
741 allowed) type='Allowed'; D_TMP="$A_TMP"
742 ;;
743 blocked) type='Blocked'; D_TMP="$B_TMP"
744 ;;
745 file) type='File'; D_TMP="$B_TMP"
746 ;;
747 esac
748 if [ "${1:0:5}" = "https" ] && [ -z "$isSSLSupported" ]; then
749 output 1 "$_FAIL_"
750 output 2 "[DL] $type $label $__FAIL__\\n"
751 echo "errorNoSSLSupport|${1}" >> "$sharedMemoryError"
752 return 0
753 fi
754 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
755 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
756 done
757 if ! $dl_command "$1" "$dl_flag" "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
758 output 1 "$_FAIL_"
759 output 2 "[DL] $type $label $__FAIL__\\n"
760 echo "errorDownloadingList|${1}" >> "$sharedMemoryError"
761 else
762 sed -i "$filter" "$R_TMP"
763 if [ ! -s "$R_TMP" ]; then
764 output 1 "$_FAIL_"
765 output 2 "[DL] $type $label $__FAIL__\\n"
766 echo "errorParsingList|${1}" >> "$sharedMemoryError"
767 else
768 cat "${R_TMP}" >> "$D_TMP"
769 output 1 "$_OK_"
770 output 2 "[DL] $type $label $__OK__\\n"
771 fi
772 fi
773 rm -f "$R_TMP"
774 return 0
775 }
776
777 download_dnsmasq_file() {
778 local hf allow_filter j=0 R_TMP
779
780 json set message "$(get_text "statusDownloading")..."
781 json set status "statusDownloading"
782
783 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
784 if [ "$($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
785 output 3 'Low free memory, restarting resolver '
786 if dns 'quiet'; then
787 output_okn
788 else
789 output_failn
790 fi
791 fi
792 touch $A_TMP; touch $B_TMP;
793 output 1 'Downloading dnsmasq file '
794 rm -f "$sharedMemoryError"
795 process_url "$dnsmasq_config_file_url" 'dnsmasq' 'file'
796 # output 1 '\n'
797 if [ -s "$sharedMemoryError" ]; then
798 while IFS= read -r line; do
799 json add error "$line"
800 done < "$sharedMemoryError"
801 rm -f "$sharedMemoryError"
802 fi
803 output 2 'Creating dnsmasq file '
804 if mv "$B_TMP" "$outputFile"; then
805 output 2 "$__OK__\\n"
806 else
807 output 2 "$__FAIL__\\n"
808 json add error "errorMovingDataFile"
809 fi
810 output 1 '\n'
811 }
812
813 download_lists() {
814 local hf allow_filter j=0 R_TMP
815
816 json set message "$(get_text "statusDownloading")..."
817 json set status "statusDownloading"
818
819 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
820 if [ "$($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
821 output 3 'Low free memory, restarting resolver '
822 if dns 'quiet'; then
823 output_okn
824 else
825 output_failn
826 fi
827 fi
828 touch $A_TMP; touch $B_TMP;
829 output 1 'Downloading lists '
830 rm -f "$sharedMemoryError"
831 for hf in ${blocked_hosts_url}; do
832 if [ "$parallel_downloads" -gt 0 ]; then
833 process_url "$hf" 'hosts' 'blocked' &
834 else
835 process_url "$hf" 'hosts' 'blocked'
836 fi
837 done
838 for hf in ${blocked_adblockplus_url}; do
839 if [ "$parallel_downloads" -gt 0 ]; then
840 process_url "$hf" 'adbp' 'blocked' &
841 else
842 process_url "$hf" 'adbp' 'blocked'
843 fi
844 done
845 for hf in ${blocked_domains_url}; do
846 if [ "$parallel_downloads" -gt 0 ]; then
847 process_url "$hf" 'domains' 'blocked' &
848 else
849 process_url "$hf" 'domains' 'blocked'
850 fi
851 done
852 for hf in ${allowed_domains_url}; do
853 if [ "$parallel_downloads" -gt 0 ]; then
854 process_url "$hf" 'domains' 'allowed' &
855 else
856 process_url "$hf" 'domains' 'allowed'
857 fi
858 done
859 wait
860 output 1 '\n'
861 if [ -s "$sharedMemoryError" ]; then
862 while IFS= read -r line; do
863 json add error "$line"
864 done < "$sharedMemoryError"
865 rm -f "$sharedMemoryError"
866 fi
867
868 if [ "$canary_domains_icloud" -ne 0 ]; then
869 canaryDomains="${canaryDomains:+$canaryDomains }${canaryDomainsiCloud}"
870 fi
871 if [ "$canary_domains_mozilla" -ne 0 ]; then
872 canaryDomains="${canaryDomains:+$canaryDomains }${canaryDomainsMozilla}"
873 fi
874
875 for hf in $blocked_domain $canaryDomains; do echo "$hf" | sed "$domainsFilter" >> $B_TMP; done
876 allowed_domain="${allowed_domain}
877 $(cat $A_TMP)"
878 for hf in ${allowed_domain}; do hf="$(echo "$hf" | sed 's/\./\\./g')"; allow_filter="$allow_filter/(^|\.)${hf}$/d;"; done
879
880 [ ! -s "$B_TMP" ] && return 1
881
882 output 1 'Processing downloads '
883 output 2 'Sorting combined list '
884 json set status "statusProcessing"
885 json set message "$(get_text "statusProcessing"): sorting combined list"
886 if [ "$allow_non_ascii" -gt 0 ]; then
887 if sort -u "$B_TMP" > "$A_TMP"; then
888 output_ok
889 else
890 output_failn
891 json add error "errorSorting"
892 fi
893 else
894 if sort -u "$B_TMP" | grep -E -v '[^a-zA-Z0-9=/.-]' > "$A_TMP"; then
895 output_ok
896 else
897 output_failn
898 json add error "errorSorting"
899 fi
900 fi
901
902 if [ "$dns" = 'dnsmasq.conf' ] || \
903 [ "$dns" = 'dnsmasq.ipset' ] || \
904 [ "$dns" = 'dnsmasq.nftset' ] || \
905 [ "$dns" = 'dnsmasq.servers' ] || \
906 [ "$dns" = 'unbound.adb_list' ]; then
907 # TLD optimization written by Dirk Brenken (dev@brenken.org)
908 output 2 'Optimizing combined list '
909 json set message "$(get_text "statusProcessing"): optimizing combined list"
910 # sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
911 if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then
912 if sort "$B_TMP" > "$A_TMP"; then
913 if $awk '{if(NR=1){tld=$NF};while(getline){if($NF!~tld"\\."){print tld;tld=$NF}}print tld}' "$A_TMP" > "$B_TMP"; then
914 if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$B_TMP" > "$A_TMP"; then
915 if sort -u "$A_TMP" > "$B_TMP"; then
916 output_ok
917 else
918 output_failn
919 json add error "errorOptimization"
920 mv "$A_TMP" "$B_TMP"
921 fi
922 else
923 output_failn
924 json add error "errorOptimization"
925 fi
926 else
927 output_failn
928 json add error "errorOptimization"
929 mv "$A_TMP" "$B_TMP"
930 fi
931 else
932 output_failn
933 json add error "errorOptimization"
934 fi
935 else
936 output_failn
937 json add error "errorOptimization"
938 mv "$A_TMP" "$B_TMP"
939 fi
940 else
941 mv "$A_TMP" "$B_TMP"
942 fi
943
944 output 2 'Allowing domains '
945 json set message "$(get_text "statusProcessing"): allowing domains"
946 if sed -i -E "$allow_filter" "$B_TMP"; then
947 output_ok
948 else
949 output_failn
950 json add error "errorAllowListProcessing"
951 fi
952
953 output 2 'Formatting merged file '
954 json set message "$(get_text "statusProcessing"): formatting merged file"
955 if [ -z "$outputFilterIPv6" ]; then
956 if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
957 output_ok
958 else
959 output_failn
960 json add error "errorDataFileFormatting"
961 fi
962 else
963 case "$dns" in
964 dnsmasq.addnhosts)
965 if sed "$outputFilter" "$B_TMP" > "$A_TMP" && \
966 sed "$outputFilterIPv6" "$B_TMP" >> "$A_TMP"; then
967 output_ok
968 else
969 output_failn
970 json add error "errorDataFileFormatting"
971 fi
972 ;;
973 esac
974 fi
975
976 case "$dns" in
977 dnsmasq.addnhosts)
978 output 2 'Creating dnsmasq addnhosts file '
979 json set message "$(get_text "statusProcessing"): creating dnsmasq addnhosts file"
980 ;;
981 dnsmasq.conf)
982 output 2 'Creating dnsmasq config file '
983 json set message "$(get_text "statusProcessing"): creating dnsmasq config file"
984 ;;
985 dnsmasq.ipset)
986 output 2 'Creating dnsmasq ipset file '
987 json set message "$(get_text "statusProcessing"): creating dnsmasq ipset file"
988 ;;
989 dnsmasq.nftset)
990 output 2 'Creating dnsmasq nft set file '
991 json set message "$(get_text "statusProcessing"): creating dnsmasq nft set file"
992 ;;
993 dnsmasq.servers)
994 output 2 'Creating dnsmasq servers file '
995 json set message "$(get_text "statusProcessing"): creating dnsmasq servers file"
996 ;;
997 unbound.adb_list)
998 output 2 'Creating Unbound adb_list file '
999 json set message "$(get_text "statusProcessing"): creating Unbound adb_list file"
1000 ;;
1001 esac
1002
1003 if mv "$A_TMP" "$outputFile"; then
1004 output_ok
1005 else
1006 output_failn
1007 json add error "errorMovingDataFile"
1008 fi
1009 if [ "$compressed_cache" -gt 0 ]; then
1010 output 2 'Creating compressed cache '
1011 json set message "$(get_text "statusProcessing"): creating compressed cache"
1012 if cache 'create_gzip'; then
1013 output_ok
1014 else
1015 output_failn
1016 json add error "errorCreatingCompressedCache"
1017 fi
1018 else
1019 rm -f "$outputGzip"
1020 fi
1021 output 2 'Removing temporary files '
1022 json set message "$(get_text "statusProcessing"): removing temporary files"
1023 rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
1024 if [ $j -eq 0 ]; then
1025 output_ok
1026 else
1027 output_failn
1028 json add error "errorRemovingTempFiles"
1029 fi
1030 output 1 '\n'
1031 }
1032
1033 adb_allow() {
1034 local c hf string="$1"
1035 local validation_result="$3"
1036 load_environment "$validation_result" 'quiet' || return 1
1037 if [ ! -s "$outputFile" ]; then
1038 output "No block-list ('$outputFile') found.\\n"
1039 return 0
1040 elif [ -z "$string" ]; then
1041 output "Usage: /etc/init.d/${packageName} allow 'domain' ...\\n"
1042 return 0
1043 elif [ -n "$dnsmasq_config_file_url" ]; then
1044 output "Allowing individual domains is not possible when using external dnsmasq config file.\\n"
1045 return 0
1046 fi
1047 case "$dns" in
1048 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
1049 output 1 "Allowing domain(s) and restarting dnsmasq "
1050 output 2 "Allowing domain(s) \\n"
1051 for c in $string; do
1052 output 2 " $c "
1053 hf="$(echo "$c" | sed 's/\./\\./g')"
1054 if sed -i "/(^|\.)${hf}$/d;" "$outputFile" && \
1055 uci_add_list_if_new "${packageName}" 'config' 'allowed_domain' "$c"; then
1056 output_ok
1057 else
1058 output_fail
1059 fi
1060 done
1061 if [ "$compressed_cache" -gt 0 ]; then
1062 output 2 'Creating compressed cache '
1063 if cache 'create_gzip'; then
1064 output_ok
1065 else
1066 output_failn
1067 fi
1068 fi
1069 output 2 "Committing changes to config "
1070 if [ -n "$(uci_changes "$packageName")" ] && uci_commit "$packageName"; then
1071 allowed_domain="$(uci_get "$packageName" 'config' 'allowed_domain')"
1072 json set triggers
1073 json set stats "$serviceName is blocking $(wc -l < "$outputFile") domains (with ${dns})"
1074 output_ok;
1075 if [ "$dns" = 'dnsmasq.ipset' ]; then
1076 output 2 "Flushing adb ipset "
1077 if ipset -q -! flush adb; then output_ok; else output_fail; fi
1078 fi
1079 if [ "$dns" = 'dnsmasq.nftset' ]; then
1080 output 2 "Flushing adb nft sets "
1081 nft flush set inet fw4 adb6
1082 if nft flush set inet fw4 adb4; then output_ok; else output_fail; fi
1083 fi
1084 output 2 "Restarting dnsmasq "
1085 if dnsmasq_restart; then output_okn; else output_failn; fi
1086 else
1087 output_fail;
1088 fi
1089 ;;
1090 unbound.adb_list)
1091 output 1 "Allowing domain(s) and restarting Unbound "
1092 output 2 "Allowing domain(s) \\n"
1093 for c in $string; do
1094 output 2 " $c "
1095 if sed -i "/${string}/d" "$outputFile" && \
1096 uci_add_list_if_new "$packageName" 'config' 'allowed_domain' "$string"; then
1097 output_ok
1098 else
1099 output_fail
1100 fi
1101 done
1102 if [ "$compressed_cache" -gt 0 ]; then
1103 output 2 'Creating compressed cache '
1104 if cache 'create_gzip'; then
1105 output_ok
1106 else
1107 output_failn
1108 fi
1109 fi
1110 output 2 "Committing changes to config "
1111 if [ -n "$(uci_changes "$packageName")" ] && uci_commit "$packageName"; then
1112 allowed_domain="$(uci_get "$packageName" 'config' 'allowed_domain')"
1113 json set triggers
1114 json set stats "$serviceName is blocking $(wc -l < "$outputFile") domains (with ${dns})"
1115 output_ok;
1116 output 2 "Restarting Unbound "
1117 if unbound_restart; then output_okn; else output_failn; fi
1118 else
1119 output_fail;
1120 fi
1121 ;;
1122 esac
1123 }
1124
1125 adb_check() {
1126 local c param="$1"
1127 local validation_result="$3"
1128 load_environment "$validation_result" 'quiet' || return 1
1129 if [ ! -s "$outputFile" ]; then
1130 output "No block-list ('$outputFile') found.\\n"
1131 return 0
1132 elif [ -z "$param" ]; then
1133 output "Usage: /etc/init.d/${packageName} check 'domain' ...\\n"
1134 return 0
1135 fi
1136 for string in ${param}; do
1137 c="$(grep -c "$string" "$outputFile")"
1138 if [ "$c" -gt 0 ]; then
1139 if [ "$c" -eq 1 ]; then
1140 output "Found 1 match for '$string' in '$outputFile'.\\n"
1141 else
1142 output "Found $c matches for '$string' in '$outputFile'.\\n"
1143 fi
1144 if [ "$c" -le 20 ]; then
1145 case "$dns" in
1146 dnsmasq.addnhosts)
1147 grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
1148 dnsmasq.conf)
1149 grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
1150 dnsmasq.ipset)
1151 grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
1152 dnsmasq.nftset)
1153 grep "$string" "$outputFile" | sed 's|nftset=/||;s|/4#inet#adb#adb4||;';;
1154 dnsmasq.servers)
1155 grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
1156 unbound.adb_list)
1157 grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';;
1158 esac
1159 fi
1160 else
1161 output "The '$string' is not found in current block-list ('$outputFile').\\n"
1162 fi
1163 done
1164 }
1165
1166 adb_config_update() {
1167 local R_TMP label
1168 local param validation_result="$3"
1169 case "$1" in
1170 on_boot) param="$1";;
1171 *) param='quiet';;
1172 esac
1173 load_environment "$validation_result" "$param" || return 1
1174 label="${config_update_url##*//}"
1175 label="${label%%/*}";
1176 [ "$config_update_enabled" -ne 0 ] || return 0
1177
1178 if [ "$param" != 'download' ]; then
1179 cache 'test' && return 0
1180 cache 'test_gzip' && return 0
1181 fi
1182 output 1 'Updating config '
1183 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
1184 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
1185 done
1186 if ! $dl_command "$config_update_url" "$dl_flag" "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
1187 output 1 "$_FAIL_\\n"
1188 output 2 "[DL] Config Update: $label $__FAIL__\\n"
1189 json add error "errorDownloadingConfigUpdate"
1190 else
1191 if [ -s "$R_TMP" ] && sed -f "$R_TMP" -i "$packageConfigFile" 2>/dev/null; then
1192 output 1 "$_OK_\\n"
1193 output 2 "[DL] Config Update: $label $__OK__\\n"
1194 else
1195 output 1 "$_FAIL_\\n"
1196 output 2 "[DL] Config Update: $label $__FAIL__\\n"
1197 json add error "errorParsingConfigUpdate"
1198 fi
1199 fi
1200 rm -f "$R_TMP"
1201 return 0
1202 }
1203
1204 adb_sizes() {
1205 local i
1206 local validation_result="$3"
1207 load_environment "$validation_result" 'quiet' || return 1
1208
1209 echo "# $(date)"
1210 for i in ${blocked_adblockplus_url}; do
1211 [ "${i//melmac}" != "$i" ] && continue
1212 if $dl_command "$i" "$dl_flag" /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then
1213 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1214 if is_greater "$(du -sk /tmp/sast)" "500"; then
1215 echo "# block-list too big for most routers"
1216 elif is_greater "$(du -sk /tmp/sast)" "100"; then
1217 echo "# block-list may be too big for some routers"
1218 fi
1219 rm -rf /tmp/sast
1220 echo " list blocked_adblockplus_url '$i'"
1221 echo ""
1222 else
1223 echo "# site was down on last check"
1224 echo "# list blocked_adblockplus_url '$i'"
1225 echo ""
1226 fi
1227 done
1228 for i in ${blocked_domains_url}; do
1229 [ "${i//melmac}" != "$i" ] && continue
1230 if $dl_command "$i" "$dl_flag" /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then
1231 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1232 if is_greater "$(du -sk /tmp/sast)" "500"; then
1233 echo "# block-list too big for most routers"
1234 elif is_greater "$(du -sk /tmp/sast)" "100"; then
1235 echo "# block-list may be too big for some routers"
1236 fi
1237 rm -rf /tmp/sast
1238 echo " list blocked_domains_url '$i'"
1239 echo ""
1240 else
1241 echo "# site was down on last check"
1242 echo "# list blocked_domains_url '$i'"
1243 echo ""
1244 fi
1245 done
1246 for i in ${blocked_hosts_url}; do
1247 if $dl_command "$i" "$dl_flag" /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then
1248 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1249 if is_greater "$(du -sk /tmp/sast)" "500"; then
1250 echo "# block-list too big for most routers"
1251 elif is_greater "$(du -sk /tmp/sast)" "100"; then
1252 echo "# block-list may be too big for some routers"
1253 fi
1254 rm -rf /tmp/sast
1255 echo " list blocked_hosts_url '$i'"
1256 echo ""
1257 else
1258 echo "# site was down on last check"
1259 echo "# list blocked_hosts_url '$i'"
1260 echo ""
1261 fi
1262 done
1263 }
1264
1265 adb_start() {
1266 local action status error message stats c
1267 local param="$1" validation_result="$3"
1268
1269 load_environment "$validation_result" "$param" || return 1
1270
1271 status="$(json get status)"
1272 error="$(json get error)"
1273 message="$(json get message)"
1274 stats="$(json get stats)"
1275 action="$(json get triggers)"
1276
1277 if [ "$action" = 'on_boot' ] || [ "$1" = 'on_boot' ]; then
1278 if cache 'test_gzip' || cache 'test'; then
1279 action='restore'
1280 else
1281 action='download'
1282 fi
1283 elif [ "$action" = 'download' ] || [ "$1" = 'download' ] || [ -n "$error" ]; then
1284 action='download'
1285 elif [ ! -s "$outputFile" ]; then
1286 if cache 'test_gzip' || cache 'test'; then
1287 action='restore'
1288 else
1289 action='download'
1290 fi
1291 elif [ "$action" = 'restart' ] || [ "$1" = 'restart' ]; then
1292 action='restart'
1293 elif [ -s "$outputFile" ] && [ "$status" = "statusSuccess" ] && [ -z "$error" ]; then
1294 status_service
1295 return 0
1296 else
1297 action='download'
1298 fi
1299
1300 json del all
1301 json set triggers
1302
1303 if [ "$action" = 'restore' ]; then
1304 output 0 "Starting $serviceName... "
1305 output 3 "Starting $serviceName...\\n"
1306 json set status "statusStarting"
1307 if cache 'test_gzip' && ! cache 'test' && [ ! -s "$outputFile" ]; then
1308 output 3 'Found compressed cache file, unpacking it '
1309 json set message 'found compressed cache file, unpacking it.'
1310 if cache 'unpack_gzip'; then
1311 output_okn
1312 else
1313 output_failn
1314 json add error "errorRestoreCompressedCache"
1315 output "${_ERROR_}: $(get_text 'errorRestoreCompressedCache')!\\n"
1316 action='download'
1317 fi
1318 fi
1319 if cache 'test' && [ ! -s "$outputFile" ]; then
1320 output 3 'Found cache file, reusing it '
1321 json set message 'found cache file, reusing it.'
1322 if cache 'restore'; then
1323 output_okn
1324 dns 'on_start'
1325 else
1326 output_failn
1327 json add error "errorRestoreCache"
1328 output "${_ERROR_}: $(get_text 'errorRestoreCache')!\\n"
1329 action='download'
1330 fi
1331 fi
1332 fi
1333 if [ "$action" = 'download' ]; then
1334 if [ -s "$outputFile" ] || cache 'test' || cache 'test_gzip'; then
1335 output 0 "Force-reloading $serviceName... "
1336 output 3 "Force-reloading $serviceName...\\n"
1337 json set status "statusForceReloading"
1338 else
1339 output 0 "Starting $serviceName... "
1340 output 3 "Starting $serviceName...\\n"
1341 json set status "statusStarting"
1342 fi
1343 if [ -n "$dnsmasq_config_file_url" ]; then
1344 download_dnsmasq_file
1345 else
1346 download_lists
1347 fi
1348 dns 'on_start'
1349 fi
1350 if [ "$action" = 'restart' ]; then
1351 output 0 "Restarting $serviceName... "
1352 output 3 "Restarting $serviceName...\\n"
1353 json set status "statusRestarting"
1354 dns 'on_start'
1355 fi
1356 if [ "$action" = 'start' ]; then
1357 output 0 "Starting $serviceName... "
1358 output 3 "Starting $serviceName...\\n"
1359 json set status "statusStarting"
1360 dns 'on_start'
1361 fi
1362 if [ -s "$outputFile" ] && [ "$(json get status)" != "statusFail" ]; then
1363 output 0 "$__OK__\\n";
1364 json del message
1365 json set status "statusSuccess"
1366 json set stats "$serviceName is blocking $(wc -l < "$outputFile") domains (with ${dns})"
1367 status_service
1368 else
1369 output 0 "$__FAIL__\\n";
1370 json set status "statusFail"
1371 json add error "errorOhSnap"
1372 status_service
1373 fi
1374
1375 procd_open_instance 'main'
1376 procd_set_param command /bin/true
1377 procd_set_param stdout 1
1378 procd_set_param stderr 1
1379 procd_open_data
1380 json_add_string 'status' "$(json get status)"
1381 json_add_string 'errors' "$(json get errors)"
1382 if [ -s "$outputFile" ]; then
1383 json_add_int 'entries' "$(wc -l < "$outputFile")"
1384 else
1385 json_add_int 'entries' '0'
1386 fi
1387 json_add_array firewall
1388 if [ "$force_dns" -ne 0 ]; then
1389 for c in $force_dns_port; do
1390 if netstat -tuln | grep LISTEN | grep ":${c}" >/dev/null 2>&1; then
1391 json_add_object ""
1392 json_add_string type redirect
1393 json_add_string target DNAT
1394 json_add_string src lan
1395 json_add_string proto "tcp udp"
1396 json_add_string src_dport "$c"
1397 json_add_string dest_port "$c"
1398 json_add_string family any
1399 json_add_boolean reflection 0
1400 json_close_object
1401 else
1402 json_add_object ""
1403 json_add_string type rule
1404 json_add_string src lan
1405 json_add_string dest "*"
1406 json_add_string proto "tcp udp"
1407 json_add_string dest_port "$c"
1408 json_add_string target REJECT
1409 json_close_object
1410 fi
1411 done
1412 fi
1413 case "$dns" in
1414 dnsmasq.ipset)
1415 json_add_object ""
1416 json_add_string type ipset
1417 json_add_string name adb
1418 json_add_string match dest_net
1419 json_add_string storage hash
1420 json_close_object
1421 json_add_object ""
1422 json_add_string type rule
1423 json_add_string ipset adb
1424 json_add_string src lan
1425 json_add_string dest "*"
1426 json_add_string proto "tcp udp"
1427 json_add_string target REJECT
1428 json_close_object
1429 ;;
1430 dnsmasq.nftset)
1431 json_add_object ""
1432 json_add_string type ipset
1433 json_add_string name adb4
1434 json_add_string family 4
1435 json_add_string match dest_net
1436 json_close_object
1437 json_add_object ""
1438 json_add_string type rule
1439 json_add_string ipset adb4
1440 json_add_string src lan
1441 json_add_string dest "*"
1442 json_add_string proto "tcp udp"
1443 json_add_string target REJECT
1444 json_close_object
1445 if [ "$ipv6_enabled" -ne 0 ]; then
1446 json_add_object ""
1447 json_add_string type ipset
1448 json_add_string name adb6
1449 json_add_string family 6
1450 json_add_string match dest_net
1451 json_close_object
1452 json_add_object ""
1453 json_add_string type rule
1454 json_add_string ipset adb6
1455 json_add_string src lan
1456 json_add_string dest "*"
1457 json_add_string proto "tcp udp"
1458 json_add_string target REJECT
1459 json_close_object
1460 fi
1461 ;;
1462 esac
1463 json_close_array
1464 procd_close_data
1465 procd_close_instance
1466 }
1467
1468 adb_status() {
1469 local c url status message error stats
1470 local validation_result="$3"
1471 load_environment "$validation_result" 'quiet' || return 1
1472 status="$(json get status)"
1473 message="$(json get message)"
1474 error="$(json get error)"
1475 stats="$(json get stats)"
1476 if [ "$status" = "statusSuccess" ]; then
1477 output "$stats "; output_okn;
1478 else
1479 [ -n "$status" ] && status="$(get_text "$status")"
1480 if [ -n "$status" ] && [ -n "$message" ]; then
1481 status="${status}: $message"
1482 fi
1483 [ -n "$status" ] && output "$serviceName $status\\n"
1484 fi
1485 if [ -n "$error" ]; then
1486 for c in $error; do
1487 url="${c##*|}"
1488 c="${c%|*}"
1489 case "$c" in
1490 errorDownloadingList|errorParsingList)
1491 output "${_ERROR_}: $(get_text "$c") $url!\\n";;
1492 *)
1493 output "${_ERROR_}: $(get_text "$c")!\\n";;
1494 esac
1495 n=$((n+1))
1496 done
1497 fi
1498 }
1499
1500 adb_stop() {
1501 local validation_result="$3"
1502 load_environment "$validation_result" 'quiet' || return 1
1503 if [ -s "$outputFile" ]; then
1504 output "Stopping $serviceName... "
1505 cache 'create'
1506 if dns 'on_stop'; then
1507 ipset -q -! flush adb
1508 ipset -q -! destroy adb
1509 nft delete set inet fw4 adb4
1510 nft delete set inet fw4 adb6
1511 led_off "$led"
1512 output 0 "$__OK__\\n"; output_okn;
1513 json set status "statusStopped"
1514 json del message
1515 else
1516 output 0 "$__FAIL__\\n"; output_fail;
1517 json set status "statusFail"
1518 json add error "errorStopping"
1519 output "${_ERROR_}: $(get_text 'errorStopping')!\\n"
1520 fi
1521 fi
1522 }
1523
1524 allow() { load_validate_config 'config' adb_allow "'$*'"; }
1525 boot() {
1526 ubus -t 30 wait_for network.interface 2>/dev/null
1527 rc_procd start_service 'on_boot'
1528 }
1529 check() { load_validate_config 'config' adb_check "'$*'"; }
1530 dl() { rc_procd start_service 'download'; }
1531 killcache() {
1532 local compressed_cache_dir
1533 config_load "$packageName"
1534 config_get compressed_cache_dir 'config' 'compressed_cache_dir' '/etc'
1535 if [ "$(sanitize_dir "$compressed_cache_dir")" = '/' ]; then
1536 compressed_cache_dir=''
1537 elif [ -n "$(sanitize_dir "$compressed_cache_dir")" ]; then
1538 compressed_cache_dir="$(sanitize_dir "$compressed_cache_dir")"
1539 else
1540 compressed_cache_dir="/etc"
1541 fi
1542 rm -f "$dnsmasqAddnhostsCache" "${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
1543 rm -f "$dnsmasqConfCache" "${compressed_cache_dir}/${dnsmasqConfGzip}"
1544 rm -f "$dnsmasqIpsetCache" "${compressed_cache_dir}/${dnsmasqIpsetGzip}"
1545 rm -f "$dnsmasqNftsetCache" "${compressed_cache_dir}/${dnsmasqNftsetGzip}"
1546 rm -f "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
1547 rm -f "$unboundCache" "$unboundGzip"
1548 config_load 'dhcp'
1549 config_foreach resolver 'dnsmasq' 'cleanup'
1550 uci_commit 'dhcp'
1551 return 0
1552 }
1553 reload_service() { rc_procd start_service 'restart'; }
1554 restart_service() { rc_procd start_service 'restart'; }
1555 service_started() { procd_set_config_changed firewall; }
1556 service_stopped() { procd_set_config_changed firewall; }
1557 service_triggers() {
1558 local wan wan6 i
1559 local procd_trigger_wan6
1560 config_load "$packageName"
1561 config_get_bool procd_trigger_wan6 'config' 'procd_trigger_wan6' '0'
1562 . /lib/functions/network.sh
1563 network_flush_cache
1564 network_find_wan wan
1565 wan="${wan:-wan}"
1566 if [ "$procd_trigger_wan6" -ne 0 ]; then
1567 network_find_wan6 wan6
1568 wan6="${wan6:-wan6}"
1569 fi
1570 for i in "$wan" "$wan6"; do
1571 [ -n "$i" ] && procd_add_interface_trigger "interface.*" "$i" "/etc/init.d/${packageName}" start
1572 done
1573 procd_add_config_trigger "config.change" "$packageName" "/etc/init.d/${packageName}" reload
1574 }
1575 sizes() { load_validate_config 'config' adb_sizes "''"; }
1576 start_service() {
1577 load_validate_config 'config' adb_config_update "'$*'"
1578 load_validate_config 'config' adb_start "'$*'"
1579 }
1580 status_service() { load_validate_config 'config' adb_status "''"; }
1581 stop_service() { load_validate_config 'config' adb_stop "'$*'"; }
1582 version() { echo "$PKG_VERSION"; }
1583
1584 load_validate_config() {
1585 . /lib/functions/network.sh
1586 . /usr/share/libubox/jshn.sh
1587 local enabled
1588 local force_dns
1589 local force_dns_port
1590 local parallel_downloads
1591 local debug
1592 local compressed_cache
1593 local compressed_cache_dir
1594 local ipv6_enabled
1595 local allow_non_ascii
1596 local canary_domains_icloud
1597 local canary_domains_mozilla
1598 local config_update_enabled
1599 local config_update_url
1600 local download_timeout
1601 local curl_additional_param
1602 local curl_max_file_size
1603 local curl_retry
1604 local verbosity
1605 local procd_trigger_wan6
1606 local procd_boot_wan_timeout
1607 local led
1608 local dns
1609 local dns_instance
1610 local allowed_domain
1611 local allowed_domains_url
1612 local blocked_adblockplus_url
1613 local blocked_domain
1614 local blocked_domains_url
1615 local blocked_hosts_url
1616 local dnsmasq_config_file_url
1617 uci_load_validate "$packageName" "$packageName" "$1" "${2}${3:+ $3}" \
1618 'enabled:bool:0' \
1619 'force_dns:bool:1' \
1620 'force_dns_port:list(integer):53 853' \
1621 'parallel_downloads:bool:1' \
1622 'debug:bool:0' \
1623 'compressed_cache:bool:0' \
1624 'compressed_cache_dir:directory:/etc' \
1625 'ipv6_enabled:bool:0' \
1626 'allow_non_ascii:bool:0' \
1627 'canary_domains_icloud:bool:0' \
1628 'canary_domains_mozilla:bool:0' \
1629 'config_update_enabled:bool:0' \
1630 'config_update_url:string:https://cdn.jsdelivr.net/gh/openwrt/packages/net/simple-adblock/files/simple-adblock.conf.update' \
1631 'download_timeout:range(1,60):20' \
1632 'curl_additional_param:or("", string)' \
1633 'curl_max_file_size:or("", uinteger)' \
1634 'curl_retry:range(0,30):3' \
1635 'verbosity:range(0,2):2' \
1636 'procd_trigger_wan6:bool:0' \
1637 'procd_boot_wan_timeout:integer:60' \
1638 'led:or("", "none", file, device, string)' \
1639 'dns:or("dnsmasq.addnhosts", "dnsmasq.conf", "dnsmasq.ipset", "dnsmasq.nftset", "dnsmasq.servers", "unbound.adb_list"):dnsmasq.servers' \
1640 'dns_instance:or(list(integer, string)):0' \
1641 'allowed_domain:list(string)' \
1642 'allowed_domains_url:list(string)' \
1643 'blocked_domain:list(string)' \
1644 'blocked_adblockplus_url:list(string)' \
1645 'blocked_domains_url:list(string)' \
1646 'blocked_hosts_url:list(string)' \
1647 'dnsmasq_config_file_url:string'
1648 }