mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 23:08:07 +00:00
Split out IP checks.
This commit is contained in:
parent
cfed3d59e9
commit
472708376d
@ -26,7 +26,6 @@ ADLISTFILE="/etc/pihole/adlists.list"
|
|||||||
PIHOLELOG="/var/log/pihole.log"
|
PIHOLELOG="/var/log/pihole.log"
|
||||||
WHITELISTMATCHES="/tmp/whitelistmatches.list"
|
WHITELISTMATCHES="/tmp/whitelistmatches.list"
|
||||||
|
|
||||||
IPV6_READY
|
|
||||||
TIMEOUT=60
|
TIMEOUT=60
|
||||||
# Header info and introduction
|
# Header info and introduction
|
||||||
cat << EOM
|
cat << EOM
|
||||||
@ -181,77 +180,61 @@ processor_check() {
|
|||||||
ipv6_check() {
|
ipv6_check() {
|
||||||
# Check if system is IPv6 enabled, for use in other functions
|
# Check if system is IPv6 enabled, for use in other functions
|
||||||
if [[ $IPV6_ADDRESS ]]; then
|
if [[ $IPV6_ADDRESS ]]; then
|
||||||
ls /proc/net/if_inet6 &>/dev/null && IPV6_READY=true
|
ls /proc/net/if_inet6 &>/dev/null
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ip_check() {
|
ip_check() {
|
||||||
header_write "IP Address Information"
|
local protocol=${1}
|
||||||
# Get the current interface for Internet traffic
|
|
||||||
|
|
||||||
# Check if IPv6 enabled
|
local ip_addr_list="$(ip -${protocol} addr show dev ${PIHOLE_INTERFACE} | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i ~ '/^inet/') print $(i+1) }')"
|
||||||
local IPv6_interface
|
if [[ -n ${ip_addr_list} ]]; then
|
||||||
local IPv4_interface
|
log_write "IPv${protocol} on ${PIHOLE_INTERFACE}"
|
||||||
if ipv6_check; then
|
log_write "${ip_addr_list}"
|
||||||
IPv6_interface=${PIHOLE_INTERFACE:-$(ip -6 r | grep default | cut -d ' ' -f 5)}
|
echo "::: IPv${protocol} addresses located on ${PIHOLE_INTERFACE}"
|
||||||
echo ${PIHOLE_INTERFACE}
|
ip_ping_check ${protocol}
|
||||||
echo ${IPv6_interface}
|
return $(( 0 + $? ))
|
||||||
fi
|
|
||||||
# If declared in setupVars.conf use it, otherwise defer to default
|
|
||||||
# http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash
|
|
||||||
IPv4_interface=${PIHOLE_INTERFACE:-$(ip r | grep default | cut -d ' ' -f 5)}
|
|
||||||
|
|
||||||
|
|
||||||
if [[ "$IPV6_READY" = true ]]; then
|
|
||||||
local IPv6_addr_list="$(ip a | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')"
|
|
||||||
if [[ -n ${IPv6_addr_list} ]]; then
|
|
||||||
log_write "${IPv6_addr_list}"
|
|
||||||
echo "::: IPv6 addresses located"
|
|
||||||
else
|
else
|
||||||
log_echo "No IPv6 addresses found."
|
log_echo "No IPv${protocol} found on ${PIHOLE_INTERFACE}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_ping_check() {
|
||||||
|
|
||||||
|
local protocol=${1}
|
||||||
|
local cmd
|
||||||
|
|
||||||
|
if [[ ${protocol} == "6" ]]; then
|
||||||
|
cmd="ping6"
|
||||||
|
else
|
||||||
|
cmd="ping"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local ip_def_gateway=$(ip -${protocol} route | grep default | cut -d ' ' -f 3)
|
||||||
|
if [[ -n ${ip_def_gateway} ]]; then
|
||||||
|
echo -n "::: Pinging default IPv${protocol} gateway: "
|
||||||
|
if ! ping_gateway="$(${cmd} -q -W 3 -c 3 -n ${ip_def_gateway} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then
|
||||||
|
echo "Gateway did not respond."
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo "Gateway responded."
|
||||||
|
log_write "${ping_gateway}"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3)
|
|
||||||
if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then
|
|
||||||
echo -n "::: Pinging default IPv6 gateway: "
|
|
||||||
local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n ${IPv6_def_gateway} -I ${IPv6_interface} | tail -n3)" \
|
|
||||||
&& echo "Gateway Responded." \
|
|
||||||
|| echo "Gateway did not respond."
|
|
||||||
block_parse "${IPv6_def_gateway_check}"
|
|
||||||
|
|
||||||
echo -n "::: Pinging Internet via IPv6: "
|
|
||||||
local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \
|
|
||||||
&& echo "Query responded." \
|
|
||||||
|| echo "Query did not respond."
|
|
||||||
block_parse "${IPv6_inet_check}"
|
|
||||||
else
|
|
||||||
log_echo="No IPv6 Gateway Detected"
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_check_wrapper() {
|
||||||
|
header_write "IP Address Information"
|
||||||
|
|
||||||
|
if ipv6_check; then
|
||||||
|
ip_check "6"
|
||||||
fi
|
fi
|
||||||
|
ip_check "4"
|
||||||
local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \
|
|
||||||
&& (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\
|
|
||||||
|| log_echo "No IPv4 addresses found."
|
|
||||||
|
|
||||||
local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3)
|
|
||||||
if [[ $? = 0 ]]; then
|
|
||||||
echo -n "::: Pinging default IPv4 gateway: "
|
|
||||||
local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n ${IPv4_def_gateway} -I ${IPv4_interface} | tail -n3)" \
|
|
||||||
&& echo "Gateway responded." \
|
|
||||||
|| echo "Gateway did not respond."
|
|
||||||
block_parse "${IPv4_def_gateway_check}"
|
|
||||||
|
|
||||||
echo -n "::: Pinging Internet via IPv4: "
|
|
||||||
local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 -I ${IPv4_interface} | tail -n3)" \
|
|
||||||
&& echo "Query responded." \
|
|
||||||
|| echo "Query did not respond."
|
|
||||||
block_parse "${IPv4_inet_check}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
port_check() {
|
port_check() {
|
||||||
@ -364,7 +347,7 @@ distro_check || echo "Distro Check soft fail"
|
|||||||
# Gather processor type
|
# Gather processor type
|
||||||
processor_check || echo "Processor Check soft fail"
|
processor_check || echo "Processor Check soft fail"
|
||||||
|
|
||||||
ip_check
|
ip_check_wrapper
|
||||||
|
|
||||||
daemon_check lighttpd http
|
daemon_check lighttpd http
|
||||||
daemon_check dnsmasq domain
|
daemon_check dnsmasq domain
|
||||||
|
Loading…
Reference in New Issue
Block a user