From 25f384a923c3f0feccedc3ee4033cc482f2683c8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 20 Jun 2024 19:41:47 +0200 Subject: [PATCH] Do not use CLI password when no password is set at all Signed-off-by: DL6ER --- advanced/Scripts/api.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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"