4 # NEODIGIT_API_TOKEN="jasdfhklsjadhflnhsausdfas"
6 # This is Neodigit.net api wrapper for acme.sh
8 # Author: Adrian Almenar
9 # Report Bugs here: https://github.com/tecnocratica/acme.sh
11 NEODIGIT_API_URL
="https://api.neodigit.net/v1"
13 ######## Public functions #####################
15 # Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20 NEODIGIT_API_TOKEN
="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}"
21 if [ -z "$NEODIGIT_API_TOKEN" ]; then
23 _err
"You haven't specified a Token api key."
24 _err
"Please create the key and try again."
28 #save the api key and email to the account conf file.
29 _saveaccountconf_mutable NEODIGIT_API_TOKEN
"$NEODIGIT_API_TOKEN"
31 _debug
"First detect the root zone"
32 if ! _get_root
"$fulldomain"; then
37 _debug fulldomain
"$fulldomain"
38 _debug txtvalue
"$txtvalue"
39 _debug domain
"$_domain"
40 _debug sub_domain
"$_sub_domain"
42 _debug
"Getting txt records"
43 _neo_rest GET
"dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain"
47 if [ "$_code" != "200" ]; then
48 _err
"error retrieving data!"
52 _debug fulldomain
"$fulldomain"
53 _debug txtvalue
"$txtvalue"
54 _debug domain
"$_domain"
55 _debug sub_domain
"$_sub_domain"
58 if _neo_rest POST
"dns/zones/$_domain_id/records" "{\"record\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":60}}"; then
59 if printf -- "%s" "$response" |
grep "$_sub_domain" >/dev
/null
; then
63 _err
"Add txt record error."
67 _err
"Add txt record error."
76 NEODIGIT_API_TOKEN
="${NEODIGIT_API_TOKEN:-$(_readaccountconf_mutable NEODIGIT_API_TOKEN)}"
77 if [ -z "$NEODIGIT_API_TOKEN" ]; then
79 _err
"You haven't specified a Token api key."
80 _err
"Please create the key and try again."
84 #save the api key and email to the account conf file.
85 _saveaccountconf_mutable NEODIGIT_API_TOKEN
"$NEODIGIT_API_TOKEN"
87 _debug
"First detect the root zone"
88 if ! _get_root
"$fulldomain"; then
93 _debug _domain_id
"$_domain_id"
94 _debug _sub_domain
"$_sub_domain"
95 _debug _domain
"$_domain"
97 _debug
"Getting txt records"
98 _neo_rest GET
"dns/zones/${_domain_id}/records?type=TXT&name=$fulldomain&content=$txtvalue"
100 if [ "$_code" != "200" ]; then
101 _err
"error retrieving data!"
105 record_id
=$
(echo "$response" | _egrep_o
"\"id\":\s*[0-9]+" | _head_n
1 | cut
-d: -f2 | cut
-d, -f1)
106 _debug
"record_id" "$record_id"
107 if [ -z "$record_id" ]; then
108 _err
"Can not get record id to remove."
111 if ! _neo_rest DELETE
"dns/zones/$_domain_id/records/$record_id"; then
112 _err
"Delete record error."
118 #################### Private functions below ##################################
119 #_acme-challenge.www.domain.com
121 # _sub_domain=_acme-challenge.www
123 # _domain_id=dasfdsafsadg5ythd
129 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
136 if ! _neo_rest GET
"dns/zones?name=$h"; then
142 if _contains
"$response" "\"name\":\"$h\"" >/dev
/null
; then
143 _domain_id
=$
(echo "$response" | _egrep_o
"\"id\":\s*[0-9]+" | _head_n
1 | cut
-d: -f2 | cut
-d, -f1)
144 if [ "$_domain_id" ]; then
145 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
163 export _H1
="X-TCPanel-Token: $NEODIGIT_API_TOKEN"
164 export _H2
="Content-Type: application/json"
166 if [ "$m" != "GET" ]; then
168 response
="$(_post "$data" "$NEODIGIT_API_URL/$ep" "" "$m")"
170 response
="$(_get "$NEODIGIT_API_URL/$ep")"
173 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
175 if [ "$?" != "0" ]; then
179 _debug2 response
"$response"