Merge branch 'development' into networkchoices

This commit is contained in:
ryt51V 2016-03-13 16:51:40 +00:00
commit 4b76d74db6
9 changed files with 121 additions and 117 deletions

View file

@ -1,4 +1,4 @@
# Automated Install # Automated Install
##### Designed For Raspberry Pi A+, B, B+, 2, Zero (with an Ethernet adapter), and also works on most Debian based distros! ##### Designed For Raspberry Pi A+, B, B+, 2, Zero (with an Ethernet adapter), and also works on most Debian based distros!
1. Install Raspbian on Raspberry Pi variants or a Debian based distribution on other hardware or virtual machines 1. Install Raspbian on Raspberry Pi variants or a Debian based distribution on other hardware or virtual machines

View file

@ -5,11 +5,11 @@
# 2. run `nano /etc/pihole/adlists.list` # # 2. run `nano /etc/pihole/adlists.list` #
# 3. Uncomment or comment any of the below lists # # 3. Uncomment or comment any of the below lists #
# # # #
# Know of any other lists? Feel free to let us know about them, or add them # # Know of any other lists? Feel free to let us know about them, or add them #
# to this file! # # to this file! #
################################################################################ ################################################################################
# The below list amalgamates several lists we used previously. # The below list amalgamates several lists we used previously.
# See `https://github.com/StevenBlack/hosts` for details # See `https://github.com/StevenBlack/hosts` for details
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
@ -30,8 +30,8 @@ http://hosts-file.net/ad_servers.txt
# ADZHOSTS list. Has been known to block legitimate domains # ADZHOSTS list. Has been known to block legitimate domains
#http://optimate.dl.sourceforge.net/project/adzhosts/HOSTS.txt #http://optimate.dl.sourceforge.net/project/adzhosts/HOSTS.txt
# Windows 10 telemetry list - warning this one may block windows update # Windows 10 telemetry list
#https://raw.githubusercontent.com/crazy-max/HostsWindowsBlocker/master/hosts.txt #https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/hostsBlockWindowsSpy.txt
# Securemecca.com list - Also blocks "adult" sites (pornography/gambling etc) # Securemecca.com list - Also blocks "adult" sites (pornography/gambling etc)
#http://securemecca.com/Downloads/hosts.txt #http://securemecca.com/Downloads/hosts.txt
@ -39,6 +39,9 @@ http://hosts-file.net/ad_servers.txt
# Quidsup's tracker list # Quidsup's tracker list
https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt
# Block the BBC News website Breaking News banner
#https://raw.githubusercontent.com/BreakingTheNews/BreakingTheNews.github.io/master/hosts
# Untested Lists: # Untested Lists:
#https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt #https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt

View file

@ -74,13 +74,13 @@ if [[ -f $piholeIPv6file ]];then
fi fi
function HandleOther(){ function HandleOther(){
#check validity of domain #check validity of domain
validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if [ -z "$validDomain" ]; then if [ -z "$validDomain" ]; then
echo $1 is not a valid argument or domain name echo $1 is not a valid argument or domain name
else else
domList=("${domList[@]}" $validDomain) domList=("${domList[@]}" $validDomain)
fi fi
} }
@ -89,9 +89,9 @@ function PopBlacklistFile(){
#check blacklist file exists, and if not, create it #check blacklist file exists, and if not, create it
if [[ ! -f $blacklist ]];then if [[ ! -f $blacklist ]];then
touch $blacklist touch $blacklist
fi fi
for dom in "${domList[@]}" for dom in "${domList[@]}"
do do
if $addmode; then if $addmode; then
AddDomain $dom AddDomain $dom
else else
@ -120,7 +120,7 @@ function AddDomain(){
} }
function RemoveDomain(){ function RemoveDomain(){
bool=false bool=false
grep -Ex -q "$1" $blacklist || bool=true grep -Ex -q "$1" $blacklist || bool=true
if $bool; then if $bool; then
@ -133,42 +133,42 @@ function RemoveDomain(){
if $versbose; then if $versbose; then
echo "::: Un-blacklisting $dom..." echo "::: Un-blacklisting $dom..."
fi fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true modifyHost=true
fi fi
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if $addmode; then
#add domains to the hosts file #add domains to the hosts file
if [[ -r $blacklist ]];then if [[ -r $blacklist ]];then
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
if [[ -n $piholeIPv6 ]];then if [[ -n $piholeIPv6 ]];then
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
else else
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
fi fi
fi fi
else else
echo ":::" echo ":::"
for dom in "${domToRemoveList[@]}" for dom in "${domToRemoveList[@]}"
do do
#we need to remove the domains from the blacklist file and the host file #we need to remove the domains from the blacklist file and the host file
echo "::: $dom" echo "::: $dom"
echo -n "::: removing from HOSTS file..." echo -n "::: removing from HOSTS file..."
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
echo " done!" echo " done!"
echo -n "::: removing from blackist.txt..." echo -n "::: removing from blackist.txt..."
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
echo " done!" echo " done!"
done done
fi fi
} }
function Reload() { function Reload() {
@ -193,17 +193,17 @@ function Reload() {
for var in "$@" for var in "$@"
do do
case "$var" in case "$var" in
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;; "-f" | "--force" ) force=true;;
"-q" | "--quiet" ) versbose=false;; "-q" | "--quiet" ) versbose=false;;
* ) HandleOther $var;; * ) HandleOther $var;;
esac esac
done done
PopBlacklistFile PopBlacklistFile
if $modifyHost || $force; then if $modifyHost || $force; then
ModifyHostFile ModifyHostFile
else else
if $versbose; then if $versbose; then

View file

@ -73,9 +73,9 @@ function outputJSON(){
CalcQueriesToday CalcQueriesToday
CalcblockedToday CalcblockedToday
CalcPercentBlockedToday CalcPercentBlockedToday
CalcBlockedDomains CalcBlockedDomains
printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday" printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday"
} }
@ -88,30 +88,31 @@ function normalChrono(){
echo " $(ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d':' -f2)" echo " $(ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d':' -f2)"
echo "" echo ""
uptime | cut -d' ' -f11- uptime | cut -d' ' -f11-
uptime -p #uptime -p #Doesn't work on all versions of uptime
uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}'
echo "-------------------------------" echo "-------------------------------"
# Uncomment to continually read the log file and display the current domain being blocked # Uncomment to continually read the log file and display the current domain being blocked
#tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}' #tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}'
#uncomment next 4 lines to use original query count calculation #uncomment next 4 lines to use original query count calculation
#today=$(date "+%b %e") #today=$(date "+%b %e")
#todaysQueryCount=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ {print $7}' | wc -l) #todaysQueryCount=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ {print $7}' | wc -l)
#todaysQueryCountV4=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[A\]/ {print $7}' | wc -l) #todaysQueryCountV4=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[A\]/ {print $7}' | wc -l)
#todaysQueryCountV6=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[AAAA\]/ {print $7}' | wc -l) #todaysQueryCountV6=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[AAAA\]/ {print $7}' | wc -l)
CalcQueriesToday CalcQueriesToday
CalcblockedToday CalcblockedToday
CalcPercentBlockedToday CalcPercentBlockedToday
CalcBlockedDomains CalcBlockedDomains
echo "Blocking: $blockedDomainsTotal" echo "Blocking: $blockedDomainsTotal"
#below commented line does not add up to todaysQueryCount #below commented line does not add up to todaysQueryCount
#echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6" #echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6"
echo "Queries: $queriesToday" #same total calculation as dashboard echo "Queries: $queriesToday" #same total calculation as dashboard
echo "Pi-holed: $blockedToday ($percentBlockedToday%)" echo "Pi-holed: $blockedToday ($percentBlockedToday%)"
sleep 5 sleep 5
done done
} }
@ -125,7 +126,7 @@ function displayHelp(){
echo "Options:" echo "Options:"
echo " -j, --json output stats as JSON formatted string" echo " -j, --json output stats as JSON formatted string"
echo " -h, --help display this help text" echo " -h, --help display this help text"
exit 1 exit 1
} }
@ -137,7 +138,7 @@ for var in "$@"
do do
case "$var" in case "$var" in
"-j" | "--json" ) outputJSON;; "-j" | "--json" ) outputJSON;;
"-h" | "--help" ) displayHelp;; "-h" | "--help" ) displayHelp;;
* ) exit 1;; * ) exit 1;;
esac esac
done done

View file

@ -63,7 +63,7 @@ make_repo() {
update_repo() { update_repo() {
# pull the latest commits # pull the latest commits
cd "$WEB_INTERFACE_DIR" cd "$WEB_INTERFACE_DIR"
git pull git pull
} }
main main

View file

@ -73,13 +73,13 @@ if [[ -f $piholeIPv6file ]];then
fi fi
function HandleOther(){ function HandleOther(){
#check validity of domain #check validity of domain
validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if [ -z "$validDomain" ]; then if [ -z "$validDomain" ]; then
echo "::: $1 is not a valid argument or domain name" echo "::: $1 is not a valid argument or domain name"
else else
domList=("${domList[@]}" $validDomain) domList=("${domList[@]}" $validDomain)
fi fi
} }
@ -88,9 +88,9 @@ function PopWhitelistFile(){
#check whitelist file exists, and if not, create it #check whitelist file exists, and if not, create it
if [[ ! -f $whitelist ]];then if [[ ! -f $whitelist ]];then
touch $whitelist touch $whitelist
fi fi
for dom in "${domList[@]}" for dom in "${domList[@]}"
do do
if $addmode; then if $addmode; then
AddDomain $dom AddDomain $dom
else else
@ -102,7 +102,7 @@ function PopWhitelistFile(){
function AddDomain(){ function AddDomain(){
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" $whitelist || bool=true
if $bool; then if $bool; then
#domain not found in the whitelist file, add it! #domain not found in the whitelist file, add it!
@ -122,7 +122,7 @@ function AddDomain(){
} }
function RemoveDomain(){ function RemoveDomain(){
bool=false bool=false
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" $whitelist || bool=true
if $bool; then if $bool; then
@ -136,11 +136,11 @@ function RemoveDomain(){
#echo "::: Un-whitelisting $dom..." #echo "::: Un-whitelisting $dom..."
#fi #fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
modifyHost=true modifyHost=true
fi fi
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if $addmode; then
#remove domains in from hosts file #remove domains in from hosts file
if [[ -r $whitelist ]];then if [[ -r $whitelist ]];then
@ -152,19 +152,19 @@ function ModifyHostFile(){
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
echo "l" >> /etc/pihole/whitelist.tmp echo "l" >> /etc/pihole/whitelist.tmp
grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp
rm /etc/pihole/gravity.list rm /etc/pihole/gravity.list
mv /etc/pihole/gravity.tmp /etc/pihole/gravity.list mv /etc/pihole/gravity.tmp /etc/pihole/gravity.list
rm /etc/pihole/whitelist.tmp rm /etc/pihole/whitelist.tmp
echo " done!" echo " done!"
fi fi
else else
#we need to add the removed domains to the hosts file #we need to add the removed domains to the hosts file
echo ":::" echo ":::"
echo "::: Modifying HOSTS file to un-whitelist domains..." echo "::: Modifying HOSTS file to un-whitelist domains..."
for rdom in "${domToRemoveList[@]}" for rdom in "${domToRemoveList[@]}"
do do
if [[ -n $piholeIPv6 ]];then if [[ -n $piholeIPv6 ]];then
echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..." echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..."
echo $rdom | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList echo $rdom | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
@ -178,7 +178,7 @@ function ModifyHostFile(){
echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist
echo " done!" echo " done!"
done done
fi fi
} }
function Reload() { function Reload() {
@ -202,10 +202,10 @@ function Reload() {
for var in "$@" for var in "$@"
do do
case "$var" in case "$var" in
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;; "-f" | "--force" ) force=true;;
"-q" | "--quiet" ) versbose=false;; "-q" | "--quiet" ) versbose=false;;
* ) HandleOther $var;; * ) HandleOther $var;;
esac esac
done done

View file

@ -27,8 +27,8 @@
# Replies which are not DNSSEC signed may be legitimate, because the domain # Replies which are not DNSSEC signed may be legitimate, because the domain
# is unsigned, or may be forgeries. Setting this option tells dnsmasq to # is unsigned, or may be forgeries. Setting this option tells dnsmasq to
# check that an unsigned reply is OK, by finding a secure proof that a DS # check that an unsigned reply is OK, by finding a secure proof that a DS
# record somewhere between the root and the domain does not exist. # record somewhere between the root and the domain does not exist.
# The cost of setting this is that even queries in unsigned domains will need # The cost of setting this is that even queries in unsigned domains will need
# one or more extra DNS queries to verify. # one or more extra DNS queries to verify.
#dnssec-check-unsigned #dnssec-check-unsigned
@ -183,11 +183,11 @@
#dhcp-range=1234::2, 1234::500, 64, 12h #dhcp-range=1234::2, 1234::500, 64, 12h
# Do Router Advertisements, BUT NOT DHCP for this subnet. # Do Router Advertisements, BUT NOT DHCP for this subnet.
#dhcp-range=1234::, ra-only #dhcp-range=1234::, ra-only
# Do Router Advertisements, BUT NOT DHCP for this subnet, also try and # Do Router Advertisements, BUT NOT DHCP for this subnet, also try and
# add names to the DNS for the IPv6 address of SLAAC-configured dual-stack # add names to the DNS for the IPv6 address of SLAAC-configured dual-stack
# hosts. Use the DHCPv4 lease to derive the name, network segment and # hosts. Use the DHCPv4 lease to derive the name, network segment and
# MAC address and assume that the host will also have an # MAC address and assume that the host will also have an
# IPv6 address calculated using the SLAAC alogrithm. # IPv6 address calculated using the SLAAC alogrithm.
#dhcp-range=1234::, ra-names #dhcp-range=1234::, ra-names
@ -210,9 +210,9 @@
#dhcp-range=1234::, ra-stateless, ra-names #dhcp-range=1234::, ra-stateless, ra-names
# Do router advertisements for all subnets where we're doing DHCPv6 # Do router advertisements for all subnets where we're doing DHCPv6
# Unless overriden by ra-stateless, ra-names, et al, the router # Unless overriden by ra-stateless, ra-names, et al, the router
# advertisements will have the M and O bits set, so that the clients # advertisements will have the M and O bits set, so that the clients
# get addresses and configuration from DHCPv6, and the A bit reset, so the # get addresses and configuration from DHCPv6, and the A bit reset, so the
# clients don't use SLAAC addresses. # clients don't use SLAAC addresses.
#enable-ra #enable-ra
@ -278,11 +278,11 @@
# any machine with Ethernet address starting 11:22:33: # any machine with Ethernet address starting 11:22:33:
#dhcp-host=11:22:33:*:*:*,set:red #dhcp-host=11:22:33:*:*:*,set:red
# Give a fixed IPv6 address and name to client with # Give a fixed IPv6 address and name to client with
# DUID 00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2 # DUID 00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2
# Note the MAC addresses CANNOT be used to identify DHCPv6 clients. # Note the MAC addresses CANNOT be used to identify DHCPv6 clients.
# Note also the they [] around the IPv6 address are obilgatory. # Note also the they [] around the IPv6 address are obilgatory.
#dhcp-host=id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5] #dhcp-host=id:00:01:00:01:16:d2:83:fc:92:d4:19:e2:d8:b2, fred, [1234::5]
# Ignore any clients which are not specified in dhcp-host lines # Ignore any clients which are not specified in dhcp-host lines
# or /etc/ethers. Equivalent to ISC "deny unknown-clients". # or /etc/ethers. Equivalent to ISC "deny unknown-clients".
@ -338,7 +338,7 @@
# Send DHCPv6 option. Note [] around IPv6 addresses. # Send DHCPv6 option. Note [] around IPv6 addresses.
#dhcp-option=option6:dns-server,[1234::77],[1234::88] #dhcp-option=option6:dns-server,[1234::77],[1234::88]
# Send DHCPv6 option for namservers as the machine running # Send DHCPv6 option for namservers as the machine running
# dnsmasq and another. # dnsmasq and another.
#dhcp-option=option6:dns-server,[::],[1234::88] #dhcp-option=option6:dns-server,[::],[1234::88]
@ -645,4 +645,4 @@
#conf-dir=/etc/dnsmasq.d,.bak #conf-dir=/etc/dnsmasq.d,.bak
# Include all files in a directory which end in .conf # Include all files in a directory which end in .conf
#conf-dir=/etc/dnsmasq.d/*.conf #conf-dir=/etc/dnsmasq.d/*.conf

View file

@ -108,7 +108,7 @@ welcomeDialogs() {
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 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 # 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. 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.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." $r $c In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." $r $c
} }
@ -116,12 +116,12 @@ welcomeDialogs() {
verifyFreeDiskSpace() { verifyFreeDiskSpace() {
# 25MB is the minimum space needed (20MB install + 5MB one day of logs.) # 25MB is the minimum space needed (20MB install + 5MB one day of logs.)
requiredFreeBytes=51200 requiredFreeBytes=51200
existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1` existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1`
if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then
existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1` existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1`
fi fi
if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space" "\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n" $r $c whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space" "\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n" $r $c
echo "$existingFreeBytes is less than $requiredFreeBytes" echo "$existingFreeBytes is less than $requiredFreeBytes"
@ -160,7 +160,7 @@ chooseInterface() {
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
exit 1 exit 1
fi fi
} }
cleanupIPv6() { cleanupIPv6() {
@ -184,7 +184,7 @@ use4andor6() {
IPv6 ) useIPv6=true;; IPv6 ) useIPv6=true;;
esac esac
done done
if [ $useIPv4 ]; then if [ $useIPv4 ]; then
# Get interface address information # Get interface address information
@ -341,7 +341,7 @@ function valid_ip()
{ {
local ip=$1 local ip=$1
local stat=1 local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS OIFS=$IFS
IFS='.' IFS='.'
@ -393,9 +393,9 @@ setDNS(){
Custom) Custom)
until [[ $DNSSettingsCorrect = True ]] until [[ $DNSSettingsCorrect = True ]]
do do
strInvalid="Invalid" strInvalid="Invalid"
if [ ! $piholeDNS1 ]; then if [ ! $piholeDNS1 ]; then
if [ ! $piholeDNS2 ]; then if [ ! $piholeDNS2 ]; then
prePopulate="" prePopulate=""
@ -407,38 +407,38 @@ setDNS(){
elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then
prePopulate="$piholeDNS1, $piholeDNS2" prePopulate="$piholeDNS1, $piholeDNS2"
fi fi
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3) piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then
piholeDNS1=$strInvalid piholeDNS1=$strInvalid
fi fi
if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then
piholeDNS2=$strInvalid piholeDNS2=$strInvalid
fi fi
else else
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
exit 1 exit 1
fi fi
if [[ $piholeDNS1 == $strInvalid ]] || [[ $piholeDNS2 == $strInvalid ]]; then if [[ $piholeDNS1 == $strInvalid ]] || [[ $piholeDNS2 == $strInvalid ]]; then
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c
if [[ $piholeDNS1 == $strInvalid ]]; then if [[ $piholeDNS1 == $strInvalid ]]; then
piholeDNS1="" piholeDNS1=""
fi fi
if [[ $piholeDNS2 == $strInvalid ]]; then if [[ $piholeDNS2 == $strInvalid ]]; then
piholeDNS2="" piholeDNS2=""
fi fi
DNSSettingsCorrect=False DNSSettingsCorrect=False
else else
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then
DNSSettingsCorrect=True DNSSettingsCorrect=True
else else
@ -460,11 +460,11 @@ versionCheckDNSmasq(){
dnsFile1="/etc/dnsmasq.conf" dnsFile1="/etc/dnsmasq.conf"
dnsFile2="/etc/dnsmasq.conf.orig" dnsFile2="/etc/dnsmasq.conf.orig"
dnsSearch="addn-hosts=/etc/pihole/gravity.list" dnsSearch="addn-hosts=/etc/pihole/gravity.list"
defaultFile="/etc/.pihole/advanced/dnsmasq.conf.original" defaultFile="/etc/.pihole/advanced/dnsmasq.conf.original"
newFileToInstall="/etc/.pihole/advanced/01-pihole.conf" newFileToInstall="/etc/.pihole/advanced/01-pihole.conf"
newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf" newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf"
if [ -f $dnsFile1 ]; then if [ -f $dnsFile1 ]; then
echo -n "::: Existing dnsmasq.conf found..." echo -n "::: Existing dnsmasq.conf found..."
if grep -q $dnsSearch $dnsFile1; then if grep -q $dnsSearch $dnsFile1; then
@ -476,14 +476,14 @@ versionCheckDNSmasq(){
$SUDO cp $defaultFile $dnsFile1 $SUDO cp $defaultFile $dnsFile1
echo " done." echo " done."
else else
echo " it is not a pi-hole file, leaving alone!" echo " it is not a pi-hole file, leaving alone!"
fi fi
else else
echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..." echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..."
$SUDO cp $defaultFile $dnsFile1 $SUDO cp $defaultFile $dnsFile1
echo " done." echo " done."
fi fi
echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..." echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..."
$SUDO cp $newFileToInstall $newFileFinalLocation $SUDO cp $newFileToInstall $newFileFinalLocation
echo " done." echo " done."
@ -668,9 +668,9 @@ installCron() {
runGravity() { runGravity() {
# Rub gravity.sh to build blacklists # Rub gravity.sh to build blacklists
$SUDO echo ":::" $SUDO echo ":::"
$SUDO echo "::: Preparing to run gravity.sh to refresh hosts..." $SUDO echo "::: Preparing to run gravity.sh to refresh hosts..."
if ls /etc/pihole/list* 1> /dev/null 2>&1; then if ls /etc/pihole/list* 1> /dev/null 2>&1; then
echo "::: Cleaning up previous install (preserving whitelist/blacklist)" echo "::: Cleaning up previous install (preserving whitelist/blacklist)"
$SUDO rm /etc/pihole/list.* $SUDO rm /etc/pihole/list.*
fi fi
#Don't run as SUDO, this was causing issues #Don't run as SUDO, this was causing issues
@ -694,7 +694,7 @@ setUser(){
setPassword() { setPassword() {
# Password needed to authorize changes to lists from admin page # Password needed to authorize changes to lists from admin page
pass=$(whiptail --passwordbox "Please enter a password to secure your Pi-hole web interface." 10 50 3>&1 1>&2 2>&3) pass=$(whiptail --passwordbox "Please enter a password to secure your Pi-hole web interface." 10 50 3>&1 1>&2 2>&3)
if [ $? = 0 ]; then if [ $? = 0 ]; then
# Entered password # Entered password
echo $pass > /etc/pihole/password.txt echo $pass > /etc/pihole/password.txt

View file

@ -124,7 +124,7 @@ function gravity_collapse() {
sources+=($line) sources+=($line)
fi fi
done < $adListFile done < $adListFile
echo " done!" echo " done!"
else else
#no custom file found, use defaults! #no custom file found, use defaults!
echo -n "::: No custom adlist file detected, reading from default file..." echo -n "::: No custom adlist file detected, reading from default file..."
@ -137,8 +137,8 @@ function gravity_collapse() {
sources+=($line) sources+=($line)
fi fi
done < $adListDefault done < $adListDefault
echo " done!" echo " done!"
fi fi
# Create the pihole resource directory if it doesn't exist. Future files will be stored here # Create the pihole resource directory if it doesn't exist. Future files will be stored here
if [[ -d $piholeDir ]];then if [[ -d $piholeDir ]];then
@ -186,9 +186,9 @@ function gravity_transport() {
fi fi
# Silently curl url # Silently curl url
curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
# Check for list updates # Check for list updates
gravity_patternCheck $patternBuffer gravity_patternCheck $patternBuffer
# Cleanup # Cleanup
rm -f $patternBuffer rm -f $patternBuffer
@ -236,13 +236,13 @@ function gravity_Schwarzchild() {
echo "::: " echo "::: "
# Find all active domains and compile them into one file and remove CRs # Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..." echo -n "::: Aggregating list of domains..."
truncate -s 0 $piholeDir/$matterandlight & spinner $! truncate -s 0 $piholeDir/$matterandlight & spinner $!
for i in "${activeDomains[@]}" for i in "${activeDomains[@]}"
do do
cat $i |tr -d '\r' >> $piholeDir/$matterandlight cat $i |tr -d '\r' >> $piholeDir/$matterandlight
done done
echo " done!" echo " done!"
} }
@ -250,12 +250,12 @@ function gravity_Blacklist(){
# Append blacklist entries if they exist # Append blacklist entries if they exist
echo -n "::: Running blacklist script to update HOSTS file...." echo -n "::: Running blacklist script to update HOSTS file...."
$blacklistScript -f -nr -q > /dev/null & spinner $! $blacklistScript -f -nr -q > /dev/null & spinner $!
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
echo " $numBlacklisted domain${plural} blacklisted!" echo " $numBlacklisted domain${plural} blacklisted!"
} }
@ -264,7 +264,7 @@ function gravity_Whitelist() {
# Prevent our sources from being pulled into the hole # Prevent our sources from being pulled into the hole
plural=; [[ "${sources[@]}" != "1" ]] && plural=s plural=; [[ "${sources[@]}" != "1" ]] && plural=s
echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..." echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..."
urls=() urls=()
for url in ${sources[@]} for url in ${sources[@]}
do do
@ -272,16 +272,16 @@ function gravity_Whitelist() {
urls=("${urls[@]}" $tmp) urls=("${urls[@]}" $tmp)
done done
echo " done!" echo " done!"
echo -n "::: Running whitelist script to update HOSTS file...." echo -n "::: Running whitelist script to update HOSTS file...."
$whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $! $whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $!
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!" echo " $numWhitelisted domain${plural} whitelisted!"
} }
function gravity_unique() { function gravity_unique() {
@ -301,7 +301,7 @@ function gravity_hostFormat() {
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
else else
# Otherwise, just create gravity.list as normal using IPv4 # Otherwise, just create gravity.list as normal using IPv4
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
@ -336,12 +336,12 @@ function gravity_advanced() {
echo -n "::: Formatting list of domains to remove comments...." echo -n "::: Formatting list of domains to remove comments...."
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova & spinner $! awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova & spinner $!
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$supernova) numberOf=$(wc -l < $piholeDir/$supernova)
echo "::: $numberOf domains being pulled in by gravity..." echo "::: $numberOf domains being pulled in by gravity..."
gravity_unique gravity_unique
} }
function gravity_reload() { function gravity_reload() {
@ -350,7 +350,7 @@ function gravity_reload() {
echo -n "::: Cleaning up un-needed files..." echo -n "::: Cleaning up un-needed files..."
$SUDO rm /etc/pihole/pihole.* $SUDO rm /etc/pihole/pihole.*
echo " done!" echo " done!"
# Reload hosts file # Reload hosts file
echo ":::" echo ":::"
echo -n "::: Refresh lists in dnsmasq..." echo -n "::: Refresh lists in dnsmasq..."