@@ -105,14 +105,17 @@ TestAPIAvailability() {
105
105
106
106
local chaos_api_list authResponse cmdResult digReturnCode authStatus authData apiAvailable
107
107
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
112
116
# 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
116
119
# Query the API URLs from FTL using CHAOS TXT
117
120
# The result is a space-separated enumeration of full URLs
118
121
# e.g., "http://localhost:80/api" or "https://domain.com:443/api"
@@ -136,8 +139,7 @@ TestAPIAvailability() {
136
139
# Dig returned 0 (success), so get the actual response (first line)
137
140
chaos_api_list=" $( echo " ${cmdResult} " | head -n 1) "
138
141
fi
139
- ;;
140
- esac
142
+ fi
141
143
142
144
# Iterate over space-separated list of URLs
143
145
while [ -n " ${chaos_api_list} " ]; do
@@ -301,7 +303,7 @@ Authenticate() {
301
303
302
304
if [ -z " ${sessionResponse} " ]; then
303
305
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>] "
305
307
exit 1
306
308
fi
307
309
# obtain validity, session ID and sessionMessage from session response
@@ -1827,6 +1829,7 @@ DisplayHelp() {
1827
1829
::: --yoff [num] set the y-offset, reference is the upper left corner, disables auto-centering
1828
1830
:::
1829
1831
::: --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/)
1830
1833
::: --secret <password> your Pi-hole's password, required to access the API
1831
1834
::: --2fa <2fa> your Pi-hole's 2FA code, if 2FA is enabled
1832
1835
::: --runonce display output once and exit
@@ -1931,6 +1934,7 @@ while [ "$#" -gt 0 ]; do
1931
1934
" --xoff" ) xOffset=" $2 " ; xOffOrig=" $2 " ; shift ;;
1932
1935
" --yoff" ) yOffset=" $2 " ; yOffOrig=" $2 " ; shift ;;
1933
1936
" --server" ) SERVER=" $2 " ; shift ;;
1937
+ " --api" ) API_LOCATION=" $2 " ; shift ;;
1934
1938
" --secret" ) password=" $2 " ; shift ;;
1935
1939
" --2fa" ) totp=" $2 " ; shift ;;
1936
1940
* ) DisplayHelp; exit 1;;
0 commit comments