#!/usr/bin/perl -w
+
+eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
+ if 0; # not running under some shell
#-*-mode:perl-*-
-#Time-stamp: <2005-05-02 01:00:02 (djcb)>
+#Time-stamp: <2005-05-07 19:24:09 (djcb)>
# script to send message using xmpp (aka jabber),
# somewhat resembling mail(1)
use strict;
# subroutines decls
-sub xmpp_login($$$$$$);
+sub xmpp_login($$$$$$$);
sub xmpp_send ($$$);
sub xmpp_send_message($$$$);
sub xmpp_send_chatroom_message($$$$$);
sub main();
my # MakeMaker
-$VERSION = '0.0.7.1';
+$VERSION = '0.0.8';
my $RESOURCE = 'sendxmpp';
my $VERBOSE = 0;
my $DEBUG = 0;
# login to xmpp
my $cnx = xmpp_login ($$cmdline{'jserver'} || $$config{'jserver'},
+ $$cmdline{'port'} || $$config{'port'},
$$cmdline{'username'} || $$config{'username'},
$$cmdline{'password'} || $$config{'password'},
$$cmdline{'resource'},
s/\#.*$//; # ignore comments in lines
- if (/([-\.\w]+)@([-\.\w]+)\s+(\S+)\s*$/) {
+ if (/([-\.\w]+)@([-\.\w:]+)\s+(\S+)\s*$/) {
%config = ('username' => $1,
'jserver' => $2,
+ 'port' => 0,
'password' => $3);
+
+ if ($config{'jserver'} =~ /(.*):(\d+)/) {
+ $config{'jserver'} = $1;
+ $config{'port'} = $2;
+ }
} else {
close CFG;
error_exit ("syntax error in line $line of $cfg_file");
usage() unless (scalar(@ARGV));
- my ($subject,$file,$resource,$jserver,$username,$password,
+ my ($subject,$file,$resource,$jserver,$port,$username,$password,
$message,$chatroom,$debug,$tls,$interactive,$help,$verbose);
my $res = GetOptions ('subject|s=s' => \$subject,
'file|f=s' => \$file,
my $rcpt = $ARGV[0]
or error_exit "no recipient specified";
- if ($message && $interactive) {
- error_exit "cannot have both -m (--message) and -i (--interactive)\n";
- }
+ if ($message && $interactive) {
+ error_exit "cannot have both -m (--message) and -i (--interactive)\n";
+ }
+
+ if ($jserver && $jserver =~ /(.*):(\d+)/) {
+ $jserver = $1;
+ $port = $2;
+ }
my %dict = ('subject' => ($subject or ''),
'resource' => ($resource or $RESOURCE),
'jserver' => ($jserver or ''),
+ 'port' => ($port or 0),
'username' => ($username or ''),
'password' => ($password or ''),
'chatroom' => ($chatroom or 0),
#
# xmpp_login: login to the xmpp (jabber) server
-# input: hostname,username,password,resource,tls,debug
+# input: hostname,port,username,password,resource,tls,debug
# output: an XMPP connection object
#
-sub xmpp_login ($$$$$$) {
+sub xmpp_login ($$$$$$$) {
- my ($host,$user,$pw,$res,$tls,$debug) = @_;
+ my ($host,$port,$user,$pw,$res,$tls,$debug) = @_;
my $cnx = new Net::XMPP::Client(debuglevel=>($debug?2:0));
error_exit "could not create XMPP client object: $!"
unless ($cnx);
- my @res = $cnx->Connect(hostname=>$host,tls=>$tls);
+ my @res;
+ if (!$port) {
+ @res = $cnx->Connect(hostname=>$host,tls=>$tls);
+ } else {
+ @res = $cnx->Connect(hostname=>$host,port=>$port,tls=>$tls);
+ }
+
xmpp_check_result("Connect",\@res,$cnx);
-
@res = $cnx->AuthSend('hostname' => $host,
'username' => $user,
'password' => $pw,
my ($txt,$res,$cnx)=@_;
error_exit ("Error '$txt': result undefined")
- unless (defined $res);
-
+ unless (defined $res);
+
# res may be 0
if ($res == 0) {
debug_print "$txt";
use <password> instead of the one in the configuration file
B<-j>,B<--jserver> <server>
-use jabber server <server> instead of the one in the configuration file
+use jabber server <server> instead of the one in the configuration file. Note that you can add :<port> to use a non-default port, ie. B<-j myjabber.org:1234>
B<-r>,B<--resource> <res>
use resource <res> for the sender [default: 'sendxmpp']; when sending to a chatroom, this determines the 'alias'
# my account
alice@jabber.org secret
-('#' and newlines are allowed like in shellscripts)
+('#' and newlines are allowed like in shellscripts). You can add :<port> to
+the <host> if you need an alternative port, ie.
+
+ # account with weird port number
+ alice@myjabberhost.com:1234 secret
B<NOTE>: for your security, sendxmpp demands that the configuration
file is owned by you and has file permissions 600.
$ echo "Dinner Time" | sendxmpp -r TheCook --chatroom test2@conference.jabber.org
+ or to send your system logs somewhere, as new lines appear:
+
+ $ tail -f /var/log/syslog | sendxmpp -i sysadmin@myjabberserver.com
+
+ NOTE: be careful not the overload public jabber services
+
=head1 SEE ALSO
Documentation for the L<Net::XMPP> module