Unverified Commit 48e80220 authored by linux-insideDE's avatar linux-insideDE Committed by GitHub
Browse files

improved handling for third level domains

parent 4715a1a5
...@@ -18,48 +18,33 @@ dns_netcup_add() { ...@@ -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) while [ "$exit" -gt 0 ]
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 do
if [ "$((exit-1))" = "$i" ]; then tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
inc="$inc$i" if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
break; domain="$tmp"
else else
if [ "$inc" = "" ]; then domain="$tmp.$domain"
inc="$i,"
else
inc="$inc$i,"
fi
fi fi
i=$(_math "$i" + 1) if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
done 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")
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")
_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() { ...@@ -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 else
domain=$tmp domain="$tmp.$domain"
exit=$i
break;
fi
fi fi
i=$(_math "$i" - 1) if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
done msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST")
inc="" rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
i=1 _debug "$msg"
while [ "$i" -lt "$exit" ]; if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
do if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
if [ "$((exit-1))" = "$i" ]; then _err "$msg"
inc="$inc$i" return 1
break;
else
if [ "$inc" = "" ]; then
inc="$i,"
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() { ...@@ -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() { ...@@ -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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment