forked from yulewang/cloudflare-api-v4-ddns
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new authenticate way, see https://api.cloudflare.com/#getting-started-requests. Change auth header to `Authorization: Bearer`. Remove `X-Auth-Key` and `X-Auth-Email` header. Remove $CFUSER and -u option. fix issue yulewang#22
- Loading branch information
Showing
1 changed file
with
3 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ set -o pipefail | |
|
||
# Usage: | ||
# cf-ddns.sh -k cloudflare-api-key \ | ||
# -u [email protected] \ | ||
# -h host.example.com \ # fqdn of the record you want to update | ||
# -z example.com \ # will show you all zones if forgot, but you need this | ||
# -t A|AAAA # specify ipv4/ipv6, default: ipv4 | ||
|
@@ -30,9 +29,6 @@ set -o pipefail | |
# incorrect api-key results in E_UNAUTH error | ||
CFKEY= | ||
|
||
# Username, eg: [email protected] | ||
CFUSER= | ||
|
||
# Zone name, eg: example.com | ||
CFZONE_NAME= | ||
|
||
|
@@ -64,7 +60,6 @@ fi | |
while getopts k:u:h:z:t:f: opts; do | ||
case ${opts} in | ||
k) CFKEY=${OPTARG} ;; | ||
u) CFUSER=${OPTARG} ;; | ||
h) CFRECORD_NAME=${OPTARG} ;; | ||
z) CFZONE_NAME=${OPTARG} ;; | ||
t) CFRECORD_TYPE=${OPTARG} ;; | ||
|
@@ -78,11 +73,6 @@ if [ "$CFKEY" = "" ]; then | |
echo "and save in ${0} or using the -k flag" | ||
exit 2 | ||
fi | ||
if [ "$CFUSER" = "" ]; then | ||
echo "Missing username, probably your email-address" | ||
echo "and save in ${0} or using the -u flag" | ||
exit 2 | ||
fi | ||
if [ "$CFRECORD_NAME" = "" ]; then | ||
echo "Missing hostname, what host do you want to update?" | ||
echo "save in ${0} or using the -h flag" | ||
|
@@ -120,8 +110,8 @@ if [ -f $ID_FILE ] && [ $(wc -l $ID_FILE | cut -d " " -f 1) == 4 ] \ | |
CFRECORD_ID=$(sed -n '2,1p' "$ID_FILE") | ||
else | ||
echo "Updating zone_identifier & record_identifier" | ||
CFZONE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$CFZONE_NAME" -H "X-Auth-Email: $CFUSER" -H "X-Auth-Key: $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) | ||
CFRECORD_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records?name=$CFRECORD_NAME" -H "X-Auth-Email: $CFUSER" -H "X-Auth-Key: $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) | ||
CFZONE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$CFZONE_NAME" -H "Authorization: Bearer $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) | ||
CFRECORD_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records?name=$CFRECORD_NAME" -H "Authorization: Bearer $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 ) | ||
echo "$CFZONE_ID" > $ID_FILE | ||
echo "$CFRECORD_ID" >> $ID_FILE | ||
echo "$CFZONE_NAME" >> $ID_FILE | ||
|
@@ -132,8 +122,7 @@ fi | |
echo "Updating DNS to $WAN_IP" | ||
|
||
RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records/$CFRECORD_ID" \ | ||
-H "X-Auth-Email: $CFUSER" \ | ||
-H "X-Auth-Key: $CFKEY" \ | ||
-H "Authorization: Bearer $CFKEY" \ | ||
-H "Content-Type: application/json" \ | ||
--data "{\"id\":\"$CFZONE_ID\",\"type\":\"$CFRECORD_TYPE\",\"name\":\"$CFRECORD_NAME\",\"content\":\"$WAN_IP\", \"ttl\":$CFTTL}") | ||
|
||
|