Skip to content

Commit

Permalink
Update handler-example.sh
Browse files Browse the repository at this point in the history
A full-fledged example based on dnyu API.
  • Loading branch information
C0deGyver authored May 29, 2019
1 parent 6fc5522 commit 847bc1a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions handler-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ case "$cmd" in
echo "key_path: ${key_path}" 1>&2
echo "port: ${port}" 1>&2
echo "json: ${cbot_json}" 1>&2
# the json below is from dynu's API you will need to change accordingly
curl -X POST https://api.dynu.com/v2/dns/<DNS-ID>/record -H "accept: application/json" -H "API-Key: <API-KEY>" \
-H "Content-Type: application/json" -d "{\"nodeName\":\"_acme-challenge\",\"recordType\":\"TXT\",\"ttl\":90,\"state\":true,\"group\":\"\",\"textData\":\"${validation}\"}"

# wait for the record to actually show up (the builtin time out is WAY too sort)
while true
do
recordset=$(dig _acme-challenge.<DOMAIN> TXT +short | tr -d "\"")
if [[ $recordset == ${validation} ]]
then
sleep 10s
break
else
sleep 1m
fi
done
echo "-----END PERFORM-----" 1>&2
;;
post-perform)
Expand All @@ -45,6 +61,9 @@ case "$cmd" in
echo "token: ${token}" 1>&2
echo "error: ${error}" 1>&2
echo "json: ${cbot_json}" 1>&2
recordset=$(curl -s -X GET https://api.dynu.com/v2/dns/<DNS-ID>/record -H "accept: application/json" -H "API-Key: <API-KEY>")
temp=$(echo "$recordset" | sed 's+{+\n+g' | grep "${validation}" | cut -d ":" -f 2 | cut -d "," -f 1)
curl -s -X DELETE https://api.dynu.com/v2/dns/<DNS-ID>/record/"${records[0]}" -H "accept: application/json" -H "API-Key: <API-KEY>"
echo "-----END CLEANUP-----" 1>&2
;;
post-cleanup)
Expand Down

0 comments on commit 847bc1a

Please sign in to comment.