Created
March 4, 2021 00:34
-
-
Save moqmar/89733357a04058cde9caa73d8dd26009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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