From 4df7cee6c20bf3bbcf3ad806345f3b8dc82aced3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 19 Jun 2024 22:21:43 +0200 Subject: [PATCH] Add partial matching hint if exact matching found nothing Signed-off-by: DL6ER --- advanced/Scripts/api.sh | 4 ++-- advanced/Scripts/query.sh | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 3d35742f..4162eff1 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -74,7 +74,7 @@ TestAPIAvailability() { fi } -Authentication() { +LoginAPI() { # 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) @@ -96,7 +96,7 @@ Authentication() { } -LoginAPI() { +Authentication() { sessionResponse="$(curl -skS -X POST "${API_URL}auth" --user-agent "Pi-hole cli " --data "{\"password\":\"${password}\"}" )" if [ -z "${sessionResponse}" ]; then diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 123eee21..c76e890e 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -112,6 +112,12 @@ GenerateOutput() { printf "\n\n" done fi + + # If no exact results were found, suggest using partial matching + if [ "${num_lists}" -eq 0 ] && [ "${num_gravity}" -eq 0 ] && [ "${partial}" = false ]; then + printf "%s\n" "Hint: Try partial matching with" + printf "%s\n\n" " ${COL_GREEN}pihole -q --partial ${domain}${COL_NC}" + fi } Main() { @@ -129,12 +135,14 @@ Main() { TestAPIAvailability # Authenticate with FTL - Authentication + LoginAPI # send query again data=$(GetFTLData "search/${domain}?N=${max_results}&partial=${partial}") GenerateOutput "${data}" + + # Delete session LogoutAPI }