From 3a8a6dc7e9954c24a324d21ba57f59287185a835 Mon Sep 17 00:00:00 2001 From: Mike Lape <31513230+bioinformike@users.noreply.github.com> Date: Sun, 18 Jul 2021 20:49:53 -0400 Subject: [PATCH 1/4] Adding date time function for logs --- cloudflare-template.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index fc384a1..89ea26e 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -6,12 +6,21 @@ zone_identifier="" # Can be found in the "Overvi record_name="" # Which record you want to be synced proxy=true # Set the proxy to true or false + +########################################### +## Define date time stamp function +########################################### +function ds() { + date +"[%F %T]" +} + + ########################################### ## Check if we have an public IP ########################################### ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/) if [ "${ip}" == "" ]; then - message="No public IP found." + message="$(ds) No public IP found." >&2 echo -e "${message}" >> ~/log exit 1 fi @@ -19,14 +28,14 @@ fi ########################################### ## Seek for the A record ########################################### -echo " Check Initiated" >> ~/log +echo "$(ds) Check Initiated" >> ~/log record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?name=$record_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json") ########################################### ## Check if the domaine has an A record ########################################### if [[ $record == *"\"count\":0"* ]]; then - message=" Record does not exist, perhaps create one first? (${ip} for ${record_name})" + message="$(ds) Record does not exist, perhaps create one first? (${ip} for ${record_name})" >&2 echo -e "${message}" >> ~/log exit 1 fi @@ -37,7 +46,7 @@ fi old_ip=$(echo "$record" | grep -Po '(?<="content":")[^"]*' | head -1) # Compare if they're the same if [[ $ip == $old_ip ]]; then - message=" IP ($ip) for ${record_name} has not changed." + message="$(ds) IP ($ip) for ${record_name} has not changed." echo "${message}" >> ~/log exit 0 fi @@ -61,11 +70,11 @@ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identi ########################################### case "$update" in *"\"success\":false"*) - message="$ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update" + message="$(ds) $ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update" >&2 echo -e "${message}" >> ~/log exit 1;; *) - message="$ip $record_name DDNS updated." + message="$(ds) $ip $record_name DDNS updated." echo "${message}" >> ~/log exit 0;; -esac \ No newline at end of file +esac From 5debdd0e56a7e277b6f6645752d5961995bf63f9 Mon Sep 17 00:00:00 2001 From: Mike Lape <31513230+bioinformike@users.noreply.github.com> Date: Mon, 19 Jul 2021 07:13:53 -0400 Subject: [PATCH 2/4] Changed whitespace in function definition --- cloudflare-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudflare-template.sh b/cloudflare-template.sh index 89ea26e..1b7dfa6 100644 --- a/cloudflare-template.sh +++ b/cloudflare-template.sh @@ -11,7 +11,7 @@ proxy=true # Set the proxy to true or fa ## Define date time stamp function ########################################### function ds() { - date +"[%F %T]" + date +"[%F %T]" } From f48fe12fb9082dcc7ba536d20d53f90910619f42 Mon Sep 17 00:00:00 2001 From: Jason K Date: Mon, 19 Jul 2021 19:45:43 +0800 Subject: [PATCH 3/4] Update README.md --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dd78b9..334e24e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Cloudflare Dynamic DNS IP Register +# Cloudflare Dynamic DNS IP Updater This script is used to update dynamic DNS entries for accounts on Cloudflare. @@ -20,8 +20,7 @@ This script is used with crontab. Specify the frequency of execution through cro # │ │ │ │ │ ┌───────────── command to issue # │ │ │ │ │ │ # │ │ │ │ │ │ -# * * * * * cd /{location of repo} && /{location of repo}/cloudflare-template.sh >> /cron.log 2>&1 -# 0 0 */3 * * echo " " > /cloudflare-autoupdate.log >> /cron.log 2>&1 +# * * * * * /bin/bash {Location of the script} ``` ## Contributing From f639d9bcb2c595c1698ded24721c1f643883f147 Mon Sep 17 00:00:00 2001 From: Jason K Date: Mon, 19 Jul 2021 19:55:48 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 334e24e..da23fea 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Cloudflare Dynamic DNS IP Updater +GitHub GitHub last commit (branch) GitHub contributors This script is used to update dynamic DNS entries for accounts on Cloudflare.