diff --git a/README.md b/README.md index 0b98d116..9a0a9ed6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,27 @@ -pi-hole -======= +# Raspberry Pi Ad Blocker +**A black hole for ads, hence Pi-hole** -Raspberry Pi Ad Blocker (A black hole for ads, hence Pi-hole) +![Pi-hole](http://i.imgur.com/wd5ltCU.png) + +The Pi-hole is a DNS/Web server that will **block ads for any device on your network**. + +## Coverage +Featured on [MakeUseOf](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) and [Lifehacker](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)! + +## Automated Install +### Make sure to set a **static** IP address before running this!! +On a clean installation of Raspbian, you can run this command to **auto-install the Pi-hole**. Once installed, configure any device to use the Raspberry Pi as your DNS server and the ads will be blocked. + +```curl -s "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/automated%20install/basic-install.sh" | bash``` + +## Gravity +The [gravity.sh](https://github.com/jacobsalmela/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 900,000 entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0). + +## Whitelist and blacklist +You can add a `whitelist.txt` or `blacklist.txt` in `/etc/pihole/` and the script will apply those files automatically. + +### How It Works +A technical and detailed description can be found [here](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0)! + +## Other Operating Systems +This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install only works for a clean install of Raspiban right now since that is how the project originated. \ No newline at end of file diff --git a/advanced/GIFs/25Bytes.gif b/advanced/GIFs/25Bytes.gif new file mode 100644 index 00000000..472727f2 Binary files /dev/null and b/advanced/GIFs/25Bytes.gif differ diff --git a/advanced/GIFs/26Bytes.gif b/advanced/GIFs/26Bytes.gif new file mode 100644 index 00000000..264e471a Binary files /dev/null and b/advanced/GIFs/26Bytes.gif differ diff --git a/advanced/GIFs/37Bytes.gif b/advanced/GIFs/37Bytes.gif new file mode 100644 index 00000000..b3aa80d8 Binary files /dev/null and b/advanced/GIFs/37Bytes.gif differ diff --git a/advanced/GIFs/43Bytes.gif b/advanced/GIFs/43Bytes.gif new file mode 100644 index 00000000..9884f476 Binary files /dev/null and b/advanced/GIFs/43Bytes.gif differ diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh new file mode 100755 index 00000000..353fc125 --- /dev/null +++ b/advanced/Scripts/chronometer.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Infinite loop that can be used to display ad domains on a Pi touch screen +# Continually watch the log file and display ad domains that are blocked being blocked +# Set the pi user to log in automatically and add run this script from .bashrc +clear +echo "" +echo " +-+-+-+-+-+-+-+ " +echo " Pi-hole " +echo " +-+-+-+-+-+-+-+ " +echo "" +echo " A black hole for" +echo " Internet Ads " +echo "" +echo " http://pi-hole.net" +echo "" +echo " $(ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d':' -f2)" +sleep 7 +# Look for only the entries that contain /etc/hosts, indicating the domain was found to be an advertisement +tail -f /var/log/daemon.log | awk '/\/etc\/hosts/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/hosts") print $7; else;}' \ No newline at end of file diff --git a/advanced/dnsmasq.conf b/advanced/dnsmasq.conf index 70d062f6..4340f83a 100644 --- a/advanced/dnsmasq.conf +++ b/advanced/dnsmasq.conf @@ -1,9 +1,9 @@ domain-needed bogus-priv no-resolv -server=127.0.0.1 server=8.8.8.8 server=8.8.4.4 interface=eth0 +listen-address=127.0.0.1 cache-size=10000 log-queries \ No newline at end of file diff --git a/advanced/enable-dns.sh b/advanced/enable-dns.sh deleted file mode 100644 index 0d04ed0f..00000000 --- a/advanced/enable-dns.sh +++ /dev/null @@ -1,8 +0,0 @@ -# !/bin/bash -# Download the ad list -sudo /usr/local/bin/gravity.sh - -# Enable DNS and start blocking ads -sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo mv /etc/dnsmasq.conf.pihole /etc/dnsmasq.conf -sudo service dnsmasq start diff --git a/advanced/gravity.sh b/advanced/gravity.sh deleted file mode 100755 index e9fa14bc..00000000 --- a/advanced/gravity.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -# /usr/local/bin/gravity.sh - -# URL to pull list of known ad servers from -adListURL="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" - -# Address to send ads to -piholeIP="127.0.0.1" - -# Where the list of ad servers are stored once downloaded -# Any file in /etc/dnsmasq.d is loaded automatically when the service starts -adFile="/etc/dnsmasq.d/adList.conf" - -# The temporary file for holding -eventHorizion="/etc/dnsmasq.d/adList.conf.tmp" - -# Parses out the default 127.0.0.1 address and replaces it with the IP where ads will be sent -curl $adListURL | sed "s/127\.0\.0\.1/$piholeIP/" > $eventHorizion - -sleep 10 - -# If the temporary list of ad servers already exists (the eventHorizion) -if [ -f "$eventHorizion" ];then - # Then replace it as the new ad file - mv -f $eventHorizion $adFile -else - echo "Error building the ad list, please try again." - exit 1 -fi \ No newline at end of file diff --git a/index.html b/advanced/index.html similarity index 65% rename from index.html rename to advanced/index.html index aa7b9c93..6bfc7988 100644 --- a/index.html +++ b/advanced/index.html @@ -1,6 +1,4 @@ - - \ No newline at end of file diff --git a/advanced/lighttpd.conf b/advanced/lighttpd.conf index 3c23a2b9..1c3ed076 100644 --- a/advanced/lighttpd.conf +++ b/advanced/lighttpd.conf @@ -1,12 +1,10 @@ server.modules = ( - "mod_access", - "mod_alias", + "mod_expire", "mod_compress", "mod_redirect", - "mod_auth", "mod_rewrite" ) - + server.document-root = "/var/www" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error.log" @@ -14,22 +12,27 @@ server.pid-file = "/var/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" server.port = 80 - - + + index-file.names = ( "index.php", "index.html", "index.lighttpd.html" ) url.access-deny = ( "~", ".inc" ) static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) - + compress.cache-dir = "/var/cache/lighttpd/compress/" compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" ) - + # default listening port for IPv6 falls back to the IPv4 port include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl" - + +# Set access to 1 day for better query performance when the list gets so large +# http://jacobsalmela.com/raspberry-pi-block-ads-adtrap/#comment-2013820434 +$HTTP["url"] =~ "^/pihole/" { + expire.url = ("" => "access plus 1 days") +} + # Rewrites all URLs to the /var/www/pihole/index.html -# This should be a blank file (for speed) $HTTP["host"] =~ ".*" { url.rewrite = (".*" => "pihole/index.html") } \ No newline at end of file diff --git a/automated install/basic-install.sh b/automated instal/basic-install.sh similarity index 77% rename from automated install/basic-install.sh rename to automated instal/basic-install.sh index 9068d674..43f9d663 100755 --- a/automated install/basic-install.sh +++ b/automated instal/basic-install.sh @@ -18,18 +18,19 @@ echo " |_| |_| |_| |_|\___/|_|\___| " echo " " echo " Raspberry Pi Ad-blocker " echo " " -echo " Automated install " -echo " --Advanced-- " +echo "Set a static IP before running this!" +echo " " +echo " Press Enter when ready " echo " " -echo " " -sleep 2 +read echo "Updating the Pi..." sudo apt-get update sudo apt-get -y upgrade echo "Installing DNS..." -sudo apt-get -y install dnsutils dnsmasq +sudo apt-get -y install dnsmasq +sudo update-rc.d dnsmasq enable echo "Installing a Web server" sudo apt-get -y install lighttpd @@ -48,19 +49,16 @@ sudo mv /var/www/index.lighttpd.html /var/www/index.lighttpd.orig sudo curl -o /etc/dnsmasq.conf "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf" sudo curl -o /etc/lighttpd/lighttpd.conf "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf" sudo mkdir /var/www/pihole -sudo curl -o /var/www/pihole/index.html "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/index.html" - -echo "Turning services back on..." -sudo service dnsmasq start -sudo service lighttpd start +sudo curl -o /var/www/pihole/index.html "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html" echo "Locating the Pi-hole..." -sudo curl -o /usr/local/bin/gravity.sh "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity-adv.sh" +sudo curl -o /usr/local/bin/gravity.sh "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh" +sudo curl -o /usr/local/bin/chronometer.sh "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/scripts/chronometer.sh" sudo chmod 755 /usr/local/bin/gravity.sh +sudo chmod 755 /usr/local/bin/chronometer.sh + echo "Entering the event horizon..." sudo /usr/local/bin/gravity.sh -echo "Restarting services..." -sudo service dnsmasq restart -sudo service lighttpd restart - +echo "Restarting..." +sudo shutdown -r now \ No newline at end of file diff --git a/block hulu ads/dnsmasq.conf b/block hulu ads/dnsmasq.conf deleted file mode 100644 index 74dc2f18..00000000 --- a/block hulu ads/dnsmasq.conf +++ /dev/null @@ -1,12 +0,0 @@ -no-resolv -no-poll -server=/localnet/192.168.0.1 -server=/localnet/8.8.8.8 -server=/localnet/8.8.4.4 -domain-needed -interface=eth0 -strict-order -min-port=4096 -cache-size=10000 -log-queries -bogus-priv diff --git a/block hulu ads/hulAdList.conf b/block hulu ads/hulAdList.conf deleted file mode 100644 index 90e6cc4e..00000000 --- a/block hulu ads/hulAdList.conf +++ /dev/null @@ -1,2 +0,0 @@ -address=/ads.hulu.com/192.168.1.101 -address=/ads-v-darwin.hulu.com/192.168.1.101 \ No newline at end of file diff --git a/block hulu ads/index.html b/block hulu ads/index.html deleted file mode 100644 index ecf9666b..00000000 --- a/block hulu ads/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - -Pi-hole blocked an ad - - -

No ads here

- - \ No newline at end of file diff --git a/block hulu ads/lighttpd.conf b/block hulu ads/lighttpd.conf index 354a2d6d..b22f599e 100644 --- a/block hulu ads/lighttpd.conf +++ b/block hulu ads/lighttpd.conf @@ -3,7 +3,7 @@ server.modules = ( "mod_alias", "mod_compress", "mod_redirect", -# "mod_rewrite" + "mod_rewrite" ) server.document-root = "/var/www" @@ -27,6 +27,6 @@ include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port include_shell "/usr/share/lighttpd/create-mime.assign.pl" include_shell "/usr/share/lighttpd/include-conf-enabled.pl" -$HTTP["host"] =~ "ads.hulu.com|ads-v-darwin.hulu.com|" { - url.redirect = ( "^/(.*)" => "http://192.168.1.101:8200/MediaItems/19.mov") +$HTTP["host"] =~ "ads.hulu.com|ads-v-darwin.hulu.com" { + url.redirect = ( ".*" => "http://192.168.1.101:8200/MediaItems/19.mov") } diff --git a/block hulu ads/setup-resolv.sh b/block hulu ads/setup-resolv.sh deleted file mode 100644 index d894f12f..00000000 --- a/block hulu ads/setup-resolv.sh +++ /dev/null @@ -1,6 +0,0 @@ -# !/bin/bash -# DNS config file -# Run as a local script since modifying it will disconnect the Internet connection -sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo mv /etc/dnsmasq.conf.pihole /etc/dnsmasq.conf -sudo service dnsmasq start diff --git a/block hulu ads/setup.sh b/block hulu ads/setup.sh deleted file mode 100755 index 450fd43d..00000000 --- a/block hulu ads/setup.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -# Block Hulu Plus ads using a Raspberry Pi - -# Install with this command (from the Pi): -# -# curl -s https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/block%20hulu%20ads/setup.sh | bash -# -# Or run the commands below in order - -# Update the Pi -sudo apt-get update -#sudo apt-get -y upgrade - -# Install DNS -sudo apt-get -y install dnsutils dnsmasq -sudo service dnsmasq stop - -# Install Web server -sudo apt-get -y install lighttpd -sudo service lighttpd stop - -# Install streaming software -sudo apt-get -y install minidlna -sudo service minidlna stop - -# Configure Web server -#sudo lighty-enable-mod fastcgi-php -sudo chown www-data:www-data /var/www -sudo chmod 775 /var/www -sudo usermod -a -G www-data pi -sudo mv /var/www/index.lighttpd.html /var/www/index.lighttpd.orig -sudo curl -o /var/www/index.html "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/block%20hulu%20ads/index.html" -sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig -sudo curl -o /etc/lighttpd/lighttpd.conf "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/block%20hulu%20ads/lighttpd.conf" - -# Configure streaming service -sudo mv /etc/minidlna.conf /etc/minidlna.conf.orig -sudo mkdir /var/lib/minidlna/videos/ -sudo curl -o /etc/minidlna.conf "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/block%20hulu%20ads/minidlna.conf" -sudo service minidlna start -sudo curl -o /var/lib/minidlna/videos/pi-hole.mov "https://dl.dropboxusercontent.com/u/16366947/Documents/Videos/pi-hole.mov" -sudo service minidlna force-reload -tail /var/log/minidlna.log - -# Configure DNS -sudo curl -o /etc/dnsmasq.conf.pihole "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/dnsmasq.conf" -sudo curl -o /tmp/piholedns.sh "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/block%20hulu%20ads/setup-resolv.sh" -sudo chmod 755 /tmp/piholedns.sh - -# Download [advanced] ad-blocking script and then run it -# http://jacobsalmela.com/raspberry-pi-ad-blocker-advanced-setup/ -sudo curl -o /usr/local/bin/gravity.sh "https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity-adv.sh" -sudo chmod 755 /usr/local/bin/gravity.sh -clear -echo "" -echo "" -echo "" -echo "" -echo "Go get some coffee--this will take a while" -echo "" -echo "" -echo "" -echo "" -sleep 5 -sudo /usr/local/bin/gravity.sh -sudo service dnsmasq stop - -# Restart everything to apply all the changes -sudo service lighttpd start -sudo service minidlna start -sudo /tmp/piholedns.sh \ No newline at end of file diff --git a/dnsmasq.conf b/dnsmasq.conf deleted file mode 100644 index 39987b90..00000000 --- a/dnsmasq.conf +++ /dev/null @@ -1,6 +0,0 @@ -domain-needed -interface=eth0 -min-port=4096 -cache-size=10000 -log-queries -bogus-priv diff --git a/gravity-adv.sh b/gravity-adv.sh deleted file mode 100755 index 5de6c4d1..00000000 --- a/gravity-adv.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# The Pi-hole now blocks over 120,000 ad domains -# Address to send ads to (the RPi) -piholeIP="127.0.0.1" -# Optionally, uncomment to automatically detect the address. Thanks Gregg -#piholeIP=$(ifconfig eth0 | awk '/inet addr/{print substr($2,6)}') - -# Config file to hold URL rules -eventHorizion="/etc/dnsmasq.d/adList.conf" -whitelist=/etc/pihole/whitelist.txt - -# Create the pihole resource directory if it doesn't exist. Future files will be stored here -if [[ -d /etc/pihole/ ]];then - : -else - echo "Forming pihole directory..." - sudo mkdir /etc/pihole -fi - -echo "Getting yoyo ad list..." # Approximately 2452 domains at the time of writing -curl -s -d mimetype=plaintext -d hostformat=unixhosts http://pgl.yoyo.org/adservers/serverlist.php? | sort > /tmp/matter.txt -echo "Getting winhelp2002 ad list..." # 12985 domains -curl -s http://winhelp2002.mvps.org/hosts.txt | grep -v "#" | grep -v "127.0.0.1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | sort >> /tmp/matter.txt -echo "Getting adaway ad list..." # 445 domains -curl -s https://adaway.org/hosts.txt | grep -v "#" | grep -v "::1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt -echo "Getting hosts-file ad list..." # 28050 domains -curl -s http://hosts-file.net/.%5Cad_servers.txt | grep -v "#" | grep -v "::1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt -echo "Getting malwaredomainlist ad list..." # 1352 domains -curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $3}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt -echo "Getting adblock.gjtech ad list..." # 696 domains -curl -s http://adblock.gjtech.net/?format=unix-hosts | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt -echo "Getting someone who cares ad list..." # 10600 -curl -s http://someonewhocares.org/hosts/hosts | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | grep -v '^\\' | grep -v '\\$' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt -echo "Getting Mother of All Ad Blocks list..." # 102168 domains!! Thanks Kacy -curl -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' -e http://forum.xda-developers.com/ http://adblock.mahakala.is/ | grep -v "#" | awk '{print $2}' | sort >> /tmp/matter.txt - -# Sort the aggregated results and remove any duplicates -# Remove entries from the whitelist file if it exists at the root of the current user's home folder -if [[ -f $whitelist ]];then - echo "Removing duplicates, whitelisting, and formatting the list of domains..." - cat /tmp/matter.txt | sed $'s/\r$//' | sort | uniq | sed '/^$/d' | grep -v -x -f $whitelist | awk -v "IP=$piholeIP" '{sub(/\r$/,""); print "address=/"$0"/"IP}' > /tmp/andLight.txt - numberOfSitesWhitelisted=$(cat $whitelist | wc -l | sed 's/^[ \t]*//') - echo "$numberOfSitesWhitelisted domains whitelisted." -else - echo "Removing duplicates and formatting the list of domains..." - cat /tmp/matter.txt | sed $'s/\r$//' | sort | uniq | sed '/^$/d' | awk -v "IP=$piholeIP" '{sub(/\r$/,""); print "address=/"$0"/"IP}' > /tmp/andLight.txt -fi - -# Count how many domains/whitelists were added so it can be displayed to the user -numberOfAdsBlocked=$(cat /tmp/andLight.txt | wc -l | sed 's/^[ \t]*//') -echo "$numberOfAdsBlocked ad domains blocked." - -# Turn the file into a dnsmasq config file -sudo mv /tmp/andLight.txt $eventHorizion - -# Restart DNS -sudo service dnsmasq restart \ No newline at end of file diff --git a/gravity.sh b/gravity.sh old mode 100644 new mode 100755 index c3c766b0..36ab544f --- a/gravity.sh +++ b/gravity.sh @@ -1,28 +1,123 @@ #!/bin/bash -# /usr/local/bin/gravity.sh +# http://pi-hole.net +# Compiles a list of ad-serving domains by downloading them from multiple sources -# URL to pull list of known ad servers from -adListURL="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext" +# This script should only be run after you have a static IP address set on the Pi +piholeIP=$(hostname -I) -# Address to send ads to -piholeIP="127.0.0.1" +# Ad-list sources--one per line in single quotes +sources=('https://adaway.org/hosts.txt' +'http://adblock.gjtech.net/?format=unix-hosts' +'http://adblock.mahakala.is/' +'http://hosts-file.net/.%5Cad_servers.txt' +'http://www.malwaredomainlist.com/hostslist/hosts.txt' +'http://pgl.yoyo.org/adservers/serverlist.php?' +'http://someonewhocares.org/hosts/hosts' +'http://winhelp2002.mvps.org/hosts.txt') -# Where the list of ad servers are stored once downloaded -# Any file in /etc/dnsmasq.d is loaded automatically when the service starts -adFile="/etc/dnsmasq.d/adList.conf" +# Variables for various stages of downloading and formatting the list +origin=/etc/pihole +piholeDir=/etc/pihole +justDomainsExtension=domains +matter=pihole.0.matter.txt +andLight=pihole.1.andLight.txt +supernova=pihole.2.supernova.txt +eventHorizon=pihole.3.eventHorizon.txt +accretionDisc=pihole.4.accretionDisc.txt +eyeOfTheNeedle=pihole.5.wormhole.txt +adList=/etc/hosts +blacklist=$piholeDir/blacklist.txt +latentBlacklist=$origin/latentBlacklist.txt +whitelist=$piholeDir/whitelist.txt +latentWhitelist=$origin/latentWhitelist.txt -# The temporary file for holding -eventHorizion="/etc/dnsmasq.d/adList.conf.tmp" - -# Parses out the default 127.0.0.1 address and replaces it with the IP where ads will be sent -curl $adListURL | sed "s/127\.0\.0\.1/$piholeIP/" > $eventHorizion +echo "** Neutrino emissions detected..." -# If the temporary list of ad servers already exists (the eventHorizion) -if [ -f "$eventHorizion" ];then - # Then replace it as the new ad file - mv -f $eventHorizion $adFile +# Create the pihole resource directory if it doesn't exist. Future files will be stored here +if [[ -d $piholeDir ]];then + : else - echo "Error building the ad list, please try again." - exit 1 + echo "** Creating pihole directory..." + sudo mkdir $piholeDir fi -service dnsmasq restart \ No newline at end of file + +# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and blank lines +for ((i = 0; i < "${#sources[@]}"; i++)) +do + # Get just the domain from the URL + domain=$(echo "${sources[$i]}" | cut -d'/' -f3) + + # Save the file as list.#.domain + saveLocation=$origin/"list"."$i"."$domain" + + # Use a case statement to download lists that need special cURL commands to complete properly + case "$domain" in + "adblock.mahakala.is") data=$(curl -s -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' -e http://forum.xda-developers.com/ -z $saveLocation."$justDomainsExtension" "${sources[$i]}");; + + "pgl.yoyo.org") data=$(curl -s -d mimetype=plaintext -d hostformat=hosts -z $saveLocation."$justDomainsExtension" "${sources[$i]}");; + + *) data=$(curl -s -z $saveLocation."$justDomainsExtension" -A "Mozilla/10.0" "${sources[$i]}");; + esac + + if [[ -n "$data" ]];then + echo "Getting $domain list..." + # Remove comments and print only the domain name + # Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious + # This helps with that and makes it easier to read + # It also helps with debugging so each stage of the script can be researched more in depth + echo "$data" | awk 'NF {if ($1 !~ "#") print $2}' > $saveLocation."$justDomainsExtension" + else + echo "Skipping $domain list because it does not have any new entries..." + fi +done + +# Find all files with the .domains extension and compile them into one file +echo "** Aggregating list of domains..." +find $origin/ -type f -name "*.$justDomainsExtension" -exec cat {} \; > $origin/$matter + +# Append blacklist entries if they exist +if [[ -f $blacklist ]];then + numberOf=$(cat $blacklist | wc -l | sed 's/^[ \t]*//') + echo "** Blacklisting $numberOf domain(s)..." + cat $blacklist >> /tmp/matter.txt +else + : +fi + +function gravity_advanced() +########################### + { + numberOf=$(cat $origin/$andLight | wc -l | sed 's/^[ \t]*//') + echo "** $numberOf domains being pulled in by gravity..." + # Remove carriage returns and preceding whitespace + cat $origin/$andLight | sed $'s/\r$//' | sed '/^\s*$/d' > $origin/$supernova + # Sort and remove duplicates + cat $origin/$supernova | sort | uniq > $origin/$eventHorizon + numberOf=$(cat $origin/$eventHorizon | wc -l | sed 's/^[ \t]*//') + echo "** $numberOf unique domains trapped in the event horizon." + # Format domain list as "192.168.x.x domain.com" + echo "** Formatting domains into a HOSTS file..." + cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"'" $0}' > $origin/$accretionDisc + # Put the default host entries at the top of the file + echo "::1 localhost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc + echo "255.255.255.255 broadcasthost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc + echo "127.0.0.1 localhost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc + echo "127.0.0.1 raspberrypi" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc + # Copy the file so dnsmasq can use it + sudo cp $origin/$accretionDisc $adList + } + +# Whitelist (if applicable) then remove duplicates and format for dnsmasq +if [[ -f $whitelist ]];then + # Remove whitelist entries + numberOf=$(cat $whitelist | wc -l | sed 's/^[ \t]*//') + echo "** Whitelisting $numberOf domain(s)..." + # Append a "$" to the end of each line so it can be parsed out with grep -w + echo -n "^$" > $latentWhitelist + awk -F '[# \t]' 'NF>0&&$1!="" {print $1"$"}' $whitelist > $latentWhitelist + cat $origin/$matter | grep -vwf $latentWhitelist > $origin/$andLight + gravity_advanced +else + cat $origin/$matter > $origin/$andLight + gravity_advanced +fi \ No newline at end of file diff --git a/lighttpd.conf b/lighttpd.conf deleted file mode 100644 index 16e4c8a2..00000000 --- a/lighttpd.conf +++ /dev/null @@ -1,48 +0,0 @@ -# /etc/lighttpd/lighttpd.conf -server.modules = ( - "mod_access", - "mod_alias", - "mod_compress", - "mod_redirect", - "mod_auth", - "mod_rewrite", -) - -server.document-root = "/var/www" -server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) -server.errorlog = "/var/log/lighttpd/error.log" -server.pid-file = "/var/run/lighttpd.pid" -server.username = "www-data" -server.groupname = "www-data" -server.port = 80 - - -index-file.names = ( "index.php", "index.html", "index.lighttpd.html" ) -url.access-deny = ( "~", ".inc" ) -static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" ) - -compress.cache-dir = "/var/cache/lighttpd/compress/" -compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" ) - -# default listening port for IPv6 falls back to the IPv4 port -include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port -include_shell "/usr/share/lighttpd/create-mime.assign.pl" -include_shell "/usr/share/lighttpd/include-conf-enabled.pl" - -# Optional if a password protected directory is desired -# See http://jacobsalmela.com/password-protect-a-lighttpd-web-server-on-a-raspberry-pi-using-mod-auth/ -#auth.backend = "htdigest" -#auth.backend.htdigest.userfile = "/etc/lighttpd/.htpasswd/lighttpd-htdigest.user" -#auth.require = ( "/stream/" => -# ( -# "method" => "digest", -# "realm" => "lcars", -# "require" => "valid-user" -# ), -#) - -# Rewrites all URLs to the /var/www/pihole/index.html -# This should be a blank file (for speed) -$HTTP["host"] =~ ".*" { - url.rewrite = (".*" => "pihole/index.html") -} diff --git a/pihole.png b/pihole.png deleted file mode 100644 index 9da19eac..00000000 Binary files a/pihole.png and /dev/null differ diff --git a/resolv.conf b/resolv.conf deleted file mode 100644 index a605b3f9..00000000 --- a/resolv.conf +++ /dev/null @@ -1,3 +0,0 @@ -nameserver 192.168.1.101 -nameserver 8.8.8.8 -nameserver 8.8.4.4