Created
April 13, 2014 21:11
-
-
Save rafamaciel/10602512 to your computer and use it in GitHub Desktop.
Cloudflare update domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Parameters: | |
# Domain to be changed. | |
z="your-domain.com" | |
# Your CloudFlare token (https://www.cloudflare.com/my-account) | |
token="seu-token-da-api-no-cloudflare" | |
# Type of recording (A/CNAME/MX/TXT/SPF/AAAA/NS/SRV/LOC) | |
type="A" | |
# name of recording | |
name="www" | |
# Timeout recording (automatic: 1) | |
ttl=1 | |
# CloudFlare proxy status (1: on, 0:off) just found to A/AAAA/CNAME | |
service_mode=1 | |
# Record Id | |
id=00000000 | |
# Your email (https://www.cloudflare.com/my-account) | |
email="[email protected]" | |
# Run curl to save the data on cloudflare. | |
#request=$(curl --data "a=$a&tkn=$token&id=$id&email=$email&z=$z&type=$type&name=$name&content=$content&service_mode=$service_mode&ttl=$ttl" https://www.cloudflare.com/api_json.html ) | |
# Consult the desired field and writes the Json with the result. | |
echo $(curl --data "a=rec_load_all&tkn=$token&email=$email&z=$z" https://www.cloudflare.com/api_json.html -o "result.json") | |
# Uses jq to get ip. | |
IP_NO_CLOUD=$(cat result.json | jq '.response.recs.objs[0].content'| sed 's/"//'| sed 's/"//') | |
# Get the external ip of the machine. | |
IP_ATUAL=$(curl "http://myexternalip.com/raw") | |
# Compares the two IPs | |
if [ "$IP_NO_CLUD" != "$IP_ATUAL" ]; then | |
echo "Update ip on cloudflare..." | |
# Executes registry update. | |
REQUEST=$(curl --data "a=rec_edit&tkn=$token&id=$id&email=$email&z=$z&type=$type&name=$name&content=$IP_ATUAL&service_mode=$service_mode&ttl=$ttl" https://www.cloudflare.com/api_json.html -o "result.json") | |
# Gets result. | |
REQUEST=$(cat result.json | jq '.result'| sed 's/"//'| sed 's/"//') | |
# Checks if the domain has been updated | |
if [ "$REQUEST" == "success" ]; then | |
echo "Success..." | |
else | |
echo "Fail..." | |
fi | |
else | |
echo "The ip address has changed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment