Forked from benkulbertis/cloudflare-update-record.sh
Created
December 9, 2018 17:16
-
-
Save test0103/abd1b17a7c21882fd1662d291228d2e5 to your computer and use it in GitHub Desktop.
Revisions
-
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ record_name="www.example.com" # MAYBE CHANGE THESE ip=$(curl -s http://ipv4.icanhazip.com) ip_file="ip.txt" id_file="cloudflare.ids" log_file="cloudflare.log" # LOGGER @@ -29,9 +30,15 @@ if [ -f $ip_file ]; then fi fi if [ -f $id_file ] && [ $(wc -l $id_file | cut -d " " -f 1) == 2 ]; then zone_identifier=$(head -1 $id_file) record_identifier=$(tail -1 $id_file) else zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) record_identifier=$(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" | grep -Po '(?<="id":")[^"]*') echo "$zone_identifier" > $id_file echo "$record_identifier" >> $id_file fi update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}") -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -36,12 +36,13 @@ record_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}") if [[ $update == *"\"success\":false"* ]]; then message="API UPDATE FAILED. DUMPING RESULTS:\n$update" log "$message" echo -e "$message" exit 1 else message="IP changed to: $ip" echo "$ip" > $ip_file log "$message" echo "$message" fi -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ log_file="cloudflare.log" # LOGGER log() { if [ "$1" ]; then echo -e "[$(date)] - $1" >> $log_file fi } @@ -36,8 +36,7 @@ record_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}") if [[ $update == *"\"success\":false"* ]]; then log "API UPDATE FAILED. DUMPING RESULTS:\n$update" echo "API UPDATE FAILED. DUMPING RESULTS:" echo "$update" exit 1 -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 17 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,15 +11,22 @@ ip=$(curl -s http://ipv4.icanhazip.com) ip_file="ip.txt" log_file="cloudflare.log" # LOGGER log() { if [ "$1" ]; then echo "[$(date)] - $1" >> $log_file fi } # SCRIPT START log "Check Initiated" if [ -f $ip_file ]; then old_ip=$(cat $ip_file) if [ $ip == $old_ip ]; then echo "IP has not changed." exit 0 fi fi zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) @@ -29,13 +36,13 @@ record_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}") if [[ $update == *"\"success\":false"* ]]; then log "API UPDATE FAILED. DUMPING RESULTS:" log "$update" echo "API UPDATE FAILED. DUMPING RESULTS:" echo "$update" exit 1 else echo "$ip" > $ip_file log "IP changed to: $ip" echo "IP changed to: $ip" fi -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,7 @@ if [[ $update == *"\"success\":false"* ]]; then echo "$update" >> $log_file echo "API UPDATE FAILED. DUMPING RESULTS:" echo "$update" exit 1 else echo "$ip" > $ip_file echo "[$(date)] - IP changed to: $ip" >> $log_file -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,20 +20,21 @@ if [ -f $ip_file ]; then echo "IP has not changed." exit 0 fi fi zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) record_identifier=$(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" | grep -Po '(?<="id":")[^"]*') update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}") if [[ $update == *"\"success\":false"* ]]; then echo "[$(date)] - API UPDATE FAILED. DUMPING RESULTS:" >> $log_file echo "$update" >> $log_file echo "API UPDATE FAILED. DUMPING RESULTS:" echo "$update" else echo "$ip" > $ip_file echo "[$(date)] - IP changed to: $ip" >> $log_file echo "IP changed to: $ip" fi -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,12 @@ auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare a zone_name="example.com" record_name="www.example.com" # MAYBE CHANGE THESE ip=$(curl -s http://ipv4.icanhazip.com) ip_file="ip.txt" log_file="cloudflare.log" # SCRIPT START echo "[$(date)] - Check Initiated" >> $log_file if [ -f $ip_file ]; then -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 13 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,15 @@ #!/bin/bash # CHANGE THESE auth_email="[email protected]" auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings zone_name="example.com" record_name="www.example.com" ip=$(curl -s http://ipv4.icanhazip.com) ip_file="ip.txt" log_file="cloudflare.log" echo "[$(date)] - Check Initiated" >> $log_file if [ -f $ip_file ]; then @@ -20,12 +22,16 @@ else echo "$ip" > $ip_file fi zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) record_identifier=$(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" | grep -Po '(?<="id":")[^"]*') curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: $auth_email" -H "X-Auth-Key: $auth_key" -H "Content-Type: application/json" --data "{\"id\":\"$zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}" -o /dev/null if [ $? -eq 0 ]; then echo "[$(date)] - IP changed to: $ip" >> $log_file echo "IP changed to: $ip" else echo "[$(date)] - API UPDATE FAILED" >> $log_file echo "API UPDATE FAILED." fi -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ zone_identifier="ZONE IDENTIFIER" record_identifier="RECORD IDENTIFIER" record_name="RECORD NAME" echo "[$(date)] - Check Initiated" >> $log_file if [ -f $ip_file ]; then old_ip=$(cat $ip_file) @@ -23,9 +23,9 @@ fi curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" -H "Content-Type: application/json" --data "{\"id\":\":zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}" -o /dev/null if [ $? -eq 0 ]; then echo "[$(date)] - IP changed to: $ip" >> $log_file echo "IP changed to: $ip" else echo "[$(date)] - API UPDATE FAILED WTF SON" >> $log_file echo "API UPDATE FAILED WTF SON." fi -
benkulbertis revised this gist
May 4, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #!/bin/bash ip=$(curl -s http://ipv4.icanhazip.com) ip_file="ip.txt" log_file="cloudflare.log" zone_identifier="ZONE IDENTIFIER" -
benkulbertis created this gist
May 4, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ #!/bin/bash ip_file="ip.txt" ip=$(curl -s http://ipv4.icanhazip.com) log_file="cloudflare.log" zone_identifier="ZONE IDENTIFIER" record_identifier="RECORD IDENTIFIER" record_name="RECORD NAME" echo "[$(date)] - Check Initiated" > $log_file if [ -f $ip_file ]; then old_ip=$(cat $ip_file) if [ $ip == $old_ip ]; then echo "IP has not changed." exit 0 fi else echo "$ip" > $ip_file fi curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" -H "Content-Type: application/json" --data "{\"id\":\":zone_identifier\",\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\"}" -o /dev/null if [ $? -eq 0 ]; then echo "[$(date)] - IP changed to: $ip" > $log_file echo "IP changed to: $ip" else echo "[$(date)] - API UPDATE FAILED WTF SON" > $log_file echo "API UPDATE FAILED WTF SON." fi