Make gravity / bblacklist / whitlist and make use of pihole.conf

This commit is contained in:
Tommy Huff 2016-10-05 20:13:08 -04:00
parent 6eedfb572e
commit 192c627e27
4 changed files with 65 additions and 85 deletions

View file

@ -45,22 +45,16 @@ if [[ $# = 0 ]]; then
helpFunc
fi
#globals
basename=pihole
piholeDir=/etc/${basename}
adList=${piholeDir}/gravity.list
blacklist=${piholeDir}/blacklist.txt
reload=true
addmode=true
force=false
verbose=true
# After setting defaults, check if there's local overrides
if [[ -r ../../pihole.conf ]];then
echo "::: Local calibration requested..."
source ../../pihole.conf
fi
domList=()
domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
if [[ -f ${piholeIPfile} ]];then
# 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})
@ -74,13 +68,6 @@ fi
modifyHost=false
# After setting defaults, check if there's local overrides
if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: Local calibration requested..."
. ${piholeDir}/pihole.conf
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) }')

View file

@ -45,22 +45,16 @@ if [[ $# = 0 ]]; then
helpFunc
fi
#globals
basename=pihole
piholeDir=/etc/${basename}
adList=${piholeDir}/gravity.list
whitelist=${piholeDir}/whitelist.txt
reload=true
addmode=true
force=false
verbose=true
# After setting defaults, check if there's local overrides
if [[ -r ../../pihole.conf ]];then
echo "::: Local calibration requested..."
source ../../pihole.conf
fi
domList=()
domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
if [[ -f ${piholeIPfile} ]];then
# 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})
@ -74,12 +68,6 @@ fi
modifyHost=false
# After setting defaults, check if there's local overrides
if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: Local calibration requested..."
. ${piholeDir}/pihole.conf
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) }')
@ -160,8 +148,8 @@ function ModifyHostFile(){
plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > ${piholeDir}/whitelist.tmp
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> ${piholeDir}/whitelist.tmp
echo "l" >> /etc/pihole/whitelist.tmp
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
rm ${adList}

View file

@ -39,13 +39,6 @@ function helpFunc()
exit 1
}
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
adListFile=/etc/pihole/adlists.list
adListDefault=/etc/pihole/adlists.default
whitelistScript=/opt/pihole/whitelist.sh
blacklistScript=/opt/pihole/blacklist.sh
if [[ -f ${piholeIPfile} ]];then
# 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
@ -63,25 +56,10 @@ if [[ -f ${piholeIPv6file} ]];then
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
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
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
# After setting defaults, check if there's local overrides
if [[ -r ${piholeDir}/pihole.conf ]];then
if [[ -r pihole.conf ]];then
echo "::: Local calibration requested..."
. ${piholeDir}/pihole.conf
source pihole.conf
fi
###########################
@ -226,7 +204,7 @@ function gravity_Blacklist(){
echo -n "::: Running blacklist script to update HOSTS file...."
${blacklistScript} -f -nr -q > /dev/null
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
numBlacklisted=$(wc -l < "${blacklist}")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
echo " $numBlacklisted domain${plural} blacklisted!"
}
@ -247,7 +225,7 @@ function gravity_Whitelist() {
echo -n "::: Running whitelist script to update HOSTS file...."
${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
numWhitelisted=$(wc -l < "${whitelist}")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!"
}
@ -316,27 +294,31 @@ function gravity_reload() {
echo -n "::: Cleaning up un-needed files..."
${SUDO} rm ${piholeDir}/pihole.*.txt
echo " done!"
# Reload hosts file
echo ":::"
echo -n "::: Refresh lists in dnsmasq..."
#ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
#First escape forward slashes in the path:
adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file
${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
dnsmasqPid=$(pidof dnsmasq)
find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
if [[ ${dnsmasqPid} ]]; then
# service already running - reload config
${SUDO} killall -s HUP dnsmasq
if [ ${etchosts} == "1" ] ; then
${SUDO} cp ${adList} /etc/hosts
else
# service not running, start it up
${SUDO} service dnsmasq start
# Reload hosts file
echo ":::"
echo -n "::: Refresh lists in dnsmasq..."
#ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list!
#First escape forward slashes in the path:
adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file
${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
dnsmasqPid=$(pidof dnsmasq)
if [[ ${dnsmasqPid} ]]; then
# service already running - reload config
${SUDO} killall -s HUP dnsmasq
else
# service not running, start it up
${SUDO} service dnsmasq start
fi
fi
# SHOULDNT NEED TO CHMOD THE WHOLE DIR
# find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
${SUDO} chmod 644 "${adList}"
echo " done!"
}
@ -357,7 +339,7 @@ if [[ ${forceGrav} == true ]]; then
echo " done!"
fi
${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
#${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
gravity_collapse
gravity_spinup
gravity_Schwarzchild

23
pihole.conf Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
# Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables
export basename=pihole
export piholeDir=/home/ubuntu/FORKHOLE/pi-hole
export adList=${piholeDir}/gravity.list
export adListFile=${piholeDir}/adlists.list
export adListDefault=${piholeDir}/adlists.default
export whitelistScript=${piholeDir}/advanced/Scripts/whitelist.sh
export blacklistScript=${piholeDir}/advanced/Scripts/blacklist.sh
export piholeIPfile=${piholeDir}/piholeIP
export piholeIPv6file=${piholeDir}/.useIPv6
export blacklist=$piholeDir/blacklist.txt
export whitelist=$piholeDir/whitelist.txt
#export latentWhitelist=$piholeDir/latentWhitelist.txt
export justDomainsExtension=domains
export matterandlight=${basename}.0.matterandlight.txt
export supernova=${basename}.1.supernova.txt
export eventHorizon=${basename}.2.eventHorizon.txt
export accretionDisc=${basename}.3.accretionDisc.txt
#export eyeOfTheNeedle=$basename.4.wormhole.txt
export etchosts=1 # Push to /ETC/Hosts/ or DNSMASQ