2018-05-15 13:18:50 +02:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
#developed by linux-insideDE
|
|
|
|
|
|
|
|
NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}"
|
|
|
|
NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}"
|
|
|
|
NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}"
|
|
|
|
end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON"
|
|
|
|
client=""
|
|
|
|
|
|
|
|
dns_netcup_add() {
|
|
|
|
login
|
|
|
|
if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then
|
|
|
|
_err "No Credentials given"
|
|
|
|
return 1
|
|
|
|
fi
|
2018-05-29 16:56:07 +02:00
|
|
|
_saveaccountconf_mutable NC_Apikey "$NC_Apikey"
|
|
|
|
_saveaccountconf_mutable NC_Apipw "$NC_Apipw"
|
|
|
|
_saveaccountconf_mutable NC_CID "$NC_CID"
|
2018-05-15 13:18:50 +02:00
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
domain=""
|
2018-05-29 16:23:28 +02:00
|
|
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
|
|
|
|
exit=$(_math "$exit" + 1)
|
|
|
|
i=$exit
|
2018-05-29 16:56:07 +02:00
|
|
|
|
|
|
|
while
|
|
|
|
[ "$exit" -gt 0 ]; do
|
2018-05-29 16:23:28 +02:00
|
|
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
|
|
|
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
|
|
|
|
domain="$tmp"
|
2018-05-15 13:18:50 +02:00
|
|
|
else
|
2018-05-29 16:23:28 +02:00
|
|
|
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"
|
2018-05-29 16:56:07 +02:00
|
|
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
|
2018-05-29 16:23:28 +02:00
|
|
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
|
|
|
|
_err "$msg"
|
|
|
|
return 1
|
|
|
|
else
|
2018-05-29 16:56:07 +02:00
|
|
|
break
|
|
|
|
fi
|
2018-05-29 16:23:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exit=$(_math "$exit" - 1)
|
2018-05-15 13:18:50 +02:00
|
|
|
done
|
|
|
|
logout
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_netcup_rm() {
|
|
|
|
login
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
2018-05-29 16:56:07 +02:00
|
|
|
|
2018-05-15 13:18:50 +02:00
|
|
|
domain=""
|
2018-05-29 16:23:28 +02:00
|
|
|
exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
|
|
|
|
exit=$(_math "$exit" + 1)
|
|
|
|
i=$exit
|
|
|
|
rec=""
|
2018-05-29 16:56:07 +02:00
|
|
|
|
|
|
|
while
|
|
|
|
[ "$exit" -gt 0 ]; do
|
2018-05-29 16:23:28 +02:00
|
|
|
tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
|
|
|
|
if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
|
|
|
|
domain="$tmp"
|
2018-05-15 13:18:50 +02:00
|
|
|
else
|
2018-05-29 16:23:28 +02:00
|
|
|
domain="$tmp.$domain"
|
|
|
|
fi
|
2018-05-29 16:56:07 +02:00
|
|
|
if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
|
2018-05-29 16:23:28 +02:00
|
|
|
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')
|
2018-05-29 16:56:07 +02:00
|
|
|
_debug "$msg"
|
|
|
|
if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
|
2018-05-29 16:23:28 +02:00
|
|
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
|
|
|
|
_err "$msg"
|
|
|
|
return 1
|
|
|
|
else
|
2018-05-29 16:56:07 +02:00
|
|
|
break
|
|
|
|
fi
|
2018-05-15 13:18:50 +02:00
|
|
|
fi
|
|
|
|
fi
|
2018-05-29 16:23:28 +02:00
|
|
|
exit=$(_math "$exit" - 1)
|
2018-05-15 13:18:50 +02:00
|
|
|
done
|
2018-05-29 16:56:07 +02:00
|
|
|
|
2018-05-15 16:21:57 +02:00
|
|
|
ida=0000
|
|
|
|
idv=0001
|
2018-05-29 16:56:07 +02:00
|
|
|
ids=0000000000
|
2018-05-15 16:21:57 +02:00
|
|
|
i=1
|
2018-05-29 16:56:07 +02:00
|
|
|
while
|
|
|
|
[ "$i" -ne 0 ]; do
|
2018-05-15 16:21:57 +02:00
|
|
|
specrec=$(_getfield "$rec" "$i" ";")
|
|
|
|
idv="$ida"
|
|
|
|
ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g')
|
2018-05-29 16:56:07 +02:00
|
|
|
txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g')
|
2018-05-15 16:21:57 +02:00
|
|
|
i=$(_math "$i" + 1)
|
|
|
|
if [ "$txtvalue" = "$txtv" ]; then
|
|
|
|
i=0
|
|
|
|
ids="$ida"
|
2018-05-29 16:56:07 +02:00
|
|
|
fi
|
2018-05-15 16:21:57 +02:00
|
|
|
if [ "$ida" = "$idv" ]; then
|
|
|
|
i=0
|
|
|
|
fi
|
2018-05-29 16:23:28 +02:00
|
|
|
done
|
|
|
|
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")
|
2018-05-15 13:18:50 +02:00
|
|
|
_debug "$msg"
|
2018-05-15 16:21:57 +02:00
|
|
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
|
2018-05-15 13:18:50 +02:00
|
|
|
_err "$msg"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
logout
|
|
|
|
}
|
|
|
|
|
|
|
|
login() {
|
2018-05-29 16:56:07 +02:00
|
|
|
tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
|
2018-05-15 16:21:57 +02:00
|
|
|
sid=$(_getfield "$tmp" "8" | sed s/\"responsedata\":\{\"apisessionid\":\"//g | sed 's/\"\}\}//g')
|
2018-05-15 13:18:50 +02:00
|
|
|
_debug "$tmp"
|
2018-05-15 16:21:57 +02:00
|
|
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
|
|
|
|
_err "$msg"
|
2018-05-15 13:18:50 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
logout() {
|
|
|
|
tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
|
|
|
|
_debug "$tmp"
|
2018-05-15 16:21:57 +02:00
|
|
|
if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
|
|
|
|
_err "$msg"
|
2018-05-15 13:18:50 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|