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