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.

144 lines
4.8 KiB

6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_netcup_info='netcup.eu
  4. Domains: netcup.de netcup.net
  5. Site: netcup.eu/
  6. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_netcup
  7. Options:
  8. NC_Apikey API Key
  9. NC_Apipw API Password
  10. NC_CID Customer Number
  11. Author: linux-insideDE
  12. '
  13. NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}"
  14. NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}"
  15. NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}"
  16. end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON"
  17. client=""
  18. dns_netcup_add() {
  19. _debug NC_Apikey "$NC_Apikey"
  20. login
  21. if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then
  22. _err "No Credentials given"
  23. return 1
  24. fi
  25. _saveaccountconf_mutable NC_Apikey "$NC_Apikey"
  26. _saveaccountconf_mutable NC_Apipw "$NC_Apipw"
  27. _saveaccountconf_mutable NC_CID "$NC_CID"
  28. fulldomain=$1
  29. txtvalue=$2
  30. domain=""
  31. exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
  32. exit=$(_math "$exit" + 1)
  33. i=$exit
  34. while
  35. [ "$exit" -gt 0 ]
  36. do
  37. tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
  38. if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
  39. domain="$tmp"
  40. else
  41. domain="$tmp.$domain"
  42. fi
  43. if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
  44. 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")
  45. _debug "$msg"
  46. if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
  47. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  48. _err "$msg"
  49. return 1
  50. else
  51. break
  52. fi
  53. fi
  54. fi
  55. exit=$(_math "$exit" - 1)
  56. done
  57. logout
  58. }
  59. dns_netcup_rm() {
  60. login
  61. fulldomain=$1
  62. txtvalue=$2
  63. domain=""
  64. exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
  65. exit=$(_math "$exit" + 1)
  66. i=$exit
  67. rec=""
  68. while
  69. [ "$exit" -gt 0 ]
  70. do
  71. tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
  72. if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
  73. domain="$tmp"
  74. else
  75. domain="$tmp.$domain"
  76. fi
  77. if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
  78. msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST")
  79. rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
  80. _debug "$msg"
  81. if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
  82. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  83. _err "$msg"
  84. return 1
  85. else
  86. break
  87. fi
  88. fi
  89. fi
  90. exit=$(_math "$exit" - 1)
  91. done
  92. ida=0000
  93. idv=0001
  94. ids=0000000000
  95. i=1
  96. while
  97. [ "$i" -ne 0 ]
  98. do
  99. specrec=$(_getfield "$rec" "$i" ";")
  100. idv="$ida"
  101. ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g')
  102. txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g')
  103. i=$(_math "$i" + 1)
  104. if [ "$txtvalue" = "$txtv" ]; then
  105. i=0
  106. ids="$ida"
  107. fi
  108. if [ "$ida" = "$idv" ]; then
  109. i=0
  110. fi
  111. done
  112. 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")
  113. _debug "$msg"
  114. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  115. _err "$msg"
  116. return 1
  117. fi
  118. logout
  119. }
  120. login() {
  121. tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
  122. sid=$(echo "$tmp" | tr '{}' '\n' | grep apisessionid | cut -d '"' -f 4)
  123. _debug "$tmp"
  124. if [ "$(_getfield "$tmp" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  125. _err "$tmp"
  126. return 1
  127. fi
  128. }
  129. logout() {
  130. tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
  131. _debug "$tmp"
  132. if [ "$(_getfield "$tmp" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  133. _err "$tmp"
  134. return 1
  135. fi
  136. }