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.

119 lines
3.1 KiB

  1. #!/usr/bin/env sh
  2. ########################################################################
  3. # https://namemaster.de hook script for acme.sh
  4. #
  5. # Environment variables:
  6. #
  7. # - $NM_user (your namemaster.de API username)
  8. # - $NM_sha256 (your namemaster.de API password_as_sha256hash)
  9. #
  10. # Author: Thilo Gass <thilo.gass@gmail.com>
  11. # Git repo: https://github.com/ThiloGa/acme.sh
  12. #-- dns_nm_add() - Add TXT record --------------------------------------
  13. # Usage: dns_nm_add _acme-challenge.subdomain.domain.com "XyZ123..."
  14. namemaster_api="https://namemaster.de/api/api.php"
  15. dns_nm_add() {
  16. fulldomain=$1
  17. txt_value=$2
  18. _info "Using DNS-01 namemaster hook"
  19. NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
  20. NM_sha256="${NM_sha256:-$(_readaccountconf_mutable NM_sha256)}"
  21. if [ -z "$NM_user" ] || [ -z "$NM_sha256" ]; then
  22. NM_user=""
  23. NM_sha256=""
  24. _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_sha256 environment variables."
  25. return 1
  26. fi
  27. #save the api user and sha256 password to the account conf file.
  28. _debug "Save user and hash"
  29. _saveaccountconf_mutable NM_user "$NM_user"
  30. _saveaccountconf_mutable NM_sha256 "$NM_sha256"
  31. _debug "First detect the root zone"
  32. if ! _get_root "$fulldomain"; then
  33. _err "invalid domain" "$fulldomain"
  34. return 1
  35. fi
  36. _info "die Zone lautet:" "$zone"
  37. get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Antwort=csv&Typ=ACME&zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600"
  38. if ! erg="$(_get "$get")"
  39. then
  40. _err "error Adding $fulldomain TXT: $txt_value"
  41. return 1
  42. fi
  43. if _contains "$erg" "Success"; then
  44. _info "Success, TXT Added, OK"
  45. else
  46. _err "error Adding $fulldomain TXT: $txt_value erg: $erg"
  47. return 1
  48. fi
  49. _debug "ok Auto $fulldomain TXT: $txt_value erg: $erg"
  50. return 0
  51. }
  52. dns_nm_rm() {
  53. fulldomain=$1
  54. txt_value=$2
  55. NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
  56. NM_sha256="${NM_sha256:-$(_readaccountconf_mutable NM_sha256)}"
  57. if [ -z "$NM_user" ] || [ -z "$NM_sha256" ]; then
  58. NM_user=""
  59. NM_sha256=""
  60. _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_sha256 environment variables."
  61. return 1
  62. fi
  63. zone="$(echo "$fulldomain" | _egrep_o "[^.]+.[^.]+$")"
  64. get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Antwort=csv&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN"
  65. if ! erg="$(_get "$get")"
  66. then
  67. _err "error Deleting $fulldomain TXT: $txt_value"
  68. return 1
  69. fi
  70. if _contains "$erg" "Success"; then
  71. _info "Success, TXT removed, OK"
  72. else
  73. _err "error Auto $fulldomain TXT: $txt_value erg: $erg"
  74. return 1
  75. fi
  76. _debug "ok Auto $fulldomain TXT: $txt_value erg: $erg"
  77. return 0
  78. }
  79. _get_root() {
  80. domain=$1
  81. get="$namemaster_api?User=$NM_user&Password=$NM_sha256&Typ=acme&hostname=$domain&Action=getzone&antwort=csv"
  82. if ! zone="$(_get "$get")"
  83. then
  84. _err "error getting Zone"
  85. return 1
  86. else
  87. if _contains "$zone" "hostname not found"
  88. then
  89. return 1
  90. fi
  91. fi
  92. }