Merge branch 'main' into main
This commit is contained in:
commit
cf243aa00b
|
@ -1,4 +1,5 @@
|
||||||
# Cloudflare Dynamic DNS IP Register
|
# Cloudflare Dynamic DNS IP Updater
|
||||||
|
<img alt="GitHub" src="https://img.shields.io/github/license/K0p1-Git/cloudflare-ddns-updater?color=black"> <img alt="GitHub last commit (branch)" src="https://img.shields.io/github/last-commit/K0p1-Git/cloudflare-ddns-updater/main"> <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/K0p1-Git/cloudflare-ddns-updater">
|
||||||
|
|
||||||
This script is used to update dynamic DNS entries for accounts on Cloudflare.
|
This script is used to update dynamic DNS entries for accounts on Cloudflare.
|
||||||
|
|
||||||
|
@ -20,8 +21,7 @@ This script is used with crontab. Specify the frequency of execution through cro
|
||||||
# │ │ │ │ │ ┌───────────── command to issue
|
# │ │ │ │ │ ┌───────────── command to issue
|
||||||
# │ │ │ │ │ │
|
# │ │ │ │ │ │
|
||||||
# │ │ │ │ │ │
|
# │ │ │ │ │ │
|
||||||
# * * * * * cd /{location of repo} && /{location of repo}/cloudflare-template.sh >> /cron.log 2>&1
|
# * * * * * /bin/bash {Location of the script}
|
||||||
# 0 0 */3 * * echo " " > /cloudflare-autoupdate.log >> /cron.log 2>&1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
|
@ -8,12 +8,22 @@ record_name="" # Which record you want to be
|
||||||
proxy=false # Set the proxy to true or false
|
proxy=false # Set the proxy to true or false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################################
|
||||||
|
## Define date time stamp function
|
||||||
|
###########################################
|
||||||
|
function ds() {
|
||||||
|
date +"[%F %T]"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
## Check if we have a public IP
|
## Check if we have a public IP
|
||||||
###########################################
|
###########################################
|
||||||
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/)
|
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com/)
|
||||||
if [ "${ip}" == "" ]; then
|
|
||||||
message="No public IP found."
|
if [ "${ip}" == "" ]; then
|
||||||
|
message="$(ds) No public IP found."
|
||||||
>&2 echo -e "${message}" >> ~/log
|
>&2 echo -e "${message}" >> ~/log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -30,15 +40,15 @@ fi
|
||||||
###########################################
|
###########################################
|
||||||
## Seek for the A record
|
## Seek for the A record
|
||||||
###########################################
|
###########################################
|
||||||
echo " 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 "$auth_header $auth_key" -H "Content-Type: application/json")
|
|
||||||
|
|
||||||
|
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 domain has an A record
|
## Check if the domain has an A record
|
||||||
###########################################
|
###########################################
|
||||||
if [[ $record == *"\"count\":0"* ]]; then
|
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
|
>&2 echo -e "${message}" >> ~/log
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -49,7 +59,7 @@ fi
|
||||||
old_ip=$(echo "$record" | grep -Po '(?<="content":")[^"]*' | head -1)
|
old_ip=$(echo "$record" | grep -Po '(?<="content":")[^"]*' | head -1)
|
||||||
# Compare if they're the same
|
# Compare if they're the same
|
||||||
if [[ $ip == $old_ip ]]; then
|
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
|
echo "${message}" >> ~/log
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -73,11 +83,11 @@ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identi
|
||||||
###########################################
|
###########################################
|
||||||
case "$update" in
|
case "$update" in
|
||||||
*"\"success\":false"*)
|
*"\"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
|
>&2 echo -e "${message}" >> ~/log
|
||||||
exit 1;;
|
exit 1;;
|
||||||
*)
|
*)
|
||||||
message="$ip $record_name DDNS updated."
|
message="$(ds) $ip $record_name DDNS updated."
|
||||||
echo "${message}" >> ~/log
|
echo "${message}" >> ~/log
|
||||||
exit 0;;
|
exit 0;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue