1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Not hardcoding dns and covering all blockingmodes

Using double brackets

Mode double brackets
This commit is contained in:
Gusher123 2018-08-12 01:15:42 +02:00 committed by Gusher123
parent e58142b4ac
commit 03a9d3bc5b

View File

@ -68,6 +68,17 @@ else
exit 1 exit 1
fi fi
# Source pihole-FTL from install script
pihole_FTL="${piholeDir}/pihole-FTL.conf"
if [[ -f "${pihole_FTL}" ]]; then
source "${pihole_FTL}"
if [[ -z "${BLOCKINGMODE}" ]] ; then
BLOCKINGMODE="Default (NULL)"
fi
else
BLOCKINGMODE="Default (NULL)"
fi
# Determine if superseded pihole.conf exists # Determine if superseded pihole.conf exists
if [[ -r "${piholeDir}/pihole.conf" ]]; then if [[ -r "${piholeDir}/pihole.conf" ]]; then
echo -e " ${COL_LIGHT_RED}Ignoring overrides specified within pihole.conf! ${COL_NC}" echo -e " ${COL_LIGHT_RED}Ignoring overrides specified within pihole.conf! ${COL_NC}"
@ -216,20 +227,31 @@ gravity_DownloadBlocklistFromUrl() {
str="Status:" str="Status:"
echo -ne " ${INFO} ${str} Pending..." echo -ne " ${INFO} ${str} Pending..."
# Determine if the domain is blocked by Pi-hole blocked=false
if [ `dig $domain +short | grep 0.0.0.0 -c` -ge 1 ]; then case $BLOCKINGMODE in
# If the domain is blocked by Pi-hole, use an alternate dns server to lookup the ip adres "IP-NODATA-AAAA"|"IP")
ip=`dig @1.1.1.1 +short $domain` if [[ $(dig "${domain}" +short | grep "${IPV4_ADDRESS}" -c) -ge 1 ]]; then
# Determine the port to be used by curl. If "https://" is not present, port 80 is asumed blocked=true
if [ `echo $url | awk -F '://' '{print $1}'` = "https" ]; then fi;;
"NXDOMAIN")
if [[ $(dig "${domain}" | grep "NXDOMAIN" -c) -ge 1 ]]; then
blocked=true
fi;;
"NULL"|"Default (NULL)"|*)
if [[ $(dig "${domain}" +short | grep "0.0.0.0" -c) -ge 1 ]]; then
blocked=true
fi;;
esac
if [[ "${blocked}" = true ]]; then
ip=$(dig "@${CONDITIONAL_FORWARDING_IP}" +short "${domain}")
if [[ $(echo "${url}" | awk -F '://' '{print $1}') = "https" ]]; then
port=443; port=443;
else else port=80
port=80
fi fi
# Print some extra info bad_list=$(pihole -q -adlist hosts-file.net | head -n1 | awk -F 'Match found in ' '{print $2}')
echo -e "${OVER} ${CROSS} ${str} ${domain} is currently blocked by pi-hole. Circumventing pi-hole and trying again"; echo -e "${OVER} ${CROSS} ${str} ${domain} is blocked by ${bad_list%:} on Pi-hole. Using DNS on ${CONDITIONAL_FORWARDING_IP} to download ${url}";
echo -ne " ${INFO} ${str} Pending..." echo -ne " ${INFO} ${str} Pending..."
# Add extra options to $cmd_ext
cmd_ext="--resolve $domain:$port:$ip $cmd_ext" cmd_ext="--resolve $domain:$port:$ip $cmd_ext"
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086