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.

77 lines
2.7 KiB

  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_selfhost_add() {
  7. fulldomain=$1
  8. txt=$2
  9. _info "Calling acme-dns on selfhost"
  10. _debug fulldomain "$fulldomain"
  11. _debug txtvalue "$txt"
  12. _debug domain "$d"
  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. SELFHOSTDNS_MAP="${SELFHOSTDNS_MAP:-$(_readdomainconf SELFHOSTDNS_MAP)}"
  19. if [ -z "${SELFHOSTDNS_USERNAME:-}" ] || [ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
  20. _err "SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
  21. return 1
  22. fi
  23. # get the domain entry from SELFHOSTDNS_MAP
  24. # only match full domains (at the beginning of the string or with a leading whitespace),
  25. # e.g. don't match mytest.example.com or sub.test.example.com for test.example.com
  26. # if the domain is defined multiple times only the last occurance will be matched
  27. mapEntry=$(echo "$SELFHOSTDNS_MAP" | sed -n -E "s/(^|^.*[[:space:]])($fulldomain)(:[[:digit:]]+)([:]?[[:digit:]]*)(.*)/\2\3\4/p")
  28. _debug mapEntry "$mapEntry"
  29. if test -z "$mapEntry"; then
  30. _err "SELFHOSTDNS_MAP must contain the fulldomain incl. prefix and at least one RID"
  31. return 1
  32. fi
  33. # get the RIDs from the map entry
  34. rid1=$(echo "$mapEntry" | cut -d: -f2)
  35. _debug rid1 "$rid1"
  36. rid2=$(echo "$mapEntry" | cut -d: -f3)
  37. _debug rid2 "$rid2"
  38. rid=$rid1
  39. # check for wildcard domain and use rid2 if set
  40. if _startswith "$d" '*.'; then
  41. _debug2 "wildcard domain"
  42. if ! test -z "$rid2"; then
  43. rid="$rid2"
  44. fi
  45. fi
  46. _info "Trying to add $txt on selfhost for rid: $rid"
  47. data="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
  48. response="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
  49. if ! echo "$response" | grep "200 OK" >/dev/null; then
  50. _err "Invalid response of acme-dns for selfhost"
  51. return 1
  52. fi
  53. # Now that we know the values are good, save them
  54. _saveaccountconf_mutable SELFHOSTDNS_USERNAME "$SELFHOSTDNS_USERNAME"
  55. _saveaccountconf_mutable SELFHOSTDNS_PASSWORD "$SELFHOSTDNS_PASSWORD"
  56. # These values are domain dependent, so store them there
  57. _savedomainconf SELFHOSTDNS_MAP "$SELFHOSTDNS_MAP"
  58. }
  59. dns_selfhost_rm() {
  60. fulldomain=$1
  61. txt=$2
  62. _debug fulldomain "$fulldomain"
  63. _debug txtvalue "$txt"
  64. _info "Creating and removing of records is not supported by selfhost API, will not delete anything."
  65. }