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.

94 lines
2.9 KiB

4 months ago
4 months ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_limacity_info='lima-city.de
  4. Site: www.lima-city.de
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_limacity
  6. Options:
  7. LIMACITY_APIKEY API Key. Note: The API Key must have following roles: dns.admin, domains.reader
  8. Issues: github.com/acmesh-official/acme.sh/issues/4758
  9. Author: @Laraveluser
  10. '
  11. ######## Public functions #####################
  12. LIMACITY_APIKEY="${LIMACITY_APIKEY:-$(_readaccountconf_mutable LIMACITY_APIKEY)}"
  13. AUTH=$(printf "%s" "api:$LIMACITY_APIKEY" | _base64 -w 0)
  14. export _H1="Authorization: Basic $AUTH"
  15. export _H2="Content-Type: application/json"
  16. APIBASE=https://www.lima-city.de/usercp
  17. #Usage: dns_limacity_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  18. dns_limacity_add() {
  19. _debug LIMACITY_APIKEY "$LIMACITY_APIKEY"
  20. if [ "$LIMACITY_APIKEY" = "" ]; then
  21. _err "No Credentials given"
  22. return 1
  23. fi
  24. # save the dns server and key to the account conf file.
  25. _saveaccountconf_mutable LIMACITY_APIKEY "${LIMACITY_APIKEY}"
  26. fulldomain=$1
  27. txtvalue=$2
  28. if ! _lima_get_domain_id "$fulldomain"; then return 1; fi
  29. msg=$(_post "{\"nameserver_record\":{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"${txtvalue}\",\"ttl\":60}}" "${APIBASE}/domains/${LIMACITY_DOMAINID}/records.json" "" "POST")
  30. _debug "$msg"
  31. if [ "$(echo "$msg" | _egrep_o "\"status\":\"ok\"")" = "" ]; then
  32. _err "$msg"
  33. return 1
  34. fi
  35. return 0
  36. }
  37. #Usage: dns_limacity_rm _acme-challenge.www.domain.com
  38. dns_limacity_rm() {
  39. fulldomain=$1
  40. txtvalue=$2
  41. if ! _lima_get_domain_id "$fulldomain"; then return 1; fi
  42. for recordId in $(_get "${APIBASE}/domains/${LIMACITY_DOMAINID}/records.json" | _egrep_o "{\"id\":[0-9]*[^}]*,\"name\":\"${fulldomain}\"" | _egrep_o "[0-9]*"); do
  43. _post "" "${APIBASE}/domains/${LIMACITY_DOMAINID}/records/${recordId}" "" "DELETE"
  44. done
  45. return 0
  46. }
  47. #################### Private functions below ##################################
  48. _lima_get_domain_id() {
  49. domain="$1"
  50. _debug "$domain"
  51. i=2
  52. p=1
  53. domains=$(_get "${APIBASE}/domains.json")
  54. if [ "$(echo "$domains" | _egrep_o "\{.*""domains""")" ]; then
  55. response="$(echo "$domains" | tr -d "\n" | tr '{' "|" | sed 's/|/&{/g' | tr "|" "\n")"
  56. while true; do
  57. h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
  58. _debug h "$h"
  59. if [ -z "$h" ]; then
  60. #not valid
  61. return 1
  62. fi
  63. hostedzone="$(echo "$response" | _egrep_o "\{.*""unicode_fqdn""[^,]+""$h"".*\}")"
  64. if [ "$hostedzone" ]; then
  65. LIMACITY_DOMAINID=$(printf "%s\n" "$hostedzone" | _egrep_o "\"id\":\s*[0-9]+" | _head_n 1 | cut -d : -f 2 | tr -d \ )
  66. if [ "$LIMACITY_DOMAINID" ]; then
  67. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
  68. _domain=$h
  69. return 0
  70. fi
  71. return 1
  72. fi
  73. p=$i
  74. i=$(_math "$i" + 1)
  75. done
  76. fi
  77. return 1
  78. }