4 #NJALLA_Token="sdfsdfsdfljlbjkljlkjsdfoiwje"
6 NJALLA_Api
="https://njal.la/api/1/"
8 ######## Public functions #####################
10 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
15 NJALLA_Token
="${NJALLA_Token:-$(_readaccountconf_mutable NJALLA_Token)}"
17 if [ "$NJALLA_Token" ]; then
18 _saveaccountconf_mutable NJALLA_Token
"$NJALLA_Token"
21 _err
"You didn't specify a Njalla api token yet."
25 _debug
"First detect the root zone"
26 if ! _get_root
"$fulldomain"; then
30 _debug _sub_domain
"$_sub_domain"
31 _debug _domain
"$_domain"
33 # For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
34 # we can not use updating anymore.
35 # count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
36 # _debug count "$count"
37 # if [ "$count" = "0" ]; then
39 if _njalla_rest
"{\"method\":\"add-record\",\"params\":{\"domain\":\"$_domain\",\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":120}}"; then
40 if _contains
"$response" "$txtvalue"; then
44 _err
"Add txt record error."
48 _err
"Add txt record error."
58 NJALLA_Token
="${NJALLA_Token:-$(_readaccountconf_mutable NJALLA_Token)}"
60 if [ "$NJALLA_Token" ]; then
61 _saveaccountconf_mutable NJALLA_Token
"$NJALLA_Token"
64 _err
"You didn't specify a Njalla api token yet."
68 _debug
"First detect the root zone"
69 if ! _get_root
"$fulldomain"; then
73 _debug _sub_domain
"$_sub_domain"
74 _debug _domain
"$_domain"
76 _debug
"Getting records for domain"
77 if ! _njalla_rest
"{\"method\":\"list-records\",\"params\":{\"domain\":\"${_domain}\"}}"; then
81 if ! echo "$response" |
tr -d " " |
grep "\"id\":" >/dev
/null
; then
82 _err
"Error: $response"
86 records
=$
(echo "$response" | _egrep_o
"\"records\":\s?\[(.*)\]\}" | _egrep_o
"\[.*\]" | _egrep_o
"\{[^\{\}]*\"id\":[^\{\}]*\}")
87 count
=$
(echo "$records" |
wc -l)
90 if [ "$count" = "0" ]; then
91 _info
"Don't need to remove."
93 echo "$records" |
while read -r record
; do
94 record_name
=$
(echo "$record" | _egrep_o
"\"name\":\s?\"[^\"]*\"" | cut
-d : -f 2 |
tr -d " " |
tr -d \")
95 record_content
=$
(echo "$record" | _egrep_o
"\"content\":\s?\"[^\"]*\"" | cut
-d : -f 2 |
tr -d " " |
tr -d \")
96 record_id
=$
(echo "$record" | _egrep_o
"\"id\":\s?[0-9]+" | cut
-d : -f 2 |
tr -d " " |
tr -d \")
97 if [ "$_sub_domain" = "$record_name" ]; then
98 if [ "$txtvalue" = "$record_content" ]; then
99 _debug
"record_id" "$record_id"
100 if ! _njalla_rest
"{\"method\":\"remove-record\",\"params\":{\"domain\":\"${_domain}\",\"id\":${record_id}}}"; then
101 _err
"Delete record error."
104 echo "$response" |
tr -d " " |
grep "\"result\"" >/dev
/null
112 #################### Private functions below ##################################
113 #_acme-challenge.www.domain.com
115 # _sub_domain=_acme-challenge.www
117 # _domain_id=sdjkglgdfewsdfg
124 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
131 if ! _njalla_rest
"{\"method\":\"get-domain\",\"params\":{\"domain\":\"${h}\"}}"; then
135 if _contains
"$response" "\"$h\""; then
136 _domain_returned
=$
(echo "$response" | _egrep_o
"\{\"name\": *\"[^\"]*\"" | _head_n
1 | cut
-d : -f 2 |
tr -d \" |
tr -d " ")
137 if [ "$_domain_returned" ]; then
138 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
153 token_trimmed
=$
(echo "$NJALLA_Token" |
tr -d '"')
155 export _H1
="Content-Type: application/json"
156 export _H2
="Accept: application/json"
157 export _H3
="Authorization: Njalla $token_trimmed"
160 response
="$(_post "$data" "$NJALLA_Api" "" "POST
")"
162 if [ "$?" != "0" ]; then
166 _debug2 response
"$response"