_err "You don't specify dnsla api id and key yet."
_err "You didn't specify a dnsla api id and key yet."
_err "Please create your key and try again."
return1
return1
fi
fi
@ -25,13 +26,30 @@ dns_la_add() {
_saveaccountconf_mutable LA_Id "$LA_Id"
_saveaccountconf_mutable LA_Id "$LA_Id"
_saveaccountconf_mutable LA_Key "$LA_Key"
_saveaccountconf_mutable LA_Key "$LA_Key"
_debug "detect the root zone"
_debug "First detect the root zone"
if ! _get_root "$fulldomain";then
if ! _get_root "$fulldomain";then
_err "invalid domain"
_err "invalid domain"
return1
return1
fi
fi
_debug _domain_id "$_domain_id"
add_record "$_domain""$_sub_domain""$txtvalue"
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
_info "Adding record"
if _la_rest "record.ashx?cmd=create&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue&recordline=";then
if _contains "$response"'"resultid":';then
_info "Added, OK"
return0
elif _contains "$response"'"code":532';then
_info "Already exists, OK"
return0
else
_err "Add txt record error."
return1
fi
fi
_err "Add txt record error."
return1
}
}
@ -48,45 +66,33 @@ dns_la_rm() {
_err "invalid domain"
_err "invalid domain"
return1
return1
fi
fi
_debug _domain_id "$_domain_id"
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
if ! _rest GET "record.ashx?cmd=listn&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue";then
_debug "Getting txt records"
_err "get record list error."
if ! _la_rest "record.ashx?cmd=listn&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue";then
if ! _rest GET "record.ashx?cmd=remove&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&recordid=$_record_id";then
_err "Can not get record id to remove."
_err "record remove error."
return1
return1
fi
fi
if ! _la_rest "record.ashx?cmd=remove&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&recordid=$record_id";then
_contains "$response""\"code\":300"
_err "Delete record error."
}
#add the txt record.
#usage: root sub txtvalue
add_record(){
root=$1
sub=$2
txtvalue=$3
fulldomain="$sub.$root"
_info "adding txt record"
if ! _rest GET "record.ashx?cmd=create&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue&recordline=";then
return1
return1
fi
fi
_contains "$response"'"code":300'
if _contains "$response""resultid"|| _contains "$response""\"code\":532";then