diff --git a/dnsapi/dns_plesk.sh b/dnsapi/dns_plesk.sh index 5896f80b..1a5647b5 100644 --- a/dnsapi/dns_plesk.sh +++ b/dnsapi/dns_plesk.sh @@ -16,15 +16,13 @@ dns_plesk_add() { txtvalue=$2 PLESK_Host="${CF_Key:-$(_readaccountconf_mutable PLESK_Host)}" - PLESK_SiteName="${CF_Key:-$(_readaccountconf_mutable PLESK_SiteName)}" PLESK_User="${CF_Key:-$(_readaccountconf_mutable PLESK_User)}" PLESK_Password="${CF_Key:-$(_readaccountconf_mutable PLESK_Password)}" - if [ -z "$PLESK_Host" ] || [ -z "$PLESK_User" ] || [ -z "$PLESK_Password"] || [ -z "$PLESK_SiteName"]; then + if [ -z "$PLESK_Host" ] || [ -z "$PLESK_User" ] || [ -z "$PLESK_Password"]; then PLESK_Host="" PLESK_User="" PLESK_Password="" - PLESK_SiteName="" _err "You didn't specify a plesk credentials yet." _err "Please create the key and try again." return 1 @@ -34,8 +32,7 @@ dns_plesk_add() { _saveaccountconf_mutable PLESK_Host "$PLESK_Host" _saveaccountconf_mutable PLESK_User "$PLESK_User" _saveaccountconf_mutable PLESK_Password "$PLESK_Password" - _saveaccountconf_mutable PLESK_SiteName "$PLESK_SiteName" - + _debug "First detect the root zone" if ! _get_root "$fulldomain"; then _err "invalid domain" @@ -50,6 +47,42 @@ dns_plesk_add() { } +#fulldomain txtvalue +dns_plesk_rm() { + fulldomain=$1 + txtvalue=$2 + + PLESK_Host="${CF_Key:-$(_readaccountconf_mutable PLESK_Host)}" + PLESK_User="${CF_Key:-$(_readaccountconf_mutable PLESK_User)}" + PLESK_Password="${CF_Key:-$(_readaccountconf_mutable PLESK_Password)}" + + if [ -z "$PLESK_Host" ] || [ -z "$PLESK_User" ] || [ -z "$PLESK_Password"]; then + PLESK_Host="" + PLESK_User="" + PLESK_Password="" + _err "You didn't specify a plesk credentials yet." + _err "Please create the key and try again." + return 1 + fi + + #save the api key and email to the account conf file. + _saveaccountconf_mutable PLESK_Host "$PLESK_Host" + _saveaccountconf_mutable PLESK_User "$PLESK_User" + _saveaccountconf_mutable PLESK_Password "$PLESK_Password" + + _debug "First detect the root zone" + if ! _get_root "$fulldomain"; then + _err "invalid domain" + return 1 + fi + _debug _domain_id "$_domain_id" + _debug _sub_domain "$_sub_domain" + _debug _domain "$_domain" + + _info "Remove record" + del_txt_record $_domain_id $fulldomain +} + function plesk_api() { local request="$1" @@ -78,6 +111,32 @@ function add_txt_record() { return 0 } +function del_txt_record() { + local site_id=$1 + local fulldomain="${2}." + + get_dns_record_list $site_id + + j=0 + for item in "${_plesk_dns_host[@]}" + do + _debug "item" $item + if [ "$fulldomain" = "$item" ]; then + _dns_record_id=${_plesk_dns_ids[$j]} + fi + j=$(_math "$j" +1) + done + + _debug "record id" "$_dns_record_id" + local request="$_dns_record_id" + plesk_api $request + + if ! _contains "${response}" 'ok'; then + return 1 + fi + return 0 +} + function get_domain_list() { local request='' @@ -91,6 +150,21 @@ function get_domain_list() { _plesk_domain_ids=($(echo "${response}"| sed -nr 's_(.*)_\1_p')); _plesk_domain_ids=("${_plesk_domain_ids[@]:1}") +} + +function get_dns_record_list() { + local siteid=$1 + local request="$siteid" + + plesk_api $request + + if ! _contains "${response}" 'ok'; then + return 1 + fi + + _plesk_dns_host=($(echo "${response}" | sed -nr 's_(.*)_\1_p')); + _plesk_dns_ids=($(echo "${response}"| sed -nr 's_(.*)_\1_p')); + } #urls=($(sed -nr 's_(.*)_\1_p' resp.txt)); echo ${urls[@]}