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.4 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_selfhost_add() {
  7. domain=$1
  8. txt=$2
  9. _info "Calling acme-dns on selfhost"
  10. _debug fulldomain "$domain"
  11. _debug txtvalue "$txt"
  12. SELFHOSTDNS_UPDATE_URL="https://selfhost.de/cgi-bin/api.pl"
  13. # Get values, but don't save until we successfully validated
  14. SELFHOSTDNS_USERNAME="${SELFHOSTDNS_USERNAME:-$(_readaccountconf_mutable SELFHOSTDNS_USERNAME)}"
  15. SELFHOSTDNS_PASSWORD="${SELFHOSTDNS_PASSWORD:-$(_readaccountconf_mutable SELFHOSTDNS_PASSWORD)}"
  16. # These values are domain dependent, so read them from there
  17. _getdeployconf SELFHOSTDNS_MAP
  18. _getdeployconf SELFHOSTDNS_RID
  19. _getdeployconf SELFHOSTDNS_RID2
  20. _getdeployconf SELFHOSTDNS_LAST_SLOT
  21. if [ -z "${SELFHOSTDNS_USERNAME:-}" ] || [ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
  22. _err "SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
  23. return 1
  24. fi
  25. if test -z "$SELFHOSTDNS_LAST_SLOT"; then
  26. SELFHOSTDNS_LAST_SLOT=1
  27. fi
  28. rid=$(echo "$SELFHOSTDNS_MAP" | grep -Eoi "$domain:(\d+)" | tr -d "$domain:")
  29. if test -z "$rid"; then
  30. if [ $SELFHOSTDNS_LAST_SLOT = "2" ]; then
  31. rid=$SELFHOSTDNS_RID
  32. SELFHOSTDNS_LAST_SLOT=1
  33. else
  34. rid=$SELFHOSTDNS_RID2
  35. SELFHOSTDNS_LAST_SLOT=2
  36. fi
  37. fi
  38. if test -z "$rid"; then
  39. _err "SELFHOSTDNS_RID and SELFHOSTDNS_RID2, or SELFHOSTDNS_MAP must be set"
  40. return 1
  41. fi
  42. _info "Trying to add $txt on selfhost for rid: $rid"
  43. data="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
  44. response="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
  45. if ! echo "$response" | grep "200 OK" >/dev/null; then
  46. _err "Invalid response of acme-dns for selfhost"
  47. return 1
  48. fi
  49. # Now that we know the values are good, save them
  50. _saveaccountconf_mutable SELFHOSTDNS_USERNAME "$SELFHOSTDNS_USERNAME"
  51. _saveaccountconf_mutable SELFHOSTDNS_PASSWORD "$SELFHOSTDNS_PASSWORD"
  52. # These values are domain dependent, so store them there
  53. _savedeployconf SELFHOSTDNS_MAP "$SELFHOSTDNS_MAP"
  54. _savedeployconf SELFHOSTDNS_RID "$SELFHOSTDNS_RID"
  55. _savedeployconf SELFHOSTDNS_RID2 "$SELFHOSTDNS_RID2"
  56. _savedeployconf SELFHOSTDNS_LAST_SLOT "$SELFHOSTDNS_LAST_SLOT"
  57. }
  58. dns_selfhost_rm() {
  59. domain=$1
  60. txt=$2
  61. _debug fulldomain "$domain"
  62. _debug txtvalue "$txt"
  63. _info "Creating and removing of records is not supported by selfhost API, will not delete anything."
  64. }