2015-12-06 13:55:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# (c) 2015 by Jacob Salmela
|
|
|
|
# This file is part of Pi-hole.
|
|
|
|
#
|
|
|
|
# Pi-hole is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
2016-01-14 22:23:15 +00:00
|
|
|
whiteList=/etc/pihole/whitelist.txt
|
2015-11-28 00:38:33 +00:00
|
|
|
adList=/etc/pihole/gravity.list
|
2016-01-14 22:23:15 +00:00
|
|
|
latentWhitelist=/etc/pihole/latentWhitelist.txt
|
|
|
|
if [[ ! -f $whiteList ]];then
|
|
|
|
touch $whiteList
|
2015-11-28 00:29:44 +00:00
|
|
|
fi
|
|
|
|
|
2015-11-28 00:34:02 +00:00
|
|
|
if [[ $# = 0 ]]; then
|
2015-10-25 23:53:20 +00:00
|
|
|
echo "Immediately whitelists one or more domains."
|
|
|
|
echo "Usage: whitelist.sh domain1 [domain2 ...]"
|
|
|
|
fi
|
|
|
|
|
2016-01-14 22:23:15 +00:00
|
|
|
latentPattern=""
|
|
|
|
boolA=false
|
|
|
|
boolB=false
|
2015-07-18 14:39:18 +00:00
|
|
|
for var in "$@"
|
|
|
|
do
|
2016-01-14 22:23:15 +00:00
|
|
|
bool=false;
|
|
|
|
echo "Whitelisting $var..."
|
|
|
|
#add to whitelist.txt if it is not already there
|
|
|
|
grep -Ex -q "$var" $whiteList || boolB=true
|
|
|
|
if $boolB; then
|
|
|
|
echo $var >> $whiteList
|
|
|
|
#add to latentwhitelist.txt. Double-check it's not already there
|
|
|
|
latentPattern=$(echo $var | sed 's/\./\\./g')
|
|
|
|
grep -Ex -q "$latentPattern" $whiteList || echo $latentPattern >> $latentWhitelist
|
|
|
|
boolA=true;
|
|
|
|
else
|
|
|
|
echo "$var Already in whitelist.txt"
|
|
|
|
fi
|
2015-07-18 14:39:18 +00:00
|
|
|
done
|
2015-10-25 23:53:20 +00:00
|
|
|
|
2016-01-14 22:23:15 +00:00
|
|
|
if $boolA; then
|
|
|
|
echo "New domains added to whitelist. Running gravity.sh"
|
|
|
|
/usr/local/bin/gravity.sh
|
|
|
|
else
|
|
|
|
echo "No need to update Hosts list, given domains already in whitelist"
|
2015-10-25 23:53:20 +00:00
|
|
|
fi
|