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.

93 lines
2.4 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 "" "https://www.lima-city.de/usercp/domains/${LIMACITY_DOMAINID}/records/${recordId}" "" "DELETE"
  43. done
  44. return 0
  45. }
  46. #################### Private functions below ##################################
  47. _lima_get_root() {
  48. _lima_get_root=$1
  49. i=1
  50. while true; do
  51. h=$(printf "%s" "$_lima_get_root" | cut -d . -f $i-100)
  52. _debug h "$h"
  53. if [ -z "$h" ]; then
  54. #not valid
  55. return 0
  56. fi
  57. if _contains "$h" "\."; then
  58. domain=$h
  59. fi
  60. i=$(_math "$i" + 1)
  61. done
  62. }
  63. _lima_get_domain_id() {
  64. _lima_get_root "$1"
  65. _debug "$domain"
  66. LIMACITY_DOMAINID=$(_get "${APIBASE}/domains.json" | _egrep_o "{\"id\":[0-9]*[^}]*$domain" | _egrep_o "[0-9]*")
  67. _debug "$LIMACITY_DOMAINID"
  68. if [ -z "$LIMACITY_DOMAINID" ]; then
  69. return 1
  70. fi
  71. return 0
  72. }