100100
101101
102102
103+ # Dump debug info
104+ debug_log () {
105+ echo -e " \n==[${1} ]==\n${2} \n" >> " $log_file "
106+ }
107+
103108# ----------------------------------------------------------#
104109# Action #
105110# ----------------------------------------------------------#
106111
112+
113+
114+
107115# Generate correct variables for mail domain SSL certificates
108116if [ ! -z " $mail " ]; then
109117 root_domain=$domain
110118 domain=" mail.$root_domain "
111119 aliases=" $WEBMAIL_ALIAS .$root_domain "
112120fi
113121
122+ log_file=" /var/log/hestia/LE-${user} -${domain} -$( date +%Y%m%d-%H%M%S) .log"
123+ touch " $log_file "
124+ chmod 600 " $log_file "
125+
126+ echo -e " \n\n=============================
127+ WEB_SYSTEM: ${WEB_SYSTEM}
128+ PROXY_SYSTEM: ${PROXY_SYSTEM}
129+ user: ${user}
130+ domain: ${domain}
131+ " >> " $log_file "
132+
114133# Registering LetsEncrypt user account
115134$BIN /v-add-letsencrypt-user $user
116135if [ " $? " -ne 0 ]; then
@@ -134,6 +153,12 @@ else
134153 proto=" http-01"
135154fi
136155
156+ echo -e "
157+ - aliases: ${aliases}
158+ - proto: ${proto}
159+ - wildcard: ${wildcard}
160+ " >> " $log_file "
161+
137162# Check if dns records exist for requested domain/aliases
138163if [ " $proto " = " http-01" ]; then
139164 for identifier in $( echo $domain ,$aliases | tr ' ,' ' \n' | sort -u) ; do
164189answer= $( curl -s -I " $LE_API /directory" )
165190nonce= $( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
166191status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
192+
193+ debug_log " Step 1" " - status: ${status} \n- nonce: ${nonce} \n- answer: ${answer} "
194+
167195if [[ " $status " -ne 200 ]]; then
168196 # Delete DNS CAA record
169197 if [ ! -z " $DNS_SYSTEM " ]; then
@@ -192,6 +220,9 @@ nonce=$(echo "$answer" |grep -i nonce |cut -f2 -d \ |tr -d '\r\n')
192220authz= $( echo " $answer " | grep " acme/authz" | cut -f2 -d ' "' )
193221finalize= $( echo " $answer " | grep ' finalize":' | cut -f4 -d ' "' )
194222status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f2 -d ' ' )
223+
224+ debug_log " Step 2" " - status: ${status} \n- nonce: ${nonce} \n- authz: ${authz} \n- finalize: ${finalize} \n- payload: ${payload} \n- answer: ${answer} "
225+
195226if [[ " $status " -ne 201 ]]; then
196227 # Delete DNS CAA record
197228 if [ ! -z " $DNS_SYSTEM " ]; then
@@ -212,6 +243,9 @@ for auth in $authz; do
212243 token=$( echo " $answer " | grep -A3 $proto | grep token | cut -f 4 -d \" )
213244 nonce=$( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
214245 status=$( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
246+
247+ debug_log " Step 3" " - status: ${status} \n- nonce: ${nonce} \n- url: ${url} \n- token: ${token} \n- answer: ${answer} "
248+
215249 if [[ " $status " -ne 200 ]]; then
216250 # Delete DNS CAA record
217251 if [ ! -z " $DNS_SYSTEM " ]; then
@@ -303,6 +337,9 @@ for auth in $authz; do
303337 nonce=$( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
304338 status=$( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
305339 details=$( echo " $answer " | grep detail | cut -f 1 -d ' ,' | cut -f 2-4 -d ' :' | cut -f 2 -d ' "' )
340+
341+ debug_log " Step 5" " - status: ${status} \n- nonce: ${nonce} \n- validation: ${validation} \n- details: ${details} \n- answer: ${answer} "
342+
306343 if [[ " $status " -ne 200 ]]; then
307344 # Delete DNS CAA record
308345 if [ ! -z " $DNS_SYSTEM " ]; then
@@ -315,6 +352,7 @@ for auth in $authz; do
315352 fi
316353 fi
317354 fi
355+ debug_log " Abort Step 5" " => Wrong status"
318356 check_result $E_CONNECT " Let's Encrypt validation status $status . Details: $details "
319357 fi
320358
@@ -331,6 +369,7 @@ for auth in $authz; do
331369 fi
332370 fi
333371 fi
372+ debug_log " Abort Step 5" " => Too many validation retries"
334373 check_result $E_CONNECT " Let's Encrypt domain validation timeout"
335374 fi
336375 sleep $(( i* 2 ))
@@ -362,6 +401,9 @@ answer=$(query_le_v2 "$finalize" "$payload" "$nonce")
362401nonce= $( echo " $answer " | grep -i nonce | cut -f2 -d \ | tr -d ' \r\n' )
363402status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
364403certificate= $( echo " $answer " | grep ' certificate":' | cut -f4 -d ' "' )
404+
405+ debug_log " Step 6" " - status: ${status} \n- nonce: ${nonce} \n- payload: ${payload} \n- certificate: ${certificate} \n- answer: ${answer} "
406+
365407if [[ " $status " -ne 200 ]]; then
366408 [ -d " $ssl_dir " ] && rm -rf " $ssl_dir "
367409 check_result $E_CONNECT " Let's Encrypt finalize bad status $status "
370412# Downloading signed certificate / STEP 7
371413answer= $( query_le_v2 " $certificate " " " " $nonce " " $ssl_dir /$domain .pem" )
372414status= $( echo " $answer " | grep HTTP/ | tail -n1 | cut -f 2 -d ' ' )
415+
416+ debug_log " Step 7" " - status: ${status} \n- answer: ${answer} "
417+ debug_log " CERT DIR" " $( ls -las " $ssl_dir /" ) "
418+ debug_log " CERT PEM" " $( cat " $ssl_dir /$domain .pem" ) "
419+
420+
373421if [[ " $status " -ne 200 ]]; then
374422 [ -d " $ssl_dir " ] && rm -rf " $ssl_dir "
375423 check_result $E_NOTEXIST " Let's Encrypt downloading signed cert failed status:$status "
@@ -384,10 +432,13 @@ ca_end=$(grep -n "BEGIN" $ssl_dir/$domain.pem |tail -n1 |cut -f 1 -d :)
384432ca_end= $(( pem_lines - crt_end + 1 ))
385433tail -n $ca_end $ssl_dir /$domain .pem > $ssl_dir /$domain .ca
386434
435+ debug_log " CERT CRT" " $( cat " $ssl_dir /$domain .crt" ) "
436+ debug_log " CERT CA-1" " $( cat " $ssl_dir /$domain .ca" ) "
387437# Temporary fix for double "END CERTIFICATE"
388438if [[ $( head -n 1 $ssl_dir /$domain .ca) = " -----END CERTIFICATE-----" ]]; then
389439 sed -i ' 1,2d' $ssl_dir /$domain .ca
390440fi
441+ debug_log " CERT CA-2" " $( cat " $ssl_dir /$domain .ca" ) "
391442
392443# Rename certs for mail
393444if [ ! -z " $mail " ]; then
@@ -467,4 +518,7 @@ send_notice 'LETSENCRYPT' "$domain SSL has been installed successfully"
467518# Logging
468519log_event " $OK " " $ARGUMENTS "
469520
521+ # Cleanup debug since the SSL was issues succesfully
522+ rm -f " $log_file "
523+
470524exit
0 commit comments