Last active
May 14, 2024 21:35
-
-
Save cmer81/9bea1c1580539005efd1e765fb55f2ac to your computer and use it in GitHub Desktop.
dynamic dns IPV6 script for Synology
This file contains 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
#!/bin/sh | |
# cloudflareddns6.sh - dynamic dns IPV6 updater module for Synology | |
# | |
# Author: | |
# Cedric Mercier | |
# | |
# Version: | |
# 0.1 | |
# | |
# Description: | |
# copy to /homedirectory-USER/cloudflaredns6.sh | |
# make executable (chmod +x) | |
# add the following entry to task scheduler | |
# | |
# | |
# (note that URL is not actually used, DSM will pass us the variables) | |
# run a rec_load_all query to get the record id | |
# (see https://www.cloudflare.com/docs/client-api.html) | |
# | |
# Changelog: | |
# 0.2: | |
# - Simplified this thing to its most basic requirements (curl + logging) | |
# - Now either returns 'good' or the result (no checking for cases -- the log was always more useful anyway!) | |
# | |
# Based on Brian Schmidt Pedersen (http://blog.briped.net) gratisdns.sh | |
# TODO | |
# read addition parameters from cloudflare api calls | |
# | |
# these variables are passed by DSM | |
# username is your email | |
__USERNAME__="<YOUREMAIL>" | |
# password is your cloudflare API key | |
__PASSWORD__="<YOURAPIKEY>" | |
__HOSTNAME__="<YOURDOMAIM>" | |
__MYIP__="$(/sbin/ip -6 addr | grep inet6 | awk -F '[ \t]+|/' '{print $3}' | grep -v ^::1 | grep -v ^fe80)" | |
# log location | |
__LOGFILE__="/var/log/cloudflareddns.log" | |
# additional parameters needed for CloudFlare | |
__RECTYPE6__="AAAA" | |
__RECID__="<YOUR-REC_ID>" | |
__RECNAME__="<YOUR-SUBDOMAIN>" | |
__TTL__="1" | |
__SERVICEMODE__="0" | |
log() { | |
__LOGTIME__=$(date +"%b %e %T") | |
if [ "${#}" -lt 1 ]; then | |
false | |
else | |
__LOGMSG__="${1}" | |
fi | |
if [ "${#}" -lt 2 ]; then | |
__LOGPRIO__=7 | |
else | |
__LOGPRIO__=${2} | |
fi | |
logger -p ${__LOGPRIO__} -t "$(basename ${0})" "${__LOGMSG__}" | |
echo "${__LOGTIME__} $(basename ${0}) (${__LOGPRIO__}): ${__LOGMSG__}" >> ${__LOGFILE__} | |
} | |
__URL__="https://www.cloudflare.com/api_json.html?a=rec_edit&tkn=${__PASSWORD__}&email=${__USERNAME__}&z=${__HOSTNAME__}&type=${__RECTYPE6__}&id=${__RECID__}&name=${__RECNAME__}&content=${__MYIP__}&ttl=${__TTL__}&service_mode=${__SERVICEMODE__}" | |
# Update DNS record: | |
log "Updating with ${__MYIP__}..." 7 | |
__RESPONSE__=$(curl --silent "${__URL__}") | |
# Strip the result element from response json | |
__RESULT__=$(echo ${__RESPONSE__} | grep -o -E .result.:.[A-z]+.) | |
case ${__RESULT__} in | |
'"result":"success"') | |
__STATUS__='good' | |
true | |
;; | |
*) | |
__STATUS__="${__RESULT__}" | |
log "__RESPONSE__=${__RESPONSE__}" 5 | |
false | |
;; | |
esac | |
log "Status: ${__STATUS__}" 6 | |
printf "%s" "${__STATUS__}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment