diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 21447105..6f31a6d2 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -51,6 +51,12 @@ TestAPIAvailability() { API_PORT="" else # API is available at this URL combination + + if [ "${availabilityResonse}" = 200 ]; then + # API is available without authentication + needAuth=false + fi + break fi @@ -75,10 +81,16 @@ TestAPIAvailability() { } LoginAPI() { + # If the API URL is not set, test the availability if [ -z "${API_URL}" ]; then TestAPIAvailability fi + # Exit early if authentication is not needed + if [ "${needAuth}" = false ]; then + return + fi + # Try to read the CLI password (if enabled and readable by the current user) if [ -r /etc/pihole/cli_pw ]; then password=$(cat /etc/pihole/cli_pw) @@ -87,6 +99,8 @@ LoginAPI() { Authentication fi + + # If this did not work, ask the user for the password while [ "${validSession}" = false ] || [ -z "${validSession}" ] ; do echo "Authentication failed. Please enter your Pi-hole password"