adblock: update 1.1.2
* remove hardcoded paths for system tools like iptables, uci & fetch (wget) * support openwrt & lede spin-off * cosmetics & cleanups Signed-off-by: Dirk Brenken <openwrt@brenken.org>
This commit is contained in:
parent
262f4551e2
commit
7b4ad33255
4 changed files with 41 additions and 39 deletions
|
@ -7,7 +7,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=adblock
|
PKG_NAME:=adblock
|
||||||
PKG_VERSION:=1.1.1
|
PKG_VERSION:=1.1.2
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_LICENSE:=GPL-3.0+
|
PKG_LICENSE:=GPL-3.0+
|
||||||
PKG_MAINTAINER:=Dirk Brenken <openwrt@brenken.org>
|
PKG_MAINTAINER:=Dirk Brenken <openwrt@brenken.org>
|
||||||
|
|
|
@ -147,7 +147,7 @@ This rule removes _all_ domains from the blocklists with this string in it, i.e.
|
||||||
photos.daily-deals.analoganalytics.com
|
photos.daily-deals.analoganalytics.com
|
||||||
adblockanalytics.com
|
adblockanalytics.com
|
||||||
|
|
||||||
**example to add a new blocklist sources:**
|
**example to add a new blocklist source:**
|
||||||
<pre><code>
|
<pre><code>
|
||||||
1. the easy way ...
|
1. the easy way ...
|
||||||
example: https://easylist-downloads.adblockplus.org/rolist+easylist.txt
|
example: https://easylist-downloads.adblockplus.org/rolist+easylist.txt
|
||||||
|
|
|
@ -6,25 +6,25 @@
|
||||||
#
|
#
|
||||||
f_envload()
|
f_envload()
|
||||||
{
|
{
|
||||||
# source in openwrt function library
|
# source in system function library
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions.sh" ]
|
if [ -r "/lib/functions.sh" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions.sh"
|
. "/lib/functions.sh"
|
||||||
else
|
else
|
||||||
rc=110
|
rc=110
|
||||||
f_log "openwrt function library not found" "${rc}"
|
f_log "system function library not found" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# source in openwrt network library
|
# source in system network library
|
||||||
#
|
#
|
||||||
if [ -r "/lib/functions/network.sh" ]
|
if [ -r "/lib/functions/network.sh" ]
|
||||||
then
|
then
|
||||||
. "/lib/functions/network.sh"
|
. "/lib/functions/network.sh"
|
||||||
else
|
else
|
||||||
rc=115
|
rc=115
|
||||||
f_log "openwrt network library not found" "${rc}"
|
f_log "system network library not found" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -89,13 +89,13 @@ f_envload()
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get list with all installed openwrt packages
|
# get list with all installed packages
|
||||||
#
|
#
|
||||||
pkg_list="$(opkg list-installed)"
|
pkg_list="$(opkg list-installed)"
|
||||||
if [ -z "${pkg_list}" ]
|
if [ -z "${pkg_list}" ]
|
||||||
then
|
then
|
||||||
rc=120
|
rc=120
|
||||||
f_log "empty openwrt package list" "${rc}"
|
f_log "empty package list" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -127,8 +127,10 @@ f_envload()
|
||||||
adb_tmpdir="$(mktemp -p /tmp -d)"
|
adb_tmpdir="$(mktemp -p /tmp -d)"
|
||||||
adb_dnsdir="/tmp/dnsmasq.d"
|
adb_dnsdir="/tmp/dnsmasq.d"
|
||||||
adb_dnsprefix="adb_list"
|
adb_dnsprefix="adb_list"
|
||||||
adb_fetch="/usr/bin/wget"
|
adb_uci="$(which uci)"
|
||||||
adb_uci="/sbin/uci"
|
adb_iptv4="$(which iptables)"
|
||||||
|
adb_iptv6="$(which ip6tables)"
|
||||||
|
adb_fetch="$(which wget-ssl)"
|
||||||
unset adb_srclist adb_revsrclist adb_errsrclist
|
unset adb_srclist adb_revsrclist adb_errsrclist
|
||||||
|
|
||||||
# get lan ip addresses
|
# get lan ip addresses
|
||||||
|
@ -137,10 +139,15 @@ f_envload()
|
||||||
network_get_ipaddr6 adb_ipv6 "${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=135
|
rc=130
|
||||||
f_log "no valid IPv4/IPv6 configuration found (${adb_lanif}), please set 'adb_lanif' manually" "${rc}"
|
f_log "no valid IPv4/IPv6 configuration found (${adb_lanif}), please set 'adb_lanif' manually" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# get system release level
|
||||||
|
#
|
||||||
|
adb_sysver="$(printf "${pkg_list}" | grep "^base-files -")"
|
||||||
|
adb_sysver="${adb_sysver##*-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# f_envcheck: check/set environment prerequisites
|
# f_envcheck: check/set environment prerequisites
|
||||||
|
@ -161,6 +168,8 @@ f_envcheck()
|
||||||
|
|
||||||
# check general package dependencies
|
# check general package dependencies
|
||||||
#
|
#
|
||||||
|
f_depend "busybox"
|
||||||
|
f_depend "uci"
|
||||||
f_depend "uhttpd"
|
f_depend "uhttpd"
|
||||||
f_depend "wget"
|
f_depend "wget"
|
||||||
f_depend "iptables"
|
f_depend "iptables"
|
||||||
|
@ -203,7 +212,7 @@ f_envcheck()
|
||||||
then
|
then
|
||||||
if [ $((av_space)) -le 2000 ]
|
if [ $((av_space)) -le 2000 ]
|
||||||
then
|
then
|
||||||
rc=140
|
rc=135
|
||||||
f_log "not enough free space in '${adb_tmpdir}' (avail. ${av_space} kb)" "${rc}"
|
f_log "not enough free space in '${adb_tmpdir}' (avail. ${av_space} kb)" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
else
|
else
|
||||||
|
@ -211,7 +220,7 @@ f_envcheck()
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
rc=145
|
rc=140
|
||||||
f_log "temp directory not found" "${rc}"
|
f_log "temp directory not found" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
@ -262,17 +271,17 @@ 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
|
||||||
else
|
else
|
||||||
rc=150
|
rc=145
|
||||||
f_log "please enable the local dns server to use adblock" "${rc}"
|
f_log "please enable the local dns server to use adblock" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check running firewall
|
# check running firewall
|
||||||
#
|
#
|
||||||
check="$(/usr/sbin/iptables -vnL | grep -F "DROP")"
|
check="$(${adb_iptv4} -vnL | grep -F "DROP")"
|
||||||
if [ -z "${check}" ]
|
if [ -z "${check}" ]
|
||||||
then
|
then
|
||||||
rc=155
|
rc=150
|
||||||
f_log "please enable the local firewall to use adblock" "${rc}"
|
f_log "please enable the local firewall to use adblock" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
@ -367,7 +376,7 @@ f_depend()
|
||||||
check="$(printf "${pkg_list}" | grep "^${package} -")"
|
check="$(printf "${pkg_list}" | grep "^${package} -")"
|
||||||
if [ -z "${check}" ]
|
if [ -z "${check}" ]
|
||||||
then
|
then
|
||||||
rc=160
|
rc=155
|
||||||
f_log "package '${package}' not found" "${rc}"
|
f_log "package '${package}' not found" "${rc}"
|
||||||
f_exit
|
f_exit
|
||||||
fi
|
fi
|
||||||
|
@ -377,9 +386,7 @@ f_depend()
|
||||||
#
|
#
|
||||||
f_firewall()
|
f_firewall()
|
||||||
{
|
{
|
||||||
local ipt
|
local ipt="${adb_iptv4}"
|
||||||
local iptv4="/usr/sbin/iptables"
|
|
||||||
local iptv6="/usr/sbin/ip6tables"
|
|
||||||
local proto="${1}"
|
local proto="${1}"
|
||||||
local table="${2}"
|
local table="${2}"
|
||||||
local ctype="${3}"
|
local ctype="${3}"
|
||||||
|
@ -387,13 +394,11 @@ f_firewall()
|
||||||
local notes="${5}"
|
local notes="${5}"
|
||||||
local rules="${6}"
|
local rules="${6}"
|
||||||
|
|
||||||
# select appropriate iptables executable
|
# select appropriate iptables executable for IPv6
|
||||||
#
|
#
|
||||||
if [ "${proto}" = "IPv4" ]
|
if [ "${proto}" = "IPv6" ]
|
||||||
then
|
then
|
||||||
ipt="${iptv4}"
|
ipt="${adb_iptv6}"
|
||||||
else
|
|
||||||
ipt="${iptv6}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check whether iptables rule already applied and proceed accordingly
|
# check whether iptables rule already applied and proceed accordingly
|
||||||
|
@ -558,7 +563,7 @@ f_restore()
|
||||||
f_cntconfig
|
f_cntconfig
|
||||||
f_log "adblock lists with overall ${adb_count} domains loaded"
|
f_log "adblock lists with overall ${adb_count} domains loaded"
|
||||||
else
|
else
|
||||||
rc=165
|
rc=160
|
||||||
f_log "dnsmasq restart failed, please check 'logread' output" "${rc}"
|
f_log "dnsmasq restart failed, please check 'logread' output" "${rc}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -571,8 +576,6 @@ f_exit()
|
||||||
{
|
{
|
||||||
local ipv4_adblock=0
|
local ipv4_adblock=0
|
||||||
local ipv6_adblock=0
|
local ipv6_adblock=0
|
||||||
local iptv4="/usr/sbin/iptables"
|
|
||||||
local iptv6="/usr/sbin/ip6tables"
|
|
||||||
|
|
||||||
# delete temporary files & directories
|
# delete temporary files & directories
|
||||||
#
|
#
|
||||||
|
@ -591,27 +594,27 @@ f_exit()
|
||||||
then
|
then
|
||||||
if [ -n "${adb_wanif4}" ]
|
if [ -n "${adb_wanif4}" ]
|
||||||
then
|
then
|
||||||
ipv4_adblock="$(${iptv4} -t nat -vnL | awk '$11 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
|
ipv4_adblock="$(${adb_iptv4} -t nat -vnL | awk '$11 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
|
||||||
ipv4_adblock="$((${ipv4_adblock} + $(${iptv4} -vnL | awk '$11 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
|
ipv4_adblock="$((${ipv4_adblock} + $(${adb_iptv4} -vnL | awk '$11 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
|
||||||
fi
|
fi
|
||||||
if [ -n "${adb_wanif6}" ]
|
if [ -n "${adb_wanif6}" ]
|
||||||
then
|
then
|
||||||
ipv6_adblock="$(${iptv6} -t nat -vnL | awk '$10 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
|
ipv6_adblock="$(${adb_iptv6} -t nat -vnL | awk '$10 ~ /^adb-nat$/ {sum += $1} END {printf sum}')"
|
||||||
ipv6_adblock="$((${ipv6_adblock} + $(${iptv6} -vnL | awk '$10 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
|
ipv6_adblock="$((${ipv6_adblock} + $(${adb_iptv6} -vnL | awk '$10 ~ /^adb-(fwd|out)$/ {sum += $1} END {printf sum}')))"
|
||||||
fi
|
fi
|
||||||
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
||||||
then
|
then
|
||||||
${adb_uci} -q commit "adblock"
|
${adb_uci} -q commit "adblock"
|
||||||
fi
|
fi
|
||||||
f_log "firewall statistics (IPv4/IPv6): ${ipv4_adblock}/${ipv6_adblock} ad related packets blocked"
|
f_log "firewall statistics (IPv4/IPv6): ${ipv4_adblock}/${ipv6_adblock} ad related packets blocked"
|
||||||
f_log "domain adblock processing finished successfully (${adb_scriptver}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
f_log "domain adblock processing finished successfully (${adb_scriptver}, ${adb_sysver}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
||||||
elif [ $((rc)) -gt 0 ]
|
elif [ $((rc)) -gt 0 ]
|
||||||
then
|
then
|
||||||
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
if [ -n "$(${adb_uci} -q changes adblock)" ]
|
||||||
then
|
then
|
||||||
${adb_uci} -q revert "adblock"
|
${adb_uci} -q revert "adblock"
|
||||||
fi
|
fi
|
||||||
f_log "domain adblock processing failed (${adb_scriptver}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
f_log "domain adblock processing failed (${adb_scriptver}, ${adb_sysver}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
||||||
else
|
else
|
||||||
rc=0
|
rc=0
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# ad/abuse domain blocking script for dnsmasq/openwrt
|
# dns based ad/abuse domain blocking script
|
||||||
# written by Dirk Brenken (openwrt@brenken.org)
|
# written by Dirk Brenken (openwrt@brenken.org)
|
||||||
|
|
||||||
# This is free software, licensed under the GNU General Public License v3.
|
# This is free software, licensed under the GNU General Public License v3.
|
||||||
|
@ -33,11 +33,10 @@ else
|
||||||
printf "${adb_pid}" > "${adb_pidfile}"
|
printf "${adb_pid}" > "${adb_pidfile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get current directory, script- and openwrt version
|
# get current directory and script version
|
||||||
#
|
#
|
||||||
adb_scriptdir="${0%/*}"
|
adb_scriptdir="${0%/*}"
|
||||||
adb_scriptver="1.1.1"
|
adb_scriptver="1.1.2"
|
||||||
openwrt_version="$(cat /etc/openwrt_version)"
|
|
||||||
|
|
||||||
# source in adblock function library
|
# source in adblock function library
|
||||||
#
|
#
|
||||||
|
@ -61,7 +60,7 @@ f_envload
|
||||||
|
|
||||||
# start logging
|
# start logging
|
||||||
#
|
#
|
||||||
f_log "domain adblock processing started (${adb_scriptver}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
f_log "domain adblock processing started (${adb_scriptver}, ${adb_sysver}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
|
||||||
|
|
||||||
# check environment
|
# check environment
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue