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.

146 lines
4.0 KiB

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