mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-03 12:40:56 +00:00
Merge pull request #1534 from pi-hole/new/black.list
Introducing black.list
This commit is contained in:
commit
6f2ec22894
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
addn-hosts=/etc/pihole/gravity.list
|
addn-hosts=/etc/pihole/gravity.list
|
||||||
addn-hosts=/etc/pihole/local.list
|
addn-hosts=/etc/pihole/local.list
|
||||||
|
addn-hosts=/etc/pihole/black.list
|
||||||
|
|
||||||
domain-needed
|
domain-needed
|
||||||
|
|
||||||
|
109
gravity.sh
109
gravity.sh
@ -54,6 +54,7 @@ IPV6_ADDRESS=${IPV6_ADDRESS}
|
|||||||
basename=pihole
|
basename=pihole
|
||||||
piholeDir=/etc/${basename}
|
piholeDir=/etc/${basename}
|
||||||
adList=${piholeDir}/gravity.list
|
adList=${piholeDir}/gravity.list
|
||||||
|
blackList=${piholeDir}/black.list
|
||||||
localList=${piholeDir}/local.list
|
localList=${piholeDir}/local.list
|
||||||
justDomainsExtension=domains
|
justDomainsExtension=domains
|
||||||
matterAndLight=${basename}.0.matterandlight.txt
|
matterAndLight=${basename}.0.matterandlight.txt
|
||||||
@ -235,9 +236,7 @@ gravity_Blacklist() {
|
|||||||
if [[ -f "${blacklistFile}" ]]; then
|
if [[ -f "${blacklistFile}" ]]; then
|
||||||
numBlacklisted=$(wc -l < "${blacklistFile}")
|
numBlacklisted=$(wc -l < "${blacklistFile}")
|
||||||
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
|
||||||
echo -n "::: Blacklisting $numBlacklisted domain${plural}..."
|
echo "::: Exact blocked domain${plural}: $numBlacklisted"
|
||||||
cat ${blacklistFile} >> ${piholeDir}/${eventHorizon}
|
|
||||||
echo " done!"
|
|
||||||
else
|
else
|
||||||
echo "::: Nothing to blacklist!"
|
echo "::: Nothing to blacklist!"
|
||||||
fi
|
fi
|
||||||
@ -299,9 +298,25 @@ gravity_unique() {
|
|||||||
echo "::: $numberOf unique domains trapped in the event horizon."
|
echo "::: $numberOf unique domains trapped in the event horizon."
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity_hostFormat() {
|
gravity_doHostFormat() {
|
||||||
|
# Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both.
|
||||||
|
if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then
|
||||||
|
# Both IPv4 and IPv6
|
||||||
|
awk -v ipv4addr="$IPV4_ADDRESS" -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> "${2}" < "${1}"
|
||||||
|
elif [[ -n "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then
|
||||||
|
# Only IPv4
|
||||||
|
awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> "${2}" < "${1}"
|
||||||
|
elif [[ -z "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then
|
||||||
|
# Only IPv6
|
||||||
|
awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> "${2}" < "${1}"
|
||||||
|
elif [[ -z "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then
|
||||||
|
echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
gravity_hostFormatLocal() {
|
||||||
# Format domain list as "192.168.x.x domain.com"
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
echo -n "::: Formatting domains into a HOSTS file..."
|
|
||||||
|
|
||||||
if [[ -f /etc/hostname ]]; then
|
if [[ -f /etc/hostname ]]; then
|
||||||
hostname=$(</etc/hostname)
|
hostname=$(</etc/hostname)
|
||||||
@ -310,33 +325,32 @@ gravity_hostFormat() {
|
|||||||
else
|
else
|
||||||
echo "::: Error: Unable to determine fully qualified domain name of host"
|
echo "::: Error: Unable to determine fully qualified domain name of host"
|
||||||
fi
|
fi
|
||||||
# Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both.
|
|
||||||
if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then
|
|
||||||
|
|
||||||
echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV6_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole\n${IPV6_ADDRESS} pi.hole" > ${localList}
|
echo -e "${hostname}\npi.hole" > "${localList}.tmp"
|
||||||
# Both IPv4 and IPv6
|
# Copy the file over as /etc/pihole/local.list so dnsmasq can use it
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
rm "${localList}"
|
||||||
|
gravity_doHostFormat "${localList}.tmp" "${localList}"
|
||||||
elif [[ -n "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then
|
rm "${localList}.tmp"
|
||||||
|
}
|
||||||
echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole" > ${localList}
|
|
||||||
# Only IPv4
|
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
|
||||||
|
|
||||||
elif [[ -z "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then
|
|
||||||
|
|
||||||
echo -e "${IPV6_ADDRESS} ${hostname}\n${IPV6_ADDRESS} pi.hole" > ${localList}
|
|
||||||
# Only IPv6
|
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
|
||||||
|
|
||||||
elif [[ -z "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then
|
|
||||||
echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
gravity_hostFormatGravity() {
|
||||||
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
|
echo "" > "${piholeDir}/${accretionDisc}"
|
||||||
|
gravity_doHostFormat "${piholeDir}/${eventHorizon}" "${piholeDir}/${accretionDisc}"
|
||||||
# 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}
|
mv "${piholeDir}/${accretionDisc}" "${adList}"
|
||||||
echo " done!"
|
}
|
||||||
|
|
||||||
|
gravity_hostFormatBlack() {
|
||||||
|
if [[ -f "${blacklistFile}" ]]; then
|
||||||
|
numBlacklisted=$(wc -l < "${blacklistFile}")
|
||||||
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
|
gravity_doHostFormat "${blacklistFile}" "${blackList}.tmp"
|
||||||
|
# Copy the file over as /etc/pihole/black.list so dnsmasq can use it
|
||||||
|
mv "${blackList}.tmp" "${blackList}"
|
||||||
|
else
|
||||||
|
echo "::: Nothing to blacklist!"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# blackbody - remove any remnant files from script processes
|
# blackbody - remove any remnant files from script processes
|
||||||
@ -377,11 +391,6 @@ gravity_advanced() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gravity_reload() {
|
gravity_reload() {
|
||||||
#Clear no longer needed files...
|
|
||||||
echo ":::"
|
|
||||||
echo -n "::: Cleaning up un-needed files..."
|
|
||||||
rm ${piholeDir}/pihole.*.txt
|
|
||||||
echo " done!"
|
|
||||||
|
|
||||||
# Reload hosts file
|
# Reload hosts file
|
||||||
echo ":::"
|
echo ":::"
|
||||||
@ -402,6 +411,7 @@ for var in "$@"; do
|
|||||||
"-f" | "--force" ) forceGrav=true;;
|
"-f" | "--force" ) forceGrav=true;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
"-sd" | "--skip-download" ) skipDownload=true;;
|
"-sd" | "--skip-download" ) skipDownload=true;;
|
||||||
|
"-b" | "--blacklist-only" ) blackListOnly=true;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -411,22 +421,39 @@ if [[ "${forceGrav}" == true ]]; then
|
|||||||
echo " done!"
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gravity_collapse
|
if [[ ! "${blackListOnly}" == true ]]; then
|
||||||
gravity_spinup
|
gravity_collapse
|
||||||
if [[ "${skipDownload}" == false ]]; then
|
gravity_spinup
|
||||||
|
if [[ "${skipDownload}" == false ]]; then
|
||||||
gravity_Schwarzchild
|
gravity_Schwarzchild
|
||||||
gravity_advanced
|
gravity_advanced
|
||||||
else
|
else
|
||||||
echo "::: Using cached Event Horizon list..."
|
echo "::: Using cached Event Horizon list..."
|
||||||
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon})
|
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon})
|
||||||
echo "::: $numberOf unique domains trapped in the event horizon."
|
echo "::: $numberOf unique domains trapped in the event horizon."
|
||||||
|
fi
|
||||||
|
gravity_Whitelist
|
||||||
fi
|
fi
|
||||||
gravity_Whitelist
|
|
||||||
gravity_Blacklist
|
gravity_Blacklist
|
||||||
gravity_Wildcard
|
gravity_Wildcard
|
||||||
|
|
||||||
gravity_hostFormat
|
echo -n "::: Formatting domains into a HOSTS file..."
|
||||||
|
if [[ ! "${blackListOnly}" == true ]]; then
|
||||||
|
gravity_hostFormatLocal
|
||||||
|
gravity_hostFormatGravity
|
||||||
|
fi
|
||||||
|
gravity_hostFormatBlack
|
||||||
|
echo " done!"
|
||||||
|
|
||||||
gravity_blackbody
|
gravity_blackbody
|
||||||
|
|
||||||
|
if [[ ! "${blackListOnly}" == true ]]; then
|
||||||
|
#Clear no longer needed files...
|
||||||
|
echo ":::"
|
||||||
|
echo -n "::: Cleaning up un-needed files..."
|
||||||
|
rm ${piholeDir}/pihole.*.txt
|
||||||
|
echo " done!"
|
||||||
|
fi
|
||||||
|
|
||||||
gravity_reload
|
gravity_reload
|
||||||
"${PIHOLE_COMMAND}" status
|
"${PIHOLE_COMMAND}" status
|
||||||
|
1
pihole
1
pihole
@ -193,6 +193,7 @@ Time:
|
|||||||
elif [[ "${1}" == "0" ]]; then
|
elif [[ "${1}" == "0" ]]; then
|
||||||
# Disable Pi-hole
|
# Disable Pi-hole
|
||||||
sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf
|
sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
sed -i 's/^addn-hosts=\/etc\/pihole\/black.list/#addn-hosts=\/etc\/pihole\/black.list/' /etc/dnsmasq.d/01-pihole.conf
|
||||||
if [[ -e "$wildcardlist" ]]; then
|
if [[ -e "$wildcardlist" ]]; then
|
||||||
mv "$wildcardlist" "/etc/pihole/wildcard.list"
|
mv "$wildcardlist" "/etc/pihole/wildcard.list"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user