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.

116 lines
3.0 KiB

5 years ago
5 years ago
3 months ago
5 years ago
4 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_joker_info='Joker.com
  4. Site: Joker.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_joker
  6. Options:
  7. JOKER_USERNAME Username
  8. JOKER_PASSWORD Password
  9. Issues: github.com/acmesh-official/acme.sh/issues/2840
  10. Author: <https://github.com/aattww/>
  11. '
  12. JOKER_API="https://svc.joker.com/nic/replace"
  13. ######## Public functions #####################
  14. #Usage: dns_joker_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  15. dns_joker_add() {
  16. fulldomain=$1
  17. txtvalue=$2
  18. JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}"
  19. JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}"
  20. if [ -z "$JOKER_USERNAME" ] || [ -z "$JOKER_PASSWORD" ]; then
  21. _err "No Joker.com username and password specified."
  22. return 1
  23. fi
  24. _saveaccountconf_mutable JOKER_USERNAME "$JOKER_USERNAME"
  25. _saveaccountconf_mutable JOKER_PASSWORD "$JOKER_PASSWORD"
  26. if ! _get_root "$fulldomain"; then
  27. _err "Invalid domain"
  28. return 1
  29. fi
  30. _info "Adding TXT record"
  31. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value=$txtvalue"; then
  32. if _startswith "$response" "OK"; then
  33. _info "Added, OK"
  34. return 0
  35. fi
  36. fi
  37. _err "Error adding TXT record."
  38. return 1
  39. }
  40. #fulldomain txtvalue
  41. dns_joker_rm() {
  42. fulldomain=$1
  43. txtvalue=$2
  44. JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}"
  45. JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}"
  46. if ! _get_root "$fulldomain"; then
  47. _err "Invalid domain"
  48. return 1
  49. fi
  50. _info "Removing TXT record"
  51. # TXT record is removed by setting its value to empty.
  52. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value="; then
  53. if _startswith "$response" "OK"; then
  54. _info "Removed, OK"
  55. return 0
  56. fi
  57. fi
  58. _err "Error removing TXT record."
  59. return 1
  60. }
  61. #################### Private functions below ##################################
  62. #_acme-challenge.www.domain.com
  63. #returns
  64. # _sub_domain=_acme-challenge.www
  65. # _domain=domain.com
  66. _get_root() {
  67. fulldomain=$1
  68. i=1
  69. while true; do
  70. h=$(printf "%s" "$fulldomain" | cut -d . -f "$i"-100)
  71. _debug h "$h"
  72. if [ -z "$h" ]; then
  73. return 1
  74. fi
  75. # Try to remove a test record. With correct root domain, username and password this will return "OK: ..." regardless
  76. # of record in question existing or not.
  77. if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$h&label=jokerTXTUpdateTest&type=TXT&value="; then
  78. if _startswith "$response" "OK"; then
  79. _sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")"
  80. _domain=$h
  81. return 0
  82. fi
  83. fi
  84. i=$(_math "$i" + 1)
  85. done
  86. _debug "Root domain not found"
  87. return 1
  88. }
  89. _joker_rest() {
  90. data="$1"
  91. _debug data "$data"
  92. if ! response="$(_post "$data" "$JOKER_API" "" "POST")"; then
  93. _err "Error POSTing"
  94. return 1
  95. fi
  96. _debug response "$response"
  97. return 0
  98. }