MERGE FAIL :ashamed_face:

This commit is contained in:
Promofaux 2016-10-23 22:43:11 +01:00
parent 476fd1f695
commit bd0cc134bf

View file

@ -35,7 +35,7 @@ basename=pihole
piholeDir=/etc/${basename} piholeDir=/etc/${basename}
adList=${piholeDir}/gravity.list adList=${piholeDir}/gravity.list
blacklist=${piholeDir}/blacklist.txt blacklist=${piholeDir}/blacklist.txt
reload=false reload=true
addmode=true addmode=true
verbose=true verbose=true
@ -48,87 +48,58 @@ HandleOther(){
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
} }
PopBlacklistFile() { 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[@]}"; do for dom in "${domList[@]}"; do
if "${addmode}"; then if "$addmode"; then
AddDomain "${dom}" AddDomain "$dom"
else else
RemoveDomain "${dom}" RemoveDomain "$dom"
fi fi
done done
} }
AddDomain() { AddDomain() {
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" ${blacklist} || bool=true grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then if ${bool}; then
#domain not found in the blacklist file, add it! #domain not found in the blacklist file, add it!
if ${verbose}; then if ${verbose}; then
echo -n "::: Adding $1 to blacklist file..." echo -n "::: Adding $1 to blacklist file..."
fi fi
echo "${1}" >> ${blacklist} echo "$1" >> ${blacklist}
modifyHost=true
echo " done!" echo " done!"
else else
if ${verbose}; then if ${verbose}; then
echo "::: ${1} already exists in ${blacklist}! No need to add" echo "::: $1 already exists in $blacklist! No need to add"
fi fi
fi fi
} }
RemoveDomain() { RemoveDomain() {
bool=false
grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then
#Domain is not in the blacklist file, no need to Remove
if ${verbose}; then
echo "::: $1 is NOT blacklisted! No need to remove"
fi
else
#Domain is in the blacklist file, remove it
if ${verbose}; then
echo "::: Un-blacklisting ${dom}..."
fi
echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
fi
}
ModifyHostFile() { bool=false
if ${addmode}; then grep -Ex -q "$1" ${blacklist} || bool=true
#add domains to the hosts file if ${bool}; then
if [[ -r ${blacklist} ]]; then #Domain is not in the blacklist file, no need to Remove
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) if ${verbose}; then
plural=; [[ "${numberOf}" != "1" ]] && plural=s echo "::: $1 is NOT blacklisted! No need to remove"
echo ":::" fi
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." else
if [[ -n ${piholeIPv6} ]]; then #Domain is in the blacklist file,remove it
cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} if ${verbose}; then
else echo "::: Un-blacklisting $dom..."
cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} fi
fi echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
fi fi
else
echo ":::"
for dom in "${domToRemoveList[@]}"; do
#we need to remove the domains from the blacklist file and the host file
echo "::: ${dom}"
echo -n "::: removing from HOSTS file..."
echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList}
echo " done!"
echo -n "::: removing from blackist.txt..."
echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
echo " done!"
done
fi
} }
Reload() { Reload() {
@ -139,24 +110,25 @@ DisplayBlist() {
verbose=false verbose=false
echo -e " Displaying Gravity Affected Domains \n" echo -e " Displaying Gravity Affected Domains \n"
count=1 count=1
while IFS= read -r AD; do while IFS= read -r AD
echo "${count}: ${AD}" do
echo "${count}: $AD"
count=$((count+1)) count=$((count+1))
done < "${blacklist}" done < "$blacklist"
exit 0;
} }
################################################### ###################################################
for var in "$@"; do for var in "$@"
case "$var" in do
"-nr"| "--noreload" ) reload=false;; case "$var" in
"-d" | "--delmode" ) addmode=false;; "-nr"| "--noreload" ) reload=false;;
"-q" | "--quiet" ) verbose=false;; "-d" | "--delmode" ) addmode=false;;
"-h" | "--help" ) helpFunc;; "-q" | "--quiet" ) verbose=false;;
"-l" | "--list" ) DisplayBlist;; "-h" | "--help" ) helpFunc;;
* ) HandleOther "$var";; "-l" | "--list" ) DisplayBlist;;
esac * ) HandleOther "$var";;
esac
done done
PopBlacklistFile PopBlacklistFile