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.

85 lines
3.3 KiB

2 years ago
2 years ago
2 years ago
  1. #!/usr/bin/env sh
  2. #
  3. # Author: Recolic Keghart <root@recolic.net>
  4. #
  5. # acme.sh user: please set your token here!
  6. [ -z "$FREEMYIP_Token" ] && FREEMYIP_Token="05ddb54360621d37dea67259"
  7. ################ Do not modify after this line ##############
  8. # Note: this script was executed in subshell. It means all env would be cleanup, and EXIT event would be called between different domain names. The only way to persist state is a temporary file.
  9. freemyip_prevdomain_tmpfile=/tmp/.acme-sh-freemyip-prevdomain
  10. # There is random failure while calling freemyip API too fast. This function automatically retry until success.
  11. freemyip_get_until_ok() {
  12. _fmi_url="$1"
  13. for i in $(seq 1 8); do
  14. _debug "HTTP GET freemyip.com API '$_fmi_url', retry $i/8..."
  15. _get "$_fmi_url" | tee /dev/fd/2 | grep OK && return 0
  16. sleep 1 # DO NOT send the request too fast
  17. done
  18. _err "Failed to request freemyip API: $_fmi_url . Server does not say 'OK'"
  19. return 2
  20. }
  21. #Usage: dns_freemyip_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  22. dns_freemyip_add() {
  23. fulldomain="$1"
  24. txtvalue="$2"
  25. _info "Add TXT record $txtvalue for $fulldomain using freemyip.com api"
  26. FREEMYIP_Token="${FREEMYIP_Token:-$(_readaccountconf_mutable FREEMYIP_Token)}"
  27. if [ -z "$FREEMYIP_Token" ]; then
  28. FREEMYIP_Token=""
  29. _err "You don't specify FREEMYIP_Token yet."
  30. _err "Please specify your token and try again."
  31. return 1
  32. fi
  33. #save the credentials to the account conf file.
  34. _saveaccountconf_mutable FREEMYIP_Token "$FREEMYIP_Token"
  35. if [ ! -f "$freemyip_prevdomain_tmpfile" ]; then
  36. echo "$fulldomain" >"$freemyip_prevdomain_tmpfile"
  37. else
  38. _err "freemyip API don't allow you to set multiple TXT record for the same subdomain! "
  39. _err "You must apply certificate for only one domain at a time! "
  40. _err "===="
  41. _err "For example, aaa.yourdomain.freemyip.com and bbb.yourdomain.freemyip.com and yourdomain.freemyip.com ALWAYS share the same TXT record. They will overwrite each other if you apply multiple domain at the same time. "
  42. _err "(You are trying to set TXT record for $fulldomain, but it will overwrite $(cat "$freemyip_prevdomain_tmpfile"))"
  43. _debug "If you are testing this workflow in github pipeline or acmetest, please set TEST_DNS_NO_SUBDOMAIN=1 and TEST_DNS_NO_WILDCARD=1"
  44. rm -f "$freemyip_prevdomain_tmpfile"
  45. return 2
  46. fi
  47. # txtvalue must be url-encoded. But it's not necessary for acme txt value.
  48. freemyip_get_until_ok "https://freemyip.com/update?token=$FREEMYIP_Token&domain=$fulldomain&txt=$txtvalue" 2>&1
  49. return $?
  50. }
  51. #Usage: fulldomain txtvalue
  52. #Remove the txt record after validation.
  53. dns_freemyip_rm() {
  54. fulldomain="$1"
  55. txtvalue="$2"
  56. _info "Delete TXT record $txtvalue for $fulldomain using freemyip.com api"
  57. rm -f "$freemyip_prevdomain_tmpfile"
  58. FREEMYIP_Token="${FREEMYIP_Token:-$(_readaccountconf_mutable FREEMYIP_Token)}"
  59. if [ -z "$FREEMYIP_Token" ]; then
  60. FREEMYIP_Token=""
  61. _err "You don't specify FREEMYIP_Token yet."
  62. _err "Please specify your token and try again."
  63. return 1
  64. fi
  65. #save the credentials to the account conf file.
  66. _saveaccountconf_mutable FREEMYIP_Token "$FREEMYIP_Token"
  67. # Leave the TXT record as empty or "null" to delete the record.
  68. freemyip_get_until_ok "https://freemyip.com/update?token=$FREEMYIP_Token&domain=$fulldomain&txt=" 2>&1
  69. return $?
  70. }