mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
remove trailing whitespace blacklist.sh
This commit is contained in:
parent
4f90b41343
commit
f633d1fa5b
1 changed files with 24 additions and 24 deletions
|
@ -51,13 +51,13 @@ if [[ -f $piholeIPv6file ]];then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
function HandleOther(){
|
function HandleOther(){
|
||||||
#check validity of domain
|
#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/')
|
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
|
if [ -z "$validDomain" ]; then
|
||||||
echo $1 is not a valid argument or domain name
|
echo $1 is not a valid argument or domain name
|
||||||
else
|
else
|
||||||
domList=("${domList[@]}" $validDomain)
|
domList=("${domList[@]}" $validDomain)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,9 @@ function PopBlacklistFile(){
|
||||||
#check blacklist file exists, and if not, create it
|
#check blacklist file exists, and if not, create it
|
||||||
if [[ ! -f $blacklist ]];then
|
if [[ ! -f $blacklist ]];then
|
||||||
touch $blacklist
|
touch $blacklist
|
||||||
fi
|
fi
|
||||||
for dom in "${domList[@]}"
|
for dom in "${domList[@]}"
|
||||||
do
|
do
|
||||||
if $addmode; then
|
if $addmode; then
|
||||||
AddDomain $dom
|
AddDomain $dom
|
||||||
else
|
else
|
||||||
|
@ -97,7 +97,7 @@ function AddDomain(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function RemoveDomain(){
|
function RemoveDomain(){
|
||||||
|
|
||||||
bool=false
|
bool=false
|
||||||
grep -Ex -q "$1" $blacklist || bool=true
|
grep -Ex -q "$1" $blacklist || bool=true
|
||||||
if $bool; then
|
if $bool; then
|
||||||
|
@ -110,42 +110,42 @@ function RemoveDomain(){
|
||||||
if $versbose; then
|
if $versbose; then
|
||||||
echo "::: Un-blacklisting $dom..."
|
echo "::: Un-blacklisting $dom..."
|
||||||
fi
|
fi
|
||||||
domToRemoveList=("${domToRemoveList[@]}" $1)
|
domToRemoveList=("${domToRemoveList[@]}" $1)
|
||||||
modifyHost=true
|
modifyHost=true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ModifyHostFile(){
|
function ModifyHostFile(){
|
||||||
if $addmode; then
|
if $addmode; then
|
||||||
#add domains to the hosts file
|
#add domains to the hosts file
|
||||||
if [[ -r $blacklist ]];then
|
if [[ -r $blacklist ]];then
|
||||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||||
if [[ -n $piholeIPv6 ]];then
|
if [[ -n $piholeIPv6 ]];then
|
||||||
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||||
else
|
else
|
||||||
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
||||||
echo ":::"
|
echo ":::"
|
||||||
for dom in "${domToRemoveList[@]}"
|
for dom in "${domToRemoveList[@]}"
|
||||||
do
|
do
|
||||||
#we need to remove the domains from the blacklist file and the host file
|
#we need to remove the domains from the blacklist file and the host file
|
||||||
echo "::: $dom"
|
echo "::: $dom"
|
||||||
echo -n "::: removing from HOSTS file..."
|
echo -n "::: removing from HOSTS file..."
|
||||||
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
|
||||||
echo " done!"
|
echo " done!"
|
||||||
echo -n "::: removing from blackist.txt..."
|
echo -n "::: removing from blackist.txt..."
|
||||||
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
|
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
|
||||||
echo " done!"
|
echo " done!"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Reload() {
|
function Reload() {
|
||||||
|
@ -170,17 +170,17 @@ function Reload() {
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
case "$var" in
|
case "$var" in
|
||||||
"-nr"| "--noreload" ) reload=false;;
|
"-nr"| "--noreload" ) reload=false;;
|
||||||
"-d" | "--delmode" ) addmode=false;;
|
"-d" | "--delmode" ) addmode=false;;
|
||||||
"-f" | "--force" ) force=true;;
|
"-f" | "--force" ) force=true;;
|
||||||
"-q" | "--quiet" ) versbose=false;;
|
"-q" | "--quiet" ) versbose=false;;
|
||||||
* ) HandleOther $var;;
|
* ) HandleOther $var;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
PopBlacklistFile
|
PopBlacklistFile
|
||||||
|
|
||||||
if $modifyHost || $force; then
|
if $modifyHost || $force; then
|
||||||
ModifyHostFile
|
ModifyHostFile
|
||||||
else
|
else
|
||||||
if $versbose; then
|
if $versbose; then
|
||||||
|
|
Loading…
Reference in a new issue