Skip to content

Instantly share code, notes, and snippets.

@moqmar
Created March 4, 2021 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moqmar/89733357a04058cde9caa73d8dd26009 to your computer and use it in GitHub Desktop.
Save moqmar/89733357a04058cde9caa73d8dd26009 to your computer and use it in GitHub Desktop.
# OpenWRT custom Dynamic DNS script for the hosting.de API.
# Set the password to your API key and the domain to the full FQDN of the DNS entry you want to change.
# TODO: try different zone names - currently only the root domain can be used.
HOSTINGDE_ENDPOINT=https://secure.hosting.de
HOSTINGDE_APIKEY="$password"
DOMAIN="$__VALUE"
RECORD_TYPE=A
if [ "$use_ipv6" = "1" ]; then RECORD_TYPE=AAAA; fi
TTL=60
VALUE="$__IP"
echo "Getting zone..."
ZONE=$(curl -s --data-raw "{ \"authToken\": \"${HOSTINGDE_APIKEY}\", \"filter\": { \"field\": \"zoneNameUnicode\", \"value\": \"${DOMAIN}\" } }" "$HOSTINGDE_ENDPOINT/api/dns/v1/json/zonesFind")
if [ "$(echo "$ZONE" | jsonfilter -e '@.status')" != "success" ]; then
echo "Couldn't retrieve zone:"
echo "$ZONE"
exit 1
fi
ZONE_CONFIG=$(echo "$ZONE" | jsonfilter -e '@.response.data[0].zoneConfig')
RECORD_ID=$(echo "$ZONE" | jsonfilter -e '@.response.data[0].records[*]' | grep -F "\"name\": \"${DOMAIN}\"" | grep -F "\"type\": \"${RECORD_TYPE}\"" | jsonfilter -e '@.id')
echo "Updating zone..."
UPDATE=$(curl -s --data-raw "{ \"authToken\": \"${HOSTINGDE_APIKEY}\", \"zoneConfig\": ${ZONE_CONFIG}, \"recordsToModify\": [{ \"id\": \"${RECORD_ID}\", \"name\": \"${DOMAIN}\", \"type\": \"${RECORD_TYPE}\", \"content\": \"${VALUE}\", \"ttl\": ${TTL} }]}" "${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate")
if [ "$(echo "$UPDATE" | jsonfilter -e '@.status')" != "success" ] && [ "$(echo "$UPDATE" | jsonfilter -e '@.status')" != "pending" ]; then
echo "Couldn't update zone:"
echo "$UPDATE"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment