4 #SIMPLY_AccountName="accountname"
6 #SIMPLY_ApiKey="apikey"
8 #SIMPLY_Api="https://api.simply.com/1/[ACCOUNTNAME]/[APIKEY]"
10 SIMPLY_Api_Default
="https://api.simply.com/1"
11 ######## Public functions #####################
13 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 if ! _simply_load_config
; then
24 _debug
"First detect the root zone"
25 if ! _get_root
"$fulldomain"; then
30 _debug _sub_domain
"$_sub_domain"
31 _debug _domain
"$_domain"
35 if ! _simply_add_record
"$_domain" "$_sub_domain" "$txtvalue"; then
36 _err
"Could not add DNS record"
46 if ! _simply_load_config
; then
52 _debug
"First detect the root zone"
54 if ! _get_root
"$fulldomain"; then
59 _debug _sub_domain
"$_sub_domain"
60 _debug _domain
"$_domain"
61 _debug txtvalue
"$txtvalue"
63 _info
"Getting all existing records"
65 if ! _simply_get_all_records
"$_domain"; then
70 records
=$
(echo "$response" |
tr '{' "\n" |
grep 'record_id\|type\|data\|\name' |
sed 's/\"record_id/;\"record_id/' |
tr "\n" ' ' |
tr -d ' ' |
tr ';' ' ')
72 nr_of_deleted_records
=0
73 _info
"Fetching txt record"
75 for record
in $records; do
76 _debug record
"$record"
78 record_data
=$
(echo "$record" | cut
-d "," -f 3 |
sed 's/"//g' |
grep "data" | cut
-d ":" -f 2)
79 record_type
=$
(echo "$record" | cut
-d "," -f 4 |
sed 's/"//g' |
grep "type" | cut
-d ":" -f 2)
81 _debug2 record_data
"$record_data"
82 _debug2 record_type
"$record_type"
84 if [ "$record_data" = "$txtvalue" ] && [ "$record_type" = "TXT" ]; then
86 record_id
=$
(echo "$record" | cut
-d "," -f 1 |
grep "record_id" | cut
-d ":" -f 2)
88 _info
"Deleting record $record"
89 _debug2 record_id
"$record_id"
91 if [ "$record_id" -gt 0 ]; then
93 if ! _simply_delete_record
"$_domain" "$_sub_domain" "$record_id"; then
94 _err
"Record with id $record_id could not be deleted"
98 nr_of_deleted_records
=1
101 _err
"Fetching record_id could not be done, this should not happen, exiting function. Failing record is $record"
108 if [ "$nr_of_deleted_records" -eq 0 ]; then
109 _err
"No record deleted, the DNS record needs to be removed manually."
111 _info
"Deleted $nr_of_deleted_records record"
117 #################### Private functions below ##################################
119 _simply_load_config
() {
120 SIMPLY_Api
="${SIMPLY_Api:-$(_readaccountconf_mutable SIMPLY_Api)}"
121 SIMPLY_AccountName
="${SIMPLY_AccountName:-$(_readaccountconf_mutable SIMPLY_AccountName)}"
122 SIMPLY_ApiKey
="${SIMPLY_ApiKey:-$(_readaccountconf_mutable SIMPLY_ApiKey)}"
124 if [ -z "$SIMPLY_Api" ]; then
125 SIMPLY_Api
="$SIMPLY_Api_Default"
128 if [ -z "$SIMPLY_AccountName" ] ||
[ -z "$SIMPLY_ApiKey" ]; then
129 SIMPLY_AccountName
=""
132 _err
"A valid Simply API account and apikey not provided."
133 _err
"Please provide a valid API user and try again."
141 _simply_save_config
() {
142 if [ "$SIMPLY_Api" != "$SIMPLY_Api_Default" ]; then
143 _saveaccountconf_mutable SIMPLY_Api
"$SIMPLY_Api"
145 _saveaccountconf_mutable SIMPLY_AccountName
"$SIMPLY_AccountName"
146 _saveaccountconf_mutable SIMPLY_ApiKey
"$SIMPLY_ApiKey"
149 _simply_get_all_records
() {
152 if ! _simply_rest GET
"my/products/$domain/dns/records"; then
164 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
170 if ! _simply_rest GET
"my/products/$h/dns"; then
174 if _contains
"$response" '"code":"NOT_FOUND"'; then
175 _debug
"$h not found"
177 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
187 _simply_add_record
() {
192 data
="{\"name\": \"$sub_domain\", \"type\":\"TXT\", \"data\": \"$txtval\", \"priority\":0, \"ttl\": 3600}"
194 if ! _simply_rest POST
"my/products/$domain/dns/records" "$data"; then
195 _err
"Adding record not successfull!"
202 _simply_delete_record
() {
207 _debug record_id
"Delete record with id $record_id"
209 if ! _simply_rest DELETE
"my/products/$domain/dns/records/$record_id"; then
210 _err
"Deleting record not successfull!"
226 export _H1
="Content-Type: application/json"
228 if [ "$m" != "GET" ]; then
229 response
="$(_post "$data" "$SIMPLY_Api/$SIMPLY_AccountName/$SIMPLY_ApiKey/$ep" "" "$m")"
231 response
="$(_get "$SIMPLY_Api/$SIMPLY_AccountName/$SIMPLY_ApiKey/$ep")"
234 if [ "$?" != "0" ]; then
239 _debug2 response
"$response"
241 if _contains
"$response" "Invalid account authorization"; then
242 _err
"It seems that your api key or accountnumber is not correct."