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.

133 lines
4.6 KiB

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