adblock: update 2.3.1
* various optimizations & corner case fixes * removed no longer needed debug information * polished up for forthcoming LEDE release ;-) Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
5e4cd25103
commit
5cf40c94ee
3 changed files with 41 additions and 74 deletions
|
@ -6,8 +6,8 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=adblock
|
PKG_NAME:=adblock
|
||||||
PKG_VERSION:=2.3.0
|
PKG_VERSION:=2.3.1
|
||||||
PKG_RELEASE:=3
|
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>
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ adb_script="/usr/bin/adblock.sh"
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
local wanif4 wanif6 cnt=0
|
local wanif4 wanif6 cnt=0 max_cnt=30
|
||||||
|
|
||||||
. "/lib/functions/network.sh"
|
. "/lib/functions/network.sh"
|
||||||
while [ ${cnt} -le 30 ]
|
while [ ${cnt} -le ${max_cnt} ]
|
||||||
do
|
do
|
||||||
network_find_wan wanif4
|
network_find_wan wanif4
|
||||||
network_find_wan6 wanif6
|
network_find_wan6 wanif6
|
||||||
if [ -n "${wanif4}" ] || [ -n "${wanif6}" ] || [ ${cnt} -eq 30 ]
|
if [ -n "${wanif4}" ] || [ -n "${wanif6}" ] || [ ${cnt} -eq ${max_cnt} ]
|
||||||
then
|
then
|
||||||
rc_procd start_service
|
rc_procd start_service
|
||||||
return 0
|
return 0
|
||||||
|
@ -81,6 +81,8 @@ service_triggers()
|
||||||
{
|
{
|
||||||
local iface="$(uci -q get adblock.global.adb_iface)"
|
local iface="$(uci -q get adblock.global.adb_iface)"
|
||||||
|
|
||||||
|
procd_open_trigger
|
||||||
|
procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
|
||||||
if [ -z "${iface}" ]
|
if [ -z "${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
|
||||||
|
@ -90,6 +92,5 @@ service_triggers()
|
||||||
procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
|
procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
procd_close_trigger
|
||||||
procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.3.0-3"
|
adb_ver="2.3.1"
|
||||||
adb_enabled=1
|
adb_enabled=1
|
||||||
adb_debug=0
|
adb_debug=0
|
||||||
adb_backup=0
|
adb_backup=0
|
||||||
|
@ -34,7 +34,7 @@ f_envload()
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
else
|
else
|
||||||
f_log "error" "status ::: system library not found"
|
f_log "error" "system library not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set dns backend environment
|
# set dns backend environment
|
||||||
|
@ -69,7 +69,7 @@ f_envload()
|
||||||
done
|
done
|
||||||
if [ -z "${adb_dns}" ]
|
if [ -z "${adb_dns}" ]
|
||||||
then
|
then
|
||||||
f_log "error" "status ::: no active/supported DNS backend found"
|
f_log "error" "no active/supported DNS backend found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# parse global section by callback
|
# parse global section by callback
|
||||||
|
@ -125,7 +125,7 @@ f_envcheck()
|
||||||
f_rmdns
|
f_rmdns
|
||||||
f_dnsrestart
|
f_dnsrestart
|
||||||
fi
|
fi
|
||||||
f_log "info " "status ::: adblock is currently disabled, please set adb_enabled to '1' to use this service"
|
f_log "info " "adblock is currently disabled, please set adb_enabled to '1' to use this service"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ f_envcheck()
|
||||||
fi
|
fi
|
||||||
if [ -z "${adb_fetch}" ] || [ -z "${adb_fetchparm}" ] || [ ! -x "${adb_fetch}" ] || [ "$(readlink -fn "${adb_fetch}")" = "/bin/busybox" ]
|
if [ -z "${adb_fetch}" ] || [ -z "${adb_fetchparm}" ] || [ ! -x "${adb_fetch}" ] || [ "$(readlink -fn "${adb_fetch}")" = "/bin/busybox" ]
|
||||||
then
|
then
|
||||||
f_log "error" "status ::: required download utility with ssl support not found, e.g. install full 'wget' package"
|
f_log "error" "required download utility with ssl support not found, e.g. install full 'wget' package"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# create dns hideout directory
|
# create dns hideout directory
|
||||||
|
@ -192,38 +192,33 @@ f_rmdns()
|
||||||
f_dnsrestart()
|
f_dnsrestart()
|
||||||
{
|
{
|
||||||
local cnt=0
|
local cnt=0
|
||||||
adb_dnsup="false"
|
|
||||||
|
|
||||||
killall -q -TERM "${adb_dns}"
|
"/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
|
||||||
while [ ${cnt} -le 10 ]
|
while [ ${cnt} -le 10 ]
|
||||||
do
|
do
|
||||||
adb_dnsup="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" | jsonfilter -l1 -e "@.${adb_dns}.instances.*.running")"
|
adb_dnsup="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" | jsonfilter -l1 -e "@.${adb_dns}.instances.*.running")"
|
||||||
if [ "${adb_dnsup}" = "true" ]
|
if [ "${adb_dnsup}" = "true" ]
|
||||||
then
|
then
|
||||||
break
|
return 0
|
||||||
fi
|
fi
|
||||||
cnt=$((cnt+1))
|
cnt=$((cnt+1))
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
f_log "debug" "restart ::: dns: ${adb_dns}, dns-up: ${adb_dnsup}, count: ${cnt}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# f_list: backup/restore/remove block lists
|
# f_list: backup/restore/remove block lists
|
||||||
#
|
#
|
||||||
f_list()
|
f_list()
|
||||||
{
|
{
|
||||||
local mode="${1}"
|
local mode="${1}" in_rc="${adb_rc}" cnt=0
|
||||||
|
|
||||||
if [ ${adb_backup} -eq 0 ]
|
|
||||||
then
|
|
||||||
rc=0
|
|
||||||
fi
|
|
||||||
case "${mode}" in
|
case "${mode}" in
|
||||||
backup)
|
backup)
|
||||||
|
cnt="$(wc -l < "${adb_tmpfile}")"
|
||||||
if [ ${adb_backup} -eq 1 ] && [ -d "${adb_backupdir}" ]
|
if [ ${adb_backup} -eq 1 ] && [ -d "${adb_backupdir}" ]
|
||||||
then
|
then
|
||||||
gzip -cf "${adb_tmpfile}" > "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
|
gzip -cf "${adb_tmpfile}" > "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
restore)
|
restore)
|
||||||
|
@ -233,7 +228,7 @@ f_list()
|
||||||
if [ -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" ]
|
if [ -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" ]
|
||||||
then
|
then
|
||||||
gunzip -cf "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" > "${adb_tmpfile}"
|
gunzip -cf "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" > "${adb_tmpfile}"
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -243,10 +238,10 @@ f_list()
|
||||||
then
|
then
|
||||||
rm -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
|
rm -f "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz"
|
||||||
fi
|
fi
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
f_log "debug" "list ::: name: ${src_name}, mode: ${mode}, rc: ${rc}"
|
f_log "debug" "name: ${src_name}, mode: ${mode}, count: ${cnt}, in_rc: ${in_rc}, out_rc: ${adb_rc}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# f_switch: suspend/resume adblock processing
|
# f_switch: suspend/resume adblock processing
|
||||||
|
@ -274,7 +269,7 @@ f_switch()
|
||||||
then
|
then
|
||||||
mv -f "${source}"* "${target}"
|
mv -f "${source}"* "${target}"
|
||||||
f_dnsrestart
|
f_dnsrestart
|
||||||
f_log "info " "status ::: adblock processing ${status}"
|
f_log "info " "adblock processing ${status}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -317,8 +312,7 @@ f_query()
|
||||||
#
|
#
|
||||||
f_log()
|
f_log()
|
||||||
{
|
{
|
||||||
local class="${1}"
|
local class="${1}" log_msg="${2}"
|
||||||
local log_msg="${2}"
|
|
||||||
|
|
||||||
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${adb_debug} -eq 1 ])
|
if [ -n "${log_msg}" ] && ([ "${class}" != "debug" ] || [ ${adb_debug} -eq 1 ])
|
||||||
then
|
then
|
||||||
|
@ -333,40 +327,15 @@ f_log()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# f_debug: gather memory & space information
|
|
||||||
#
|
|
||||||
f_debug()
|
|
||||||
{
|
|
||||||
local mem_total=0 mem_free=0 mem_swap=0 tmp_space=0 backup_space=0
|
|
||||||
|
|
||||||
if [ ${adb_debug} -eq 1 ]
|
|
||||||
then
|
|
||||||
mem_total="$(awk '$1 ~ /^MemTotal/ {printf $2}' "/proc/meminfo")"
|
|
||||||
mem_free="$(awk '$1 ~ /^MemFree/ {printf $2}' "/proc/meminfo")"
|
|
||||||
mem_swap="$(awk '$1 ~ /^SwapTotal/ {printf $2}' "/proc/meminfo")"
|
|
||||||
f_log "debug" "memory ::: total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap}"
|
|
||||||
|
|
||||||
if [ -d "${adb_tmpdir}" ]
|
|
||||||
then
|
|
||||||
tmp_space="$(df "${adb_tmpdir}" 2>/dev/null | tail -n1 | awk '{printf $4}')"
|
|
||||||
fi
|
|
||||||
if [ -d "${adb_backupdir}" ]
|
|
||||||
then
|
|
||||||
backup_space="$(df "${adb_backupdir}" 2>/dev/null | tail -n1 | awk '{printf $4}')"
|
|
||||||
fi
|
|
||||||
f_log "debug" "space ::: tmp_dir: ${adb_tmpdir}, tmp_kb: ${tmp_space}, backup: ${adb_backup}, backup_dir: ${adb_backupdir}, backup_kb: ${backup_space}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# main function for block list processing
|
# main function for block list processing
|
||||||
#
|
#
|
||||||
f_main()
|
f_main()
|
||||||
{
|
{
|
||||||
local enabled url rc cnt sum_cnt=0
|
local enabled url cnt sum_cnt=0
|
||||||
local src_name src_rset shalla_file shalla_archive list active_lists
|
local src_name src_rset shalla_file shalla_archive list active_lists
|
||||||
local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
local sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
|
||||||
|
|
||||||
f_log "debug" "main ::: dns-backend: ${adb_dns}, fetch-tool: ${adb_fetch}, parm: ${adb_fetchparm}"
|
f_log "info " "start adblock processing ..."
|
||||||
for src_name in ${adb_sources}
|
for src_name in ${adb_sources}
|
||||||
do
|
do
|
||||||
eval "enabled=\"\${enabled_${src_name}}\""
|
eval "enabled=\"\${enabled_${src_name}}\""
|
||||||
|
@ -375,6 +344,7 @@ f_main()
|
||||||
adb_dnsfile="${adb_tmpdir}/${adb_dnsprefix}.${src_name}"
|
adb_dnsfile="${adb_tmpdir}/${adb_dnsprefix}.${src_name}"
|
||||||
> "${adb_tmpload}"
|
> "${adb_tmpload}"
|
||||||
> "${adb_tmpfile}"
|
> "${adb_tmpfile}"
|
||||||
|
adb_rc=0
|
||||||
|
|
||||||
# basic pre-checks
|
# basic pre-checks
|
||||||
#
|
#
|
||||||
|
@ -386,25 +356,25 @@ f_main()
|
||||||
|
|
||||||
# download block list
|
# download block list
|
||||||
#
|
#
|
||||||
f_log "debug" "loop_0 ::: name: ${src_name}, enabled: ${enabled}, dnsfile: ${adb_dnsfile}"
|
f_log "debug" "name: ${src_name}, enabled: ${enabled}, backup: ${adb_backup}, dns: ${adb_dns}, fetch: ${adb_fetch}"
|
||||||
if [ "${src_name}" = "blacklist" ]
|
if [ "${src_name}" = "blacklist" ]
|
||||||
then
|
then
|
||||||
cat "${url}" 2>/dev/null > "${adb_tmpload}"
|
cat "${url}" 2>/dev/null > "${adb_tmpload}"
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
elif [ "${src_name}" = "shalla" ]
|
elif [ "${src_name}" = "shalla" ]
|
||||||
then
|
then
|
||||||
shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
|
shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
|
||||||
shalla_file="${adb_tmpdir}/shallalist.txt"
|
shalla_file="${adb_tmpdir}/shallalist.txt"
|
||||||
"${adb_fetch}" ${adb_fetchparm} "${shalla_archive}" "${url}"
|
"${adb_fetch}" ${adb_fetchparm} "${shalla_archive}" "${url}" 2>/dev/null
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
if [ ${rc} -eq 0 ]
|
if [ ${adb_rc} -eq 0 ]
|
||||||
then
|
then
|
||||||
> "${shalla_file}"
|
> "${shalla_file}"
|
||||||
for category in ${adb_src_cat_shalla}
|
for category in ${adb_src_cat_shalla}
|
||||||
do
|
do
|
||||||
tar -xOzf "${shalla_archive}" BL/${category}/domains >> "${shalla_file}"
|
tar -xOzf "${shalla_archive}" BL/${category}/domains >> "${shalla_file}"
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
if [ ${rc} -ne 0 ]
|
if [ ${adb_rc} -ne 0 ]
|
||||||
then
|
then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
@ -415,14 +385,13 @@ f_main()
|
||||||
rm -f "${shalla_archive}"
|
rm -f "${shalla_archive}"
|
||||||
rm -rf "${adb_tmpdir}/BL"
|
rm -rf "${adb_tmpdir}/BL"
|
||||||
else
|
else
|
||||||
"${adb_fetch}" ${adb_fetchparm} "${adb_tmpload}" "${url}"
|
"${adb_fetch}" ${adb_fetchparm} "${adb_tmpload}" "${url}" 2>/dev/null
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
fi
|
fi
|
||||||
f_log "debug" "loop_1 ::: name: ${src_name}, rc: ${rc}"
|
|
||||||
|
|
||||||
# check download result and prepare domain output (incl. list backup/restore)
|
# check download result and prepare domain output (incl. list backup/restore)
|
||||||
#
|
#
|
||||||
if [ ${rc} -eq 0 ] && [ -s "${adb_tmpload}" ]
|
if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpload}" ]
|
||||||
then
|
then
|
||||||
awk "${src_rset}" "${adb_tmpload}" > "${adb_tmpfile}"
|
awk "${src_rset}" "${adb_tmpload}" > "${adb_tmpfile}"
|
||||||
if [ -s "${adb_tmpfile}" ]
|
if [ -s "${adb_tmpfile}" ]
|
||||||
|
@ -434,11 +403,10 @@ f_main()
|
||||||
else
|
else
|
||||||
f_list restore
|
f_list restore
|
||||||
fi
|
fi
|
||||||
f_log "debug" "loop_2 ::: name: ${src_name}, rc: ${rc}"
|
|
||||||
|
|
||||||
# remove whitelist domains, final list preparation
|
# remove whitelist domains, final list preparation
|
||||||
#
|
#
|
||||||
if [ ${rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
|
if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
|
||||||
then
|
then
|
||||||
if [ -s "${adb_tmpdir}/tmp.whitelist" ]
|
if [ -s "${adb_tmpdir}/tmp.whitelist" ]
|
||||||
then
|
then
|
||||||
|
@ -446,15 +414,14 @@ f_main()
|
||||||
else
|
else
|
||||||
sort -u "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
|
sort -u "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
|
||||||
fi
|
fi
|
||||||
rc=${?}
|
adb_rc=${?}
|
||||||
if [ ${rc} -ne 0 ]
|
if [ ${adb_rc} -ne 0 ]
|
||||||
then
|
then
|
||||||
f_list remove
|
f_list remove
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
f_list remove
|
f_list remove
|
||||||
fi
|
fi
|
||||||
f_log "debug" "loop_3 ::: name: ${src_name}, rc: ${rc}"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# sort/unique overall
|
# sort/unique overall
|
||||||
|
@ -483,10 +450,9 @@ f_main()
|
||||||
mv -f "${adb_tmpdir}/${adb_dnsprefix}"* "${adb_dnsdir}" 2>/dev/null
|
mv -f "${adb_tmpdir}/${adb_dnsprefix}"* "${adb_dnsdir}" 2>/dev/null
|
||||||
chown "${adb_dns}":"${adb_dns}" "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null
|
chown "${adb_dns}":"${adb_dns}" "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null
|
||||||
f_dnsrestart
|
f_dnsrestart
|
||||||
f_debug
|
|
||||||
if [ "${adb_dnsup}" = "true" ]
|
if [ "${adb_dnsup}" = "true" ]
|
||||||
then
|
then
|
||||||
f_log "info " "status ::: block lists with overall ${sum_cnt} domains loaded (${sysver})"
|
f_log "info " "block lists with overall ${sum_cnt} domains loaded successfully (${sysver})"
|
||||||
ubus call service set "{\"name\":\"adblock_stats\",
|
ubus call service set "{\"name\":\"adblock_stats\",
|
||||||
\"instances\":{\"statistics\":{\"command\":[\"\"],
|
\"instances\":{\"statistics\":{\"command\":[\"\"],
|
||||||
\"data\":{\"active_lists\":[{${active_lists}}],
|
\"data\":{\"active_lists\":[{${active_lists}}],
|
||||||
|
@ -498,7 +464,7 @@ f_main()
|
||||||
f_rmtemp
|
f_rmtemp
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
f_log "error" "status ::: dns backend restart with active block lists failed (${sysver})"
|
f_log "error" "dns backend restart with active block lists failed (${sysver})"
|
||||||
}
|
}
|
||||||
|
|
||||||
# handle different adblock actions
|
# handle different adblock actions
|
||||||
|
|
Loading…
Reference in a new issue