-
-
Save funasoul/ac85187242cb49d0e212d0862fb0f794 to your computer and use it in GitHub Desktop.
unboundのdnsブロッキングリストを更新する。for OpenBSD
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 zsh | |
## @since 2020-05-15 | |
## @last 2021-01-05 | |
## @author takuya | |
## unbound にブロッキング | |
## ブロッキングするURLを定期的に更新する | |
function update_domain_lists(){ | |
update280blocker | |
# updateYoutubeAdblocker (https://github.com/anudeepND/youtubeadsblacklist is dead) | |
} | |
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=/var/unbound/etc/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=/var/unbound/etc/youtube-ad.conf | |
## | |
if ! checkHTTPStatusIs200 $URL ; then | |
echo failed; | |
return 1 | |
fi | |
## | |
geneate_conf $URL $OUTPUT | |
} | |
function restart_unbund(){ | |
/usr/sbin/rcctl ls on | /usr/bin/grep -q unbound && | |
/usr/sbin/rcctl restart unbound | |
} | |
function restart_dnsmasq(){ | |
/usr/sbin/rcctl ls on | /usr/bin/grep -q dnsmasq && | |
/usr/sbin/rcctl restart dnsmasq | |
} | |
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