Browse Source

cleanup according to styleguide / ShellCheck

pull/2843/head
der-berni 5 years ago
committed by GitHub
parent
commit
da7b1fb014
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      dnsapi/dns_one.sh

55
dnsapi/dns_one.sh

@ -7,6 +7,9 @@
# Fixed by: @der-berni
# Modified: 2020-04-07
#
# Use ONECOM_KeepCnameProxy to keep the CNAME DNS record
# export ONECOM_KeepCnameProxy="1"
#
# export ONECOM_User="username"
# export ONECOM_Password="password"
#
@ -56,14 +59,14 @@ dns_one_add() {
#Check if the TXT exists
_dns_one_getrecord "TXT" "$subdomain" "$txtvalue"
if [ ! -z "$id" ]; then
if [ -n "$id" ]; then
_info "$(__green "Txt record with the same value found. Skip adding.")"
return 0
fi
_dns_one_addrecord "TXT" "$subdomain" "$txtvalue"
if [ -z "$id" ]; then
_err "Add CNAME record error."
_err "Add TXT record error."
return 1
else
_info "$(__green "Added, OK ($id)")"
@ -98,16 +101,16 @@ dns_one_rm() {
_debug subdomain "$subdomain"
_debug maindomain "$maindomain"
if [ $useProxy -eq 1 ]; then
if [ "$ONECOM_KeepCnameProxy" = "1" ]; then
_info "$(__red "Keeping CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")"
else
#Check if the CNAME exists
_dns_one_getrecord "CNAME" "$_sub_domain" "$subdomain.$maindomain"
if [ ! -z "$id" ]; then
_info "$(__red "Removing CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")"
_dns_one_delrecord "$id"
fi
if [ "$ONECOM_KeepCnameProxy" = "1" ]; then
_info "$(__red "Keeping CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")"
else
#Check if the CNAME exists
_dns_one_getrecord "CNAME" "$_sub_domain" "$subdomain.$maindomain"
if [ -n "$id" ]; then
_info "$(__red "Removing CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")"
_dns_one_delrecord "$id"
fi
fi
fi
#Check if the TXT exists
@ -118,13 +121,12 @@ dns_one_rm() {
fi
# delete entry
if _dns_one_delrecord "$id"; then
_info "$(__green Removed, OK)"
return 0
_info "$(__green Removed, OK)"
return 0
else
_err "Removing txt record error."
return 1
_err "Removing txt record error."
return 1
fi
}
@ -162,6 +164,7 @@ _dns_one_login() {
# get credentials
ONECOM_KeepCnameProxy="${ONECOM_KeepCnameProxy:-$(_readaccountconf_mutable ONECOM_KeepCnameProxy)}"
ONECOM_KeepCnameProxy="${ONECOM_KeepCnameProxy:-0}"
ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
@ -173,6 +176,7 @@ _dns_one_login() {
fi
#save the api key and email to the account conf file.
_saveaccountconf_mutable ONECOM_KeepCnameProxy "$ONECOM_KeepCnameProxy"
_saveaccountconf_mutable ONECOM_User "$ONECOM_User"
_saveaccountconf_mutable ONECOM_Password "$ONECOM_Password"
@ -207,11 +211,11 @@ _dns_one_getrecord() {
name="$2"
value="$3"
if [ -z "$type" ]; then
type="TXT"
type="TXT"
fi
if [ -z "$name" ]; then
_err "Record name is empty."
return 1
_err "Record name is empty."
return 1
fi
response="$(_get "https://www.one.com/admin/api/domains/$maindomain/dns/custom_records")"
@ -225,7 +229,6 @@ _dns_one_getrecord() {
id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"${value}\",\"priority\":0,\"ttl\":600}.*/\1/p")
fi
if [ -z "$id" ]; then
_err "Record not found."
return 1
fi
return 0
@ -236,11 +239,11 @@ _dns_one_addrecord() {
name="$2"
value="$3"
if [ -z "$type" ]; then
type="TXT"
type="TXT"
fi
if [ -z "$name" ]; then
_err "Record name is empty."
return 1
_err "Record name is empty."
return 1
fi
postdata="{\"type\":\"dns_custom_records\",\"attributes\":{\"priority\":0,\"ttl\":600,\"type\":\"${type}\",\"prefix\":\"${name}\",\"content\":\"${value}\"}}"
@ -261,7 +264,7 @@ _dns_one_addrecord() {
_dns_one_delrecord() {
id="$1"
if [ -z "$id" ]; then
return 1
return 1
fi
response="$(_post "" "https://www.one.com/admin/api/domains/$maindomain/dns/custom_records/$id" "" "DELETE" "application/json")"
@ -269,8 +272,8 @@ _dns_one_delrecord() {
_debug response "$response"
if [ "$response" = '{"result":null,"metadata":null}' ]; then
return 0
return 0
else
return 1
return 1
fi
}
Loading…
Cancel
Save