Merge pull request #15048 from BKPepe/update-hwdata
[feed/packages.git] / net / simple-adblock / files / simple-adblock.init
1 #!/bin/sh /etc/rc.common
2 # Copyright 2017-2020 Stan Grishin (stangri@melmac.net)
3 # shellcheck disable=SC2039,SC1091,SC2016
4 PKG_VERSION='dev-test'
5
6 # shellcheck disable=SC2034
7 START=94
8 # shellcheck disable=SC2034
9 USE_PROCD=1
10 LC_ALL=C
11
12 extra_command 'check' 'Checks if specified domain is found in current block-list'
13 extra_command 'dl' 'Force-downloads all enabled block-list'
14 extra_command 'killcache' 'Delete all cached files'
15 extra_command 'sizes' 'Displays the file-sizes of enabled block-listo'
16 extra_command 'show' 'Shows the service last-run status'
17 extra_command 'version' 'Show version information'
18
19 readonly packageName='simple-adblock'
20 readonly serviceName="$packageName $PKG_VERSION"
21 readonly addnhostsFile="/var/run/${packageName}.addnhosts"
22 readonly addnhostsCache="/var/run/${packageName}.addnhosts.cache"
23 readonly addnhostsGzip="/etc/${packageName}.addnhosts.gz"
24 readonly addnhostsOutputFilter='s|^|127.0.0.1 |;s|$||'
25 readonly addnhostsOutputFilterIPv6='s|^|:: |;s|$||'
26 readonly dnsmasqFile="/var/dnsmasq.d/${packageName}"
27 readonly dnsmasqCache="/var/run/${packageName}.dnsmasq.cache"
28 readonly dnsmasqGzip="/etc/${packageName}.dnsmasq.gz"
29 readonly dnsmasqOutputFilter='s|^|local=/|;s|$|/|'
30 readonly ipsetFile="/var/dnsmasq.d/${packageName}.ipset"
31 readonly ipsetCache="/var/run/${packageName}.ipset.cache"
32 readonly ipsetGzip="/etc/${packageName}.ipset.gz"
33 readonly ipsetOutputFilter='s|^|ipset=/|;s|$|/adb|'
34 readonly serversFile="/var/run/${packageName}.servers"
35 readonly serversCache="/var/run/${packageName}.servers.cache"
36 readonly serversGzip="/etc/${packageName}.servers.gz"
37 readonly serversOutputFilter='s|^|server=/|;s|$|/|'
38 readonly unboundFile="/var/lib/unbound/adb_list.${packageName}"
39 readonly unboundCache="/var/run/${packageName}.unbound.cache"
40 readonly unboundGzip="/etc/${packageName}.unbound.gz"
41 readonly unboundOutputFilter='s|^|local-zone: "|;s|$|" static|'
42 readonly A_TMP="/var/${packageName}.hosts.a.tmp"
43 readonly B_TMP="/var/${packageName}.hosts.b.tmp"
44 readonly PIDFile="/var/run/${packageName}.pid"
45 readonly jsonFile="/var/run/${packageName}.json"
46 readonly sharedMemoryError="/dev/shm/$packageName-error"
47 readonly sharedMemoryOutput="/dev/shm/$packageName-output"
48 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;'
49 readonly domainsFilter='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
50 readonly _OK_='\033[0;32m\xe2\x9c\x93\033[0m'
51 readonly _FAIL_='\033[0;31m\xe2\x9c\x97\033[0m'
52 readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m'
53 readonly __FAIL__='\033[0;31m[\xe2\x9c\x97]\033[0m'
54 readonly _ERROR_='\033[0;31mERROR\033[0m'
55 readonly _WARNING_='\033[0;33mWARNING\033[0m'
56
57 version() { echo "$PKG_VERSION"; }
58
59 getStatusText() {
60 local _ret
61 case "$1" in
62 statusNoInstall) _ret="$serviceName is not installed or not found";;
63 statusStopped) _ret="Stopped";;
64 statusStarting) _ret="Starting";;
65 statusRestarting) _ret="Restarting";;
66 statusForceReloading) _ret="Force Reloading";;
67 statusDownloading) _ret="Downloading";;
68 statusProcessing) _ret="Processing";;
69 statusError) _ret="Error";;
70 statusWarning) _ret="Warning";;
71 statusFail) _ret="Fail";;
72 statusSuccess) _ret="Success";;
73 esac
74 printf "%b" "$_ret"
75 }
76 getErrorText() {
77 local _ret
78 case "$1" in
79 errorOutputFileCreate) _ret="failed to create $outputFile file";;
80 errorFailDNSReload) _ret="failed to restart/reload DNS resolver";;
81 errorSharedMemory) _ret="failed to access shared memory";;
82 errorSorting) _ret="failed to sort data file";;
83 errorOptimization) _ret="failed to optimize data file";;
84 errorAllowListProcessing) _ret="failed to process allow-list";;
85 errorDataFileFormatting) _ret="failed to format data file";;
86 errorMovingDataFile) _ret="failed to move data file '${A_TMP}' to '${outputFile}'";;
87 errorCreatingCompressedCache) _ret="failed to create compressed cache";;
88 errorRemovingTempFiles) _ret="failed to remove temporary files";;
89 errorRestoreCompressedCache) _ret="failed to unpack compressed cache";;
90 errorRestoreCache) _ret="failed to move '$outputCache' to '$outputFile'";;
91 errorOhSnap) _ret="failed to create block-list or restart DNS resolver";;
92 errorStopping) _ret="failed to stop $serviceName";;
93 errorDNSReload) _ret="failed to reload/restart DNS resolver";;
94 errorDownloadingConfigUpdate) _ret="failed to download Config Update file";;
95 errorDownloadingList) _ret="failed to download";;
96 errorParsingList) _ret="failed to parse";;
97 errorParsingConfigUpdate) _ret="failed to parse Config Update file";;
98 esac
99 printf "%b" "$_ret"
100 }
101
102 create_lock() { [ -e "$PIDFile" ] && return 1; touch "$PIDFile"; }
103 remove_lock() { [ -e "$PIDFile" ] && rm -f "$PIDFile"; }
104 trap remove_lock EXIT
105 output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; }
106 output_okn() { output 1 "$_OK_\\n"; output 2 "$__OK__\\n"; }
107 output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n"; }
108 output_failn() { output 1 "$_FAIL_\\n"; output 2 "$__FAIL__\\n"; }
109 str_replace() { printf "%b" "$1" | sed -e "s/$(printf "%b" "$2")/$(printf "%b" "$3")/g"; }
110 str_contains() { test "$1" != "$(str_replace "$1" "$2" '')"; }
111 compare_values() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
112 is_chaos_calmer() { ubus -S call system board | grep -q 'Chaos Calmer'; }
113 led_on(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'default-on' > "${1}/trigger" 2>&1; fi; }
114 led_off(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'none' > "${1}/trigger" 2>&1; fi; }
115 dnsmasq_hup() { killall -q -HUP dnsmasq; }
116 dnsmasq_kill() { killall -q -KILL dnsmasq; }
117 dnsmasq_restart() { /etc/init.d/dnsmasq restart >/dev/null 2>&1; }
118 unbound_restart() { /etc/init.d/unbound restart >/dev/null 2>&1; }
119 is_force_dns_active() { iptables-save | grep -q -w -- '--dport 53'; }
120 is_present() { command -v "$1" >/dev/null 2>&1; }
121
122 output() {
123 # Can take a single parameter (text) to be output at any verbosity
124 # Or target verbosity level and text to be output at specifc verbosity
125 local msg memmsg logmsg
126 if [ $# -ne 1 ]; then
127 if [ $((verbosity & $1)) -gt 0 ] || [ "$verbosity" = "$1" ]; then shift; else return 0; fi
128 fi
129 [ -t 1 ] && printf "%b" "$1"
130 msg="${1//$serviceName /service }";
131 if [ "$(printf "%b" "$msg" | wc -l)" -gt 0 ]; then
132 [ -s "$sharedMemoryOutput" ] && memmsg="$(cat "$sharedMemoryOutput")"
133 logmsg="$(printf "%b" "${memmsg}${msg}" | sed 's/\x1b\[[0-9;]*m//g')"
134 logger -t "${packageName:-service} [$$]" "$(printf "%b" "$logmsg")"
135 rm -f "$sharedMemoryOutput"
136 else
137 printf "%b" "$msg" >> "$sharedMemoryOutput"
138 fi
139 }
140
141 serviceEnabled=''; forceDNS=''; parallelDL=''; debug=''; compressedCache='';
142 ipv6Enabled=''; configUpdateEnabled=''; configUpdateURL=''; bootDelay='';
143 dlTimeout=''; curlRetry=''; verbosity=''; led=''; targetDNS=''; dnsInstance='';
144 allowed_domains=''; allowed_domains_urls='';
145 blocked_domains=''; blocked_domains_urls=''; blocked_hosts_urls='';
146 dl_command=''; dl_flag=''; isSSLSupported=''; allowIDN='';
147 outputFilter=''; outputFilterIPv6=''; outputFile=''; outputGzip=''; outputCache='';
148 awk='awk';
149
150 load_package_config() {
151 config_load "$packageName"
152 config_get_bool serviceEnabled 'config' 'enabled' 1
153 config_get_bool forceDNS 'config' 'force_dns' 1
154 config_get_bool parallelDL 'config' 'parallel_downloads' 1
155 config_get_bool debug 'config' 'debug' 0
156 config_get_bool compressedCache 'config' 'compressed_cache' 0
157 config_get_bool ipv6Enabled 'config' 'ipv6_enabled' 0
158 config_get_bool configUpdateEnabled 'config' 'config_update_enabled' 0
159 config_get bootDelay 'config' 'boot_delay' '120'
160 config_get dlTimeout 'config' 'download_timeout' '20'
161 config_get curlRetry 'config' 'curl_retry' '3'
162 config_get verbosity 'config' 'verbosity' '2'
163 config_get led 'config' 'led'
164 config_get targetDNS 'config' 'dns' 'dnsmasq.servers'
165 config_get dnsInstance 'config' 'dns_instance' '0'
166 config_get allowed_domains 'config' 'allowed_domain'
167 config_get allowed_domains_urls 'config' 'allowed_domains_url'
168 config_get blocked_domains 'config' 'blocked_domain'
169 config_get blocked_domains_urls 'config' 'blocked_domains_url'
170 config_get blocked_hosts_urls 'config' 'blocked_hosts_url'
171 config_get configUpdateURL 'config' 'config_update_url' 'https://cdn.jsdelivr.net/gh/openwrt/packages/net/simple-adblock/files/simple-adblock.conf.update'
172
173 if [ "$targetDNS" != 'dnsmasq.addnhosts' ] && [ "$targetDNS" != 'dnsmasq.conf' ] && \
174 [ "$targetDNS" != 'dnsmasq.servers' ] && [ "$targetDNS" != 'unbound.adb_list' ] && \
175 [ "$targetDNS" != 'dnsmasq.ipset' ] ; then
176 targetDNS='dnsmasq.servers'
177 fi
178
179 case "$targetDNS" in
180 dnsmasq.addnhosts)
181 outputFilter="$addnhostsOutputFilter"
182 outputFile="$addnhostsFile"
183 outputCache="$addnhostsCache"
184 outputGzip="$addnhostsGzip"
185 [ "$ipv6Enabled" -gt 0 ] && outputFilterIPv6="$addnhostsOutputFilterIPv6"
186 rm -f "$dnsmasqFile" "$dnsmasqCache" "$dnsmasqGzip"
187 rm -f "$ipsetFile" "$ipsetCache" "$ipsetGzip"
188 rm -f "$serversFile" "$serversCache" "$serversGzip"
189 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
190 ;;
191 dnsmasq.conf)
192 outputFilter="$dnsmasqOutputFilter"
193 outputFile="$dnsmasqFile"
194 outputCache="$dnsmasqCache"
195 outputGzip="$dnsmasqGzip"
196 rm -f "$addnhostsFile" "$addnhostsCache" "$addnhostsGzip"
197 rm -f "$ipsetFile" "$ipsetCache" "$ipsetGzip"
198 rm -f "$serversFile" "$serversCache" "$serversGzip"
199 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
200 ;;
201 dnsmasq.ipset)
202 outputFilter="$ipsetOutputFilter"
203 outputFile="$ipsetFile"
204 outputCache="$ipsetCache"
205 outputGzip="$ipsetGzip"
206 rm -f "$dnsmasqFile" "$dnsmasqCache" "$dnsmasqGzip"
207 rm -f "$addnhostsFile" "$addnhostsCache" "$addnhostsGzip"
208 rm -f "$serversFile" "$serversCache" "$serversGzip"
209 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
210 ;;
211 dnsmasq.servers)
212 outputFilter="$serversOutputFilter"
213 outputFile="$serversFile"
214 outputCache="$serversCache"
215 outputGzip="$serversGzip"
216 rm -f "$dnsmasqFile" "$dnsmasqCache" "$dnsmasqGzip"
217 rm -f "$addnhostsFile" "$addnhostsCache" "$addnhostsGzip"
218 rm -f "$ipsetFile" "$ipsetCache" "$ipsetGzip"
219 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
220 ;;
221 unbound.adb_list)
222 outputFilter="$unboundOutputFilter"
223 outputFile="$unboundFile"
224 outputCache="$unboundCache"
225 outputGzip="$unboundGzip"
226 rm -f "$addnhostsFile" "$addnhostsCache" "$addnhostsGzip"
227 rm -f "$dnsmasqFile" "$dnsmasqCache" "$dnsmasqGzip"
228 rm -f "$ipsetFile" "$ipsetCache" "$ipsetGzip"
229 rm -f "$serversFile" "$serversCache" "$serversGzip"
230 ;;
231 esac
232 if [ -z "${verbosity##*[!0-9]*}" ] || [ "$verbosity" -lt 0 ] || [ "$verbosity" -gt 2 ]; then
233 verbosity=1
234 fi
235 . /lib/functions/network.sh
236 . /usr/share/libubox/jshn.sh
237 is_present 'gawk' && awk='gawk'
238 if ! is_present '/usr/libexec/grep-gnu' || ! is_present '/usr/libexec/sed-gnu' || \
239 ! is_present '/usr/libexec/sort-coreutils' || ! is_present 'gawk'; then
240 local s="opkg update; opkg --force-overwrite install"
241 is_present 'gawk' || s="$s gawk"
242 is_present '/usr/libexec/grep-gnu' || s="$s grep"
243 is_present '/usr/libexec/sed-gnu' || s="$s sed"
244 is_present '/usr/libexec/sort-coreutils' || s="$s coreutils-sort"
245 output "$_WARNING_: Some recommended packages are missing, install them by running:\\n"
246 output "$s;\\n"
247 fi
248 # Prefer curl because it supports the file:// scheme.
249 if is_present 'curl'; then
250 dl_command="curl --insecure --retry $curlRetry --connect-timeout $dlTimeout --silent"
251 dl_flag="-o"
252 elif is_present wget && wget --version 2>/dev/null | grep -q "+https"; then
253 dl_command="wget --no-check-certificate --timeout $dlTimeout -q"
254 dl_flag="-O"
255 else
256 dl_command="uclient-fetch --no-check-certificate --timeout $dlTimeout -q"
257 dl_flag="-O"
258 fi
259 led="${led:+/sys/class/leds/$led}"
260 if curl --version 2>/dev/null | grep -q "https" \
261 || wget --version 2>/dev/null | grep -q "+https" \
262 || grep -q "libustream-mbedtls" /usr/lib/opkg/status \
263 || grep -q "libustream-openssl" /usr/lib/opkg/status \
264 || grep -q "libustream-wolfssl" /usr/lib/opkg/status; then
265 isSSLSupported=1
266 else
267 unset isSSLSupported
268 fi
269 }
270
271 is_enabled() {
272 wan_if=''; wan_gw='';
273 load_package_config
274
275 if [ "$debug" -ne 0 ]; then
276 exec 1>>/tmp/simple-adblock.log
277 exec 2>&1
278 set -x
279 fi
280
281 if [ "$serviceEnabled" -eq 0 ]; then
282 case "$1" in
283 on_start)
284 output "$packageName is currently disabled.\\n"
285 output "Run the following commands before starting service again:\\n"
286 output "uci set ${packageName}.config.enabled='1'; uci commit $packageName;\\n"
287 ;;
288 esac
289 return 1
290 fi
291
292 case $targetDNS in
293 dnsmasq.addnhosts | dnsmasq.conf | dnsmasq.ipset | dnsmasq.servers)
294 if dnsmasq -v 2>/dev/null | grep -q 'no-IDN' || ! dnsmasq -v 2>/dev/null | grep -q -w 'IDN'; then
295 allowIDN=0
296 else
297 allowIDN=1
298 fi
299 ;;
300 unbound.adb_list)
301 allowIDN=1;;
302 esac
303
304 case $targetDNS in
305 dnsmasq.ipset)
306 if dnsmasq -v 2>/dev/null | grep -q 'no-ipset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'ipset'; then
307 output "$_ERROR_: DNSMASQ ipset support is enabled in $packageName, but DNSMASQ is either not installed or installed DNSMASQ does not support ipsets!\\n"
308 targetDNS='dnsmasq.servers'
309 fi
310 if ! ipset help hash:net >/dev/null 2>&1; then
311 output "$_ERROR_: DNSMASQ ipset support is enabled in $packageName, but ipset is either not installed or installed ipset does not support 'hash:net' type!\\n"
312 targetDNS='dnsmasq.servers'
313 fi
314 ;;
315 esac
316
317 [ ! -d "${outputFile%/*}" ] && mkdir -p "${outputFile%/*}"
318 [ ! -d "${outputCache%/*}" ] && mkdir -p "${outputFile%/*}"
319 [ ! -d "${outputGzip%/*}" ] && mkdir -p "${outputFile%/*}"
320 cacheOps 'testGzip' && return 0
321 network_flush_cache; network_find_wan wan_if; network_get_gateway wan_gw "$wan_if";
322 [ -n "$wan_gw" ] && return 0
323 output "$_ERROR_: $serviceName failed to discover WAN gateway.\\n"; return 1;
324 }
325
326 dnsmasqOps() {
327 local cfg="$1" param="$2"
328 case "$param" in
329 dnsmasq.addnhosts)
330 if [ "$(uci -q get dhcp."$cfg".serversfile)" = "$serversFile" ]; then
331 uci -q del dhcp."$cfg".serversfile
332 fi
333 if ! uci -q get dhcp."$cfg".addnhosts | grep -q "$addnhostsFile"; then
334 uci add_list dhcp."$cfg".addnhosts="$addnhostsFile"
335 fi
336 ;;
337 dnsmasq.conf|dnsmasq.ipset|unbound.adb_list|cleanup)
338 uci -q del_list dhcp."$cfg".addnhosts="$addnhostsFile"
339 if [ "$(uci -q get dhcp."$cfg".serversfile)" = "$serversFile" ]; then
340 uci -q del dhcp."$cfg".serversfile
341 fi
342 ;;
343 dnsmasq.servers)
344 uci -q del_list dhcp."$cfg".addnhosts="$addnhostsFile"
345 if [ "$(uci -q get dhcp."$cfg".serversfile)" != "$serversFile" ]; then
346 uci set dhcp."$cfg".serversfile="$serversFile"
347 fi
348 ;;
349 esac
350 }
351
352 dnsOps() {
353 local param output_text i
354 case $1 in
355 on_start)
356 if [ ! -s "$outputFile" ]; then
357 tmpfs set status "statusFail"
358 tmpfs add error "errorOutputFileCreate"
359 output "$_ERROR_: $(getErrorText 'errorOutputFileCreate')!\\n"
360 return 1
361 fi
362
363 config_load 'dhcp'
364 if [ "$dnsInstance" = "*" ]; then
365 config_foreach dnsmasqOps 'dnsmasq' "$targetDNS"
366 elif [ -n "$dnsInstance" ]; then
367 for i in $dnsInstance; do
368 dnsmasqOps "@dnsmasq[$i]" "$targetDNS"
369 done
370 fi
371
372 case "$targetDNS" in
373 dnsmasq.addnhosts|dnsmasq.servers)
374 param=dnsmasq_hup
375 output_text='Reloading DNSMASQ'
376 ;;
377 dnsmasq.conf|dnsmasq.ipset)
378 param=dnsmasq_restart
379 output_text='Restarting DNSMASQ'
380 ;;
381 unbound.adb_list)
382 param=unbound_restart
383 output_text='Restarting Unbound'
384 ;;
385 esac
386
387 if [ -n "$(uci changes dhcp)" ]; then
388 uci commit dhcp
389 if [ "$param" = 'unbound_restart' ]; then
390 param='dnsmasq_restart; unbound_restart;'
391 output_text='Restarting Unbound/DNSMASQ'
392 else
393 param=dnsmasq_restart
394 output_text='Restarting DNSMASQ'
395 fi
396 fi
397 output 1 "$output_text "
398 output 2 "$output_text "
399 tmpfs set message "$output_text"
400 if eval "$param"; then
401 tmpfs set status "statusSuccess"
402 led_on "$led"
403 output_okn
404 else
405 output_fail
406 tmpfs set status "statusFail"
407 tmpfs add error "errorDNSReload"
408 output "$_ERROR_: $(getErrorText 'errorDNSReload')!\\n"
409 return 1
410 fi
411 ;;
412 on_stop)
413 case "$targetDNS" in
414 dnsmasq.addnhosts | dnsmasq.servers)
415 param=dnsmasq_hup
416 ;;
417 dnsmasq.conf | dnsmasq.ipset)
418 param=dnsmasq_restart
419 ;;
420 unbound.adb_list)
421 param=unbound_restart
422 ;;
423 esac
424 if [ -n "$(uci changes dhcp)" ]; then
425 uci -q commit dhcp
426 if [ "$param" = 'unbound_restart' ]; then
427 param='dnsmasq_restart; unbound_restart;'
428 else
429 param=dnsmasq_restart
430 fi
431 fi
432 eval "$param"
433 return $?
434 ;;
435 quiet)
436 case "$targetDNS" in
437 dnsmasq.addnhosts | dnsmasq.conf | dnsmasq.ipset | dnsmasq.servers)
438 param=dnsmasq_restart
439 ;;
440 unbound.adb_list)
441 param=unbound_restart
442 ;;
443 esac
444 eval "$param"
445 return $?
446 ;;
447 esac
448 }
449
450 tmpfs() {
451 # shellcheck disable=SC2034
452 local action="$1" param="$2" value="$3"
453 local status message error stats
454 local reload restart curReload curRestart ret i
455 if [ -s "$jsonFile" ]; then
456 json_load_file "$jsonFile" 2>/dev/null
457 json_select 'data' 2>/dev/null
458 for i in status message error stats reload restart; do
459 json_get_var $i "$i" 2>/dev/null
460 done
461 fi
462 case "$action" in
463 get)
464 case "$param" in
465 triggers)
466 curReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS"
467 curRestart="$compressedCache $forceDNS $led"
468 if [ ! -s "$jsonFile" ]; then
469 ret='on_boot'
470 elif [ "$curReload" != "$reload" ]; then
471 ret='download'
472 elif [ "$curRestart" != "$restart" ]; then
473 ret='restart'
474 fi
475 printf "%b" "$ret"
476 return;;
477 *)
478 printf "%b" "$(eval echo "\$$param")"; return;;
479 esac
480 ;;
481 add)
482 eval "$param"='$(eval echo "\$$param")${value} ';;
483 del)
484 case "$param" in
485 all)
486 unset status message error stats;;
487 triggers)
488 unset reload restart;;
489 *)
490 unset "$param";;
491 esac
492 ;;
493 set)
494 case "$param" in
495 triggers)
496 reload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS"
497 restart="$compressedCache $forceDNS $led"
498 ;;
499 *)
500 eval "$param"='$value';;
501 esac
502 ;;
503 esac
504 json_init
505 json_add_object 'data'
506 json_add_string version "$PKG_VERSION"
507 json_add_string status "$status"
508 json_add_string message "$message"
509 json_add_string error "$error"
510 json_add_string stats "$stats"
511 json_add_string reload "$reload"
512 json_add_string restart "$restart"
513 json_close_object
514 json_dump > "$jsonFile"
515 sync
516 }
517
518 cacheOps() {
519 local R_TMP
520 case "$1" in
521 create|backup)
522 [ -s "$outputFile" ] && { mv -f "$outputFile" "$outputCache"; true > "$outputFile"; } >/dev/null 2>/dev/null
523 return $?
524 ;;
525 restore|use)
526 [ -s "$outputCache" ] && mv "$outputCache" "$outputFile" >/dev/null 2>/dev/null
527 return $?
528 ;;
529 test)
530 [ -s "$outputCache" ]
531 return $?
532 ;;
533 testGzip)
534 [ -s "$outputGzip" ] && gzip -t -c "$outputGzip"
535 return $?
536 ;;
537 createGzip)
538 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
539 if gzip < "$outputFile" > "$R_TMP"; then
540 if mv "$R_TMP" "$outputGzip"; then
541 rm -f "$R_TMP"
542 return 0
543 else
544 rm -f "$R_TMP"
545 return 1
546 fi
547 else
548 return 1
549 fi
550 ;;
551 expand|unpack|expandGzip|unpackGzip)
552 [ -s "$outputGzip" ] && gzip -dc < "$outputGzip" > "$outputCache"
553 return $?
554 ;;
555 esac
556 }
557
558 process_url() {
559 local label type D_TMP R_TMP
560 if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then return 1; fi
561 label="${1##*//}"; label="${label%%/*}";
562 if [ "$2" = 'hosts' ]; then
563 label="Hosts: $label"; filter="$hostsFilter";
564 else
565 label="Domains: $label"; filter="$domainsFilter";
566 fi
567 if [ "$3" = 'blocked' ]; then
568 type='Blocked'; D_TMP="$B_TMP";
569 else
570 type='Allowed'; D_TMP="$A_TMP";
571 fi
572 if [ "${1:0:5}" == "https" ] && [ -z "$isSSLSupported" ]; then
573 output 1 "$_FAIL_"
574 output 2 "[DL] $type $label $__FAIL__\\n"
575 echo "errorNoSSLSupport|${1}" >> "$sharedMemoryError"
576 return 0
577 fi
578 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
579 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
580 done
581 if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
582 output 1 "$_FAIL_"
583 output 2 "[DL] $type $label $__FAIL__\\n"
584 echo "errorDownloadingList|${1}" >> "$sharedMemoryError"
585 else
586 sed -i "$filter" "$R_TMP"
587 if [ ! -s "$R_TMP" ]; then
588 output 1 "$_FAIL_"
589 output 2 "[DL] $type $label $__FAIL__\\n"
590 echo "errorParsingList|${1}" >> "$sharedMemoryError"
591 else
592 cat "${R_TMP}" >> "$D_TMP"
593 output 1 "$_OK_"
594 output 2 "[DL] $type $label $__OK__\\n"
595 fi
596 fi
597 rm -f "$R_TMP"
598 return 0
599 }
600
601 process_config_update() {
602 local label R_TMP
603 [ "$configUpdateEnabled" -eq 0 ] && return 0
604 label="${1##*//}"; label="${label%%/*}";
605 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
606 R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)"
607 done
608 if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
609 output 1 "$_FAIL_"
610 output 2 "[DL] Config Update: $label $__FAIL__\\n"
611 tmpfs add error "errorDownloadingConfigUpdate"
612 else
613 if [ -s "$R_TMP" ] && sed -f "$R_TMP" -i /etc/config/simple-adblock; then
614 output 1 "$_OK_"
615 output 2 "[DL] Config Update: $label $__OK__\\n"
616 else
617 output 1 "$_FAIL_"
618 output 2 "[DL] Config Update: $label $__FAIL__\\n"
619 tmpfs add error "errorParsingConfigUpdate"
620 fi
621 fi
622 rm -f "$R_TMP"
623 return 0
624 }
625
626 download_lists() {
627 local hf w_filter j=0 R_TMP
628
629 tmpfs set message "$(getStatusText "statusDownloading")..."
630 tmpfs set status "statusDownloading"
631
632 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
633 if [ "$($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
634 output 3 'Low free memory, restarting resolver... '
635 if dnsOps 'quiet'; then
636 output_okn
637 else
638 output_fail
639 fi
640 fi
641 touch $A_TMP; touch $B_TMP;
642 output 1 'Downloading lists '
643 process_config_update "$configUpdateURL"
644 rm -f "$sharedMemoryError"
645 if [ -n "$blocked_hosts_urls" ]; then
646 for hf in ${blocked_hosts_urls}; do
647 if [ "$parallelDL" -gt 0 ]; then
648 process_url "$hf" 'hosts' 'blocked' &
649 else
650 process_url "$hf" 'hosts' 'blocked'
651 fi
652 done
653 fi
654 if [ -n "$blocked_domains_urls" ]; then
655 for hf in ${blocked_domains_urls}; do
656 if [ "$parallelDL" -gt 0 ]; then
657 process_url "$hf" 'domains' 'blocked' &
658 else
659 process_url "$hf" 'domains' 'blocked'
660 fi
661 done
662 fi
663 if [ -n "$allowed_domains_urls" ]; then
664 for hf in ${allowed_domains_urls}; do
665 if [ "$parallelDL" -gt 0 ]; then
666 process_url "$hf" 'domains' 'allowed' &
667 else
668 process_url "$hf" 'domains' 'allowed'
669 fi
670 done
671 fi
672 wait
673 output 1 '\n'
674 if [ -s "$sharedMemoryError" ]; then
675 while IFS= read -r line; do
676 tmpfs add error "$line"
677 done < "$sharedMemoryError"
678 rm -f "$sharedMemoryError"
679 fi
680
681 [ -n "$blocked_domains" ] && for hf in ${blocked_domains}; do echo "$hf" | sed "$domainsFilter" >> $B_TMP; done
682 allowed_domains="${allowed_domains}
683 $(cat $A_TMP)"
684 [ -n "$allowed_domains" ] && for hf in ${allowed_domains}; do hf="$(echo "$hf" | sed 's/\./\\./g')"; w_filter="$w_filter/${hf}$/d;"; done
685
686 [ ! -s "$B_TMP" ] && return 1
687
688 output 1 'Processing downloads '
689 output 2 'Sorting combined list '
690 tmpfs set message "$(getStatusText "statusProcessing"): sorting combined list"
691 if [ "$allowIDN" -gt 0 ]; then
692 if sort -u "$B_TMP" > "$A_TMP"; then
693 output_ok
694 else
695 output_failn
696 tmpfs add error "errorSorting"
697 fi
698 else
699 if sort -u "$B_TMP" | grep -E -v '[^a-zA-Z0-9=/.-]' > "$A_TMP"; then
700 output_ok
701 else
702 output_failn
703 tmpfs add error "errorSorting"
704 fi
705 fi
706
707 if [ "$targetDNS" = 'dnsmasq.conf' ] || \
708 [ "$targetDNS" = 'dnsmasq.ipset' ] || \
709 [ "$targetDNS" = 'dnsmasq.servers' ] || \
710 [ "$targetDNS" = 'unbound.adb_list' ]; then
711 # TLD optimization written by Dirk Brenken (dev@brenken.org)
712 output 2 'Optimizing combined list '
713 tmpfs set message "$(getStatusText "statusProcessing"): optimizing combined list"
714 # sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
715 if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then
716 if sort "$B_TMP" > "$A_TMP"; then
717 if $awk '{if(NR=1){tld=$NF};while(getline){if($NF!~tld"\\."){print tld;tld=$NF}}print tld}' "$A_TMP" > "$B_TMP"; then
718 if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$B_TMP" > "$A_TMP"; then
719 if sort -u "$A_TMP" > "$B_TMP"; then
720 output_ok
721 else
722 output_failn
723 tmpfs add error "errorOptimization"
724 mv "$A_TMP" "$B_TMP"
725 fi
726 else
727 output_failn
728 tmpfs add error "errorOptimization"
729 fi
730 else
731 output_failn
732 tmpfs add error "errorOptimization"
733 mv "$A_TMP" "$B_TMP"
734 fi
735 else
736 output_failn
737 tmpfs add error "errorOptimization"
738 fi
739 else
740 output_failn
741 tmpfs add error "errorOptimization"
742 mv "$A_TMP" "$B_TMP"
743 fi
744 else
745 mv "$A_TMP" "$B_TMP"
746 fi
747
748 output 2 'Allowing domains '
749 tmpfs set message "$(getStatusText "statusProcessing"): allowing domains"
750 if sed -i "$w_filter" "$B_TMP"; then
751 output_ok
752 else
753 output_failn
754 tmpfs add error "errorAllowListProcessing"
755 fi
756
757 output 2 'Formatting merged file '
758 tmpfs set message "$(getStatusText "statusProcessing"): formatting merged file"
759 if [ -z "$outputFilterIPv6" ]; then
760 if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
761 output_ok
762 else
763 output_failn
764 tmpfs add error "errorDataFileFormatting"
765 fi
766 else
767 case "$targetDNS" in
768 dnsmasq.addnhosts)
769 if sed "$outputFilter" "$B_TMP" > "$A_TMP" && \
770 sed "$outputFilterIPv6" "$B_TMP" >> "$A_TMP"; then
771 output_ok
772 else
773 output_failn
774 tmpfs add error "errorDataFileFormatting"
775 fi
776 ;;
777 esac
778 fi
779
780 case "$targetDNS" in
781 dnsmasq.addnhosts)
782 output 2 'Creating DNSMASQ addnhosts file '
783 tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ addnhosts file"
784 ;;
785 dnsmasq.conf)
786 output 2 'Creating DNSMASQ config file '
787 tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ config file"
788 ;;
789 dnsmasq.ipset)
790 output 2 'Creating DNSMASQ ipset file '
791 tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ ipset file"
792 ;;
793 dnsmasq.servers)
794 output 2 'Creating DNSMASQ servers file '
795 tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ servers file"
796 ;;
797 unbound.adb_list)
798 output 2 'Creating Unbound adb_list file '
799 tmpfs set message "$(getStatusText "statusProcessing"): creating Unbound adb_list file"
800 ;;
801 esac
802 if mv "$A_TMP" "$outputFile"; then
803 output_ok
804 else
805 output_failn
806 tmpfs add error "errorMovingDataFile"
807 fi
808 if [ "$compressedCache" -gt 0 ]; then
809 output 2 'Creating compressed cache '
810 tmpfs set message "$(getStatusText "statusProcessing"): creating compressed cache"
811 if cacheOps 'createGzip'; then
812 output_ok
813 else
814 output_failn
815 tmpfs add error "errorCreatingCompressedCache"
816 fi
817 else
818 rm -f "$outputGzip"
819 fi
820 output 2 'Removing temporary files '
821 tmpfs set message "$(getStatusText "statusProcessing"): removing temporary files"
822 rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
823 if [ $j -eq 0 ]; then
824 output_ok
825 else
826 output_failn
827 tmpfs add error "errorRemovingTempFiles"
828 fi
829 output 1 '\n'
830 }
831
832 boot() {
833 load_package_config
834 if create_lock; then
835 sleep "$bootDelay"
836 remove_lock
837 rc_procd start_service 'on_boot' && rc_procd service_triggers
838 fi
839 }
840
841 start_service() {
842 is_enabled 'on_start' || return 1
843 local action status error message stats c
844 if ! create_lock; then
845 output 3 "$serviceName: another instance is starting up "; output_fail
846 return 0
847 fi
848
849 status="$(tmpfs get status)"
850 error="$(tmpfs get error)"
851 message="$(tmpfs get message)"
852 stats="$(tmpfs get stats)"
853 action="$(tmpfs get triggers)"
854
855 if [ "$action" = 'on_boot' ] || [ "$1" = 'on_boot' ]; then
856 if cacheOps 'testGzip' || cacheOps 'test'; then
857 action='restore'
858 else
859 action='download'
860 fi
861 elif [ "$action" = 'download' ] || [ "$1" = 'download' ] || [ -n "$error" ]; then
862 action='download'
863 elif [ ! -s "$outputFile" ]; then
864 if cacheOps 'testGzip' || cacheOps 'test'; then
865 action='restore'
866 else
867 action='download'
868 fi
869 elif [ "$action" = 'restart' ] || [ "$1" = 'restart' ]; then
870 action='restart'
871 elif [ -s "$outputFile" ] && [ "$status" = "statusSuccess" ] && [ -z "$error" ]; then
872 [ "$1" != 'hotplug' ] && showstatus
873 exit 0
874 else
875 action='download'
876 fi
877
878 tmpfs del all
879 tmpfs set triggers
880
881 procd_open_instance 'main'
882 procd_set_param command /bin/true
883 procd_set_param stdout 1
884 procd_set_param stderr 1
885 procd_open_data
886 json_add_array firewall
887 if [ "$forceDNS" -ne 0 ]; then
888 json_add_object ''
889 json_add_string type redirect
890 json_add_string name simple_adblock_dns_redirect
891 json_add_string target DNAT
892 json_add_string src lan
893 json_add_string proto tcpudp
894 json_add_string src_dport 53
895 json_add_string dest_port 53
896 json_add_string reflection 0
897 json_close_object
898 fi
899 if [ "$targetDNS" = 'dnsmasq.ipset' ]; then
900 json_add_object ''
901 json_add_string type ipset
902 json_add_string name adb
903 json_add_string match dest_net
904 json_add_string storage hash
905 json_add_string enabled 1
906 json_close_object
907 json_add_object ''
908 json_add_string type rule
909 json_add_string name simple_adblock_ipset_rule
910 json_add_string ipset adb
911 json_add_string src lan
912 json_add_string dest '*'
913 json_add_string proto tcpudp
914 json_add_string target REJECT
915 json_add_string enabled 1
916 json_close_object
917 fi
918 json_close_array
919 procd_close_data
920 procd_close_instance
921
922 if [ "$action" = 'restore' ]; then
923 output 0 "Starting $serviceName... "
924 output 3 "Starting $serviceName...\\n"
925 tmpfs set status "statusStarting"
926 if cacheOps 'testGzip' && ! cacheOps 'test' && [ ! -s "$outputFile" ]; then
927 output 3 'Found compressed cache file, unpacking it '
928 tmpfs set message 'found compressed cache file, unpacking it.'
929 if cacheOps 'unpackGzip'; then
930 output_okn
931 else
932 output_fail
933 tmpfs add error "errorRestoreCompressedCache"
934 output "$_ERROR_: $(getErrorText 'errorRestoreCompressedCache')!\\n"
935 action='download'
936 fi
937 fi
938 if cacheOps 'test' && [ ! -s "$outputFile" ]; then
939 output 3 'Found cache file, reusing it '
940 tmpfs set message 'found cache file, reusing it.'
941 if cacheOps 'restore'; then
942 output_okn
943 dnsOps 'on_start'
944 else
945 output_fail
946 tmpfs add error "errorRestoreCache"
947 output "$_ERROR_: $(getErrorText 'errorRestoreCache')!\\n"
948 action='download'
949 fi
950 fi
951 fi
952 case "$action" in
953 download)
954 if [ -s "$outputFile" ] || cacheOps 'test' || cacheOps 'testGzip'; then
955 output 0 "Force-reloading $serviceName... "
956 output 3 "Force-reloading $serviceName...\\n"
957 tmpfs set status "statusForceReloading"
958 else
959 output 0 "Starting $serviceName... "
960 output 3 "Starting $serviceName...\\n"
961 tmpfs set status "statusStarting"
962 fi
963 download_lists
964 dnsOps 'on_start'
965 ;;
966 restart)
967 output 0 "Restarting $serviceName... "
968 output 3 "Restarting $serviceName...\\n"
969 tmpfs set status "statusRestarting"
970 dnsOps 'on_start'
971 ;;
972 start)
973 output 0 "Starting $serviceName... "
974 output 3 "Starting $serviceName...\\n"
975 tmpfs set status "statusStarting"
976 dnsOps 'on_start'
977 ;;
978 esac
979 if [ -s "$outputFile" ] && [ "$(tmpfs get status)" != "statusFail" ]; then
980 output 0 "$__OK__\\n";
981 tmpfs del message
982 tmpfs set status "statusSuccess"
983 c="$(wc -l < "$outputFile")"
984 tmpfs set stats "$serviceName is blocking $c domains (with ${targetDNS})"
985 showstatus
986 else
987 output 0 "$__FAIL__\\n";
988 tmpfs set status "statusFail"
989 tmpfs add error "errorOhSnap"
990 showstatus
991 fi
992 remove_lock
993 }
994
995 service_started() { procd_set_config_changed firewall; }
996 service_stopped() { procd_set_config_changed firewall; }
997 restart_service() { rc_procd start_service 'restart'; }
998 reload_service() { restart_service; }
999 restart() { restart_service; }
1000 reload() { restart_service; }
1001 dl() { rc_procd start_service 'download'; }
1002 killcache() {
1003 rm -f "$addnhostsCache" "$addnhostsGzip"
1004 rm -f "$dnsmasqCache" "$dnsmasqGzip"
1005 rm -f "$ipsetCache" "$ipsetGzip"
1006 rm -f "$serversCache" "$serversGzip"
1007 rm -f "$unboundCache" "$unboundGzip"
1008 config_load 'dhcp'
1009 config_foreach dnsmasqOps 'dnsmasq' 'cleanup'
1010 uci -q commit 'dhcp'
1011 return 0
1012 }
1013
1014 show() { showstatus; }
1015 status_service() { showstatus; }
1016 showstatus() {
1017 local c url status message error stats
1018 status="$(tmpfs get status)"
1019 message="$(tmpfs get message)"
1020 error="$(tmpfs get error)"
1021 stats="$(tmpfs get stats)"
1022 if [ "$status" = "statusSuccess" ]; then
1023 output "$stats "; output_okn;
1024 else
1025 [ -n "$status" ] && status="$(getStatusText "$status")"
1026 if [ -n "$status" ] && [ -n "$message" ]; then
1027 status="${status}: $message"
1028 fi
1029 [ -n "$status" ] && output "$serviceName $status\\n"
1030 fi
1031 if [ -n "$error" ]; then
1032 for c in $error; do
1033 url="${c##*|}"
1034 c="${c%|*}"
1035 case "$c" in
1036 errorDownloadingList|errorParsingList)
1037 output "$_ERROR_: $(getErrorText "$c") $url!\\n";;
1038 *)
1039 output "$_ERROR_: $(getErrorText "$c")!\\n";;
1040 esac
1041 let n=n+1
1042 done
1043 fi
1044 }
1045
1046 stop_service() {
1047 load_package_config
1048 if [ -s "$outputFile" ]; then
1049 output "Stopping $serviceName... "
1050 cacheOps 'create'
1051 if dnsOps 'on_stop'; then
1052 led_off "$led"
1053 output 0 "$__OK__\\n"; output_okn;
1054 tmpfs set status "statusStopped"
1055 tmpfs del message
1056 else
1057 output 0 "$__FAIL__\\n"; output_fail;
1058 tmpfs set status "statusFail"
1059 tmpfs add error "errorStopping"
1060 output "$_ERROR_: $(getErrorText 'errorStopping')!\\n"
1061 fi
1062 fi
1063 }
1064
1065 service_triggers() {
1066 procd_open_trigger
1067 procd_add_config_trigger "config.change" "${packageName}" /etc/init.d/${packageName} reload
1068 procd_close_trigger
1069 }
1070
1071 check() {
1072 load_package_config
1073 local c string="$1"
1074 c="$(grep -c "$string" "$outputFile")"
1075 if [ ! -s "$outputFile" ]; then
1076 echo "No block-list ('$outputFile') found."
1077 elif [ -z "$string" ]; then
1078 echo "Usage: /etc/init.d/${packageName} check string"
1079 elif [ "$c" -gt 0 ]; then
1080 if [ "$c" -gt 1 ]; then
1081 echo "Found $c matches for '$string' in '$outputFile':"
1082 else
1083 echo "Found 1 match for '$string' in '$outputFile':"
1084 fi
1085 case "$targetDNS" in
1086 dnsmasq.addnhosts)
1087 grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
1088 dnsmasq.conf)
1089 grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
1090 dnsmasq.ipset)
1091 grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
1092 dnsmasq.servers)
1093 grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
1094 unbound.adb_list)
1095 grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';;
1096 esac
1097 else
1098 echo "The $string is not found in current block-list ('$outputFile')."
1099 fi
1100 }
1101
1102 sizes() {
1103 local i
1104 load_package_config
1105 echo "# $(date)"
1106
1107 for i in $blocked_domains_urls; do
1108 [ "${i//melmac}" != "$i" ] && continue
1109 if $dl_command "$i" $dl_flag /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then
1110 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1111 if compare_values "$(du -sk /tmp/sast)" "500"; then
1112 echo "# block-list too big for most routers"
1113 elif compare_values "$(du -sk /tmp/sast)" "100"; then
1114 echo "# block-list may be too big for some routers"
1115 fi
1116 rm -rf /tmp/sast
1117 echo " list blocked_domains_url '$i'"
1118 echo ""
1119 else
1120 echo "# site was down on last check"
1121 echo "# list blocked_domains_url '$i'"
1122 echo ""
1123 fi
1124 done
1125
1126 for i in $blocked_hosts_urls; do
1127 if $dl_command "$i" $dl_flag /tmp/sast 2>/dev/null && [ -s /tmp/sast ]; then
1128 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1129 if compare_values "$(du -sk /tmp/sast)" "500"; then
1130 echo "# block-list too big for most routers"
1131 elif compare_values "$(du -sk /tmp/sast)" "100"; then
1132 echo "# block-list may be too big for some routers"
1133 fi
1134 rm -rf /tmp/sast
1135 echo " list blocked_hosts_url '$i'"
1136 echo ""
1137 else
1138 echo "# site was down on last check"
1139 echo "# list blocked_hosts_url '$i'"
1140 echo ""
1141 fi
1142 done
1143 }