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