improved handling for third level domains

This commit is contained in:
linux-insideDE 2018-05-29 16:23:28 +02:00 committed by GitHub
parent 4715a1a5e0
commit 48e8022095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,48 +18,33 @@ dns_netcup_add() {
_saveaccountconf_mutable NC_CID "$NC_CID" _saveaccountconf_mutable NC_CID "$NC_CID"
fulldomain=$1 fulldomain=$1
txtvalue=$2 txtvalue=$2
tld=""
domain="" domain=""
exit=0 exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
i=20 exit=$(_math "$exit" + 1)
while [ "$i" -gt 0 ]; i=$exit
do
tmp=$(echo "$fulldomain" | cut -d'.' -f$i)
if [ "$tmp" != "" ]; then
if [ "$tld" = "" ]; then
tld=$tmp
else
domain=$tmp
exit=$i
break;
fi
fi
i=$(_math "$i" - 1)
done
inc=""
i=1
while [ "$i" -lt "$exit" ];
do
if [ "$((exit-1))" = "$i" ]; then
inc="$inc$i"
break;
else
if [ "$inc" = "" ]; then
inc="$i,"
else
inc="$inc$i,"
fi
fi
i=$(_math "$i" + 1)
done
tmp=$(echo "$fulldomain" | cut -d'.' -f$inc) while [ "$exit" -gt 0 ]
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain.$tld\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") do
_debug "$msg" tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
_err "$msg" domain="$tmp"
return 1 else
fi domain="$tmp.$domain"
fi
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST")
_debug "$msg"
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
_err "$msg"
return 1
else
break;
fi
fi
fi
exit=$(_math "$exit" - 1)
done
logout logout
} }
@ -67,43 +52,36 @@ dns_netcup_rm() {
login login
fulldomain=$1 fulldomain=$1
txtvalue=$2 txtvalue=$2
tld=""
domain="" domain=""
exit=0 exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
i=20 exit=$(_math "$exit" + 1)
while [ "$i" -gt 0 ]; i=$exit
rec=""
while [ "$exit" -gt 0 ]
do do
tmp=$(echo "$fulldomain" | cut -d'.' -f$i) tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
if [ "$tmp" != "" ]; then if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
if [ "$tld" = "" ]; then domain="$tmp"
tld=$tmp
else
domain=$tmp
exit=$i
break;
fi
fi
i=$(_math "$i" - 1)
done
inc=""
i=1
while [ "$i" -lt "$exit" ];
do
if [ "$((exit-1))" = "$i" ]; then
inc="$inc$i"
break;
else else
if [ "$inc" = "" ]; then domain="$tmp.$domain"
inc="$i," fi
else if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
inc="$inc$i," msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST")
rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
_debug "$msg"
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
_err "$msg"
return 1
else
break;
fi
fi fi
fi fi
i=$(_math "$i" + 1) exit=$(_math "$exit" - 1)
done done
tmp=$(echo "$fulldomain" | cut -d'.' -f$inc)
doma="$domain.$tld"
rec=$(getRecords "$doma")
ida=0000 ida=0000
idv=0001 idv=0001
@ -123,8 +101,9 @@ dns_netcup_rm() {
if [ "$ida" = "$idv" ]; then if [ "$ida" = "$idv" ]; then
i=0 i=0
fi fi
done done
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$doma\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST")
msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST")
_debug "$msg" _debug "$msg"
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
_err "$msg" _err "$msg"
@ -150,13 +129,3 @@ logout() {
return 1 return 1
fi fi
} }
getRecords() {
tmp2=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$1\"}}" "$end" "" "POST")
out=$(echo "$tmp2" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
echo "$out"
_debug "$tmp2"
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
_err "$msg"
return 1
fi
}