Browse Source

Add dns scripts for Dynu.com

pull/618/head
Tim Kimber 5 years ago
parent
commit
92673dae6e
No known key found for this signature in database GPG Key ID: 3E1804964E76BD18
2 changed files with 131 additions and 0 deletions
  1. +68
    -0
      dns_scripts/dns_add_dynu
  2. +63
    -0
      dns_scripts/dns_del_dynu

+ 68
- 0
dns_scripts/dns_add_dynu View File

@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Need to add your API key below or set as env variable
apikey=${DYNU_API_KEY:-''}
# This script adds a token to dynu.com DNS for the ACME challenge
# usage dns_add_dynu "domain name" "token"
# return codes are;
# 0 - success
# 1 - error in input
# 2 - error within internal processing
# 3 - error in result ( domain not found in dynu.com etc)
fulldomain="${1}"
token="${2}"
API='https://api.dynu.com/v2/dns'
# Check initial parameters
if [[ -z "$fulldomain" ]]; then
echo "DNS script requires full domain name as first parameter"
exit 1
fi
if [[ -z "$token" ]]; then
echo "DNS script requires challenge token as second parameter"
exit 1
fi
curl_params=( -H "accept: application/json" -H "API-Key: $apikey" -H 'Content-Type: application/json' )
# Get domain id
resp=$(curl --silent "${curl_params[@]}" -X GET "$API")
# Match domain id
re="\"id\":([^,]*),\"name\":\"getssl-testing.freeddns.org\""
if [[ "$resp" =~ $re ]]; then
domain_id="${BASH_REMATCH[1]}"
fi
if [[ -z "$domain_id" ]]; then
echo 'Domain name not found on your Dynu account'
exit 3
fi
# Check for existing _acme-challenge TXT record
resp=$(curl --silent "${curl_params[@]}" -X GET "${API}/record/_acme-challenge.${fulldomain}?recordType=TXT")
re="\"id\":([^,]*)"
if [[ "$resp" =~ $re ]]; then
record_id="${BASH_REMATCH[1]}"
fi
if [[ -z "$record_id" ]]; then
# Add new TXT challenge record
resp=$(curl --silent \
"${curl_params[@]}" \
-X POST "${API}/${domain_id}/record" \
--data "{\"nodeName\":\"_acme-challenge\",\"recordType\":\"TXT\",\"textData\":\"$token\"}")
else
resp=$(curl --silent \
"${curl_params[@]}" \
-X POST "${API}/${domain_id}/record/${record_id}" \
--data "{\"nodeName\":\"_acme-challenge\",\"recordType\":\"TXT\",\"textData\":\"$token\"}")
fi
# If adding record failed (exception:) then print error message
if [[ "${resp// }" == *'"exception"'* ]]; then
echo "Error: DNS challenge not added: unknown error - ${resp}"
exit 3
fi

+ 63
- 0
dns_scripts/dns_del_dynu View File

@ -0,0 +1,63 @@
#!/usr/bin/env bash
# Need to add your API key below or set as env variable
apikey=${DYNU_API_KEY:-''}
# This script deletes the _acme-challenge TXT record from the dynu.com DNS entry for the domain
# usage dns_del_dynu "domain name"
# return codes are;
# 0 - success
# 1 - error in input
# 2 - error within internal processing
# 3 - error in result ( domain not found in dynu.com etc)
fulldomain="${1}"
API='https://api.dynu.com/v2/dns'
# Check initial parameters
if [[ -z "$fulldomain" ]]; then
echo "DNS script requires full domain name as first parameter"
exit 1
fi
if [[ -z "$apikey" ]]; then
echo "DNS script requires an apikey to be set"
exit 1
fi
curl_params=( -H "accept: application/json" -H "API-Key: $apikey" -H 'Content-Type: application/json' )
# Get domain id
resp=$(curl --silent "${curl_params[@]}" -X GET "$API")
# Match domain id
re="\"id\":([^,]*),\"name\":\"getssl-testing.freeddns.org\""
if [[ "$resp" =~ $re ]]; then
domain_id="${BASH_REMATCH[1]}"
fi
if [[ -z "$domain_id" ]]; then
echo 'Domain name not found on your Dynu account'
exit 3
fi
# Find existing _acme-challenge TXT record
resp=$(curl --silent "${curl_params[@]}" -X GET "${API}/record/_acme-challenge.${fulldomain}?recordType=TXT")
re="\"id\":([^,]*)"
if [[ "$resp" =~ $re ]]; then
record_id="${BASH_REMATCH[1]}"
fi
if [[ -z "$record_id" ]]; then
echo "No _acme-challenge TXT record found for $fulldomain"
exit 3
fi
resp=$(curl --silent \
"${curl_params[@]}" \
-X DELETE "${API}/${domain_id}/record/${record_id}")
# If adding record failed (exception:) then print error message
if [[ "${resp// }" == *'"exception"'* ]]; then
echo "Error: DNS challenge not added: unknown error - ${resp}"
exit 3
fi

Loading…
Cancel
Save