@ -18,13 +23,20 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei
## Pi-hole Is Free, But Powered By Your Donations
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "Free, but powered by donations")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate")
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON:
@ -92,4 +106,4 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-
- There is also an [FAQ section on pi-hole.net](http://pi-hole.net)
## 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.
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 is only for a clean install of a Debian based system, such as the Raspberry Pi.
# 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}')
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev"| awk '{print $4}'| awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
modifyHost=false
@ -53,11 +51,19 @@ fi
function HandleOther(){
#check validity of domain
<<<<<<< HEAD
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
echo$1 is not a valid argument or domain name
else
=======
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
echo"$1" is not a valid argument or domain name
else
>>>>>>> ScriptCleanup
domList=("${domList[@]}"$validDomain)
fi
}
@ -68,11 +74,17 @@ function PopBlacklistFile(){
touch $blacklist
fi
for dom in "${domList[@]}"
<<<<<<< HEAD
do
if$addmode;then
AddDomain $dom
=======
do
if"$addmode";then
AddDomain "$dom"
>>>>>>> ScriptCleanup
else
RemoveDomain $dom
RemoveDomain "$dom"
fi
done
}
@ -86,7 +98,7 @@ function AddDomain(){
if$versbose;then
echo -n "::: Adding $1 to blacklist file..."
fi
echo$1 >> $blacklist
echo"$1" >> $blacklist
modifyHost=true
echo" done!"
else
@ -119,9 +131,10 @@ function ModifyHostFile(){
if$addmode;then
#add domains to the hosts file
if[[ -r $blacklist]];then
numberOf=$(cat $blacklist| sed '/^\s*$/d'| wc -l)
numberOf=$($blacklist| sed '/^\s*$/d'| wc -l)
plural=;[["$numberOf" !="1"]]&&plural=s
echo":::"
<<<<<<< HEAD
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
# 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}')
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev"| awk '{print $4}'| awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
modifyHost=false
@ -52,8 +51,13 @@ fi
function HandleOther(){
#check validity of domain
<<<<<<< HEAD
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/')
>>>>>>> ScriptCleanup
if[ -z "$validDomain"];then
echo"::: $1 is not a valid argument or domain name"
else
@ -69,9 +73,9 @@ function PopWhitelistFile(){
for dom in "${domList[@]}"
do
if$addmode;then
AddDomain $dom
AddDomain "$dom"
else
RemoveDomain $dom
RemoveDomain "$dom"
fi
done
}
@ -86,7 +90,7 @@ function AddDomain(){
if$versbose;then
echo -n "::: Adding $1 to whitelist.txt..."
fi
echo$1 >> $whitelist
echo"$1" >> $whitelist
modifyHost=true
if$versbose;then
echo" done!"
@ -122,12 +126,12 @@ function ModifyHostFile(){
#remove domains in from hosts file
if[[ -r $whitelist]];then
# Remove whitelist entries
numberOf=$(cat $whitelist| sed '/^\s*$/d'| wc -l)
numberOf=$($whitelist| sed '/^\s*$/d'| wc -l)
plural=;[["$numberOf" !="1"]]&&plural=s
echo":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
# Give the user a chance to review their settings before moving on
@ -257,8 +269,8 @@ getStaticIPv4Settings() {
Gateway: $IPv4gw"$r$c)then
# If the settings are correct, then we need to set the piholeIP
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script
echo${IPv4addr%/*} > /tmp/piholeIP
echo$piholeInterface > /tmp/piholeINT
echo"${IPv4addr%/*}" > /tmp/piholeIP
echo"$piholeInterface" > /tmp/piholeINT
# After that's done, the loop ends and we move on
ipSettingsCorrect=True
else
@ -292,12 +304,12 @@ setDHCPCD() {
setStaticIPv4(){
# Tries to set the IPv4 address
if grep -q $IPv4addr$dhcpcdFile;then
if grep -q "$IPv4addr"$dhcpcdFile;then
# address already set, noop
:
else
setDHCPCD
$SUDO ip addr replace dev $piholeInterface$IPv4addr
$SUDO ip addr replace dev "$piholeInterface""$IPv4addr"
echo":::"
echo"::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
echo":::"
@ -377,6 +389,7 @@ setDNS(){
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
<<<<<<< HEAD
piholeDNS1=$(echo$piholeDNS| sed 's/[, \t]\+/,/g'| awk -F, '{print$1}')
piholeDNS2=$(echo$piholeDNS| sed 's/[, \t]\+/,/g'| awk -F, '{print$2}')
@ -385,6 +398,16 @@ setDNS(){
fi
if ! valid_ip $piholeDNS2&&[$piholeDNS2];then
=======
piholeDNS1=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$1}')
piholeDNS2=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$2}')
if ! valid_ip "$piholeDNS1"||[ ! "$piholeDNS1"];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
piholeDNS1=""
fi
if[[$piholeDNS2=="$strInvalid"]];then
>>>>>>> ScriptCleanup
piholeDNS2=""
fi
@ -470,14 +505,23 @@ versionCheckDNSmasq(){
installScripts(){
# Install the scripts from /etc/.pihole to their various locations
# 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}')
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev"| awk '{print $4}'| awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
fi
@ -54,18 +54,19 @@ fi
# Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables
basename=pihole
piholeDir=/etc/$basename
adList=$piholeDir/gravity.list
blacklist=$piholeDir/blacklist.txt
whitelist=$piholeDir/whitelist.txt
latentWhitelist=$piholeDir/latentWhitelist.txt
#blacklist=$piholeDir/blacklist.txt
#whitelist=$piholeDir/whitelist.txt
#latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt
supernova=$basename.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.txt
eyeOfTheNeedle=$basename.4.wormhole.txt
#eyeOfTheNeedle=$basename.4.wormhole.txt
# After setting defaults, check if there's local overrides