From d646612a2597ae4a8da35e36ac0737dc012f0c41 Mon Sep 17 00:00:00 2001 From: Salmela Date: Thu, 31 Dec 2015 20:26:05 -0600 Subject: [PATCH 1/4] Block ads over IPv6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’m pretty sure this works well. Maybe someone else can try it out. --- automated install/basic-install.sh | 38 ++++++++++++++++-------------- gravity.sh | 21 +++++++++++++---- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bbf1fbc2..21b9c245 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -36,10 +36,6 @@ IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1 IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') -# IPv6 support to be added later -#IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1) -#IPv6linkLocal=$(ip addr show | awk '/inet/ && /scope\ link/ && /fe80/ {print $2}' | cut -d'/' -f1) - availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1) dhcpcdFile=/etc/dhcpcd.conf @@ -65,6 +61,9 @@ welcomeDialogs() # Display the welcome dialog whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" $r $c +# Support for a part-time dev +whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" $r $c + # Explain the need for a static address whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. @@ -116,7 +115,9 @@ done useIPv6dialog() { -whiptail --msgbox --backtitle "Coming soon..." --title "IPv6 not yet supported" "I need your help for IPv6. Consider donating at: http://pi-hole.net/donate" $r $c +piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +whiptail --msgbox --backtitle "IPv6..." --title "$piholeIPv6 will be used to block ads." $r $c +sudo touch /etc/pihole/.useIPv6 } getStaticIPv4Settings() @@ -263,6 +264,17 @@ installCron sudo /usr/local/bin/gravity.sh } +displayFinalMessage(){ + whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using: + + $IPv4addr + $piholeIPv6 + + If you set a new IP address, you should restart the Pi. + + The install log is in /etc/pihole." $r $c +} + ######## SCRIPT ############ # Start the installer welcomeDialogs @@ -288,16 +300,10 @@ fi # Decide is IPv6 will be used if [[ "$useIPv6" = true ]];then - # If only IPv6 is selected, exit because it is not supported yet - if [[ "$useIPv6" = true ]] && [[ "$useIPv4" = false ]];then - useIPv6dialog - exit - else - useIPv6dialog - fi + useIPv6dialog else useIPv6=false - echo "IPv6 will NOT be used. Consider a donation at pi-hole.net/donate" + echo "IPv6 will NOT be used." fi # Install and log everything to a file @@ -306,11 +312,7 @@ installPihole | tee $tmpLog # Move the log file into /etc/pihole for storage sudo mv $tmpLog $instalLogLoc -whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using this IP: $IPv4addr. - -If you set a new IP address, it should work fine, but you may want to reboot the Pi at some point. - -The install log is in /etc/pihole." $r $c +displayFinalMessage sudo service dnsmasq start sudo service lighttpd start diff --git a/gravity.sh b/gravity.sh index 1a8f48e8..c2a05534 100755 --- a/gravity.sh +++ b/gravity.sh @@ -11,15 +11,20 @@ # (at your option) any later version. piholeIPfile=/tmp/piholeIP +piholeIPv6file=/etc/pihole/.useIPv6 if [[ -f $piholeIPfile ]];then + if [[ -f $piholeIPv6file ]];then + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') + fi # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script piholeIP=$(cat $piholeIPfile) rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') - piholeIP=${piholeIPCIDR%/*} + IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') + piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') + piholeIP=${piholeIPCIDR%/*} fi # Ad-list sources--one per line in single quotes @@ -208,7 +213,13 @@ function gravity_unique() { function gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo "** Formatting domains into a HOSTS file..." - cat $piholeDir/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $piholeDir/$accretionDisc + # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols + if [[ -n $piholeIPv6 ]];then + cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' > $piholeDir/$accretionDisc + else + # Otherwise, just create gravity.list as normal using IPv4 + cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' > $piholeDir/$accretionDisc + fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it cp $piholeDir/$accretionDisc $adList } @@ -243,7 +254,7 @@ function gravity_advanced() { function gravity_reload() { # Reload hosts file - + echo "** Refresh lists in dnsmasq..." sudo kill -HUP $(pidof dnsmasq) } From 987e4e02a9bd62273b67eb07bb5ce670b14ec10f Mon Sep 17 00:00:00 2001 From: Clinton Date: Fri, 1 Jan 2016 14:11:46 +0000 Subject: [PATCH 2/4] Fix bug in gravity.sh where IPv6 list was not always populated Failed to be populated if /tmp/piholeIP does not exist. This may happen under the following conditions: - was not generated during install - gravity.sh being run again after the original install (the file is deleted during the installation process) --- gravity.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index c2a05534..091b5563 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,10 +13,6 @@ piholeIPfile=/tmp/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 if [[ -f $piholeIPfile ]];then - if [[ -f $piholeIPv6file ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') - fi # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script piholeIP=$(cat $piholeIPfile) rm $piholeIPfile @@ -27,6 +23,11 @@ else piholeIP=${piholeIPCIDR%/*} fi +if [[ -f $piholeIPv6file ]];then + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +fi + # Ad-list sources--one per line in single quotes # The mahakala source is commented out due to many users having issues with it blocking legitimate domains. # Uncomment at your own risk From d37db4304ca9194cca4ff6c515334dbb91307940 Mon Sep 17 00:00:00 2001 From: Salmela Date: Fri, 1 Jan 2016 10:59:30 -0600 Subject: [PATCH 3/4] A few small display changes IPv6 box was missing the title. Added some IPv6 echoes. --- automated install/basic-install.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 21b9c245..a529b40d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -116,7 +116,8 @@ done useIPv6dialog() { piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') -whiptail --msgbox --backtitle "IPv6..." --title "$piholeIPv6 will be used to block ads." $r $c +whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." $r $c +sudo mkdir -p /etc/pihole/ sudo touch /etc/pihole/.useIPv6 } @@ -270,9 +271,9 @@ displayFinalMessage(){ $IPv4addr $piholeIPv6 - If you set a new IP address, you should restart the Pi. +If you set a new IP address, you should restart the Pi. - The install log is in /etc/pihole." $r $c +The install log is in /etc/pihole." $r $c } ######## SCRIPT ############ @@ -301,6 +302,8 @@ fi # Decide is IPv6 will be used if [[ "$useIPv6" = true ]];then useIPv6dialog + echo "Using IPv6." + echo "Your IPv6 address is: $piholeIPv6" else useIPv6=false echo "IPv6 will NOT be used." From 3fc1817e7a3f880c82aceb54be34bc69a8222e50 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Fri, 1 Jan 2016 18:34:33 -0600 Subject: [PATCH 4/4] Merge branch 'master' into ipv6 --- gravity.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 091b5563..fbecb3ad 100755 --- a/gravity.sh +++ b/gravity.sh @@ -255,9 +255,17 @@ function gravity_advanced() { function gravity_reload() { # Reload hosts file - echo "** Refresh lists in dnsmasq..." - sudo kill -HUP $(pidof dnsmasq) + + dnsmasqPid=$(pidof dnsmasq) + + if [[ $dnsmasqPid ]]; then + # service already running - reload config + sudo kill -HUP $dnsmasqPid + else + # service not running, start it up + sudo service dnsmasq start + fi } gravity_collapse