diff --git a/advanced/Scripts/api.sh b/advanced/Scripts/api.sh index 79fc90f4..e824640a 100755 --- a/advanced/Scripts/api.sh +++ b/advanced/Scripts/api.sh @@ -301,14 +301,23 @@ secretRead() { } apiFunc() { - local data response status status_col + local data response status status_col verbose + + # Define if the output will be verbose (default) or silent + verbose="verbose" + if [ "$1" = "silent" ] || [ "$1" = "-s" ]; then + verbose="" + shift + fi # Authenticate with the API - LoginAPI verbose - echo "" + LoginAPI "${verbose}" - echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}" - echo "" + if [ "${verbose}" = "verbose" ]; then + echo "" + echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}" + echo "" + fi # Get the data from the API response=$(GetFTLData "$1" raw) @@ -325,11 +334,18 @@ apiFunc() { else status_col="${COL_RED}" fi - echo "Status: ${status_col}${status}${COL_NC}" + + # Only print the status in verbose mode or if the status is not 200 + if [ "${verbose}" = "verbose" ] || [ "${status}" != 200 ]; then + echo "Status: ${status_col}${status}${COL_NC}" + fi # Output the data. Format it with jq if available and data is actually JSON. # Otherwise just print it - echo "Data:" + if [ "${verbose}" = "verbose" ]; then + echo "Data:" + fi + if command -v jq >/dev/null && echo "${data}" | jq . >/dev/null 2>&1; then echo "${data}" | jq . else @@ -337,5 +353,5 @@ apiFunc() { fi # Delete the session - LogoutAPI verbose + LogoutAPI "${verbose}" } diff --git a/pihole b/pihole index bf662a82..39eec5a8 100755 --- a/pihole +++ b/pihole @@ -592,6 +592,6 @@ case "${1}" in "updatechecker" ) shift; updateCheckFunc "$@";; "arpflush" ) arpFunc "$@";; "-t" | "tail" ) tailFunc "$2";; - "api" ) apiFunc "$2";; + "api" ) shift; apiFunc "$@";; * ) helpFunc;; esac