Browse Source

add scripts to use IONOS DNS API

pull/730/head
Thomas Mieslinger 4 years ago
parent
commit
63d8206794
3 changed files with 86 additions and 0 deletions
  1. +9
    -0
      dns_scripts/DNS_IONOS.md
  2. +54
    -0
      dns_scripts/dns_add_ionos
  3. +23
    -0
      dns_scripts/dns_del_ionos

+ 9
- 0
dns_scripts/DNS_IONOS.md View File

@ -0,0 +1,9 @@
# Do DNS-01 verification using IONOS DNS API
The getting started guide explains how to obtain API Keys https://developer.hosting.ionos.de/docs/getstarted
All API Documentation can be found here https://developer.hosting.ionos.de/docs/dns
JSON processing in bash is ... hard. So I choose `jq` to do the heavylifting. Other authors choose python so if
you think I did a bad decision feel free to implement this whith python/perl/ruby...

+ 54
- 0
dns_scripts/dns_add_ionos View File

@ -0,0 +1,54 @@
#!/usr/bin/bash
#
# Called as
#
# eval "${DNS_ADD_COMMAND}" "${lower_d}" "${auth_key}"
#
# See https://developer.hosting.ionos.de/docs/getstarted how to generate
# an API Key consisting of prefix and key
#
# see DNS API Doc here https://developer.hosting.ionos.de/docs/dns
#
API_KEY="X-API-Key: <prefix>.<key>"
API_URL="https://api.hosting.ionos.com/dns/v1"
# TODO: check $1,$2 not empty
DNS_RR=$1
DNS_SECRET=$2
# get zone id:
curl -s -X GET "$API_URL/zones" -H "accept: application/json" -H "Content-Type: application/json" -H "$API_KEY" \
| jq -r 'map([.name, .id] | join (";")) | .[]' >/tmp/$$.zones
ZONE=$DNS_RR
do=true
while $do; do
ZONE_ID=$(awk -F\; '/^'"$ZONE"';/{print $2}' </tmp/$$.zones)
if [ -z "$ZONE_ID" ]; then
ZONE=$(echo "$ZONE" | cut -d'.' -f2-)
# check that it has at minimum one '.'. This check is incomplete
# when dealing with .co.nz etc Zones
DOTS=$(echo "$ZONE" | awk -F. '{ print NF -1 }')
if [ $DOTS -le 0 ]; then
echo "No ZoneID found for $1"
echo "Zones found with API"
cat /tmp/$$.zones
rm -f /tmp/$$.zones
exit 1
fi
else
break
do=false # Never reached
fi
done
# create record
curl -X POST "$API_URL/zones/$ZONE_ID/records" -H "accept: application/json" -H "Content-Type: application/json" -H "$API_KEY" -d '[ { "name": "_acme-challenge.'$DNS_RR'", "type": "TXT", "content": "'$DNS_SECRET'", "ttl": 60, "prio": 100, "disabled": false } ]'
rm -f /tmp/$$.zones

+ 23
- 0
dns_scripts/dns_del_ionos View File

@ -0,0 +1,23 @@
#!/usr/bin/bash
#
# Called as
#
# eval "${DNS_DEL_COMMAND}" "${lower_d}" "${auth_key}"
#
# See https://developer.hosting.ionos.de/docs/getstarted how to generate
# an API Key consisting of prefix and key
#
# see DNS API Doc here https://developer.hosting.ionos.de/docs/dns
#
API_KEY="X-API-Key: <prefix>.<key>"
API_URL="https://api.hosting.ionos.com/dns/v1"
# get zone id:
ZONE_ID=$(curl -s -X GET "$API_URL/zones" -H "accept: application/json" -H "Content-Type: application/json" -H "$API_KEY" | jq -r '.[].id')
RECORD_ID=$(curl -s -X GET "$API_URL/zones/$ZONE_ID?recordName=_acme-challenge.$1&recordType=TXT" -H "$API_KEY" -H "Accept: application/json" | jq -r '.["records"][]["id"]')
# delete record
curl -X DELETE "$API_URL/zones/$ZONE_ID/records/$RECORD_ID" -H "accept: application/json" -H "Content-Type: application/json" -H "$API_KEY"

Loading…
Cancel
Save