dns_maradns.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env sh
  2. #Usage: dns_maradns_add _acme-challenge.www.domain.com "token"
  3. dns_maradns_add() {
  4. fulldomain="$1"
  5. txtvalue="$2"
  6. MARA_ZONE_FILE="${MARA_ZONE_FILE:-$(_readaccountconf_mutable MARA_ZONE_FILE)}"
  7. MARA_DUENDE_PID_PATH="${MARA_DUENDE_PID_PATH:-$(_readaccountconf_mutable MARA_DUENDE_PID_PATH)}"
  8. _check_zone_file "$MARA_ZONE_FILE" || return 1
  9. _check_duende_pid_path "$MARA_DUENDE_PID_PATH" || return 1
  10. _saveaccountconf_mutable MARA_ZONE_FILE "$MARA_ZONE_FILE"
  11. _saveaccountconf_mutable MARA_DUENDE_PID_PATH "$MARA_DUENDE_PID_PATH"
  12. printf "%s. TXT '%s' ~\n" "$fulldomain" "$txtvalue" >>"$MARA_ZONE_FILE"
  13. _reload_maradns "$MARA_DUENDE_PID_PATH" || return 1
  14. }
  15. #Usage: dns_maradns_rm _acme-challenge.www.domain.com "token"
  16. dns_maradns_rm() {
  17. fulldomain="$1"
  18. txtvalue="$2"
  19. MARA_ZONE_FILE="${MARA_ZONE_FILE:-$(_readaccountconf_mutable MARA_ZONE_FILE)}"
  20. MARA_DUENDE_PID_PATH="${MARA_DUENDE_PID_PATH:-$(_readaccountconf_mutable MARA_DUENDE_PID_PATH)}"
  21. _check_zone_file "$MARA_ZONE_FILE" || return 1
  22. _check_duende_pid_path "$MARA_DUENDE_PID_PATH" || return 1
  23. _saveaccountconf_mutable MARA_ZONE_FILE "$MARA_ZONE_FILE"
  24. _saveaccountconf_mutable MARA_DUENDE_PID_PATH "$MARA_DUENDE_PID_PATH"
  25. _sed_i "/^$fulldomain.\+TXT '$txtvalue' ~/d" "$MARA_ZONE_FILE"
  26. _reload_maradns "$MARA_DUENDE_PID_PATH" || return 1
  27. }
  28. _check_zone_file() {
  29. zonefile="$1"
  30. if [ -z "$zonefile" ]; then
  31. _err "MARA_ZONE_FILE not passed!"
  32. return 1
  33. elif [ ! -w "$zonefile" ]; then
  34. _err "MARA_ZONE_FILE not writable: $zonefile"
  35. return 1
  36. fi
  37. }
  38. _check_duende_pid_path() {
  39. pidpath="$1"
  40. if [ -z "$pidpath" ]; then
  41. _err "MARA_DUENDE_PID_PATH not passed!"
  42. return 1
  43. fi
  44. if [ ! -r "$pidpath" ]; then
  45. _err "MARA_DUENDE_PID_PATH not readable: $pidpath"
  46. return 1
  47. fi
  48. }
  49. _reload_maradns() {
  50. pidpath="$1"
  51. kill -s HUP -- "$(cat "$pidpath")"
  52. if [ $? -ne 0 ]; then
  53. _err "Unable to reload MaraDNS, kill returned $?"
  54. return 1
  55. fi
  56. }