Skip to content

Commit 13d5dea

Browse files
darkexplosiveqwxyubiuser
authored andcommitted
move full API URL variable to --api
Signed-off-by: darkexplosiveqwx <[email protected]>
1 parent 3ce5187 commit 13d5dea

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

padd.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,17 @@ TestAPIAvailability() {
105105

106106
local chaos_api_list authResponse cmdResult digReturnCode authStatus authData apiAvailable
107107

108-
# Check if SERVER is a full URL
109-
# If it is, skip the DNS lookup
110-
case "$SERVER" in
111-
http://* | https://*)
108+
if [ -n "$API_LOCATION" ] && [ -n "$SERVER" ]; then
109+
moveXOffset; echo "Do not set --server and --api simultaneously."
110+
moveXOffset; echo "Exiting."
111+
exit 1
112+
fi
113+
114+
# Check if an API location was specified with --api
115+
if [ -n "${API_LOCATION}" ]; then
112116
# The list of available API URLs is just the provided URL
113-
chaos_api_list="${SERVER}"
114-
;;
115-
*)
117+
chaos_api_list="${API_LOCATION}"
118+
else
116119
# Query the API URLs from FTL using CHAOS TXT
117120
# The result is a space-separated enumeration of full URLs
118121
# e.g., "http://localhost:80/api" or "https://domain.com:443/api"
@@ -136,8 +139,7 @@ TestAPIAvailability() {
136139
# Dig returned 0 (success), so get the actual response (first line)
137140
chaos_api_list="$(echo "${cmdResult}" | head -n 1)"
138141
fi
139-
;;
140-
esac
142+
fi
141143

142144
# Iterate over space-separated list of URLs
143145
while [ -n "${chaos_api_list}" ]; do
@@ -301,7 +303,7 @@ Authenticate() {
301303

302304
if [ -z "${sessionResponse}" ]; then
303305
moveXOffset; echo "No response from FTL server. Please check connectivity and use the options to set the API URL"
304-
moveXOffset; echo "Usage: $0 [--server <domain|IP>]"
306+
moveXOffset; echo "Usage: $0 [--server <domain|IP>] or [--api <API URL>]"
305307
exit 1
306308
fi
307309
# obtain validity, session ID and sessionMessage from session response
@@ -1827,6 +1829,7 @@ DisplayHelp() {
18271829
::: --yoff [num] set the y-offset, reference is the upper left corner, disables auto-centering
18281830
:::
18291831
::: --server <DOMAIN|IP> domain or IP of your Pi-hole (default: localhost)
1832+
::: --api <API URL> API URL location of your Pi-hole (example: https://pi.hole/api/)
18301833
::: --secret <password> your Pi-hole's password, required to access the API
18311834
::: --2fa <2fa> your Pi-hole's 2FA code, if 2FA is enabled
18321835
::: --runonce display output once and exit
@@ -1931,6 +1934,7 @@ while [ "$#" -gt 0 ]; do
19311934
"--xoff" ) xOffset="$2"; xOffOrig="$2"; shift;;
19321935
"--yoff" ) yOffset="$2"; yOffOrig="$2"; shift;;
19331936
"--server" ) SERVER="$2"; shift;;
1937+
"--api" ) API_LOCATION="$2"; shift;;
19341938
"--secret" ) password="$2"; shift;;
19351939
"--2fa" ) totp="$2"; shift;;
19361940
* ) DisplayHelp; exit 1;;

0 commit comments

Comments
 (0)