Changed API a little to split and pass domain in a compatible way
This commit is contained in:
parent
b2baa656b9
commit
0353a19ded
2 changed files with 47 additions and 21 deletions
|
@ -12,8 +12,8 @@ if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf" ]]; then
|
||||||
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf"
|
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$DIP_CUR_IP" ]] || [[ -z "$DIP_OLD_IP" ]] || [[ -z "$DIP_RECORD" ]]; then
|
if [[ -z "$DIP_CUR_IP" ]] || [[ -z "$DIP_OLD_IP" ]] || [[ -z "$DIP_RECORD" ]] || [[ -z "$DIP_DOMAIN" ]]; then
|
||||||
logerr "ERROR: Agent expects currentip, existingip, and record."
|
logerr "ERROR: Agent expects currentip, existingip, record and domain."
|
||||||
exit 98
|
exit 98
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -21,15 +21,30 @@ fi
|
||||||
|
|
||||||
_get_host_and_domain() {
|
_get_host_and_domain() {
|
||||||
local record=$1
|
local record=$1
|
||||||
|
local domain=$2
|
||||||
|
local hostname
|
||||||
|
|
||||||
hostname=${record%%.*}
|
if [[ -z "$record" ]] || [[ -z "$domain" ]]; then
|
||||||
domain=${record#*.}
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
hostname="${record%%."$domain"}"
|
||||||
|
|
||||||
|
if [[ -n "$hostname" ]]; then
|
||||||
|
DIP_RECORD="$hostname"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#hostname=${record%%.*}
|
||||||
|
#hostname="${record%%."$domain"}"
|
||||||
|
#domain=${record#*.}
|
||||||
|
|
||||||
if [[ -n "${agent_update_dns_namecheap_token[$domain]}" ]]; then
|
if [[ -n "${agent_update_dns_namecheap_token[$domain]}" ]]; then
|
||||||
token="${agent_update_dns_namecheap_token[$domain]}"
|
DIP_TOKEN="${agent_update_dns_namecheap_token["$domain"]}"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
logerr "ERROR: Password for $domain not found in agent configuration."
|
logerr "ERROR: Password for '$domain' not found in agent configuration."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -37,21 +52,21 @@ _get_host_and_domain() {
|
||||||
# Update and Check Response
|
# Update and Check Response
|
||||||
|
|
||||||
_update_dns_namecheap() {
|
_update_dns_namecheap() {
|
||||||
local dnsHostname=$1
|
local rec=$1
|
||||||
local dnsDomain=$2
|
local dom=$2
|
||||||
local dnsToken=$3
|
local pas=$3
|
||||||
local dnsIP=$4
|
local ip=$4
|
||||||
local result
|
local result
|
||||||
local errors
|
local errors
|
||||||
|
|
||||||
if result=$(curl -qs "https://dynamicdns.park-your-domain.com/update?host=${dnsHostname}&domain=${dnsDomain}&password=${dnsToken}&ip=${dnsIP}" | grep ErrCount); then
|
if result=$(curl -qs "https://dynamicdns.park-your-domain.com/update?host=${rec}&domain=${dom}&password=${pas}&ip=${ip}" | grep ErrCount); then
|
||||||
errors=$(grep -oPm1 "(?<=<ErrCount>)[^<]+" <<< "$result")
|
errors=$(grep -oPm1 "(?<=<ErrCount>)[^<]+" <<< "$result")
|
||||||
|
|
||||||
if [[ "$errors" -eq 0 ]]; then
|
if [[ "$errors" -eq 0 ]]; then
|
||||||
echo "DNS record ${dnsHostname}.${dnsDomain} updated successfully."
|
echo "DNS record ${rec}.${dom} updated successfully."
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echo "DNS record ${dnsHostname}.${dnsDomain} failed to update."
|
echo "DNS record ${rec}.${dom} failed to update."
|
||||||
return 96
|
return 96
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -62,16 +77,18 @@ _update_dns_namecheap() {
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
|
|
||||||
_get_host_and_domain "$DIP_RECORD" || return 99
|
_get_host_and_domain "$DIP_RECORD" "$DIP_DOMAIN" || exit 99
|
||||||
|
|
||||||
if valid_ipv4 "$DIP_CUR_IP"; then
|
if valid_ipv4 "$DIP_CUR_IP"; then
|
||||||
log "Updating Namecheap DNS IPv4 Record for ${hostname}.${domain}"
|
log "Updating Namecheap DNS IPv4 Record for ${DIP_RECORD}.${DIP_DOMAIN}"
|
||||||
_update_dns_namecheap "$hostname" "$domain" "$token" "${DIP_CUR_IP}"
|
_update_dns_namecheap "$DIP_RECORD" "$DIP_DOMAIN" "$DIP_TOKEN" "${DIP_CUR_IP}"
|
||||||
|
unset DIP_TOKEN
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if valid_ipv6 "$DIP_CUR_IP"; then
|
if valid_ipv6 "$DIP_CUR_IP"; then
|
||||||
log "Updating Namecheap DNS IPv6 Record for ${hostname}.${domain}"
|
log "Updating Namecheap DNS IPv6 Record for ${DIP_RECORD}.${DIP_DOMAIN}"
|
||||||
_update_dns_namecheap "$hostname" "$domain" "$token" "${DIP_CUR_IP}"
|
_update_dns_namecheap "$DIP_RECORD" "$DIP_DOMAIN" "$DIP_TOKEN" "${DIP_CUR_IP}"
|
||||||
|
unset DIP_TOKEN
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -271,6 +271,7 @@ run-hook() {
|
||||||
DIP_CUR_IP="$1" \
|
DIP_CUR_IP="$1" \
|
||||||
DIP_OLD_IP="$2" \
|
DIP_OLD_IP="$2" \
|
||||||
DIP_RECORD="$3" \
|
DIP_RECORD="$3" \
|
||||||
|
DIP_DOMAIN="$4" \
|
||||||
"$hook_script" "$@"
|
"$hook_script" "$@"
|
||||||
then
|
then
|
||||||
logerr "WARNING: Agent $(basename "$hook_script") had errors"
|
logerr "WARNING: Agent $(basename "$hook_script") had errors"
|
||||||
|
@ -285,9 +286,10 @@ run-update() {
|
||||||
local cip=$1
|
local cip=$1
|
||||||
local eip=$2
|
local eip=$2
|
||||||
local rec=$3
|
local rec=$3
|
||||||
|
local dom=$4
|
||||||
|
|
||||||
if [[ "$cip" != "$eip" ]]; then
|
if [[ "$cip" != "$eip" ]]; then
|
||||||
run-hook "${script_dir}/update.d" "$cip" "$eip" "$rec" || return $?
|
run-hook "${script_dir}/update.d" "$cip" "$eip" "$rec" "$dom" || return $?
|
||||||
else
|
else
|
||||||
log "No change detected"
|
log "No change detected"
|
||||||
fi
|
fi
|
||||||
|
@ -342,18 +344,25 @@ getCurrentIP() {
|
||||||
check-update() {
|
check-update() {
|
||||||
local iptype=$1
|
local iptype=$1
|
||||||
local record=$2
|
local record=$2
|
||||||
|
local domain
|
||||||
|
|
||||||
[[ -z "$iptype" ]] && return 1
|
[[ -z "$iptype" ]] && return 1
|
||||||
[[ -z "$record" ]] && return 1
|
[[ -z "$record" ]] && return 1
|
||||||
|
|
||||||
|
if [[ "$record" == *":"* ]]; then
|
||||||
|
domain="${record##*:}"
|
||||||
|
#record="${record%%."$domain"}"
|
||||||
|
record="${record%%:*}"
|
||||||
|
fi
|
||||||
|
|
||||||
getCurrentIP "$iptype" "$record"
|
getCurrentIP "$iptype" "$record"
|
||||||
local status=$?
|
local status=$?
|
||||||
|
|
||||||
case $status in
|
case $status in
|
||||||
0) if [[ "$currentip" != "$externalip" ]]; then
|
0) if [[ "$currentip" != "$externalip" ]]; then
|
||||||
log "Updates found: $externalip is not $currentip"
|
log "Updates found: $externalip is not $currentip"
|
||||||
log "Running Agents for $record"
|
log "Running Agents for $recordi${domain:+."$domain"}"
|
||||||
if run-update "$currentip" "$externalip" "$record"; then
|
if run-update "$currentip" "$externalip" "$record" "$domain"; then
|
||||||
log "Agents ran successfully"
|
log "Agents ran successfully"
|
||||||
else
|
else
|
||||||
logerr "WARNING: Agents had $? errors"
|
logerr "WARNING: Agents had $? errors"
|
||||||
|
|
Loading…
Reference in a new issue