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.

88 lines
3.1 KiB

3 years ago
  1. #!/usr/bin/env sh
  2. #
  3. # Author: Marvin Edeler
  4. # Report Bugs here: https://github.com/Marvo2011/acme.sh/issues/1
  5. # Last Edit: 17.02.2022
  6. DNS_CHALLENGE_PREFIX_ESCAPED="_acme-challenge\."
  7. dns_selfhost_add() {
  8. fulldomain=$1
  9. txt=$2
  10. _info "Calling acme-dns on selfhost"
  11. _debug fulldomain "$fulldomain"
  12. _debug txtvalue "$txt"
  13. SELFHOSTDNS_UPDATE_URL="https://selfhost.de/cgi-bin/api.pl"
  14. # Get values, but don't save until we successfully validated
  15. SELFHOSTDNS_USERNAME="${SELFHOSTDNS_USERNAME:-$(_readaccountconf_mutable SELFHOSTDNS_USERNAME)}"
  16. SELFHOSTDNS_PASSWORD="${SELFHOSTDNS_PASSWORD:-$(_readaccountconf_mutable SELFHOSTDNS_PASSWORD)}"
  17. # These values are domain dependent, so read them from there
  18. _getdeployconf SELFHOSTDNS_MAP
  19. _getdeployconf SELFHOSTDNS_RID
  20. _getdeployconf SELFHOSTDNS_RID2
  21. _getdeployconf SELFHOSTDNS_LAST_SLOT
  22. if [ -z "${SELFHOSTDNS_USERNAME:-}" ] || [ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
  23. _err "SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
  24. return 1
  25. fi
  26. if test -z "$SELFHOSTDNS_LAST_SLOT"; then
  27. SELFHOSTDNS_LAST_SLOT=1
  28. fi
  29. # cut DNS_CHALLENGE_PREFIX_ESCAPED from fulldomain if present at the beginning of the string
  30. lookupdomain=$(echo "$fulldomain" | sed "s/^$DNS_CHALLENGE_PREFIX_ESCAPED//")
  31. _debug lookupdomain "$lookupdomain"
  32. # get the RID for lookupdomain or fulldomain from SELFHOSTDNS_MAP
  33. # only match full domains (at the beginning of the string or with a leading whitespace),
  34. # e.g. don't match mytest.example.com or sub.test.example.com for test.example.com
  35. # replace the whole string with the RID (matching group 3) for assignment
  36. # if the domain is defined multiple times only the last occurance will be matched
  37. rid=$(echo "$SELFHOSTDNS_MAP" | sed -E "s/(^|^.*[[:space:]])($lookupdomain:|$fulldomain:)([0-9][0-9]*)(.*)/\3/")
  38. if test -z "$rid"; then
  39. if [ $SELFHOSTDNS_LAST_SLOT = "2" ]; then
  40. rid=$SELFHOSTDNS_RID
  41. SELFHOSTDNS_LAST_SLOT=1
  42. else
  43. rid=$SELFHOSTDNS_RID2
  44. SELFHOSTDNS_LAST_SLOT=2
  45. fi
  46. fi
  47. if test -z "$rid"; then
  48. _err "SELFHOSTDNS_RID and SELFHOSTDNS_RID2, or SELFHOSTDNS_MAP must be set"
  49. return 1
  50. fi
  51. _info "Trying to add $txt on selfhost for rid: $rid"
  52. data="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
  53. response="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
  54. if ! echo "$response" | grep "200 OK" >/dev/null; then
  55. _err "Invalid response of acme-dns for selfhost"
  56. return 1
  57. fi
  58. # Now that we know the values are good, save them
  59. _saveaccountconf_mutable SELFHOSTDNS_USERNAME "$SELFHOSTDNS_USERNAME"
  60. _saveaccountconf_mutable SELFHOSTDNS_PASSWORD "$SELFHOSTDNS_PASSWORD"
  61. # These values are domain dependent, so store them there
  62. _savedeployconf SELFHOSTDNS_MAP "$SELFHOSTDNS_MAP"
  63. _savedeployconf SELFHOSTDNS_RID "$SELFHOSTDNS_RID"
  64. _savedeployconf SELFHOSTDNS_RID2 "$SELFHOSTDNS_RID2"
  65. _savedeployconf SELFHOSTDNS_LAST_SLOT "$SELFHOSTDNS_LAST_SLOT"
  66. }
  67. dns_selfhost_rm() {
  68. fulldomain=$1
  69. txt=$2
  70. _debug fulldomain "$fulldomain"
  71. _debug txtvalue "$txt"
  72. _info "Creating and removing of records is not supported by selfhost API, will not delete anything."
  73. }