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.

134 lines
4.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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. _debug NC_Apikey "$NC_Apikey"
  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. domain=""
  21. exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
  22. exit=$(_math "$exit" + 1)
  23. i=$exit
  24. while
  25. [ "$exit" -gt 0 ]
  26. do
  27. tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
  28. if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
  29. domain="$tmp"
  30. else
  31. domain="$tmp.$domain"
  32. fi
  33. if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
  34. 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")
  35. _debug "$msg"
  36. if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
  37. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  38. _err "$msg"
  39. return 1
  40. else
  41. break
  42. fi
  43. fi
  44. fi
  45. exit=$(_math "$exit" - 1)
  46. done
  47. logout
  48. }
  49. dns_netcup_rm() {
  50. login
  51. fulldomain=$1
  52. txtvalue=$2
  53. domain=""
  54. exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
  55. exit=$(_math "$exit" + 1)
  56. i=$exit
  57. rec=""
  58. while
  59. [ "$exit" -gt 0 ]
  60. do
  61. tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
  62. if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
  63. domain="$tmp"
  64. else
  65. domain="$tmp.$domain"
  66. fi
  67. if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
  68. msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST")
  69. rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
  70. _debug "$msg"
  71. if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
  72. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  73. _err "$msg"
  74. return 1
  75. else
  76. break
  77. fi
  78. fi
  79. fi
  80. exit=$(_math "$exit" - 1)
  81. done
  82. ida=0000
  83. idv=0001
  84. ids=0000000000
  85. i=1
  86. while
  87. [ "$i" -ne 0 ]
  88. do
  89. specrec=$(_getfield "$rec" "$i" ";")
  90. idv="$ida"
  91. ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g')
  92. txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g')
  93. i=$(_math "$i" + 1)
  94. if [ "$txtvalue" = "$txtv" ]; then
  95. i=0
  96. ids="$ida"
  97. fi
  98. if [ "$ida" = "$idv" ]; then
  99. i=0
  100. fi
  101. done
  102. 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")
  103. _debug "$msg"
  104. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "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=$(_getfield "$tmp" "8" | sed s/\"responsedata\":\{\"apisessionid\":\"//g | sed 's/\"\}\}//g')
  113. _debug "$tmp"
  114. if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  115. _err "$msg"
  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 [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
  123. _err "$msg"
  124. return 1
  125. fi
  126. }