You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.6 KiB

  1. #!/usr/bin/env sh
  2. #Requirments: jq
  3. NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}"
  4. NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}"
  5. NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}"
  6. end=https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON
  7. client=""
  8. dns_netcup_add() {
  9. login
  10. if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then
  11. _err "No Credentials given"
  12. return 1
  13. fi
  14. fulldomain=$1
  15. txtvalue=$2
  16. tld=""
  17. domain=""
  18. exit=0
  19. for (( i=20; i>0; i--))
  20. do
  21. tmp=$(cut -d'.' -f$i <<< $fulldomain)
  22. if [ "$tmp" != "" ]; then
  23. if [ "$tld" = "" ]; then
  24. tld=$tmp
  25. else
  26. domain=$tmp
  27. exit=$i
  28. break;
  29. fi
  30. fi
  31. done
  32. inc=""
  33. for (( i=1; i<($exit); i++))
  34. do
  35. if [ "$((exit-1))" = "$i" ]; then
  36. inc="$inc$i"
  37. break;
  38. else
  39. if [ "$inc" = "" ]; then
  40. inc="$i,"
  41. else
  42. inc="$inc$i,"
  43. fi
  44. fi
  45. done
  46. tmp=$(cut -d'.' -f$inc <<< $fulldomain)
  47. 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")
  48. _debug "$msg"
  49. if [ $(echo $msg | jq -r .status) != "success" ]; then
  50. _err "$msg"
  51. return 1
  52. fi
  53. logout
  54. }
  55. dns_netcup_rm() {
  56. login
  57. fulldomain=$1
  58. txtvalue=$2
  59. tld=""
  60. domain=""
  61. exit=0
  62. for (( i=20; i>0; i--))
  63. do
  64. tmp=$(cut -d'.' -f$i <<< $fulldomain)
  65. if [ "$tmp" != "" ]; then
  66. if [ "$tld" = "" ]; then
  67. tld=$tmp
  68. else
  69. domain=$tmp
  70. exit=$i
  71. break;
  72. fi
  73. fi
  74. done
  75. inc=""
  76. for (( i=1; i<($exit); i++))
  77. do
  78. if [ "$((exit-1))" = "$i" ]; then
  79. inc="$inc$i"
  80. break;
  81. else
  82. if [ "$inc" = "" ]; then
  83. inc="$i,"
  84. else
  85. inc="$inc$i,"
  86. fi
  87. fi
  88. done
  89. tmp=$(cut -d'.' -f$inc <<< $fulldomain)
  90. doma="$domain.$tld"
  91. rec=$(getRecords $doma)
  92. ids=$(echo $rec | jq -r ".[]|select(.destination==\"$txtvalue\")|.id")
  93. 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")
  94. _debug "$msg"
  95. if [ $(echo $msg | jq -r .status) != "success" ]; then
  96. _err "$msg"
  97. return 1
  98. fi
  99. logout
  100. }
  101. login() {
  102. tmp=$(_post '{"action": "login", "param": {"apikey": "'$NC_Apikey'", "apipassword": "'$NC_Apipw'", "customernumber": "'$NC_CID'"}}' $end "" "POST")
  103. sid=$(echo ${tmp} | jq -r .responsedata.apisessionid)
  104. _debug "$tmp"
  105. if [ $(echo $tmp | jq -r .status) != "success" ]; then
  106. _err "$tmp"
  107. return 1
  108. fi
  109. }
  110. logout() {
  111. tmp=$(_post '{"action": "logout", "param": {"apikey": "'$NC_Apikey'", "apisessionid": "'$sid'", "customernumber": "'$NC_CID'"}}' $end "" "POST")
  112. _debug "$tmp"
  113. if [ $(echo $tmp | jq -r .status) != "success" ]; then
  114. _err "$tmp"
  115. return 1
  116. fi
  117. }
  118. getRecords() {
  119. tmp2=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$1\"}}" $end "" "POST")
  120. xxd=$(echo ${tmp2} | jq -r '.responsedata.dnsrecords | .[]')
  121. xcd=$(echo $xxd | sed 's/} {/},{/g')
  122. echo "[ $xcd ]"
  123. _debug "$tmp2"
  124. if [ $(echo $tmp2 | jq -r .status) != "success" ]; then
  125. _err "$tmp2"
  126. return 1
  127. fi
  128. }