Browse Source

adblock: update 1.4.3

* fix race condition in restricted mode
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
lilik-openwrt-22.03
Dirk Brenken 8 years ago
parent
commit
58883787bf
4 changed files with 51 additions and 54 deletions
  1. +1
    -1
      net/adblock/Makefile
  2. +37
    -41
      net/adblock/files/adblock-helper.sh
  3. +1
    -1
      net/adblock/files/adblock-update.sh
  4. +12
    -11
      net/adblock/files/adblock.init

+ 1
- 1
net/adblock/Makefile View File

@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=adblock PKG_NAME:=adblock
PKG_VERSION:=1.4.2
PKG_VERSION:=1.4.3
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>


+ 37
- 41
net/adblock/files/adblock-helper.sh View File

@ -108,14 +108,6 @@ f_envload()
network_get_device adb_landev "${adb_lanif}" network_get_device adb_landev "${adb_lanif}"
network_find_wan adb_wanif4 network_find_wan adb_wanif4
network_find_wan6 adb_wanif6 network_find_wan6 adb_wanif6
# set restricted mode
#
if [ "${adb_restricted}" = "1" ]
then
adb_uci="$(which true)"
restricted_ok="true"
fi
} }
# f_envcheck: check/set environment prerequisites # f_envcheck: check/set environment prerequisites
@ -137,7 +129,7 @@ f_envcheck()
fi fi
if [ "${adb_enabled}" != "1" ] if [ "${adb_enabled}" != "1" ]
then then
rc=-1
rc=-10
f_log "adblock is currently disabled, please set adblock.global.adb_enabled=1' to use this service" f_log "adblock is currently disabled, please set adblock.global.adb_enabled=1' to use this service"
f_exit f_exit
fi fi
@ -176,8 +168,8 @@ f_envcheck()
then then
adb_nullipv4="${adb_ipv4}" adb_nullipv4="${adb_ipv4}"
adb_nullipv6="${adb_ipv6}" adb_nullipv6="${adb_ipv6}"
if [ "$(${adb_uci} -q get uhttpd.main.listen_http | grep -Fo "80")" = "80" ] ||
[ "$(${adb_uci} -q get uhttpd.main.listen_https | grep -Fo "443")" = "443" ]
if [ -n "$(${adb_uci} -q get uhttpd.main.listen_http | grep -Fo "80")" ] ||
[ -n "$(${adb_uci} -q get uhttpd.main.listen_https | grep -Fo "443")" ]
then then
rc=-1 rc=-1
f_log "AP mode detected, please set local LuCI instance to ports <> 80/443" f_log "AP mode detected, please set local LuCI instance to ports <> 80/443"
@ -200,8 +192,7 @@ f_envcheck()
check="$(${adb_uci} -q get bcp38.@bcp38[0].enabled)" check="$(${adb_uci} -q get bcp38.@bcp38[0].enabled)"
if [ "${check}" = "1" ] if [ "${check}" = "1" ]
then then
check="$(${adb_uci} -q get bcp38.@bcp38[0].match | grep -Fo "${adb_nullipv4%.*}")"
if [ -n "${check}" ]
if [ -n "$(${adb_uci} -q get bcp38.@bcp38[0].match | grep -Fo "${adb_nullipv4%.*}")" ]
then then
rc=-1 rc=-1
f_log "please whitelist '${adb_nullipv4}' in your bcp38 configuration to use adblock" f_log "please whitelist '${adb_nullipv4}' in your bcp38 configuration to use adblock"
@ -295,10 +286,11 @@ f_envcheck()
f_log "AP mode enabled" f_log "AP mode enabled"
fi fi
# log restricted mode
# set/log restricted mode
# #
if [ "${restricted_ok}" = "true" ]
if [ "${adb_restricted}" = "1" ]
then then
adb_uci="$(which true)"
f_log "Restricted mode enabled" f_log "Restricted mode enabled"
fi fi
@ -601,18 +593,14 @@ f_rmconfig()
local options="adb_src_timestamp adb_src_count" local options="adb_src_timestamp adb_src_count"
local section="${1}" local section="${1}"
rm_cfg="${adb_lastrun}"
if [ -n "${rm_cfg}" ]
then
"${adb_uci}" -q delete "adblock.global.adb_overall_count"
"${adb_uci}" -q delete "adblock.global.adb_dnstoggle"
"${adb_uci}" -q delete "adblock.global.adb_percentage"
"${adb_uci}" -q delete "adblock.global.adb_lastrun"
for opt in ${options}
do
"${adb_uci}" -q delete "adblock.${section}.${opt}"
done
fi
"${adb_uci}" -q delete "adblock.global.adb_overall_count"
"${adb_uci}" -q delete "adblock.global.adb_dnstoggle"
"${adb_uci}" -q delete "adblock.global.adb_percentage"
"${adb_uci}" -q delete "adblock.global.adb_lastrun"
for opt in ${options}
do
"${adb_uci}" -q delete "adblock.${section}.${opt}"
done
} }
# f_rmdns: remove dns block lists and backups # f_rmdns: remove dns block lists and backups
@ -669,7 +657,6 @@ f_log()
local log_parm local log_parm
local log_msg="${1}" local log_msg="${1}"
local class="info " local class="info "
local lastrun="$(date "+%d.%m.%Y %H:%M:%S")"
# check for terminal session # check for terminal session
# #
@ -687,18 +674,6 @@ f_log()
class="error" class="error"
fi fi
logger ${log_parm} -t "adblock[${adb_pid}] ${class}" "${log_msg}" 2>&1 logger ${log_parm} -t "adblock[${adb_pid}] ${class}" "${log_msg}" 2>&1
# clean exit on error
#
if [ $((rc)) -eq -1 ] || [ $((rc)) -gt 0 ]
then
f_rmdns
f_rmuhttpd
f_rmfirewall
config_foreach f_rmconfig source
"${adb_uci}" -q set "adblock.global.adb_lastrun=${lastrun} => runtime error, please check the log!"
"${adb_uci}" -q commit "adblock"
fi
fi fi
} }
@ -742,16 +717,36 @@ f_exit()
{ {
local lastrun="$(date "+%d.%m.%Y %H:%M:%S")" local lastrun="$(date "+%d.%m.%Y %H:%M:%S")"
if [ "${adb_restricted}" = "1" ]
then
adb_uci="$(which true)"
fi
# delete temp files & directories
#
rm -f "${adb_tmpfile}" rm -f "${adb_tmpfile}"
rm -rf "${adb_tmpdir}" rm -rf "${adb_tmpdir}"
# tidy up on error
#
if [ $((rc)) -lt 0 ] || [ $((rc)) -gt 0 ]
then
f_rmdns
f_rmuhttpd
f_rmfirewall
config_foreach f_rmconfig source
if [ $((rc)) -eq -1 ]
then
"${adb_uci}" -q set "adblock.global.adb_lastrun=${lastrun} => runtime error, please check the log!"
fi
fi
# final log message and iptables statistics # final log message and iptables statistics
# #
if [ $((rc)) -eq 0 ] if [ $((rc)) -eq 0 ]
then then
f_statistics f_statistics
"${adb_uci}" -q set "adblock.global.adb_lastrun=${lastrun}" "${adb_uci}" -q set "adblock.global.adb_lastrun=${lastrun}"
"${adb_uci}" -q commit "adblock"
f_log "domain adblock processing finished successfully (${adb_scriptver}, ${adb_sysver}, ${lastrun})" f_log "domain adblock processing finished successfully (${adb_scriptver}, ${adb_sysver}, ${lastrun})"
elif [ $((rc)) -gt 0 ] elif [ $((rc)) -gt 0 ]
then then
@ -759,6 +754,7 @@ f_exit()
else else
rc=0 rc=0
fi fi
"${adb_uci}" -q commit "adblock"
rm -f "${adb_pidfile}" rm -f "${adb_pidfile}"
exit ${rc} exit ${rc}
} }

+ 1
- 1
net/adblock/files/adblock-update.sh View File

@ -10,7 +10,7 @@
# #
adb_pid="${$}" adb_pid="${$}"
adb_pidfile="/var/run/adblock.pid" adb_pidfile="/var/run/adblock.pid"
adb_scriptver="1.4.2"
adb_scriptver="1.4.3"
adb_mincfgver="2.3" adb_mincfgver="2.3"
adb_scriptdir="${0%/*}" adb_scriptdir="${0%/*}"
if [ -r "${adb_pidfile}" ] if [ -r "${adb_pidfile}" ]


+ 12
- 11
net/adblock/files/adblock.init View File

@ -13,10 +13,6 @@ adb_script="/usr/bin/adblock-update.sh"
adb_helper="/usr/bin/adblock-helper.sh" adb_helper="/usr/bin/adblock-helper.sh"
adb_pidfile="/var/run/adblock.pid" adb_pidfile="/var/run/adblock.pid"
bg_parm="&" bg_parm="&"
if [ -t 1 ]
then
unset bg_parm
fi
if [ $((adb_debug)) -eq 0 ] if [ $((adb_debug)) -eq 0 ]
then then
@ -32,6 +28,11 @@ fi
. "${adb_helper}" . "${adb_helper}"
f_envload f_envload
if [ "${adb_restricted}" = "1" ]
then
adb_uci="$(which true)"
fi
boot() boot()
{ {
return 0 return 0
@ -39,6 +40,10 @@ boot()
start() start()
{ {
if [ -t 1 ]
then
unset bg_parm
fi
eval "${adb_script}" ${bg_parm} eval "${adb_script}" ${bg_parm}
return 0 return 0
} }
@ -60,18 +65,14 @@ stop()
{ {
f_rmdns f_rmdns
f_rmuhttpd f_rmuhttpd
adb_uci="$(which uci)"
config_foreach f_rmconfig source config_foreach f_rmconfig source
if [ -n "$(${adb_uci} -q changes adblock)" ]
then
"${adb_uci}" -q commit adblock
fi
if [ -z "${reload}" ] if [ -z "${reload}" ]
then then
f_rmfirewall f_rmfirewall
fi fi
if [ -n "${rm_dns}" ] || [ -n "${rm_uhttpd}" ] || [ -n "${rm_fw}" ] || [ -n "${rm_cfg}" ]
if [ -n "${rm_dns}" ] || [ -n "${rm_uhttpd}" ] || [ -n "${rm_fw}" ] || [ -n "$(${adb_uci} -q changes adblock)" ]
then then
"${adb_uci}" -q commit adblock
f_log "all adblock related services stopped" f_log "all adblock related services stopped"
fi fi
return 0 return 0
@ -97,9 +98,9 @@ toggle()
if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ] if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ]
then then
mv -f "${source}"* "${target}" mv -f "${source}"* "${target}"
/etc/init.d/dnsmasq restart
"${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}" "${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}"
"${adb_uci}" -q commit "adblock" "${adb_uci}" -q commit "adblock"
/etc/init.d/dnsmasq restart
f_log "adblock toggle switched '${pos}'" f_log "adblock toggle switched '${pos}'"
fi fi
fi fi


Loading…
Cancel
Save