adblock: update 1.2.1
* small optimizations & cosmetics Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
parent
8ab3d8bdc2
commit
672dd10b10
4 changed files with 71 additions and 62 deletions
|
@ -7,7 +7,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=adblock
|
PKG_NAME:=adblock
|
||||||
PKG_VERSION:=1.2.0
|
PKG_VERSION:=1.2.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>
|
||||||
|
|
|
@ -118,6 +118,7 @@ f_envload()
|
||||||
adb_dnsprefix="adb_list"
|
adb_dnsprefix="adb_list"
|
||||||
adb_iptv4="$(which iptables)"
|
adb_iptv4="$(which iptables)"
|
||||||
adb_iptv6="$(which ip6tables)"
|
adb_iptv6="$(which ip6tables)"
|
||||||
|
adb_uhttpd="$(which uhttpd)"
|
||||||
adb_fetch="$(which wget)"
|
adb_fetch="$(which wget)"
|
||||||
adb_uci="$(which uci)"
|
adb_uci="$(which uci)"
|
||||||
adb_date="$(which date)"
|
adb_date="$(which date)"
|
||||||
|
@ -181,7 +182,7 @@ f_envload()
|
||||||
rc=-1
|
rc=-1
|
||||||
f_log "please enable the local dnsmasq instance to use adblock"
|
f_log "please enable the local dnsmasq instance to use adblock"
|
||||||
f_exit
|
f_exit
|
||||||
elif [ -z "$(${adb_iptv4} -vnL | grep -Fo "DROP")" ]
|
elif [ -z "$(${adb_iptv4} -w -vnL | grep -Fo "DROP")" ]
|
||||||
then
|
then
|
||||||
rc=-1
|
rc=-1
|
||||||
f_log "please enable the local firewall to use adblock"
|
f_log "please enable the local firewall to use adblock"
|
||||||
|
@ -197,7 +198,7 @@ f_envload()
|
||||||
if [ -n "${check}" ]
|
if [ -n "${check}" ]
|
||||||
then
|
then
|
||||||
rc=-1
|
rc=-1
|
||||||
f_log "please whitelist '${adb_nullipv4}' in your bcp38 configuration to use default adblock null-ip"
|
f_log "please whitelist '${adb_nullipv4}' in your bcp38 configuration to use your adblock null-ip"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -348,74 +349,71 @@ f_envcheck()
|
||||||
adb_dnsformat="awk -v ipv6="${adb_nullipv6}" '{print \"address=/\"\$0\"/\"ipv6}'"
|
adb_dnsformat="awk -v ipv6="${adb_nullipv6}" '{print \"address=/\"\$0\"/\"ipv6}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check ipv4/iptables configuration
|
# check volatile iptables configuration
|
||||||
#
|
#
|
||||||
if [ -n "${adb_wanif4}" ]
|
if [ -n "${adb_wanif4}" ]
|
||||||
|
then
|
||||||
|
check="$(${adb_iptv4} -w -vnL | grep -Fo "adb-")"
|
||||||
|
if [ -z "${check}" ]
|
||||||
then
|
then
|
||||||
if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev4}" ]
|
if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev4}" ]
|
||||||
then
|
then
|
||||||
f_firewall "IPv4" "nat" "prerouting_rule" "prerouting_rule" "0" "dns" "-i ${adb_landev4} -p udp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
|
f_firewall "IPv4" "nat" "prerouting_rule" "prerouting_rule" "0" "dns" "-i ${adb_landev4} -p udp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
|
||||||
f_firewall "IPv4" "nat" "prerouting_rule" "prerouting_rule" "0" "dns" "-i ${adb_landev4} -p tcp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
|
f_firewall "IPv4" "nat" "prerouting_rule" "prerouting_rule" "0" "dns" "-i ${adb_landev4} -p tcp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53"
|
||||||
fi
|
fi
|
||||||
f_firewall "IPv4" "nat" "prerouting_rule" "adb-nat" "1" "nat" "-d ${adb_nullipv4} -p tcp --dport 80 -j DNAT --to-destination ${adb_ipv4}:${adb_nullport}"
|
f_firewall "IPv4" "nat" "prerouting_rule" "adb-nat" "1" "nat" "-p tcp --dport 80 -j DNAT --to-destination ${adb_ipv4}:${adb_nullport}"
|
||||||
f_firewall "IPv4" "nat" "prerouting_rule" "adb-nat" "2" "nat" "-d ${adb_nullipv4} -p tcp --dport 443 -j DNAT --to-destination ${adb_ipv4}:${adb_nullportssl}"
|
f_firewall "IPv4" "nat" "prerouting_rule" "adb-nat" "2" "nat" "-p tcp --dport 443 -j DNAT --to-destination ${adb_ipv4}:${adb_nullportssl}"
|
||||||
f_firewall "IPv4" "filter" "forwarding_rule" "adb-fwd" "1" "fwd" "-d ${adb_nullipv4} -p tcp -j REJECT --reject-with tcp-reset"
|
f_firewall "IPv4" "filter" "forwarding_rule" "adb-fwd" "1" "fwd" "-p tcp -j REJECT --reject-with tcp-reset"
|
||||||
f_firewall "IPv4" "filter" "forwarding_rule" "adb-fwd" "2" "fwd" "-d ${adb_nullipv4} -j REJECT --reject-with icmp-host-unreachable"
|
f_firewall "IPv4" "filter" "forwarding_rule" "adb-fwd" "2" "fwd" "-j REJECT --reject-with icmp-host-unreachable"
|
||||||
f_firewall "IPv4" "filter" "output_rule" "adb-out" "1" "out" "-d ${adb_nullipv4} -p tcp -j REJECT --reject-with tcp-reset"
|
f_firewall "IPv4" "filter" "output_rule" "adb-out" "1" "out" "-p tcp -j REJECT --reject-with tcp-reset"
|
||||||
f_firewall "IPv4" "filter" "output_rule" "adb-out" "2" "out" "-d ${adb_nullipv4} -j REJECT --reject-with icmp-host-unreachable"
|
f_firewall "IPv4" "filter" "output_rule" "adb-out" "2" "out" "-j REJECT --reject-with icmp-host-unreachable"
|
||||||
if [ "${fw_done}" = "true" ]
|
|
||||||
then
|
|
||||||
f_log "created volatile IPv4 firewall ruleset"
|
|
||||||
fw_done="false"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check ipv6/ip6tables configuration
|
|
||||||
#
|
|
||||||
if [ -n "${adb_wanif6}" ]
|
if [ -n "${adb_wanif6}" ]
|
||||||
|
then
|
||||||
|
check="$(${adb_iptv6} -w -vnL | grep -Fo "adb-")"
|
||||||
|
if [ -z "${check}" ]
|
||||||
then
|
then
|
||||||
if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev6}" ]
|
if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev6}" ]
|
||||||
then
|
then
|
||||||
f_firewall "IPv6" "nat" "PREROUTING" "PREROUTING" "0" "dns" "-i ${adb_landev6} -p udp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
|
f_firewall "IPv6" "nat" "PREROUTING" "PREROUTING" "0" "dns" "-i ${adb_landev6} -p udp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
|
||||||
f_firewall "IPv6" "nat" "PREROUTING" "PREROUTING" "0" "dns" "-i ${adb_landev6} -p tcp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
|
f_firewall "IPv6" "nat" "PREROUTING" "PREROUTING" "0" "dns" "-i ${adb_landev6} -p tcp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53"
|
||||||
fi
|
fi
|
||||||
f_firewall "IPv6" "nat" "PREROUTING" "adb-nat" "1" "nat" "-d ${adb_nullipv6} -p tcp --dport 80 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullport}"
|
f_firewall "IPv6" "nat" "PREROUTING" "adb-nat" "1" "nat" "-p tcp --dport 80 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullport}"
|
||||||
f_firewall "IPv6" "nat" "PREROUTING" "adb-nat" "2" "nat" "-d ${adb_nullipv6} -p tcp --dport 443 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullportssl}"
|
f_firewall "IPv6" "nat" "PREROUTING" "adb-nat" "2" "nat" "-p tcp --dport 443 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullportssl}"
|
||||||
f_firewall "IPv6" "filter" "forwarding_rule" "adb-fwd" "1" "fwd" "-d ${adb_nullipv6} -p tcp -j REJECT --reject-with tcp-reset"
|
f_firewall "IPv6" "filter" "forwarding_rule" "adb-fwd" "1" "fwd" "-p tcp -j REJECT --reject-with tcp-reset"
|
||||||
f_firewall "IPv6" "filter" "forwarding_rule" "adb-fwd" "2" "fwd" "-d ${adb_nullipv6} -j REJECT --reject-with icmp6-addr-unreachable"
|
f_firewall "IPv6" "filter" "forwarding_rule" "adb-fwd" "2" "fwd" "-j REJECT --reject-with icmp6-addr-unreachable"
|
||||||
f_firewall "IPv6" "filter" "output_rule" "adb-out" "1" "out" "-d ${adb_nullipv6} -p tcp -j REJECT --reject-with tcp-reset"
|
f_firewall "IPv6" "filter" "output_rule" "adb-out" "1" "out" "-p tcp -j REJECT --reject-with tcp-reset"
|
||||||
f_firewall "IPv6" "filter" "output_rule" "adb-out" "2" "out" "-d ${adb_nullipv6} -j REJECT --reject-with icmp6-addr-unreachable"
|
f_firewall "IPv6" "filter" "output_rule" "adb-out" "2" "out" "-j REJECT --reject-with icmp6-addr-unreachable"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [ "${fw_done}" = "true" ]
|
if [ "${fw_done}" = "true" ]
|
||||||
then
|
then
|
||||||
f_log "created volatile IPv6 firewall ruleset"
|
f_log "created volatile firewall rulesets"
|
||||||
fw_done="false"
|
fw_done="false"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# check volatile adblock uhttpd instance configuration
|
# check volatile uhttpd instance configuration
|
||||||
#
|
#
|
||||||
check="$(pgrep -f "uhttpd -h /www/adblock")"
|
check="$(pgrep -f "uhttpd -h /www/adblock")"
|
||||||
if [ -z "${check}" ]
|
if [ -z "${check}" ]
|
||||||
then
|
then
|
||||||
if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ]
|
if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ]
|
||||||
then
|
then
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 1 -k 0 -t 0 -R -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullport}" -p "[${adb_ipv6}]:${adb_nullport}"
|
f_uhttpd "adbIPv4+6_80" "1" "-p ${adb_ipv4}:${adb_nullport} -p [${adb_ipv6}]:${adb_nullport}"
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 0 -k 0 -t 0 -R -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullportssl}" -p "[${adb_ipv6}]:${adb_nullportssl}"
|
f_uhttpd "adbIPv4+6_443" "0" "-p ${adb_ipv4}:${adb_nullportssl} -p [${adb_ipv6}]:${adb_nullportssl}"
|
||||||
elif [ -n "${adb_wanif4}" ]
|
elif [ -n "${adb_wanif4}" ]
|
||||||
then
|
then
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 1 -k 0 -t 0 -R -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullport}"
|
f_uhttpd "adbIPv4_80" "1" "-p ${adb_ipv4}:${adb_nullport}"
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 0 -k 0 -t 0 -R -D -S -E "/index.html" -p "${adb_ipv4}:${adb_nullportssl}"
|
f_uhttpd "adbIPv4_443" "0" "-p ${adb_ipv4}:${adb_nullportssl}"
|
||||||
else
|
else
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 1 -k 0 -t 0 -R -D -S -E "/index.html" -p "[${adb_ipv6}]:${adb_nullport}"
|
f_uhttpd "adbIPv6_80" "1" "-p [${adb_ipv6}]:${adb_nullport}"
|
||||||
uhttpd -h "/www/adblock" -N 25 -T 0 -k 0 -t 0 -R -D -S -E "/index.html" -p "[${adb_ipv6}]:${adb_nullportssl}"
|
f_uhttpd "adbIPv6_443" "0" "-p [${adb_ipv6}]:${adb_nullportssl}"
|
||||||
fi
|
fi
|
||||||
rc=${?}
|
if [ "${uhttpd_done}" = "true" ]
|
||||||
if [ $((rc)) -eq 0 ]
|
|
||||||
then
|
then
|
||||||
f_log "created volatile uhttpd instances"
|
f_log "created volatile uhttpd instances"
|
||||||
else
|
uhttpd_done="false"
|
||||||
f_log "failed to initialize volatile uhttpd instances" "${rc}"
|
|
||||||
f_exit
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -501,6 +499,24 @@ f_firewall()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# f_uhttpd: start uhttpd instances
|
||||||
|
#
|
||||||
|
f_uhttpd()
|
||||||
|
{
|
||||||
|
local realm="${1}"
|
||||||
|
local timeout="${2}"
|
||||||
|
local ports="${3}"
|
||||||
|
"${adb_uhttpd}" -h "/www/adblock" -N 25 -T "${timeout}" -r "${realm}" -k 0 -t 0 -R -D -S -E "/index.html" ${ports}
|
||||||
|
rc=${?}
|
||||||
|
if [ $((rc)) -eq 0 ]
|
||||||
|
then
|
||||||
|
uhttpd_done="true"
|
||||||
|
else
|
||||||
|
f_log "failed to initialize volatile uhttpd instance (${realm})" "${rc}"
|
||||||
|
f_exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# f_log: log messages to stdout and syslog
|
# f_log: log messages to stdout and syslog
|
||||||
#
|
#
|
||||||
f_log()
|
f_log()
|
||||||
|
@ -632,11 +648,8 @@ f_exit()
|
||||||
f_log "firewall statistics (IPv4/IPv6): ${ipv4_pct}%/${ipv6_pct}% of all packets in prerouting chain are ad related & blocked"
|
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
|
|
||||||
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
|
||||||
then
|
then
|
||||||
"${adb_uci}" -q revert "adblock"
|
"${adb_uci}" -q revert "adblock"
|
||||||
fi
|
|
||||||
f_log "domain adblock processing failed (${adb_scriptver}, ${adb_sysver}, ${lastrun})"
|
f_log "domain adblock processing failed (${adb_scriptver}, ${adb_sysver}, ${lastrun})"
|
||||||
else
|
else
|
||||||
rc=0
|
rc=0
|
||||||
|
|
|
@ -28,7 +28,7 @@ fi
|
||||||
# get current directory and set script/config version
|
# get current directory and set script/config version
|
||||||
#
|
#
|
||||||
adb_scriptdir="${0%/*}"
|
adb_scriptdir="${0%/*}"
|
||||||
adb_scriptver="1.2.0"
|
adb_scriptver="1.2.1"
|
||||||
adb_mincfgver="2.2"
|
adb_mincfgver="2.2"
|
||||||
|
|
||||||
# source in adblock function library
|
# source in adblock function library
|
||||||
|
@ -99,7 +99,7 @@ do
|
||||||
if [ -z "${url_time}" ]
|
if [ -z "${url_time}" ]
|
||||||
then
|
then
|
||||||
url_time="$(date)"
|
url_time="$(date)"
|
||||||
f_log " online timestamp not received, current date will be used"
|
f_log " no online timestamp received"
|
||||||
fi
|
fi
|
||||||
if [ -z "${list_time}" ] || [ "${list_time}" != "${url_time}" ] || [ ! -r "${adb_dnsfile}" ] ||\
|
if [ -z "${list_time}" ] || [ "${list_time}" != "${url_time}" ] || [ ! -r "${adb_dnsfile}" ] ||\
|
||||||
([ "${backup_ok}" = "true" ] && [ ! -r "${adb_dir_backup}/${adb_dnsprefix}.${src_name}.gz" ])
|
([ "${backup_ok}" = "true" ] && [ ! -r "${adb_dir_backup}/${adb_dnsprefix}.${src_name}.gz" ])
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
START=99
|
START=99
|
||||||
|
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
EXTRA_COMMANDS="toggle cfgup"
|
EXTRA_COMMANDS="toggle cfgup"
|
||||||
EXTRA_HELP=" toggle Toggle adblocking 'on' or 'off'
|
EXTRA_HELP=" toggle Toggle adblocking 'on' or 'off'
|
||||||
cfgup Update the adblock configuration file"
|
cfgup Update the adblock configuration file"
|
||||||
|
|
||||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
|
||||||
|
|
||||||
adb_debug=0
|
adb_debug=0
|
||||||
if [ $((adb_debug)) -eq 0 ]
|
if [ $((adb_debug)) -eq 0 ]
|
||||||
then
|
then
|
||||||
|
@ -74,7 +73,7 @@ reload()
|
||||||
stop()
|
stop()
|
||||||
{
|
{
|
||||||
cfg_check="$(${adb_uci} -q get "adblock.global.adb_overall_count")"
|
cfg_check="$(${adb_uci} -q get "adblock.global.adb_overall_count")"
|
||||||
if [ -n "${cfg_check}" ]
|
if [ -n "${cfg_check}" ] && [ -z "${restart}" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
config_load adblock
|
config_load adblock
|
||||||
|
@ -83,12 +82,9 @@ stop()
|
||||||
"${adb_uci}" -q delete "adblock.global.adb_overall_count"
|
"${adb_uci}" -q delete "adblock.global.adb_overall_count"
|
||||||
"${adb_uci}" -q delete "adblock.global.adb_percentage"
|
"${adb_uci}" -q delete "adblock.global.adb_percentage"
|
||||||
"${adb_uci}" -q delete "adblock.global.adb_lastrun"
|
"${adb_uci}" -q delete "adblock.global.adb_lastrun"
|
||||||
if [ -z "${restart}" ]
|
|
||||||
then
|
|
||||||
"${adb_uci}" -q commit "adblock"
|
"${adb_uci}" -q commit "adblock"
|
||||||
fi
|
fi
|
||||||
fi
|
fw_check="$(iptables -w -vnL | grep -Fo "adb-")"
|
||||||
fw_check="$(iptables -w -t nat -nL | grep -F "adb-")"
|
|
||||||
if [ -n "${fw_check}" ] && [ -z "${restart}" ]
|
if [ -n "${fw_check}" ] && [ -z "${restart}" ]
|
||||||
then
|
then
|
||||||
iptables-save -t nat | grep -Fv -- "adb-" | iptables-restore
|
iptables-save -t nat | grep -Fv -- "adb-" | iptables-restore
|
||||||
|
|
Loading…
Reference in a new issue