autodetect API by length of API key
This commit is contained in:
parent
6c08ad807c
commit
de91e17240
4 changed files with 61 additions and 16 deletions
35
petrified
35
petrified
|
|
@ -38,9 +38,18 @@ while getopts ":c:" opt; do
|
|||
done
|
||||
|
||||
## v2 API - How to update DNS - DDNS_KEY is unique per domain
|
||||
DDNS_URL=https://sync.afraid.org/u/
|
||||
DDNS_URL=""
|
||||
DDNS_KEY=""
|
||||
|
||||
## From Josh, v1 key is variable but v2 is fixed length @24char. When set
|
||||
## to 0 (auto) the length of the DDNS_KEY will be used to choose which API
|
||||
## endpoint, otherwise specify 1 (API v1) or 2 (API v2) directly
|
||||
DDNS_API=0
|
||||
|
||||
## API URL endpoints, no trailing slashes
|
||||
DDNS_V1U=https://freedns.afraid.org/dynamic/update.php
|
||||
DDNS_V2U=https://sync.afraid.org/u
|
||||
|
||||
## Which URL to use to get an IP
|
||||
# IPv4 icanhazip (http://major.io/icanhazip-com-faq/)
|
||||
DDNS_CHECK="http://4.icanhazip.com"
|
||||
|
|
@ -106,6 +115,28 @@ fi
|
|||
if [[ -z "${DDNS_KEY}" ]]; then
|
||||
echo "DDNS_KEY must be configured, exiting."
|
||||
exit 1
|
||||
else
|
||||
# Set the API version endpoint, IP added later
|
||||
case ${DDNS_API} in
|
||||
0)
|
||||
# From Josh, v2 is fixed @24 but v1 is variable (typically >24)
|
||||
if [[ ${#DDNS_KEY} -ne 24 ]]; then
|
||||
DDNS_URL="${DDNS_V1U}?${DDNS_KEY}&address="
|
||||
else
|
||||
DDNS_URL="${DDNS_V2U}/${DDNS_KEY}/?ip="
|
||||
fi
|
||||
;;
|
||||
1)
|
||||
DDNS_URL="${DDNS_V1U}?${DDNS_KEY}&address="
|
||||
;;
|
||||
2)
|
||||
DDNS_URL="${DDNS_V2U}/${DDNS_KEY}/?ip="
|
||||
;;
|
||||
*)
|
||||
echo "DDNS_API must be 0, 1 or 2; exiting."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Make sure that PET_LOG will work if required
|
||||
|
|
@ -219,7 +250,7 @@ fi
|
|||
# If they don't match, tell upstream
|
||||
__UPDATED=0
|
||||
if [[ "${OLDIP}" != "${NEWIP}" ]]; then
|
||||
UPDURL="${DDNS_URL}${DDNS_KEY}/?ip=${NEWIP}"
|
||||
UPDURL="${DDNS_URL}${NEWIP}"
|
||||
RESULT=$(curl -m ${CURL_WAIT} -sk "${UPDURL}" 2>/dev/null)
|
||||
logmsg "${RESULT}"
|
||||
# "Updated foo from 1.2.3.4 to 5.6.7.8"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue