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.

125 lines
4.1 KiB

  1. #!/usr/bin/env sh
  2. # Usage to order a * certificate
  3. # ./acme.sh --issue -d '*.www.domain.com' --dns dns_sdns --server letsencrypt --dnssleep 240
  4. SDNS_API_URL="https://robot.s-dns.de:8488/"
  5. # export SDNS_ZONE_KEY=your_zone_key
  6. ######## Public functions #####################
  7. # Adds a txt record with the specified value. Does not remove an existing record
  8. # Usage: dns_sdns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  9. dns_sdns_add ()
  10. {
  11. fulldomain=$1;
  12. txtvalue=$2;
  13. _debug2 "dns_sdns_add() entered";
  14. SDNS_ZONE_KEY="${SDNS_ZONE_KEY:-$(_readaccountconf_mutable SDNS_ZONE_KEY)}";
  15. if [ -z "$SDNS_ZONE_KEY" ]; then
  16. SDNS_ZONE_KEY="";
  17. _err "You didn't specify your zone key yet. (export SDNS_ZONE_KEY=yourkey)";
  18. return 1;
  19. fi;
  20. _saveaccountconf_mutable SDNS_ZONE_KEY "$SDNS_ZONE_KEY";
  21. _debug "First detect the root zone";
  22. if ! _get_root "$fulldomain"; then
  23. _err "invalid domain";
  24. return 1;
  25. fi;
  26. _debug _sub_domain "$_sub_domain";
  27. _debug _domain "$_domain";
  28. _payload="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
  29. <zoneRequest>
  30. <zone name=\"$_domain\" action=\"ADDORUPDATERR\" ddnskey=\"$SDNS_ZONE_KEY\">
  31. <rr host=\"$_sub_domain\" type=\"TXT\" value=\"$txtvalue\" keepExisting=\"true\"/>
  32. </zone>
  33. </zoneRequest>";
  34. _debug2 "$_payload";
  35. response=$(_post "$_payload" "$SDNS_API_URL");
  36. _debug2 "$response";
  37. if _contains "$response" "status=\"OK\""; then
  38. _debug "The TXT record has been added.";
  39. return 0;
  40. else
  41. _err "The attempt to add the TXT record has failed.";
  42. return 1;
  43. fi
  44. }
  45. # Removes a txt record with the specified value. This function does not remove resource records with the same name but a different values.
  46. # Usage: dns_sdns_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  47. dns_sdns_rm ()
  48. {
  49. fulldomain=$1;
  50. txtvalue=$2;
  51. _debug2 "dns_sdns_rm() entered";
  52. SDNS_ZONE_KEY="${SDNS_ZONE_KEY:-$(_readaccountconf_mutable SDNS_ZONE_KEY)}";
  53. if [ -z "$SDNS_ZONE_KEY" ]; then
  54. SDNS_ZONE_KEY="";
  55. _err "You didn't specify your zone key yet. (export SDNS_ZONE_KEY=yourkey)";
  56. return 1;
  57. fi;
  58. _saveaccountconf_mutable SDNS_ZONE_KEY "$SDNS_ZONE_KEY";
  59. _debug "First detect the root zone";
  60. if ! _get_root "$fulldomain"; then
  61. _err "invalid domain";
  62. return 1;
  63. fi;
  64. _debug _sub_domain "$_sub_domain";
  65. _debug _domain "$_domain";
  66. _payload="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
  67. <zoneRequest>
  68. <zone name=\"$_domain\" action=\"DELRR\" ddnskey=\"$SDNS_ZONE_KEY\">
  69. <rr host=\"$_sub_domain\" type=\"TXT\" value=\"$txtvalue\" keepExisting=\"true\"/>
  70. </zone>
  71. </zoneRequest>";
  72. _debug $_payload;
  73. response=$(_post "$_payload" "$SDNS_API_URL");
  74. _debug $response;
  75. if _contains "$response" "status=\"OK\""; then
  76. _debug "The TXT record has been deleted.";
  77. return 0;
  78. else
  79. _err "The attempt to delete the TXT record has failed.";
  80. return 1;
  81. fi
  82. }
  83. #################### Private functions below ##################################
  84. #_acme-challenge.www.domain.com
  85. #returns
  86. # _sub_domain=_acme-challenge.www
  87. # _domain=domain.com
  88. _get_root ()
  89. {
  90. fulldomain=$1;
  91. _debug2 "_get_root() entered";
  92. SDNS_ZONE_KEY="${SDNS_ZONE_KEY:-$(_readaccountconf_mutable SDNS_ZONE_KEY)}";
  93. if [ -z "$SDNS_ZONE_KEY" ]; then
  94. SDNS_ZONE_KEY="";
  95. _err "You didn't specify your zone key yet. (export SDNS_ZONE_KEY=yourkey)";
  96. return 1;
  97. fi;
  98. _saveaccountconf_mutable SDNS_ZONE_KEY "$SDNS_ZONE_KEY";
  99. _payload="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
  100. <zoneRequest action=\"getRootZone\" ddnskey=\"$SDNS_ZONE_KEY\">
  101. <hostname>$fulldomain</hostname>
  102. </zoneRequest>";
  103. _debug2 "$_payload";
  104. response=$(_post "$_payload" "$SDNS_API_URL");
  105. _debug2 "$response";
  106. if _contains "$response" "status=\"found\""; then
  107. _debug "root domain is found";
  108. _domain=$(printf "%s\n" "$response" | _egrep_o "<zonename>(.*)</zonename>" | cut -d ">" -f 2 | cut -d "<" -f 1);
  109. _sub_domain=$(printf "%s\n" "$response" | _egrep_o "<hostname>(.*)</hostname>" | cut -d ">" -f 2 | cut -d "<" -f 1);
  110. _debug _domain "$_domain";
  111. _debug _sub_domain "$_sub_domain";
  112. return 0;
  113. fi
  114. }