Skip to content

Instantly share code, notes, and snippets.

@takuya
Last active July 26, 2022 17:10
Show Gist options
  • Save takuya/982fa69669c880ecc8486e49b64c1767 to your computer and use it in GitHub Desktop.
Save takuya/982fa69669c880ecc8486e49b64c1767 to your computer and use it in GitHub Desktop.
unboundのdnsブロッキングリストを更新する。
#!/usr/bin/env sh
## @since 2020-05-15
## @last 2021-01-05
## @author takuya
## unbound にブロッキング
## ブロッキングするURLを定期的に更新する
function update_domain_lists(){
update280blocker
updateYoutubeAdblocker
}
function geneate_conf(){
URL=$1
OUTPUT=$2
curl -sL $URL \
| sed -e "s/\r//" \
| grep -E '^[a-z0-9]' \
| awk '{print "local-zone: \""$1".\" static"}' \
| sort \
| uniq \
> $OUTPUT
}
function checkHTTPStatusIs200(){
URL=$1
RET=$(curl -IL -s -o /dev/null -w '%{http_code}' $URL)
[[ $RET == 200 ]];
}
function update280blocker () {
URL=https://280blocker.net/files/280blocker_domain_$(date +%Y%m).txt
## mirror
## URL=https://raw.githubusercontent.com/junkurihara/280blocker_domain-mirror/master/280blocker_domain.txt
OUTPUT=/etc/unbound/280blocker-list.conf
if ! checkHTTPStatusIs200 $URL ; then
echo failed;
return 1
fi
##
geneate_conf $URL $OUTPUT
}
function updateYoutubeAdblocker () {
URL=https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt
OUTPUT=/etc/unbound/youtube-ad.conf
##
if ! checkHTTPStatusIs200 $URL ; then
echo failed;
return 1
fi
##
geneate_conf $URL $OUTPUT
}
function restart_unbund(){
[ -e /etc/init.d/unbound ] &&
/etc/init.d/unbound restart
}
function restart_dnsmasq(){
[ -e /etc/init.d/dnsmasq ] &&
/etc/init.d/dnsmasq restart 2>&1 > /dev/null
}
function main(){
update_domain_lists &&
restart_unbund &&
restart_dnsmasq
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment