1
Tutorials and FAQs / Re: Blocking ads using only unbound
« on: January 29, 2020, 06:31:46 am »
Hello there
yesterday i got following error:
So i update the script to replace more then one dot with a single dot.
Thanks Itow
--Edit 30.01.20
fix Typos and few Issues add new checks
yesterday i got following error:
Code: [Select]
[1580222648] unbound-checkconf[27733:0] error: cannot parse name queda212..duckdns.org
[1580222648] unbound-checkconf[27733:0] error: bad zone name queda212..duckdns.org static
[1580222648] unbound-checkconf[27733:0] fatal error: failed local-zone, local-data configuration
So i update the script to replace more then one dot with a single dot.
Code: [Select]
#!/usr/local/bin/bash
oldtmp="$(find /tmp -type f -name 'tmp.*' | wc -l)"
if [ $oldtmp -gt 0 ]; then
echo Found $oldtmp old tmp-files.
echo Delete the old Files
find /tmp -type f -name 'tmp.*' -exec rm -f {} \;
fi
#Erstelle Temp Datein
tmp1="$(mktemp)"
tmp2="$(mktemp)"
tmp3="$(mktemp)"
tmp4="$(mktemp)"
tmp5="$(mktemp)"
tmp6="$(mktemp)"
tmp7="$(mktemp)"
file="/var/unbound/adblocklist.conf"
filebackup="/var/unbound/adblocklist.bck"
whitelist="/root/whitelist"
blacklist="/root/blacklist"
actionfile="/usr/local/opnsense/service/conf/actions.d/actions_AdBlock.conf"
# Backup der alten Blocklist
if [ -f $file ]; then
mv $file $filebackup
else
touch $filebackup
echo '# Empty File' > $filebackup
fi
# Pruefe Custom White and Blacklist
if ! [ -f $whitelist ]; then
touch $whitelist
echo '# Domains nach dieser Zeile einfuegen. Diese Zeile nicht loeschen!' > $whitelist
fi
if ! [ -f $blacklist ]; then
touch $blacklist
echo '# Domains nach dieser Zeile einfuegen. Diese Zeile nicht loeschen!' > $blacklist
fi
# Pruefe und Erstelle Actionfile fuer Cron
if ! [ -f $actionfile ]; then
touch $actionfile
printf "[reload]\ncommand:/root/adblockscript\nparameter:\ntype:script\nmessage:Update AdBlocklist and load them\ndescription:Update AdBlocklist and load them" >> $actionfile
service configd restart
echo 'Now you can configure the Cron Job via Web Interface'
fi
# Download Blocklist
{ \
wget -qO- https://raw.githubusercontent.com/EnergizedProtection/block/master/ultimate/formats/domains.txt; \
wget -qO- https://raw.githubusercontent.com/EnergizedProtection/block/master/extensions/xtreme/formats/domains.txt; \
wget -qO- https://raw.githubusercontent.com/EnergizedProtection/block/master/extensions/regional/formats/domains.txt; \
cat $blacklist; \
} > $tmp1
# Download Whitelist
{ \
wget -qO- https://raw.githubusercontent.com/EnergizedProtection/unblock/master/basic/formats/domains.txt; \
cat $whitelist; \
} > $tmp4
# Saeubere die Blocklisten
sed -i '' -e '/\//d;/:/d;/(/d;/|/d;/\[/d;/\]/d;/#/d;/^$/d;/[\]/d' $tmp1
cat $tmp1 | sed -r 's/\.+/\./' | tr -d '\r' >> $tmp2
sed -i '' -e 's/ *$//' $tmp2 && sort -uf $tmp2 |tee |uniq -i > $tmp3
sed -i '' -e '/^$/d' $tmp3
rm $tmp1 $tmp2
# Saeubere die Whitelist
sed -i '' -e '/\//d;/:/d;/(/d;/|/d;/\[/d;/\]/d;/#/d;/^$/d;/[\]/d' $tmp4
cat $tmp4 | sed -r 's/\.+/\./' | tr -d '\r' >> $tmp5
sed -i '' -e 's/ *$//' $tmp5 && sort -uf $tmp5 |tee |uniq -i > $tmp6
sed -i '' -e '/^$/d' $tmp6
rm $tmp4 $tmp5
# Fuege Blocklist und Whitelist zusammen
comm -23 $tmp3 $tmp6 > $tmp7
rm $tmp3 $tmp6
sed -i '' -e '/^$/d' $tmp7
awk '$0="local-zone: \""$0"\" static"' $tmp7 > $file
rm $tmp7
# Check Unbound Config
if ! unbound-checkconf /var/unbound/unbound.conf; then
rm $file
echo Nutze alte Blockliste
mv $filebackup $file
exit 1
else
# echo Config ist Okey
if ! grep -cq "include: $file" /var/unbound/unbound.conf; then
echo Please add "include: $file" to your custom Unbound settings.
fi
rm $filebackup
fi
if [ "$1" == info ]; then
domains=$(awk '!/^#/ && !/^$/{c++}END{print c}' $file | awk '{ len=length($0); res=""; for (i=0;i<=len;i++) { res=substr($0,len-i+1,1) res; if (i > 0 && i < len && i % 3 == 0) { res = "," res } }; print res }')
echo "Anzahl zu Blockender Domains = $domains"
fi
# Aendere Benutzer und Gruppe
chown unbound:unbound $file
# Starte Unbound neu
pluginctl dns
exit 0
Thanks Itow
--Edit 30.01.20
fix Typos and few Issues add new checks