2017-06-27 13:21:39 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
#Created by RaidenII, to use DuckDNS's API to add/remove text records
|
|
|
|
#06/27/2017
|
|
|
|
|
|
|
|
# Currently only support single domain access
|
2017-06-27 19:28:10 +00:00
|
|
|
# Due to the fact that DuckDNS uses StartSSL as cert provider, --insecure must be used with acme.sh
|
2017-06-27 13:21:39 +00:00
|
|
|
|
2017-06-27 19:28:10 +00:00
|
|
|
DuckDNS_API="https://www.duckdns.org/update"
|
2017-07-01 12:14:52 +00:00
|
|
|
API_Params="domains=$DuckDNS_Domain&token=$DuckDNS_Token"
|
2017-06-27 13:21:39 +00:00
|
|
|
|
|
|
|
######## Public functions #####################
|
|
|
|
|
|
|
|
#Usage: dns_duckdns_add _acme-challenge.domain.duckdns.org "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
|
|
|
dns_duckdns_add() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
|
|
|
# We'll extract the domain/username from full domain
|
2017-07-01 12:18:12 +00:00
|
|
|
DuckDNS_Domain=$(echo "$fulldomain" | _lower_case | _egrep_o '.[^.]*.duckdns.org' | cut -d . -f 2)
|
2017-06-27 13:21:39 +00:00
|
|
|
|
2017-07-01 12:14:52 +00:00
|
|
|
if [ -z "$DuckDNS_Domain" ]; then
|
2017-06-27 13:21:39 +00:00
|
|
|
_err "Error extracting the domain."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2017-07-01 12:14:52 +00:00
|
|
|
if [ -z "$DuckDNS_Token" ]; then
|
|
|
|
DuckDNS_Token=""
|
2017-06-27 13:21:39 +00:00
|
|
|
_err "The token for your DuckDNS account is necessary."
|
|
|
|
_err "You can look it up in your DuckDNS account."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Now save the credentials.
|
2017-07-01 12:14:52 +00:00
|
|
|
_saveaccountconf DuckDNS_Domain "$DuckDNS_Domain"
|
|
|
|
_saveaccountconf DuckDNS_Token "$DuckDNS_Token"
|
2017-06-27 13:21:39 +00:00
|
|
|
|
|
|
|
# Unfortunately, DuckDNS does not seems to support lookup domain through API
|
|
|
|
# So I assume your credentials (which are your domain and token) are correct
|
|
|
|
# If something goes wrong, we will get a KO response from DuckDNS
|
|
|
|
|
|
|
|
# Now add the TXT record to DuckDNS
|
|
|
|
_info "Trying to add TXT record"
|
2017-06-29 19:43:58 +00:00
|
|
|
if _duckdns_rest GET "$API_Params&txt=$txtvalue" && [ "$response" = "OK" ]; then
|
2017-06-27 13:21:39 +00:00
|
|
|
_info "TXT record has been successfully added to your DuckDNS domain."
|
|
|
|
_info "Note that all subdomains under this domain uses the same TXT record."
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
_err "Errors happened during adding the TXT record."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#Usage: fulldomain txtvalue
|
|
|
|
#Remove the txt record after validation.
|
|
|
|
dns_duckdns_rm() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
|
|
|
# Now remove the TXT record from DuckDNS
|
2017-06-27 19:28:10 +00:00
|
|
|
_info "Trying to remove TXT record"
|
2017-06-29 19:43:58 +00:00
|
|
|
if _duckdns_rest GET "$API_Params&txt=&clear=true" && [ "$response" = "OK" ]; then
|
2017-06-27 13:21:39 +00:00
|
|
|
_info "TXT record has been successfully removed from your DuckDNS domain."
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
_err "Errors happened during removing the TXT record."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#################### Private functions below ##################################
|
|
|
|
|
2017-06-27 19:28:10 +00:00
|
|
|
#Usage: method URI
|
2017-06-27 13:21:39 +00:00
|
|
|
_duckdns_rest() {
|
|
|
|
method=$1
|
|
|
|
param="$2"
|
|
|
|
_debug param "$param"
|
|
|
|
url="$DuckDNS_API?$param"
|
|
|
|
_debug url "$url"
|
|
|
|
|
|
|
|
# DuckDNS uses GET to update domain info
|
2017-06-29 19:43:58 +00:00
|
|
|
if [ "$method" = "GET" ]; then
|
2017-06-27 13:21:39 +00:00
|
|
|
response="$(_get "$url")"
|
|
|
|
else
|
|
|
|
_err "Unsupported method"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2017-07-01 12:14:52 +00:00
|
|
|
_debug2 response "$response"
|
2017-06-27 13:21:39 +00:00
|
|
|
return 0
|
|
|
|
}
|