mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-01-27 06:49:51 +00:00
Check for valid OS via IPv4 and IPv6 (#5305)
This commit is contained in:
commit
758ace57c0
2 changed files with 44 additions and 4 deletions
|
@ -324,7 +324,7 @@ os_check() {
|
||||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||||
|
|
||||||
cmdResult="$(dig +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
cmdResult="$(dig -4 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||||
#Get the return code of the previous command (last line)
|
#Get the return code of the previous command (last line)
|
||||||
digReturnCode="${cmdResult##*$'\n'}"
|
digReturnCode="${cmdResult##*$'\n'}"
|
||||||
|
|
||||||
|
@ -334,7 +334,20 @@ os_check() {
|
||||||
if [ "${digReturnCode}" -ne 0 ]; then
|
if [ "${digReturnCode}" -ne 0 ]; then
|
||||||
log_write "${INFO} Distro: ${detected_os^}"
|
log_write "${INFO} Distro: ${detected_os^}"
|
||||||
log_write "${INFO} Version: ${detected_version}"
|
log_write "${INFO} Version: ${detected_version}"
|
||||||
log_write "${CROSS} dig return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
log_write "${CROSS} dig IPv4 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||||
|
log_write "${CROSS} dig response: ${response}"
|
||||||
|
log_write "${INFO} Retrying via IPv6"
|
||||||
|
|
||||||
|
cmdResult="$(dig -6 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||||
|
#Get the return code of the previous command (last line)
|
||||||
|
digReturnCode="${cmdResult##*$'\n'}"
|
||||||
|
|
||||||
|
# Extract dig response
|
||||||
|
response="${cmdResult%%$'\n'*}"
|
||||||
|
fi
|
||||||
|
# If also no success via IPv6
|
||||||
|
if [ "${digReturnCode}" -ne 0 ]; then
|
||||||
|
log_write "${CROSS} dig IPv6 return code: ${COL_RED}${digReturnCode}${COL_NC}"
|
||||||
log_write "${CROSS} dig response: ${response}"
|
log_write "${CROSS} dig response: ${response}"
|
||||||
log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}"
|
log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -175,7 +175,8 @@ os_check() {
|
||||||
detected_os=$(grep '^ID=' /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
detected_os=$(grep '^ID=' /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||||
|
|
||||||
cmdResult="$(dig +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
# Test via IPv4
|
||||||
|
cmdResult="$(dig -4 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||||
# Gets the return code of the previous command (last line)
|
# Gets the return code of the previous command (last line)
|
||||||
digReturnCode="${cmdResult##*$'\n'}"
|
digReturnCode="${cmdResult##*$'\n'}"
|
||||||
|
|
||||||
|
@ -187,8 +188,34 @@ os_check() {
|
||||||
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
|
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
|
||||||
if [ "${response}" == 0 ]; then
|
if [ "${response}" == 0 ]; then
|
||||||
valid_response=false
|
valid_response=false
|
||||||
|
else
|
||||||
|
valid_response=true
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Try again via IPv6
|
||||||
|
if [ "$valid_response" = false ]; then
|
||||||
|
unset valid_response
|
||||||
|
|
||||||
|
cmdResult="$(dig -6 +short -t txt "${remote_os_domain}" @ns1.pi-hole.net 2>&1; echo $?)"
|
||||||
|
# Gets the return code of the previous command (last line)
|
||||||
|
digReturnCode="${cmdResult##*$'\n'}"
|
||||||
|
|
||||||
|
if [ ! "${digReturnCode}" == "0" ]; then
|
||||||
|
valid_response=false
|
||||||
|
else
|
||||||
|
# Dig returned 0 (success), so get the actual response, and loop through it to determine if the detected variables above are valid
|
||||||
|
response="${cmdResult%%$'\n'*}"
|
||||||
|
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
|
||||||
|
if [ "${response}" == 0 ]; then
|
||||||
|
valid_response=false
|
||||||
|
else
|
||||||
|
valid_response=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$valid_response" = true ]; then
|
||||||
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
||||||
for distro_and_versions in "${supportedOS[@]}"
|
for distro_and_versions in "${supportedOS[@]}"
|
||||||
do
|
do
|
||||||
|
@ -211,7 +238,7 @@ os_check() {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$valid_os" = true ] && [ "$valid_version" = true ] && [ ! "$valid_response" = false ]; then
|
if [ "$valid_os" = true ] && [ "$valid_version" = true ] && [ "$valid_response" = true ]; then
|
||||||
display_warning=false
|
display_warning=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue