5
5
# By Erreur32 - July 2024
6
6
# NPM api https://github.com/NginxProxyManager/nginx-proxy-manager/tree/develop/backend/schema
7
7
8
- VERSION=" 2.8 .0"
8
+ VERSION=" 3.0 .0"
9
9
10
10
# ################################
11
11
# This script allows you to manage Nginx Proxy Manager via the API. It provides
@@ -1353,6 +1353,9 @@ create_or_update_proxy_host() {
1353
1353
# Si on a demandé de générer un certificat
1354
1354
if [ " $GENERATE_CERT " = true ]; then
1355
1355
echo -e " 🔐 Generate SSL certificat ..."
1356
+ # Initialiser les variables DNS
1357
+ DNS_PROVIDER=" "
1358
+ DNS_API_KEY=" "
1356
1359
generate_certificate " $DOMAIN_NAMES " " $CERT_EMAIL " " $DNS_PROVIDER " " $DNS_API_KEY "
1357
1360
1358
1361
# Vérifier que le certificat a été créé
@@ -2118,6 +2121,38 @@ generate_certificate() {
2118
2121
echo -e " \n 📧 Using default email: ${COLOR_YELLOW} $EMAIL ${CoR} "
2119
2122
fi
2120
2123
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
2121
2156
# Check if domain exists in NPM proxy hosts
2122
2157
echo -e " \n ${COLOR_CYAN} 🔍${CoR} Checking if domain exists in NPM..."
2123
2158
PROXY_RESPONSE=$( curl -s -X GET " $BASE_URL /nginx/proxy-hosts" \
@@ -2167,12 +2202,15 @@ generate_certificate() {
2167
2202
RESPONSE=$( curl -s -X GET " $BASE_URL /nginx/certificates" \
2168
2203
-H " Authorization: Bearer $( cat " $TOKEN_FILE " ) " )
2169
2204
2205
+ # Check for existing certificates
2206
+ BASE_DOMAIN=" ${DOMAIN# \*\. } "
2207
+
2170
2208
# 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 " \
2172
2210
' .[] | 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:])))
2176
2214
)' )
2177
2215
2178
2216
if [ -n " $EXISTING_CERT " ]; then
@@ -2325,27 +2363,42 @@ generate_certificate() {
2325
2363
echo -e " ${COLOR_CYAN} $0 --host-ssl-enable $DOMAIN_EXISTS ${CoR} "
2326
2364
fi
2327
2365
else
2328
-
2329
-
2330
2366
echo -e " \n ${COLOR_RED} ❌ Certificate generation failed!${CoR} "
2331
2367
ERROR_MSG=$( echo " $HTTP_BODY " | jq -r ' .error.message // "Unknown error"' )
2332
2368
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:"
2334
2380
echo -e " • Verify domain DNS records are properly configured"
2335
2381
echo -e " • Ensure domain is accessible via HTTP/HTTPS"
2336
2382
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 "
2346
2399
2347
2400
exit 1
2348
- fi
2401
+ fi
2349
2402
}
2350
2403
2351
2404
# ###############################
@@ -3356,7 +3409,7 @@ while [[ "$#" -gt 0 ]]; do
3356
3409
echo -e " Usage: ${COLOR_ORANGE} $0 --user-create <username> <password> <email>${CoR} "
3357
3410
echo -e " Example:"
3358
3411
echo -e " ${COLOR_GREEN} $0 --user-create john secretpass john@domain.com${CoR} \n"
3359
- exit 1
3412
+ exit 1
3360
3413
fi
3361
3414
3362
3415
USERNAME=" $1 "
@@ -3701,6 +3754,7 @@ while [[ "$#" -gt 0 ]]; do
3701
3754
echo -e " Usage: $0 --host-ssl-enable <host_id>"
3702
3755
exit 1
3703
3756
fi
3757
+ host_enable_ssl " $HOST_ID "
3704
3758
;;
3705
3759
--host-ssl-disable)
3706
3760
shift
@@ -3711,7 +3765,7 @@ while [[ "$#" -gt 0 ]]; do
3711
3765
echo -e " \n ⛔ ${COLOR_RED} The --host-ssl-disable option requires a host 🆔.${CoR} "
3712
3766
exit 1
3713
3767
fi
3714
- DISABLE_SSL=true
3768
+ host_disable_ssl " $HOST_ID "
3715
3769
;;
3716
3770
--generate-cert)
3717
3771
shift
0 commit comments