Update cloudflare-template.sh
Proposed fix for double sending webhooks even if IP Address did not change. What it does is it saves the ip address on a file ".cf-wan_ip_<name of record>.txt" and fetches this text file every update making sure that it is comparing a valid IP address.
This commit is contained in:
parent
88c73e30f8
commit
31989c5298
|
@ -33,6 +33,25 @@ if [[ ! $ip =~ ^$ipv4_regex$ ]]; then
|
|||
exit 2
|
||||
fi
|
||||
|
||||
###########################################
|
||||
## Check for the old IP record
|
||||
###########################################
|
||||
wan_ip_record=$HOME/.cf-wan_ip_$record_name.txt
|
||||
if [ -f $wan_ip_record ]; then
|
||||
old_ip=`cat $wan_ip_record`
|
||||
else
|
||||
logger "DDNS Updater: No old IP record found."
|
||||
old_ip=""
|
||||
fi
|
||||
|
||||
###########################################
|
||||
## Compare existing IP record to new IP
|
||||
###########################################
|
||||
if [[ $ip == $old_ip ]]; then
|
||||
logger "DDNS Updater: IP ($ip) for ${record_name} has not changed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
###########################################
|
||||
## Check and set the proper auth header
|
||||
###########################################
|
||||
|
@ -60,16 +79,6 @@ if [[ $record == *"\"count\":0"* ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
###########################################
|
||||
## Get existing IP
|
||||
###########################################
|
||||
old_ip=$(echo "$record" | sed -E 's/.*"content":"(([0-9]{1,3}\.){3}[0-9]{1,3})".*/\1/')
|
||||
# Compare if they're the same
|
||||
if [[ $ip == $old_ip ]]; then
|
||||
logger "DDNS Updater: IP ($ip) for ${record_name} has not changed."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
###########################################
|
||||
## Set the record identifier from result
|
||||
###########################################
|
||||
|
@ -106,6 +115,10 @@ case "$update" in
|
|||
exit 1;;
|
||||
*)
|
||||
logger "DDNS Updater: $ip $record_name DDNS updated."
|
||||
|
||||
# echo our new ip to the record
|
||||
echo $ip > $wan_ip_record
|
||||
|
||||
if [[ $slackuri != "" ]]; then
|
||||
curl -L -X POST $slackuri \
|
||||
--data-raw '{
|
||||
|
|
Loading…
Reference in New Issue