1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-23 07:18:07 +00:00

add resolver functions and check directory content functions

This commit is contained in:
Jacob Salmela 2017-05-24 15:29:31 -05:00
parent 1a87d3a659
commit 76266cf31b
No known key found for this signature in database
GPG Key ID: 1962FF1A5046135E

View File

@ -340,17 +340,63 @@ check_required_ports() {
done done
} }
check_networking() { check_networking() {
echo_current_diagnostic "Networking" echo_current_diagnostic "Networking"
detect_ip_addresses "4" detect_ip_addresses "4"
ping_gateway "4" ping_gateway "4"
detect_ip_addresses "6" detect_ip_addresses "6"
ping_gateway "6" ping_gateway "6"
port_check 4 http
check_required_ports check_required_ports
} }
check_x_headers() {
curl -Is localhost | awk '/X-Pi-hole/'
curl -Is localhost/admin/ | awk '/X-Pi-hole/'
}
dig_at() {
local protocol="${1}"
local IP="${2}"
echo_current_diagnostic "Domain name resolution (IPv${protocol}) using a random blocked domain"
local url
local local_dig
local pihole_dig
local remote_dig
if [[ ${protocol} == "6" ]]; then
local local_address="::1"
local pihole_address="${IPV6_ADDRESS%/*}"
local remote_address="2001:4860:4860::8888"
local record_type="AAAA"
else
local local_address="127.0.0.1"
local pihole_address="${IPV4_ADDRESS%/*}"
local remote_address="8.8.8.8"
local record_type="A"
fi
# Find a random blocked url that has not been whitelisted.
local random_url=$(shuf -n 1 "${GRAVITYFILE}" | awk -F ' ' '{ print $2 }')
if local_dig=$(dig -"${protocol}" "${random_url}" @${local_address} +short "${record_type}"); then
echo -e " ${TICK} ${random_url} is ${local_dig} via localhost (${local_address})"
else
echo -e " ${CROSS} Failed to resolve ${random_url} via localhot (${local_address})"
fi
if pihole_dig=$(dig -"${protocol}" "${random_url}" @${pihole_address} +short "${record_type}"); then
echo -e " ${TICK} ${random_url} is ${pihole_dig} via Pi-hole (${pihole_address})"
else
echo -e " ${CROSS} Failed to resolve ${random_url} via Pi-hole (${pihole_address})"
fi
if remote_dig=$(dig -"${protocol}" "${random_url}" @${remote_address} +short "${record_type}"); then
echo -e " ${TICK} ${random_url} is ${remote_dig} via a remote, public DNS server (${remote_address})"
else
echo -e " ${CROSS} Failed to resolve ${random_url} via a remote, public DNS server (${remote_address})"
fi
}
process_status(){ process_status(){
echo_current_diagnostic "Pi-hole processes" echo_current_diagnostic "Pi-hole processes"
PROCESSES=( dnsmasq lighttpd pihole-FTL ) PROCESSES=( dnsmasq lighttpd pihole-FTL )
@ -397,6 +443,15 @@ diagnose_setup_variables() {
parse_file "${VARSFILE}" parse_file "${VARSFILE}"
} }
check_name_resolution() {
# Check name resoltion from localhost, Pi-hole's IP, and Google's name severs
dig_at 4 "${IPV4_ADDRESS%/*}"
# If IPv6 enabled, check resolution
if [[ "${IPV6_ADDRESS}" ]]; then
dig_at 6 "${IPV6_ADDRESS%/*}"
fi
}
# This function can check a directory exists # This function can check a directory exists
# Pi-hole has files in several places, so we will reuse this function # Pi-hole has files in several places, so we will reuse this function
dir_check() { dir_check() {
@ -405,7 +460,7 @@ dir_check() {
# Display the current test that is running # Display the current test that is running
echo_current_diagnostic "contents of ${directory}" echo_current_diagnostic "contents of ${directory}"
# For each file in the directory, # For each file in the directory,
for filename in "${directory}"*; do for filename in "${directory}"; do
# check if exists first; if it does, # check if exists first; if it does,
file_exists "${filename}" && \ file_exists "${filename}" && \
# show a success message # show a success message
@ -418,14 +473,13 @@ dir_check() {
list_files_in_dir() { list_files_in_dir() {
# Set the first argument passed to tihs function as a named variable for better readability # Set the first argument passed to tihs function as a named variable for better readability
local dir_to_parse="${1}" local dir_to_parse="${1}"
# Set another local variable for better readability
local filename
# Store the files found in an array # Store the files found in an array
files_found=( $(ls "${dir_to_parse}") ) files_found=( $(ls "${dir_to_parse}") )
# For each file in the arry, # For each file in the arry,
for each_file in "${files_found[@]}"; do for each_file in "${files_found[@]}"; do
# display the information with the ${INFO} icon # display the information with the ${INFO} icon
echo " ${INFO} ${each_file}" # Also print the permissions and the user/group
echo -e " ${INFO} ${each_file} ( $(ls -ld ${dir_to_parse}/${each_file} | awk '{print $1, $3, $4}') )"
done done
} }
@ -439,6 +493,30 @@ check_dnsmasq_d() {
list_files_in_dir "${directory}" list_files_in_dir "${directory}"
} }
check_cron_d() {
# Set a local variable for better readability
local directory=/etc/cron.d
# Check if the directory exists
dir_check "${directory}"
# if it does, list the files in it
list_files_in_dir "${directory}"
}
check_http_directory() {
# Set a local variable for better readability
local directory=/var/www/html
# Check if the directory exists
dir_check "${directory}"
# if it does, list the files in it
list_files_in_dir "${directory}"
}
upload_to_tricorder() {
echo tricorder
}
upload_to_tricorder
initiate_debug initiate_debug
check_core_version check_core_version
check_web_version check_web_version
@ -447,6 +525,9 @@ diagnose_setup_variables
diagnose_operating_system diagnose_operating_system
processor_check processor_check
check_networking check_networking
check_name_resolution
process_status process_status
check_critical_dependencies check_critical_dependencies
check_dnsmasq_d check_dnsmasq_d
check_http_directory
check_cron_d