@ -18,46 +18,46 @@ FastVps_EndPoint="https://fastdns.fv.ee"
dns_fastvps_add( ) {
dns_fastvps_add( ) {
fulldomain = $1
fulldomain = $1
txtvalue = $2
txtvalue = $2
FastVps_Secret = " ${ FastVps_Secret :- $( _readaccountconf_mutable FastVps_Secret) } "
FastVps_Secret = " ${ FastVps_Secret :- $( _readaccountconf_mutable FastVps_Secret) } "
FastVps_Token = " ${ FastVps_Token :- $( _readaccountconf_mutable FastVps_Token) } "
FastVps_Token = " ${ FastVps_Token :- $( _readaccountconf_mutable FastVps_Token) } "
if [ -z " $FastVps_Secret " ] ; then
if [ -z " $FastVps_Secret " ] ; then
FastVps_Secret = ""
FastVps_Secret = ""
_err "FastVps secret is not specified."
_err "FastVps secret is not specified."
_err "Please create secret https://bill2fast.com/dns and try again."
_err "Please create secret https://bill2fast.com/dns and try again."
return 1
return 1
fi
fi
#save the secret to the account conf file.
#save the secret to the account conf file.
_saveaccountconf_mutable FastVps_Secret " $FastVps_Secret "
_saveaccountconf_mutable FastVps_Secret " $FastVps_Secret "
if [ -z " $FastVps_Token " ] ; then
if [ -z " $FastVps_Token " ] ; then
_info "Getting FastVps token."
_info "Getting FastVps token."
if ! _fastvps_authentication; then
if ! _fastvps_authentication; then
_err "Can not get token."
_err "Can not get token."
fi
fi
fi
fi
_debug "Detect root zone"
_debug "Detect root zone"
if ! _get_root " $fulldomain " ; then
if ! _get_root " $fulldomain " ; then
_err "Invalid domain."
_err "Invalid domain."
return 1
return 1
fi
fi
_debug _node " $_node "
_debug _node " $_node "
_debug _domain_name " $_domain_name "
_debug _domain_name " $_domain_name "
_info "Creating TXT record."
_info "Creating TXT record."
if ! _fastvps_rest POST " api/domains/ $dnsId /records " " {\"name\":\" $_node \",\"type\":\"TXT\",\"content\":\" $txtvalue \",\"ttl\":90} " ; then
if ! _fastvps_rest POST " api/domains/ $dnsId /records " " {\"name\":\" $_node \",\"type\":\"TXT\",\"content\":\" $txtvalue \",\"ttl\":90} " ; then
return 1
return 1
fi
fi
if _contains " $response " "errors" ; then
if _contains " $response " "errors" ; then
_err "Could not add TXT record."
_err "Could not add TXT record."
return 1
return 1
fi
fi
return 0
return 0
}
}
@ -65,51 +65,51 @@ dns_fastvps_add() {
dns_fastvps_rm( ) {
dns_fastvps_rm( ) {
fulldomain = $1
fulldomain = $1
txtvalue = $2
txtvalue = $2
FastVps_Secret = " ${ FastVps_Secret :- $( _readaccountconf_mutable FastVps_Secret) } "
FastVps_Secret = " ${ FastVps_Secret :- $( _readaccountconf_mutable FastVps_Secret) } "
FastVps_Token = " ${ FastVps_Token :- $( _readaccountconf_mutable FastVps_Token) } "
FastVps_Token = " ${ FastVps_Token :- $( _readaccountconf_mutable FastVps_Token) } "
if [ -z " $FastVps_Secret " ] ; then
if [ -z " $FastVps_Secret " ] ; then
FastVps_Secret = ""
FastVps_Secret = ""
_err "Please create you API secret and try again."
_err "Please create you API secret and try again."
return 1
return 1
fi
fi
#save the secret to the account conf file.
#save the secret to the account conf file.
_saveaccountconf_mutable FastVps_Secret " $FastVps_Secret "
_saveaccountconf_mutable FastVps_Secret " $FastVps_Secret "
if [ -z " $FastVps_Token " ] ; then
if [ -z " $FastVps_Token " ] ; then
_info "Getting FastVps token."
_info "Getting FastVps token."
if ! _fastvps_authentication; then
if ! _fastvps_authentication; then
_err "Can not get token."
_err "Can not get token."
fi
fi
fi
fi
_debug "Detect root zone."
_debug "Detect root zone."
if ! _get_root " $fulldomain " ; then
if ! _get_root " $fulldomain " ; then
_err "Invalid domain."
_err "Invalid domain."
return 1
return 1
fi
fi
_debug _node " $_node "
_debug _node " $_node "
_debug _domain_name " $_domain_name "
_debug _domain_name " $_domain_name "
_info "Checking for TXT record."
_info "Checking for TXT record."
if ! _get_recordid " $fulldomain " " $txtvalue " ; then
if ! _get_recordid " $fulldomain " " $txtvalue " ; then
_err "Could not get TXT record id."
_err "Could not get TXT record id."
return 1
return 1
fi
fi
if [ " $_dns_record_id " = "" ] ; then
if [ " $_dns_record_id " = "" ] ; then
_err "TXT record not found."
_err "TXT record not found."
return 1
return 1
fi
fi
_info "Removing TXT record."
_info "Removing TXT record."
if ! _delete_txt_record " $_dns_record_id " ; then
if ! _delete_txt_record " $_dns_record_id " ; then
_err " Could not remove TXT record $_dns_record_id . "
_err " Could not remove TXT record $_dns_record_id . "
fi
fi
return 0
return 0
}
}
@ -129,11 +129,11 @@ _get_root() {
#not valid
#not valid
return 1
return 1
fi
fi
if ! _fastvps_rest GET " api/domains/ $h /name " ; then
if ! _fastvps_rest GET " api/domains/ $h /name " ; then
return 1
return 1
fi
fi
if _contains " $response " " \"name\":\" $h \" " >/dev/null; then
if _contains " $response " " \"name\":\" $h \" " >/dev/null; then
dnsId = $( printf "%s" " $response " | grep -Po '(?<="id":)[^,"\\]*(?:\\.[^"\\]*)*' )
dnsId = $( printf "%s" " $response " | grep -Po '(?<="id":)[^,"\\]*(?:\\.[^"\\]*)*' )
_domain_name = $h
_domain_name = $h
@ -144,37 +144,37 @@ _get_root() {
i = $( _math " $i " + 1)
i = $( _math " $i " + 1)
done
done
return 1
return 1
}
}
_get_recordid( ) {
_get_recordid( ) {
fulldomain = $1
fulldomain = $1
txtvalue = $2
txtvalue = $2
if ! _fastvps_rest GET " api/domains/ $dnsId /records " ; then
if ! _fastvps_rest GET " api/domains/ $dnsId /records " ; then
return 1
return 1
fi
fi
if ! _contains " $response " " $txtvalue " ; then
if ! _contains " $response " " $txtvalue " ; then
_dns_record_id = 0
_dns_record_id = 0
return 0
return 0
fi
fi
_dns_record_id = $( printf "%s" " $response " | sed -e 's/[^{]*\({[^}]*}\)[^{]*/\1\n/g' | grep " \"content\":\" $txtvalue \" " | sed -e 's/.*"id":"\([^",]*\).*/\1/' )
_dns_record_id = $( printf "%s" " $response " | sed -e 's/[^{]*\({[^}]*}\)[^{]*/\1\n/g' | grep " \"content\":\" $txtvalue \" " | sed -e 's/.*"id":"\([^",]*\).*/\1/' )
return 0
return 0
}
}
_delete_txt_record( ) {
_delete_txt_record( ) {
_dns_record_id = $1
_dns_record_id = $1
if ! _fastvps_rest DELETE " api/domains/ $dnsId /records/ $_dns_record_id " ; then
if ! _fastvps_rest DELETE " api/domains/ $dnsId /records/ $_dns_record_id " ; then
return 1
return 1
fi
fi
if _contains " $response " "errors" ; then
if _contains " $response " "errors" ; then
return 1
return 1
fi
fi
return 0
return 0
}
}
@ -183,10 +183,10 @@ _fastvps_rest() {
ep = " $2 "
ep = " $2 "
data = " $3 "
data = " $3 "
_debug " $ep "
_debug " $ep "
export _H1 = " Authorization: Bearer $FastVps_Token "
export _H1 = " Authorization: Bearer $FastVps_Token "
export _H2 = "Content-Type: application/json"
export _H2 = "Content-Type: application/json"
if [ " $data " ] || [ " $m " = "DELETE" ] ; then
if [ " $data " ] || [ " $m " = "DELETE" ] ; then
_debug data " $data "
_debug data " $data "
response = " $( _post " $data " " $FastVps_EndPoint / $ep " "" " $m " ) "
response = " $( _post " $data " " $FastVps_EndPoint / $ep " "" " $m " ) "
@ -194,7 +194,7 @@ _fastvps_rest() {
_info " Getting $FastVps_EndPoint / $ep "
_info " Getting $FastVps_EndPoint / $ep "
response = " $( _get " $FastVps_EndPoint / $ep " ) "
response = " $( _get " $FastVps_EndPoint / $ep " ) "
fi
fi
# shellcheck disable=SC2181
# shellcheck disable=SC2181
if [ " $? " != "0" ] ; then
if [ " $? " != "0" ] ; then
_err " error $ep "
_err " error $ep "
@ -205,12 +205,12 @@ _fastvps_rest() {
}
}
_fastvps_authentication( ) {
_fastvps_authentication( ) {
export _H1 = " Authenticate: $FastVps_Secret "
export _H1 = " Authenticate: $FastVps_Secret "
export _H2 = "Content-Type: application/json"
export _H2 = "Content-Type: application/json"
response = " $( _post "" " $FastVps_EndPoint /login_token " "" "" ) "
response = " $( _post "" " $FastVps_EndPoint /login_token " "" "" ) "
# shellcheck disable=SC2181
# shellcheck disable=SC2181
if [ " $? " != "0" ] ; then
if [ " $? " != "0" ] ; then
_err "Authentication failed."
_err "Authentication failed."
@ -223,7 +223,7 @@ _fastvps_authentication() {
FastVps_Token = ""
FastVps_Token = ""
fi
fi
_info "Authentication success"
_info "Authentication success"
_debug2 response " $response "
_debug2 response " $response "
return 0
return 0
}
}