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.

88 lines
2.6 KiB

5 years ago
  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_md5 (your namemaster.de API password_as_md5hash)
  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. dns_nm_add() {
  15. fulldomain=$1
  16. txt_value=$2
  17. _info "Using DNS-01 namemaster hook"
  18. NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
  19. NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
  20. if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
  21. NM_user=""
  22. NM_md5=""
  23. _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
  24. return 1
  25. fi
  26. #save the api user and md5 password to the account conf file.
  27. _debug "Save user and hash"
  28. _saveaccountconf_mutable NM_user "$NM_user"
  29. _saveaccountconf_mutable NM_md5 "$NM_md5"
  30. zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")"
  31. get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=ACME&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600"
  32. if ! erg="$(_get "$get")"; then
  33. _err "error Deleting $zone TXT: $txt_value"
  34. _err "Error $exit_code"
  35. return 1
  36. fi
  37. if _contains "$erg" "Success"; then
  38. _info "Success, TXT Added, OK"
  39. else
  40. _err "error Adding $zone TXT: $txt_value erg: $erg"
  41. return 1
  42. fi
  43. _debug "ok Auto $zone TXT: $txt_value erg: $erg"
  44. return 0
  45. }
  46. dns_nm_rm() {
  47. fulldomain=$1
  48. txt_value=$2
  49. NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}"
  50. NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}"
  51. if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then
  52. NM_user=""
  53. NM_md5=""
  54. _err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables."
  55. return 1
  56. fi
  57. zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")"
  58. get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN&TTL=0"
  59. if ! erg="$(_get "$get")"; then
  60. _err "error Deleting $zone TXT: $txt_value"
  61. _err "Error $exit_code"
  62. return 1
  63. fi
  64. if _contains "$erg" "Success"; then
  65. _info "Success, TXT removed, OK"
  66. else
  67. _err "error Auto $zone TXT: $txt_value erg: $erg"
  68. return 1
  69. fi
  70. _debug "ok Auto $zone TXT: $txt_value erg: $erg"
  71. return 0
  72. }