mirror of
https://github.com/pi-hole/pi-hole
synced 2024-11-18 06:08:21 +00:00
Gravity Bugfixes
* Merge development OpenVPN code * Determine which domain to resolve depending on existence of $localList * Re-add code to remove $localList, preventing duplicate local entries * Minor shellcheck validation fix
This commit is contained in:
parent
4d39ab9753
commit
8191ec01e5
30
gravity.sh
30
gravity.sh
@ -32,6 +32,7 @@ wildcardFile="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
|||||||
adList="${piholeDir}/gravity.list"
|
adList="${piholeDir}/gravity.list"
|
||||||
blackList="${piholeDir}/black.list"
|
blackList="${piholeDir}/black.list"
|
||||||
localList="${piholeDir}/local.list"
|
localList="${piholeDir}/local.list"
|
||||||
|
VPNList="/etc/openvpn/ipp.txt"
|
||||||
|
|
||||||
domainsExtension="domains"
|
domainsExtension="domains"
|
||||||
matterAndLight="${basename}.0.matterandlight.txt"
|
matterAndLight="${basename}.0.matterandlight.txt"
|
||||||
@ -66,10 +67,17 @@ fi
|
|||||||
|
|
||||||
# Determine if DNS resolution is available before proceeding with retrieving blocklists
|
# Determine if DNS resolution is available before proceeding with retrieving blocklists
|
||||||
gravity_DNSLookup() {
|
gravity_DNSLookup() {
|
||||||
local plu
|
local lookupDomain plu
|
||||||
|
|
||||||
# Determine if pi.hole can be resolved
|
# Determine which domain to resolve depending on existence of $localList
|
||||||
if ! timeout 10 nslookup pi.hole > /dev/null; then
|
if [[ -e "${localList}" ]]; then
|
||||||
|
lookupDomain="pi.hole"
|
||||||
|
else
|
||||||
|
lookupDomain="raw.githubusercontent.com"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine if domain can be resolved
|
||||||
|
if ! timeout 10 nslookup "${lookupDomain}" > /dev/null; then
|
||||||
if [[ -n "${secs}" ]]; then
|
if [[ -n "${secs}" ]]; then
|
||||||
echo -e "${OVER} ${CROSS} DNS resolution is still unavailable, cancelling"
|
echo -e "${OVER} ${CROSS} DNS resolution is still unavailable, cancelling"
|
||||||
exit 1
|
exit 1
|
||||||
@ -452,20 +460,28 @@ gravity_ParseDomainsIntoHosts() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create "localhost" entries
|
# Create "localhost" entries into hosts format
|
||||||
gravity_ParseLocalDomains() {
|
gravity_ParseLocalDomains() {
|
||||||
local hostname
|
local hostname
|
||||||
|
|
||||||
if [[ -f "/etc/hostname" ]]; then
|
if [[ -f "/etc/hostname" ]]; then
|
||||||
hostname=$(< "/etc/hostname")
|
hostname=$(< "/etc/hostname")
|
||||||
elif command -v hostname > /dev/null; then
|
elif command -v hostname &> /dev/null; then
|
||||||
hostname=$(hostname -f)
|
hostname=$(hostname -f)
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} Unable to determine fully qualified domain name of host"
|
echo -e " ${CROSS} Unable to determine fully qualified domain name of host"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${hostname}\\npi.hole" > "${localList}.tmp"
|
echo -e "${hostname}\\npi.hole" > "${localList}.tmp"
|
||||||
|
# Copy the file over as /etc/pihole/local.list so dnsmasq can use it
|
||||||
|
rm "${localList}" 2> /dev/null || true
|
||||||
gravity_ParseDomainsIntoHosts "${localList}.tmp" "${localList}"
|
gravity_ParseDomainsIntoHosts "${localList}.tmp" "${localList}"
|
||||||
|
rm "${localList}.tmp" 2> /dev/null || true
|
||||||
|
|
||||||
|
# Add additional local hosts provided by OpenVPN (if available)
|
||||||
|
if [[ -f "${VPNList}" ]]; then
|
||||||
|
awk -F, '{printf $2"\t"$1"\n"}' "${VPNList}" >> "${localList}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create primary blacklist entries
|
# Create primary blacklist entries
|
||||||
@ -494,8 +510,6 @@ gravity_ParseUserDomains() {
|
|||||||
# Copy the file over as /etc/pihole/black.list so dnsmasq can use it
|
# Copy the file over as /etc/pihole/black.list so dnsmasq can use it
|
||||||
mv "${blackList}.tmp" "${blackList}" 2> /dev/null || \
|
mv "${blackList}.tmp" "${blackList}" 2> /dev/null || \
|
||||||
echo -e " ${CROSS} Unable to move ${blackList##*/}.tmp to ${piholeDir}"
|
echo -e " ${CROSS} Unable to move ${blackList##*/}.tmp to ${piholeDir}"
|
||||||
else
|
|
||||||
echo -e " ${INFO} Nothing to blacklist!"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,7 +531,7 @@ gravity_Cleanup() {
|
|||||||
# Remove any unused .domains files
|
# Remove any unused .domains files
|
||||||
for file in ${piholeDir}/*.${domainsExtension}; do
|
for file in ${piholeDir}/*.${domainsExtension}; do
|
||||||
# If list is not in active array, then remove it
|
# If list is not in active array, then remove it
|
||||||
if [[ ! "${activeDomains[*]}" =~ "${file}" ]]; then
|
if [[ ! "${activeDomains[*]}" == *"${file}"* ]]; then
|
||||||
rm -f "${file}" 2> /dev/null || \
|
rm -f "${file}" 2> /dev/null || \
|
||||||
echo -e " ${CROSS} Failed to remove ${file##*/}"
|
echo -e " ${CROSS} Failed to remove ${file##*/}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user