mirror of
https://github.com/Erreur32/nginx-proxy-manager-Bash-API.git
synced 2024-12-22 13:32:11 +01:00
FIX --HOST-DISABLE
This commit is contained in:
parent
94bb96bc48
commit
ca8cc272dd
1 changed files with 11 additions and 22 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Nginx Proxy Manager CLI Script v2.1.0
|
# Nginx Proxy Manager CLI Script v1.1.2
|
||||||
# Erreur32 - July 2024
|
# Erreur32 - July 2024
|
||||||
#
|
#
|
||||||
# This script allows you to manage Nginx Proxy Manager via the API. It provides
|
# This script allows you to manage Nginx Proxy Manager via the API. It provides
|
||||||
|
@ -1171,33 +1171,22 @@ disable_proxy_host() {
|
||||||
fi
|
fi
|
||||||
echo -e "\n ❌ Disabling 🌐 proxy host ID: $HOST_ID..."
|
echo -e "\n ❌ Disabling 🌐 proxy host ID: $HOST_ID..."
|
||||||
|
|
||||||
# Check if the proxy host exists before disabling
|
HTTP_RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X POST "$BASE_URL/nginx/proxy-hosts/$HOST_ID/disable" \
|
||||||
CHECK_RESPONSE=$(curl -s -X GET "$BASE_URL/nginx/proxy-hosts/$HOST_ID" \
|
-H "Authorization: Bearer $(cat $TOKEN_FILE)" \
|
||||||
-H "Authorization: Bearer $(cat $TOKEN_FILE)")
|
-H "Content-Type: application/json")
|
||||||
|
|
||||||
if echo "$CHECK_RESPONSE" | jq -e '.id' > /dev/null 2>&1; then
|
# Extract the body and the status
|
||||||
# Proxy host exists, proceed to disable
|
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
|
||||||
DATA=$(echo "$CHECK_RESPONSE" | jq '{enabled: 0}')
|
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
|
||||||
|
|
||||||
HTTP_RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X PUT "$BASE_URL/nginx/proxy-hosts/$HOST_ID" \
|
if [ "$HTTP_STATUS" -eq 200 ]; then
|
||||||
-H "Authorization: Bearer $(cat $TOKEN_FILE)" \
|
echo -e " ✅ ${COLOR_GREEN}Proxy host disabled successfully!${COLOR_RESET}\n"
|
||||||
-H "Content-Type: application/json; charset=UTF-8" \
|
|
||||||
--data-raw "$DATA")
|
|
||||||
|
|
||||||
# Extract the body and the status
|
|
||||||
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
|
|
||||||
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
|
|
||||||
|
|
||||||
if [ "$HTTP_STATUS" -eq 200 ]; then
|
|
||||||
echo -e " ✅ ${COLOR_GREEN}Proxy host disabled successfully!${COLOR_RESET}\n"
|
|
||||||
else
|
|
||||||
echo -e " ⛔ ${COLOR_RED}Failed to disable proxy host. HTTP status: $HTTP_STATUS. Response: $HTTP_BODY${COLOR_RESET}\n"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo -e " ⛔ ${COLOR_RED}Proxy host with ID $HOST_ID does not exist.${COLOR_RESET}\n"
|
echo -e " ⛔ ${COLOR_RED}Failed to disable proxy host. HTTP status: $HTTP_STATUS. Response: $HTTP_BODY${COLOR_RESET}\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Generate Let's Encrypt certificate if not exists
|
# Generate Let's Encrypt certificate if not exists
|
||||||
generate_certificate() {
|
generate_certificate() {
|
||||||
if [ -z "$DOMAIN" ] || [ -z "$EMAIL" ]; then
|
if [ -z "$DOMAIN" ] || [ -z "$EMAIL" ]; then
|
||||||
|
|
Loading…
Reference in a new issue