@ -1,8 +1,8 @@
#!/bin/bash
#!/bin/bash
# Copyright (C) 2017,2018) Timothe Litt litt at acm _dot org
# Copyright (C) 2017,2018 Timothe Litt litt at acm _dot org
VERSION="1.0.2 "
VERSION="1.0.3 "
PROG="`basename $0`"
PROG="`basename $0`"
# This script is used to update TXT records in GoDaddy DNS server
# This script is used to update TXT records in GoDaddy DNS server
@ -31,6 +31,7 @@ DEBUG="$GODADDY_DEBUG"
while getopts 'dhj:k:s:t:qv' opt; do
while getopts 'dhj:k:s:t:qv' opt; do
case $opt in
case $opt in
b) GODADDY_BASE="$OPTARG" ;;
d) DEBUG="Y" ;;
d) DEBUG="Y" ;;
j) JSON="$OPTARG" ;;
j) JSON="$OPTARG" ;;
k) GODADDY_KEY="$OPTARG" ;;
k) GODADDY_KEY="$OPTARG" ;;
@ -72,6 +73,9 @@ Arguments:
For minimal trace output (to override -q), define GODADDY_TRACE="y".
For minimal trace output (to override -q), define GODADDY_TRACE="y".
Options
Options
-b Domain name(s) in which challenge records are stored
E.g. often, www.example.net is stored in example.net.
Default from GODADDY_BASE
-d Provide debugging output - all requests and responses
-d Provide debugging output - all requests and responses
-h This help.
-h This help.
-j: Location of JSON.sh Default `dirname $0`/JSON.sh, or
-j: Location of JSON.sh Default `dirname $0`/JSON.sh, or
@ -84,6 +88,7 @@ Options
All output, except for this help text, is to stderr.
All output, except for this help text, is to stderr.
Environment variables
Environment variables
GODADDY_BASE Domain name(s) in which challenge records are stored
GODADDY_JSON location of the JSOH.sh script
GODADDY_JSON location of the JSOH.sh script
GODADDY_KEY default API key
GODADDY_KEY default API key
GODADDY_SCRIPT location of this script, default location of JSON.sh
GODADDY_SCRIPT location of this script, default location of JSON.sh
@ -92,7 +97,7 @@ Environment variables
GODADDY_TFILE appends protocol trace to file. Overrides -t
GODADDY_TFILE appends protocol trace to file. Overrides -t
BUGS
BUGS
Due to a limitation of the gOdADDY API, deleting the last TXT record
Due to a limitation of the GoDaddy API, deleting the last TXT record
would be too risky for my taste. So in that case, I replace it with
would be too risky for my taste. So in that case, I replace it with
_dummy.record_.domain. TXT "Ihis record is not used". This record is
_dummy.record_.domain. TXT "Ihis record is not used". This record is
not automatically deleted by this script, though it's perfectly OK to
not automatically deleted by this script, though it's perfectly OK to
@ -207,7 +212,23 @@ if [ "$op" = "add" ]; then
while [[ "$domain" =~ [^.]+\.[^.]+ ]]; do
while [[ "$domain" =~ [^.]+\.[^.]+ ]]; do
url="$API/$domain/records/TXT/$name"
reqname="$name"
# The API doesn't trim the base domain from the name (it used to)
# If specified, remove any listed base.
if [ -n "$GODADDY_BASE" ]; then
for GDB in $GODADDY_BASE; do
gdb="`echo "$GDB" | sed -e's/\\.$//;s/\\./\\\\./g;'`"
gdb="^(.+)\\.$gdb\\.?$"
if [[ "$name" =~ $gdb ]]; then
reqname="${BASH_REMATCH[1]}"
break;
fi
done
else
eval 'reqname="$''{name%'"'.$domain.'}"'"'
fi
url="$API/$domain/records/TXT/$reqname"
request='[{"data":"'$data'","ttl":'$ttl'}]'
request='[{"data":"'$data'","ttl":'$ttl'}]'
[ -n "$DEBUG" ] && cat >&2 <<EOF
[ -n "$DEBUG" ] && cat >&2 <<EOF
@ -216,7 +237,6 @@ Add request to: $url
$request"
$request"
--------
--------
EOF
EOF
result="$(curl -i -s -X PUT -d "$request" --config - "$url" <<EOF
result="$(curl -i -s -X PUT -d "$request" --config - "$url" <<EOF
header = "Content-Type: application/json"
header = "Content-Type: application/json"
header = "$authhdr"
header = "$authhdr"
@ -333,7 +353,7 @@ Old TXT RRSET:
$current
$current
EOF
EOF
# Remove the desired record. The name must be relative.
# Remove the desired record. The name must be relative. Order varies.
eval 'name="$''{name%'"'.$domain.'}"'"'
eval 'name="$''{name%'"'.$domain.'}"'"'
@ -341,6 +361,10 @@ match="$(printf '"name":"%s","data":"%s","ttl":' "$name" "$data")"
cmd="$(printf 'echo %s%s%s | grep -v %s%s%s' "'" "$current" "'" "'" "$match" "'")"
cmd="$(printf 'echo %s%s%s | grep -v %s%s%s' "'" "$current" "'" "'" "$match" "'")"
eval 'new="$('"$cmd"')"'
eval 'new="$('"$cmd"')"'
match="$(printf '"data":"%s","name":"%s","ttl":' "$data" "$name")"
cmd="$(printf 'echo %s%s%s | grep -v %s%s%s' "'" "$current" "'" "'" "$match" "'")"
eval 'new="$('"$cmd"')"'
if [ "$new" = "$base" ]; then
if [ "$new" = "$base" ]; then
[ -n "$VERB" ] && echo "$domain: $name TXT \"$data\" does not exist" >&2
[ -n "$VERB" ] && echo "$domain: $name TXT \"$data\" does not exist" >&2
exit 1 # Intent was to change DNS, so this is an error
exit 1 # Intent was to change DNS, so this is an error