Browse Source

Notify xmpp (#2407)

* notify via xmpp (using sendxmpp)

* fix formatting in notify/xmpp.sh

* minor cleanup
fgma 1 month ago
parent
commit
b9994e52eb
1 changed files with 90 additions and 0 deletions
  1. 90
    0
      notify/xmpp.sh

+ 90
- 0
notify/xmpp.sh View File

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

Loading…
Cancel
Save