#!/bin/sh
# DNS challenge present script for dnsexit.com
# lego exec provider calls: present [--] <fqdn> <value>  (RAW mode: present -- <domain> <token> <keyAuth>)

API_KEY="${DNSEXIT_API_KEY}"
DOMAIN="${DNSEXIT_DOMAIN}"

[ "${1}" = "present" ] && shift
[ "${1}" = "--" ] && shift
FQDN="${1%.}"
TXT_VALUE="${2}"

echo "dns-present: name=${FQDN} value=${TXT_VALUE}" >&2

wget -q -O - \
  --header='Content-type:application/json' \
  --post-data="{
    \"apikey\": \"${API_KEY}\",
    \"domain\": \"${DOMAIN}\",
    \"add\": [
      {
        \"type\": \"TXT\",
        \"name\": \"${FQDN}\",
        \"content\": \"${TXT_VALUE}\",
        \"ttl\": 120,
        \"overwrite\": true
      }
    ]
  }" \
  https://api.dnsexit.com/dns/

sleep 30
