15773efbef09acce0e4f4ba604973d211d63ee19
[feed/packages.git] / net / adblock / files / adblock-helper.sh
1 #!/bin/sh
2 # function library used by adblock-update.sh
3 # written by Dirk Brenken (dev@brenken.org)
4
5 # f_envload: load adblock environment
6 #
7 f_envload()
8 {
9 # source in system function library
10 #
11 if [ -r "/lib/functions.sh" ]
12 then
13 . "/lib/functions.sh"
14 else
15 rc=110
16 f_log "system function library not found" "${rc}"
17 f_exit
18 fi
19
20 # source in system network library
21 #
22 if [ -r "/lib/functions/network.sh" ]
23 then
24 . "/lib/functions/network.sh"
25 else
26 rc=115
27 f_log "system network library not found" "${rc}"
28 f_exit
29 fi
30
31 # set initial defaults,
32 # may be overwritten by setting appropriate adblock config options in global section of /etc/config/adblock
33 #
34 adb_lanif="lan"
35 adb_nullport="65535"
36 adb_nullipv4="192.0.2.1"
37 adb_nullipv6="::ffff:c000:0201"
38 adb_whitelist="/etc/adblock/adblock.whitelist"
39 adb_whitelist_rset="\$1 ~/^([A-Za-z0-9_-]+\.){1,}[A-Za-z]+/{print tolower(\$1)}"
40 adb_forcedns=1
41 adb_fetchttl=5
42
43 # function to parse global section by callback
44 #
45 config_cb()
46 {
47 local type="${1}"
48 if [ "${type}" = "adblock" ]
49 then
50 option_cb()
51 {
52 local option="${1}"
53 local value="${2}"
54 eval "${option}=\"${value}\""
55 }
56 else
57 reset_cb
58 fi
59 }
60
61 # function to parse 'service' and 'source' sections
62 #
63 parse_config()
64 {
65 local value opt section="${1}" options="adb_dir adb_src adb_src_rset adb_src_cat"
66 config_get switch "${section}" "enabled"
67 if [ "${switch}" = "1" ]
68 then
69 if [ "${section}" != "backup" ]
70 then
71 eval "adb_sources=\"${adb_sources} ${section}\""
72 fi
73 for opt in ${options}
74 do
75 config_get value "${section}" "${opt}"
76 if [ -n "${value}" ]
77 then
78 eval "${opt}_${section}=\"${value}\""
79 fi
80 done
81 fi
82 }
83
84 # check opkg availability
85 #
86 if [ -r "/var/lock/opkg.lock" ]
87 then
88 rc=-1
89 f_log "adblock installation finished successfully, 'opkg' currently locked by package installer"
90 f_exit
91 fi
92
93 # get list with all installed packages
94 #
95 pkg_list="$(opkg list-installed)"
96 if [ -z "${pkg_list}" ]
97 then
98 rc=120
99 f_log "empty package list" "${rc}"
100 f_exit
101 fi
102
103 # load adblock config and start parsing functions
104 #
105 config_load adblock
106 config_foreach parse_config service
107 config_foreach parse_config source
108
109 # set more script defaults (can't be overwritten by adblock config options)
110 #
111 adb_minspace=12000
112 adb_tmpfile="$(mktemp -tu)"
113 adb_tmpdir="$(mktemp -p /tmp -d)"
114 adb_dnsdir="/tmp/dnsmasq.d"
115 adb_dnshidedir="${adb_dnsdir}/.adb_hidden"
116 adb_dnsprefix="adb_list"
117 adb_uci="$(which uci)"
118 adb_iptv4="$(which iptables)"
119 adb_iptv6="$(which ip6tables)"
120 adb_fetch="$(which wget)"
121 unset adb_srclist adb_revsrclist adb_errsrclist
122
123 # check 'enabled' & 'version' config options
124 #
125 if [ -z "${adb_enabled}" ] || [ -z "${adb_cfgver}" ] || [ "${adb_cfgver%%.*}" != "${adb_mincfgver%%.*}" ]
126 then
127 rc=-1
128 f_log "outdated adblock config (${adb_mincfgver} vs. ${adb_cfgver}), please use latest version from '/etc/adblock/adblock.conf.default'"
129 f_exit
130 elif [ "${adb_cfgver#*.}" != "${adb_mincfgver#*.}" ]
131 then
132 outdate_ok="true"
133 fi
134 if [ $((adb_enabled)) -ne 1 ]
135 then
136 rc=-1
137 f_log "adblock is currently disabled, please set adblock.global.adb_enabled=1' to use this service"
138 f_exit
139 fi
140
141 # check running dnsmasq instance
142 #
143 rc="$(ps | grep -q "[d]nsmasq"; printf ${?})"
144 if [ $((rc)) -ne 0 ]
145 then
146 rc=-1
147 f_log "please enable the local dnsmasq instance to use adblock"
148 f_exit
149 fi
150
151 # check running firewall
152 #
153 check="$(${adb_iptv4} -vnL | grep -F "DROP")"
154 if [ -z "${check}" ]
155 then
156 rc=-1
157 f_log "please enable the local firewall to use adblock"
158 f_exit
159 fi
160
161 # get lan ip addresses
162 #
163 network_get_ipaddr adb_ipv4 "${adb_lanif}"
164 network_get_ipaddr6 adb_ipv6 "${adb_lanif}"
165 if [ -z "${adb_ipv4}" ] && [ -z "${adb_ipv6}" ]
166 then
167 rc=-1
168 f_log "no valid IPv4/IPv6 configuration found (${adb_lanif}), please set 'adb_lanif' manually"
169 f_exit
170 fi
171
172 # check logical update interfaces (with default route)
173 #
174 network_find_wan adb_wanif4
175 network_find_wan6 adb_wanif6
176 if [ -z "${adb_wanif4}" ] && [ -z "${adb_wanif6}" ]
177 then
178 adb_wanif4="${adb_lanif}"
179 fi
180
181 # check AP mode
182 #
183 if [ "${adb_wanif4}" = "${adb_lanif}" ] || [ "${adb_wanif6}" = "${adb_lanif}" ]
184 then
185 adb_nullipv4="${adb_ipv4}"
186 adb_nullipv6="${adb_ipv6}"
187 if [ "$(uci get uhttpd.main.listen_http | grep -Fo "80")" = "80" ] ||
188 [ "$(uci get uhttpd.main.listen_https | grep -Fo "443")" = "443" ]
189 then
190 rc=-1
191 f_log "AP mode detected, set local LuCI instance to ports <> 80/443"
192 f_exit
193 else
194 apmode_ok="true"
195 fi
196 fi
197
198 # get system release level
199 #
200 adb_sysver="$(printf "${pkg_list}" | grep "^base-files -")"
201 adb_sysver="${adb_sysver##*-}"
202 }
203
204 # f_envcheck: check/set environment prerequisites
205 #
206 f_envcheck()
207 {
208 local check
209
210 if [ "${outdate_ok}" = "true" ]
211 then
212 f_log "partially outdated adblock config (${adb_mincfgver} vs. ${adb_cfgver}), please use latest version from '/etc/adblock/adblock.conf.default'"
213 fi
214
215 if [ "${apmode_ok}" = "true" ]
216 then
217 f_log "AP mode enabled"
218 fi
219
220 # check general package dependencies
221 #
222 f_depend "busybox"
223 f_depend "uci"
224 f_depend "uhttpd"
225 f_depend "wget"
226 f_depend "iptables"
227 f_depend "kmod-ipt-nat"
228
229 # check ipv6 related package dependencies
230 #
231 if [ -n "${adb_wanif6}" ]
232 then
233 check="$(printf "${pkg_list}" | grep "^ip6tables -")"
234 if [ -z "${check}" ]
235 then
236 f_log "package 'ip6tables' not found, IPv6 support will be disabled"
237 unset adb_wanif6
238 else
239 check="$(printf "${pkg_list}" | grep "^kmod-ipt-nat6 -")"
240 if [ -z "${check}" ]
241 then
242 f_log "package 'kmod-ipt-nat6' not found, IPv6 support will be disabled"
243 unset adb_wanif6
244 fi
245 fi
246 fi
247
248 # check dns hideout directory
249 #
250 if [ -d "${adb_dnshidedir}" ]
251 then
252 mv_done="$(find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print -exec mv -f "{}" "${adb_dnsdir}" \;)"
253 else
254 mkdir -p -m 660 "${adb_dnshidedir}"
255 fi
256
257 # check ca-certificates package and set fetch parms accordingly
258 #
259 fetch_parm="--no-config --quiet --tries=1 --no-cache --no-cookies --max-redirect=0 --dns-timeout=${adb_fetchttl} --connect-timeout=${adb_fetchttl} --read-timeout=${adb_fetchttl}"
260 check="$(printf "${pkg_list}" | grep "^ca-certificates -")"
261 if [ -z "${check}" ]
262 then
263 fetch_parm="${fetch_parm} --no-check-certificate"
264 fi
265
266 # check adblock temp directory
267 #
268 if [ -n "${adb_tmpdir}" ] && [ -d "${adb_tmpdir}" ]
269 then
270 f_space "${adb_tmpdir}"
271 if [ "${space_ok}" = "false" ]
272 then
273 if [ $((av_space)) -le 2000 ]
274 then
275 rc=125
276 f_log "not enough free space in '${adb_tmpdir}' (avail. ${av_space} kb)" "${rc}"
277 f_exit
278 else
279 f_log "not enough free space to handle all adblock list sources at once in '${adb_tmpdir}' (avail. ${av_space} kb)"
280 fi
281 fi
282 else
283 rc=130
284 f_log "temp directory not found" "${rc}"
285 f_exit
286 fi
287
288 # check memory
289 #
290 mem_total="$(awk '$1 ~ /^MemTotal/ {printf $2}' "/proc/meminfo")"
291 mem_free="$(awk '$1 ~ /^MemFree/ {printf $2}' "/proc/meminfo")"
292 mem_swap="$(awk '$1 ~ /^SwapTotal/ {printf $2}' "/proc/meminfo")"
293 if [ $((mem_total)) -le 64000 ] && [ $((mem_swap)) -eq 0 ]
294 then
295 mem_ok="false"
296 f_log "not enough free memory, overall sort processing will be disabled (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
297 else
298 mem_ok="true"
299 fi
300
301 # check backup configuration
302 #
303 if [ -n "${adb_dir_backup}" ] && [ -d "${adb_dir_backup}" ]
304 then
305 f_space "${adb_dir_backup}"
306 if [ "${space_ok}" = "false" ]
307 then
308 f_log "not enough free space in '${adb_dir_backup}'(avail. ${av_space} kb), backup/restore will be disabled"
309 backup_ok="false"
310 else
311 f_log "backup/restore will be enabled"
312 backup_ok="true"
313 fi
314 else
315 backup_ok="false"
316 f_log "backup/restore will be disabled"
317 fi
318
319 # set dnsmasq defaults
320 #
321 if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ]
322 then
323 adb_dnsformat="awk -v ipv4="${adb_nullipv4}" -v ipv6="${adb_nullipv6}" '{print \"address=/\"\$0\"/\"ipv4\"\n\"\"address=/\"\$0\"/\"ipv6}'"
324 elif [ -n "${adb_wanif4}" ]
325 then
326 adb_dnsformat="awk -v ipv4="${adb_nullipv4}" '{print \"address=/\"\$0\"/\"ipv4}'"
327 else
328 adb_dnsformat="awk -v ipv6="${adb_nullipv6}" '{print \"address=/\"\$0\"/\"ipv6}'"
329 fi
330
331 # check ipv4/iptables configuration
332 #
333 if [ -n "${adb_wanif4}" ]
334 then
335 f_firewall "IPv4" "nat" "A" "prerouting_rule" "adb-nat" "-p tcp -d ${adb_nullipv4} -m multiport --dports 80,443 -j DNAT --to-destination ${adb_ipv4}:${adb_nullport}"
336 f_firewall "IPv4" "filter" "A" "forwarding_rule" "adb-fwd" "-p tcp -d ${adb_nullipv4} -j REJECT --reject-with tcp-reset"
337 f_firewall "IPv4" "filter" "A" "forwarding_rule" "adb-fwd" "-d ${adb_nullipv4} -j REJECT --reject-with icmp-host-unreachable"
338 f_firewall "IPv4" "filter" "A" "output_rule" "adb-out" "-p tcp -d ${adb_nullipv4} -j REJECT --reject-with tcp-reset"
339 f_firewall "IPv4" "filter" "A" "output_rule" "adb-out" "-d ${adb_nullipv4} -j REJECT --reject-with icmp-host-unreachable"
340 if [ $((adb_forcedns)) -eq 1 ]
341 then
342 f_firewall "IPv4" "nat" "A" "prerouting_rule" "adb-dns" "-p udp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
343 f_firewall "IPv4" "nat" "A" "prerouting_rule" "adb-dns" "-p tcp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
344 fi
345 if [ "${fw_done}" = "true" ]
346 then
347 f_log "created volatile IPv4 firewall ruleset"
348 fw_done="false"
349 fi
350 fi
351
352 # check ipv6/ip6tables configuration
353 #
354 if [ -n "${adb_wanif6}" ]
355 then
356 f_firewall "IPv6" "nat" "A" "PREROUTING" "adb-nat" "-p tcp -d ${adb_nullipv6} -m multiport --dports 80,443 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullport}"
357 f_firewall "IPv6" "filter" "A" "forwarding_rule" "adb-fwd" "-p tcp -d ${adb_nullipv6} -j REJECT --reject-with tcp-reset"
358 f_firewall "IPv6" "filter" "A" "forwarding_rule" "adb-fwd" "-d ${adb_nullipv6} -j REJECT --reject-with icmp6-addr-unreachable"
359 f_firewall "IPv6" "filter" "A" "output_rule" "adb-out" "-p tcp -d ${adb_nullipv6} -j REJECT --reject-with tcp-reset"
360 f_firewall "IPv6" "filter" "A" "output_rule" "adb-out" "-d ${adb_nullipv6} -j REJECT --reject-with icmp6-addr-unreachable"
361 if [ $((adb_forcedns)) -eq 1 ]
362 then
363 f_firewall "IPv6" "nat" "A" "PREROUTING" "adb-dns" "-p udp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
364 f_firewall "IPv6" "nat" "A" "PREROUTING" "adb-dns" "-p tcp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
365 fi
366 if [ "${fw_done}" = "true" ]
367 then
368 f_log "created volatile IPv6 firewall ruleset"
369 fw_done="false"
370 fi
371 fi
372
373 # check volatile adblock uhttpd instance configuration
374 #
375 rc="$(ps | grep -q "[u]httpd.*\-h /www/adblock"; printf ${?})"
376 if [ $((rc)) -ne 0 ]
377 then
378 if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ]
379 then
380 uhttpd -h "/www/adblock" -k 0 -N 100 -t 0 -T 1 -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullport}" -p "[${adb_ipv6}]:${adb_nullport}"
381 rc=${?}
382 elif [ -n "${adb_wanif4}" ]
383 then
384 uhttpd -h "/www/adblock" -k 0 -N 100 -t 0 -T 1 -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullport}"
385 rc=${?}
386 else
387 uhttpd -h "/www/adblock" -k 0 -N 100 -t 0 -T 1 -D -S -E "/index.html" -p "[${adb_ipv6}]:${adb_nullport}"
388 rc=${?}
389 fi
390 if [ $((rc)) -eq 0 ]
391 then
392 f_log "created volatile uhttpd instance"
393 else
394 f_log "failed to initialize volatile uhttpd instance" "${rc}"
395 f_restore
396 fi
397 fi
398
399 # check whitelist entries
400 #
401 if [ -s "${adb_whitelist}" ]
402 then
403 awk "${adb_whitelist_rset}" "${adb_whitelist}" > "${adb_tmpdir}/tmp.whitelist"
404 fi
405
406 # remove no longer used opkg package list
407 #
408 unset pkg_list
409 }
410
411 # f_depend: check package dependencies
412 #
413 f_depend()
414 {
415 local check
416 local package="${1}"
417
418 check="$(printf "${pkg_list}" | grep "^${package} -")"
419 if [ -z "${check}" ]
420 then
421 rc=135
422 f_log "package '${package}' not found" "${rc}"
423 f_exit
424 fi
425 }
426
427 # f_firewall: set iptables rules for ipv4/ipv6
428 #
429 f_firewall()
430 {
431 local ipt="${adb_iptv4}"
432 local proto="${1}"
433 local table="${2}"
434 local ctype="${3}"
435 local chain="${4}"
436 local notes="${5}"
437 local rules="${6}"
438
439 # select appropriate iptables executable for IPv6
440 #
441 if [ "${proto}" = "IPv6" ]
442 then
443 ipt="${adb_iptv6}"
444 fi
445
446 # check whether iptables rule already applied and proceed accordingly
447 #
448 rc="$("${ipt}" -w -t "${table}" -C "${chain}" -m comment --comment "${notes}" ${rules}; printf ${?})"
449 if [ $((rc)) -ne 0 ]
450 then
451 "${ipt}" -w -t "${table}" -"${ctype}" "${chain}" -m comment --comment "${notes}" ${rules}
452 rc=${?}
453 if [ $((rc)) -eq 0 ]
454 then
455 fw_done="true"
456 else
457 f_log "failed to initialize volatile ${proto} firewall rule '${notes}'" "${rc}"
458 f_exit
459 fi
460 fi
461 }
462
463 # f_log: log messages to stdout and syslog
464 #
465 f_log()
466 {
467 local log_parm
468 local log_msg="${1}"
469 local log_rc="${2}"
470 local class="info "
471
472 # check for terminal session
473 #
474 if [ -t 1 ]
475 then
476 log_parm="-s"
477 fi
478
479 # log to different output devices and set log class accordingly
480 #
481 if [ -n "${log_msg}" ]
482 then
483 if [ $((log_rc)) -gt 0 ]
484 then
485 class="error"
486 log_rc=", rc: ${log_rc}"
487 log_msg="${log_msg}${log_rc}"
488 fi
489 "${adb_log}" ${log_parm} -t "adblock[${adb_pid}] ${class}" "${log_msg}" 2>&1
490 fi
491 }
492
493 ################################################
494 # f_space: check mount points/space requirements
495 #
496 f_space()
497 {
498 local mp="${1}"
499
500 if [ -d "${mp}" ]
501 then
502 av_space="$(df "${mp}" | tail -n1 | awk '{printf $4}')"
503 if [ $((av_space)) -lt $((adb_minspace)) ]
504 then
505 space_ok="false"
506 fi
507 fi
508 }
509
510 # f_cntconfig: calculate counters in config
511 #
512 f_cntconfig()
513 {
514 local src_name
515 local count=0
516 local count_sum=0
517
518 for src_name in $(ls -ASr "${adb_dnsdir}/${adb_dnsprefix}"*)
519 do
520 count="$(wc -l < "${src_name}")"
521 src_name="${src_name##*.}"
522 if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ]
523 then
524 count=$((count / 2))
525 fi
526 "${adb_uci}" -q set "adblock.${src_name}.adb_src_count=${count}"
527 count_sum=$((count_sum + count))
528 done
529 "${adb_uci}" -q set "adblock.global.adb_overall_count=${count_sum}"
530 }
531
532 # f_rmconfig: remove counters & timestamps in given config sections
533 #
534 f_rmconfig()
535 {
536 local src_name
537 local rm_done="${1}"
538 local restore_done="${2:-false}"
539
540 for src_name in ${rm_done}
541 do
542 src_name="${src_name#*.}"
543 if [ "${restore_done}" = "true" ]
544 then
545 src_name="${src_name%.*}"
546 "${adb_uci}" -q set "adblock.${src_name}.adb_src_timestamp=list restored"
547 else
548 "${adb_uci}" -q delete "adblock.${src_name}.adb_src_count"
549 "${adb_uci}" -q delete "adblock.${src_name}.adb_src_timestamp"
550 fi
551 done
552 }
553
554 # f_restore: restore last adblock list backups and restart dnsmasq
555 #
556 f_restore()
557 {
558 local rm_done
559 local restore_done
560
561 # remove bogus adblock lists
562 #
563 if [ -n "${adb_revsrclist}" ]
564 then
565 rm_done="$(find "${adb_dnsdir}" -maxdepth 1 -type f \( ${adb_revsrclist} \) -print -exec rm -f "{}" \;)"
566 rc=${?}
567 if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
568 then
569 f_rmconfig "${rm_done}"
570 f_log "all bogus adblock lists removed"
571 elif [ $((rc)) -ne 0 ]
572 then
573 f_log "error during removal of bogus adblock lists" "${rc}"
574 f_exit
575 fi
576 fi
577
578 # restore backups
579 #
580 if [ "${backup_ok}" = "true" ]
581 then
582 restore_done="$(find "${adb_dir_backup}" -maxdepth 1 -type f -name "${adb_dnsprefix}*.gz" -print -exec cp -pf "{}" "${adb_dnsdir}" \;)"
583 rc=${?}
584 if [ $((rc)) -eq 0 ] && [ -n "${restore_done}" ]
585 then
586 find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*.gz" -exec gunzip -f "{}" \;
587 f_log "all available backups restored"
588 elif [ $((rc)) -ne 0 ] && [ -n "${restore_done}" ]
589 then
590 f_log "error during restore of adblock lists" "${rc}"
591 f_exit
592 fi
593 else
594 f_log "backup service disabled, nothing to restore"
595 fi
596
597 # (re-)try dnsmasq restart without bogus adblock lists / with backups
598 #
599 if [ -n "${restore_done}" ] || [ -n "${rm_done}" ]
600 then
601 /etc/init.d/dnsmasq restart
602 sleep 1
603 rc="$(ps | grep -q "[d]nsmasq"; printf ${?})"
604 if [ $((rc)) -eq 0 ]
605 then
606 rc=0
607 f_cntconfig
608 f_log "adblock lists with overall ${adb_count} domains loaded"
609 else
610 rc=140
611 f_log "dnsmasq restart failed, please check 'logread' output" "${rc}"
612 fi
613 fi
614 f_exit
615 }
616
617 # f_exit: delete (temporary) files, generate statistics and exit
618 #
619 f_exit()
620 {
621 local ipv4_adblock=0
622 local ipv6_adblock=0
623
624 # delete temporary files & directories
625 #
626 if [ -f "${adb_tmpfile}" ]
627 then
628 rm -f "${adb_tmpfile}"
629 fi
630 if [ -d "${adb_tmpdir}" ]
631 then
632 rm -rf "${adb_tmpdir}"
633 fi
634
635 # final log message and iptables statistics
636 #
637 if [ $((rc)) -eq 0 ]
638 then
639 if [ -n "${adb_wanif4}" ]
640 then
641 ipv4_adblock="$(${adb_iptv4} -t nat -vnL | awk '$11 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
642 ipv4_adblock="$((${ipv4_adblock} + $(${adb_iptv4} -vnL | awk '$11 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
643 fi
644 if [ -n "${adb_wanif6}" ]
645 then
646 ipv6_adblock="$(${adb_iptv6} -t nat -vnL | awk '$10 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
647 ipv6_adblock="$((${ipv6_adblock} + $(${adb_iptv6} -vnL | awk '$10 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
648 fi
649 if [ -n "$(${adb_uci} -q changes adblock)" ]
650 then
651 "${adb_uci}" -q commit "adblock"
652 fi
653 f_log "firewall statistics (IPv4/IPv6): ${ipv4_adblock}/${ipv6_adblock} ad related packets blocked"
654 f_log "domain adblock processing finished successfully (${adb_scriptver}, ${adb_sysver}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
655 elif [ $((rc)) -gt 0 ]
656 then
657 if [ -n "$(${adb_uci} -q changes adblock)" ]
658 then
659 "${adb_uci}" -q revert "adblock"
660 fi
661 f_log "domain adblock processing failed (${adb_scriptver}, ${adb_sysver}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
662 else
663 rc=0
664 fi
665 rm -f "${adb_pidfile}"
666 exit ${rc}
667 }