From 31989c5298a9efde7996d0b342476e0f2d481a52 Mon Sep 17 00:00:00 2001 From: psycho-neon <60956316+psycho-neon@users.noreply.github.com> Date: Fri, 6 Jan 2023 22:07:43 +0300 Subject: [PATCH] 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_.txt" and fetches this text file every update making sure that it is comparing a valid IP address. --- cloudflare-template.sh | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index 454c9db..8050aad 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -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 '{