123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #!/usr/bin/env sh
- dns_da_add() {
- fulldomain="${1}"
- txtvalue="${2}"
- _debug "Calling: dns_da_add() '${fulldomain}' '${txtvalue}'"
- _DA_credentials && _DA_getDomainInfo && _DA_addTxt
- }
- dns_da_rm() {
- fulldomain="${1}"
- txtvalue="${2}"
- _debug "Calling: dns_da_rm() '${fulldomain}' '${txtvalue}'"
- _DA_credentials && _DA_getDomainInfo && _DA_rmTxt
- }
- _DA_credentials() {
- DA_Api="${DA_Api:-$(_readaccountconf_mutable DA_Api)}"
- DA_Api_Insecure="${DA_Api_Insecure:-$(_readaccountconf_mutable DA_Api_Insecure)}"
- if [ -z "${DA_Api}" ] || [ -z "${DA_Api_Insecure}" ]; then
- DA_Api=""
- DA_Api_Insecure=""
- _err "You haven't specified the DirectAdmin Login data, URL and whether you want check the DirectAdmin SSL cert. Please try again."
- return 1
- else
- _saveaccountconf_mutable DA_Api "${DA_Api}"
- _saveaccountconf_mutable DA_Api_Insecure "${DA_Api_Insecure}"
-
- export HTTPS_INSECURE="${DA_Api_Insecure}"
- fi
- }
- _get_root() {
- domain=$1
- i=2
- p=1
-
-
- _da_api CMD_API_SHOW_DOMAINS "" "${domain}"
- while true; do
- h=$(printf "%s" "$domain" | cut -d . -f $i-100)
- _debug h "$h"
- if [ -z "$h" ]; then
-
- _debug "The given domain $h is not valid"
- return 1
- fi
- if _contains "$response" "$h" >/dev/null; then
- _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
- _domain=$h
- return 0
- fi
- p=$i
- i=$(_math "$i" + 1)
- done
- _debug "Stop on 100"
- return 1
- }
- _da_api() {
- cmd=$1
- data=$2
- domain=$3
- _debug "$domain; $data"
- response="$(_post "$data" "$DA_Api/$cmd" "" "POST")"
- if [ "$?" != "0" ]; then
- _err "error $cmd"
- return 1
- fi
- _debug response "$response"
- case "${cmd}" in
- CMD_API_DNS_CONTROL)
-
-
-
- err_field="$(_getfield "$response" 1 '&')"
- txt_field="$(_getfield "$response" 2 '&')"
- details_field="$(_getfield "$response" 3 '&')"
- error="$(_getfield "$err_field" 2 '=')"
- text="$(_getfield "$txt_field" 2 '=')"
- details="$(_getfield "$details_field" 2 '=')"
- _debug "error: ${error}, text: ${text}, details: ${details}"
- if [ "$error" != "0" ]; then
- _err "error $response"
- return 1
- fi
- ;;
- CMD_API_SHOW_DOMAINS) ;;
- esac
- return 0
- }
- _DA_getDomainInfo() {
- _debug "First detect the root zone"
- if ! _get_root "$fulldomain"; then
- _err "invalid domain"
- return 1
- else
- _debug "The root domain: $_domain"
- _debug "The sub domain: $_sub_domain"
- fi
- return 0
- }
- _DA_addTxt() {
- curData="domain=${_domain}&action=add&type=TXT&name=${_sub_domain}&value=\"${txtvalue}\""
- _debug "Calling _DA_addTxt: '${curData}' '${DA_Api}/CMD_API_DNS_CONTROL'"
- _da_api CMD_API_DNS_CONTROL "${curData}" "${_domain}"
- _debug "Result of _DA_addTxt: '$response'"
- if _contains "${response}" 'error=0'; then
- _debug "Add TXT succeeded"
- return 0
- fi
- _debug "Add TXT failed"
- return 1
- }
- _DA_rmTxt() {
- curData="domain=${_domain}&action=select&txtrecs0=name=${_sub_domain}&value=\"${txtvalue}\""
- _debug "Calling _DA_rmTxt: '${curData}' '${DA_Api}/CMD_API_DNS_CONTROL'"
- if _da_api CMD_API_DNS_CONTROL "${curData}" "${_domain}"; then
- _debug "Result of _DA_rmTxt: '$response'"
- else
- _err "Result of _DA_rmTxt: '$response'"
- fi
- if _contains "${response}" 'error=0'; then
- _debug "RM TXT succeeded"
- return 0
- fi
- _debug "RM TXT failed"
- return 1
- }
|