@ -1,6 +1,6 @@
#!/bin/sh
#!/bin/sh
# dns based ad/abuse domain blocking
# dns based ad/abuse domain blocking
# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# Copyright (c) 2015-2021 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
# set (s)hellcheck exceptions
@ -11,12 +11,11 @@
export LC_ALL = C
export LC_ALL = C
export PATH = "/usr/sbin:/usr/bin:/sbin:/bin"
export PATH = "/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail
set -o pipefail
adb_ver = "4.0.8 "
adb_ver = "4.1.0 "
adb_enabled = 0
adb_enabled = 0
adb_debug = 0
adb_debug = 0
adb_forcedns = 0
adb_forcedns = 0
adb_maxqueue = 4
adb_maxqueue = 4
adb_dnsfilereset = 0
adb_dnsflush = 0
adb_dnsflush = 0
adb_dnstimeout = 20
adb_dnstimeout = 20
adb_safesearch = 0
adb_safesearch = 0
@ -33,13 +32,12 @@ adb_dns=""
adb_dnsprefix = "adb_list"
adb_dnsprefix = "adb_list"
adb_locallist = "blacklist whitelist"
adb_locallist = "blacklist whitelist"
adb_tmpbase = "/tmp"
adb_tmpbase = "/tmp"
adb_backupdir = "/ tmp"
adb_reportdir = "/ tmp"
adb_backupdir = " ${ adb_ tmpbase } /adblock-Backup "
adb_reportdir = " ${ adb_ tmpbase } /adblock-Report "
adb_jaildir = "/tmp"
adb_jaildir = "/tmp"
adb_pidfile = "/var/run/adblock.pid"
adb_pidfile = "/var/run/adblock.pid"
adb_blacklist = "/etc/adblock/adblock.blacklist"
adb_blacklist = "/etc/adblock/adblock.blacklist"
adb_whitelist = "/etc/adblock/adblock.whitelist"
adb_whitelist = "/etc/adblock/adblock.whitelist"
adb_ubusservice = "/etc/adblock/adblock.monitor"
adb_mailservice = "/etc/adblock/adblock.mail"
adb_mailservice = "/etc/adblock/adblock.mail"
adb_dnsfile = " ${ adb_dnsprefix } .overall "
adb_dnsfile = " ${ adb_dnsprefix } .overall "
adb_dnsjail = " ${ adb_dnsprefix } .jail "
adb_dnsjail = " ${ adb_dnsprefix } .jail "
@ -75,12 +73,11 @@ f_load()
f_fetch
f_fetch
fi
fi
if [ " ${ adb_enabled } " -eq 0 ]
if [ " ${ adb_enabled } " = "0" ]
then
then
f_extconf
f_extconf
f_temp
f_temp
f_rmdns
f_rmdns
f_bgserv "stop"
f_jsnup "disabled"
f_jsnup "disabled"
f_log "info" "adblock is currently disabled, please set the config option 'adb_enabled' to '1' to use this service"
f_log "info" "adblock is currently disabled, please set the config option 'adb_enabled' to '1' to use this service"
exit 0
exit 0
@ -97,7 +94,7 @@ f_env()
f_extconf
f_extconf
f_temp
f_temp
if [ " ${ adb_dnsflush } " -eq 1 ]
if [ " ${ adb_dnsflush } " = "1" ]
then
then
printf " ${ adb_dnsheader } " > " ${ adb_dnsdir } / ${ adb_dnsfile } "
printf " ${ adb_dnsheader } " > " ${ adb_dnsdir } / ${ adb_dnsfile } "
f_dnsup
f_dnsup
@ -146,6 +143,18 @@ f_conf()
if [ " ${ option } " = "adb_sources" ]
if [ " ${ option } " = "adb_sources" ]
then
then
eval " ${ option } =\" $( printf "%s" " ${ adb_sources } " ) ${ value } \" "
eval " ${ option } =\" $( printf "%s" " ${ adb_sources } " ) ${ value } \" "
elif [ " ${ option } " = "adb_eng_sources" ]
then
eval " ${ option } =\" $( printf "%s" " ${ adb_eng_sources } " ) ${ value } \" "
elif [ " ${ option } " = "adb_sha_sources" ]
then
eval " ${ option } =\" $( printf "%s" " ${ adb_sha_sources } " ) ${ value } \" "
elif [ " ${ option } " = "adb_stb_sources" ]
then
eval " ${ option } =\" $( printf "%s" " ${ adb_stb_sources } " ) ${ value } \" "
elif [ " ${ option } " = "adb_utc_sources" ]
then
eval " ${ option } =\" $( printf "%s" " ${ adb_utc_sources } " ) ${ value } \" "
elif [ " ${ option } " = "adb_safesearchlist" ]
elif [ " ${ option } " = "adb_safesearchlist" ]
then
then
eval " ${ option } =\" $( printf "%s" " ${ adb_safesearchlist } " ) ${ value } \" "
eval " ${ option } =\" $( printf "%s" " ${ adb_safesearchlist } " ) ${ value } \" "
@ -299,7 +308,7 @@ f_dns()
if [ -n " ${ adb_dnsdir } " ] && [ ! -d " ${ adb_dnsdir } " ]
if [ -n " ${ adb_dnsdir } " ] && [ ! -d " ${ adb_dnsdir } " ]
then
then
mkdir -p " ${ adb_dnsdir } "
mkdir -p " ${ adb_dnsdir } "
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
f_log "info" " dns backend directory ' ${ adb_dnsdir } ' created "
f_log "info" " dns backend directory ' ${ adb_dnsdir } ' created "
else
else
@ -315,27 +324,27 @@ f_dns()
if [ " ${ dns_up } " != "true" ]
if [ " ${ dns_up } " != "true" ]
then
then
f_dnsup 4
f_dnsup 4
if [ " ${ ? } " -ne 0 ]
if [ " ${ ? } " != "0" ]
then
then
f_log "err" " dns backend ' ${ adb_dns } ' not running or executable "
f_log "err" " dns backend ' ${ adb_dns } ' not running or executable "
fi
fi
fi
fi
if [ " ${ adb_backup } " -eq 1 ] && [ -n " ${ adb_backupdir } " ] && [ ! -d " ${ adb_backupdir } " ]
if [ " ${ adb_backup } " = "1" ] && [ -n " ${ adb_backupdir } " ] && [ ! -d " ${ adb_backupdir } " ]
then
then
mkdir -p " ${ adb_backupdir } "
mkdir -p " ${ adb_backupdir } "
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
f_log "info" " backup directory ' ${ adb_backupdir } ' created "
f_log "info" " backup directory ' ${ adb_backupdir } ' created "
else
else
f_log "err" " backup backend directory ' ${ adb_backupdir } ' could not be created "
f_log "err" " backup directory ' ${ adb_backupdir } ' could not be created "
fi
fi
fi
fi
if [ -n " ${ adb_jaildir } " ] && [ ! -d " ${ adb_jaildir } " ]
if [ -n " ${ adb_jaildir } " ] && [ ! -d " ${ adb_jaildir } " ]
then
then
mkdir -p " ${ adb_jaildir } "
mkdir -p " ${ adb_jaildir } "
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
f_log "info" " jail directory ' ${ adb_jaildir } ' created "
f_log "info" " jail directory ' ${ adb_jaildir } ' created "
else
else
@ -405,11 +414,11 @@ f_temp()
cpu = " $( grep -c '^processor' /proc/cpuinfo 2>/dev/null) "
cpu = " $( grep -c '^processor' /proc/cpuinfo 2>/dev/null) "
core = " $( grep -cm1 '^core id' /proc/cpuinfo 2>/dev/null) "
core = " $( grep -cm1 '^core id' /proc/cpuinfo 2>/dev/null) "
if [ " ${ cpu } " -eq 0 ]
if [ " ${ cpu } " = "0" ]
then
then
cpu = 1
cpu = 1
fi
fi
if [ " ${ core } " -eq 0 ]
if [ " ${ core } " = "0" ]
then
then
core = 1
core = 1
fi
fi
@ -454,7 +463,7 @@ f_rmdns()
if [ " ${ adb_dns } " = "raw" ] || { [ -n " ${ adb_dns } " ] && [ -n " ${ status } " ] ; }
if [ " ${ adb_dns } " = "raw" ] || { [ -n " ${ adb_dns } " ] && [ -n " ${ status } " ] ; }
then
then
> " ${ adb_rtfile } "
> " ${ adb_rtfile } "
if [ " ${ adb_backup } " -eq 1 ]
if [ " ${ adb_backup } " = "1" ]
then
then
rm -f " ${ adb_backupdir } / ${ adb_dnsprefix } " .*.gz
rm -f " ${ adb_backupdir } / ${ adb_dnsprefix } " .*.gz
fi
fi
@ -566,7 +575,7 @@ f_extconf()
"dnsmasq" )
"dnsmasq" )
config = "dhcp"
config = "dhcp"
config_dir = " $( uci_get dhcp " @dnsmasq[ ${ adb_dnsinstance } ] " confdir | grep -Fo " ${ adb_dnsdir } " ) "
config_dir = " $( uci_get dhcp " @dnsmasq[ ${ adb_dnsinstance } ] " confdir | grep -Fo " ${ adb_dnsdir } " ) "
if [ " ${ adb_enabled } " -eq 1 ] && [ -z " ${ config_dir } " ]
if [ " ${ adb_enabled } " = "1" ] && [ -z " ${ config_dir } " ]
then
then
uci_set dhcp " @dnsmasq[ ${ adb_dnsinstance } ] " confdir " ${ adb_dnsdir } " 2>/dev/null
uci_set dhcp " @dnsmasq[ ${ adb_dnsinstance } ] " confdir " ${ adb_dnsdir } " 2>/dev/null
fi
fi
@ -574,10 +583,10 @@ f_extconf()
"kresd" )
"kresd" )
config = "resolver"
config = "resolver"
config_file = " $( uci_get resolver kresd rpz_file | grep -Fo " ${ adb_dnsdir } / ${ adb_dnsfile } " ) "
config_file = " $( uci_get resolver kresd rpz_file | grep -Fo " ${ adb_dnsdir } / ${ adb_dnsfile } " ) "
if [ " ${ adb_enabled } " -eq 1 ] && [ -z " ${ config_file } " ]
if [ " ${ adb_enabled } " = "1" ] && [ -z " ${ config_file } " ]
then
then
uci -q add_list resolver.kresd.rpz_file= " ${ adb_dnsdir } / ${ adb_dnsfile } "
uci -q add_list resolver.kresd.rpz_file= " ${ adb_dnsdir } / ${ adb_dnsfile } "
elif [ " ${ adb_enabled } " -eq 0 ] && [ -n " ${ config_file } " ]
elif [ " ${ adb_enabled } " = "0" ] && [ -n " ${ config_file } " ]
then
then
uci -q del_list resolver.kresd.rpz_file= " ${ adb_dnsdir } / ${ adb_dnsfile } "
uci -q del_list resolver.kresd.rpz_file= " ${ adb_dnsdir } / ${ adb_dnsfile } "
fi
fi
@ -587,8 +596,8 @@ f_extconf()
config = "firewall"
config = "firewall"
fwcfg = " $( uci -qNX show " ${ config } " | " ${ adb_awk } " 'BEGIN{FS="[.=]"};/adblock_/{if(zone==$2){next}else{ORS=" ";zone=$2;print zone}}' ) "
fwcfg = " $( uci -qNX show " ${ config } " | " ${ adb_awk } " 'BEGIN{FS="[.=]"};/adblock_/{if(zone==$2){next}else{ORS=" ";zone=$2;print zone}}' ) "
if [ " ${ adb_enabled } " -eq 1 ] && [ " ${ adb_forcedns } " -eq 1 ] && \
[ " $( /etc/init.d/firewall enabled; printf "%u" ${ ? } ) " -eq 0 ]
if [ " ${ adb_enabled } " = "1" ] && [ " ${ adb_forcedns } " = "1" ] && \
[ " $( /etc/init.d/firewall enabled; printf "%u" ${ ? } ) " = "0" ]
then
then
for zone in ${ adb_zonelist }
for zone in ${ adb_zonelist }
do
do
@ -612,7 +621,7 @@ f_extconf()
fwcfg = " ${ fwcfg # " ${ fwcfg %%[![ : space : ]]* } " } "
fwcfg = " ${ fwcfg # " ${ fwcfg %%[![ : space : ]]* } " } "
fwcfg = " ${ fwcfg % " ${ fwcfg ##*[![ : space : ]] } " } "
fwcfg = " ${ fwcfg % " ${ fwcfg ##*[![ : space : ]] } " } "
fi
fi
if [ " ${ adb_enabled } " -eq 0 ] || [ " ${ adb_forcedns } " -eq 0 ] || [ -n " ${ fwcfg } " ]
if [ " ${ adb_enabled } " = "0" ] || [ " ${ adb_forcedns } " = "0" ] || [ -n " ${ fwcfg } " ]
then
then
for section in ${ fwcfg }
for section in ${ fwcfg }
do
do
@ -628,7 +637,7 @@ f_dnsup()
{
{
local dns_service dns_up dns_pid dns_procfile restart_rc cnt = 0 out_rc = 4 in_rc = " ${ 1 :- 0 } "
local dns_service dns_up dns_pid dns_procfile restart_rc cnt = 0 out_rc = 4 in_rc = " ${ 1 :- 0 } "
if [ " ${ adb_dns } " = "raw" ] || { [ " ${ in_rc } " -eq 0 ] && [ " ${ adb_dnsinotify } " -eq 1 ] ; }
if [ " ${ adb_dns } " = "raw" ] || { [ " ${ in_rc } " = "0" ] && [ " ${ adb_dnsinotify } " = "1" ] ; }
then
then
out_rc = 0
out_rc = 0
else
else
@ -648,7 +657,7 @@ f_dnsup()
if [ -x " ${ adb_lookupcmd } " ] && [ " ${ adb_lookupdomain } " != "false" ]
if [ -x " ${ adb_lookupcmd } " ] && [ " ${ adb_lookupdomain } " != "false" ]
then
then
" ${ adb_lookupcmd } " " ${ adb_lookupdomain } " >/dev/null 2>& 1
" ${ adb_lookupcmd } " " ${ adb_lookupdomain } " >/dev/null 2>& 1
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
out_rc = 0
out_rc = 0
break
break
@ -690,16 +699,16 @@ f_list()
rset = " /^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]| $)/{print tolower(\$1)} "
rset = " /^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]| $)/{print tolower(\$1)} "
" ${ adb_awk } " " ${ rset } " " ${ adb_whitelist } " > " ${ adb_tmpdir } /tmp.raw. ${ src_name } "
" ${ adb_awk } " " ${ rset } " " ${ adb_whitelist } " > " ${ adb_tmpdir } /tmp.raw. ${ src_name } "
out_rc = " ${ ? } "
out_rc = " ${ ? } "
if [ " ${ out_rc } " -eq 0 ]
if [ " ${ out_rc } " = "0" ]
then
then
rset = " /^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]| $)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^(|.*\\\\.)\"\$1\" $\")} "
rset = " /^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]| $)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^(|.*\\\\.)\"\$1\" $\")} "
" ${ adb_awk } " " ${ rset } " " ${ adb_tmpdir } /tmp.raw. ${ src_name } " > " ${ adb_tmpdir } /tmp.rem. ${ src_name } "
" ${ adb_awk } " " ${ rset } " " ${ adb_tmpdir } /tmp.raw. ${ src_name } " > " ${ adb_tmpdir } /tmp.rem. ${ src_name } "
out_rc = " ${ ? } "
out_rc = " ${ ? } "
if [ " ${ out_rc } " -eq 0 ] && [ " ${ adb_dnsallow } " != "1" ]
if [ " ${ out_rc } " = "0" ] && [ " ${ adb_dnsallow } " != "1" ]
then
then
eval " ${ adb_dnsallow } " " ${ adb_tmpdir } /tmp.raw. ${ src_name } " > " ${ adb_tmpdir } /tmp.add. ${ src_name } "
eval " ${ adb_dnsallow } " " ${ adb_tmpdir } /tmp.raw. ${ src_name } " > " ${ adb_tmpdir } /tmp.add. ${ src_name } "
out_rc = " ${ ? } "
out_rc = " ${ ? } "
if [ " ${ out_rc } " -eq 0 ] && [ " ${ adb_jail } " = "1" ] && [ " ${ adb_dnsstop } " != "0" ]
if [ " ${ out_rc } " = "0" ] && [ " ${ adb_jail } " = "1" ] && [ " ${ adb_dnsstop } " != "0" ]
then
then
> " ${ adb_jaildir } / ${ adb_dnsjail } "
> " ${ adb_jaildir } / ${ adb_dnsjail } "
if [ -n " ${ adb_dnsheader } " ]
if [ -n " ${ adb_dnsheader } " ]
@ -720,19 +729,19 @@ f_list()
safe_url = "https://www.google.com/supported_domains"
safe_url = "https://www.google.com/supported_domains"
safe_cname = "forcesafesearch.google.com"
safe_cname = "forcesafesearch.google.com"
safe_domains = " ${ adb_tmpdir } /tmp.load.safesearch. ${ src_name } "
safe_domains = " ${ adb_tmpdir } /tmp.load.safesearch. ${ src_name } "
if [ " ${ adb_backup } " -eq 1 ] && [ -s " ${ adb_backupdir } /safesearch. ${ src_name } .gz " ]
if [ " ${ adb_backup } " = "1" ] && [ -s " ${ adb_backupdir } /safesearch. ${ src_name } .gz " ]
then
then
zcat " ${ adb_backupdir } /safesearch. ${ src_name } .gz " > " ${ safe_domains } "
zcat " ${ adb_backupdir } /safesearch. ${ src_name } .gz " > " ${ safe_domains } "
out_rc = " ${ ? } "
out_rc = " ${ ? } "
else
else
" ${ adb_fetchutil } " ${ adb_fetchparm } " ${ safe_domains } " " ${ safe_url } " 2>/dev/null
" ${ adb_fetchutil } " ${ adb_fetchparm } " ${ safe_domains } " " ${ safe_url } " 2>/dev/null
out_rc = " ${ ? } "
out_rc = " ${ ? } "
if [ " ${ adb_backup } " -eq 1 ] && [ " ${ out_rc } " -eq 0 ]
if [ " ${ adb_backup } " = "1" ] && [ " ${ out_rc } " = "0" ]
then
then
gzip -cf " ${ safe_domains } " > " ${ adb_backupdir } /safesearch. ${ src_name } .gz "
gzip -cf " ${ safe_domains } " > " ${ adb_backupdir } /safesearch. ${ src_name } .gz "
fi
fi
fi
fi
if [ " ${ out_rc } " -eq 0 ]
if [ " ${ out_rc } " = "0" ]
then
then
if [ -x " ${ adb_lookupcmd } " ]
if [ -x " ${ adb_lookupcmd } " ]
then
then
@ -786,7 +795,7 @@ f_list()
; ;
; ;
"yandex" )
"yandex" )
safe_cname = "familysearch.yandex.ru"
safe_cname = "familysearch.yandex.ru"
safe_domains = "ya.ru yandex.ru yandex.com yandex.com.tr yandex.ua yandex.by yandex.ee yandex.lt yandex.lv yandex.md yandex.uz yandex.tm yandex.tj yandex.az"
safe_domains = "ya.ru yandex.ru yandex.com yandex.com.tr yandex.ua yandex.by yandex.ee yandex.lt yandex.lv yandex.md yandex.uz yandex.tm yandex.tj yandex.az yandex.kz "
if [ -x " ${ adb_lookupcmd } " ]
if [ -x " ${ adb_lookupcmd } " ]
then
then
safe_ips = " $( " ${ adb_lookupcmd } " " ${ safe_cname } " 2>/dev/null | " ${ adb_awk } " '/^Address[ 0-9]*: /{ORS=" ";print $NF}' ) "
safe_ips = " $( " ${ adb_lookupcmd } " " ${ safe_cname } " 2>/dev/null | " ${ adb_awk } " '/^Address[ 0-9]*: /{ORS=" ";print $NF}' ) "
@ -798,7 +807,7 @@ f_list()
out_rc = " ${ ? } "
out_rc = " ${ ? } "
; ;
; ;
"youtube" )
"youtube" )
if [ " ${ adb_safesearchmod } " -eq 0 ]
if [ " ${ adb_safesearchmod } " = "0" ]
then
then
safe_cname = "restrict.youtube.com"
safe_cname = "restrict.youtube.com"
else
else
@ -816,7 +825,7 @@ f_list()
out_rc = " ${ ? } "
out_rc = " ${ ? } "
; ;
; ;
esac
esac
if [ " ${ out_rc } " -eq 0 ] && [ -s " ${ adb_tmpdir } /tmp.raw.safesearch. ${ src_name } " ]
if [ " ${ out_rc } " = "0" ] && [ -s " ${ adb_tmpdir } /tmp.raw.safesearch. ${ src_name } " ]
then
then
> " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
> " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
if [ " ${ adb_dns } " = "named" ]
if [ " ${ adb_dns } " = "named" ]
@ -828,7 +837,7 @@ f_list()
for item in ${ array }
for item in ${ array }
do
do
eval " ${ adb_dnssafesearch } " " ${ adb_tmpdir } /tmp.raw.safesearch. ${ src_name } " >> " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
eval " ${ adb_dnssafesearch } " " ${ adb_tmpdir } /tmp.raw.safesearch. ${ src_name } " >> " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
if [ " ${ ? } " -ne 0 ]
if [ " ${ ? } " != "0" ]
then
then
rm -f " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
rm -f " ${ adb_tmpdir } /tmp.safesearch. ${ src_name } "
break
break
@ -859,7 +868,7 @@ f_list()
name = " ${ name %.* } "
name = " ${ name %.* } "
zcat " ${ file } " > " ${ adb_tmpfile } . ${ name } " &
zcat " ${ file } " > " ${ adb_tmpfile } . ${ name } " &
hold = $(( cnt%adb_maxqueue))
hold = $(( cnt%adb_maxqueue))
if [ " ${ hold } " -eq 0 ]
if [ " ${ hold } " = "0" ]
then
then
wait
wait
fi
fi
@ -871,13 +880,13 @@ f_list()
else
else
out_rc = 4
out_rc = 4
fi
fi
if [ " ${ adb_action } " != "start" ] && [ " ${ adb_action } " != "resume" ] && [ -n " ${ src_name } " ] && [ " ${ out_rc } " -ne 0 ]
if [ " ${ adb_action } " != "start" ] && [ " ${ adb_action } " != "resume" ] && [ -n " ${ src_name } " ] && [ " ${ out_rc } " != "0" ]
then
then
adb_sources = " ${ adb_sources / ${ src_name } } "
adb_sources = " ${ adb_sources / ${ src_name } } "
fi
fi
; ;
; ;
"remove" )
"remove" )
if [ " ${ adb_backup } " -eq 1 ]
if [ " ${ adb_backup } " = "1" ]
then
then
rm " ${ adb_backupdir } / ${ adb_dnsprefix } . ${ src_name } .gz " 2>/dev/null
rm " ${ adb_backupdir } / ${ adb_dnsprefix } . ${ src_name } .gz " 2>/dev/null
fi
fi
@ -885,13 +894,13 @@ f_list()
adb_sources = " ${ adb_sources / ${ src_name } } "
adb_sources = " ${ adb_sources / ${ src_name } } "
; ;
; ;
"merge" )
"merge" )
if [ " ${ adb_backup } " -eq 1 ]
if [ " ${ adb_backup } " = "1" ]
then
then
for src_name in ${ adb_sources }
for src_name in ${ adb_sources }
do
do
ffiles = " ${ ffiles } -a ! -name ${ adb_dnsprefix } . ${ src_name } .gz "
ffiles = " ${ ffiles } -a ! -name ${ adb_dnsprefix } . ${ src_name } .gz "
done
done
if [ " ${ adb_safesearch } " -eq 1 ] && [ " ${ adb_dnssafesearch } " != "0" ]
if [ " ${ adb_safesearch } " = "1" ] && [ " ${ adb_dnssafesearch } " != "0" ]
then
then
ffiles = " ${ ffiles } -a ! -name safesearch.google.gz "
ffiles = " ${ ffiles } -a ! -name safesearch.google.gz "
fi
fi
@ -944,7 +953,7 @@ f_tld()
" ${ adb_awk } " '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' " ${ source } " | \
" ${ adb_awk } " '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' " ${ source } " | \
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ temp_tld } "
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ temp_tld } "
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
mv -f " ${ temp_tld } " " ${ source } "
mv -f " ${ temp_tld } " " ${ source } "
cnt_tld = " $( wc -l 2>/dev/null < " ${ source } " ) "
cnt_tld = " $( wc -l 2>/dev/null < " ${ source } " ) "
@ -979,13 +988,8 @@ f_switch()
then
then
if [ " ${ mode } " = "suspend" ]
if [ " ${ mode } " = "suspend" ]
then
then
f_bgserv "stop"
f_dnsup
f_dnsup
fi
fi
if [ " ${ mode } " = "resume" ]
then
f_bgserv "start"
fi
f_jsnup " ${ mode } "
f_jsnup " ${ mode } "
f_log "info" " ${ mode } adblock processing "
f_log "info" " ${ mode } adblock processing "
fi
fi
@ -1000,7 +1004,7 @@ f_query()
if [ -z " ${ domain } " ] || [ " ${ domain } " = " ${ tld } " ]
if [ -z " ${ domain } " ] || [ " ${ domain } " = " ${ tld } " ]
then
then
printf "%s\\ n" "::: invalid input, please submit a single (sub-)domain :::"
printf "%s\n" "::: invalid input, please submit a single (sub-)domain :::"
else
else
case " ${ adb_dns } " in
case " ${ adb_dns } " in
"dnsmasq" )
"dnsmasq" )
@ -1030,48 +1034,45 @@ f_query()
; ;
; ;
esac
esac
query_start = " $( date "+%s" ) "
query_start = " $( date "+%s" ) "
if [ " ${ adb_dnsfilereset } " -eq 0 ]
then
while [ " ${ domain } " != " ${ tld } " ]
do
search = " ${ domain //[+*~% \$ & \" \' ]/ } "
search = " ${ search //./ \\ . } "
result = " $( " ${ adb_awk } " -F '/|\"|\t| ' " /^( ${ search } | ${ prefix } + ${ search } .* ${ suffix } ) $/{i++;if(i<=9){printf \" + %s\\n\",\$ ${ field } }else if(i==10){printf \" + %s\\n\",\"[...]\";exit}} " " ${ adb_dnsdir } / ${ adb_dnsfile } " ) "
printf "%s\\n%s\\n%s\\n" ":::" " ::: domain ' ${ domain } ' in active blocklist " ":::"
printf "%s\\n\\n" " ${ result :- " - no match" } "
domain = " ${ tld } "
tld = " ${ domain #*. } "
done
fi
if [ " ${ adb_backup } " -eq 1 ] && [ -d " ${ adb_backupdir } " ]
while [ " ${ domain } " != " ${ tld } " ]
do
search = " ${ domain //[+*~% \$ & \" \' ]/ } "
search = " ${ search //./ \\ . } "
result = " $( " ${ adb_awk } " -F '/|\"|\t| ' " /^( ${ search } | ${ prefix } + ${ search } .* ${ suffix } ) $/{i++;if(i<=9){printf \" + %s\n\",\$ ${ field } }else if(i==10){printf \" + %s\n\",\"[...]\";exit}} " " ${ adb_dnsdir } / ${ adb_dnsfile } " ) "
printf "%s\n%s\n%s\n" ":::" " ::: domain ' ${ domain } ' in active blocklist " ":::"
printf "%s\n\n" " ${ result :- " - no match" } "
domain = " ${ tld } "
tld = " ${ domain #*. } "
done
if [ " ${ adb_backup } " = "1" ] && [ -d " ${ adb_backupdir } " ]
then
then
search = " ${ 1 //[+*~% \$ & \" \' ]/ } "
search = " ${ 1 //[+*~% \$ & \" \' ]/ } "
search = " ${ search //./ \\ . } "
search = " ${ search //./ \\ . } "
printf "%s\\ n%s\ \n%s\ \n" ":::" " ::: domain ' ${ 1 } ' in backups and black-/whitelist " ":::"
printf "%s\n%s\n%s\n" ":::" " ::: domain ' ${ 1 } ' in backups and black-/whitelist " ":::"
for file in " ${ adb_backupdir } / ${ adb_dnsprefix } " .*.gz " ${ adb_blacklist } " " ${ adb_whitelist } "
for file in " ${ adb_backupdir } / ${ adb_dnsprefix } " .*.gz " ${ adb_blacklist } " " ${ adb_whitelist } "
do
do
suffix = " ${ file ##*. } "
suffix = " ${ file ##*. } "
if [ " ${ suffix } " = "gz" ]
if [ " ${ suffix } " = "gz" ]
then
then
zcat " ${ file } " 2>/dev/null | \
zcat " ${ file } " 2>/dev/null | \
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' | " ${ adb_awk } " -v f = " ${ file ##*/ } " " BEGIN{rc=1};/^( $search |.*\\. ${ search } ) $/{i++;if(i<=3){printf \" + %-30s%s\\ n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\ \n\",f,\"[...]\"}};END{exit rc} "
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' | " ${ adb_awk } " -v f = " ${ file ##*/ } " " BEGIN{rc=1};/^( $search |.*\\. ${ search } ) $/{i++;if(i<=3){printf \" + %-30s%s\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\n\",f,\"[...]\"}};END{exit rc} "
else
else
" ${ adb_awk } " -v f = " ${ file ##*/ } " " BEGIN{rc=1};/^( $search |.*\\. ${ search } ) $/{i++;if(i<=3){printf \" + %-30s%s\\ n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\ \n\",f,\"[...]\"}};END{exit rc} " " ${ file } "
" ${ adb_awk } " -v f = " ${ file ##*/ } " " BEGIN{rc=1};/^( $search |.*\\. ${ search } ) $/{i++;if(i<=3){printf \" + %-30s%s\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\n\",f,\"[...]\"}};END{exit rc} " " ${ file } "
fi
fi
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
result = "true"
result = "true"
query_end = " $( date "+%s" ) "
query_end = " $( date "+%s" ) "
if [ " $(( query_end-query_start)) " -gt " ${ query_timeout } " ]
if [ " $(( query_end-query_start)) " -gt " ${ query_timeout } " ]
then
then
printf "%s\\ n\ \n" " - [...]"
printf "%s\n\n" " - [...]"
break
break
fi
fi
fi
fi
done
done
if [ " ${ result } " != "true" ]
if [ " ${ result } " != "true" ]
then
then
printf "%s\\ n\ \n" " - no match"
printf "%s\n\n" " - no match"
fi
fi
fi
fi
fi
fi
@ -1106,8 +1107,7 @@ f_jsnup()
; ;
; ;
esac
esac
json_load_file " ${ adb_rtfile } " >/dev/null 2>& 1
json_load_file " ${ adb_rtfile } " >/dev/null 2>& 1
json_select "data" >/dev/null 2>& 1
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
if [ -z " ${ adb_fetchutil } " ] || [ -z " ${ adb_awk } " ]
if [ -z " ${ adb_fetchutil } " ] || [ -z " ${ adb_awk } " ]
then
then
@ -1128,7 +1128,6 @@ f_jsnup()
> " ${ adb_rtfile } "
> " ${ adb_rtfile } "
json_load_file " ${ adb_rtfile } " >/dev/null 2>& 1
json_load_file " ${ adb_rtfile } " >/dev/null 2>& 1
json_init
json_init
json_add_object "data"
json_add_string "adblock_status" " ${ status :- "enabled" } "
json_add_string "adblock_status" " ${ status :- "enabled" } "
json_add_string "adblock_version" " ${ adb_ver } "
json_add_string "adblock_version" " ${ adb_ver } "
json_add_string "blocked_domains" " ${ adb_cnt :- 0 } "
json_add_string "blocked_domains" " ${ adb_cnt :- 0 } "
@ -1144,13 +1143,12 @@ f_jsnup()
json_add_string "run_utils" " ${ utils :- "-" } "
json_add_string "run_utils" " ${ utils :- "-" } "
json_add_string "run_ifaces" " trigger: ${ adb_trigger :- "-" } , report: ${ adb_repiface :- "-" } "
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_directories" " base: ${ adb_tmpbase } , backup: ${ adb_backupdir } , report: ${ adb_reportdir } , jail: ${ adb_jaildir } "
json_add_string "run_flags" " backup: ${ adb_backup } , reset: ${ adb_dnsfilereset } , flush: ${ adb_dnsflush } , force: ${ adb_forcedns } , search: ${ adb_safesearch } , report: ${ adb_report } , mail: ${ adb_mail } , jail: ${ adb_jail } "
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 "last_run" " ${ runtime :- "-" } "
json_add_string "last_run" " ${ runtime :- "-" } "
json_add_string "system" " ${ adb_sysver } "
json_add_string "system" " ${ adb_sysver } "
json_close_object
json_dump > " ${ adb_rtfile } "
json_dump > " ${ adb_rtfile } "
if [ " ${ adb_mail } " -eq 1 ] && [ -x " ${ adb_mailservice } " ] && \
if [ " ${ adb_mail } " = "1" ] && [ -x " ${ adb_mailservice } " ] && \
{ [ " ${ status } " = "error" ] || { [ " ${ status } " = "enabled" ] && [ " ${ adb_cnt } " -le " ${ adb_mailcnt } " ] ; } }
{ [ " ${ status } " = "error" ] || { [ " ${ status } " = "enabled" ] && [ " ${ adb_cnt } " -le " ${ adb_mailcnt } " ] ; } }
then
then
( " ${ adb_mailservice } " " ${ adb_ver } " >/dev/null 2>& 1 ) &
( " ${ adb_mailservice } " " ${ adb_ver } " >/dev/null 2>& 1 ) &
@ -1165,42 +1163,23 @@ f_log()
{
{
local class = " ${ 1 } " log_msg = " ${ 2 } "
local class = " ${ 1 } " log_msg = " ${ 2 } "
if [ -n " ${ log_msg } " ] && { [ " ${ class } " != "debug" ] || [ " ${ adb_debug } " -eq 1 ] ; }
if [ -n " ${ log_msg } " ] && { [ " ${ class } " != "debug" ] || [ " ${ adb_debug } " = "1" ] ; }
then
then
if [ -x " ${ adb_loggercmd } " ]
if [ -x " ${ adb_loggercmd } " ]
then
then
" ${ adb_loggercmd } " -p " ${ class } " -t " adblock- ${ adb_ver } [ ${ $} ] " " ${ log_msg } "
" ${ adb_loggercmd } " -p " ${ class } " -t " adblock- ${ adb_ver } [ ${ $} ] " " ${ log_msg } "
else
else
printf "%s %s %s\\ n" " ${ class } " " adblock- ${ adb_ver } [ ${ $} ] " " ${ log_msg } "
printf "%s %s %s\n" " ${ class } " " adblock- ${ adb_ver } [ ${ $} ] " " ${ log_msg } "
fi
fi
if [ " ${ class } " = "err" ]
if [ " ${ class } " = "err" ]
then
then
f_rmdns
f_rmdns
f_bgserv "stop"
f_jsnup "error"
f_jsnup "error"
exit 1
exit 1
fi
fi
fi
fi
}
}
# start ubus monitor service to trace dns backend events
#
f_bgserv( )
{
local bg_pid status = " ${ 1 } "
bg_pid = " $( pgrep -f " ^/bin/sh ${ adb_ubusservice } .*|^/bin/ubus -S -M r -m invoke monitor|^grep -qF \"method\":\"set\",\"data\":\\{\"name\":\" ${ adb_dns } \" " | " ${ adb_awk } " '{ORS=" "; print $1}' ) "
if [ " ${ adb_dns } " != "raw" ] && [ -z " ${ bg_pid } " ] && [ " ${ status } " = "start" ] \
&& [ -x " ${ adb_ubusservice } " ] && [ " ${ adb_dnsfilereset } " -eq 1 ]
then
( " ${ adb_ubusservice } " " ${ adb_ver } " & )
elif [ -n " ${ bg_pid } " ] && [ " ${ status } " = "stop" ]
then
kill -HUP " ${ bg_pid } " 2>/dev/null
fi
f_log "debug" " f_bgserv ::: status: ${ status :- "-" } , bg_pid: ${ bg_pid :- "-" } , dns_filereset: ${ adb_dnsfilereset :- "-" } , ubus_service: ${ adb_ubusservice :- "-" } "
}
# main function for blocklist processing
# main function for blocklist processing
#
#
f_main( )
f_main( )
@ -1219,7 +1198,7 @@ f_main()
# safe search preparation
# safe search preparation
#
#
if [ " ${ adb_safesearch } " -eq 1 ] && [ " ${ adb_dnssafesearch } " != "0" ]
if [ " ${ adb_safesearch } " = "1" ] && [ " ${ adb_dnssafesearch } " != "0" ]
then
then
if [ -z " ${ adb_safesearchlist } " ]
if [ -z " ${ adb_safesearchlist } " ]
then
then
@ -1237,15 +1216,15 @@ f_main()
for src_name in ${ adb_sources }
for src_name in ${ adb_sources }
do
do
json_select " ${ src_name } " >/dev/null 2>& 1
json_select " ${ src_name } " >/dev/null 2>& 1
if [ " ${ ? } " -ne 0 ]
if [ " ${ ? } " != "0" ]
then
then
adb_sources = " ${ adb_sources / ${ src_name } } "
adb_sources = " ${ adb_sources / ${ src_name } } "
continue
continue
fi
fi
json_get_var src_url "url" >/dev/null 2>& 1
json_get_var src_url "url" >/dev/null 2>& 1
json_get_var src_rset "rule" >/dev/null 2>& 1
json_get_var src_rset "rule" >/dev/null 2>& 1
json_get_values src_cat "categories" >/dev/null 2>& 1
json_select ..
json_select ..
src_tmpcat = " ${ adb_tmpload } . ${ src_name } .cat "
src_tmpload = " ${ adb_tmpload } . ${ src_name } .load "
src_tmpload = " ${ adb_tmpload } . ${ src_name } .load "
src_tmpsort = " ${ adb_tmpload } . ${ src_name } .sort "
src_tmpsort = " ${ adb_tmpload } . ${ src_name } .sort "
src_tmpfile = " ${ adb_tmpfile } . ${ src_name } "
src_tmpfile = " ${ adb_tmpfile } . ${ src_name } "
@ -1261,10 +1240,10 @@ f_main()
# backup mode
# backup mode
#
#
if [ " ${ adb_backup } " -eq 1 ] && { [ " ${ adb_action } " = "start" ] || [ " ${ adb_action } " = "resume" ] ; }
if [ " ${ adb_backup } " = "1" ] && { [ " ${ adb_action } " = "start" ] || [ " ${ adb_action } " = "resume" ] ; }
then
then
f_list restore
f_list restore
if [ " ${ ? } " -eq 0 ] && [ -s " ${ src_tmpfile } " ]
if [ " ${ ? } " = "0" ] && [ -s " ${ src_tmpfile } " ]
then
then
continue
continue
fi
fi
@ -1272,70 +1251,104 @@ f_main()
# download queue processing
# download queue processing
#
#
if [ -n " ${ src_cat } " ]
unset src_cat src_entries
if [ " ${ src_name } " = "shallalist" ] || [ " ${ src_name } " = "utcapitole" ]
then
then
(
src_arc = " ${ adb_tmpdir } / ${ src_url ##*/ } "
src_log = " $( " ${ adb_fetchutil } " ${ adb_fetchparm } " ${ src_arc } " " ${ src_url } " 2>& 1) "
src_rc = " ${ ? } "
if [ " ${ src_rc } " -eq 0 ] && [ -s " ${ src_arc } " ]
then
unset src_entries
src_suffix = " $( eval printf "%s" \" \$ \{ adb_src_suffix_${ src_name } :-\" domains\" \} \" ) "
src_list = " $( tar -tzf " ${ src_arc } " 2>/dev/null) "
for src_item in ${ src_cat }
do
src_entries = " ${ src_entries } $( printf "%s" " ${ src_list } " | grep -E " ${ src_item } / ${ src_suffix } $" ) "
done
if [ -n " ${ src_entries } " ]
then
tar -xOzf " ${ src_arc } " ${ src_entries } 2>/dev/null > " ${ src_tmpload } "
src_rc = " ${ ? } "
fi
rm -f " ${ src_arc } "
else
src_log = " $( printf "%s" " ${ src_log } " | " ${ adb_awk } " '{ORS=" ";print $0}' ) "
f_log "info" " download of ' ${ src_name } ' failed, url: ${ src_url } , rule: ${ src_rset :- "-" } , categories: ${ src_cat :- "-" } , rc: ${ src_rc } , log: ${ src_log :- "-" } "
fi
if [ " ${ src_rc } " -eq 0 ] && [ -s " ${ src_tmpload } " ]
then
if [ -s " ${ adb_tmpdir } /tmp.rem.whitelist " ]
if [ " ${ src_name } " = "shallalist" ] && [ -n " ${ adb_sha_sources } " ]
then
src_cat = " ${ adb_sha_sources } "
elif [ " ${ src_name } " = "utcapitole" ] && [ -n " ${ adb_utc_sources } " ]
then
src_cat = " ${ adb_utc_sources } "
fi
if [ -n " ${ src_cat } " ]
then
(
src_arc = " ${ adb_tmpdir } / ${ src_url ##*/ } "
src_log = " $( " ${ adb_fetchutil } " ${ adb_fetchparm } " ${ src_arc } " " ${ src_url } " 2>& 1) "
src_rc = " ${ ? } "
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_arc } " ]
then
then
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
grep -Evf " ${ adb_tmpdir } /tmp.rem.whitelist " | " ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
src_suffix = " $( eval printf "%s" \" \$ \{ adb_src_suffix_${ src_name } :-\" domains\" \} \" ) "
src_list = " $( tar -tzf " ${ src_arc } " 2>/dev/null) "
for src_item in ${ src_cat }
do
src_entries = " ${ src_entries } $( printf "%s" " ${ src_list } " | grep -E " ${ src_item } / ${ src_suffix } $" ) "
done
if [ -n " ${ src_entries } " ]
then
tar -xOzf " ${ src_arc } " ${ src_entries } 2>/dev/null > " ${ src_tmpload } "
src_rc = " ${ ? } "
fi
> " ${ src_arc } "
else
else
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
src_log = " $( printf "%s" " ${ src_log } " | "${ adb_awk } " '{ORS=" ";print $0}' ) "
f_log "info" " download of ' ${ src_name } ' failed, url: ${ src_url } , rule: ${ src_rset :- "-" } , categories: ${ src_cat :- "-" } , rc: ${ src_rc } , log: ${ src_log :- "-" } "
fi
fi
rm -f " ${ src_tmpload } "
" ${ adb_sort } " ${ adb_srtopts } -u " ${ src_tmpsort } " 2>/dev/null > " ${ src_tmpfile } "
src_rc = " ${ ? } "
rm -f " ${ src_tmpsort } "
if [ " ${ src_rc } " -eq 0 ] && [ -s " ${ src_tmpfile } " ]
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_tmpload } " ]
then
then
f_list download
if [ " ${ adb_backup } " -eq 1 ]
if [ -s " ${ adb_tmpdir } /tmp.rem.whitelist " ]
then
then
f_list backup
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
grep -Evf " ${ adb_tmpdir } /tmp.rem.whitelist " | " ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
else
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
fi
fi
elif [ " ${ adb_backup } " -eq 1 ] && [ " ${ adb_action } " != "start" ]
> " ${ src_tmpload } "
" ${ adb_sort } " ${ adb_srtopts } -u " ${ src_tmpsort } " 2>/dev/null > " ${ src_tmpfile } "
src_rc = " ${ ? } "
> " ${ src_tmpsort } "
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_tmpfile } " ]
then
f_list download
if [ " ${ adb_backup } " = "1" ]
then
f_list backup
fi
elif [ " ${ adb_backup } " = "1" ] && [ " ${ adb_action } " != "start" ]
then
f_log "info" " archive preparation of ' ${ src_name } ' failed, categories: ${ src_cat :- "-" } , entries: ${ src_entries } , rc: ${ src_rc } "
f_list restore
rm -f " ${ src_tmpfile } "
fi
elif [ " ${ adb_backup } " = "1" ] && [ " ${ adb_action } " != "start" ]
then
then
f_log "info" " archive preparation of ' ${ src_name } ' failed, categories: ${ src_cat :- "-" } , entries: ${ src_entries } , rc: ${ src_rc } "
f_log "info" " archive extrac tion of ' ${ src_name } ' failed, categories: ${ src_cat :- "-" } , entries: ${ src_entries } , rc: ${ src_rc } "
f_list restore
f_list restore
rm -f " ${ src_tmpfile } "
fi
fi
elif [ " ${ adb_backup } " -eq 1 ] && [ " ${ adb_action } " != "start" ]
then
f_log "info" " archive extraction of ' ${ src_name } ' failed, categories: ${ src_cat :- "-" } , entries: ${ src_entries } , rc: ${ src_rc } "
f_list restore
fi
) &
continue
) &
fi
else
else
if [ " ${ src_name } " = "energized" ] && [ -n " ${ adb_eng_sources } " ]
then
src_cat = " ${ adb_eng_sources } "
elif [ " ${ src_name } " = "stevenblack" ] && [ -n " ${ adb_stb_sources } " ]
then
src_cat = " ${ adb_stb_sources } "
elif { [ " ${ src_name } " = "energized" ] && [ -z " ${ adb_eng_sources } " ] ; } || \
{ [ " ${ src_name } " = "stevenblack" ] && [ -z " ${ adb_stb_sources } " ] ; }
then
continue
fi
(
(
src_log = " $( " ${ adb_fetchutil } " ${ adb_fetchparm } " ${ src_tmpload } " " ${ src_url } " 2>& 1) "
src_rc = " ${ ? } "
if [ " ${ src_rc } " -eq 0 ] && [ -s " ${ src_tmpload } " ]
for suffix in ${ src_cat :- ${ src_url } }
do
if [ " ${ src_url } " != " ${ suffix } " ]
then
src_log = " $( " ${ adb_fetchutil } " ${ adb_fetchparm } " ${ src_tmpcat } " " ${ src_url } ${ suffix } " 2>& 1) "
src_rc = " ${ ? } "
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_tmpcat } " ]
then
cat " ${ src_tmpcat } " >> " ${ src_tmpload } "
> " ${ src_tmpcat } "
fi
else
src_log = " $( " ${ adb_fetchutil } " ${ adb_fetchparm } " ${ src_tmpload } " " ${ src_url } " 2>& 1) "
src_rc = " ${ ? } "
fi
done
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_tmpload } " ]
then
then
if [ -s " ${ adb_tmpdir } /tmp.rem.whitelist " ]
if [ -s " ${ adb_tmpdir } /tmp.rem.whitelist " ]
then
then
@ -1345,18 +1358,18 @@ f_main()
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
" ${ adb_awk } " " ${ src_rset } " " ${ src_tmpload } " | sed "s/\r//g" | \
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
" ${ adb_awk } " 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > " ${ src_tmpsort } "
fi
fi
rm -f " ${ src_tmpload } "
> " ${ src_tmpload } "
" ${ adb_sort } " ${ adb_srtopts } -u " ${ src_tmpsort } " 2>/dev/null > " ${ src_tmpfile } "
" ${ adb_sort } " ${ adb_srtopts } -u " ${ src_tmpsort } " 2>/dev/null > " ${ src_tmpfile } "
src_rc = " ${ ? } "
src_rc = " ${ ? } "
rm -f " ${ src_tmpsort } "
if [ " ${ src_rc } " -eq 0 ] && [ -s " ${ src_tmpfile } " ]
> " ${ src_tmpsort } "
if [ " ${ src_rc } " = "0" ] && [ -s " ${ src_tmpfile } " ]
then
then
f_list download
f_list download
if [ " ${ adb_backup } " -eq 1 ]
if [ " ${ adb_backup } " = "1" ]
then
then
f_list backup
f_list backup
fi
fi
elif [ " ${ adb_backup } " -eq 1 ] && [ " ${ adb_action } " != "start" ]
elif [ " ${ adb_backup } " = "1" ] && [ " ${ adb_action } " != "start" ]
then
then
f_log "info" " preparation of ' ${ src_name } ' failed, rc: ${ src_rc } "
f_log "info" " preparation of ' ${ src_name } ' failed, rc: ${ src_rc } "
f_list restore
f_list restore
@ -1365,7 +1378,7 @@ f_main()
else
else
src_log = " $( printf "%s" " ${ src_log } " | " ${ adb_awk } " '{ORS=" ";print $0}' ) "
src_log = " $( printf "%s" " ${ src_log } " | " ${ adb_awk } " '{ORS=" ";print $0}' ) "
f_log "info" " download of ' ${ src_name } ' failed, url: ${ src_url } , rule: ${ src_rset :- "-" } , categories: ${ src_cat :- "-" } , rc: ${ src_rc } , log: ${ src_log :- "-" } "
f_log "info" " download of ' ${ src_name } ' failed, url: ${ src_url } , rule: ${ src_rset :- "-" } , categories: ${ src_cat :- "-" } , rc: ${ src_rc } , log: ${ src_log :- "-" } "
if [ " ${ adb_backup } " -eq 1 ] && [ " ${ adb_action } " != "start" ]
if [ " ${ adb_backup } " = "1" ] && [ " ${ adb_action } " != "start" ]
then
then
f_list restore
f_list restore
fi
fi
@ -1373,7 +1386,7 @@ f_main()
) &
) &
fi
fi
hold = $(( cnt%adb_maxqueue))
hold = $(( cnt%adb_maxqueue))
if [ " ${ hold } " -eq 0 ]
if [ " ${ hold } " = "0" ]
then
then
wait
wait
fi
fi
@ -1384,7 +1397,7 @@ f_main()
# tld compression and dns restart
# tld compression and dns restart
#
#
if [ " ${ ? } " -eq 0 ] && [ -s " ${ adb_tmpdir } / ${ adb_dnsfile } " ]
if [ " ${ ? } " = "0" ] && [ -s " ${ adb_tmpdir } / ${ adb_dnsfile } " ]
then
then
f_tld " ${ adb_tmpdir } / ${ adb_dnsfile } "
f_tld " ${ adb_tmpdir } / ${ adb_dnsfile } "
f_list final
f_list final
@ -1393,20 +1406,13 @@ f_main()
fi
fi
chown " ${ adb_dnsuser } " " ${ adb_dnsdir } / ${ adb_dnsfile } " 2>/dev/null
chown " ${ adb_dnsuser } " " ${ adb_dnsdir } / ${ adb_dnsfile } " 2>/dev/null
f_dnsup
f_dnsup
if [ " ${ ? } " -eq 0 ]
if [ " ${ ? } " = "0" ]
then
then
if [ " ${ adb_action } " != "resume" ]
if [ " ${ adb_action } " != "resume" ]
then
then
f_jsnup "enabled"
f_jsnup "enabled"
fi
fi
if [ " ${ adb_dns } " != "raw" ] && [ " ${ adb_dnsfilereset } " -eq 1 ]
then
printf " ${ adb_dnsheader } " > " ${ adb_dnsdir } / ${ adb_dnsfile } "
f_log "info" " blocklist with overall ${ adb_cnt } blocked domains loaded successfully and reset afterwards ( ${ adb_sysver } ) "
f_bgserv "start"
else
f_log "info" " blocklist with overall ${ adb_cnt } blocked domains loaded successfully ( ${ adb_sysver } ) "
fi
f_log "info" " blocklist with overall ${ adb_cnt } blocked domains loaded successfully ( ${ adb_sysver } ) "
else
else
f_log "err" "dns backend restart with adblock blocklist failed"
f_log "err" "dns backend restart with adblock blocklist failed"
fi
fi
@ -1419,10 +1425,10 @@ f_report()
{
{
local iface bg_pid status total start end blocked percent top_list top array item index hold ports cnt = 0 search = " ${ 1 } " count = " ${ 2 } " process = " ${ 3 } " print = " ${ 4 } "
local iface bg_pid status total start end blocked percent top_list top array item index hold ports cnt = 0 search = " ${ 1 } " count = " ${ 2 } " process = " ${ 3 } " print = " ${ 4 } "
if [ " ${ adb_report } " -eq 1 ] && [ ! -x " ${ adb_dumpcmd } " ]
if [ " ${ adb_report } " = "1" ] && [ ! -x " ${ adb_dumpcmd } " ]
then
then
f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature"
f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature"
elif [ " ${ adb_report } " -eq 0 ] && [ " ${ adb_action } " = "report" ]
elif [ " ${ adb_report } " = "0" ] && [ " ${ adb_action } " = "report" ]
then
then
f_log "info" "Please enable the 'DNS Report' option to use the reporting feature"
f_log "info" "Please enable the 'DNS Report' option to use the reporting feature"
fi
fi
@ -1430,7 +1436,7 @@ f_report()
if [ -x " ${ adb_dumpcmd } " ]
if [ -x " ${ adb_dumpcmd } " ]
then
then
bg_pid = " $( pgrep -f " ^ ${ adb_dumpcmd } .*adb_report\\.pcap $" | " ${ adb_awk } " '{ORS=" "; print $1}' ) "
bg_pid = " $( pgrep -f " ^ ${ adb_dumpcmd } .*adb_report\\.pcap $" | " ${ adb_awk } " '{ORS=" "; print $1}' ) "
if [ " ${ adb_report } " -eq 0 ] || { [ -n " ${ bg_pid } " ] && { [ " ${ adb_action } " = "stop" ] || [ " ${ adb_action } " = "restart" ] ; } }
if [ " ${ adb_report } " = "0" ] || { [ -n " ${ bg_pid } " ] && { [ " ${ adb_action } " = "stop" ] || [ " ${ adb_action } " = "restart" ] ; } }
then
then
if [ -n " ${ bg_pid } " ]
if [ -n " ${ bg_pid } " ]
then
then
@ -1444,7 +1450,7 @@ f_report()
fi
fi
fi
fi
if [ -x " ${ adb_dumpcmd } " ] && [ " ${ adb_report } " -eq 1 ]
if [ -x " ${ adb_dumpcmd } " ] && [ " ${ adb_report } " = "1" ]
then
then
if [ -z " ${ bg_pid } " ] && [ " ${ adb_action } " != "report" ] && [ " ${ adb_action } " != "stop" ]
if [ -z " ${ bg_pid } " ] && [ " ${ adb_action } " != "report" ] && [ " ${ adb_action } " != "stop" ]
then
then
@ -1501,7 +1507,7 @@ f_report()
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) ; gsub( /[ ^[ :alnum:] \. -] /,"" ,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 "
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) ; gsub( /[ ^[ :alnum:] \. -] /,"" ,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))
hold = $(( cnt%adb_maxqueue))
if [ " ${ hold } " -eq 0 ]
if [ " ${ hold } " = "0" ]
then
then
wait
wait
fi
fi
@ -1524,38 +1530,38 @@ f_report()
blocked = " $( " ${ adb_awk } " '{if($5=="NX")cnt++}END{printf "%s",cnt}' " ${ adb_reportdir } /adb_report.srt " ) "
blocked = " $( " ${ adb_awk } " '{if($5=="NX")cnt++}END{printf "%s",cnt}' " ${ adb_reportdir } /adb_report.srt " ) "
percent = " $( " ${ adb_awk } " -v t = " ${ total } " -v b = " ${ blocked } " 'BEGIN{printf "%.2f%s",b/t*100,"%"}' ) "
percent = " $( " ${ adb_awk } " -v t = " ${ total } " -v b = " ${ blocked } " 'BEGIN{printf "%.2f%s",b/t*100,"%"}' ) "
> " ${ adb_reportdir } /adb_report.json "
> " ${ adb_reportdir } /adb_report.json "
printf "%s" "{ \"data\": { " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"start_date\": \" ${ start %_* } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"start_time\": \" ${ start #*_ } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"end_date\": \" ${ end %_* } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"end_time\": \" ${ end #*_ } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"total\": \" ${ total } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"blocked\": \" ${ blocked } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s" " \"percent\": \" ${ percent } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "%s\n " "{ " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"start_date\": \" ${ start %_* } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"start_time\": \" ${ start #*_ } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"end_date\": \" ${ end %_* } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"end_time\": \" ${ end #*_ } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"total\": \" ${ total } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"blocked\": \" ${ blocked } \", " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s\n " " \"percent\": \" ${ percent } \", " >> " ${ adb_reportdir } /adb_report.json "
top_list = "top_clients top_domains top_blocked"
top_list = "top_clients top_domains top_blocked"
for top in ${ top_list }
for top in ${ top_list }
do
do
printf "%s" " \"${ top } \": [ " >> " ${ adb_reportdir } /adb_report.json "
printf "\t %s" " \" ${ top } \": [ " >> " ${ adb_reportdir } /adb_report.json "
case " ${ top } " in
case " ${ top } " in
"top_clients" )
"top_clients" )
" ${ adb_awk } " '{print $3}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_awk } " '{print $3}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
; ;
; ;
"top_domains" )
"top_domains" )
" ${ adb_awk } " '{if($5!="NX")print $4}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_awk } " '{if($5!="NX")print $4}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
; ;
; ;
"top_blocked" )
"top_blocked" )
" ${ adb_awk } " '{if($5=="NX")print $4}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_awk } " '{if($5=="NX")print $4}' " ${ adb_reportdir } /adb_report.srt " | " ${ adb_sort } " ${ adb_srtopts } | uniq -c | \
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
" ${ adb_sort } " ${ adb_srtopts } -nr | " ${ adb_awk } " '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t }",$1,$2}' >> " ${ adb_reportdir } /adb_report.json "
; ;
; ;
esac
esac
printf "%s" " ], " >> " ${ adb_reportdir } /adb_report.json "
printf "\n\t %s\n " "]," >> " ${ adb_reportdir } /adb_report.json "
done
done
search = " ${ search //./ \\ . } "
search = " ${ search //./ \\ . } "
search = " ${ search //[+*~% \$ & \" \' ]/ } "
search = " ${ search //[+*~% \$ & \" \' ]/ } "
" ${ adb_awk } " " BEGIN{i=0;printf \"\\\"requests\\\": [ \" }/( ${ search } )/{i++;if(i==1)printf \"{ \\\"date\\\": \\\"%s\\\", \\\"time\\\": \\\"%s\\\", \\\"client\\\": \\\"%s\\\", \\\"domain\\\": \\\"%s\\\", \\\"rc\\\": \\\"%s\\\" }\",\$1,\$2,\$3,\$4,\$5;else if(i<= ${ count } )printf \", { \\\"date\\\": \\\"%s\\\", \\\"time\\\": \\\"%s\\\", \\\"client\\\": \\\"%s\\\", \\\"domain\\\": \\\"%s\\\", \\\"rc\\\": \\\"%s\\\" }\",\$1,\$2,\$3,\$4,\$5}END{printf \" ] } }\n\"} " " ${ adb_reportdir } /adb_report.srt " >> " ${ adb_reportdir } /adb_report.json "
" ${ adb_awk } " " BEGIN{i=0;printf \"\t\\\"requests\\\": [\n\" }/( ${ search } )/{i++;if(i==1)printf \"\n\t\t{\n\t\t\t\\\"date\\\": \\\"%s\\\",\n\t\t\t\\\"time\\\": \\\"%s\\\",\n\t\t\t\\\"client\\\": \\\"%s\\\",\n\t\t\t\\\"domain\\\": \\\"%s\\\",\n\t\t\t\\\"rc\\\": \\\"%s\\\"\n\t\t }\",\$1,\$2,\$3,\$4,\$5;else if(i<= ${ count } )printf \",\n\t\t{\n\t\t\t\\\"date\\\": \\\"%s\\\",\n\t\t\t\\\"time\\\": \\\"%s\\\",\n\t\t\t\\\"client\\\": \\\"%s\\\",\n\t\t\t\\\"domain\\\": \\\"%s\\\",\n\t\t\t\\\"rc\\\": \\\"%s\\\"\n\t\t}\",\$1,\$2,\$3,\$4,\$5}END{printf \"\n\t]\n }\n\"} " " ${ adb_reportdir } /adb_report.srt " >> " ${ adb_reportdir } /adb_report.json "
rm -f " ${ adb_reportdir } /adb_report.srt "
rm -f " ${ adb_reportdir } /adb_report.srt "
fi
fi
fi
fi
@ -1564,17 +1570,16 @@ f_report()
then
then
if [ " ${ print } " = "cli" ]
if [ " ${ print } " = "cli" ]
then
then
printf "%s\\ n%s\ \n%s\ \n" ":::" "::: Adblock DNS-Query Report" ":::"
printf "%s\n%s\n%s\n" ":::" "::: Adblock DNS-Query Report" ":::"
json_load_file " ${ adb_reportdir } /adb_report.json "
json_load_file " ${ adb_reportdir } /adb_report.json "
json_select "data"
json_get_keys keylist
json_get_keys keylist
for key in ${ keylist }
for key in ${ keylist }
do
do
json_get_var value " ${ key } "
json_get_var value " ${ key } "
eval " ${ key } =\" ${ value } \" "
eval " ${ key } =\" ${ value } \" "
done
done
printf " + %s\\ n + %s\ \n" " Start ::: ${ start_date } , ${ start_time } " " End ::: ${ end_date } , ${ end_time } "
printf " + %s\\ n + %s %s\ \n" " Total ::: ${ total } " " Blocked ::: ${ blocked } " " ( ${ percent } ) "
printf " + %s\n + %s\n" " Start ::: ${ start_date } , ${ start_time } " " End ::: ${ end_date } , ${ end_time } "
printf " + %s\n + %s %s\n" " Total ::: ${ total } " " Blocked ::: ${ blocked } " " ( ${ percent } ) "
top_list = "top_clients top_domains top_blocked requests"
top_list = "top_clients top_domains top_blocked requests"
for top in ${ top_list }
for top in ${ top_list }
@ -1592,25 +1597,25 @@ f_report()
esac
esac
if json_get_type status " ${ top } " && [ " ${ top } " != "requests" ] && [ " ${ status } " = "array" ]
if json_get_type status " ${ top } " && [ " ${ top } " != "requests" ] && [ " ${ status } " = "array" ]
then
then
printf "%s\\ n%s\ \n%s\ \n" ":::" " ${ item } " ":::"
printf "%s\n%s\n%s\n" ":::" " ${ item } " ":::"
json_select " ${ top } "
json_select " ${ top } "
index = 1
index = 1
while json_get_type status " ${ index } " && [ " ${ status } " = "object" ]
while json_get_type status " ${ index } " && [ " ${ status } " = "object" ]
do
do
json_get_values item " ${ index } "
json_get_values item " ${ index } "
printf " + %-9s::: %s\\ n" ${ item }
printf " + %-9s::: %s\n" ${ item }
index = $(( index+1))
index = $(( index+1))
done
done
elif json_get_type status " ${ top } " && [ " ${ top } " = "requests" ] && [ " ${ status } " = "array" ]
elif json_get_type status " ${ top } " && [ " ${ top } " = "requests" ] && [ " ${ status } " = "array" ]
then
then
printf "%s\\ n%s\ \n%s\ \n" ":::" "::: Latest DNS Queries" ":::"
printf "%-15s%-15s%-45s%-80s%s\\ n" "Date" "Time" "Client" "Domain" "Answer"
printf "%s\n%s\n%s\n" ":::" "::: Latest DNS Queries" ":::"
printf "%-15s%-15s%-45s%-80s%s\n" "Date" "Time" "Client" "Domain" "Answer"
json_select " ${ top } "
json_select " ${ top } "
index = 1
index = 1
while json_get_type status " ${ index } " && [ " ${ status } " = "object" ]
while json_get_type status " ${ index } " && [ " ${ status } " = "object" ]
do
do
json_get_values item " ${ index } "
json_get_values item " ${ index } "
printf "%-15s%-15s%-45s%-80s%s\\ n" ${ item }
printf "%-15s%-15s%-45s%-80s%s\n" ${ item }
index = $(( index+1))
index = $(( index+1))
done
done
fi
fi
@ -1650,7 +1655,7 @@ fi
# sort selection
# sort selection
#
#
adb_sort = " $( command -v gnu-sort ) "
adb_sort = " $( command -v /usr/libexec/sort-coreutils ) "
if [ -z " ${ adb_sort } " ]
if [ -z " ${ adb_sort } " ]
then
then
adb_sort = " $( command -v sort) "
adb_sort = " $( command -v sort) "
@ -1673,12 +1678,10 @@ fi
f_load
f_load
case " ${ adb_action } " in
case " ${ adb_action } " in
"stop" )
"stop" )
f_bgserv "stop"
f_report "+" "50" "false" "false"
f_report "+" "50" "false" "false"
f_rmdns
f_rmdns
; ;
; ;
"restart" )
"restart" )
f_bgserv "stop"
f_report "+" "50" "false" "false"
f_report "+" "50" "false" "false"
f_rmdns
f_rmdns
f_env
f_env
@ -1703,7 +1706,6 @@ case "${adb_action}" in
f_query " ${ 2 } "
f_query " ${ 2 } "
; ;
; ;
"start" | "reload" )
"start" | "reload" )
f_bgserv "stop"
f_report "+" "50" "false" "false"
f_report "+" "50" "false" "false"
f_env
f_env
f_main
f_main