2016-10-23 21:15:10 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-03-20 01:32:11 +00:00
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-09-27 01:06:31 +00:00
|
|
|
# Generates pihole_debug.log to be used for troubleshooting.
|
2016-03-20 01:32:11 +00:00
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
|
|
|
|
2017-05-26 17:16:22 +00:00
|
|
|
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
|
|
|
|
# -u a reference to any variable you haven't previously defined
|
|
|
|
# with the exceptions of $* and $@ - is an error, and causes the program to immediately exit
|
|
|
|
# -o pipefail prevents errors in a pipeline from being masked. If any command in a pipeline fails,
|
|
|
|
# that return code will be used as the return code of the whole pipeline. By default, the
|
|
|
|
# pipeline's return code is that of the last command - even if it succeeds
|
2016-09-28 02:30:37 +00:00
|
|
|
set -o pipefail
|
2017-05-26 17:16:22 +00:00
|
|
|
IFS=$'\n\t'
|
2016-03-20 01:32:11 +00:00
|
|
|
|
|
|
|
######## GLOBAL VARS ########
|
2016-10-28 21:52:08 +00:00
|
|
|
VARSFILE="/etc/pihole/setupVars.conf"
|
2016-03-20 01:32:11 +00:00
|
|
|
DEBUG_LOG="/var/log/pihole_debug.log"
|
2016-03-24 21:21:29 +00:00
|
|
|
DNSMASQFILE="/etc/dnsmasq.conf"
|
2017-02-10 16:42:37 +00:00
|
|
|
DNSMASQCONFDIR="/etc/dnsmasq.d/*"
|
2016-03-24 21:21:29 +00:00
|
|
|
LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf"
|
2016-04-11 23:35:44 +00:00
|
|
|
LIGHTTPDERRFILE="/var/log/lighttpd/error.log"
|
2016-03-24 21:21:29 +00:00
|
|
|
GRAVITYFILE="/etc/pihole/gravity.list"
|
|
|
|
WHITELISTFILE="/etc/pihole/whitelist.txt"
|
|
|
|
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
2016-10-28 21:52:08 +00:00
|
|
|
ADLISTFILE="/etc/pihole/adlists.list"
|
2016-03-24 21:21:29 +00:00
|
|
|
PIHOLELOG="/var/log/pihole.log"
|
2017-03-05 01:54:38 +00:00
|
|
|
PIHOLEGITDIR="/etc/.pihole/"
|
|
|
|
ADMINGITDIR="/var/www/html/admin/"
|
2016-03-25 21:42:17 +00:00
|
|
|
WHITELISTMATCHES="/tmp/whitelistmatches.list"
|
2017-05-02 07:18:58 +00:00
|
|
|
readonly FTLLOG="/var/log/pihole-FTL.log"
|
2017-05-20 06:34:13 +00:00
|
|
|
coltable=/opt/pihole/COL_TABLE
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# These provide the colors we need for making the log more readable
|
2017-05-20 06:34:13 +00:00
|
|
|
if [[ -f ${coltable} ]]; then
|
|
|
|
source ${coltable}
|
|
|
|
else
|
|
|
|
COL_NC='\e[0m' # No Color
|
|
|
|
COL_YELLOW='\e[1;33m'
|
|
|
|
COL_LIGHT_PURPLE='\e[1;35m'
|
|
|
|
COL_CYAN='\e[0;36m'
|
|
|
|
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
|
|
|
|
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
|
|
|
|
INFO="[i]"
|
|
|
|
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
|
|
|
|
OVER="\r\033[K"
|
|
|
|
fi
|
2016-03-24 21:21:29 +00:00
|
|
|
|
2017-05-26 17:16:22 +00:00
|
|
|
make_temporary_log() {
|
|
|
|
# Create temporary file for log
|
|
|
|
TEMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX)
|
|
|
|
# Open handle 3 for templog
|
|
|
|
# https://stackoverflow.com/questions/18460186/writing-outputs-to-log-file-and-console
|
|
|
|
exec 3>"$TEMPLOG"
|
|
|
|
# Delete templog, but allow for addressing via file handle.
|
|
|
|
rm "$TEMPLOG"
|
|
|
|
}
|
|
|
|
|
|
|
|
log_write() {
|
|
|
|
# echo arguments to both the log and the console"
|
|
|
|
echo -e "${@}" | tee -a /proc/$$/fd/3
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_to_debug_log() {
|
|
|
|
cat /proc/$$/fd/3 >> "${DEBUG_LOG}"
|
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_succes_or_fail() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Set the first argument passed to this function as a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local message="${1}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# If the command was successful (a zero),
|
2017-05-25 01:24:23 +00:00
|
|
|
if [[ $? -eq 0 ]]; then
|
2017-05-22 04:25:53 +00:00
|
|
|
# show success
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${message}"
|
2017-02-10 16:42:37 +00:00
|
|
|
else
|
2017-05-22 04:25:53 +00:00
|
|
|
# Otherwise, show a error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} ${message}"
|
2016-10-26 02:53:00 +00:00
|
|
|
fi
|
2016-10-28 13:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
initiate_debug() {
|
|
|
|
# Clear the screen so the debug log is readable
|
|
|
|
clear
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "${COL_LIGHT_PURPLE}*** [ INITIALIZING ]${COL_NC}" 2>&1 | tee "${DEBUG_LOG}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Timestamp the start of the log
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} $(date "+%Y-%m-%d:%H:%M:%S") debug log has been initiated."
|
2016-10-28 21:52:08 +00:00
|
|
|
}
|
2016-09-27 01:06:31 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# This is a function for visually displaying the curent test that is being run.
|
|
|
|
# Accepts one variable: the name of what is being diagnosed
|
2017-05-22 04:25:53 +00:00
|
|
|
# Colors do not show in the dasboard, but the icons do: [i], [✓], and [✗]
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_current_diagnostic() {
|
|
|
|
# Colors are used for visually distinguishing each test in the output
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "\n${COL_LIGHT_PURPLE}*** [ DIAGNOSING ]:${COL_NC} ${1}"
|
2016-09-27 01:06:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 07:39:00 +00:00
|
|
|
file_exists() {
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set the first argument passed to tihs function as a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local file_to_test="${1}"
|
|
|
|
# If the file is readable
|
|
|
|
if [[ -r "${file_to_test}" ]]; then
|
|
|
|
# Return success
|
2016-10-26 19:22:20 +00:00
|
|
|
return 0
|
|
|
|
else
|
2017-05-20 06:34:13 +00:00
|
|
|
# Otherwise, return a failure
|
2016-10-26 19:22:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 06:06:15 +00:00
|
|
|
if_directory_exists() {
|
|
|
|
# Set the first argument passed to tihs function as a named variable for better readability
|
|
|
|
local directory_to_test="${1}"
|
|
|
|
# If the file is readable
|
|
|
|
if [[ -d "${directory_to_test}" ]]; then
|
|
|
|
# Return success
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
# Otherwise, return a failure
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 07:39:00 +00:00
|
|
|
check_core_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Checks the core version of the Pi-hole codebase
|
2017-05-22 07:39:00 +00:00
|
|
|
echo_current_diagnostic "Pi-hole Versions"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store the error message in a variable in case we want to change and/or reuse it
|
2017-05-22 07:39:00 +00:00
|
|
|
local error_msg="git status failed"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the pihole git directory exists,
|
2017-05-22 07:39:00 +00:00
|
|
|
if_directory_exists "${PIHOLEGITDIR}" && \
|
2017-05-25 03:07:15 +00:00
|
|
|
# move into it
|
2017-05-22 07:39:00 +00:00
|
|
|
cd "${PIHOLEGITDIR}" || \
|
2017-05-25 03:07:15 +00:00
|
|
|
# if not, report an error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "pihole repo does not exist"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the git status command completes successfully,
|
|
|
|
# we can assume we can get the information we want
|
2017-05-22 07:39:00 +00:00
|
|
|
if git status &> /dev/null; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# The current version the user is on
|
2017-05-22 07:39:00 +00:00
|
|
|
PI_HOLE_VERSION=$(git describe --tags --abbrev=0);
|
2017-05-25 03:07:15 +00:00
|
|
|
# What branch they are on
|
2017-05-22 07:39:00 +00:00
|
|
|
PI_HOLE_BRANCH=$(git rev-parse --abbrev-ref HEAD);
|
2017-05-25 03:07:15 +00:00
|
|
|
# The commit they are on
|
2017-05-22 07:39:00 +00:00
|
|
|
PI_HOLE_COMMIT=$(git describe --long --dirty --tags --always)
|
2017-05-25 03:07:15 +00:00
|
|
|
# echo this information out to the user in a nice format
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Core: ${PI_HOLE_VERSION}
|
2017-05-22 07:39:00 +00:00
|
|
|
${INFO} Branch: ${PI_HOLE_BRANCH}
|
2017-05-26 17:16:22 +00:00
|
|
|
${INFO} Commit: ${PI_HOLE_COMMIT}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If git status failed,
|
2017-05-22 07:39:00 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# Return an error message
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "${error_msg}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# and exit with a non zero code
|
2017-05-22 07:39:00 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_web_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Local variable for the error message
|
2017-05-22 07:39:00 +00:00
|
|
|
local error_msg="git status failed"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the directory exists,
|
2017-05-22 07:39:00 +00:00
|
|
|
if_directory_exists "${ADMINGITDIR}" && \
|
2017-05-25 03:07:15 +00:00
|
|
|
# move into it
|
2017-05-22 07:39:00 +00:00
|
|
|
cd "${ADMINGITDIR}" || \
|
2017-05-25 03:07:15 +00:00
|
|
|
# if not, give an error message
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "repo does not exist"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the git status command completes successfully,
|
|
|
|
# we can assume we can get the information we want
|
2017-05-22 07:39:00 +00:00
|
|
|
if git status &> /dev/null; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# The current version the user is on
|
2017-05-22 07:39:00 +00:00
|
|
|
WEB_VERSION=$(git describe --tags --abbrev=0);
|
2017-05-25 03:07:15 +00:00
|
|
|
# What branch they are on
|
2017-05-22 07:39:00 +00:00
|
|
|
WEB_BRANCH=$(git rev-parse --abbrev-ref HEAD);
|
2017-05-25 03:07:15 +00:00
|
|
|
# The commit they are on
|
2017-05-22 07:39:00 +00:00
|
|
|
WEB_COMMIT=$(git describe --long --dirty --tags --always)
|
2017-05-25 03:07:15 +00:00
|
|
|
# echo this information out to the user in a nice format
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Web: ${WEB_VERSION}
|
2017-05-22 07:39:00 +00:00
|
|
|
${INFO} Branch: ${WEB_BRANCH}
|
2017-05-26 17:16:22 +00:00
|
|
|
${INFO} Commit: ${WEB_COMMIT}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If git status failed,
|
2017-05-22 07:39:00 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# Return an error message
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "${error_msg}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# and exit with a non zero code
|
2017-05-22 07:39:00 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_ftl_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Use the built in command to check FTL's version
|
2017-05-22 07:39:00 +00:00
|
|
|
FTL_VERSION=$(pihole-FTL version)
|
2017-05-25 03:07:15 +00:00
|
|
|
# and display it to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} FTL: ${FTL_VERSION}"
|
2017-05-22 07:39:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Check the current version of the Web server
|
2017-05-22 08:05:51 +00:00
|
|
|
check_web_server_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store the name in a variable in case we ever want to change it
|
2017-05-22 08:05:51 +00:00
|
|
|
WEB_SERVER="lighttpd"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Parse out just the version number
|
2017-05-22 08:05:51 +00:00
|
|
|
WEB_SERVER_VERSON="$(lighttpd -v |& head -n1 | cut -d '/' -f2 | cut -d ' ' -f1)"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display the information to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${WEB_SERVER}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the Web server does not have a version (the variable is empty)
|
2017-05-22 08:05:51 +00:00
|
|
|
if [[ -z "${WEB_SERVER_VERSON}" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display and error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} ${WEB_SERVER} version could not be detected."
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-22 08:05:51 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# display the version
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${WEB_SERVER_VERSON}"
|
2017-05-22 08:05:51 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Check the current version of the DNS server
|
2017-05-22 08:05:51 +00:00
|
|
|
check_resolver_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store the name in a variable in case we ever want to change it
|
2017-05-22 08:05:51 +00:00
|
|
|
RESOLVER="dnsmasq"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Parse out just the version number
|
2017-05-22 08:05:51 +00:00
|
|
|
RESOVLER_VERSON="$(dnsmasq -v |& head -n1 | awk '{print $3}')"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display the information to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${RESOLVER}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the DNS server does not have a version (the variable is empty)
|
2017-05-22 08:05:51 +00:00
|
|
|
if [[ -z "${RESOVLER_VERSON}" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display and error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} ${RESOLVER} version could not be detected."
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-22 08:05:51 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# display the version
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${RESOVLER_VERSON}"
|
2017-05-22 08:05:51 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 13:48:56 +00:00
|
|
|
check_php_version() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Parse out just the version number
|
2017-05-22 13:48:56 +00:00
|
|
|
PHP_VERSION=$(php -v |& head -n1 | cut -d '-' -f1 | cut -d ' ' -f2)
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display the info to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} PHP"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If no version is detected,
|
2017-05-22 13:48:56 +00:00
|
|
|
if [[ -z "${PHP_VERSION}" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# show an error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} PHP version could not be detected."
|
2017-05-25 03:07:15 +00:00
|
|
|
# otherwise,
|
2017-05-22 13:48:56 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# Show the version
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${PHP_VERSION}"
|
2017-05-22 13:48:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# These are the most critical dependencies of Pi-hole, so we check for them
|
|
|
|
# and their versions, using the functions above.
|
2017-05-22 08:05:51 +00:00
|
|
|
check_critical_dependencies() {
|
|
|
|
echo_current_diagnostic "Versions of critical dependencies"
|
|
|
|
check_web_server_version
|
|
|
|
check_web_server_version
|
2017-05-22 13:48:56 +00:00
|
|
|
check_php_version
|
2017-05-22 08:05:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
get_distro_attributes() {
|
|
|
|
# Put the current Internal Field Separator into another variable so it can be restored later
|
|
|
|
OLD_IFS="$IFS"
|
|
|
|
# Store the distro info in an array and make it global since the OS won't change,
|
|
|
|
# but we'll keep it within the function for better unit testing
|
|
|
|
IFS=$'\r\n' command eval 'distro_info=( $(cat /etc/*release) )'
|
2016-10-28 22:53:18 +00:00
|
|
|
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local distro_attribute
|
2017-05-22 04:25:53 +00:00
|
|
|
# For each line found in an /etc/*release file,
|
2017-05-20 06:34:13 +00:00
|
|
|
for distro_attribute in "${distro_info[@]}"; do
|
2017-05-22 04:25:53 +00:00
|
|
|
# display the information with the ${INFO} icon
|
2017-05-20 07:01:56 +00:00
|
|
|
pretty_name_key=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f1)
|
2017-05-22 04:25:53 +00:00
|
|
|
# we need just the OS PRETTY_NAME, so print it when we find it
|
2017-05-20 07:01:56 +00:00
|
|
|
if [[ "${pretty_name_key}" == "PRETTY_NAME" ]]; then
|
|
|
|
PRETTY_NAME=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f2- | tr -d '"')
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${PRETTY_NAME}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Otherwise, do nothing
|
2017-05-20 07:01:56 +00:00
|
|
|
else
|
|
|
|
:
|
|
|
|
fi
|
2017-05-20 06:34:13 +00:00
|
|
|
done
|
|
|
|
# Set the IFS back to what it was
|
|
|
|
IFS="$OLD_IFS"
|
2016-10-26 21:33:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
diagnose_operating_system() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# local variable for system requirements
|
2017-05-22 04:25:53 +00:00
|
|
|
local faq_url="https://discourse.pi-hole.net/t/hardware-software-requirements/273"
|
2017-05-25 03:07:15 +00:00
|
|
|
# error message in a variable so we can easily modify it later (or re-use it)
|
2017-05-22 04:25:53 +00:00
|
|
|
local error_msg="Distribution unknown -- most likely you are on an unsupported platform and may run into issues."
|
2017-05-20 06:34:13 +00:00
|
|
|
# Display the current test that is running
|
|
|
|
echo_current_diagnostic "Operating system"
|
2016-10-26 18:38:19 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# If there is a /etc/*release file, it's probably a supported operating system, so we can
|
2017-05-22 07:39:00 +00:00
|
|
|
file_exists /etc/*release && \
|
2017-05-25 03:07:15 +00:00
|
|
|
# display the attributes to the user from the function made earlier
|
2017-05-20 06:34:13 +00:00
|
|
|
get_distro_attributes || \
|
2017-05-22 04:25:53 +00:00
|
|
|
# If it doesn't exist, it's not a system we currently support and link to FAQ
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} ${COL_LIGHT_RED}${error_msg}${COL_NC}
|
|
|
|
${INFO} ${COL_LIGHT_RED}Please see${COL_NC}: ${COL_CYAN}${faq_url}${COL_NC}"
|
2016-09-27 03:39:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 13:48:56 +00:00
|
|
|
processor_check() {
|
|
|
|
echo_current_diagnostic "Processor"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store the processor type in a variable
|
2017-05-22 13:48:56 +00:00
|
|
|
PROCESSOR=$(uname -m)
|
2017-05-25 03:07:15 +00:00
|
|
|
# If it does not contain a value,
|
2017-05-22 13:48:56 +00:00
|
|
|
if [[ -z "${PROCESSOR}" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# we couldn't detect it, so show an error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Processor could not be identified."
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-22 13:48:56 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# Show the processor type
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${PROCESSOR}"
|
2017-05-22 17:05:42 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_ip_addresses() {
|
|
|
|
# First argument should be a 4 or a 6
|
|
|
|
local protocol=${1}
|
|
|
|
# Use ip to show the addresses for the chosen protocol
|
|
|
|
# Store the values in an arry so they can be looped through
|
|
|
|
# Get the lines that are in the file(s) and store them in an array for parsing later
|
|
|
|
declare -a ip_addr_list=( $(ip -${protocol} addr show dev ${PIHOLE_INTERFACE} | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i ~ '/^inet/') print $(i+1) }') )
|
|
|
|
|
|
|
|
# If there is something in the IP address list,
|
|
|
|
if [[ -n ${ip_addr_list} ]]; then
|
|
|
|
# Local iterator
|
|
|
|
local i
|
2017-05-25 03:07:15 +00:00
|
|
|
# Display the protocol and interface
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} IPv${protocol} on ${PIHOLE_INTERFACE}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Since there may be more than one IP address, store them in an array
|
2017-05-22 17:35:57 +00:00
|
|
|
for i in "${!ip_addr_list[@]}"; do
|
2017-05-25 03:07:15 +00:00
|
|
|
# For each one in the list, print it out using the iterator as a numbered list
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " [$i] ${ip_addr_list[$i]}"
|
2017-05-22 17:05:42 +00:00
|
|
|
done
|
2017-05-25 03:07:15 +00:00
|
|
|
# Othwerwise,
|
2017-05-22 17:05:42 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# explain that the protocol is not configured
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} No IPv${protocol} found on ${PIHOLE_INTERFACE}"
|
2017-05-22 17:05:42 +00:00
|
|
|
return 1
|
2017-05-22 13:48:56 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 17:35:57 +00:00
|
|
|
|
|
|
|
ping_gateway() {
|
|
|
|
# First argument should be a 4 or a 6
|
|
|
|
local protocol="${1}"
|
|
|
|
# If the protocol is 6,
|
|
|
|
if [[ ${protocol} == "6" ]]; then
|
|
|
|
# use ping6
|
|
|
|
local cmd="ping6"
|
|
|
|
# and Google's public IPv6 address
|
|
|
|
local public_address="2001:4860:4860::8888"
|
|
|
|
# Otherwise,
|
|
|
|
else
|
|
|
|
# use ping
|
|
|
|
local cmd="ping"
|
|
|
|
# and Google's public IPv4 address
|
|
|
|
local public_address="8.8.8.8"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find the default gateway using IPv4 or IPv6
|
|
|
|
local gateway
|
|
|
|
gateway="$(ip -${protocol} route | grep default | cut -d ' ' -f 3)"
|
|
|
|
|
|
|
|
# If the gateway variable has a value (meaning a gateway was found),
|
|
|
|
if [[ -n "${gateway}" ]]; then
|
|
|
|
# Let the user know we will ping the gateway for a response
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Trying three pings on IPv${protocol} gateway at ${gateway}..."
|
2017-05-22 17:35:57 +00:00
|
|
|
# Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only,
|
|
|
|
# on the pihole interface, and tail the last three lines of the output
|
|
|
|
# If pinging the gateway is not successful,
|
|
|
|
if ! ping_cmd="$(${cmd} -q -c 3 -W 3 -n ${gateway} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then
|
|
|
|
# let the user know
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Gateway did not respond."
|
2017-05-22 17:35:57 +00:00
|
|
|
# and return an error code
|
|
|
|
return 1
|
|
|
|
# Otherwise,
|
|
|
|
else
|
|
|
|
# show a success
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} Gateway responded."
|
2017-05-22 17:35:57 +00:00
|
|
|
# and return a success code
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 17:57:55 +00:00
|
|
|
ping_internet() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Give the first argument a readable name
|
2017-05-22 17:57:55 +00:00
|
|
|
local protocol="${1}"
|
|
|
|
# If the protocol is 6,
|
|
|
|
if [[ ${protocol} == "6" ]]; then
|
|
|
|
# use ping6
|
|
|
|
local cmd="ping6"
|
|
|
|
# and Google's public IPv6 address
|
|
|
|
local public_address="2001:4860:4860::8888"
|
|
|
|
# Otherwise,
|
|
|
|
else
|
|
|
|
# use ping
|
|
|
|
local cmd="ping"
|
|
|
|
# and Google's public IPv4 address
|
|
|
|
local public_address="8.8.8.8"
|
|
|
|
fi
|
2017-05-26 17:16:22 +00:00
|
|
|
echo -n " ${INFO} Trying three pings on IPv${protocol} to reach the Internet..."
|
2017-05-25 03:07:15 +00:00
|
|
|
# Try to ping the address 3 times
|
2017-05-22 17:57:55 +00:00
|
|
|
if ! ping_inet="$(${cmd} -q -W 3 -c 3 -n ${public_address} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# if it's unsuccessful, show an error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Cannot reach the Internet"
|
2017-05-22 17:57:55 +00:00
|
|
|
return 1
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-22 17:57:55 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# show success
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} Query responded."
|
2017-05-22 17:57:55 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-24 03:32:30 +00:00
|
|
|
check_required_ports() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Since Pi-hole needs 53, 80, and 4711, check what they are being used by
|
|
|
|
# so we can detect any issues
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Ports in use:"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Create an array for these ports in use
|
2017-05-24 03:32:30 +00:00
|
|
|
ports_in_use=()
|
2017-05-25 03:07:15 +00:00
|
|
|
# Sort the addresses and remove duplicates
|
2017-05-24 03:32:30 +00:00
|
|
|
while IFS= read -r line; do
|
|
|
|
ports_in_use+=( "$line" )
|
|
|
|
done < <( lsof -i -P -n | awk -F' ' '/LISTEN/ {print $9, $1}' | sort | uniq | cut -d':' -f2 )
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Now that we have the values stored,
|
2017-05-24 03:32:30 +00:00
|
|
|
for i in ${!ports_in_use[@]}; do
|
|
|
|
local port_number="$(echo "${ports_in_use[$i]}" | awk '{print $1}')"
|
|
|
|
local service_name=$(echo "${ports_in_use[$i]}" | awk '{print $2}')
|
2017-05-25 03:07:15 +00:00
|
|
|
# display the information nicely to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " [${port_number}] is in use by ${service_name}"
|
2017-05-24 03:32:30 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-05-22 17:35:57 +00:00
|
|
|
check_networking() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Runs through several of the functions made earlier; we just clump them
|
|
|
|
# together since they are all related to the networking aspect of things
|
2017-05-22 17:35:57 +00:00
|
|
|
echo_current_diagnostic "Networking"
|
|
|
|
detect_ip_addresses "4"
|
|
|
|
ping_gateway "4"
|
|
|
|
detect_ip_addresses "6"
|
|
|
|
ping_gateway "6"
|
2017-05-24 03:32:30 +00:00
|
|
|
check_required_ports
|
2017-05-22 17:35:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 20:29:31 +00:00
|
|
|
check_x_headers() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# The X-Headers allow us to determine from the command line if the Web
|
|
|
|
# server is operating correctly
|
2017-05-24 21:10:14 +00:00
|
|
|
echo_current_diagnostic "Dashboard and block page"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Use curl -I to get the header and parse out just the X-Pi-hole one
|
2017-05-24 21:10:14 +00:00
|
|
|
local block_page=$(curl -Is localhost | awk '/X-Pi-hole/' | tr -d '\r')
|
2017-05-25 03:07:15 +00:00
|
|
|
# Do it for the dashboard as well, as the header is different than above
|
2017-05-24 21:10:14 +00:00
|
|
|
local dashboard=$(curl -Is localhost/admin/ | awk '/X-Pi-hole/' | tr -d '\r')
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store what the X-Header shoud be in variables for comparision later
|
2017-05-24 23:31:55 +00:00
|
|
|
local block_page_working="X-Pi-hole: A black hole for Internet advertisements."
|
|
|
|
local dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the X-header found by curl matches what is should be,
|
2017-05-24 21:10:14 +00:00
|
|
|
if [[ $block_page == $block_page_working ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# display a success message
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " $TICK ${block_page}"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-24 21:10:14 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# show an error
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " $CROSS X-Header does not match or could not be retrieved"
|
2017-05-24 21:10:14 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Same logic applies to the dashbord as above
|
2017-05-24 21:10:14 +00:00
|
|
|
if [[ $dashboard == $dashboard_working ]]; then
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " $TICK ${dashboard}"
|
2017-05-24 21:10:14 +00:00
|
|
|
else
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " $CROSS X-Header does not match or could not be retrieved"
|
2017-05-24 21:10:14 +00:00
|
|
|
fi
|
2017-05-24 20:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dig_at() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# We need to test if Pi-hole can properly resolve domain names as it is an
|
|
|
|
# essential piece of the software that needs to work
|
|
|
|
|
|
|
|
# Store the arguments as variables with names
|
2017-05-24 20:29:31 +00:00
|
|
|
local protocol="${1}"
|
|
|
|
local IP="${2}"
|
|
|
|
echo_current_diagnostic "Domain name resolution (IPv${protocol}) using a random blocked domain"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Set more local variables
|
2017-05-24 20:29:31 +00:00
|
|
|
local url
|
|
|
|
local local_dig
|
|
|
|
local pihole_dig
|
|
|
|
local remote_dig
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the protocol (4 or 6) is 6,
|
2017-05-24 20:29:31 +00:00
|
|
|
if [[ ${protocol} == "6" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# Set the IPv6 variables and record type
|
2017-05-24 20:29:31 +00:00
|
|
|
local local_address="::1"
|
|
|
|
local pihole_address="${IPV6_ADDRESS%/*}"
|
|
|
|
local remote_address="2001:4860:4860::8888"
|
|
|
|
local record_type="AAAA"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Othwerwise, it should be 4
|
2017-05-24 20:29:31 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# so use the IPv4 values
|
2017-05-24 20:29:31 +00:00
|
|
|
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 }')
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# First do a dig on localhost, to see if Pi-hole can use itself to block a domain
|
2017-05-24 20:29:31 +00:00
|
|
|
if local_dig=$(dig -"${protocol}" "${random_url}" @${local_address} +short "${record_type}"); then
|
2017-05-25 03:07:15 +00:00
|
|
|
# If it can, show sucess
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${random_url} is ${local_dig} via localhost (${local_address})"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-24 20:29:31 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# show a failure
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Failed to resolve ${random_url} via localhot (${local_address})"
|
2017-05-24 20:29:31 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Next we need to check if Pi-hole can resolve a domain when the query is sent to it's IP address
|
|
|
|
# This better emulates how clients will interact with Pi-hole as opposed to above where Pi-hole is
|
|
|
|
# just asing itself locally
|
2017-05-24 20:29:31 +00:00
|
|
|
if pihole_dig=$(dig -"${protocol}" "${random_url}" @${pihole_address} +short "${record_type}"); then
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${random_url} is ${pihole_dig} via Pi-hole (${pihole_address})"
|
2017-05-24 20:29:31 +00:00
|
|
|
else
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Failed to resolve ${random_url} via Pi-hole (${pihole_address})"
|
2017-05-24 20:29:31 +00:00
|
|
|
fi
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Finally, we need to make sure legitimate sites can out if using an external, public DNS server
|
2017-05-24 21:10:14 +00:00
|
|
|
if remote_dig=$(dig -"${protocol}" "${remote_url}" @${remote_address} +short "${record_type}" | head -n1); then
|
2017-05-25 03:07:15 +00:00
|
|
|
# If successful, the real IP of the domain will be returned instead of Pi-hole's IP
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${TICK} ${random_url} is ${remote_dig} via a remote, public DNS server (${remote_address})"
|
2017-05-24 20:29:31 +00:00
|
|
|
else
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} Failed to resolve ${random_url} via a remote, public DNS server (${remote_address})"
|
2017-05-24 20:29:31 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-24 03:57:22 +00:00
|
|
|
process_status(){
|
2017-05-25 03:07:15 +00:00
|
|
|
# Check to make sure Pi-hole's services are running and active
|
2017-05-24 03:57:22 +00:00
|
|
|
echo_current_diagnostic "Pi-hole processes"
|
2017-05-25 03:07:15 +00:00
|
|
|
# Store them in an array for easy use
|
2017-05-24 03:57:22 +00:00
|
|
|
PROCESSES=( dnsmasq lighttpd pihole-FTL )
|
|
|
|
local i
|
2017-05-25 03:07:15 +00:00
|
|
|
# For each process,
|
2017-05-24 03:57:22 +00:00
|
|
|
for i in "${PROCESSES[@]}"; do
|
2017-05-25 03:07:15 +00:00
|
|
|
# get it's status
|
2017-05-24 03:57:22 +00:00
|
|
|
local status_of_process=$(systemctl is-active "${i}")
|
2017-05-25 03:07:15 +00:00
|
|
|
# and print it out to the user
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " [i] ${i} daemon is ${status_of_process}"
|
2017-05-24 03:57:22 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
parse_file() {
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set the first argument passed to tihs function as a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local filename="${1}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Put the current Internal Field Separator into another variable so it can be restored later
|
2017-05-20 06:34:13 +00:00
|
|
|
OLD_IFS="$IFS"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Get the lines that are in the file(s) and store them in an array for parsing later
|
2017-05-20 06:34:13 +00:00
|
|
|
IFS=$'\r\n' command eval 'file_info=( $(cat "${filename}") )'
|
2017-03-04 19:34:34 +00:00
|
|
|
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local file_lines
|
2017-05-22 04:25:53 +00:00
|
|
|
# For each lin in the file,
|
2017-05-20 06:34:13 +00:00
|
|
|
for file_lines in "${file_info[@]}"; do
|
2017-05-22 04:25:53 +00:00
|
|
|
# display the information with the ${INFO} icon
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${file_lines}"
|
2017-05-20 06:34:13 +00:00
|
|
|
done
|
|
|
|
# Set the IFS back to what it was
|
|
|
|
IFS="$OLD_IFS"
|
2017-03-04 23:06:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
diagnose_setup_variables() {
|
|
|
|
# Display the current test that is running
|
|
|
|
echo_current_diagnostic "Setup variables"
|
2016-09-28 17:14:47 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# If the variable file exists,
|
2017-05-22 07:39:00 +00:00
|
|
|
file_exists "${VARSFILE}" && \
|
2017-05-20 06:34:13 +00:00
|
|
|
# source it
|
|
|
|
source ${VARSFILE};
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Sourcing ${VARSFILE}...";
|
2017-05-20 06:34:13 +00:00
|
|
|
# and display a green check mark with ${DONE}
|
|
|
|
echo_succes_or_fail "${VARSFILE} is readable and has been sourced." || \
|
|
|
|
# Othwerwise, error out
|
|
|
|
echo_succes_or_fail "${VARSFILE} is not readable.
|
2017-05-22 04:25:53 +00:00
|
|
|
${INFO} $(ls -l ${VARSFILE} 2>/dev/null)";
|
2017-05-20 06:34:13 +00:00
|
|
|
parse_file "${VARSFILE}"
|
2016-04-04 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 20:29:31 +00:00
|
|
|
check_name_resolution() {
|
|
|
|
# Check name resoltion from localhost, Pi-hole's IP, and Google's name severs
|
2017-05-25 03:07:15 +00:00
|
|
|
# using the function we created earlier
|
2017-05-24 20:29:31 +00:00
|
|
|
dig_at 4 "${IPV4_ADDRESS%/*}"
|
|
|
|
# If IPv6 enabled, check resolution
|
|
|
|
if [[ "${IPV6_ADDRESS}" ]]; then
|
|
|
|
dig_at 6 "${IPV6_ADDRESS%/*}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-22 04:25:53 +00:00
|
|
|
# This function can check a directory exists
|
|
|
|
# Pi-hole has files in several places, so we will reuse this function
|
2017-05-20 06:34:13 +00:00
|
|
|
dir_check() {
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set the first argument passed to tihs function as a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local directory="${1}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Display the current test that is running
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_current_diagnostic "contents of ${directory}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# For each file in the directory,
|
2017-05-24 20:29:31 +00:00
|
|
|
for filename in "${directory}"; do
|
2017-05-22 04:25:53 +00:00
|
|
|
# check if exists first; if it does,
|
2017-05-22 07:39:00 +00:00
|
|
|
file_exists "${filename}" && \
|
2017-05-22 04:25:53 +00:00
|
|
|
# show a success message
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_succes_or_fail "Files detected" || \
|
2017-05-22 04:25:53 +00:00
|
|
|
# Otherwise, show an error
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_succes_or_fail "directory does not exist"
|
|
|
|
done
|
2016-04-11 23:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
list_files_in_dir() {
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set the first argument passed to tihs function as a named variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local dir_to_parse="${1}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# Store the files found in an array
|
2017-05-20 06:34:13 +00:00
|
|
|
files_found=( $(ls "${dir_to_parse}") )
|
2017-05-22 04:25:53 +00:00
|
|
|
# For each file in the arry,
|
2017-05-20 06:34:13 +00:00
|
|
|
for each_file in "${files_found[@]}"; do
|
2017-05-22 04:25:53 +00:00
|
|
|
# display the information with the ${INFO} icon
|
2017-05-24 20:29:31 +00:00
|
|
|
# Also print the permissions and the user/group
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${each_file} ( $(ls -ld ${dir_to_parse}/${each_file} | awk '{print $1, $3, $4}') )"
|
2016-11-18 21:27:06 +00:00
|
|
|
done
|
2017-01-22 20:38:09 +00:00
|
|
|
|
2016-03-20 01:32:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
check_dnsmasq_d() {
|
2017-05-22 04:25:53 +00:00
|
|
|
# Set a local variable for better readability
|
2017-05-20 06:34:13 +00:00
|
|
|
local directory=/etc/dnsmasq.d
|
2017-05-22 04:25:53 +00:00
|
|
|
# Check if the directory exists
|
2017-05-20 06:34:13 +00:00
|
|
|
dir_check "${directory}"
|
2017-05-22 04:25:53 +00:00
|
|
|
# if it does, list the files in it
|
2017-05-20 06:34:13 +00:00
|
|
|
list_files_in_dir "${directory}"
|
2016-03-20 01:32:11 +00:00
|
|
|
}
|
2016-08-01 20:43:13 +00:00
|
|
|
|
2017-05-24 23:31:55 +00:00
|
|
|
check_lighttpd_d() {
|
|
|
|
# Set a local variable for better readability
|
|
|
|
local directory=/etc/lighttpd
|
|
|
|
# Check if the directory exists
|
|
|
|
dir_check "${directory}"
|
|
|
|
# if it does, list the files in it
|
|
|
|
list_files_in_dir "${directory}"
|
|
|
|
}
|
|
|
|
|
2017-05-24 20:29:31 +00:00
|
|
|
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}"
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:31:55 +00:00
|
|
|
analyze_gravity_list() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# It's helpful to know how big a user's gravity file is
|
2017-05-24 23:31:55 +00:00
|
|
|
gravity_length=$(grep -c ^ "${GRAVITYFILE}") && \
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} ${GRAVITYFILE} is ${gravity_length} lines long." || \
|
2017-05-25 03:07:15 +00:00
|
|
|
# If the previous command failed, something is wrong with the file
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} ${GRAVITYFILE} not found!"
|
2017-05-24 23:31:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 02:11:15 +00:00
|
|
|
tricorder_nc_or_ssl() {
|
2017-05-25 03:07:15 +00:00
|
|
|
# Users can submit their debug logs using nc (unencrypted) or opensll (enrypted) if available
|
|
|
|
# Check fist for openssl since encryption is a good thing
|
2017-05-25 02:11:15 +00:00
|
|
|
if command -v openssl &> /dev/null; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# If successful
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Using openssl for transmission."
|
2017-05-25 03:07:15 +00:00
|
|
|
# transmit the log and store the token returned in the tricorder variable
|
2017-05-25 02:11:15 +00:00
|
|
|
tricorder=$(cat /var/log/pihole_debug.log | openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null)
|
2017-05-25 03:07:15 +00:00
|
|
|
# Otherwise,
|
2017-05-25 02:11:15 +00:00
|
|
|
else
|
2017-05-25 03:07:15 +00:00
|
|
|
# use net cat
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Using netcat for transmission."
|
2017-05-25 02:11:15 +00:00
|
|
|
tricorder=$(cat /var/log/pihole_debug.log | nc tricorder.pi-hole.net 9999)
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:31:55 +00:00
|
|
|
|
2017-05-25 02:11:15 +00:00
|
|
|
upload_to_tricorder() {
|
2017-05-24 23:31:55 +00:00
|
|
|
# Set the permissions and owner
|
|
|
|
chmod 644 ${DEBUG_LOG}
|
|
|
|
chown "$USER":pihole ${DEBUG_LOG}
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Let the user know debugging is complete
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "${TICK} Finshed debugging!"
|
2017-05-25 02:11:15 +00:00
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Provide information on what they should do with their token
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only."
|
|
|
|
log_write " For more information, see: https://pi-hole.net/2016/11/07/crack-our-medical-tricorder-win-a-raspberry-pi-3/"
|
2017-05-25 03:07:15 +00:00
|
|
|
# If pihole -d is running automatically (usually throught the dashboard)
|
2017-05-24 23:31:55 +00:00
|
|
|
if [[ "${AUTOMATED}" ]]; then
|
2017-05-25 03:07:15 +00:00
|
|
|
# let the user know
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Debug script running in automated mode"
|
2017-05-25 03:07:15 +00:00
|
|
|
# and then decide again which tool to use to submit it
|
2017-05-25 02:11:15 +00:00
|
|
|
if command -v openssl &> /dev/null; then
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Using openssl for transmission."
|
2017-05-25 02:11:15 +00:00
|
|
|
openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null < /dev/stdin
|
|
|
|
else
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${INFO} Using netcat for transmission."
|
2017-05-25 02:11:15 +00:00
|
|
|
nc tricorder.pi-hole.net 9999 < /dev/stdin
|
|
|
|
fi
|
2017-05-24 23:31:55 +00:00
|
|
|
else
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-25 03:07:15 +00:00
|
|
|
# Give the user a choice of uploading it or not
|
|
|
|
# Users can review the log file locally and try to self-diagnose their problem
|
2017-05-25 02:11:15 +00:00
|
|
|
read -r -p "[?] Would you like to upload the log? [y/N] " response
|
2017-05-24 23:31:55 +00:00
|
|
|
case ${response} in
|
2017-05-25 03:07:15 +00:00
|
|
|
# If they say yes, run our function for uploading the log
|
2017-05-25 02:11:15 +00:00
|
|
|
[yY][eE][sS]|[yY]) tricorder_nc_or_ssl;;
|
2017-05-25 03:07:15 +00:00
|
|
|
# If they choose no, just exit out of the script
|
2017-05-26 17:16:22 +00:00
|
|
|
*) log_write " ${INFO} Log will NOT be uploaded to tricorder.";exit;
|
2017-05-24 23:31:55 +00:00
|
|
|
esac
|
|
|
|
fi
|
2017-05-25 03:07:15 +00:00
|
|
|
# Check if tricorder.pi-hole.net is reachable and provide token
|
|
|
|
# along with some additional useful information
|
2017-05-24 23:31:55 +00:00
|
|
|
if [[ -n "${tricorder}" ]]; then
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write "${COL_LIGHT_PURPLE}***********************************${COL_NC}"
|
|
|
|
log_write "${TICK} Your debug token is: ${COL_LIGHT_GREEN}${tricorder}${COL_NC}"
|
|
|
|
log_write "${COL_LIGHT_PURPLE}***********************************${COL_NC}"
|
|
|
|
log_write ""
|
|
|
|
log_write " Provide this token to the Pi-hole team for assistance:"
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " https://discourse.pi-hole.net"
|
2017-05-24 23:31:55 +00:00
|
|
|
else
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " ${CROSS} There was an error uploading your debug log."
|
|
|
|
log_write " Please try again or contact the Pi-hole team for assistance."
|
2017-05-24 23:31:55 +00:00
|
|
|
fi
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-26 17:16:22 +00:00
|
|
|
log_write " A local copy of the debug log can be found at : /var/log/pihole_debug.log"
|
2017-05-25 02:11:15 +00:00
|
|
|
echo ""
|
2017-05-24 20:29:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 03:07:15 +00:00
|
|
|
# Run through all the functions we made
|
2017-05-26 17:16:22 +00:00
|
|
|
make_temporary_log
|
2017-05-20 06:34:13 +00:00
|
|
|
initiate_debug
|
2017-05-22 07:39:00 +00:00
|
|
|
check_core_version
|
|
|
|
check_web_version
|
|
|
|
check_ftl_version
|
2017-05-25 03:07:15 +00:00
|
|
|
# setupVars.conf needs to be sourced before the networking so the values are
|
|
|
|
# available to the check_networking function
|
2017-05-22 17:05:42 +00:00
|
|
|
diagnose_setup_variables
|
2017-05-20 06:34:13 +00:00
|
|
|
diagnose_operating_system
|
2017-05-22 13:48:56 +00:00
|
|
|
processor_check
|
2017-05-22 17:35:57 +00:00
|
|
|
check_networking
|
2017-05-24 20:29:31 +00:00
|
|
|
check_name_resolution
|
2017-05-24 03:57:22 +00:00
|
|
|
process_status
|
2017-05-24 21:10:14 +00:00
|
|
|
check_x_headers
|
2017-05-22 08:05:51 +00:00
|
|
|
check_critical_dependencies
|
2017-05-20 06:34:13 +00:00
|
|
|
check_dnsmasq_d
|
2017-05-24 23:31:55 +00:00
|
|
|
check_lighttpd_d
|
2017-05-24 20:29:31 +00:00
|
|
|
check_http_directory
|
|
|
|
check_cron_d
|
2017-05-26 17:16:22 +00:00
|
|
|
copy_to_debug_log
|
2017-05-25 02:11:15 +00:00
|
|
|
upload_to_tricorder
|