Allow simple pihole api output, containing only the JSON payload
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
+24
-8
@@ -301,14 +301,23 @@ secretRead() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiFunc() {
|
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
|
# Authenticate with the API
|
||||||
LoginAPI verbose
|
LoginAPI "${verbose}"
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}"
|
if [ "${verbose}" = "verbose" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Requesting: ${COL_PURPLE}GET ${COL_CYAN}${API_URL}${COL_YELLOW}$1${COL_NC}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the data from the API
|
# Get the data from the API
|
||||||
response=$(GetFTLData "$1" raw)
|
response=$(GetFTLData "$1" raw)
|
||||||
@@ -325,11 +334,18 @@ apiFunc() {
|
|||||||
else
|
else
|
||||||
status_col="${COL_RED}"
|
status_col="${COL_RED}"
|
||||||
fi
|
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.
|
# Output the data. Format it with jq if available and data is actually JSON.
|
||||||
# Otherwise just print it
|
# 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
|
if command -v jq >/dev/null && echo "${data}" | jq . >/dev/null 2>&1; then
|
||||||
echo "${data}" | jq .
|
echo "${data}" | jq .
|
||||||
else
|
else
|
||||||
@@ -337,5 +353,5 @@ apiFunc() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Delete the session
|
# Delete the session
|
||||||
LogoutAPI verbose
|
LogoutAPI "${verbose}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -601,6 +601,6 @@ case "${1}" in
|
|||||||
"updatechecker" ) shift; updateCheckFunc "$@";;
|
"updatechecker" ) shift; updateCheckFunc "$@";;
|
||||||
"arpflush" ) arpFunc "$@";;
|
"arpflush" ) arpFunc "$@";;
|
||||||
"-t" | "tail" ) tailFunc "$2";;
|
"-t" | "tail" ) tailFunc "$2";;
|
||||||
"api" ) apiFunc "$2";;
|
"api" ) shift; apiFunc "$@";;
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user