Last active
October 22, 2023 11:53
-
-
Save BlackDex/492a9cfc6a0ba65ed53c8cd9a2fa9660 to your computer and use it in GitHub Desktop.
PiHole CNAME cloacking updater using NextDNS blocklist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/nextdns/cname-cloaking-blocklist | |
# Add this script to /etc/cron.weekly and make it executable | |
file=/tmp/pihole-nextdns.$$ | |
Cleanup() { | |
rm -f $file | |
} | |
trap Cleanup EXIT | |
wget -q https://raw.githubusercontent.com/nextdns/cname-cloaking-blocklist/master/domains -O $file | |
# Clear old list | |
# echo "SQL: DELETE FROM domainlist WHERE type=3 AND comment='NextDNS CNAME list';" | |
sqlite3 /etc/pihole/gravity.db "DELETE FROM domainlist WHERE type=3 AND comment='NextDNS CNAME list';" | |
while read -r domain | |
do | |
if ! [[ "$domain" == \#* ]]; then | |
if [ ! -z "$domain" ]; then | |
# echo -ne "\n\nDomain: ${domain}\n" | |
regex=(\\.\|^)${domain%.*}\\.${domain##*.}$ | |
# echo "Regex: ${regex}" | |
# echo "SQL: INSERT OR IGNORE INTO domainlist (type, domain, enabled, comment) VALUES (3, \"$regex\", 1, 'NextDNS CNAME list');" | |
sqlite3 /etc/pihole/gravity.db "INSERT OR IGNORE INTO domainlist (type, domain, enabled, comment) VALUES (3, \"$regex\", 1, 'NextDNS CNAME list');" | |
fi | |
fi | |
done < $file | |
/usr/local/bin/pihole restartdns reload-lists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment