adblock: bugfix 3.0.1
[feed/packages.git] / net / adblock / files / adblock.sh
1 #!/bin/sh
2 # dns based ad/abuse domain blocking
3 # written by Dirk Brenken (dev@brenken.org)
4
5 # This is free software, licensed under the GNU General Public License v3.
6 # You should have received a copy of the GNU General Public License
7 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
9 # set initial defaults
10 #
11 LC_ALL=C
12 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
13 adb_ver="3.0.1"
14 adb_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
15 adb_enabled=0
16 adb_debug=0
17 adb_manmode=0
18 adb_forcesrt=0
19 adb_forcedns=0
20 adb_triggerdelay=0
21 adb_backup=0
22 adb_backupdir="/mnt"
23 adb_fetch="/usr/bin/wget"
24 adb_fetchparm="--quiet --no-cache --no-cookies --max-redirect=0 --timeout=10 --no-check-certificate -O"
25 adb_dns="dnsmasq"
26 adb_dnsprefix="adb_list"
27 adb_dnsfile="${adb_dnsprefix}.overall"
28 adb_rtfile="/tmp/adb_runtime.json"
29 adb_action="${1:-"start"}"
30 adb_cnt=0
31 adb_rc=0
32
33 # f_envload: load adblock environment
34 #
35 f_envload()
36 {
37 local dns_up cnt=0
38
39 # source in system libraries
40 #
41 if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
42 then
43 . "/lib/functions.sh"
44 . "/usr/share/libubox/jshn.sh"
45 else
46 f_log "error" "system libraries not found"
47 fi
48
49 # parse global section by callback
50 #
51 config_cb()
52 {
53 local type="${1}"
54 if [ "${type}" = "adblock" ]
55 then
56 option_cb()
57 {
58 local option="${1}"
59 local value="${2}"
60 eval "${option}=\"${value}\""
61 }
62 else
63 reset_cb
64 fi
65 }
66
67 # parse 'source' sections
68 #
69 parse_config()
70 {
71 local value opt section="${1}" options="enabled adb_src adb_src_rset adb_src_cat"
72 eval "adb_sources=\"${adb_sources} ${section}\""
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 }
82
83 # load adblock config
84 #
85 config_load adblock
86 config_foreach parse_config source
87
88 # set/check dns backend environment
89 #
90 case "${adb_dns}" in
91 dnsmasq)
92 adb_dnsuser="${adb_dns}"
93 adb_dnsdir="${adb_dnsdir:-"/tmp/dnsmasq.d"}"
94 adb_dnsformat="awk '{print \"local=/\"\$0\"/\"}'"
95 ;;
96 unbound)
97 adb_dnsuser="${adb_dns}"
98 adb_dnsdir="${adb_dnsdir:-"/var/lib/unbound"}"
99 adb_dnsformat="awk '{print \"local-zone: \042\"\$0\"\042 static\"}'"
100 ;;
101 named)
102 adb_dnsuser="bind"
103 adb_dnsdir="${adb_dnsdir:-"/var/lib/bind"}"
104 adb_dnsformat="awk '{print \"\"\$0\" IN CNAME .\n*.\"\$0\" IN CNAME .\"}'"
105 ;;
106 kresd)
107 adb_dnsuser="root"
108 adb_dnsdir="${adb_dnsdir:-"/etc/kresd"}"
109 adb_dnsformat="awk '{print \"\"\$0\" CNAME .\n*.\"\$0\" CNAME .\"}'"
110 adb_dnsheader="\$TTL 2h"$'\n'"@ IN SOA localhost. root.localhost. (2 6h 1h 1w 2h)"$'\n'" IN NS localhost."
111 ;;
112 dnscrypt-proxy)
113 adb_dnsuser="nobody"
114 adb_dnsdir="${adb_dnsdir:-"/tmp"}"
115 adb_dnsformat="awk '{print \$0}'"
116 ;;
117 esac
118
119 if [ -d "${adb_dnsdir}" ] && [ ! -f "${adb_dnsdir}/${adb_dnsfile}" ]
120 then
121 > "${adb_dnsdir}/${adb_dnsfile}"
122 fi
123
124 case "${adb_action}" in
125 start|restart|reload)
126 > "${adb_rtfile}"
127 if [ "${adb_action}" = "start" ] && [ "${adb_trigger}" = "timed" ]
128 then
129 sleep ${adb_triggerdelay}
130 fi
131 ;;
132 esac
133
134 while [ ${cnt} -le 30 ]
135 do
136 dns_up="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" 2>/dev/null | jsonfilter -l1 -e "@[\"${adb_dns}\"].instances.*.running" 2>/dev/null)"
137 if [ "${dns_up}" = "true" ]
138 then
139 break
140 fi
141 sleep 1
142 cnt=$((cnt+1))
143 done
144
145 if [ -z "${adb_dns}" ] || [ -z "${adb_dnsformat}" ] || [ ! -x "$(command -v ${adb_dns})" ] || [ ! -d "${adb_dnsdir}" ]
146 then
147 f_log "error" "'${adb_dns}' not running, DNS backend not found"
148 fi
149
150 # force dns to local resolver
151 #
152 if [ ${adb_forcedns} -eq 1 ] && [ -z "$(uci -q get firewall.adblock_dns)" ]
153 then
154 uci -q set firewall.adblock_dns="redirect"
155 uci -q set firewall.adblock_dns.name="Adblock DNS"
156 uci -q set firewall.adblock_dns.src="lan"
157 uci -q set firewall.adblock_dns.proto="tcp udp"
158 uci -q set firewall.adblock_dns.src_dport="53"
159 uci -q set firewall.adblock_dns.dest_port="53"
160 uci -q set firewall.adblock_dns.target="DNAT"
161 elif [ ${adb_forcedns} -eq 0 ] && [ -n "$(uci -q get firewall.adblock_dns)" ]
162 then
163 uci -q delete firewall.adblock_dns
164 fi
165 if [ -n "$(uci -q changes firewall)" ]
166 then
167 uci -q commit firewall
168 if [ $(/etc/init.d/firewall enabled; printf "%u" ${?}) -eq 0 ]
169 then
170 /etc/init.d/firewall reload >/dev/null 2>&1
171 fi
172 fi
173 }
174
175 # f_envcheck: check/set environment prerequisites
176 #
177 f_envcheck()
178 {
179 local ssl_lib
180
181 # check 'enabled' option
182 #
183 if [ ${adb_enabled} -ne 1 ]
184 then
185 if [ -s "${adb_dnsdir}/${adb_dnsfile}" ]
186 then
187 f_rmdns
188 f_dnsrestart
189 fi
190 f_jsnupdate
191 f_log "info " "adblock is currently disabled, please set adb_enabled to '1' to use this service"
192 exit 0
193 fi
194
195 # check fetch utility
196 #
197 ssl_lib="-"
198 if [ -x "${adb_fetch}" ]
199 then
200 if [ "$(readlink -fn "${adb_fetch}")" = "/usr/bin/wget-nossl" ]
201 then
202 adb_fetchparm="--quiet --no-cache --no-cookies --max-redirect=0 --timeout=10 -O"
203 elif [ "$(readlink -fn "${adb_fetch}")" = "/bin/busybox" ] ||
204 ([ "$(readlink -fn "/bin/wget")" = "/bin/busybox" ] && [ "$(readlink -fn "${adb_fetch}")" != "/usr/bin/wget" ])
205 then
206 adb_fetch="/bin/busybox"
207 adb_fetchparm="-q -O"
208 else
209 ssl_lib="built-in"
210 fi
211 fi
212 if [ ! -x "${adb_fetch}" ] && [ "$(readlink -fn "/bin/wget")" = "/bin/uclient-fetch" ]
213 then
214 adb_fetch="/bin/uclient-fetch"
215 if [ -f "/lib/libustream-ssl.so" ]
216 then
217 adb_fetchparm="-q --timeout=10 --no-check-certificate -O"
218 ssl_lib="libustream-ssl"
219 else
220 adb_fetchparm="-q --timeout=10 -O"
221 fi
222 fi
223 if [ ! -x "${adb_fetch}" ] || [ -z "${adb_fetch}" ] || [ -z "${adb_fetchparm}" ]
224 then
225 f_log "error" "no download utility found, please install 'uclient-fetch' with 'libustream-mbedtls' or the full 'wget' package"
226 fi
227 adb_fetchinfo="${adb_fetch##*/} (${ssl_lib})"
228
229 # create adblock temp file/directory
230 #
231 adb_tmpload="$(mktemp -tu)"
232 adb_tmpfile="$(mktemp -tu)"
233 adb_tmpdir="$(mktemp -p /tmp -d)"
234
235 # prepare whitelist entries
236 #
237 if [ -s "${adb_whitelist}" ] && [ -n "${adb_whitelist_rset}" ]
238 then
239 awk "${adb_whitelist_rset}" "${adb_whitelist}" > "${adb_tmpdir}/tmp.whitelist"
240 fi
241 }
242
243 # f_rmtemp: remove temporary files & directories
244 #
245 f_rmtemp()
246 {
247 if [ -d "${adb_tmpdir}" ]
248 then
249 rm -f "${adb_tmpload}"
250 rm -f "${adb_tmpfile}"
251 rm -rf "${adb_tmpdir}"
252 fi
253 }
254
255 # f_rmdns: remove dns related files & directories
256 #
257 f_rmdns()
258 {
259 if [ -n "${adb_dns}" ]
260 then
261 > "${adb_dnsdir}/${adb_dnsfile}"
262 > "${adb_rtfile}"
263 rm -f "${adb_dnsdir}/.${adb_dnsfile}"
264 rm -f "${adb_backupdir}/${adb_dnsprefix}"*.gz
265 fi
266 }
267
268 # f_dnsrestart: restart the dns backend
269 #
270 f_dnsrestart()
271 {
272 local dns_up cnt=0
273
274 "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
275 while [ ${cnt} -le 10 ]
276 do
277 dns_up="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" | jsonfilter -l1 -e "@[\"${adb_dns}\"].instances.*.running")"
278 if [ "${dns_up}" = "true" ]
279 then
280 return 0
281 fi
282 cnt=$((cnt+1))
283 sleep 1
284 done
285 return 1
286 }
287
288 # f_list: backup/restore/remove block lists
289 #
290 f_list()
291 {
292 local mode="${1}" in_rc="${adb_rc}" cnt=0
293
294 case "${mode}" in
295 backup)
296 cnt="$(wc -l < "${adb_tmpfile}")"
297 if [ ${adb_backup} -eq 1 ] && [ -d "${adb_backupdir}" ]
298 then
299 gzip -cf "${adb_tmpfile}" > "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
300 adb_rc=${?}
301 fi
302 ;;
303 restore)
304 if [ ${adb_backup} -eq 1 ] && [ -d "${adb_backupdir}" ] &&
305 [ -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" ]
306 then
307 gunzip -cf "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" > "${adb_tmpfile}"
308 adb_rc=${?}
309 fi
310 ;;
311 remove)
312 if [ -d "${adb_backupdir}" ]
313 then
314 rm -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
315 fi
316 adb_rc=${?}
317 ;;
318 merge)
319 if [ -s "${adb_tmpfile}" ]
320 then
321 cat "${adb_tmpfile}" >> "${adb_tmpdir}/${adb_dnsfile}"
322 adb_rc=${?}
323 fi
324 ;;
325 format)
326 if [ -s "${adb_tmpdir}/tmp.whitelist" ]
327 then
328 grep -vf "${adb_tmpdir}/tmp.whitelist" "${adb_tmpdir}/${adb_dnsfile}" | eval "${adb_dnsformat}" > "${adb_dnsdir}/${adb_dnsfile}"
329 else
330 eval "${adb_dnsformat}" "${adb_tmpdir}/${adb_dnsfile}" > "${adb_dnsdir}/${adb_dnsfile}"
331 fi
332 if [ -n "${adb_dnsheader}" ]
333 then
334 printf '%s\n' "${adb_dnsheader}" | cat - "${adb_dnsdir}/${adb_dnsfile}" > "${adb_tmpdir}/${adb_dnsfile}"
335 cat "${adb_tmpdir}/${adb_dnsfile}" > "${adb_dnsdir}/${adb_dnsfile}"
336 fi
337 adb_rc=${?}
338 ;;
339 esac
340 f_log "debug" "name: ${src_name}, mode: ${mode}, count: ${cnt}, in_rc: ${in_rc}, out_rc: ${adb_rc}"
341 }
342
343 # f_tldcompression: top level domain compression
344 #
345 f_tldcompression()
346 {
347 local source="${1}" temp="${adb_tmpload}"
348
349 awk -F "." '{for(f=NF;f > 1;f--) printf "%s.", $f;print $1}' "${source}" 2>/dev/null | sort -u > "${temp}"
350 awk '{if(NR==1){tld=$NF};while(getline){if($NF !~ tld"\\."){print tld;tld=$NF}}print tld}' "${temp}" 2>/dev/null > "${source}"
351 awk -F "." '{for(f=NF;f > 1;f--) printf "%s.", $f;print $1}' "${source}" 2>/dev/null > "${temp}"
352 sort -u "${temp}" > "${source}"
353 }
354
355 # f_switch: suspend/resume adblock processing
356 #
357 f_switch()
358 {
359 local source target status mode="${1}"
360
361 if [ -s "${adb_dnsdir}/${adb_dnsfile}" ] && [ "${mode}" = "suspend" ]
362 then
363 source="${adb_dnsdir}/${adb_dnsfile}"
364 target="${adb_dnsdir}/.${adb_dnsfile}"
365 status="suspended"
366 elif [ -s "${adb_dnsdir}/.${adb_dnsfile}" ] && [ "${mode}" = "resume" ]
367 then
368 source="${adb_dnsdir}/.${adb_dnsfile}"
369 target="${adb_dnsdir}/${adb_dnsfile}"
370 status="resumed"
371 fi
372 if [ -n "${status}" ]
373 then
374 cat "${source}" > "${target}"
375 > "${source}"
376 f_dnsrestart
377 f_jsnupdate
378 f_log "info " "adblock processing ${status}"
379 fi
380 }
381
382 # f_query: query block list for certain (sub-)domains
383 #
384 f_query()
385 {
386 local search result cnt
387 local domain="${1}"
388 local tld="${domain#*.}"
389
390 if [ ! -s "${adb_dnsdir}/${adb_dnsfile}" ]
391 then
392 printf "%s\n" "::: no active block list found, please start / resume adblock first"
393 elif [ -z "${domain}" ] || [ "${domain}" = "${tld}" ]
394 then
395 printf "%s\n" "::: invalid domain input, please submit a single domain, e.g. 'doubleclick.net'"
396 else
397 cd "${adb_dnsdir}"
398 while [ "${domain}" != "${tld}" ]
399 do
400 search="${domain//./\.}"
401 if [ "${adb_dns}" = "dnsmasq" ] || [ "${adb_dns}" = "unbound" ]
402 then
403 result="$(awk -F '/|\"' "/[\/\"\.]${search}/{i++;{printf(\" + %s\n\",\$2)};if(i>9){exit}}" "${adb_dnsfile}")"
404 else
405 result="$(awk "/(^[^\*][a-z]*[\.]+${search}|^${search})/{i++;{printf(\" + %s\n\",\$1)};if(i>9){exit}}" "${adb_dnsfile}")"
406 fi
407 printf "%s\n" "::: max. ten results for domain '${domain}'"
408 printf "%s\n" "${result:-" - no match"}"
409 domain="${tld}"
410 tld="${domain#*.}"
411 done
412 fi
413 }
414
415 # f_jsnupdate: update runtime information
416 #
417 f_jsnupdate()
418 {
419 local status rundate="$(/bin/date "+%d.%m.%Y %H:%M:%S")"
420
421 if [ ${adb_rc} -gt 0 ]
422 then
423 status="error"
424 elif [ ${adb_enabled} -ne 1 ]
425 then
426 status="disabled"
427 elif [ -s "${adb_dnsdir}/.${adb_dnsfile}" ]
428 then
429 status="paused"
430 else
431 status="enabled"
432 if [ -s "${adb_dnsdir}/${adb_dnsfile}" ]
433 then
434 if [ "${adb_dns}" = "named" ] || [ "${adb_dns}" = "kresd" ]
435 then
436 adb_cnt="$(( ( $(wc -l < "${adb_dnsdir}/${adb_dnsfile}") - $(printf "%s" "${adb_dnsheader}" | grep -c "^") ) / 2 ))"
437 else
438 adb_cnt="$(( $(wc -l < "${adb_dnsdir}/${adb_dnsfile}") - $(printf "%s" "${adb_dnsheader}" | grep -c "^") ))"
439 fi
440 fi
441 fi
442
443 if [ -z "${adb_fetchinfo}" ] && [ -s "${adb_rtfile}" ]
444 then
445 json_load "$(cat "${adb_rtfile}" 2>/dev/null)"
446 json_select data
447 json_get_var adb_fetchinfo "fetch_utility"
448 fi
449
450 json_init
451 json_add_object "data"
452 json_add_string "adblock_status" "${status}"
453 json_add_string "adblock_version" "${adb_ver}"
454 json_add_string "blocked_domains" "${adb_cnt}"
455 json_add_string "fetch_utility" "${adb_fetchinfo}"
456 json_add_string "dns_backend" "${adb_dns} (${adb_dnsdir})"
457 json_add_string "last_rundate" "${rundate}"
458 json_add_string "system_release" "${adb_sysver}"
459 json_close_object
460 json_dump > "${adb_rtfile}"
461 }
462
463 # f_status: output runtime information
464 #
465 f_status()
466 {
467 local key keylist value
468
469 if [ -s "${adb_rtfile}" ]
470 then
471 printf "%s\n" "::: adblock runtime information"
472 json_load "$(cat "${adb_rtfile}" 2>/dev/null)"
473 json_select data
474 json_get_keys keylist
475 for key in ${keylist}
476 do
477 json_get_var value "${key}"
478 printf " + %-15s : %s\n" "${key}" "${value}"
479 done
480 fi
481 }
482
483 # f_log: write to syslog, exit on error
484 #
485 f_log()
486 {
487 local class="${1}" log_msg="${2}"
488
489 if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${adb_debug} -eq 1 ])
490 then
491 logger -t "adblock-[${adb_ver}] ${class}" "${log_msg}"
492 if [ "${class}" = "error" ]
493 then
494 logger -t "adblock-[${adb_ver}] ${class}" "Please check 'https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md' (${adb_sysver})"
495 f_rmtemp
496 if [ -s "${adb_dnsdir}/${adb_dnsfile}" ]
497 then
498 f_rmdns
499 f_dnsrestart
500 fi
501 adb_rc=1
502 f_jsnupdate
503 exit 1
504 fi
505 fi
506 }
507
508 # main function for block list processing
509 #
510 f_main()
511 {
512 local src_name src_rset shalla_archive enabled url hash_old hash_new
513 local mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo")"
514
515 f_log "info " "start adblock processing ..."
516 f_log "debug" "action: ${adb_action}, manual_mode:${adb_manmode}, backup: ${adb_backup}, dns: ${adb_dns}, fetch: ${adb_fetchinfo}, mem_total: ${mem_total}, force_srt/_dns: ${adb_forcesrt}/${adb_forcedns}"
517 > "${adb_rtfile}"
518 for src_name in ${adb_sources}
519 do
520 eval "enabled=\"\${enabled_${src_name}}\""
521 eval "url=\"\${adb_src_${src_name}}\""
522 eval "src_rset=\"\${adb_src_rset_${src_name}}\""
523 > "${adb_tmpload}"
524 > "${adb_tmpfile}"
525 adb_rc=4
526
527 # basic pre-checks
528 #
529 f_log "debug" "name: ${src_name}, enabled: ${enabled}, url: ${url}, rset: ${src_rset}"
530 if [ "${enabled}" != "1" ] || [ -z "${url}" ] || [ -z "${src_rset}" ]
531 then
532 f_list remove
533 continue
534 fi
535
536 # manual / backup mode
537 #
538 if [ ${adb_manmode} -eq 1 ] && [ "${adb_action}" = "start" ] && [ "${src_name}" != "blacklist" ]
539 then
540 f_list restore
541 if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
542 then
543 f_list merge
544 continue
545 fi
546 fi
547
548 # download block list
549 #
550 if [ "${src_name}" = "blacklist" ] && [ -s "${url}" ]
551 then
552 cat "${url}" > "${adb_tmpload}"
553 adb_rc=${?}
554 elif [ "${src_name}" = "shalla" ]
555 then
556 shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
557 "${adb_fetch}" ${adb_fetchparm} "${shalla_archive}" "${url}" 2>/dev/null
558 adb_rc=${?}
559 if [ ${adb_rc} -eq 0 ]
560 then
561 for category in ${adb_src_cat_shalla}
562 do
563 tar -xOzf "${shalla_archive}" "BL/${category}/domains" >> "${adb_tmpload}"
564 adb_rc=${?}
565 if [ ${adb_rc} -ne 0 ]
566 then
567 break
568 fi
569 done
570 fi
571 rm -f "${shalla_archive}"
572 rm -rf "${adb_tmpdir}/BL"
573 else
574 "${adb_fetch}" ${adb_fetchparm} "${adb_tmpload}" "${url}" 2>/dev/null
575 adb_rc=${?}
576 fi
577
578 # check download result and prepare list output (incl. tld compression, list backup & restore)
579 #
580 if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpload}" ]
581 then
582 awk "${src_rset}" "${adb_tmpload}" 2>/dev/null > "${adb_tmpfile}"
583 if [ -s "${adb_tmpfile}" ]
584 then
585 f_tldcompression "${adb_tmpfile}"
586 if [ "${src_name}" != "blacklist" ]
587 then
588 f_list backup
589 fi
590 else
591 f_list restore
592 fi
593 else
594 f_list restore
595 fi
596
597 # list merge
598 #
599 if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
600 then
601 f_list merge
602 if [ ${adb_rc} -ne 0 ]
603 then
604 f_list remove
605 fi
606 else
607 f_list remove
608 fi
609 done
610
611 # hash preparation, whitelist removal and overall sort
612 #
613 if [ -f "${adb_dnsdir}/${adb_dnsfile}" ]
614 then
615 hash_old="$(sha256sum "${adb_dnsdir}/${adb_dnsfile}" 2>/dev/null | awk '{print $1}')"
616 fi
617 if [ -s "${adb_tmpdir}/${adb_dnsfile}" ]
618 then
619 if [ ${mem_total} -ge 64 ] || [ ${adb_forcesrt} -eq 1 ]
620 then
621 f_tldcompression "${adb_tmpdir}/${adb_dnsfile}"
622 fi
623 f_list format
624 else
625 > "${adb_dnsdir}/${adb_dnsfile}"
626 fi
627 chown "${adb_dnsuser}" "${adb_dnsdir}/${adb_dnsfile}" 2>/dev/null
628 f_rmtemp
629
630 # conditional restart of the dns backend and runtime information export
631 #
632 hash_new="$(sha256sum "${adb_dnsdir}/${adb_dnsfile}" 2>/dev/null | awk '{print $1}')"
633 if [ -z "${hash_old}" ] || [ -z "${hash_new}" ] || [ "${hash_old}" != "${hash_new}" ]
634 then
635 f_dnsrestart
636 fi
637 if [ ${?} -eq 0 ]
638 then
639 f_jsnupdate "${adb_cnt}"
640 f_log "info " "block list with overall ${adb_cnt} domains loaded successfully (${adb_sysver})"
641 else
642 f_log "error" "dns backend restart with active block list failed"
643 fi
644 }
645
646 # handle different adblock actions
647 #
648 f_envload
649 case "${adb_action}" in
650 stop)
651 f_rmtemp
652 f_rmdns
653 f_dnsrestart
654 ;;
655 restart)
656 f_rmtemp
657 f_rmdns
658 f_envcheck
659 f_main
660 ;;
661 suspend)
662 f_switch suspend
663 ;;
664 resume)
665 f_switch resume
666 ;;
667 query)
668 f_query "${2}"
669 ;;
670 status)
671 f_status
672 ;;
673 *)
674 f_envcheck
675 f_main
676 ;;
677 esac
678 exit 0