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.

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