Skip to content

Commit c9d53ca

Browse files
authored
Add some loops due to 403 errors durring LE request in some random cases (hestiacp#4622)
* Make changes * Add loop in here * Fix bug * test * Prevent loop taking to become infinite * Don't use loop
1 parent 15afcef commit c9d53ca

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

bin/v-add-letsencrypt-domain

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ for identifier in $(echo $domain,$aliases | tr ',' '\n' | sort -u); do
237237
done
238238
payload=$(echo "$payload" | sed "s/,$//")
239239
payload=$payload']}'
240+
240241
answer=$(query_le_v2 "$url" "$payload" "$nonce")
241242
nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \ | tr -d '\r\n')
242243
authz=$(echo "$answer" | grep "acme/authz" | cut -f2 -d '"')
243244
finalize=$(echo "$answer" | grep 'finalize":' | cut -f4 -d '"')
244245
status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f2 -d ' ')
245246
order=$(echo -e "$answer" | grep -i location | cut -f2 -d \ | tr -d '\r\n')
246-
247247
debug_log "Step 2" "- status: ${status}\n- nonce: ${nonce}\n- authz: ${authz}\n- finalize: ${finalize}\n- payload: ${payload}\n- answer: ${answer}\n order: ${order}"
248248

249249
if [[ "$status" -ne 201 ]]; then
@@ -378,12 +378,23 @@ for auth in $authz; do
378378
# Doing pol check on status
379379
i=1
380380
while [ "$validation" = 'pending' ]; do
381-
payload='{}'
382-
answer=$(query_le_v2 "$url" "$payload" "$nonce")
383-
validation=$(echo "$answer" | grep -A1 $proto | tail -n1 | cut -f4 -d \")
384-
nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \ | tr -d '\r\n')
385-
status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
386-
details=$(echo "$answer" | grep detail | cut -f 1 -d ',' | cut -f 2-4 -d ':' | cut -f 2 -d '"')
381+
i=0
382+
while true; do
383+
payload='{}'
384+
answer=$(query_le_v2 "$url" "$payload" "$nonce")
385+
validation=$(echo "$answer" | grep -A1 $proto | tail -n1 | cut -f4 -d \")
386+
nonce=$(echo "$answer" | grep -i nonce | cut -f2 -d \ | tr -d '\r\n')
387+
status=$(echo "$answer" | grep HTTP/ | tail -n1 | cut -f 2 -d ' ')
388+
details=$(echo "$answer" | grep detail | cut -f 1 -d ',' | cut -f 2-4 -d ':' | cut -f 2 -d '"')
389+
if [[ $(echo "$answer" | grep addressesResolved) != "" ]]; then
390+
break
391+
fi
392+
i=$((i + 1))
393+
if ((i > 30)); then
394+
break
395+
fi
396+
sleep 2
397+
done
387398

388399
debug_log "Step 5" "- status: ${status}\n- url: ${url}\n- nonce: ${nonce}\n- validation: ${validation}\n- details: ${details}\n- answer: ${answer}"
389400

0 commit comments

Comments
 (0)