parse contents of each file in each dir, several log_writes

This commit is contained in:
Jacob Salmela 2017-05-27 00:04:42 -05:00
parent 7ec169ab10
commit 36907edd50
No known key found for this signature in database
GPG key ID: 1962FF1A5046135E

View file

@ -66,7 +66,7 @@ make_temporary_log() {
}
log_write() {
# echo arguments to both the log and the console"
# echo arguments to both the log and the console
echo -e "${@}" | tee -a /proc/$$/fd/3
}
@ -76,15 +76,16 @@ copy_to_debug_log() {
}
echo_succes_or_fail() {
# Set the first argument passed to this function as a named variable for better readability
local message="${1}"
# If the command was successful (a zero),
if [[ $? -eq 0 ]]; then
# Set the first argument passed to this function as a named variable for better readability
local message="${1}"
# show success
log_write " ${TICK} ${message}"
log_write "${TICK} ${message}"
else
local message="${1}"
# Otherwise, show a error
log_write " ${CROSS} ${message}"
log_write "${CROSS} ${message}"
fi
}
@ -94,7 +95,7 @@ initiate_debug() {
# Display that the debug process is beginning
log_write "${COL_LIGHT_PURPLE}*** [ INITIALIZING ]${COL_NC}"
# Timestamp the start of the log
log_write " ${INFO} $(date "+%Y-%m-%d:%H:%M:%S") debug log has been initiated."
log_write "${INFO} $(date "+%Y-%m-%d:%H:%M:%S") debug log has been initiated."
}
# This is a function for visually displaying the curent test that is being run.
@ -155,25 +156,25 @@ check_core_version() {
# echo this information out to the user in a nice format
# If the current version matches what pihole -v produces, the user is up-to-date
if [[ "${PI_HOLE_VERSION}" == "$(pihole -v | awk '/Pi-hole/ {print $6}' | cut -d ')' -f1)" ]]; then
log_write " ${TICK} Core: ${COL_LIGHT_GREEN}${PI_HOLE_VERSION}${COL_NC}"
log_write "${TICK} Core: ${COL_LIGHT_GREEN}${PI_HOLE_VERSION}${COL_NC}"
# If not,
else
# echo the current version in yellow, signifying it's something to take a look at, but not a critical error
# Also add a URL to an FAQ
log_write " ${INFO} Core: ${COL_YELLOW}${PI_HOLE_VERSION:-Untagged}${COL_NC} (${COL_CYAN}${FAQ_UPDATE_PI_HOLE}${COL_NC})"
log_write "${INFO} Core: ${COL_YELLOW}${PI_HOLE_VERSION:-Untagged}${COL_NC} (${COL_CYAN}${FAQ_UPDATE_PI_HOLE}${COL_NC})"
fi
# If the repo is on the master branch, they are on the stable codebase
if [[ "${PI_HOLE_BRANCH}" == "master" ]]; then
# so the color of the text is green
log_write " ${INFO} Branch: ${COL_LIGHT_GREEN}${PI_HOLE_BRANCH}${COL_NC}"
log_write "${INFO} Branch: ${COL_LIGHT_GREEN}${PI_HOLE_BRANCH}${COL_NC}"
# If it is any other branch, they are in a developement branch
else
# So show that in yellow, signifying it's something to take a look at, but not a critical error
log_write " ${INFO} Branch: ${COL_YELLOW}${PI_HOLE_BRANCH:-Detached}${COL_NC} (${COL_CYAN}${FAQ_CHECKOUT_COMMAND}${COL_NC})"
log_write "${INFO} Branch: ${COL_YELLOW}${PI_HOLE_BRANCH:-Detached}${COL_NC} (${COL_CYAN}${FAQ_CHECKOUT_COMMAND}${COL_NC})"
fi
# echo the current commit
log_write " ${INFO} Commit: ${PI_HOLE_COMMIT}"
log_write "${INFO} Commit: ${PI_HOLE_COMMIT}\n"
# If git status failed,
else
# Return an error message
@ -204,25 +205,25 @@ check_web_version() {
# If the Web version reported by pihole -v matches the current version
if [[ "${WEB_VERSION}" == "$(pihole -v | awk '/AdminLTE/ {print $6}' | cut -d ')' -f1)" ]]; then
# echo it in green
log_write " ${TICK} Web: ${COL_LIGHT_GREEN}${WEB_VERSION}${COL_NC}"
log_write "${TICK} Web: ${COL_LIGHT_GREEN}${WEB_VERSION}${COL_NC}"
# Otherwise,
else
# Show it in yellow with a link to update Pi-hole
log_write " ${INFO} Web: ${COL_YELLOW}${WEB_VERSION:-Untagged}${COL_NC} (${COL_CYAN}${FAQ_UPDATE_PI_HOLE}${COL_NC})"
log_write "${INFO} Web: ${COL_YELLOW}${WEB_VERSION:-Untagged}${COL_NC} (${COL_CYAN}${FAQ_UPDATE_PI_HOLE}${COL_NC})"
fi
# If the repo is on the master branch, they are on the stable codebase
if [[ "${WEB_BRANCH}" == "master" ]]; then
# so the color of the text is green
log_write " ${TICK} Branch: ${COL_LIGHT_GREEN}${WEB_BRANCH}${COL_NC}"
log_write "${TICK} Branch: ${COL_LIGHT_GREEN}${WEB_BRANCH}${COL_NC}"
else
# If it is any other branch, they are in a developement branch
# So show that in yellow, signifying it's something to take a look at, but not a critical error
log_write " ${INFO} Branch: ${COL_YELLOW}${WEB_BRANCH:-Detached}${COL_NC} (${COL_CYAN}${FAQ_CHECKOUT_COMMAND}${COL_NC})"
log_write "${INFO} Branch: ${COL_YELLOW}${WEB_BRANCH:-Detached}${COL_NC} (${COL_CYAN}${FAQ_CHECKOUT_COMMAND}${COL_NC})"
fi
# echo the current commit
log_write " ${INFO} Commit: ${WEB_COMMIT}"
log_write "${INFO} Commit: ${WEB_COMMIT}\n"
# If git status failed,
else
# Return an error message
@ -238,10 +239,10 @@ check_ftl_version() {
# Compare the current FTL version to the remote version
if [[ "${FTL_VERSION}" == "$(pihole -v | awk '/FTL/ {print $6}' | cut -d ')' -f1)" ]]; then
# If they are the same, FTL is up-to-date
log_write " ${TICK} FTL: ${COL_LIGHT_GREEN}${FTL_VERSION}${COL_NC}"
log_write "${TICK} FTL: ${COL_LIGHT_GREEN}${FTL_VERSION}${COL_NC}"
else
# If not, show it in yellow, signifying there is an update
log_write " ${TICK} FTL: ${COL_YELLOW}${FTL_VERSION}${COL_NC}"
log_write "${TICK} FTL: ${COL_YELLOW}${FTL_VERSION}${COL_NC}"
fi
}
@ -254,10 +255,10 @@ check_web_server_version() {
# If the Web server does not have a version (the variable is empty)
if [[ -z "${WEB_SERVER_VERSON}" ]]; then
# Display and error
log_write " ${CROSS} ${COL_LIGHT_RED}${WEB_SERVER} version could not be detected.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}${WEB_SERVER} version could not be detected.${COL_NC}"
else
# Otherwise, display the version
log_write " ${TICK} ${WEB_SERVER}: ${WEB_SERVER_VERSON}"
log_write "${TICK} ${WEB_SERVER}: ${WEB_SERVER_VERSON}"
fi
}
@ -270,10 +271,10 @@ check_resolver_server_version() {
# If the DNS server does not have a version (the variable is empty)
if [[ -z "${RESOVLER_VERSON}" ]]; then
# Display and error
log_write " ${CROSS} ${COL_LIGHT_RED}${RESOLVER} version could not be detected.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}${RESOLVER} version could not be detected.${COL_NC}"
else
# Otherwise, display the version
log_write " ${TICK} ${RESOLVER}: ${RESOVLER_VERSON}"
log_write "${TICK} ${RESOLVER}: ${RESOVLER_VERSON}"
fi
}
@ -283,10 +284,10 @@ check_php_version() {
# If no version is detected,
if [[ -z "${PHP_VERSION}" ]]; then
# show an error
log_write " ${CROSS} ${COL_LIGHT_RED}PHP version could not be detected.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}PHP version could not be detected.${COL_NC}"
else
# Otherwise, show the version
log_write " ${TICK} PHP: ${PHP_VERSION}"
log_write "${TICK} PHP: ${PHP_VERSION}"
fi
}
@ -318,7 +319,7 @@ get_distro_attributes() {
# so print it when we find it
PRETTY_NAME_VALUE=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f2- | tr -d '"')
# and then echoed out to the screen
log_write " ${INFO} ${PRETTY_NAME_VALUE}"
log_write "${INFO} ${PRETTY_NAME_VALUE}"
else
# Since we only need the pretty name, we can just skip over anything that is not a match
:
@ -341,7 +342,7 @@ diagnose_operating_system() {
# display the attributes to the user from the function made earlier
get_distro_attributes || \
# If it doesn't exist, it's not a system we currently support and link to FAQ
log_write " ${CROSS} ${COL_LIGHT_RED}${error_msg}${COL_NC} (${COL_CYAN}${FAQ_HARDWARE_REQUIREMENTS}${COL_NC})"
log_write "${CROSS} ${COL_LIGHT_RED}${error_msg}${COL_NC} (${COL_CYAN}${FAQ_HARDWARE_REQUIREMENTS}${COL_NC})"
}
processor_check() {
@ -351,10 +352,10 @@ processor_check() {
# If it does not contain a value,
if [[ -z "${PROCESSOR}" ]]; then
# we couldn't detect it, so show an error
log_write " ${CROSS} ${COL_LIGHT_RED}Processor could not be identified.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}Processor could not be identified.${COL_NC}"
else
# Otherwise, show the processor type
log_write " ${INFO} ${PROCESSOR}"
log_write "${INFO} ${PROCESSOR}"
fi
}
@ -371,15 +372,16 @@ detect_ip_addresses() {
# Local iterator
local i
# Display the protocol and interface
log_write " ${TICK} IPv${protocol} on ${PIHOLE_INTERFACE}"
log_write "${TICK} IPv${protocol} on ${PIHOLE_INTERFACE}"
# Since there may be more than one IP address, store them in an array
for i in "${!ip_addr_list[@]}"; do
# For each one in the list, print it out using the iterator as a numbered list
log_write " [$i] ${ip_addr_list[$i]}"
# For each one in the list, print it out
log_write "${ip_addr_list[$i]}"
done
log_write ""
else
# If there are no IPs detected, explain that the protocol is not configured
log_write " ${CROSS} ${COL_LIGHT_RED}No IPv${protocol} found on ${PIHOLE_INTERFACE}${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}No IPv${protocol} found on ${PIHOLE_INTERFACE}${COL_NC}\n"
return 1
fi
}
@ -408,19 +410,19 @@ ping_gateway() {
# 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
log_write " * Trying three pings on IPv${protocol} gateway at ${gateway}..."
log_write "* Trying three pings on IPv${protocol} gateway at ${gateway}..."
# 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
log_write " ${CROSS} ${COL_LIGHT_RED}Gateway did not respond.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}Gateway did not respond.${COL_NC}\n"
# and return an error code
return 1
# Otherwise,
else
# show a success
log_write " ${TICK} ${COL_LIGHT_GREEN}Gateway responded.${COL_NC}"
log_write "${TICK} ${COL_LIGHT_GREEN}Gateway responded.${COL_NC}\n"
# and return a success code
return 0
fi
@ -442,15 +444,15 @@ ping_internet() {
# and Google's public IPv4 address
local public_address="8.8.8.8"
fi
echo -n " ${INFO} Trying three pings on IPv${protocol} to reach the Internet..."
echo -n "${INFO} Trying three pings on IPv${protocol} to reach the Internet..."
# Try to ping the address 3 times
if ! ping_inet="$(${cmd} -q -W 3 -c 3 -n ${public_address} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then
# if it's unsuccessful, show an error
log_write " ${CROSS} ${COL_LIGHT_RED}Cannot reach the Internet.${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}Cannot reach the Internet.${COL_NC}\n"
return 1
else
# Otherwise, show success
log_write " ${TICK} ${COL_LIGHT_GREEN}Query responded.${COL_NC}"
log_write "${TICK} ${COL_LIGHT_GREEN}Query responded.${COL_NC}\n"
return 0
fi
}
@ -458,7 +460,7 @@ ping_internet() {
check_required_ports() {
# Since Pi-hole needs 53, 80, and 4711, check what they are being used by
# so we can detect any issues
log_write " ${INFO} Ports in use:"
log_write "${INFO} Ports in use:"
# Create an array for these ports in use
ports_in_use=()
# Sort the addresses and remove duplicates
@ -475,35 +477,35 @@ check_required_ports() {
case "${port_number}" in
53) if [[ "${service_name}" == "dnsmasq" ]]; then
# if port 53 is dnsmasq, show it in green as it's standard
log_write " [${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
log_write "[${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
# Otherwise,
else
# Show the service name in red since it's non-standard
log_write " [${COL_LIGHT_RED}${port_number}${COL_NC}] is in use by ${COL_LIGHT_RED}${service_name}${COL_NC}
log_write "[${COL_LIGHT_RED}${port_number}${COL_NC}] is in use by ${COL_LIGHT_RED}${service_name}${COL_NC}
Please see: ${COL_CYAN}https://discourse.pi-hole.net/t/hardware-software-requirements/273#ports${COL_NC}"
fi
;;
80) if [[ "${service_name}" == "lighttpd" ]]; then
# if port 53 is dnsmasq, show it in green as it's standard
log_write " [${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
log_write "[${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
# Otherwise,
else
# Show the service name in red since it's non-standard
log_write " [${COL_LIGHT_RED}${port_number}${COL_NC}] is in use by ${COL_LIGHT_RED}${service_name}${COL_NC}
log_write "[${COL_LIGHT_RED}${port_number}${COL_NC}] is in use by ${COL_LIGHT_RED}${service_name}${COL_NC}
Please see: ${COL_CYAN}https://discourse.pi-hole.net/t/hardware-software-requirements/273#ports${COL_NC}"
fi
;;
4711) if [[ "${service_name}" == "pihole-FT" ]]; then
# if port 4711 is pihole-FTL, show it in green as it's standard
log_write " [${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
log_write "[${COL_LIGHT_GREEN}${port_number}${COL_NC}] is in use by ${COL_LIGHT_GREEN}${service_name}${COL_NC}"
# Otherwise,
else
# Show the service name in yellow since it's non-standard, but should still work
log_write " [${COL_YELLOW}${port_number}${COL_NC}] is in use by ${COL_YELLOW}${service_name}${COL_NC}
log_write "[${COL_YELLOW}${port_number}${COL_NC}] is in use by ${COL_YELLOW}${service_name}${COL_NC}
Please see: ${COL_CYAN}https://discourse.pi-hole.net/t/hardware-software-requirements/273#ports${COL_NC}"
fi
;;
*) log_write " [${port_number}] is in use by ${service_name}";
*) log_write "[${port_number}] is in use by ${service_name}";
esac
done
}
@ -533,19 +535,19 @@ check_x_headers() {
# If the X-header found by curl matches what is should be,
if [[ $block_page == $block_page_working ]]; then
# display a success message
log_write " $TICK ${COL_LIGHT_GREEN}${block_page}${COL_NC}"
log_write "$TICK ${COL_LIGHT_GREEN}${block_page}${COL_NC}"
else
# Otherwise, show an error
log_write " $CROSS ${COL_LIGHT_RED}X-Header does not match or could not be retrieved.${COL_NC}"
log_write "$CROSS ${COL_LIGHT_RED}X-Header does not match or could not be retrieved.${COL_NC}"
fi
# Same logic applies to the dashbord as above, if the X-Header matches what a working system shoud have,
if [[ $dashboard == $dashboard_working ]]; then
# then we can show a success
log_write " $TICK ${COL_LIGHT_GREEN}${dashboard}${COL_NC}"
log_write "$TICK ${COL_LIGHT_GREEN}${dashboard}${COL_NC}"
else
# Othewise, it's a failure since the X-Headers either don't exist or have been modified in some way
log_write " $CROSS ${COL_LIGHT_RED}X-Header does not match or could not be retrieved.${COL_NC}"
log_write "$CROSS ${COL_LIGHT_RED}X-Header does not match or could not be retrieved.${COL_NC}"
fi
}
@ -590,10 +592,10 @@ dig_at() {
# First, do a dig on localhost to see if Pi-hole can use itself to block a domain
if local_dig=$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @${local_address} +short "${record_type}"); then
# If it can, show sucess
log_write " ${TICK} ${COL_LIGHT_GREEN}${random_url} is ${local_dig}${COL_NC} via localhost (${local_address})"
log_write "${TICK} ${random_url} ${COL_LIGHT_GREEN}is ${local_dig}${COL_NC} via localhost (${local_address})"
else
# Otherwise, show a failure
log_write " ${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${random_url} ${COL_LIGHT_RED}via localhost${COL_NC} (${local_address})"
log_write "${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${random_url} ${COL_LIGHT_RED}via localhost${COL_NC} (${local_address})"
fi
# Next we need to check if Pi-hole can resolve a domain when the query is sent to it's IP address
@ -604,20 +606,20 @@ dig_at() {
# If Pi-hole can dig itself from it's IP (not the loopback address)
if pihole_dig=$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @${pihole_address} +short "${record_type}"); then
# show a success
log_write " ${TICK} ${COL_LIGHT_GREEN}${random_url} is ${pihole_dig}${COL_NC} via Pi-hole (${pihole_address})"
log_write "${TICK} ${random_url} ${COL_LIGHT_GREEN}is ${pihole_dig}${COL_NC} via Pi-hole (${pihole_address})"
else
# Othewise, show a failure
log_write " ${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${random_url} ${COL_LIGHT_RED}via Pi-hole${COL_NC} (${pihole_address})"
log_write "${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${random_url} ${COL_LIGHT_RED}via Pi-hole${COL_NC} (${pihole_address})"
fi
# Finally, we need to make sure legitimate queries can out to the Internet using an external, public DNS server
# We are using the static remote_url here instead of a random one because we know it works with IPv4 and IPv6
if remote_dig=$(dig +tries=1 +time=2 -"${protocol}" "${remote_url}" @${remote_address} +short "${record_type}" | head -n1); then
# If successful, the real IP of the domain will be returned instead of Pi-hole's IP
log_write " ${TICK} ${COL_LIGHT_GREEN}${remote_url} is ${remote_dig}${COL_NC} via a remote, public DNS server (${remote_address})"
log_write "${TICK} ${remote_url} ${COL_LIGHT_GREEN}is ${remote_dig}${COL_NC} via a remote, public DNS server (${remote_address})"
else
# Otherwise, show an error
log_write " ${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${remote_url} ${COL_LIGHT_RED}via a remote, public DNS server${COL_NC} (${remote_address})"
log_write "${CROSS} ${COL_LIGHT_RED}Failed to resolve${COL_NC} ${remote_url} ${COL_LIGHT_RED}via a remote, public DNS server${COL_NC} (${remote_address})"
fi
}
@ -635,14 +637,25 @@ process_status(){
# and print it out to the user
if [[ "${status_of_process}" == "active" ]]; then
# If it's active, show it in green
log_write " ${TICK} ${COL_LIGHT_GREEN}${i}${COL_NC} daemon is ${COL_LIGHT_GREEN}${status_of_process}${COL_NC}"
log_write "${TICK} ${COL_LIGHT_GREEN}${i}${COL_NC} daemon is ${COL_LIGHT_GREEN}${status_of_process}${COL_NC}"
else
# If it's not, show it in red
log_write " ${CROSS} ${COL_LIGHT_RED}${i}${COL_NC} daemon is ${COL_LIGHT_RED}${status_of_process}${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}${i}${COL_NC} daemon is ${COL_LIGHT_RED}${status_of_process}${COL_NC}"
fi
done
}
make_array_from_file() {
local filename="${1}"
if [[ -d "${filename}" ]]; then
:
else
while IFS= read -r line;do
file_content+=("${line}")
done < "${filename}"
fi
}
parse_file() {
# Set the first argument passed to this function as a named variable for better readability
local filename="${1}"
@ -655,8 +668,8 @@ parse_file() {
local file_lines
# For each line in the file,
for file_lines in "${file_info[@]}"; do
# display the information with the ${INFO} icon
log_write " ${INFO} ${file_lines}"
# Display the file's content
log_write " ${file_lines}" | grep -v "#" | sed '/^$/d'
done
# Set the IFS back to what it was
IFS="$OLD_IFS"
@ -668,7 +681,7 @@ diagnose_setup_variables() {
# If the variable file exists,
file_exists "${VARSFILE}" && \
log_write " * Sourcing ${VARSFILE}...";
log_write "* Sourcing ${VARSFILE}...";
# source it
source ${VARSFILE};
# and display a green check mark with ${DONE}
@ -701,10 +714,10 @@ dir_check() {
for filename in "${directory}"; do
# check if exists first; if it does,
file_exists "${filename}" && \
# show a success message
echo_succes_or_fail "Files detected" || \
# do nothing
: || \
# Otherwise, show an error
echo_succes_or_fail "${COL_LIGHT_RED}irectory does not exist.${COL_NC}"
echo_succes_or_fail "${COL_LIGHT_RED}directory does not exist.${COL_NC}"
done
}
@ -715,9 +728,19 @@ list_files_in_dir() {
files_found=( $(ls "${dir_to_parse}") )
# For each file in the arry,
for each_file in "${files_found[@]}"; do
# display the information with the ${INFO} icon
# Also print the permissions and the user/group
log_write " ${INFO} $(ls -ld ${dir_to_parse}/${each_file})"
if [[ -d "${each_file}" ]]; then
:
else
# display the information with the ${INFO} icon
# Also print the permissions and the user/group
log_write "\n${COL_LIGHT_GREEN}$(ls -ld ${dir_to_parse}/${each_file})${COL_NC}"
# Otherwise, parse the file's content
make_array_from_file "${dir_to_parse}/${each_file}"
for each_line in "${file_content[@]}"; do
log_write " ${each_line}"
done
fi
file_content=()
done
}
@ -761,10 +784,9 @@ analyze_gravity_list() {
echo_current_diagnostic "Gravity list"
# It's helpful to know how big a user's gravity file is
gravity_length=$(grep -c ^ "${GRAVITYFILE}") && \
log_write " ${INFO} ${GRAVITYFILE} is ${gravity_length} lines long.";
parse_file ${GRAVITYFILE} || \
log_write "${INFO} ${GRAVITYFILE} is ${gravity_length} lines long." || \
# If the previous command failed, something is wrong with the file
log_write " ${CROSS} ${COL_LIGHT_RED}${GRAVITYFILE} not found!${COL_NC}"
log_write "${CROSS} ${COL_LIGHT_RED}${GRAVITYFILE} not found!${COL_NC}"
}
tricorder_use_nc_or_ssl() {
@ -772,13 +794,13 @@ tricorder_use_nc_or_ssl() {
# Check for openssl first since encryption is a good thing
if command -v openssl &> /dev/null; then
# If the command exists,
log_write " * Using ${COL_LIGHT_GREEN}openssl${COL_NC} for transmission."
log_write " * Using ${COL_LIGHT_GREEN}openssl${COL_NC} for transmission."
# encrypt and transmit the log and store the token returned in a variable
tricorder_token=$(cat ${DEBUG_LOG} | openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null)
# Otherwise,
else
# use net cat
log_write " ${INFO} Using ${COL_YELLOW}netcat${COL_NC} for transmission."
log_write "${INFO} Using ${COL_YELLOW}netcat${COL_NC} for transmission."
tricorder_token=$(cat ${DEBUG_LOG} | nc tricorder.pi-hole.net 9999)
fi
}
@ -791,23 +813,22 @@ upload_to_tricorder() {
# Let the user know debugging is complete
echo ""
log_write "${TICK} Finished debugging!"
log_write "${TICK} ${COL_LIGHT_GREEN}** Finished debugging! **${COL_NC}\n"
# Provide information on what they should do with their token
log_write " * The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only."
log_write " * For more information, see: ${COL_CYAN}https://pi-hole.net/2016/11/07/crack-our-medical-tricorder-win-a-raspberry-pi-3/${COL_NC}"
log_write ""
log_write " * If available, we'll use openssl to upload the log, otherwise it will fall back to netcat."
log_write " * The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only."
log_write " * For more information, see: ${COL_CYAN}https://pi-hole.net/2016/11/07/crack-our-medical-tricorder-win-a-raspberry-pi-3/${COL_NC}"
log_write " * If available, we'll use openssl to upload the log, otherwise it will fall back to netcat."
# If pihole -d is running automatically (usually throught the dashboard)
if [[ "${AUTOMATED}" ]]; then
# let the user know
log_write " ${INFO} Debug script running in automated mode"
log_write "${INFO} Debug script running in automated mode"
# and then decide again which tool to use to submit it
if command -v openssl &> /dev/null; then
log_write " ${INFO} Using ${COL_LIGHT_GREEN}openssl${COL_NC} for transmission."
log_write "${INFO} Using ${COL_LIGHT_GREEN}openssl${COL_NC} for transmission."
tricorder_token=$(openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null < /dev/stdin)
else
log_write " ${INFO} Using ${COL_YELLOW}netcat${COL_NC} for transmission."
log_write "${INFO} Using ${COL_YELLOW}netcat${COL_NC} for transmission."
tricorder_token=$(nc tricorder.pi-hole.net 9999 < /dev/stdin)
fi
else
@ -819,7 +840,7 @@ upload_to_tricorder() {
# If they say yes, run our function for uploading the log
[yY][eE][sS]|[yY]) tricorder_use_nc_or_ssl;;
# If they choose no, just exit out of the script
*) log_write " * Log will ${COL_LIGHT_GREE}NOT${COL_NC} be uploaded to tricorder.";exit;
*) log_write " * Log will ${COL_LIGHT_GREEN}NOT${COL_NC} be uploaded to tricorder.";exit;
esac
fi
# Check if tricorder.pi-hole.net is reachable and provide token
@ -829,19 +850,15 @@ upload_to_tricorder() {
log_write "${COL_LIGHT_PURPLE}***********************************${COL_NC}"
log_write "${TICK} Your debug token is: ${COL_LIGHT_GREEN}${tricorder_token}${COL_NC}"
log_write "${COL_LIGHT_PURPLE}***********************************${COL_NC}"
log_write ""
log_write " Provide this token to the Pi-hole team for assistance:"
echo ""
log_write " https://discourse.pi-hole.net"
echo ""
log_write " Your log will self-destruct after 48 hours."
log_write " * Provide this token to the Pi-hole team for assistance:"
log_write " * ${COL_CYAN}https://discourse.pi-hole.net${COL_NC}"
log_write " * Your log will self-destruct after ${COL_LIGHT_RED}48 hours${COL_NC}."
else
log_write " ${CROSS} There was an error uploading your debug log."
log_write " Please try again or contact the Pi-hole team for assistance."
log_write "${CROSS} ${COL_LIGHT_RED}There was an error uploading your debug log.${COL_NC}"
log_write " * Please try again or contact the Pi-hole team for assistance."
fi
echo ""
log_write " A local copy of the debug log can be found at : /var/log/pihole_debug.log"
echo ""
log_write " * A local copy of the debug log can be found at : ${COL_CYAN}${DEBUG_LOG}${COL_NC}\n"
}
# Run through all the functions we made