Comparison

mod_post_msg/sendxmpp-curl.sh @ 4524:9764d27db681

mod_post_msg: Add sendxmpp-curl I wrote this script around the same time as this module. My local copy has a last modification timestamp of 2011-03-29, so it's been unchanged since then. The original rationale was that it seemed overkill to establish an entire XMPP session just to send a single message. Nowadays I'm quite happy using `clix` for this kind task.
author Kim Alvefur <zash@zash.se>
date Tue, 23 Mar 2021 15:24:47 +0100
comparison
equal deleted inserted replaced
4523:6e20e6bf96f0 4524:9764d27db681
1 #!/bin/bash
2 # Does HTTP POST compatible with mod_post_msg for prosody
3 # Aims to be compatible with sendxmpp syntax
4
5 # API:
6 # http://host/msg/user => msg to user@host
7 # or http://whatever/msg/user@host => same
8 # HTTP Basic auth
9
10 # sendxmpp
11 # $0 [options] <recipient>
12
13 test -f $HOME/.sendxmpprc &&
14 read username password < $HOME/.sendxmpprc
15
16 TEMP="$(getopt -o f:u:p:j:o:r:tlcs:m:iwvhd -l file:,username:,password:,jserver:,component:,resource:,tls,headline,message-type:,chatroom,subject:,message:,interactive,raw,verbose,help,usage,debug -n "${0%%*/}" -- "$@" )"
17
18 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
19
20 eval set -- "$TEMP"
21
22 while true; do
23 case "$1" in
24 -f|--file) read username password < "$2"; shift 2;;
25 -u|--username) username="$2"; shift 2;;
26 -p|--password) password="$2"; shift 2;;
27 -j|--jserver) server="$2"; shift 2;;
28 -m|--message) message="$2"; shift 2;;
29 -v|--verbose) verbose="yes"; shift;;
30 -i|--interactive) interactive="yes"; shift;; # multiple messages, one per line on stdin
31 -r|--resource) resource="$OPTARG"; shift 2;; # not used
32 -h|--help|--usage)
33 echo "usage: ${0##*/} [options] <recipient>"
34 echo "or refer to the the source code ;)"; exit;;
35 --) shift ; break ;;
36 *) echo "option $1 is not implemented" >&1; shift ;; # TODO stuff
37 # FIXME the above will fail if the opt has a param
38 esac
39 done
40
41 if [ $# -gt 1 ]; then
42 echo "multile recipients not implemented" >&1 # TODO stuff
43 exit 1
44 fi
45
46 # Can be user@host or just user, in wich case the http host is used
47 recipient="$1"
48 shift
49
50 if [ -z "$server" ]; then
51 server="${username#*@}:5280"
52 fi
53
54 if [ -z "$recipient" -o -z "$server" -o -z "$username" ]; then
55 echo "required parameter missing or empty" >&1
56 exit 1
57 fi
58
59 do_send() {
60 #echo \
61 curl "http${secure:+s}://$server/msg/$recipient" \
62 -s ${verbose:+-v} \
63 -u "$username${password:+:$password}" \
64 "$@"
65 }
66
67 send_text() {
68 do_send -H "Content-Type: text/plain" "$@"
69 }
70
71 if [ -z "$interactive" ]; then
72 send_text -d "${message:-@-}"
73 else
74 while read line; do
75 send_text -d "$line"
76 done
77 fi
78 # TODO single curl line