Skip to content

Commit

Permalink
Storing CF API token data in domain config
Browse files Browse the repository at this point in the history
  • Loading branch information
yura3d authored Feb 23, 2024
1 parent aa8cf76 commit cd00ce3
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions dnsapi/dns_cf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,37 @@ dns_cf_add() {
fulldomain=$1
txtvalue=$2

CF_Token="${CF_Token:-$(_readaccountconf_mutable CF_Token)}"
CF_Account_ID="${CF_Account_ID:-$(_readaccountconf_mutable CF_Account_ID)}"
CF_Zone_ID="${CF_Zone_ID:-$(_readaccountconf_mutable CF_Zone_ID)}"
CF_Token="${CF_Token:-$(_readdomainconf CF_Token)}"
CF_Account_ID="${CF_Account_ID:-$(_readdomainconf CF_Account_ID)}"
CF_Zone_ID="${CF_Zone_ID:-$(_readdomainconf CF_Zone_ID)}"
CF_Key="${CF_Key:-$(_readaccountconf_mutable CF_Key)}"
CF_Email="${CF_Email:-$(_readaccountconf_mutable CF_Email)}"

if [ "$CF_Token" ]; then
if [ "$CF_Zone_ID" ]; then
_savedomainconf CF_Token "$CF_Token"
if [ -z "$CF_Account_ID" ] && [ -z "$CF_Zone_ID" ]; then
_err "You didn't specify Account ID or Zone ID yet."
_err "You can get one from Cloudflare dashboard zone's Overview page."
return 1
fi

if [ "$CF_Account_ID" ] && [ "$CF_Zone_ID" ]; then
_err "You should specify either Account ID or Zone ID:"
_err "https://github.com/acmesh-official/acme.sh/wiki/dnsapi#a-using-a-restrictive-api-token"
return 1
fi

_savedomainconf CF_Token "$CF_Token"

if [ "$CF_Account_ID" ]; then
_savedomainconf CF_Account_ID "$CF_Account_ID"
else
_cleardomainconf CF_Account_ID
fi

if [ "$CF_Zone_ID" ]; then
_savedomainconf CF_Zone_ID "$CF_Zone_ID"
else
_saveaccountconf_mutable CF_Token "$CF_Token"
_saveaccountconf_mutable CF_Account_ID "$CF_Account_ID"
_clearaccountconf_mutable CF_Zone_ID
_clearaccountconf CF_Zone_ID
_cleardomainconf CF_Zone_ID
fi
else
if [ -z "$CF_Key" ] || [ -z "$CF_Email" ]; then
Expand All @@ -52,15 +67,13 @@ dns_cf_add() {
#save the api key and email to the account conf file.
_saveaccountconf_mutable CF_Key "$CF_Key"
_saveaccountconf_mutable CF_Email "$CF_Email"

_clearaccountconf_mutable CF_Token
_clearaccountconf_mutable CF_Account_ID
_clearaccountconf_mutable CF_Zone_ID
_clearaccountconf CF_Token
_clearaccountconf CF_Account_ID
_clearaccountconf CF_Zone_ID

fi
_clearaccountconf_mutable CF_Token
_clearaccountconf_mutable CF_Account_ID
_clearaccountconf_mutable CF_Zone_ID
_clearaccountconf CF_Token
_clearaccountconf CF_Account_ID
_clearaccountconf CF_Zone_ID

_debug "First detect the root zone"
if ! _get_root "$fulldomain"; then
Expand Down

0 comments on commit cd00ce3

Please sign in to comment.