From c2022e798fdf6c7c9c4410901eb00a3769d12958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Reinbold?= Date: Tue, 12 May 2020 14:10:41 +0200 Subject: [PATCH] Initial commit --- .ruby-version | 1 + README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ jabbersend | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 .ruby-version create mode 100644 README.md create mode 100755 jabbersend diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ecd7ee5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.8 diff --git a/README.md b/README.md new file mode 100644 index 0000000..880508c --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# jabbersend + +jabbersend is a Ruby script to send XMPP (jabber) messages. + +Original script by Harisankar P S (https://github.com/coderhs) at +https://github.com/xmpp4r/xmpp4r/blob/master/data/doc/xmpp4r/examples/basic/jabbersend.rb + +## Setup + +### Prerequisites + + +- Ruby 2.5.8+ +- RubyGems + + +Example, to install Ruby and RubyGems on FreeBSD: + + + pkg inst devel/ruby-gems + + +Then, install `xmpp4r` gem: + + + gem install xmpp4r + + +Install the script + + + mkdir ~/bin + git clone https://github.com/greinbold/jabbersend + cp jabbersend/jabbersend ~/bin/ + chmod 700 ~/bin/jabbersend + + +Settings + +Edit `~/bin/jabbersend` and fill `myJID` and `myPassword` + + + # settings + myJID = 'user@example.com' + myPassword = 'securepassword' + ########## + + +Check if `$HOME/bin` is in your `$PATH` + + + echo $PATH | grep $HOME/bin + + +If isn't the case, add it according to your shell. Example for Bash: + + + PATH=$PATH:$HOME/bin; export PATH + + +## Usage + +The script will send a jabber message to the specified JID by the `-t` option. +The subject can be specified using the `-s` option, and the body can be +specified using the `-b` option. If the body is omitted, it will be taken from +stdin on run. + +Send a message + + + jabbersend -t dest@example.com -s "This is a test" -b "Hello, how are you?" + + +Help + + + jabbersend -h + + diff --git a/jabbersend b/jabbersend new file mode 100755 index 0000000..8c2b097 --- /dev/null +++ b/jabbersend @@ -0,0 +1,60 @@ +#!/usr/bin/env ruby + +# Original script by Harisankar P S (https://github.com/coderhs) +# at https://github.com/xmpp4r/xmpp4r/blob/master/data/doc/xmpp4r/examples/basic/jabbersend.rb +# +# This script will send a jabber message to the specified JID by the '-t' option. +# The subject can be specified using the '-s' option, and the body can be +# specified using the '-b' option. If the body is omitted, it will be taken from +# stdin on run. + +# settings +myJID = '' +myPassword = '' +########## + +require 'optparse' +require 'xmpp4r' +include Jabber + +if myJID.empty? || myPassword.empty? + puts "Please fill myJID and myPassword in the script." + exit 1 +end + +myJID = JID.new(myJID) +to = nil +subject = '' +body = nil +OptionParser.new do |opts| + opts.banner = 'Usage: jabbersend [-b \'body\'] -s \'subject\' -t dest@domain' + opts.separator '' + opts.on('-s', '--subject SUBJECT', 'sets the message\'s subject') { + |s| subject = s } + opts.on('-b', '--body BODY', 'sets the message\'s body') { |b| body = b } + opts.on('-t', '--to JID', 'sets the receiver') { |t| to = JID.new(t) } + opts.on_tail('-h', '--help', 'show this message') { + puts opts + exit + } + opts.parse!(ARGV) +end + +if to.nil? + puts "No receiver specified. See jabbersend -h" + exit 1 +end + +if body.nil? + puts "No body provided, so you can grab one now.\n\n" + body = STDIN.readlines.join +end + +cl = Client.new(myJID) +cl.connect +cl.auth(myPassword) + +m = Message.new(to, body).set_type(:normal).set_id('1').set_subject(subject) +puts m.to_s +cl.send(m) +cl.close