4524
|
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 |