1 #!/bin/sh /etc/rc.common
2 # Copyright 2017-2022 Stan Grishin (stangri@melmac.ca)
3 # shellcheck disable=SC2039,SC1091,SC2016,SC3043,SC3057,SC3060
6 # shellcheck disable=SC2034
8 # shellcheck disable=SC2034
12 if type extra_command
1>/dev
/null
2>&1; then
13 extra_command
'allow' 'Allows domain(s) in current block-list and config'
14 extra_command
'check' 'Checks if specified domain is found in current block-list'
15 extra_command
'dl' 'Force-downloads all enabled block-list'
16 extra_command
'killcache' 'Delete all cached files'
17 extra_command
'sizes' 'Displays the file-sizes of enabled block-lists'
18 extra_command
'version' 'Show version information'
20 # shellcheck disable=SC2034
21 EXTRA_COMMANDS
='allow check dl killcache sizes status_service version'
22 # shellcheck disable=SC2034
23 EXTRA_HELP
=' allow Allows domain(s) in current block-list and config
24 check Checks if specified domain is found in current block-list
25 dl Force-downloads all enabled block-list
26 sizes Displays the file-sizes of enabled block-lists'
29 readonly packageName
='simple-adblock'
30 readonly serviceName
="$packageName $PKG_VERSION"
31 readonly dnsmasqAddnhostsFile
="/var/run/${packageName}/dnsmasq.addnhosts"
32 readonly dnsmasqAddnhostsCache
="/var/run/${packageName}/dnsmasq.addnhosts.cache"
33 readonly dnsmasqAddnhostsGzip
="/etc/${packageName}.dnsmasq.addnhosts.gz"
34 readonly dnsmasqAddnhostsFilter
='s|^|127.0.0.1 |;s|$||'
35 readonly dnsmasqAddnhostsFilterIPv6
='s|^|:: |;s|$||'
36 readonly dnsmasqConfFile
="/tmp/dnsmasq.d/${packageName}"
37 readonly dnsmasqConfCache
="/var/run/${packageName}/dnsmasq.conf.cache"
38 readonly dnsmasqConfGzip
="/etc/${packageName}.dnsmasq.conf.gz"
39 readonly dnsmasqConfFilter
='s|^|local=/|;s|$|/|'
40 readonly dnsmasqIpsetFile
="/tmp/dnsmasq.d/${packageName}.ipset"
41 readonly dnsmasqIpsetCache
="/var/run/${packageName}/dnsmasq.ipset.cache"
42 readonly dnsmasqIpsetGzip
="/etc/${packageName}.dnsmasq.ipset.gz"
43 readonly dnsmasqIpsetFilter
='s|^|ipset=/|;s|$|/adb|'
44 readonly dnsmasqNftsetFile
="/tmp/dnsmasq.d/${packageName}.nftset"
45 readonly dnsmasqNftsetCache
="/var/run/${packageName}/dnsmasq.nftset.cache"
46 readonly dnsmasqNftsetGzip
="/etc/${packageName}.dnsmasq.nftset.gz"
47 readonly dnsmasqNftsetFilter
='s|^|nftset=/|;s|$|/adb|'
48 readonly dnsmasqServersFile
="/var/run/${packageName}/dnsmasq.servers"
49 readonly dnsmasqServersCache
="/var/run/${packageName}/dnsmasq.servers.cache"
50 readonly dnsmasqServersGzip
="/etc/${packageName}.dnsmasq.servers.gz"
51 readonly dnsmasqServersFilter
='s|^|server=/|;s|$|/|'
52 readonly unboundFile
="/var/lib/unbound/adb_list.${packageName}"
53 readonly unboundCache
="/var/run/${packageName}/unbound.cache"
54 readonly unboundGzip
="/etc/${packageName}.unbound.gz"
55 readonly unboundFilter
='s|^|local-zone: "|;s|$|" static|'
56 readonly A_TMP
="/var/${packageName}.hosts.a.tmp"
57 readonly B_TMP
="/var/${packageName}.hosts.b.tmp"
58 readonly jsonFile
="/var/run/${packageName}/${packageName}.json"
59 readonly sharedMemoryError
="/dev/shm/$packageName-error"
60 readonly sharedMemoryOutput
="/dev/shm/$packageName-output"
61 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;'
62 readonly domainsFilter
='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
63 readonly _OK_
='\033[0;32m\xe2\x9c\x93\033[0m'
64 readonly _FAIL_
='\033[0;31m\xe2\x9c\x97\033[0m'
65 readonly __OK__
='\033[0;32m[\xe2\x9c\x93]\033[0m'
66 readonly __FAIL__
='\033[0;31m[\xe2\x9c\x97]\033[0m'
67 readonly _ERROR_
='\033[0;31mERROR\033[0m'
68 readonly _WARNING_
='\033[0;33mWARNING\033[0m'
102 uci_add_list_if_new
() {
108 [ -n "$PACKAGE" ] && [ -n "$CONFIG" ] && [ -n "$OPTION" ] && [ -n "$VALUE" ] ||
return 1
109 for i
in $
(uci_get
"$PACKAGE" "$CONFIG" "$OPTION"); do
110 [ "$i" = "$VALUE" ] && return 0
112 uci_add_list
"$PACKAGE" "$CONFIG" "$OPTION" "$VALUE"
118 /sbin
/uci
${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} changes "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
121 version() { echo "$PKG_VERSION"; }
126 statusNoInstall) _ret="$serviceName is not installed or not found
";;
127 statusStopped) _ret="Stopped
";;
128 statusStarting) _ret="Starting
";;
129 statusRestarting) _ret="Restarting
";;
130 statusForceReloading) _ret="Force Reloading
";;
131 statusDownloading) _ret="Downloading
";;
132 statusProcessing) _ret="Processing
";;
133 statusError) _ret="Error
";;
134 statusWarning) _ret="Warning
";;
135 statusFail) _ret="Fail
";;
136 statusSuccess) _ret="Success
";;
143 errorOutputFileCreate) _ret="failed to create
$outputFile file";;
144 errorFailDNSReload) _ret="failed to restart
/reload DNS resolver
";;
145 errorSharedMemory) _ret="failed to access shared memory
";;
146 errorSorting) _ret="failed to
sort data
file";;
147 errorOptimization) _ret="failed to optimize data
file";;
148 errorAllowListProcessing) _ret="failed to process allow-list
";;
149 errorDataFileFormatting) _ret="failed to format data
file";;
150 errorMovingDataFile) _ret="failed to move data
file '${A_TMP}' to
'${outputFile}'";;
151 errorCreatingCompressedCache) _ret="failed to create compressed cache
";;
152 errorRemovingTempFiles) _ret="failed to remove temporary files
";;
153 errorRestoreCompressedCache) _ret="failed to unpack compressed cache
";;
154 errorRestoreCache) _ret="failed to move
'$outputCache' to
'$outputFile'";;
155 errorOhSnap) _ret="failed to create block-list or restart DNS resolver
";;
156 errorStopping) _ret="failed to stop
$serviceName";;
157 errorDNSReload) _ret="failed to reload
/restart DNS resolver
";;
158 errorDownloadingConfigUpdate) _ret="failed to download Config Update
file";;
159 errorDownloadingList) _ret="failed to download
";;
160 errorParsingConfigUpdate) _ret="failed to parse Config Update
file";;
161 errorParsingList) _ret="failed to parse
";;
162 errorNoSSLSupport) _ret="no HTTPS
/SSL support on device
";;
163 errorCreatingDirectory) _ret="failed to create output
/cache
/gzip file directory
";;
168 output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n
"; }
169 output_okn() { output 1 "$_OK_\\n
"; output 2 "$__OK__\\n
"; }
170 output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n
"; }
171 output_failn() { output 1 "$_FAIL_\\n
"; output 2 "$__FAIL__\\n
"; }
172 str_replace() { printf "%b
" "$1" | sed -e "s
/$
(printf "%b" "$2")/$
(printf "%b" "$3")/g
"; }
173 str_contains() { test "$1" != "$
(str_replace
"$1" "$2" '')"; }
174 is_greater() { test "$
(printf '%s\n' "$@" |
sort -V |
head -n 1)" != "$1"; }
175 is_greater_or_equal() { test "$
(printf '%s\n' "$@" |
sort -V |
head -n 1)" = "$2"; }
176 is_chaos_calmer() { ubus -S call system board | grep -q 'Chaos Calmer'; }
177 led_on(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'default-on' > "${1}/trigger" 2>&1; fi; }
178 led_off
(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'none' > "${1}/trigger" 2>&1; fi; }
179 dnsmasq_hup() { killall -q -s HUP dnsmasq; }
180 dnsmasq_kill() { killall -q -s KILL dnsmasq; }
181 dnsmasq_restart() { /etc/init.d/dnsmasq restart >/dev/null 2>&1; }
182 unbound_restart() { /etc/init.d/unbound restart >/dev/null 2>&1; }
183 is_present() { command -v "$1" >/dev/null 2>&1; }
186 # Can take a single parameter (text) to be output at any verbosity
187 # Or target verbosity level and text to be output at specifc verbosity
188 local msg memmsg logmsg
189 if [ $# -ne 1 ]; then
190 if [ $((verbosity & $1)) -gt 0 ] || [ "$verbosity" = "$1" ]; then shift; else return 0; fi
192 [ -t 1 ] && printf "%b
" "$1"
193 msg="${1//$serviceName /service }";
194 if [ "$
(printf "%b" "$msg" |
wc -l)" -gt 0 ]; then
195 [ -s "$sharedMemoryOutput" ] && memmsg="$
(cat "$sharedMemoryOutput")"
196 logmsg="$
(printf "%b" "${memmsg}${msg}" |
sed 's/\x1b\[[0-9;]*m//g')"
197 logger -t "${packageName:-service} [$$
]" "$
(printf "%b" "$logmsg")"
198 rm -f "$sharedMemoryOutput"
200 printf "%b
" "$msg" >> "$sharedMemoryOutput"
204 load_package_config() {
206 config_load "$packageName"
207 config_get_bool serviceEnabled 'config' 'enabled' 1
208 config_get_bool forceDNS 'config' 'force_dns' 1
209 config_get_bool parallelDL 'config' 'parallel_downloads' 1
210 config_get_bool debug 'config' 'debug' 0
211 config_get_bool compressedCache 'config' 'compressed_cache' 0
212 config_get_bool ipv6Enabled 'config' 'ipv6_enabled' 0
213 config_get_bool configUpdateEnabled 'config' 'config_update_enabled' 0
214 config_get forceDNSPorts 'config' 'force_dns_port' '53 853'
215 config_get bootDelay 'config' 'boot_delay' '120'
216 config_get dlTimeout 'config' 'download_timeout' '20'
217 config_get curlRetry 'config' 'curl_retry' '3'
218 config_get verbosity 'config' 'verbosity' '2'
219 config_get led 'config' 'led'
220 config_get targetDNS 'config' 'dns' 'dnsmasq.servers'
221 config_get dnsInstance 'config' 'dns_instance' '0'
222 config_get allowed_domains 'config' 'allowed_domain'
223 config_get allowed_domains_urls 'config' 'allowed_domains_url'
224 config_get blocked_domains 'config' 'blocked_domain'
225 config_get blocked_domains_urls 'config' 'blocked_domains_url'
226 config_get blocked_hosts_urls 'config' 'blocked_hosts_url'
227 config_get configUpdateURL 'config' 'config_update_url' 'https://cdn.jsdelivr.net/gh/openwrt/packages/net/simple-adblock/files/simple-adblock.conf.update'
229 if [ "$targetDNS" != 'dnsmasq.addnhosts' ] && [ "$targetDNS" != 'dnsmasq.conf' ] && \
230 [ "$targetDNS" != 'dnsmasq.servers' ] && [ "$targetDNS" != 'unbound.adb_list' ] && \
231 [ "$targetDNS" != 'dnsmasq.ipset' ] && [ "$targetDNS" != 'dnsmasq.nftset' ] ; then
232 targetDNS='dnsmasq.servers'
237 outputFilter="$dnsmasqAddnhostsFilter"
238 outputFile="$dnsmasqAddnhostsFile"
239 outputCache="$dnsmasqAddnhostsCache"
240 outputGzip="$dnsmasqAddnhostsGzip"
241 [ "$ipv6Enabled" -gt 0 ] && outputFilterIPv6="$dnsmasqAddnhostsFilterIPv6"
242 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "$dnsmasqConfGzip"
243 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
244 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
245 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "$dnsmasqServersGzip"
246 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
249 outputFilter="$dnsmasqConfFilter"
250 outputFile="$dnsmasqConfFile"
251 outputCache="$dnsmasqConfCache"
252 outputGzip="$dnsmasqConfGzip"
253 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
254 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
255 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
256 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "$dnsmasqServersGzip"
257 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
260 outputFilter="$dnsmasqIpsetFilter"
261 outputFile="$dnsmasqIpsetFile"
262 outputCache="$dnsmasqIpsetCache"
263 outputGzip="$dnsmasqIpsetGzip"
264 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
265 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "$dnsmasqConfGzip"
266 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
267 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "$dnsmasqServersGzip"
268 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
271 outputFilter="$dnsmasqNftsetFilter"
272 outputFile="$dnsmasqNftsetFile"
273 outputCache="$dnsmasqNftsetCache"
274 outputGzip="$dnsmasqNftsetGzip"
275 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
276 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "$dnsmasqConfGzip"
277 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
278 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "$dnsmasqServersGzip"
279 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
282 outputFilter="$dnsmasqServersFilter"
283 outputFile="$dnsmasqServersFile"
284 outputCache="$dnsmasqServersCache"
285 outputGzip="$dnsmasqServersGzip"
286 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
287 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "$dnsmasqConfGzip"
288 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
289 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
290 rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
293 outputFilter="$unboundFilter"
294 outputFile="$unboundFile"
295 outputCache="$unboundCache"
296 outputGzip="$unboundGzip"
297 rm -f "$dnsmasqAddnhostsFile" "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
298 rm -f "$dnsmasqConfFile" "$dnsmasqConfCache" "$dnsmasqConfGzip"
299 rm -f "$dnsmasqIpsetFile" "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
300 rm -f "$dnsmasqNftsetFile" "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
301 rm -f "$dnsmasqServersFile" "$dnsmasqServersCache" "$dnsmasqServersGzip"
304 if [ -z "${verbosity##*[!0-9]*}" ] || [ "$verbosity" -lt 0 ] || [ "$verbosity" -gt 2 ]; then
307 . /lib/functions/network.sh
308 . /usr/share/libubox/jshn.sh
309 is_present 'gawk' && awk='gawk'
310 if ! is_present '/usr/libexec/grep-gnu' || ! is_present '/usr/libexec/sed-gnu' || \
311 ! is_present '/usr/libexec/sort-coreutils' || ! is_present 'gawk'; then
312 local s="opkg update
; opkg
--force-overwrite install"
313 is_present 'gawk' || s="$s gawk
"
314 is_present '/usr/libexec/grep-gnu' || s="$s grep"
315 is_present '/usr/libexec/sed-gnu' || s="$s sed"
316 is_present '/usr/libexec/sort-coreutils' || s="$s coreutils-sort
"
317 output "$_WARNING_: Some recommended packages are missing
, install them by running
:\\n
"
320 # Prefer curl because it supports the file:// scheme.
321 if is_present 'curl'; then
322 dl_command="curl
--insecure --retry $curlRetry --connect-timeout $dlTimeout --silent"
324 elif is_present '/usr/libexec/wget-ssl'; then
325 dl_command="/usr
/libexec
/wget-ssl
--no-check-certificate --timeout $dlTimeout -q"
327 elif is_present wget && wget --version 2>/dev/null | grep -q "+https
"; then
328 dl_command="wget
--no-check-certificate --timeout $dlTimeout -q"
331 dl_command="uclient-fetch
--no-check-certificate --timeout $dlTimeout -q"
334 led="${led:+/sys/class/leds/$led}"
335 if curl --version 2>/dev/null | grep -q "https
" \
336 || wget --version 2>/dev/null | grep -q "+https
" \
337 || grep -q "libustream-mbedtls
" /usr/lib/opkg/status \
338 || grep -q "libustream-openssl
" /usr/lib/opkg/status \
339 || grep -q "libustream-wolfssl
" /usr/lib/opkg/status; then
351 if [ "$debug" -ne 0 ]; then
352 exec 1>>/tmp/simple-adblock.log
357 if [ "$serviceEnabled" -eq 0 ]; then
360 output "$packageName is currently disabled.
\\n
"
361 output "Run the following commands before starting service again
:\\n
"
362 output "uci
set ${packageName}.config.enabled
='1'; uci commit
$packageName;\\n
"
369 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
370 if dnsmasq -v 2>/dev/null | grep -q 'no-IDN' || ! dnsmasq -v 2>/dev/null | grep -q -w 'IDN'; then
382 if dnsmasq -v 2>/dev/null | grep -q 'no-ipset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'ipset'; then
383 output "$_ERROR_: DNSMASQ ipset support is enabled
in $packageName, but DNSMASQ is either not installed or installed DNSMASQ does not support ipset
!\\n
"
384 targetDNS='dnsmasq.servers'
386 if ! ipset help hash:net >/dev/null 2>&1; then
387 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
"
388 targetDNS='dnsmasq.servers'
392 if dnsmasq -v 2>/dev/null | grep -q 'no-nftset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'nftset'; then
393 output "$_ERROR_: DNSMASQ nftset support is enabled
in $packageName, but DNSMASQ is either not installed or installed DNSMASQ does not support nftset
!\\n
"
394 targetDNS='dnsmasq.servers'
396 if [ -z "$
(command -v nft
)" ]; then
397 output "$_ERROR_: DNSMASQ nftset support is enabled
in $packageName, but nft is not installed
!\\n
"
398 targetDNS='dnsmasq.servers'
403 for i in "$outputFile" "$outputCache" "$outputGzip"; do
404 if ! mkdir -p "$
(dirname "$i")"; then
405 output "$_ERROR_: Unable to create directory
for $i!\\n
"
406 jsonOps add error "errorOutputFileCreate
"
410 cacheOps 'testGzip' && return 0
411 network_flush_cache; network_find_wan wan_if; network_get_gateway wan_gw "$wan_if";
412 [ -n "$wan_gw" ] && return 0
413 output "$_ERROR_: $serviceName failed to discover WAN gateway.
\\n
"; return 1;
417 local cfg="$1" param="$2"
420 if [ "$
(uci_get
'dhcp' "$cfg" 'serversfile')" = "$dnsmasqServersFile" ]; then
421 uci_remove 'dhcp' "$cfg" 'serversfile'
423 uci_add_list_if_new 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
425 dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|unbound.adb_list|cleanup)
426 uci_remove_list 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
427 if [ "$
(uci_get
'dhcp' "$cfg" 'serversfile')" = "$dnsmasqServersFile" ]; then
428 uci_remove 'dhcp' "$cfg" 'serversfile'
432 uci_remove_list 'dhcp' "$cfg" 'addnhosts' "$dnsmasqAddnhostsFile"
433 if [ "$
(uci_get
'dhcp' "$cfg" 'serversfile')" != "$dnsmasqServersFile" ]; then
434 uci_set 'dhcp' "$cfg" 'serversfile' "$dnsmasqServersFile"
441 local param output_text i
444 if [ ! -s "$outputFile" ]; then
445 jsonOps set status "statusFail
"
446 jsonOps add error "errorOutputFileCreate
"
447 output "$_ERROR_: $
(getErrorText
'errorOutputFileCreate')!\\n
"
452 if [ "$dnsInstance" = "*" ]; then
453 config_foreach dnsmasqOps 'dnsmasq' "$targetDNS"
454 elif [ -n "$dnsInstance" ]; then
455 for i in $dnsInstance; do
456 dnsmasqOps "@dnsmasq
[$i]" "$targetDNS"
461 dnsmasq.addnhosts|dnsmasq.servers)
463 output_text='Reloading DNSMASQ'
465 dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset)
466 param=dnsmasq_restart
467 output_text='Restarting DNSMASQ'
470 param=unbound_restart
471 output_text='Restarting Unbound'
475 if [ -n "$
(uci_changes dhcp
)" ]; then
477 if [ "$param" = 'unbound_restart' ]; then
478 param='dnsmasq_restart; unbound_restart;'
479 output_text='Restarting Unbound/DNSMASQ'
481 param=dnsmasq_restart
482 output_text='Restarting DNSMASQ'
485 output 1 "$output_text "
486 output 2 "$output_text "
487 jsonOps set message "$output_text"
488 if eval "$param"; then
489 jsonOps set status "statusSuccess
"
494 jsonOps set status "statusFail
"
495 jsonOps add error "errorDNSReload
"
496 output "$_ERROR_: $
(getErrorText
'errorDNSReload')!\\n
"
502 dnsmasq.addnhosts|dnsmasq.servers)
505 dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset)
506 param=dnsmasq_restart
509 param=unbound_restart
512 if [ -n "$
(uci_changes dhcp
)" ]; then
514 if [ "$param" = 'unbound_restart' ]; then
515 param='dnsmasq_restart; unbound_restart;'
517 param=dnsmasq_restart
525 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
526 param=dnsmasq_restart
529 param=unbound_restart
539 # shellcheck disable=SC2034
540 local action="$1" param="$2" value="$3"
541 local status message error stats
542 local reload restart curReload curRestart ret i
543 if [ -s "$jsonFile" ]; then
544 json_load_file "$jsonFile" 2>/dev/null
545 json_select 'data' 2>/dev/null
546 for i in status message error stats reload restart; do
547 json_get_var $i "$i" 2>/dev/null
554 curReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS $configUpdateEnabled $configUpdateURL"
555 curRestart="$compressedCache $forceDNS $led $forceDNSPorts"
556 if [ ! -s "$jsonFile" ]; then
558 elif [ "$curReload" != "$reload" ]; then
560 elif [ "$curRestart" != "$restart" ]; then
566 printf "%b
" "$
(eval echo "\$$param")"; return;;
570 if [ -n "$
(eval echo "\$$param")" ]; then
571 value="$
(eval echo "\$$param") ${value}"
573 eval "$param"='${value}'
578 unset status message error stats;;
580 unset reload restart;;
588 reload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS $configUpdateEnabled $configUpdateURL"
589 restart="$compressedCache $forceDNS $led $forceDNSPorts"
592 eval "$param"='$value';;
597 json_add_object 'data'
598 json_add_string version "$PKG_VERSION"
599 json_add_string status "$status"
600 json_add_string message "$message"
601 json_add_string error "$error"
602 json_add_string stats "$stats"
603 json_add_string reload "$reload"
604 json_add_string restart "$restart"
606 json_dump > "$jsonFile"
614 [ -s "$outputFile" ] && { mv -f "$outputFile" "$outputCache"; true > "$outputFile"; } >/dev/null 2>/dev/null
618 [ -s "$outputCache" ] && mv "$outputCache" "$outputFile" >/dev/null 2>/dev/null
622 [ -s "$outputCache" ]
626 [ -s "$outputGzip" ] && gzip -t -c "$outputGzip"
630 R_TMP="$
(mktemp
-u -q -t ${packageName}_tmp.XXXXXXXX
)"
631 if gzip < "$outputFile" > "$R_TMP"; then
632 if mv "$R_TMP" "$outputGzip"; then
643 expand|unpack|expandGzip|unpackGzip)
644 [ -s "$outputGzip" ] && gzip -dc < "$outputGzip" > "$outputCache"
651 local label type D_TMP R_TMP
652 if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then return 1; fi
653 label="${1##*//}"; label="${label%%/*}";
654 if [ "$2" = 'hosts' ]; then
655 label="Hosts
: $label"; filter="$hostsFilter";
657 label="Domains
: $label"; filter="$domainsFilter";
659 if [ "$3" = 'blocked' ]; then
660 type='Blocked'; D_TMP="$B_TMP";
662 type='Allowed'; D_TMP="$A_TMP";
664 if [ "${1:0:5}" = "https
" ] && [ -z "$isSSLSupported" ]; then
666 output 2 "[DL
] $type $label $__FAIL__\\n
"
667 echo "errorNoSSLSupport|
${1}" >> "$sharedMemoryError"
670 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
671 R_TMP="$
(mktemp
-u -q -t ${packageName}_tmp.XXXXXXXX
)"
673 if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
675 output 2 "[DL
] $type $label $__FAIL__\\n
"
676 echo "errorDownloadingList|
${1}" >> "$sharedMemoryError"
678 sed -i "$filter" "$R_TMP"
679 if [ ! -s "$R_TMP" ]; then
681 output 2 "[DL
] $type $label $__FAIL__\\n
"
682 echo "errorParsingList|
${1}" >> "$sharedMemoryError"
684 cat "${R_TMP}" >> "$D_TMP"
686 output 2 "[DL
] $type $label $__OK__\\n
"
693 process_config_update() {
695 [ "$configUpdateEnabled" -eq 0 ] && return 0
696 label="${1##*//}"; label="${label%%/*}";
697 while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do
698 R_TMP="$
(mktemp
-u -q -t ${packageName}_tmp.XXXXXXXX
)"
700 if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
702 output 2 "[DL
] Config Update
: $label $__FAIL__\\n
"
703 jsonOps add error "errorDownloadingConfigUpdate
"
705 if [ -s "$R_TMP" ] && sed -f "$R_TMP" -i /etc/config/simple-adblock 2>/dev/null; then
707 output 2 "[DL
] Config Update
: $label $__OK__\\n
"
710 output 2 "[DL
] Config Update
: $label $__FAIL__\\n
"
711 jsonOps add error "errorParsingConfigUpdate
"
719 local hf w_filter j=0 R_TMP
721 jsonOps set message "$
(getStatusText
"statusDownloading")...
"
722 jsonOps set status "statusDownloading
"
724 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
725 if [ "$
($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
726 output 3 'Low free memory, restarting resolver... '
727 if dnsOps 'quiet'; then
733 touch $A_TMP; touch $B_TMP;
734 output 1 'Downloading lists '
735 process_config_update "$configUpdateURL"
736 rm -f "$sharedMemoryError"
737 if [ -n "$blocked_hosts_urls" ]; then
738 for hf in ${blocked_hosts_urls}; do
739 if [ "$parallelDL" -gt 0 ]; then
740 process_url "$hf" 'hosts' 'blocked' &
742 process_url "$hf" 'hosts' 'blocked'
746 if [ -n "$blocked_domains_urls" ]; then
747 for hf in ${blocked_domains_urls}; do
748 if [ "$parallelDL" -gt 0 ]; then
749 process_url "$hf" 'domains' 'blocked' &
751 process_url "$hf" 'domains' 'blocked'
755 if [ -n "$allowed_domains_urls" ]; then
756 for hf in ${allowed_domains_urls}; do
757 if [ "$parallelDL" -gt 0 ]; then
758 process_url "$hf" 'domains' 'allowed' &
760 process_url "$hf" 'domains' 'allowed'
766 if [ -s "$sharedMemoryError" ]; then
767 while IFS= read -r line; do
768 jsonOps add error "$line"
769 done < "$sharedMemoryError"
770 rm -f "$sharedMemoryError"
773 [ -n "$blocked_domains" ] && for hf in ${blocked_domains}; do echo "$hf" | sed "$domainsFilter" >> $B_TMP; done
774 allowed_domains="${allowed_domains}
776 [ -n "$allowed_domains" ] && for hf in ${allowed_domains}; do hf="$
(echo "$hf" |
sed 's/\./\\./g')"; w_filter="$w_filter/${hf}$
/d
;"; done
778 [ ! -s "$B_TMP" ] && return 1
780 output 1 'Processing downloads '
781 output 2 'Sorting combined list '
782 jsonOps set message "$
(getStatusText
"statusProcessing"): sorting combined list
"
783 if [ "$allowIDN" -gt 0 ]; then
784 if sort -u "$B_TMP" > "$A_TMP"; then
788 jsonOps add error "errorSorting
"
791 if sort -u "$B_TMP" | grep -E -v '[^a-zA-Z0-9=/.-]' > "$A_TMP"; then
795 jsonOps add error "errorSorting
"
799 if [ "$targetDNS" = 'dnsmasq.conf' ] || \
800 [ "$targetDNS" = 'dnsmasq.ipset' ] || \
801 [ "$targetDNS" = 'dnsmasq.nftset' ] || \
802 [ "$targetDNS" = 'dnsmasq.servers' ] || \
803 [ "$targetDNS" = 'unbound.adb_list' ]; then
804 # TLD optimization written by Dirk Brenken (dev@brenken.org)
805 output 2 'Optimizing combined list '
806 jsonOps set message "$
(getStatusText
"statusProcessing"): optimizing combined list
"
807 # sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
808 if $awk -F ".
" '{for(f=NF;f>1;f--)printf "%s.
",$f;print $1}' "$A_TMP" > "$B_TMP"; then
809 if sort "$B_TMP" > "$A_TMP"; then
810 if $awk '{if(NR=1){tld=$NF};while(getline){if($NF!~tld"\\.
"){print tld;tld=$NF}}print tld}' "$A_TMP" > "$B_TMP"; then
811 if $awk -F ".
" '{for(f=NF;f>1;f--)printf "%s.
",$f;print $1}' "$B_TMP" > "$A_TMP"; then
812 if sort -u "$A_TMP" > "$B_TMP"; then
816 jsonOps add error "errorOptimization
"
821 jsonOps add error "errorOptimization
"
825 jsonOps add error "errorOptimization
"
830 jsonOps add error "errorOptimization
"
834 jsonOps add error "errorOptimization
"
841 output 2 'Allowing domains '
842 jsonOps set message "$
(getStatusText
"statusProcessing"): allowing domains
"
843 if sed -i "$w_filter" "$B_TMP"; then
847 jsonOps add error "errorAllowListProcessing
"
850 output 2 'Formatting merged file '
851 jsonOps set message "$
(getStatusText
"statusProcessing"): formatting merged
file"
852 if [ -z "$outputFilterIPv6" ]; then
853 if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
857 jsonOps add error "errorDataFileFormatting
"
862 if sed "$outputFilter" "$B_TMP" > "$A_TMP" && \
863 sed "$outputFilterIPv6" "$B_TMP" >> "$A_TMP"; then
867 jsonOps add error "errorDataFileFormatting
"
875 output 2 'Creating DNSMASQ addnhosts file '
876 jsonOps set message "$
(getStatusText
"statusProcessing"): creating DNSMASQ addnhosts
file"
879 output 2 'Creating DNSMASQ config file '
880 jsonOps set message "$
(getStatusText
"statusProcessing"): creating DNSMASQ config
file"
883 output 2 'Creating DNSMASQ ipset file '
884 jsonOps set message "$
(getStatusText
"statusProcessing"): creating DNSMASQ ipset
file"
887 output 2 'Creating DNSMASQ nftset file '
888 jsonOps set message "$
(getStatusText
"statusProcessing"): creating DNSMASQ nftset
file"
891 output 2 'Creating DNSMASQ servers file '
892 jsonOps set message "$
(getStatusText
"statusProcessing"): creating DNSMASQ servers
file"
895 output 2 'Creating Unbound adb_list file '
896 jsonOps set message "$
(getStatusText
"statusProcessing"): creating Unbound adb_list
file"
899 if mv "$A_TMP" "$outputFile"; then
903 jsonOps add error "errorMovingDataFile
"
905 if [ "$compressedCache" -gt 0 ]; then
906 output 2 'Creating compressed cache '
907 jsonOps set message "$
(getStatusText
"statusProcessing"): creating compressed cache
"
908 if cacheOps 'createGzip'; then
912 jsonOps add error "errorCreatingCompressedCache
"
917 output 2 'Removing temporary files '
918 jsonOps set message "$
(getStatusText
"statusProcessing"): removing temporary files
"
919 rm -f "/tmp
/${packageName}_tmp.
*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
920 if [ $j -eq 0 ]; then
924 jsonOps add error "errorRemovingTempFiles
"
932 rc_procd start_service 'on_boot' && rc_procd service_triggers
936 is_enabled 'on_start' || return 1
937 local action status error message stats c
939 status="$
(jsonOps get status
)"
940 error="$
(jsonOps get error
)"
941 message="$
(jsonOps get message
)"
942 stats="$
(jsonOps get stats
)"
943 action="$
(jsonOps get triggers
)"
945 if [ "$action" = 'on_boot' ] || [ "$1" = 'on_boot' ]; then
946 if cacheOps 'testGzip' || cacheOps 'test'; then
951 elif [ "$action" = 'download' ] || [ "$1" = 'download' ] || [ -n "$error" ]; then
953 elif [ ! -s "$outputFile" ]; then
954 if cacheOps 'testGzip' || cacheOps 'test'; then
959 elif [ "$action" = 'restart' ] || [ "$1" = 'restart' ]; then
961 elif [ -s "$outputFile" ] && [ "$status" = "statusSuccess
" ] && [ -z "$error" ]; then
971 procd_open_instance 'main'
972 procd_set_param command /bin/true
973 procd_set_param stdout 1
974 procd_set_param stderr 1
976 json_add_array firewall
977 if [ "$forceDNS" -ne 0 ]; then
978 for c in $forceDNSPorts; do
979 if netstat -tuln | grep LISTEN | grep ":${c}" >/dev/null 2>&1; then
981 json_add_string type redirect
982 json_add_string target DNAT
983 json_add_string src lan
984 json_add_string proto "tcp udp
"
985 json_add_string src_dport "$c"
986 json_add_string dest_port "$c"
987 json_add_boolean reflection 0
991 json_add_string type rule
992 json_add_string src lan
993 json_add_string dest "*"
994 json_add_string proto "tcp udp
"
995 json_add_string dest_port "$c"
996 json_add_string target REJECT
1001 if [ "$targetDNS" = 'dnsmasq.ipset' ]; then
1003 json_add_string type ipset
1004 json_add_string name adb
1005 json_add_string match dest_net
1006 json_add_string storage hash
1009 json_add_string type rule
1010 json_add_string ipset adb
1011 json_add_string src lan
1012 json_add_string dest "*"
1013 json_add_string proto "tcp udp
"
1014 json_add_string target REJECT
1019 procd_close_instance
1021 if [ "$action" = 'restore' ]; then
1022 output 0 "Starting
$serviceName...
"
1023 output 3 "Starting
$serviceName...
\\n
"
1024 jsonOps set status "statusStarting
"
1025 if cacheOps 'testGzip' && ! cacheOps 'test' && [ ! -s "$outputFile" ]; then
1026 output 3 'Found compressed cache file, unpacking it '
1027 jsonOps set message 'found compressed cache file, unpacking it.'
1028 if cacheOps 'unpackGzip'; then
1032 jsonOps add error "errorRestoreCompressedCache
"
1033 output "$_ERROR_: $
(getErrorText
'errorRestoreCompressedCache')!\\n
"
1037 if cacheOps 'test' && [ ! -s "$outputFile" ]; then
1038 output 3 'Found cache file, reusing it '
1039 jsonOps set message 'found cache file, reusing it.'
1040 if cacheOps 'restore'; then
1045 jsonOps add error "errorRestoreCache
"
1046 output "$_ERROR_: $
(getErrorText
'errorRestoreCache')!\\n
"
1051 if [ "$action" = 'download' ]; then
1052 if [ -s "$outputFile" ] || cacheOps 'test' || cacheOps 'testGzip'; then
1053 output 0 "Force-reloading
$serviceName...
"
1054 output 3 "Force-reloading
$serviceName...
\\n
"
1055 jsonOps set status "statusForceReloading
"
1057 output 0 "Starting
$serviceName...
"
1058 output 3 "Starting
$serviceName...
\\n
"
1059 jsonOps set status "statusStarting
"
1064 if [ "$action" = 'restart' ]; then
1065 output 0 "Restarting
$serviceName...
"
1066 output 3 "Restarting
$serviceName...
\\n
"
1067 jsonOps set status "statusRestarting
"
1070 if [ "$action" = 'start' ]; then
1071 output 0 "Starting
$serviceName...
"
1072 output 3 "Starting
$serviceName...
\\n
"
1073 jsonOps set status "statusStarting
"
1076 if [ -s "$outputFile" ] && [ "$
(jsonOps get status
)" != "statusFail
" ]; then
1077 output 0 "$__OK__\\n
";
1079 jsonOps set status "statusSuccess
"
1080 jsonOps set stats "$serviceName is blocking $
(wc -l < "$outputFile") domains
(with
${targetDNS})"
1083 output 0 "$__FAIL__\\n
";
1084 jsonOps set status "statusFail
"
1085 jsonOps add error "errorOhSnap
"
1090 service_started() { procd_set_config_changed firewall; }
1091 service_stopped() { procd_set_config_changed firewall; }
1093 restart_service() { rc_procd start_service 'restart'; }
1094 reload_service() { rc_procd start_service 'restart'; }
1095 dl() { rc_procd start_service 'download'; }
1098 rm -f "$dnsmasqAddnhostsCache" "$dnsmasqAddnhostsGzip"
1099 rm -f "$dnsmasqConfCache" "$dnsmasqConfGzip"
1100 rm -f "$dnsmasqIpsetCache" "$dnsmasqIpsetGzip"
1101 rm -f "$dnsmasqNftsetCache" "$dnsmasqNftsetGzip"
1102 rm -f "$dnsmasqServersCache" "$dnsmasqServersGzip"
1103 rm -f "$unboundCache" "$unboundGzip"
1105 config_foreach dnsmasqOps 'dnsmasq' 'cleanup'
1111 local c url status message error stats
1112 config_load "$packageName"
1113 config_get verbosity 'config' 'verbosity' '2'
1114 status="$
(jsonOps get status
)"
1115 message="$
(jsonOps get message
)"
1116 error="$
(jsonOps get error
)"
1117 stats="$
(jsonOps get stats
)"
1118 if [ "$status" = "statusSuccess
" ]; then
1119 output "$stats "; output_okn;
1121 [ -n "$status" ] && status="$
(getStatusText
"$status")"
1122 if [ -n "$status" ] && [ -n "$message" ]; then
1123 status="${status}: $message"
1125 [ -n "$status" ] && output "$serviceName $status\\n
"
1127 if [ -n "$error" ]; then
1132 errorDownloadingList|errorParsingList)
1133 output "$_ERROR_: $
(getErrorText
"$c") $url!\\n
";;
1135 output "$_ERROR_: $
(getErrorText
"$c")!\\n
";;
1144 if [ -s "$outputFile" ]; then
1145 output "Stopping
$serviceName...
"
1147 if dnsOps 'on_stop'; then
1149 output 0 "$__OK__\\n
"; output_okn;
1150 jsonOps set status "statusStopped
"
1153 output 0 "$__FAIL__\\n
"; output_fail;
1154 jsonOps set status "statusFail
"
1155 jsonOps add error "errorStopping
"
1156 output "$_ERROR_: $
(getErrorText
'errorStopping')!\\n
"
1161 service_triggers() {
1163 procd_add_config_trigger 'config.change' "${packageName}" /etc/init.d/${packageName} reload
1164 procd_add_reload_interface_trigger 'wan'
1165 procd_add_interface_trigger 'interface.*.up' 'wan' /etc/init.d/${packageName} reload
1172 if [ ! -s "$outputFile" ]; then
1173 echo "No block-list
('$outputFile') found.
"
1174 elif [ -z "$string" ]; then
1175 echo "Usage
: /etc
/init.d
/${packageName} allow domain
(s
)"
1177 case "$targetDNS" in
1178 dnsmasq.addnhosts|dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers)
1179 output 1 "Allowing domain
(s
) and restarting DNSMASQ...
"
1180 output 2 "Allowing domain
(s
)...
\\n
"
1181 for c in $string; do
1183 if sed -i "/${string}/d
" "$outputFile" && \
1184 uci_add_list "${packageName}" 'config' 'allowed_domain' "$string"; then
1190 output 2 "Committing changes to config...
"
1191 if [ -n "$
(uci_changes
"$packageName")" ] && uci_commit "$packageName"; then
1192 allowed_domains="$
(uci_get_list
"$packageName" 'config' 'allowed_domain')"
1193 jsonOps set triggers
1194 jsonOps set stats "$serviceName is blocking $
(wc -l < "$outputFile") domains
(with
${targetDNS})"
1196 if [ "$targetDNS" = 'dnsmasq.ipset' ]; then
1197 output 2 "Flushing adb ipset...
"
1198 if command -v ipset && ipset flush adb; then output_ok; else output_fail; fi
1200 output 2 "Restarting DNSMASQ...
"
1201 if dnsmasq_restart; then output_okn; else output_failn; fi
1207 output 1 "Allowing domain
(s
) and restarting Unbound...
"
1208 output 2 "Allowing domain
(s
)...
\\n
"
1209 for c in $string; do
1211 if sed -i "/${string}/d
" "$outputFile" && \
1212 uci_add_list "$packageName" 'config' 'allowed_domain' "$string"; then
1218 output 2 "Committing changes to config...
"
1219 if [ -n "$
(uci_changes
"$packageName")" ] && uci_commit "$packageName"; then
1220 allowed_domains="$
(uci_get_list
"$packageName" 'config' 'allowed_domain')"
1221 jsonOps set triggers
1222 jsonOps set stats "$serviceName is blocking $
(wc -l < "$outputFile") domains
(with
${targetDNS})"
1224 output 2 "Restarting Unbound...
"
1225 if unbound_restart; then output_okn; else output_failn; fi
1236 if [ ! -s "$outputFile" ]; then
1237 echo "No block-list
('$outputFile') found.
"
1238 elif [ -z "$string" ]; then
1239 echo "Usage
: /etc
/init.d
/${packageName} check string
"
1241 c="$
(grep -c "$string" "$outputFile")"
1242 if [ "$c" -gt 0 ]; then
1243 if [ "$c" -eq 1 ]; then
1244 echo "Found
1 match
for '$string' in '$outputFile':"
1246 echo "Found
$c matches
for '$string' in '$outputFile'.
"
1248 if [ "$c" -le 20 ]; then
1249 case "$targetDNS" in
1251 grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
1253 grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
1255 grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
1257 grep "$string" "$outputFile" | sed 's|nftset=/||;s|/adb$||;';;
1259 grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
1261 grep "$string" "$outputFile" | sed 's|^local-zone: "||
;s|
" static$||;';;
1265 echo "The
'$string' is not found
in current block-list
('$outputFile').
"
1275 for i
in $blocked_domains_urls; do
1276 [ "${i//melmac}" != "$i" ] && continue
1277 if $dl_command "$i" $dl_flag /tmp
/sast
2>/dev
/null
&& [ -s /tmp
/sast
]; then
1278 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1279 if is_greater
"$(du -sk /tmp/sast)" "500"; then
1280 echo "# block-list too big for most routers"
1281 elif is_greater
"$(du -sk /tmp/sast)" "100"; then
1282 echo "# block-list may be too big for some routers"
1285 echo " list blocked_domains_url '$i'"
1288 echo "# site was down on last check"
1289 echo "# list blocked_domains_url '$i'"
1294 for i
in $blocked_hosts_urls; do
1295 if $dl_command "$i" $dl_flag /tmp
/sast
2>/dev
/null
&& [ -s /tmp
/sast
]; then
1296 echo "# File size: $(du -sh /tmp/sast | $awk '{print $1}')"
1297 if is_greater
"$(du -sk /tmp/sast)" "500"; then
1298 echo "# block-list too big for most routers"
1299 elif is_greater
"$(du -sk /tmp/sast)" "100"; then
1300 echo "# block-list may be too big for some routers"
1303 echo " list blocked_hosts_url '$i'"
1306 echo "# site was down on last check"
1307 echo "# list blocked_hosts_url '$i'"