# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
+# set (s)hellcheck exceptions
+# shellcheck disable=1091,2010,2016,2034,2039,2059,2086,2091,2129,2143,2154,2181,2183,2188
+
START=30
USE_PROCD=1
-EXTRA_COMMANDS="suspend resume query report list timer status_service"
+EXTRA_COMMANDS="suspend resume query report list timer status_service version"
EXTRA_HELP=" suspend Suspend adblock processing
resume Resume adblock processing
query <domain> Query active blocklists and backups for a specific domain
report [<search>] Print DNS statistics with an optional search parameter
list [[<add>|<remove>] [source(s)]] List available adblock sources or add/remove them from config
- timer <action> <hour> [<minute>] [<weekday>] Set a cron based update interval"
+ timer <action> <hour> [<minute>] [<weekday>] Set a cron based update interval
+ version print version information"
adb_init="/etc/init.d/adblock"
adb_script="/usr/bin/adblock.sh"
exit 0
fi
+version()
+{
+ rc_procd "${adb_script}" version
+}
+
boot()
{
[ -s "${adb_pidfile}" ] && > "${adb_pidfile}"
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
-# shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
+# shellcheck disable=1091,2010,2016,2034,2039,2059,2086,2091,2129,2143,2154,2181,2183,2188
# set initial defaults
#
export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
-adb_ver="4.0.6"
+adb_ver="4.0.7"
adb_enabled=0
adb_debug=0
adb_forcedns=0
fi
case "${adb_fetchutil}" in
"aria2c")
- adb_fetchparm="${adb_fetchparm:-"--timeout=20 --allow-overwrite=true --auto-file-renaming=false --check-certificate=true --dir= -o"}"
+ adb_fetchparm="${adb_fetchparm:-"--timeout=20 --allow-overwrite=true --auto-file-renaming=false --check-certificate=true --log-level=warn --dir=/ -o"}"
;;
"curl")
adb_fetchparm="${adb_fetchparm:-"--connect-timeout 20 --silent --show-error --location -o"}"
out_rc="${?}"
;;
"duckduckgo")
- safe_ips="50.16.250.179 54.208.102.2 52.204.96.252"
safe_cname="safe.duckduckgo.com"
safe_domains="duckduckgo.com"
- printf "%s\n" ${safe_domains} > "${adb_tmpdir}/tmp.raw.safesearch.${src_name}"
+ if [ -x "${adb_lookupcmd}" ]
+ then
+ safe_ips="$("${adb_lookupcmd}" "${safe_cname}" 2>/dev/null | "${adb_awk}" '/Address [0-9]+:/{ORS=" ";print $3}')"
+ if [ -n "${safe_ips}" ]
+ then
+ printf "%s\n" ${safe_domains} > "${adb_tmpdir}/tmp.raw.safesearch.${src_name}"
+ fi
+ fi
out_rc="${?}"
;;
"pixabay")
- safe_ips="104.18.82.97 2606:4700::6812:8d57 2606:4700::6812:5261"
safe_cname="safesearch.pixabay.com"
safe_domains="pixabay.com"
printf "%s\n" ${safe_domains} > "${adb_tmpdir}/tmp.raw.safesearch.${src_name}"
+ if [ -x "${adb_lookupcmd}" ]
+ then
+ safe_ips="$("${adb_lookupcmd}" "${safe_cname}" 2>/dev/null | "${adb_awk}" '/Address [0-9]+:/{ORS=" ";print $3}')"
+ if [ -n "${safe_ips}" ]
+ then
+ printf "%s\n" ${safe_domains} > "${adb_tmpdir}/tmp.raw.safesearch.${src_name}"
+ fi
+ fi
out_rc="${?}"
;;
"yandex")
out_rc="${?}"
;;
esac
- if [ "${out_rc}" -eq 0 ]
+ if [ "${out_rc}" -eq 0 ] && [ -f "${adb_tmpdir}/tmp.raw.safesearch.${src_name}" ]
then
> "${adb_tmpdir}/tmp.safesearch.${src_name}"
if [ "${adb_dns}" = "named" ]
(
"${adb_dumpcmd}" -tttt -r "${file}" 2>/dev/null | \
"${adb_awk}" -v cnt="${cnt}" '!/\.lan\. |PTR\? | SOA\? /&&/ A[\? ]+|NXDomain|0\.0\.0\.0/{a=$1;b=substr($2,0,8);c=$4;sub(/\.[0-9]+$/,"",c);d=cnt $7;sub(/\*$/,"",d);
- e=$(NF-1);sub(/[0-9]\/[0-9]\/[0-9]|0\.0\.0\.0/,"NX",e);sub(/\.$/,"",e);sub(/([0-9]{1,3}\.){3}[0-9]{1,3}/,"OK",e);printf "%s\t%s\t%s\t%s\t%s\n",d,e,a,b,c}' >> "${adb_reportdir}/adb_report.raw"
+ e=$(NF-1);sub(/[0-9]\/[0-9]\/[0-9]|0\.0\.0\.0/,"NX",e);sub(/\.$/,"",e);sub(/([0-9]{1,3}\.){3}[0-9]{1,3}/,"OK",e);if(e==""){e="err"};printf "%s\t%s\t%s\t%s\t%s\n",d,e,a,b,c}' >> "${adb_reportdir}/adb_report.raw"
)&
hold=$((cnt%adb_maxqueue))
if [ "${hold}" -eq 0 ]
f_log "err" "system libraries not found"
fi
+# version information
+#
+if [ "${adb_action}" = "version" ]
+then
+ printf "%s\n" "${adb_ver}"
+ exit 0
+fi
+
# handle different adblock actions
#
f_load