mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
remove trailing whitespace whitelist.sh
This commit is contained in:
parent
876c51302a
commit
ced0ae0d65
1 changed files with 16 additions and 16 deletions
|
@ -50,13 +50,13 @@ if [[ -f $piholeIPv6file ]];then
|
|||
fi
|
||||
|
||||
|
||||
function HandleOther(){
|
||||
function HandleOther(){
|
||||
#check validity of domain
|
||||
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
|
||||
else
|
||||
domList=("${domList[@]}" $validDomain)
|
||||
fi
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ function PopWhitelistFile(){
|
|||
#check whitelist file exists, and if not, create it
|
||||
if [[ ! -f $whitelist ]];then
|
||||
touch $whitelist
|
||||
fi
|
||||
fi
|
||||
for dom in "${domList[@]}"
|
||||
do
|
||||
do
|
||||
if $addmode; then
|
||||
AddDomain $dom
|
||||
else
|
||||
|
@ -79,7 +79,7 @@ function PopWhitelistFile(){
|
|||
function AddDomain(){
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
|
||||
|
||||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
#domain not found in the whitelist file, add it!
|
||||
|
@ -99,7 +99,7 @@ function AddDomain(){
|
|||
}
|
||||
|
||||
function RemoveDomain(){
|
||||
|
||||
|
||||
bool=false
|
||||
grep -Ex -q "$1" $whitelist || bool=true
|
||||
if $bool; then
|
||||
|
@ -113,11 +113,11 @@ function RemoveDomain(){
|
|||
#echo "::: Un-whitelisting $dom..."
|
||||
#fi
|
||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||
modifyHost=true
|
||||
fi
|
||||
modifyHost=true
|
||||
fi
|
||||
}
|
||||
|
||||
function ModifyHostFile(){
|
||||
function ModifyHostFile(){
|
||||
if $addmode; then
|
||||
#remove domains in from hosts file
|
||||
if [[ -r $whitelist ]];then
|
||||
|
@ -129,19 +129,19 @@ function ModifyHostFile(){
|
|||
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
|
||||
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
|
||||
else
|
||||
#we need to add the removed domains to the hosts file
|
||||
echo ":::"
|
||||
echo "::: Modifying HOSTS file to un-whitelist domains..."
|
||||
for rdom in "${domToRemoveList[@]}"
|
||||
do
|
||||
do
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
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
|
||||
|
@ -155,7 +155,7 @@ function ModifyHostFile(){
|
|||
echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function Reload() {
|
||||
|
@ -179,10 +179,10 @@ function Reload() {
|
|||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
* ) HandleOther $var;;
|
||||
esac
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue