make hosts with ivp4 and 6

This commit is contained in:
Tommy Huff 2016-10-19 14:36:43 -04:00
parent e93f8d59d9
commit 67f553a7f2
3 changed files with 20 additions and 13 deletions

View file

@ -96,7 +96,12 @@ ModifyHostFile(){
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}..."
sed "s/^/$piholeIP /g" ${blacklist} >> ${adList} if [[ -n "${IPv6_address}" ]] ; then
sed "s/^/${IPv6_address} /g" ${blacklist} >> ${adList}
fi
if [[ -n "${IPv4_address}" ]] ; then
sed "s/^/${IPv4_address} /g" ${blacklist} >> ${adList}
fi
fi fi
else else
echo ":::" echo ":::"

View file

@ -102,7 +102,12 @@ ModifyHostFile(){
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > ${piholeDir}/whitelist.tmp if [[ -n "${IPv6_address}" ]] ; then
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "${IPv6_address} $line"; done >> ${piholeDir}/whitelist.tmp
fi
if [[ -n "${IPv4_address}" ]] ; then
awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "${IPv4_address} $line"; done >> ${piholeDir}/whitelist.tmp
fi
echo "l" >> ${piholeDir}/whitelist.tmp echo "l" >> ${piholeDir}/whitelist.tmp
grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
rm ${adList} rm ${adList}

View file

@ -214,9 +214,14 @@ gravity_hostFormat() {
echo "::: Error: Unable to determine fully qualified domain name of host" echo "::: Error: Unable to determine fully qualified domain name of host"
fi fi
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > ${piholeDir}/${accretionDisc} if [[ -n "${IPv6_address}" ]] ; then
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} echo -e "${IPv6_address} $hostname\n${IPv6_address} pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="${IPv6_address}" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
fi
if [[ -n "${IPv4_address}" ]] ; then
echo -e "${IPv4_address} $hostname\n${IPv4_address} pi.hole" > ${piholeDir}/${accretionDisc}
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4_address}" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp ${piholeDir}/${accretionDisc} ${adList} cp ${piholeDir}/${accretionDisc} ${adList}
} }
@ -313,14 +318,6 @@ else
exit 1 exit 1
fi fi
if [[ -n "${IPv6_address}" ]] ; then
piholeIP=${IPv6_address}
piholeIP=$(echo "${piholeIP}" | cut -f1 -d"/")
else
piholeIP=${IPv4_address}
piholeIP=$(echo "${piholeIP}" | cut -f1 -d"/")
fi
# Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) # Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it)
if [[ -r ${piholeDir}/pihole.conf ]];then if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."