mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Show when requested domains were not found on the list
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
ccdbfd4130
commit
c2ed30480d
@ -166,10 +166,14 @@ PostFTLData() {
|
|||||||
local data response status
|
local data response status
|
||||||
# send the data to the API
|
# send the data to the API
|
||||||
response=$(curl -skS -w "%{http_code}" -X POST "${API_URL}$1" --data-raw "$2" -H "Accept: application/json" -H "sid: ${SID}" )
|
response=$(curl -skS -w "%{http_code}" -X POST "${API_URL}$1" --data-raw "$2" -H "Accept: application/json" -H "sid: ${SID}" )
|
||||||
# status are the last 3 characters
|
|
||||||
status=$(printf %s "${response#"${response%???}"}")
|
|
||||||
# data is everything from response without the last 3 characters
|
# data is everything from response without the last 3 characters
|
||||||
printf %s "${response%???}"
|
if [ "${3}" = "status" ]; then
|
||||||
|
# Keep the status code appended if requested
|
||||||
|
printf %s "${response}"
|
||||||
|
else
|
||||||
|
# Strip the status code
|
||||||
|
printf %s "${response%???}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
secretRead() {
|
secretRead() {
|
||||||
|
@ -66,7 +66,7 @@ CreateDomainList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddDomain() {
|
AddDomain() {
|
||||||
local json num
|
local json num data
|
||||||
|
|
||||||
# Authenticate with the API
|
# Authenticate with the API
|
||||||
LoginAPI
|
LoginAPI
|
||||||
@ -113,7 +113,7 @@ AddDomain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RemoveDomain() {
|
RemoveDomain() {
|
||||||
local json num
|
local json num data status
|
||||||
|
|
||||||
# Authenticate with the API
|
# Authenticate with the API
|
||||||
LoginAPI
|
LoginAPI
|
||||||
@ -130,7 +130,10 @@ RemoveDomain() {
|
|||||||
json=$(jq --null-input --compact-output --arg domains "${domList[*]}" --arg typeId "${typeId}" --arg kindId "${kindId}" '[ $domains | split(" ")[] as $item | {item: $item, type: $typeId, kind: $kindId} ]')
|
json=$(jq --null-input --compact-output --arg domains "${domList[*]}" --arg typeId "${typeId}" --arg kindId "${kindId}" '[ $domains | split(" ")[] as $item | {item: $item, type: $typeId, kind: $kindId} ]')
|
||||||
|
|
||||||
# Send the request
|
# Send the request
|
||||||
data=$(PostFTLData "domains:batchDelete" "${json}")
|
data=$(PostFTLData "domains:batchDelete" "${json}" "status")
|
||||||
|
# Separate the status from the data
|
||||||
|
status=$(printf %s "${data#"${data%???}"}")
|
||||||
|
data=$(printf %s "${data%???}")
|
||||||
|
|
||||||
# If there is an .error object in the returned data, display it
|
# If there is an .error object in the returned data, display it
|
||||||
local error
|
local error
|
||||||
@ -138,12 +141,10 @@ RemoveDomain() {
|
|||||||
if [[ $error != "null" && $error != "" ]]; then
|
if [[ $error != "null" && $error != "" ]]; then
|
||||||
echo -e " ${CROSS} Failed to remove domain(s):"
|
echo -e " ${CROSS} Failed to remove domain(s):"
|
||||||
echo -e " $(jq <<< "${data}" '.error')"
|
echo -e " $(jq <<< "${data}" '.error')"
|
||||||
elif [[ "${verbose}" == true ]]; then
|
elif [[ "${verbose}" == true && "${status}" == "204" ]]; then
|
||||||
echo -e " ${TICK} Removed ${#domList[@]} domain(s):"
|
echo -e " ${TICK} Domain(s) removed from the ${kindId} ${typeId}list"
|
||||||
# Loop through the domains and display them
|
elif [[ "${verbose}" == true && "${status}" == "404" ]]; then
|
||||||
for dom in "${domList[@]}"; do
|
echo -e " ${TICK} Requested domain(s) not found on ${kindId} ${typeId}list"
|
||||||
echo -e " - ${COL_BLUE}${dom}${COL_NC}"
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Log out
|
# Log out
|
||||||
|
Loading…
Reference in New Issue
Block a user