adblock: update 1.2.7
* provide adblock statistics as a separate function (/etc/init.d/adblock stats) Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
001646e3fe
commit
ba13e81d21
4 changed files with 74 additions and 71 deletions
|
@ -7,7 +7,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=adblock
|
PKG_NAME:=adblock
|
||||||
PKG_VERSION:=1.2.6
|
PKG_VERSION:=1.2.7
|
||||||
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>
|
||||||
|
|
|
@ -32,11 +32,8 @@ f_envload()
|
||||||
# source in system function library
|
# source in system function library
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions.sh" ]
|
if [ -r "/lib/functions.sh" ]
|
||||||
then
|
|
||||||
if [ -z "$(type -f config_load)" ]
|
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
rc=-10
|
rc=-10
|
||||||
f_log "system function library not found, please check your installation"
|
f_log "system function library not found, please check your installation"
|
||||||
|
@ -46,11 +43,8 @@ f_envload()
|
||||||
# source in system network library
|
# source in system network library
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions/network.sh" ]
|
if [ -r "/lib/functions/network.sh" ]
|
||||||
then
|
|
||||||
if [ -z "$(type -f network_get_device)" ]
|
|
||||||
then
|
then
|
||||||
. "/lib/functions/network.sh"
|
. "/lib/functions/network.sh"
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
rc=-10
|
rc=-10
|
||||||
f_log "system network library not found, please check your installation"
|
f_log "system network library not found, please check your installation"
|
||||||
|
@ -108,6 +102,21 @@ f_envload()
|
||||||
config_load adblock
|
config_load adblock
|
||||||
config_foreach parse_config service
|
config_foreach parse_config service
|
||||||
config_foreach parse_config source
|
config_foreach parse_config source
|
||||||
|
|
||||||
|
# get ip addresses & logical wan devices
|
||||||
|
#
|
||||||
|
network_get_ipaddr adb_ipv4 "${adb_lanif}"
|
||||||
|
network_get_ipaddr6 adb_ipv6 "${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
|
# f_envcheck: check/set environment prerequisites
|
||||||
|
@ -116,14 +125,6 @@ f_envcheck()
|
||||||
{
|
{
|
||||||
local check
|
local check
|
||||||
|
|
||||||
# check restricted mode
|
|
||||||
#
|
|
||||||
if [ "${adb_restricted}" = "1" ]
|
|
||||||
then
|
|
||||||
adb_uci="$(which true)"
|
|
||||||
restricted_ok="true"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check 'enabled' & 'version' config options
|
# check 'enabled' & 'version' config options
|
||||||
#
|
#
|
||||||
if [ -z "${adb_enabled}" ] || [ -z "${adb_cfgver}" ] || [ "${adb_cfgver%%.*}" != "${adb_mincfgver%%.*}" ]
|
if [ -z "${adb_enabled}" ] || [ -z "${adb_cfgver}" ] || [ "${adb_cfgver%%.*}" != "${adb_mincfgver%%.*}" ]
|
||||||
|
@ -156,8 +157,6 @@ f_envcheck()
|
||||||
|
|
||||||
# get lan ip addresses
|
# get lan ip addresses
|
||||||
#
|
#
|
||||||
network_get_ipaddr adb_ipv4 "${adb_lanif}"
|
|
||||||
network_get_ipaddr6 adb_ipv6 "${adb_lanif}"
|
|
||||||
if [ -z "${adb_ipv4}" ] && [ -z "${adb_ipv6}" ]
|
if [ -z "${adb_ipv4}" ] && [ -z "${adb_ipv6}" ]
|
||||||
then
|
then
|
||||||
rc=-1
|
rc=-1
|
||||||
|
@ -170,8 +169,6 @@ f_envcheck()
|
||||||
|
|
||||||
# check logical update interfaces (with default route)
|
# check logical update interfaces (with default route)
|
||||||
#
|
#
|
||||||
network_find_wan adb_wanif4
|
|
||||||
network_find_wan6 adb_wanif6
|
|
||||||
if [ -z "${adb_wanif4}" ] && [ -z "${adb_wanif6}" ]
|
if [ -z "${adb_wanif4}" ] && [ -z "${adb_wanif6}" ]
|
||||||
then
|
then
|
||||||
adb_wanif4="${adb_lanif}"
|
adb_wanif4="${adb_lanif}"
|
||||||
|
@ -675,21 +672,12 @@ f_log()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# f_exit: delete temporary files, generate statistics and exit
|
# f_statistics: adblock runtime statistics
|
||||||
#
|
f_statistics()
|
||||||
f_exit()
|
|
||||||
{
|
{
|
||||||
local ipv4_blk=0 ipv4_all=0 ipv4_pct=0
|
local ipv4_blk=0 ipv4_all=0 ipv4_pct=0
|
||||||
local ipv6_blk=0 ipv6_all=0 ipv6_pct=0
|
local ipv6_blk=0 ipv6_all=0 ipv6_pct=0
|
||||||
local lastrun="$(date "+%d.%m.%Y %H:%M:%S")"
|
|
||||||
|
|
||||||
rm -f "${adb_tmpfile}"
|
|
||||||
rm -rf "${adb_tmpdir}"
|
|
||||||
|
|
||||||
# final log message and iptables statistics
|
|
||||||
#
|
|
||||||
if [ $((rc)) -eq 0 ]
|
|
||||||
then
|
|
||||||
if [ -n "${adb_wanif4}" ]
|
if [ -n "${adb_wanif4}" ]
|
||||||
then
|
then
|
||||||
ipv4_blk="$(iptables -t nat -vnL adb-nat | awk '$3 ~ /^DNAT$/ {sum += $1} END {printf sum}')"
|
ipv4_blk="$(iptables -t nat -vnL adb-nat | awk '$3 ~ /^DNAT$/ {sum += $1} END {printf sum}')"
|
||||||
|
@ -709,9 +697,25 @@ f_exit()
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
"${adb_uci}" -q set "adblock.global.adb_percentage=${ipv4_pct}%/${ipv6_pct}%"
|
"${adb_uci}" -q set "adblock.global.adb_percentage=${ipv4_pct}%/${ipv6_pct}%"
|
||||||
|
f_log "firewall statistics (IPv4/IPv6): ${ipv4_pct}%/${ipv6_pct}% of all packets in prerouting chain are ad related & blocked"
|
||||||
|
}
|
||||||
|
|
||||||
|
# f_exit: delete temporary files, generate statistics and exit
|
||||||
|
#
|
||||||
|
f_exit()
|
||||||
|
{
|
||||||
|
local lastrun="$(date "+%d.%m.%Y %H:%M:%S")"
|
||||||
|
|
||||||
|
rm -f "${adb_tmpfile}"
|
||||||
|
rm -rf "${adb_tmpdir}"
|
||||||
|
|
||||||
|
# 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 set "adblock.global.adb_lastrun=${lastrun}"
|
||||||
"${adb_uci}" -q commit "adblock"
|
"${adb_uci}" -q commit "adblock"
|
||||||
f_log "firewall statistics (IPv4/IPv6): ${ipv4_pct}%/${ipv6_pct}% of all packets in prerouting chain are ad related & blocked"
|
|
||||||
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
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
adb_pid="${$}"
|
adb_pid="${$}"
|
||||||
adb_pidfile="/var/run/adblock.pid"
|
adb_pidfile="/var/run/adblock.pid"
|
||||||
adb_scriptver="1.2.6"
|
adb_scriptver="1.2.7"
|
||||||
adb_mincfgver="2.2"
|
adb_mincfgver="2.2"
|
||||||
adb_scriptdir="${0%/*}"
|
adb_scriptdir="${0%/*}"
|
||||||
if [ -r "${adb_pidfile}" ]
|
if [ -r "${adb_pidfile}" ]
|
||||||
|
@ -21,12 +21,9 @@ then
|
||||||
else
|
else
|
||||||
printf "${adb_pid}" > "${adb_pidfile}"
|
printf "${adb_pid}" > "${adb_pidfile}"
|
||||||
if [ -r "${adb_scriptdir}/adblock-helper.sh" ]
|
if [ -r "${adb_scriptdir}/adblock-helper.sh" ]
|
||||||
then
|
|
||||||
if [ -z "$(type -f f_envload)" ]
|
|
||||||
then
|
then
|
||||||
. "${adb_scriptdir}/adblock-helper.sh"
|
. "${adb_scriptdir}/adblock-helper.sh"
|
||||||
f_envload
|
f_envload
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
rc=254
|
rc=254
|
||||||
logger -s -t "adblock[${adb_pid}] error" "adblock function library not found"
|
logger -s -t "adblock[${adb_pid}] error" "adblock function library not found"
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
START=99
|
START=99
|
||||||
EXTRA_COMMANDS="toggle cfgup"
|
EXTRA_COMMANDS="toggle stats cfgup"
|
||||||
EXTRA_HELP=" toggle Toggle adblocking 'on' or 'off'
|
EXTRA_HELP=" toggle Toggle adblock 'on' or 'off'
|
||||||
cfgup Update the adblock configuration file"
|
stats Update adblock statistics
|
||||||
|
cfgup Update adblock configuration file"
|
||||||
|
|
||||||
adb_debug=0
|
adb_debug=0
|
||||||
adb_pid="${$}"
|
adb_pid="${$}"
|
||||||
|
@ -12,25 +13,25 @@ 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="&"
|
||||||
unset log_parm
|
if [ -t 1 ]
|
||||||
|
then
|
||||||
|
unset bg_parm
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $((adb_debug)) -eq 0 ]
|
if [ $((adb_debug)) -eq 0 ]
|
||||||
then
|
then
|
||||||
exec 2>/dev/null
|
exec 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -t 1 ]
|
|
||||||
then
|
|
||||||
log_parm="-s"
|
|
||||||
unset bg_parm
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -r "${adb_pidfile}" ]
|
if [ -r "${adb_pidfile}" ]
|
||||||
then
|
then
|
||||||
logger ${log_parm} -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile}))" 2>&1
|
logger -s -t "adblock[${adb_pid}] error" "adblock service already running ($(cat ${adb_pidfile}))" 2>&1
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
. "${adb_helper}"
|
||||||
|
f_envload
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
return 0
|
return 0
|
||||||
|
@ -57,10 +58,9 @@ reload()
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
. "${adb_helper}"
|
|
||||||
f_envload
|
|
||||||
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)" ]
|
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
||||||
then
|
then
|
||||||
|
@ -72,14 +72,13 @@ stop()
|
||||||
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 "${rm_cfg}" ]
|
||||||
then
|
then
|
||||||
logger ${log_parm} -t "adblock[${adb_pid}] info " "all adblock related services stopped" 2>&1
|
f_log "all adblock related services stopped"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle()
|
toggle()
|
||||||
{
|
{
|
||||||
. "${adb_helper}"
|
|
||||||
if [ -d "${adb_dnshidedir}" ]
|
if [ -d "${adb_dnshidedir}" ]
|
||||||
then
|
then
|
||||||
list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
|
list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
|
||||||
|
@ -97,20 +96,23 @@ toggle()
|
||||||
fi
|
fi
|
||||||
if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ]
|
if [ -n "${list_dns}" ] || [ -n "${list_dnshide}" ]
|
||||||
then
|
then
|
||||||
if [ "$(${adb_uci} -q get adblock.global.adb_restricted)" = "1" ]
|
|
||||||
then
|
|
||||||
adb_uci="$(which true)"
|
|
||||||
fi
|
|
||||||
mv -f "${source}"* "${target}"
|
mv -f "${source}"* "${target}"
|
||||||
"${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
|
/etc/init.d/dnsmasq restart
|
||||||
logger ${log_parm} -t "adblock[${adb_pid}] info " "toggle for adblock switched '${pos}'" 2>&1
|
f_log "adblock toggle switched '${pos}'"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stats()
|
||||||
|
{
|
||||||
|
f_statistics
|
||||||
|
"${adb_uci}" -q commit "adblock"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
cfgup()
|
cfgup()
|
||||||
{
|
{
|
||||||
stop
|
stop
|
||||||
|
@ -118,9 +120,9 @@ cfgup()
|
||||||
rc=$?
|
rc=$?
|
||||||
if [ $((rc)) -eq 0 ]
|
if [ $((rc)) -eq 0 ]
|
||||||
then
|
then
|
||||||
logger ${log_parm} -t "adblock[${adb_pid}] info " "default adblock configuration applied, please check the settings in '/etc/config/adblock'" 2>&1
|
f_log "default adblock configuration applied, please check the settings in '/etc/config/adblock'"
|
||||||
else
|
else
|
||||||
logger ${log_parm} -t "adblock[${adb_pid}] info " "default adblock configuration not found, please re-install the package via 'opkg install adblock --force-maintainer'" 2>&1
|
f_log "default adblock configuration not found, please re-install the package via 'opkg install adblock --force-maintainer'"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue