Skip to content

Commit

Permalink
Rewrite list functions to use the API
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Jun 19, 2024
1 parent 92b15cf commit bfc18f8
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 237 deletions.
18 changes: 16 additions & 2 deletions advanced/Scripts/api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -91,7 +95,7 @@ LoginAPI() {
secretRead; printf '\n'

# Try to authenticate again
LoginAPI
Authentication
done

}
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit bfc18f8

Please sign in to comment.