Browse Source

improved handling for third level domains

master
linux-insideDE 7 years ago
committed by GitHub
parent
commit
48e8022095
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 115
      dnsapi/dns_netcup.sh

115
dnsapi/dns_netcup.sh

@ -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
i=20
while [ "$i" -gt 0 ];
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" ];
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
exit=$(_math "$exit" + 1)
i=$exit
while [ "$exit" -gt 0 ]
do do
if [ "$((exit-1))" = "$i" ]; then
inc="$inc$i"
break;
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
domain="$tmp"
else else
if [ "$inc" = "" ]; then
inc="$i,"
else
inc="$inc$i,"
fi
domain="$tmp.$domain"
fi fi
i=$(_math "$i" + 1)
done
tmp=$(echo "$fulldomain" | cut -d'.' -f$inc)
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")
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" _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 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
_err "$msg" _err "$msg"
return 1 return 1
else
break;
fi 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
i=20
while [ "$i" -gt 0 ];
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
exit=$(_math "$exit" + 1)
i=$exit
rec=""
while [ "$exit" -gt 0 ]
do do
tmp=$(echo "$fulldomain" | cut -d'.' -f$i)
if [ "$tmp" != "" ]; then
if [ "$tld" = "" ]; then
tld=$tmp
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
domain="$tmp"
else else
domain=$tmp
exit=$i
break;
fi
domain="$tmp.$domain"
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,"
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
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 else
inc="$inc$i,"
break;
fi fi
fi fi
i=$(_math "$i" + 1)
fi
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
@ -124,7 +102,8 @@ dns_netcup_rm() {
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
}
Loading…
Cancel
Save