Mirror of acme.sh — A pure Unix shell script implementing ACME client protocol
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.

xmpp.sh 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env sh
  2. #Support xmpp via sendxmpp
  3. #XMPP_BIN="/usr/bin/sendxmpp"
  4. #XMPP_BIN_ARGS="-n -t --tls-ca-path=/etc/ssl/certs"
  5. #XMPP_TO="zzzz@example.com"
  6. xmpp_send() {
  7. _subject="$1"
  8. _content="$2"
  9. _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  10. _debug "_subject" "$_subject"
  11. _debug "_content" "$_content"
  12. _debug "_statusCode" "$_statusCode"
  13. XMPP_BIN="${XMPP_BIN:-$(_readaccountconf_mutable XMPP_BIN)}"
  14. if [ -n "$XMPP_BIN" ] && ! _exists "$XMPP_BIN"; then
  15. _err "It seems that the command $XMPP_BIN is not in path."
  16. return 1
  17. fi
  18. _XMPP_BIN=$(_xmpp_bin)
  19. if [ -n "$XMPP_BIN" ]; then
  20. _saveaccountconf_mutable XMPP_BIN "$XMPP_BIN"
  21. else
  22. _clearaccountconf "XMPP_BIN"
  23. fi
  24. XMPP_BIN_ARGS="${XMPP_BIN_ARGS:-$(_readaccountconf_mutable XMPP_BIN_ARGS)}"
  25. if [ -n "$XMPP_BIN_ARGS" ]; then
  26. _saveaccountconf_mutable XMPP_BIN_ARGS "$XMPP_BIN_ARGS"
  27. else
  28. _clearaccountconf "XMPP_BIN_ARGS"
  29. fi
  30. XMPP_TO="${XMPP_TO:-$(_readaccountconf_mutable XMPP_TO)}"
  31. if [ -n "$XMPP_TO" ]; then
  32. if ! _xmpp_valid "$XMPP_TO"; then
  33. _err "It seems that the XMPP_TO=$XMPP_TO is not a valid xmpp address."
  34. return 1
  35. fi
  36. _saveaccountconf_mutable XMPP_TO "$XMPP_TO"
  37. fi
  38. result=$({ _xmpp_message | eval "$(_xmpp_cmnd)"; } 2>&1)
  39. # shellcheck disable=SC2181
  40. if [ $? -ne 0 ]; then
  41. _debug "xmpp send error."
  42. _err "$result"
  43. return 1
  44. fi
  45. _debug "xmpp send success."
  46. return 0
  47. }
  48. _xmpp_bin() {
  49. if [ -n "$XMPP_BIN" ]; then
  50. _XMPP_BIN="$XMPP_BIN"
  51. elif _exists "sendxmpp"; then
  52. _XMPP_BIN="sendxmpp"
  53. else
  54. _err "Please install sendxmpp first."
  55. return 1
  56. fi
  57. echo "$_XMPP_BIN"
  58. }
  59. _xmpp_cmnd() {
  60. case $(basename "$_XMPP_BIN") in
  61. sendxmpp)
  62. echo "'$_XMPP_BIN' '$XMPP_TO' $XMPP_BIN_ARGS"
  63. ;;
  64. *)
  65. _err "Command $XMPP_BIN is not supported, use sendxmpp."
  66. return 1
  67. ;;
  68. esac
  69. }
  70. _xmpp_message() {
  71. echo "$_subject"
  72. }
  73. _xmpp_valid() {
  74. _contains "$1" "@"
  75. }