diff --git a/net/adblock/Makefile b/net/adblock/Makefile index 884659b3d..34c97053c 100644 --- a/net/adblock/Makefile +++ b/net/adblock/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=adblock -PKG_VERSION:=1.4.2 +PKG_VERSION:=1.4.3 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0+ PKG_MAINTAINER:=Dirk Brenken diff --git a/net/adblock/files/adblock-helper.sh b/net/adblock/files/adblock-helper.sh index 4940b255c..233707c3a 100644 --- a/net/adblock/files/adblock-helper.sh +++ b/net/adblock/files/adblock-helper.sh @@ -108,14 +108,6 @@ f_envload() network_get_device adb_landev "${adb_lanif}" network_find_wan adb_wanif4 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 @@ -137,7 +129,7 @@ f_envcheck() fi if [ "${adb_enabled}" != "1" ] then - rc=-1 + rc=-10 f_log "adblock is currently disabled, please set adblock.global.adb_enabled=1' to use this service" f_exit fi @@ -176,8 +168,8 @@ f_envcheck() then adb_nullipv4="${adb_ipv4}" 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 rc=-1 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)" if [ "${check}" = "1" ] 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 rc=-1 f_log "please whitelist '${adb_nullipv4}' in your bcp38 configuration to use adblock" @@ -295,10 +286,11 @@ f_envcheck() f_log "AP mode enabled" fi - # log restricted mode + # set/log restricted mode # - if [ "${restricted_ok}" = "true" ] + if [ "${adb_restricted}" = "1" ] then + adb_uci="$(which true)" f_log "Restricted mode enabled" fi @@ -601,18 +593,14 @@ f_rmconfig() local options="adb_src_timestamp adb_src_count" 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 @@ -669,7 +657,6 @@ f_log() local log_parm local log_msg="${1}" local class="info " - local lastrun="$(date "+%d.%m.%Y %H:%M:%S")" # check for terminal session # @@ -687,18 +674,6 @@ f_log() class="error" fi 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 } @@ -742,16 +717,36 @@ f_exit() { 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 -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 # if [ $((rc)) -eq 0 ] then f_statistics "${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})" elif [ $((rc)) -gt 0 ] then @@ -759,6 +754,7 @@ f_exit() else rc=0 fi + "${adb_uci}" -q commit "adblock" rm -f "${adb_pidfile}" exit ${rc} } diff --git a/net/adblock/files/adblock-update.sh b/net/adblock/files/adblock-update.sh index 9a9fb989f..41a4a7170 100755 --- a/net/adblock/files/adblock-update.sh +++ b/net/adblock/files/adblock-update.sh @@ -10,7 +10,7 @@ # adb_pid="${$}" adb_pidfile="/var/run/adblock.pid" -adb_scriptver="1.4.2" +adb_scriptver="1.4.3" adb_mincfgver="2.3" adb_scriptdir="${0%/*}" if [ -r "${adb_pidfile}" ] diff --git a/net/adblock/files/adblock.init b/net/adblock/files/adblock.init index 6a2f6bf0e..15c7d9ee7 100755 --- a/net/adblock/files/adblock.init +++ b/net/adblock/files/adblock.init @@ -13,10 +13,6 @@ adb_script="/usr/bin/adblock-update.sh" adb_helper="/usr/bin/adblock-helper.sh" adb_pidfile="/var/run/adblock.pid" bg_parm="&" -if [ -t 1 ] -then - unset bg_parm -fi if [ $((adb_debug)) -eq 0 ] then @@ -32,6 +28,11 @@ fi . "${adb_helper}" f_envload +if [ "${adb_restricted}" = "1" ] +then + adb_uci="$(which true)" +fi + boot() { return 0 @@ -39,6 +40,10 @@ boot() start() { + if [ -t 1 ] + then + unset bg_parm + fi eval "${adb_script}" ${bg_parm} return 0 } @@ -60,18 +65,14 @@ stop() { f_rmdns f_rmuhttpd - adb_uci="$(which uci)" config_foreach f_rmconfig source - if [ -n "$(${adb_uci} -q changes adblock)" ] - then - "${adb_uci}" -q commit adblock - fi if [ -z "${reload}" ] then f_rmfirewall 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 + "${adb_uci}" -q commit adblock f_log "all adblock related services stopped" fi return 0 @@ -97,9 +98,9 @@ toggle() if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ] then mv -f "${source}"* "${target}" + /etc/init.d/dnsmasq restart "${adb_uci}" -q set "adblock.global.adb_dnstoggle=${pos}" "${adb_uci}" -q commit "adblock" - /etc/init.d/dnsmasq restart f_log "adblock toggle switched '${pos}'" fi fi