mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 06:10:20 +00:00
... Helps if I add the changes to the repo file, and not the test file on my pi.
This commit is contained in:
parent
39507b9d0d
commit
3cd1a5b1d5
1 changed files with 36 additions and 18 deletions
|
@ -76,12 +76,13 @@ function PopWhitelistFile(){
|
||||||
function AddDomain(){
|
function AddDomain(){
|
||||||
#| sed 's/\./\\./g'
|
#| sed 's/\./\\./g'
|
||||||
bool=false
|
bool=false
|
||||||
if $versbose; then
|
|
||||||
echo -n "::: Whitelisting $1...."
|
|
||||||
fi
|
|
||||||
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!
|
||||||
|
if $versbose; then
|
||||||
|
echo -n "::: Adding $1 to whitelist.txt..."
|
||||||
|
fi
|
||||||
echo $1 >> $whitelist
|
echo $1 >> $whitelist
|
||||||
modifyHost=true
|
modifyHost=true
|
||||||
if $versbose; then
|
if $versbose; then
|
||||||
|
@ -89,7 +90,7 @@ function AddDomain(){
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if $versbose; then
|
if $versbose; then
|
||||||
echo " already whitelisted! No need to add"
|
echo "::: $1 already exists in whitelist.txt, no need to add!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -105,9 +106,9 @@ function RemoveDomain(){
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
|
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
|
||||||
if $versbose; then
|
#if $versbose; then
|
||||||
echo "** Un-whitelisting $dom..."
|
#echo "::: Un-whitelisting $dom..."
|
||||||
fi
|
#fi
|
||||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||||
modifyHost=true
|
modifyHost=true
|
||||||
fi
|
fi
|
||||||
|
@ -120,28 +121,44 @@ function ModifyHostFile(){
|
||||||
# Remove whitelist entries
|
# Remove whitelist entries
|
||||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo "** Whitelisting a total of $numberOf domain${plural}..."
|
echo ":::"
|
||||||
awk -F':' '{ print $1 }' $whitelist | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
||||||
|
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
|
||||||
|
echo "l" >> /etc/pihole/whitelist.tmp
|
||||||
|
grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp
|
||||||
|
rm /etc/pihole/gravity.list
|
||||||
|
mv /etc/pihole/gravity.tmp /etc/pihole/gravity.list
|
||||||
|
rm /etc/pihole/whitelist.tmp
|
||||||
|
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 "::: 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 "**Blacklisting $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
|
||||||
|
echo " done!"
|
||||||
else
|
else
|
||||||
echo "**Blacklisting $rdom on IPv4"
|
echo -n "::: Un-whitelisting $rdom on IPv4"
|
||||||
echo $rdom | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
echo $rdom | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||||
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
|
echo -n "::: Removing $rdom from whitelist.txt..."
|
||||||
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!"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function Reload() {
|
function Reload() {
|
||||||
# Reload hosts file
|
# Reload hosts file
|
||||||
echo "** Refresh lists in dnsmasq..."
|
echo ":::"
|
||||||
|
echo -n "::: Refresh lists in dnsmasq..."
|
||||||
dnsmasqPid=$(pidof dnsmasq)
|
dnsmasqPid=$(pidof dnsmasq)
|
||||||
|
|
||||||
if [[ $dnsmasqPid ]]; then
|
if [[ $dnsmasqPid ]]; then
|
||||||
|
@ -151,6 +168,7 @@ function Reload() {
|
||||||
# service not running, start it up
|
# service not running, start it up
|
||||||
sudo service dnsmasq start
|
sudo service dnsmasq start
|
||||||
fi
|
fi
|
||||||
|
echo " done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
|
@ -169,11 +187,11 @@ done
|
||||||
PopWhitelistFile
|
PopWhitelistFile
|
||||||
|
|
||||||
if $modifyHost || $force; then
|
if $modifyHost || $force; then
|
||||||
echo "** Modifying Hosts File"
|
|
||||||
ModifyHostFile
|
ModifyHostFile
|
||||||
else
|
else
|
||||||
if $versbose; then
|
if $versbose; then
|
||||||
echo "** No changes need to be made"
|
echo ":::"
|
||||||
|
echo "::: No changes need to be made"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue