123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #!/usr/bin/env sh
- MYDNSJP_API="https://www.mydns.jp"
- dns_mydnsjp_add() {
- fulldomain=$1
- txtvalue=$2
- _info "Using mydnsjp"
- _debug fulldomain "$fulldomain"
- _debug txtvalue "$txtvalue"
-
- MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}"
- MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}"
- if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then
- MYDNSJP_MasterID=""
- MYDNSJP_Password=""
- _err "You don't specify mydnsjp api MasterID and Password yet."
- _err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again."
- return 1
- fi
-
- _saveaccountconf_mutable MYDNSJP_MasterID "$MYDNSJP_MasterID"
- _saveaccountconf_mutable MYDNSJP_Password "$MYDNSJP_Password"
- _debug "First detect the root zone."
- if ! _get_root "$fulldomain"; then
- _err "invalid domain"
- return 1
- fi
- _debug _sub_domain "$_sub_domain"
- _debug _domain "$_domain"
- if _mydnsjp_api "REGIST" "$_domain" "$txtvalue"; then
- if printf -- "%s" "$response" | grep "OK." >/dev/null; then
- _info "Added, OK"
- return 0
- else
- _err "Add txt record error."
- return 1
- fi
- fi
- _err "Add txt record error."
- return 1
- }
- dns_mydnsjp_rm() {
- fulldomain=$1
- txtvalue=$2
- _info "Removing TXT record"
- _debug fulldomain "$fulldomain"
- _debug txtvalue "$txtvalue"
-
- MYDNSJP_MasterID="${MYDNSJP_MasterID:-$(_readaccountconf_mutable MYDNSJP_MasterID)}"
- MYDNSJP_Password="${MYDNSJP_Password:-$(_readaccountconf_mutable MYDNSJP_Password)}"
- if [ -z "$MYDNSJP_MasterID" ] || [ -z "$MYDNSJP_Password" ]; then
- MYDNSJP_MasterID=""
- MYDNSJP_Password=""
- _err "You don't specify mydnsjp api MasterID and Password yet."
- _err "Please export as MYDNSJP_MasterID / MYDNSJP_Password and try again."
- return 1
- fi
- _debug "First detect the root zone"
- if ! _get_root "$fulldomain"; then
- _err "invalid domain"
- return 1
- fi
- _debug _sub_domain "$_sub_domain"
- _debug _domain "$_domain"
- if _mydnsjp_api "DELETE" "$_domain" "$txtvalue"; then
- if printf -- "%s" "$response" | grep "OK." >/dev/null; then
- _info "Deleted, OK"
- return 0
- else
- _err "Delete txt record error."
- return 1
- fi
- fi
- _err "Delete txt record error."
- return 1
- }
- _get_root() {
- fulldomain=$1
- i=2
- p=1
-
- _mydnsjp_retrieve_domain
- if [ "$?" != "0" ]; then
-
- return 1
- fi
- while true; do
- _domain=$(printf "%s" "$fulldomain" | cut -d . -f $i-100)
- if [ -z "$_domain" ]; then
-
- return 1
- fi
- if [ "$_domain" = "$_root_domain" ]; then
- _sub_domain=$(printf "%s" "$fulldomain" | cut -d . -f 1-$p)
- return 0
- fi
- p=$i
- i=$(_math "$i" + 1)
- done
- return 1
- }
- _mydnsjp_retrieve_domain() {
- _debug "Login to MyDNS.JP"
- response="$(_post "masterid=$MYDNSJP_MasterID&masterpwd=$MYDNSJP_Password" "$MYDNSJP_API/?MENU=100")"
- cookie="$(grep -i '^set-cookie:' "$HTTP_HEADER" | _head_n 1 | cut -d " " -f 2)"
-
- if [ -z "$cookie" ]; then
- _err "Fail to get a cookie."
- return 1
- fi
- _debug "Retrieve DOMAIN INFO page"
- export _H1="Cookie:${cookie}"
- response="$(_get "$MYDNSJP_API/?MENU=300")"
- if [ "$?" != "0" ]; then
- _err "Fail to retrieve DOMAIN INFO."
- return 1
- fi
- _root_domain=$(echo "$response" | grep "DNSINFO\[domainname\]" | sed 's/^.*value="\([^"]*\)".*/\1/')
-
- response="$(_get "$MYDNSJP_API/?MENU=090")"
- _debug _root_domain "$_root_domain"
- if [ -z "$_root_domain" ]; then
- _err "Fail to get the root domain."
- return 1
- fi
- return 0
- }
- _mydnsjp_api() {
- cmd=$1
- domain=$2
- txtvalue=$3
-
- credentials=$(printf "%s:%s" "$MYDNSJP_MasterID" "$MYDNSJP_Password" | _base64)
-
- export _H1="Content-Type: application/x-www-form-urlencoded"
- export _H2="Authorization: Basic ${credentials}"
- response="$(_post "CERTBOT_DOMAIN=$domain&CERTBOT_VALIDATION=$txtvalue&EDIT_CMD=$cmd" "$MYDNSJP_API/directedit.html")"
- if [ "$?" != "0" ]; then
- _err "error $domain"
- return 1
- fi
- _debug2 response "$response"
- return 0
- }
|