Skip to content

Instantly share code, notes, and snippets.

@neta1
Last active February 27, 2017 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neta1/d2548c22fc37159182098ab6a970c81d to your computer and use it in GitHub Desktop.
Save neta1/d2548c22fc37159182098ab6a970c81d to your computer and use it in GitHub Desktop.
Squid用の広告ホストリストを更新するやつ
#!/bin/sh
CURDIR=$(pwd)
SCRDIR=$(dirname `readlink -f ${BASH_SOURCE:-$0}`)
cd $SCRDIR
mv -f merged.txt merged.old
dl()
{
curl -LRfsS --compressed -z "$1" -o "$1" "$2"
sed -e "s/\r//g" -e "s/#.*$//g" -e "s/^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\s*//" -e "s/\s*$//" -e "/^$/d" -e "/localhost$/d" "$1" >> merged.txt
}
dl hosts2ch.txt https://sites.google.com/site/hosts2ch/ja
dl winhelp2002.txt http://winhelp2002.mvps.org/hosts.txt
dl adaway.txt https://adaway.org/hosts.txt
dl hosts-file.txt https://hosts-file.net/ad_servers.txt
sed -e "/^$/d" blacklist.txt >> merged.txt
sort merged.txt | uniq > merged.tmp && mv -f merged.tmp merged.txt
systemctl reload squid.service
cd $CURDIR
# squid.conf example
acl localnet src 192.168.0.0/24
acl localnet src fe80::/10
acl ad_black dstdomain "/path/to/adlists/merged.txt"
acl ad_white dstdomain "/path/to/adlists/whitelist.txt"
http_access deny ad_black !ad_white
http_access allow localnet
http_access deny all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment