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.

142 lines
3.8 KiB

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