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.

129 lines
3.7 KiB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env sh
  2. # Joker.com API for acme.sh
  3. #
  4. # This script adds the necessary TXT record to a domain in Joker.com.
  5. #
  6. # You must activate Dynamic DNS in Joker.com DNS configuration first.
  7. # Username and password below refer to Dynamic DNS authentication,
  8. # not your Joker.com login credentials.
  9. # See: https://joker.com/faq/content/11/427/en/what-is-dynamic-dns-dyndns.html
  10. #
  11. # NOTE: This script does not support wildcard certificates, because
  12. # Joker.com API does not support adding two TXT records with the same
  13. # subdomain. Adding the second record will overwrite the first one.
  14. # See: https://joker.com/faq/content/6/496/en/let_s-encrypt-support.html
  15. # "... this request will replace all TXT records for the specified
  16. # label by the provided content"
  17. #
  18. # Author: aattww (https://github.com/aattww/)
  19. #
  20. # Report bugs to https://github.com/acmesh-official/acme.sh/issues/2840
  21. #
  22. # JOKER_USERNAME="xxxx"
  23. # JOKER_PASSWORD="xxxx"
  24. JOKER_API="https://svc.joker.com/nic/replace"
  25. ######## Public functions #####################
  26. #Usage: dns_joker_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  27. dns_joker_add() {
  28. fulldomain=$1
  29. txtvalue=$2
  30. JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}"
  31. JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}"
  32. if [ -z "$JOKER_USERNAME" ] || [ -z "$JOKER_PASSWORD" ]; then
  33. _err "No Joker.com username and password specified."
  34. return 1
  35. fi
  36. _saveaccountconf_mutable JOKER_USERNAME "$JOKER_USERNAME"
  37. _saveaccountconf_mutable JOKER_PASSWORD "$JOKER_PASSWORD"
  38. if ! _get_root "$fulldomain"; then
  39. _err "Invalid domain"
  40. return 1
  41. fi
  42. _info "Adding TXT record"
  43. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value=$txtvalue"; then
  44. if _startswith "$response" "OK"; then
  45. _info "Added, OK"
  46. return 0
  47. fi
  48. fi
  49. _err "Error adding TXT record."
  50. return 1
  51. }
  52. #fulldomain txtvalue
  53. dns_joker_rm() {
  54. fulldomain=$1
  55. txtvalue=$2
  56. JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}"
  57. JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}"
  58. if ! _get_root "$fulldomain"; then
  59. _err "Invalid domain"
  60. return 1
  61. fi
  62. _info "Removing TXT record"
  63. # TXT record is removed by setting its value to empty.
  64. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value="; then
  65. if _startswith "$response" "OK"; then
  66. _info "Removed, OK"
  67. return 0
  68. fi
  69. fi
  70. _err "Error removing TXT record."
  71. return 1
  72. }
  73. #################### Private functions below ##################################
  74. #_acme-challenge.www.domain.com
  75. #returns
  76. # _sub_domain=_acme-challenge.www
  77. # _domain=domain.com
  78. _get_root() {
  79. fulldomain=$1
  80. i=1
  81. while true; do
  82. h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100)
  83. _debug h "$h"
  84. if [ -z "$h" ]; then
  85. return 1
  86. fi
  87. # Try to remove a test record. With correct root domain, username and password this will return "OK: ..." regardless
  88. # of record in question existing or not.
  89. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$h&label=jokerTXTUpdateTest&type=TXT&value="; then
  90. if _startswith "$response" "OK"; then
  91. _sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")"
  92. _domain=$h
  93. return 0
  94. fi
  95. fi
  96. i=$(_math "$i" + 1)
  97. done
  98. _debug "Root domain not found"
  99. return 1
  100. }
  101. _joker_rest() {
  102. data="$1"
  103. _debug data "$data"
  104. if ! response="$(_post "$data" "$JOKER_API" "" "POST")"; then
  105. _err "Error POSTing"
  106. return 1
  107. fi
  108. _debug response "$response"
  109. return 0
  110. }