adblock: bugfix 2.0.1

* fixed a dnsmasq restart issue (udhcpc error)
* fixed a long standing corner case bug in "disabled" state (does not
remove active block lists!)
* simplified overall sort, removed needless 'for loop'
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
Dirk Brenken 2016-12-22 19:33:59 +01:00
parent 7eedce0a58
commit 708d83bc71
3 changed files with 20 additions and 19 deletions

View file

@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=adblock PKG_NAME:=adblock
PKG_VERSION:=2.0.0 PKG_VERSION:=2.0.1
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0+ PKG_LICENSE:=GPL-3.0+
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org> PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>

View file

@ -8,6 +8,7 @@ EXTRA_COMMANDS="suspend resume"
EXTRA_HELP=" suspend Suspend adblock processing EXTRA_HELP=" suspend Suspend adblock processing
resume Resume adblock processing" resume Resume adblock processing"
exec 2>/dev/null
adb_script="/usr/bin/adblock.sh" adb_script="/usr/bin/adblock.sh"
adb_iface="$(uci -q get adblock.global.adb_iface)" adb_iface="$(uci -q get adblock.global.adb_iface)"
@ -69,7 +70,6 @@ service_triggers()
local iface local iface
procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
if [ -z "${adb_iface}" ] if [ -z "${adb_iface}" ]
then then
procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start

View file

@ -10,7 +10,7 @@
# #
LC_ALL=C LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin" PATH="/usr/sbin:/usr/bin:/sbin:/bin"
adb_ver="2.0.0" adb_ver="2.0.1"
adb_enabled=1 adb_enabled=1
adb_debug=0 adb_debug=0
adb_whitelist="/etc/adblock/adblock.whitelist" adb_whitelist="/etc/adblock/adblock.whitelist"
@ -88,6 +88,11 @@ f_envcheck()
# #
if [ "${adb_enabled}" != "1" ] if [ "${adb_enabled}" != "1" ]
then then
if [ "$(ls -dA "${adb_dnsdir}/${adb_dnsprefix}"* >/dev/null 2>&1)" ]
then
f_rmdns
f_dnsrestart
fi
f_log "info " "status ::: adblock is currently disabled, please set adb_enabled to '1' to use this service" f_log "info " "status ::: adblock is currently disabled, please set adb_enabled to '1' to use this service"
exit 0 exit 0
fi fi
@ -153,18 +158,21 @@ f_dnsrestart()
dns_running="false" dns_running="false"
sync sync
"/etc/init.d/${adb_dns}" restart killall -q -TERM "${adb_dns}"
while [ ${cnt} -le 10 ] while [ ${cnt} -le 10 ]
do do
dns_running="$(ubus -S call service list '{"name":"dnsmasq"}' | jsonfilter -e '@.dnsmasq.instances.*.running')" dns_running="$(ubus -S call service list '{"name":"dnsmasq"}' | jsonfilter -e '@.dnsmasq.instances.*.running')"
if [ "${dns_running}" = "true" ] if [ "${dns_running}" = "true" ]
then then
sleep 1
break break
fi fi
cnt=$((cnt+1)) cnt=$((cnt+1))
sleep 1 sleep 1
done done
if [ "${dns_running}" = "false" ]
then
/etc/init.d/"${adb_dns}" restart
fi
} }
# f_list: backup/restore/remove block lists # f_list: backup/restore/remove block lists
@ -369,29 +377,22 @@ f_main()
f_log "debug" "loop ::: name: ${src_name}, list-rc: ${rc}" f_log "debug" "loop ::: name: ${src_name}, list-rc: ${rc}"
done done
# overall sort, make block list entries unique # make overall sort, restart & check dns server
# #
for list in $(ls -ASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null) for src_name in $(ls -dASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null)
do do
list="${list/*./}"
if [ -s "${adb_tmpdir}/blocklist.overall" ] if [ -s "${adb_tmpdir}/blocklist.overall" ]
then then
sort "${adb_tmpdir}/blocklist.overall" "${adb_tmpdir}/blocklist.overall" "${adb_dnsdir}/${adb_dnsprefix}.${list}" | uniq -u > "${adb_tmpdir}/tmp.blocklist" sort "${adb_tmpdir}/blocklist.overall" "${adb_tmpdir}/blocklist.overall" "${src_name}" | uniq -u > "${adb_tmpdir}/tmp.blocklist"
cat "${adb_tmpdir}/tmp.blocklist" > "${adb_dnsdir}/${adb_dnsprefix}.${list}" cat "${adb_tmpdir}/tmp.blocklist" > "${src_name}"
fi fi
cat "${adb_dnsdir}/${adb_dnsprefix}.${list}" >> "${adb_tmpdir}/blocklist.overall" cat "${src_name}" >> "${adb_tmpdir}/blocklist.overall"
done
# restart & check dns server
#
f_dnsrestart
if [ "${dns_running}" = "true" ]
then
for src_name in $(ls -ASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null)
do
cnt="$(wc -l < "${src_name}")" cnt="$(wc -l < "${src_name}")"
sum_cnt=$((sum_cnt + cnt)) sum_cnt=$((sum_cnt + cnt))
done done
f_dnsrestart
if [ "${dns_running}" = "true" ]
then
f_debug f_debug
f_rmtemp f_rmtemp
f_log "info " "status ::: block lists with overall ${sum_cnt} domains loaded (${adb_sysver})" f_log "info " "status ::: block lists with overall ${sum_cnt} domains loaded (${adb_sysver})"