export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
-adb_ver="4.1.1"
+adb_ver="4.1.2"
adb_enabled=0
adb_debug=0
adb_forcedns=0
fi
}
+# status helper function
+#
+f_char()
+{
+ local result input="${1}"
+
+ if [ "${input}" = "1" ]
+ then
+ result="✔"
+ else
+ result="✘"
+ fi
+ printf "%s" "${result}"
+}
+
# load dns backend config
#
f_dns()
then
case "${adb_dns}" in
"dnsmasq")
+ adb_dnscachecmd="-"
adb_dnsinotify="${adb_dnsinotify:-"0"}"
adb_dnsinstance="${adb_dnsinstance:-"0"}"
adb_dnsuser="${adb_dnsuser:-"dnsmasq"}"
adb_dnsstop="${adb_dnsstop:-"address=/#/"}"
;;
"unbound")
+ adb_dnscachecmd="$(command -v unbound-control || printf "%s" "-")"
adb_dnsinotify="${adb_dnsinotify:-"0"}"
adb_dnsinstance="${adb_dnsinstance:-"0"}"
adb_dnsuser="${adb_dnsuser:-"unbound"}"
adb_dnsstop="${adb_dnsstop:-"local-zone: \".\" static"}"
;;
"named")
+ adb_dnscachecmd="$(command -v rndc || printf "%s" "-")"
adb_dnsinotify="${adb_dnsinotify:-"0"}"
adb_dnsinstance="${adb_dnsinstance:-"0"}"
adb_dnsuser="${adb_dnsuser:-"bind"}"
adb_dnsstop="${adb_dnsstop:-"* CNAME ."}"
;;
"kresd")
+ adb_dnscachecmd="-"
adb_dnsinotify="${adb_dnsinotify:-"0"}"
adb_dnsinstance="${adb_dnsinstance:-"0"}"
adb_dnsuser="${adb_dnsuser:-"root"}"
adb_dnsstop="${adb_dnsstop:-"* CNAME ."}"
;;
"raw")
+ adb_dnscachecmd="-"
adb_dnsinotify="${adb_dnsinotify:-"0"}"
adb_dnsinstance="${adb_dnsinstance:-"0"}"
adb_dnsuser="${adb_dnsuser:-"root"}"
then
out_rc=0
else
- "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
- restart_rc="${?}"
+ if [ "${in_rc}" = "0" ] && [ "${adb_dnsflush}" = "0" ]
+ then
+ case "${adb_dns}" in
+ "unbound")
+ if [ -x "${adb_dnscachecmd}" ] && [ -d "${adb_tmpdir}" ] && [ -f "${adb_dnsdir}/unbound.conf" ]
+ then
+ "${adb_dnscachecmd}" -c "${adb_dnsdir}/unbound.conf" dump_cache > "${adb_tmpdir}/adb_cache.dump" 2>/dev/null
+ fi
+ "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
+ restart_rc="${?}"
+ ;;
+ "named")
+ if [ -x "${adb_dnscachecmd}" ] && [ -f "/etc/bind/rndc.conf" ]
+ then
+ "${adb_dnscachecmd}" -c "/etc/bind/rndc.conf" reload >/dev/null 2>&1
+ restart_rc="${?}"
+ fi
+ if [ -z "${restart_rc}" ] || { [ -n "${restart_rc}" ] && [ "${restart_rc}" != "0" ]; }
+ then
+ "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
+ restart_rc="${?}"
+ fi
+ ;;
+ *)
+ "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
+ restart_rc="${?}"
+ ;;
+ esac
+ fi
+ if [ -z "${restart_rc}" ]
+ then
+ "/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
+ restart_rc="${?}"
+ fi
fi
if [ "${restart_rc}" = "0" ]
then
cnt=$((cnt+1))
sleep 1
done
+ if [ "${out_rc}" = "0" ] && [ "${adb_dns}" = "unbound" ]
+ then
+ if [ -x "${adb_dnscachecmd}" ] && [ -d "${adb_tmpdir}" ] && [ -s "${adb_tmpdir}/adb_cache.dump" ]
+ then
+ "${adb_dnscachecmd}" -c "${adb_dnsdir}/unbound.conf" load_cache < "${adb_tmpdir}/adb_cache.dump" >/dev/null 2>&1
+ restart_rc="${?}"
+ fi
+ fi
fi
- f_log "debug" "f_dnsup ::: lookup_util: ${adb_lookupcmd:-"-"}, lookup_domain: ${adb_lookupdomain:-"-"}, restart_rc: ${restart_rc:-"-"}, dns_timeout: ${adb_dnstimeout}, dns_cnt: ${cnt}, in_rc: ${in_rc}, out_rc: ${out_rc}"
+ f_log "debug" "f_dnsup ::: dns: ${adb_dns}, cache_cmd: ${adb_dnscachecmd:-"-"}, lookup_cmd: ${adb_lookupcmd:-"-"}, lookup_domain: ${adb_lookupdomain:-"-"}, restart_rc: ${restart_rc:-"-"}, dns_flush: ${adb_dnsflush}, dns_inotify: ${adb_dnsinotify}, dns_timeout: ${adb_dnstimeout}, dns_cnt: ${cnt}, in_rc: ${in_rc}, out_rc: ${out_rc}"
return "${out_rc}"
}
json_load_file "${adb_rtfile}" >/dev/null 2>&1
if [ "${?}" = "0" ]
then
- if [ -z "${adb_fetchutil}" ] || [ -z "${adb_awk}" ]
- then
- json_get_var utils "utilities"
- else
- utils="${adb_fetchutil}, ${adb_awk}"
- fi
+ utils="download: $(readlink -fn "${adb_fetchutil}"), sort: $(readlink -fn "${adb_sort}"), awk: $(readlink -fn "${adb_awk}")"
if [ -z "${adb_cnt}" ]
then
json_get_var adb_cnt "blocked_domains"
json_close_object
done
json_close_array
- json_add_string "dns_backend" "${adb_dns:-"-"}, ${adb_dnsdir:-"-"}"
+ json_add_string "dns_backend" "${adb_dns:-"-"} (${adb_dnscachecmd##*/}), ${adb_dnsdir:-"-"}"
json_add_string "run_utils" "${utils:-"-"}"
json_add_string "run_ifaces" "trigger: ${adb_trigger:-"-"}, report: ${adb_repiface:-"-"}"
json_add_string "run_directories" "base: ${adb_tmpbase}, backup: ${adb_backupdir}, report: ${adb_reportdir}, jail: ${adb_jaildir}"
- json_add_string "run_flags" "backup: ${adb_backup}, flush: ${adb_dnsflush}, force: ${adb_forcedns}, search: ${adb_safesearch}, report: ${adb_report}, mail: ${adb_mail}, jail: ${adb_jail}"
+ json_add_string "run_flags" "backup: $(f_char ${adb_backup}), flush: $(f_char ${adb_dnsflush}), force: $(f_char ${adb_forcedns}), search: $(f_char ${adb_safesearch}), report: $(f_char ${adb_report}), mail: $(f_char ${adb_mail}), jail: $(f_char ${adb_jail})"
json_add_string "last_run" "${runtime:-"-"}"
json_add_string "system" "${adb_sysver}"
json_dump > "${adb_rtfile}"
f_log "err" "system libraries not found"
fi
-# awk selection
+# version information
#
-adb_awk="$(command -v gawk)"
-if [ -z "${adb_awk}" ]
+if [ "${adb_action}" = "version" ]
then
- adb_awk="$(command -v awk)"
- if [ -z "${adb_awk}" ]
- then
- f_log "err" "awk not found"
- fi
+ printf "%s\n" "${adb_ver}"
+ exit 0
fi
-# sort selection
+# awk check
#
-adb_sort="$(command -v /usr/libexec/sort-coreutils)"
-if [ -z "${adb_sort}" ]
+adb_awk="$(command -v gawk)"
+if [ ! -x "${adb_awk}" ]
then
- adb_sort="$(command -v sort)"
- if [ -z "$("${adb_sort}" --help 2>/dev/null | grep -Fo -m1 "coreutils")" ]
+ adb_awk="$(command -v awk)"
+ if [ ! -x "${adb_awk}" ]
then
- f_log "err" "coreutils sort not found"
+ f_log "err" "awk not found or not executable"
fi
fi
-# version information
+# sort check
#
-if [ "${adb_action}" = "version" ]
+adb_sort="$(command -v sort)"
+if [ ! -x "${adb_sort}" ] || [ "$("${adb_sort}" --version 2>/dev/null | grep -c "coreutils")" = "0" ]
then
- printf "%s\n" "${adb_ver}"
- exit 0
+ f_log "err" "coreutils sort not found or not executable"
fi
# handle different adblock actions