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.

78 lines
2.3 KiB

3 months ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_maradns_info='MaraDNS Server
  4. Site: MaraDNS.samiam.org
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_maradns
  6. Options:
  7. MARA_ZONE_FILE Zone file path. E.g. "/etc/maradns/db.domain.com"
  8. MARA_DUENDE_PID_PATH Duende PID Path. E.g. "/run/maradns/etc_maradns_mararc.pid"
  9. Issues: github.com/acmesh-official/acme.sh/issues/2072
  10. '
  11. #Usage: dns_maradns_add _acme-challenge.www.domain.com "token"
  12. dns_maradns_add() {
  13. fulldomain="$1"
  14. txtvalue="$2"
  15. MARA_ZONE_FILE="${MARA_ZONE_FILE:-$(_readaccountconf_mutable MARA_ZONE_FILE)}"
  16. MARA_DUENDE_PID_PATH="${MARA_DUENDE_PID_PATH:-$(_readaccountconf_mutable MARA_DUENDE_PID_PATH)}"
  17. _check_zone_file "$MARA_ZONE_FILE" || return 1
  18. _check_duende_pid_path "$MARA_DUENDE_PID_PATH" || return 1
  19. _saveaccountconf_mutable MARA_ZONE_FILE "$MARA_ZONE_FILE"
  20. _saveaccountconf_mutable MARA_DUENDE_PID_PATH "$MARA_DUENDE_PID_PATH"
  21. printf "%s. TXT '%s' ~\n" "$fulldomain" "$txtvalue" >>"$MARA_ZONE_FILE"
  22. _reload_maradns "$MARA_DUENDE_PID_PATH" || return 1
  23. }
  24. #Usage: dns_maradns_rm _acme-challenge.www.domain.com "token"
  25. dns_maradns_rm() {
  26. fulldomain="$1"
  27. txtvalue="$2"
  28. MARA_ZONE_FILE="${MARA_ZONE_FILE:-$(_readaccountconf_mutable MARA_ZONE_FILE)}"
  29. MARA_DUENDE_PID_PATH="${MARA_DUENDE_PID_PATH:-$(_readaccountconf_mutable MARA_DUENDE_PID_PATH)}"
  30. _check_zone_file "$MARA_ZONE_FILE" || return 1
  31. _check_duende_pid_path "$MARA_DUENDE_PID_PATH" || return 1
  32. _saveaccountconf_mutable MARA_ZONE_FILE "$MARA_ZONE_FILE"
  33. _saveaccountconf_mutable MARA_DUENDE_PID_PATH "$MARA_DUENDE_PID_PATH"
  34. _sed_i "/^$fulldomain.\+TXT '$txtvalue' ~/d" "$MARA_ZONE_FILE"
  35. _reload_maradns "$MARA_DUENDE_PID_PATH" || return 1
  36. }
  37. _check_zone_file() {
  38. zonefile="$1"
  39. if [ -z "$zonefile" ]; then
  40. _err "MARA_ZONE_FILE not passed!"
  41. return 1
  42. elif [ ! -w "$zonefile" ]; then
  43. _err "MARA_ZONE_FILE not writable: $zonefile"
  44. return 1
  45. fi
  46. }
  47. _check_duende_pid_path() {
  48. pidpath="$1"
  49. if [ -z "$pidpath" ]; then
  50. _err "MARA_DUENDE_PID_PATH not passed!"
  51. return 1
  52. fi
  53. if [ ! -r "$pidpath" ]; then
  54. _err "MARA_DUENDE_PID_PATH not readable: $pidpath"
  55. return 1
  56. fi
  57. }
  58. _reload_maradns() {
  59. pidpath="$1"
  60. kill -s HUP -- "$(cat "$pidpath")"
  61. if [ $? -ne 0 ]; then
  62. _err "Unable to reload MaraDNS, kill returned"
  63. return 1
  64. fi
  65. }