3 # bug reports to dev@1e.ca
5 # ME_Key=qmlkdjflmkqdjf
6 # ME_Secret=qmsdlkqmlksdvnnpae
8 ME_Api
=https
://api.dnsmadeeasy.com
/V2.0
/dns
/managed
10 ######## Public functions #####################
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 if [ -z "$ME_Key" ] ||
[ -z "$ME_Secret" ]; then
20 _err
"You didn't specify DNSMadeEasy api key and secret yet."
21 _err
"Please create you key and try again."
25 #save the api key and email to the account conf file.
26 _saveaccountconf ME_Key
"$ME_Key"
27 _saveaccountconf ME_Secret
"$ME_Secret"
29 _debug
"First detect the root zone"
30 if ! _get_root
"$fulldomain"; then
34 _debug _domain_id
"$_domain_id"
35 _debug _sub_domain
"$_sub_domain"
36 _debug _domain
"$_domain"
38 _debug
"Getting txt records"
39 _me_rest GET
"${_domain_id}/records?recordName=$_sub_domain&type=TXT"
41 if ! _contains
"$response" "\"totalRecords\":"; then
47 if _me_rest POST
"$_domain_id/records/" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\",\"gtdLocation\":\"DEFAULT\",\"ttl\":120}"; then
48 if printf -- "%s" "$response" |
grep \"id
\": >/dev
/null
; then
50 #todo: check if the record takes effect
53 _err
"Add txt record error."
64 _debug
"First detect the root zone"
65 if ! _get_root
"$fulldomain"; then
69 _debug _domain_id
"$_domain_id"
70 _debug _sub_domain
"$_sub_domain"
71 _debug _domain
"$_domain"
73 _debug
"Getting txt records"
74 _me_rest GET
"${_domain_id}/records?recordName=$_sub_domain&type=TXT"
76 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"totalRecords\":[^,]*" | cut
-d : -f 2)
78 if [ "$count" = "0" ]; then
79 _info
"Don't need to remove."
81 record_id
=$
(printf "%s\n" "$response" | _egrep_o
",\"value\":\"..$txtvalue..\",\"id\":[^,]*" | cut
-d : -f 3 |
head -n 1)
82 _debug
"record_id" "$record_id"
83 if [ -z "$record_id" ]; then
84 _err
"Can not get record id to remove."
87 if ! _me_rest DELETE
"$_domain_id/records/$record_id"; then
88 _err
"Delete record error."
91 _contains
"$response" ''
95 #################### Private functions below ##################################
96 #_acme-challenge.www.domain.com
98 # _sub_domain=_acme-challenge.www
100 # _domain_id=sdjkglgdfewsdfg
106 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
112 if ! _me_rest GET
"name?domainname=$h"; then
116 if _contains
"$response" "\"name\":\"$h\""; then
117 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[^,]*" |
head -n 1 | cut
-d : -f 2 |
tr -d '}')
118 if [ "$_domain_id" ]; then
119 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
137 cdate
=$
(LANG
=C
date -u +"%a, %d %b %Y %T %Z")
138 hmac
=$
(printf "%s" "$cdate" | _hmac sha1
"$(printf "%s
" "$ME_Secret" | _hex_dump | tr -d " ")" hex
)
140 export _H1
="x-dnsme-apiKey: $ME_Key"
141 export _H2
="x-dnsme-requestDate: $cdate"
142 export _H3
="x-dnsme-hmac: $hmac"
144 if [ "$m" != "GET" ]; then
146 response
="$(_post "$data" "$ME_Api/$ep" "" "$m")"
148 response
="$(_get "$ME_Api/$ep")"
151 if [ "$?" != "0" ]; then
155 _debug2 response
"$response"