55# By Erreur32 - July 2024
66# NPM api https://github.com/NginxProxyManager/nginx-proxy-manager/tree/develop/backend/schema
77
8- VERSION=" 2.8 .0"
8+ VERSION=" 3.0 .0"
99
1010# ################################
1111# This script allows you to manage Nginx Proxy Manager via the API. It provides
@@ -1353,6 +1353,9 @@ create_or_update_proxy_host() {
13531353 # Si on a demandé de générer un certificat
13541354 if [ " $GENERATE_CERT " = true ]; then
13551355 echo -e " 🔐 Generate SSL certificat ..."
1356+ # Initialiser les variables DNS
1357+ DNS_PROVIDER=" "
1358+ DNS_API_KEY=" "
13561359 generate_certificate " $DOMAIN_NAMES " " $CERT_EMAIL " " $DNS_PROVIDER " " $DNS_API_KEY "
13571360
13581361 # Vérifier que le certificat a été créé
@@ -2118,6 +2121,38 @@ generate_certificate() {
21182121 echo -e " \n 📧 Using default email: ${COLOR_YELLOW} $EMAIL ${CoR} "
21192122 fi
21202123 check_token_notverbose
2124+
2125+ echo -e " \n ${COLOR_CYAN} 🔍${CoR} Verifying domain accessibility..."
2126+ if ! curl -s -I " http://$DOMAIN " > /dev/null 2>&1 ; then
2127+ echo -e " ${COLOR_RED} ❌${CoR} Domain ${COLOR_YELLOW} $DOMAIN ${CoR} is not accessible via HTTP."
2128+ echo -e " ${COLOR_CYAN} 💡${CoR} Please ensure:"
2129+ echo -e " • DNS records are properly configured"
2130+ echo -e " • Domain is pointing to your server"
2131+ echo -e " • Port 80 is open and accessible"
2132+ echo -e " • Nginx Proxy Manager is properly configured"
2133+ echo -e " • No firewall is blocking access"
2134+
2135+ echo -e " \n ${COLOR_YELLOW} 🔍${CoR} Checking DNS records..."
2136+ if command -v dig > /dev/null 2>&1 ; then
2137+ echo -e " • A record:"
2138+ dig +short A " $DOMAIN " | while read -r ip; do
2139+ echo -e " └─ $ip "
2140+ done
2141+ echo -e " • CNAME record:"
2142+ dig +short CNAME " $DOMAIN " | while read -r cname; do
2143+ echo -e " └─ $cname "
2144+ done
2145+ else
2146+ echo -e " ${COLOR_YELLOW} ⚠️${CoR} dig command not found. Please install dnsutils package."
2147+ fi
2148+
2149+ echo -e " \n ${COLOR_CYAN} 💡${CoR} You can test domain accessibility with:"
2150+ echo -e " ${COLOR_GREEN} curl -I http://$DOMAIN ${CoR} "
2151+ echo -e " ${COLOR_GREEN} dig $DOMAIN ${CoR} "
2152+ exit 1
2153+ else
2154+ echo -e " ${COLOR_GREEN} ✅${CoR} Domain ${COLOR_YELLOW} $DOMAIN ${CoR} is accessible via HTTP"
2155+ fi
21212156 # Check if domain exists in NPM proxy hosts
21222157 echo -e " \n ${COLOR_CYAN} 🔍${CoR} Checking if domain exists in NPM..."
21232158 PROXY_RESPONSE=$( curl -s -X GET " $BASE_URL /nginx/proxy-hosts" \
@@ -2167,12 +2202,15 @@ generate_certificate() {
21672202 RESPONSE=$( curl -s -X GET " $BASE_URL /nginx/certificates" \
21682203 -H " Authorization: Bearer $( cat " $TOKEN_FILE " ) " )
21692204
2205+ # Check for existing certificates
2206+ BASE_DOMAIN=" ${DOMAIN# \*\. } "
2207+
21702208 # Check for exact match and wildcard matches
2171- EXISTING_CERT=$( echo " $RESPONSE " | jq -r --arg DOMAIN " $DOMAIN " \
2209+ EXISTING_CERT=$( echo " $RESPONSE " | jq -r --arg domain " $BASE_DOMAIN " \
21722210 ' .[] | select(
2173- (.domain_names[] == $DOMAIN ) or
2174- (.domain_names[] | startswith("*.") and ($DOMAIN | endswith(.[2:]))) or
2175- ($DOMAIN | startswith("*.") and (.domain_names[] | endswith(.[2:])))
2211+ (.domain_names[] == $domain ) or
2212+ (.domain_names[] | startswith("*.") and ($domain | endswith(.[2:]))) or
2213+ ($domain | startswith("*.") and (.domain_names[] | endswith(.[2:])))
21762214 )' )
21772215
21782216 if [ -n " $EXISTING_CERT " ]; then
@@ -2325,27 +2363,42 @@ generate_certificate() {
23252363 echo -e " ${COLOR_CYAN} $0 --host-ssl-enable $DOMAIN_EXISTS ${CoR} "
23262364 fi
23272365 else
2328-
2329-
23302366 echo -e " \n ${COLOR_RED} ❌ Certificate generation failed!${CoR} "
23312367 ERROR_MSG=$( echo " $HTTP_BODY " | jq -r ' .error.message // "Unknown error"' )
23322368 echo -e " ${COLOR_RED} ⛔${CoR} Error: ${COLOR_RED} $ERROR_MSG ${CoR} "
2333- echo -e " \n ${COLOR_CYAN} 🔍 Troubleshooting suggestions:${CoR} "
2369+
2370+ # Extraire les détails de débogage si disponibles
2371+ DEBUG_STACK=$( echo " $HTTP_BODY " | jq -r ' .debug.stack[]? // empty' )
2372+ if [ -n " $DEBUG_STACK " ]; then
2373+ echo -e " \n ${COLOR_YELLOW} 🔍${CoR} Debug Stack:"
2374+ echo " $DEBUG_STACK " | while read -r line; do
2375+ echo -e " • ${COLOR_YELLOW} $line ${CoR} "
2376+ done
2377+ fi
2378+
2379+ echo -e " \n ${COLOR_CYAN} 🔍${CoR} Troubleshooting suggestions:"
23342380 echo -e " • Verify domain DNS records are properly configured"
23352381 echo -e " • Ensure domain is accessible via HTTP/HTTPS"
23362382 echo -e " • Check if Let's Encrypt rate limits are not exceeded"
2337- if [ -n " $DNS_PROVIDER " ]; then
2338- echo -e " • Verify DNS provider credentials"
2339- echo -e " • Allow time for DNS propagation (up to 24 hours)"
2340- fi
2341-
2342- echo -e " 📋 Debug Information:"
2343- echo -e " • HTTP Status: $HTTP_STATUS "
2344- echo -e " • Response: $HTTP_BODY "
2345- echo -e " • Request Data: $DATA "
2383+ echo -e " • Verify Nginx Proxy Manager is properly configured"
2384+ echo -e " • Check if port 80 is open and accessible"
2385+ echo -e " • Ensure no firewall is blocking access"
2386+ echo -e " • Check Nginx Proxy Manager logs for more details"
2387+
2388+ echo -e " \n ${COLOR_CYAN} 💡${CoR} You can try:"
2389+ echo -e " • Wait a few minutes and try again (DNS propagation)"
2390+ echo -e " • Check Nginx Proxy Manager logs:"
2391+ echo -e " ${COLOR_GREEN} docker logs nginx-proxy-manager${CoR} "
2392+ echo -e " • Check Let's Encrypt logs:"
2393+ echo -e " ${COLOR_GREEN} docker exec nginx-proxy-manager cat /tmp/letsencrypt-log/letsencrypt.log${CoR} "
2394+
2395+ echo -e " \n 📋 Debug Information:"
2396+ echo -e " • HTTP Status: $HTTP_STATUS "
2397+ echo -e " • Response: $HTTP_BODY "
2398+ echo -e " • Request Data: $DATA "
23462399
23472400 exit 1
2348- fi
2401+ fi
23492402}
23502403
23512404# ###############################
@@ -3356,7 +3409,7 @@ while [[ "$#" -gt 0 ]]; do
33563409 echo -e " Usage: ${COLOR_ORANGE} $0 --user-create <username> <password> <email>${CoR} "
33573410 echo -e " Example:"
33583411 echo -e " ${COLOR_GREEN} $0 --user-create john secretpass john@domain.com${CoR} \n"
3359- exit 1
3412+ exit 1
33603413 fi
33613414
33623415 USERNAME=" $1 "
@@ -3701,6 +3754,7 @@ while [[ "$#" -gt 0 ]]; do
37013754 echo -e " Usage: $0 --host-ssl-enable <host_id>"
37023755 exit 1
37033756 fi
3757+ host_enable_ssl " $HOST_ID "
37043758 ;;
37053759 --host-ssl-disable)
37063760 shift
@@ -3711,7 +3765,7 @@ while [[ "$#" -gt 0 ]]; do
37113765 echo -e " \n ⛔ ${COLOR_RED} The --host-ssl-disable option requires a host 🆔.${CoR} "
37123766 exit 1
37133767 fi
3714- DISABLE_SSL=true
3768+ host_disable_ssl " $HOST_ID "
37153769 ;;
37163770 --generate-cert)
37173771 shift
0 commit comments