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.

163 lines
4.5 KiB

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