From 672dd10b101de5013e2df1d6a4b2d287b782e42f Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Tue, 14 Jun 2016 22:25:02 +0200 Subject: [PATCH] adblock: update 1.2.1 * small optimizations & cosmetics Signed-off-by: Dirk Brenken --- net/adblock/Makefile | 2 +- net/adblock/files/adblock-helper.sh | 115 ++++++++++++++++------------ net/adblock/files/adblock-update.sh | 4 +- net/adblock/files/adblock.init | 12 +-- 4 files changed, 71 insertions(+), 62 deletions(-) diff --git a/net/adblock/Makefile b/net/adblock/Makefile index 5b91dfab60..205f009480 100644 --- a/net/adblock/Makefile +++ b/net/adblock/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=adblock -PKG_VERSION:=1.2.0 +PKG_VERSION:=1.2.1 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 fef820e643..3ae127e5b3 100644 --- a/net/adblock/files/adblock-helper.sh +++ b/net/adblock/files/adblock-helper.sh @@ -118,6 +118,7 @@ f_envload() adb_dnsprefix="adb_list" adb_iptv4="$(which iptables)" adb_iptv6="$(which ip6tables)" + adb_uhttpd="$(which uhttpd)" adb_fetch="$(which wget)" adb_uci="$(which uci)" adb_date="$(which date)" @@ -181,7 +182,7 @@ f_envload() rc=-1 f_log "please enable the local dnsmasq instance to use adblock" f_exit - elif [ -z "$(${adb_iptv4} -vnL | grep -Fo "DROP")" ] + elif [ -z "$(${adb_iptv4} -w -vnL | grep -Fo "DROP")" ] then rc=-1 f_log "please enable the local firewall to use adblock" @@ -197,7 +198,7 @@ f_envload() if [ -n "${check}" ] then 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 fi fi @@ -348,74 +349,71 @@ f_envcheck() adb_dnsformat="awk -v ipv6="${adb_nullipv6}" '{print \"address=/\"\$0\"/\"ipv6}'" fi - # check ipv4/iptables configuration + # check volatile iptables configuration # if [ -n "${adb_wanif4}" ] then - if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev4}" ] + check="$(${adb_iptv4} -w -vnL | grep -Fo "adb-")" + if [ -z "${check}" ] 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 tcp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53" - 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" "2" "nat" "-d ${adb_nullipv4} -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" "2" "fwd" "-d ${adb_nullipv4} -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" "2" "out" "-d ${adb_nullipv4} -j REJECT --reject-with icmp-host-unreachable" - if [ "${fw_done}" = "true" ] - then - f_log "created volatile IPv4 firewall ruleset" - fw_done="false" + if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev4}" ] + 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 tcp --dport 53 -j DNAT --to-destination ${adb_ipv4}:53" + fi + 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" "-p tcp --dport 443 -j DNAT --to-destination ${adb_ipv4}:${adb_nullportssl}" + 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" "-j REJECT --reject-with icmp-host-unreachable" + 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" "-j REJECT --reject-with icmp-host-unreachable" fi fi - - # check ipv6/ip6tables configuration - # if [ -n "${adb_wanif6}" ] then - if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev6}" ] + check="$(${adb_iptv6} -w -vnL | grep -Fo "adb-")" + if [ -z "${check}" ] 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 tcp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53" - 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" "2" "nat" "-d ${adb_nullipv6} -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" "2" "fwd" "-d ${adb_nullipv6} -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" "2" "out" "-d ${adb_nullipv6} -j REJECT --reject-with icmp6-addr-unreachable" - if [ "${fw_done}" = "true" ] - then - f_log "created volatile IPv6 firewall ruleset" - fw_done="false" + if [ $((adb_forcedns)) -eq 1 ] && [ -n "${adb_landev6}" ] + 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 tcp --dport 53 -j DNAT --to-destination [${adb_ipv6}]:53" + fi + 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" "-p tcp --dport 443 -j DNAT --to-destination [${adb_ipv6}]:${adb_nullportssl}" + 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" "-j REJECT --reject-with icmp6-addr-unreachable" + 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" "-j REJECT --reject-with icmp6-addr-unreachable" fi fi + if [ "${fw_done}" = "true" ] + then + f_log "created volatile firewall rulesets" + fw_done="false" + fi - # check volatile adblock uhttpd instance configuration + # check volatile uhttpd instance configuration # check="$(pgrep -f "uhttpd -h /www/adblock")" if [ -z "${check}" ] then if [ -n "${adb_wanif4}" ] && [ -n "${adb_wanif6}" ] 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}" - 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_80" "1" "-p ${adb_ipv4}:${adb_nullport} -p [${adb_ipv6}]:${adb_nullport}" + f_uhttpd "adbIPv4+6_443" "0" "-p ${adb_ipv4}:${adb_nullportssl} -p [${adb_ipv6}]:${adb_nullportssl}" elif [ -n "${adb_wanif4}" ] then - uhttpd -h "/www/adblock" -N 25 -T 1 -k 0 -t 0 -R -D -S -E "/index.html" -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_80" "1" "-p ${adb_ipv4}:${adb_nullport}" + f_uhttpd "adbIPv4_443" "0" "-p ${adb_ipv4}:${adb_nullportssl}" else - uhttpd -h "/www/adblock" -N 25 -T 1 -k 0 -t 0 -R -D -S -E "/index.html" -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_80" "1" "-p [${adb_ipv6}]:${adb_nullport}" + f_uhttpd "adbIPv6_443" "0" "-p [${adb_ipv6}]:${adb_nullportssl}" fi - rc=${?} - if [ $((rc)) -eq 0 ] + if [ "${uhttpd_done}" = "true" ] then f_log "created volatile uhttpd instances" - else - f_log "failed to initialize volatile uhttpd instances" "${rc}" - f_exit + uhttpd_done="false" fi fi @@ -501,6 +499,24 @@ f_firewall() 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() @@ -576,7 +592,7 @@ f_rmconfig() { local src_name local rm_done="${1}" - + for src_name in ${rm_done} do src_name="${src_name#*.}" @@ -633,10 +649,7 @@ f_exit() f_log "domain adblock processing finished successfully (${adb_scriptver}, ${adb_sysver}, ${lastrun})" elif [ $((rc)) -gt 0 ] then - if [ -n "$(${adb_uci} -q changes adblock)" ] - then - "${adb_uci}" -q revert "adblock" - fi + "${adb_uci}" -q revert "adblock" f_log "domain adblock processing failed (${adb_scriptver}, ${adb_sysver}, ${lastrun})" else rc=0 diff --git a/net/adblock/files/adblock-update.sh b/net/adblock/files/adblock-update.sh index e94a53d11d..d431876ece 100755 --- a/net/adblock/files/adblock-update.sh +++ b/net/adblock/files/adblock-update.sh @@ -28,7 +28,7 @@ fi # get current directory and set script/config version # adb_scriptdir="${0%/*}" -adb_scriptver="1.2.0" +adb_scriptver="1.2.1" adb_mincfgver="2.2" # source in adblock function library @@ -99,7 +99,7 @@ do if [ -z "${url_time}" ] then url_time="$(date)" - f_log " online timestamp not received, current date will be used" + f_log " no online timestamp received" fi if [ -z "${list_time}" ] || [ "${list_time}" != "${url_time}" ] || [ ! -r "${adb_dnsfile}" ] ||\ ([ "${backup_ok}" = "true" ] && [ ! -r "${adb_dir_backup}/${adb_dnsprefix}.${src_name}.gz" ]) diff --git a/net/adblock/files/adblock.init b/net/adblock/files/adblock.init index 9af13ca17f..7dcbcaa7c9 100755 --- a/net/adblock/files/adblock.init +++ b/net/adblock/files/adblock.init @@ -2,12 +2,11 @@ # START=99 +PATH="/usr/sbin:/usr/bin:/sbin:/bin" EXTRA_COMMANDS="toggle cfgup" EXTRA_HELP=" toggle Toggle adblocking 'on' or 'off' cfgup Update the adblock configuration file" -PATH="/usr/sbin:/usr/bin:/sbin:/bin" - adb_debug=0 if [ $((adb_debug)) -eq 0 ] then @@ -74,7 +73,7 @@ reload() stop() { cfg_check="$(${adb_uci} -q get "adblock.global.adb_overall_count")" - if [ -n "${cfg_check}" ] + if [ -n "${cfg_check}" ] && [ -z "${restart}" ] then . "/lib/functions.sh" config_load adblock @@ -83,12 +82,9 @@ stop() "${adb_uci}" -q delete "adblock.global.adb_overall_count" "${adb_uci}" -q delete "adblock.global.adb_percentage" "${adb_uci}" -q delete "adblock.global.adb_lastrun" - if [ -z "${restart}" ] - then - "${adb_uci}" -q commit "adblock" - fi + "${adb_uci}" -q commit "adblock" fi - fw_check="$(iptables -w -t nat -nL | grep -F "adb-")" + fw_check="$(iptables -w -vnL | grep -Fo "adb-")" if [ -n "${fw_check}" ] && [ -z "${restart}" ] then iptables-save -t nat | grep -Fv -- "adb-" | iptables-restore