3 # DNS API for acme.sh for Core-Networks (https://beta.api.core-networks.de/doc/).
4 # created by 5ll and francis
6 CN_API
="https://beta.api.core-networks.de"
8 ######## Public functions #####################
19 _debug
"First detect the root zone"
20 if ! _cn_get_root
"$fulldomain"; then
25 _debug
"_sub_domain $_sub_domain"
26 _debug
"_domain $_domain"
29 curData
="{\"name\":\"$_sub_domain\",\"ttl\":120,\"type\":\"TXT\",\"data\":\"$txtvalue\"}"
30 curResult
="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records
/")"
32 _debug
"curData $curData"
33 _debug
"curResult $curResult"
35 if _contains
"$curResult" ""; then
39 _err
"commiting changes failed"
45 _err
"Add txt record error."
46 _debug
"curData is $curData"
47 _debug
"curResult is $curResult"
48 _err
"error adding text record, response was $curResult"
62 _debug
"First detect the root zone"
63 if ! _cn_get_root
"$fulldomain"; then
68 _info
"Deleting record"
69 curData
="{\"name\":\"$_sub_domain\",\"data\":\"$txtvalue\"}"
70 curResult
="$(_post "${curData}" "${CN_API}/dnszones/${_domain}/records
/delete
")"
71 _debug curData is
"$curData"
73 _info
"commiting changes"
75 _err
"commiting changes failed"
79 _info
"Deletet txt record"
83 ################### Private functions below ##################################
85 CN_User
="${CN_User:-$(_readaccountconf_mutable CN_User)}"
86 CN_Password
="${CN_Password:-$(_readaccountconf_mutable CN_Password)}"
87 if [ -z "$CN_User" ] ||
[ -z "$CN_Password" ]; then
90 _err
"You must export variables: CN_User and CN_Password"
94 #save the config variables to the account conf file.
95 _saveaccountconf_mutable CN_User
"$CN_User"
96 _saveaccountconf_mutable CN_Password
"$CN_Password"
98 _info
"Getting an AUTH-Token"
99 curData
="{\"login\":\"${CN_User}\",\"password\":\"${CN_Password}\"}"
100 curResult
="$(_post "${curData}" "${CN_API}/auth
/token
")"
101 _debug
"Calling _CN_login: '${curData}' '${CN_API}/auth/token'"
103 if _contains
"${curResult}" '"token":"'; then
104 authToken
=$
(echo "${curResult}" | cut
-d ":" -f2 | cut
-d "," -f1 |
sed 's/^.\(.*\).$/\1/')
105 export _H1
="Authorization: Bearer $authToken"
106 _info
"Successfully acquired AUTH-Token"
107 _debug
"AUTH-Token: '${authToken}'"
108 _debug
"_H1 '${_H1}'"
110 _err
"Couldn't acquire an AUTH-Token"
117 _info
"Commiting changes"
118 _post
"" "${CN_API}/dnszones/$h/records/commit"
127 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
136 _cn_zonelist
="$(_get ${CN_API}/dnszones/)"
137 _debug _cn_zonelist
"${_cn_zonelist}"
139 if [ "$?" != "0" ]; then
140 _err
"something went wrong while getting the zone list"
144 if _contains
"$_cn_zonelist" "\"name\":\"$h\"" >/dev
/null
; then
145 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
149 _debug
"Zonelist does not contain domain - iterating "
155 _err
"Zonelist does not contain domain - exiting"