3 #Here is a api script for MyDNS.JP.
4 #This file name is "dns_mydnsjp.sh"
5 #So, here must be a method dns_mydnsjp_add()
6 #Which will be called by acme.sh to add the txt record to your api system.
7 #returns 0 means success, otherwise error.
10 #Report Bugs here: https://github.com/epgdatacapbon/acme.sh
12 ######## Public functions #####################
14 # Export MyDNS.JP MasterID and Password in following variables...
15 # MYDNSJP_MasterID=MasterID
16 # MYDNSJP_Password=Password
18 MYDNSJP_API
="https://www.mydns.jp"
20 #Usage: dns_mydnsjp_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
26 _debug fulldomain
"$fulldomain"
27 _debug txtvalue
"$txtvalue"
29 # Load the credentials from the account conf file
30 MYDNSJP_MasterID
="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}"
31 MYDNSJP_Password
="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}"
32 if [ -z "$MYDNSJP_MasterID" ] ||
[ -z "$MYDNSJP_Password" ]; then
35 _err
"You don't specify mydnsjp api MasterID and Password yet."
36 _err
"Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again."
40 # Save the credentials to the account conf file
41 _saveaccountconf_mutable MYDNSJP_MasterID
"$MYDNSJP_MasterID"
42 _saveaccountconf_mutable MYDNSJP_Password
"$MYDNSJP_Password"
44 _debug
"First detect the root zone."
45 if ! _get_root
"$fulldomain"; then
50 _debug _sub_domain
"$_sub_domain"
51 _debug _domain
"$_domain"
53 if _mydnsjp_api
"REGIST" "$_domain" "$txtvalue"; then
54 if printf -- "%s" "$response" |
grep "OK." >/dev
/null
; then
58 _err
"Add txt record error."
62 _err
"Add txt record error."
67 #Usage: fulldomain txtvalue
68 #Remove the txt record after validation.
73 _info
"Removing TXT record"
74 _debug fulldomain
"$fulldomain"
75 _debug txtvalue
"$txtvalue"
77 # Load the credentials from the account conf file
78 MYDNSJP_MasterID
="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}"
79 MYDNSJP_Password
="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}"
80 if [ -z "$MYDNSJP_MasterID" ] ||
[ -z "$MYDNSJP_Password" ]; then
83 _err
"You don't specify mydnsjp api MasterID and Password yet."
84 _err
"Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again."
88 _debug
"First detect the root zone"
89 if ! _get_root
"$fulldomain"; then
94 _debug _sub_domain
"$_sub_domain"
95 _debug _domain
"$_domain"
97 if _mydnsjp_api
"DELETE" "$_domain" "$txtvalue"; then
98 if printf -- "%s" "$response" |
grep "OK." >/dev
/null
; then
102 _err
"Delete txt record error."
106 _err
"Delete txt record error."
111 #################### Private functions below ##################################
112 # _acme-challenge.www.domain.com
114 # _sub_domain=_acme-challenge.www
121 # Get the root domain
122 _mydnsjp_retrieve_domain
123 if [ "$?" != "0" ]; then
129 _domain
=$
(printf "%s" "$fulldomain" | cut
-d .
-f $i-100)
131 if [ -z "$_domain" ]; then
136 if [ "$_domain" = "$_root_domain" ]; then
137 _sub_domain
=$
(printf "%s" "$fulldomain" | cut
-d .
-f 1-$p)
148 # Retrieve the root domain
150 _mydnsjp_retrieve_domain
() {
151 _debug
"Login to MyDNS.JP"
153 response
="$(_post "MENU
=100&masterid
=$MYDNSJP_MasterID&masterpwd
=$MYDNSJP_Password" "$MYDNSJP_API/members
/")"
154 cookie
="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _head_n 1 | cut -d " " -f 2)"
156 # If cookies is not empty then logon successful
157 if [ -z "$cookie" ]; then
158 _err
"Fail to get a cookie."
162 _root_domain
=$
(echo "$response" |
grep "DNSINFO\[domainname\]" |
sed 's/^.*value="\([^"]*\)".*/\1/')
164 _debug _root_domain
"$_root_domain"
166 if [ -z "$_root_domain" ]; then
167 _err
"Fail to get the root domain."
179 # Base64 encode the credentials
180 credentials
=$
(printf "%s:%s" "$MYDNSJP_MasterID" "$MYDNSJP_Password" | _base64
)
182 # Construct the HTTP Authorization header
183 export _H1
="Content-Type: application/x-www-form-urlencoded"
184 export _H2
="Authorization: Basic ${credentials}"
186 response
="$(_post "CERTBOT_DOMAIN
=$domain&CERTBOT_VALIDATION
=$txtvalue&EDIT_CMD
=$cmd" "$MYDNSJP_API/directedit.html
")"
188 if [ "$?" != "0" ]; then
193 _debug2 response
"$response"