mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-19 05:40:13 +00:00
Rewrite list functions to use the API
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
92b15cf744
commit
bfc18f8329
3 changed files with 164 additions and 232 deletions
|
@ -75,12 +75,16 @@ TestAPIAvailability() {
|
|||
}
|
||||
|
||||
LoginAPI() {
|
||||
if [ -z "${API_URL}" ]; then
|
||||
TestAPIAvailability
|
||||
fi
|
||||
|
||||
# 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)
|
||||
|
||||
# Try to authenticate using the CLI password
|
||||
LoginAPI
|
||||
Authentication
|
||||
fi
|
||||
|
||||
# If this did not work, ask the user for the password
|
||||
|
@ -91,7 +95,7 @@ LoginAPI() {
|
|||
secretRead; printf '\n'
|
||||
|
||||
# Try to authenticate again
|
||||
LoginAPI
|
||||
Authentication
|
||||
done
|
||||
|
||||
}
|
||||
|
@ -144,6 +148,16 @@ GetFTLData() {
|
|||
fi
|
||||
}
|
||||
|
||||
PostFTLData() {
|
||||
local data response status
|
||||
# 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}" )
|
||||
# status are the last 3 characters
|
||||
status=$(printf %s "${response#"${response%???}"}")
|
||||
# data is everything from response without the last 3 characters
|
||||
printf %s "${response%???}"
|
||||
}
|
||||
|
||||
secretRead() {
|
||||
|
||||
# POSIX compliant function to read user-input and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue