mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-07 19:55:09 +02:00
Allow simple pihole api
output, containing only the JSON payload
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
parent
3f5c00919b
commit
d0615de6ef
@ -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}"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user