Merge pull request #34 from 9cco/alternative-ip-resolver
Added cloudflare.com as default ip lookup
This commit is contained in:
commit
d9ad375827
|
@ -7,7 +7,7 @@ auth_key="" # Your API Token or Global AP
|
||||||
zone_identifier="" # Can be found in the "Overview" tab of your domain
|
zone_identifier="" # Can be found in the "Overview" tab of your domain
|
||||||
record_name="" # Which record you want to be synced
|
record_name="" # Which record you want to be synced
|
||||||
ttl="3600" # Set the DNS TTL (seconds)
|
ttl="3600" # Set the DNS TTL (seconds)
|
||||||
proxy=false # Set the proxy to true or false
|
proxy="false" # Set the proxy to true or false
|
||||||
slacksitename="" # Title of site "Example Site"
|
slacksitename="" # Title of site "Example Site"
|
||||||
slackchannel="" # Slack Channel #example
|
slackchannel="" # Slack Channel #example
|
||||||
slackuri="" # URI for Slack WebHook "https://hooks.slack.com/services/xxxxx"
|
slackuri="" # URI for Slack WebHook "https://hooks.slack.com/services/xxxxx"
|
||||||
|
@ -17,17 +17,26 @@ slackuri="" # URI for Slack WebHook "http
|
||||||
###########################################
|
###########################################
|
||||||
## 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/)
|
ipv4_regex='([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'
|
||||||
|
ip=$(curl -s -4 https://cloudflare.com/cdn-cgi/trace | grep -E '^ip'); ret=$?
|
||||||
|
if [[ ! $ret == 0 ]]; then # In the case that cloudflare failed to return an ip.
|
||||||
|
# Attempt to get the ip from other websites.
|
||||||
|
ip=$(curl -s https://api.ipify.org || curl -s https://ipv4.icanhazip.com)
|
||||||
|
else
|
||||||
|
# Extract just the ip from the ip line from cloudflare.
|
||||||
|
ip=$(echo $ip | sed -E "s/^ip=($ipv4_regex)$/\1/")
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${ip}" == "" ]; then
|
# Use regex to check for proper IPv4 format.
|
||||||
logger -s "DDNS Updater: No public IP found"
|
if [[ ! $ip =~ ^$ipv4_regex$ ]]; then
|
||||||
exit 1
|
logger -s "DDNS Updater: Failed to find a valid IP."
|
||||||
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
## Check and set the proper auth header
|
## Check and set the proper auth header
|
||||||
###########################################
|
###########################################
|
||||||
if [ "${auth_method}" == "global" ]; then
|
if [[ "${auth_method}" == "global" ]]; then
|
||||||
auth_header="X-Auth-Key:"
|
auth_header="X-Auth-Key:"
|
||||||
else
|
else
|
||||||
auth_header="Authorization: Bearer"
|
auth_header="Authorization: Bearer"
|
||||||
|
@ -73,14 +82,14 @@ update=$(curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_iden
|
||||||
-H "X-Auth-Email: $auth_email" \
|
-H "X-Auth-Email: $auth_email" \
|
||||||
-H "$auth_header $auth_key" \
|
-H "$auth_header $auth_key" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data "{\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":\"$ttl\",\"proxied\":${proxy}}")
|
--data "{\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":\"$ttl\",\"proxied\":${proxy}}")
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
## Report the status
|
## Report the status
|
||||||
###########################################
|
###########################################
|
||||||
case "$update" in
|
case "$update" in
|
||||||
*"\"success\":false"*)
|
*"\"success\":false"*)
|
||||||
logger -s "DDNS Updater: $ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update"
|
echo -e "DDNS Updater: $ip $record_name DDNS failed for $record_identifier ($ip). DUMPING RESULTS:\n$update" | logger -s
|
||||||
if [[ $slackuri != "" ]]; then
|
if [[ $slackuri != "" ]]; then
|
||||||
curl -L -X POST $slackuri \
|
curl -L -X POST $slackuri \
|
||||||
--data-raw '{
|
--data-raw '{
|
||||||
|
|
Loading…
Reference in New Issue