mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-01 02:23:21 +00:00
Make gravity / bblacklist / whitlist and make use of pihole.conf
This commit is contained in:
parent
6eedfb572e
commit
192c627e27
4 changed files with 65 additions and 85 deletions
|
@ -45,22 +45,16 @@ if [[ $# = 0 ]]; then
|
||||||
helpFunc
|
helpFunc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#globals
|
# After setting defaults, check if there's local overrides
|
||||||
basename=pihole
|
if [[ -r ../../pihole.conf ]];then
|
||||||
piholeDir=/etc/${basename}
|
echo "::: Local calibration requested..."
|
||||||
adList=${piholeDir}/gravity.list
|
source ../../pihole.conf
|
||||||
blacklist=${piholeDir}/blacklist.txt
|
fi
|
||||||
reload=true
|
|
||||||
addmode=true
|
|
||||||
force=false
|
|
||||||
verbose=true
|
|
||||||
|
|
||||||
domList=()
|
domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
piholeIPfile=/etc/pihole/piholeIP
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
|
||||||
|
|
||||||
if [[ -f ${piholeIPfile} ]];then
|
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
|
# 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})
|
piholeIP=$(cat ${piholeIPfile})
|
||||||
|
@ -74,13 +68,6 @@ fi
|
||||||
|
|
||||||
modifyHost=false
|
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 [[ -f ${piholeIPv6file} ]];then
|
||||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
# 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) }')
|
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||||
|
|
|
@ -45,22 +45,16 @@ if [[ $# = 0 ]]; then
|
||||||
helpFunc
|
helpFunc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#globals
|
# After setting defaults, check if there's local overrides
|
||||||
basename=pihole
|
if [[ -r ../../pihole.conf ]];then
|
||||||
piholeDir=/etc/${basename}
|
echo "::: Local calibration requested..."
|
||||||
adList=${piholeDir}/gravity.list
|
source ../../pihole.conf
|
||||||
whitelist=${piholeDir}/whitelist.txt
|
fi
|
||||||
reload=true
|
|
||||||
addmode=true
|
|
||||||
force=false
|
|
||||||
verbose=true
|
|
||||||
|
|
||||||
domList=()
|
domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
piholeIPfile=/etc/pihole/piholeIP
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
|
||||||
|
|
||||||
if [[ -f ${piholeIPfile} ]];then
|
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
|
# 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})
|
piholeIP=$(cat ${piholeIPfile})
|
||||||
|
@ -74,12 +68,6 @@ fi
|
||||||
|
|
||||||
modifyHost=false
|
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 [[ -f ${piholeIPv6file} ]];then
|
||||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
# 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) }')
|
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
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
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 "$piholeIP $line"; done > ${piholeDir}/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 "$piholeIPv6 $line"; done >> ${piholeDir}/whitelist.tmp
|
||||||
echo "l" >> /etc/pihole/whitelist.tmp
|
echo "l" >> /etc/pihole/whitelist.tmp
|
||||||
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
|
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
|
||||||
rm ${adList}
|
rm ${adList}
|
||||||
|
|
44
gravity.sh
44
gravity.sh
|
@ -39,13 +39,6 @@ function helpFunc()
|
||||||
exit 1
|
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 [[ -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
|
# 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) }')
|
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||||
fi
|
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
|
# After setting defaults, check if there's local overrides
|
||||||
if [[ -r ${piholeDir}/pihole.conf ]];then
|
if [[ -r pihole.conf ]];then
|
||||||
echo "::: Local calibration requested..."
|
echo "::: Local calibration requested..."
|
||||||
. ${piholeDir}/pihole.conf
|
source pihole.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
@ -226,7 +204,7 @@ function gravity_Blacklist(){
|
||||||
echo -n "::: Running blacklist script to update HOSTS file...."
|
echo -n "::: Running blacklist script to update HOSTS file...."
|
||||||
${blacklistScript} -f -nr -q > /dev/null
|
${blacklistScript} -f -nr -q > /dev/null
|
||||||
|
|
||||||
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
|
numBlacklisted=$(wc -l < "${blacklist}")
|
||||||
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
||||||
echo " $numBlacklisted domain${plural} blacklisted!"
|
echo " $numBlacklisted domain${plural} blacklisted!"
|
||||||
}
|
}
|
||||||
|
@ -247,7 +225,7 @@ function gravity_Whitelist() {
|
||||||
|
|
||||||
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
|
${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
|
||||||
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
|
numWhitelisted=$(wc -l < "${whitelist}")
|
||||||
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
||||||
echo " $numWhitelisted domain${plural} whitelisted!"
|
echo " $numWhitelisted domain${plural} whitelisted!"
|
||||||
}
|
}
|
||||||
|
@ -316,7 +294,9 @@ function gravity_reload() {
|
||||||
echo -n "::: Cleaning up un-needed files..."
|
echo -n "::: Cleaning up un-needed files..."
|
||||||
${SUDO} rm ${piholeDir}/pihole.*.txt
|
${SUDO} rm ${piholeDir}/pihole.*.txt
|
||||||
echo " done!"
|
echo " done!"
|
||||||
|
if [ ${etchosts} == "1" ] ; then
|
||||||
|
${SUDO} cp ${adList} /etc/hosts
|
||||||
|
else
|
||||||
# Reload hosts file
|
# Reload hosts file
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Refresh lists in dnsmasq..."
|
echo -n "::: Refresh lists in dnsmasq..."
|
||||||
|
@ -327,9 +307,6 @@ function gravity_reload() {
|
||||||
#Now replace the line in dnsmasq file
|
#Now replace the line in dnsmasq file
|
||||||
${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
|
||||||
dnsmasqPid=$(pidof dnsmasq)
|
dnsmasqPid=$(pidof dnsmasq)
|
||||||
|
|
||||||
find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
|
|
||||||
|
|
||||||
if [[ ${dnsmasqPid} ]]; then
|
if [[ ${dnsmasqPid} ]]; then
|
||||||
# service already running - reload config
|
# service already running - reload config
|
||||||
${SUDO} killall -s HUP dnsmasq
|
${SUDO} killall -s HUP dnsmasq
|
||||||
|
@ -337,6 +314,11 @@ function gravity_reload() {
|
||||||
# service not running, start it up
|
# service not running, start it up
|
||||||
${SUDO} service dnsmasq start
|
${SUDO} service dnsmasq start
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
# SHOULDNT NEED TO CHMOD THE WHOLE DIR
|
||||||
|
# find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
|
||||||
|
${SUDO} chmod 644 "${adList}"
|
||||||
|
|
||||||
echo " done!"
|
echo " done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +339,7 @@ if [[ ${forceGrav} == true ]]; then
|
||||||
echo " done!"
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
|
#${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
|
||||||
gravity_collapse
|
gravity_collapse
|
||||||
gravity_spinup
|
gravity_spinup
|
||||||
gravity_Schwarzchild
|
gravity_Schwarzchild
|
||||||
|
|
23
pihole.conf
Normal file
23
pihole.conf
Normal 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
|
Loading…
Reference in a new issue