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.7 KiB

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