Import Upstream version 0.0.5 upstream/0.0.5
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 11 Aug 2017 22:35:24 +0000 (19:35 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Fri, 11 Aug 2017 22:35:24 +0000 (19:35 -0300)
Changes [new file with mode: 0644]
INSTALL [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
META.yml [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
sendxmpp [new file with mode: 0755]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..45b5477
--- /dev/null
+++ b/Changes
@@ -0,0 +1,22 @@
+2004-12-01: version 0.0.5 released.
+       - don't be too picky about passwords
+       - verbose output
+       - better error handling
+       - improved documentation
+       - use subject for chatroom
+
+2004-11-21: version 0.0.4 released.
+       - small fixes
+       - packaging (after Gentoo request)
+       - documentation (man)
+
+2004-11-17: version 0.0.3 is released. New features are:
+       - Support for authentication using SSL/TLS;
+       - Support for sending messages to chatrooms;
+       - Support for providing login information on the command line;
+       - Improved error handling;
+       - NOTE: the .sendxmpprc format has changed.
+
+2004-11-01: version 0.0.2 released. Initial release
+
+
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..08e77a1
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,12 @@
+INSTALL
+-------
+sendxmpp requires perl 5.x, Getopt::Long and Net::XMPP.
+
+$ tar xvfz sendxmpp-(version).tar.gz
+$ cd sendxmpp-(version)
+$ perl Makefile.pm
+$ make
+$ make install
+
+
+
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..3e4c8b2
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,8 @@
+Makefile.PL
+MANIFEST
+sendxmpp
+Changes
+README
+INSTALL
+Changes
+META.yml                                 Module meta-data (added by MakeMaker)
diff --git a/META.yml b/META.yml
new file mode 100644 (file)
index 0000000..1eeca68
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,12 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         sendxmpp
+version:      0.0.5
+version_from: sendxmpp
+installdirs:  site
+requires:
+    Getopt::Long:                  2
+    Net::XMPP:                     1
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..46a74a8
--- /dev/null
@@ -0,0 +1,13 @@
+# Time-stamp: <2004-11-21 00:27:48 (djcb)>
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile (NAME => 'sendxmpp',
+              AUTHOR => 'Dirk-Jan C. Binnema (djcb@djcbsoftware.nl)',
+              ABSTRACT => 'Script for sending xmpp messages',
+              PREREQ_PM => {'Getopt::Long'=>2.00,
+                            'Net::XMPP'=>1.0},
+              VERSION_FROM => 'sendxmpp',
+              EXE_FILES => ['sendxmpp']
+              );
+
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..939ec3d
--- /dev/null
+++ b/README
@@ -0,0 +1,26 @@
+Time-stamp: <2004-11-20 22:52:12 (djcb)>; -*-mode:text-*- 
+
+README 
+------
+
+sendxmpp is a perl-script to send XMPP (jabber) messages, similar to
+what mail(1) does for mail. XMPP is an open, non-proprietary protocol
+for instant messaging. See www.jabber.org for more information.
+
+sendxmpp was written by me, Dirk-Jan C. Binnema, and is available
+under the term of the GNU General Public License v2. The hard work is
+done by Ryan Eatmon's Net::XMPP-modules, and you need have them
+installed for sendxmpp to work.
+
+Obviously, you also need a jabber account; they are freely available
+at jabber.org, but you can also install your own servers.
+
+sendxmpp is already in use for monitoring remote servers (servers can
+warn by sending xmmp-messages), and watching CVS commit messages
+(developers are all connected to a XMPP-chatroom to which messages are
+sent. 
+
+I am interested in hearing about other uses.
+
+Dirk-Jan Binnema <djcb@djcbsoftware.nl>, or djcb@jabber.org (IM).
+
diff --git a/sendxmpp b/sendxmpp
new file mode 100755 (executable)
index 0000000..10bc604
--- /dev/null
+++ b/sendxmpp
@@ -0,0 +1,464 @@
+#!/usr/bin/perl -w
+#-*-mode:perl-*-
+#Time-stamp: <2004-12-01 14:52:47 (djcb)>
+
+# script to send message using xmpp (aka jabber), 
+#   somewhat resembling mail(1)
+
+# author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+# copyright (c) 2004, Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
+#
+# released under the terms of the GNU General Public License v2
+
+use Net::XMPP;
+use Getopt::Long;
+use strict;
+
+
+# subroutines decls
+sub xmpp_login($$$$$$);
+sub xmpp_send_message($$$$);
+sub xmpp_send_chatroom_message($$$$$);
+sub xmpp_logout($);
+sub xmpp_check_result;
+sub parse_cmdline();
+sub error_exit;
+sub debug_print;
+sub read_config_file($);
+sub push_hash($$);
+sub main ();
+
+
+my # MakeMaker
+$VERSION     = '0.0.5';
+my $RESOURCE = 'sendxmpp';
+my $VERBOSE  = 0;
+my $DEBUG    = 0;
+
+            
+# start!
+&main;
+
+
+#
+# main: main routine
+#
+sub main () {
+
+    my $cmdline = parse_cmdline();
+    
+    $DEBUG   = 1 if ($$cmdline{'debug'});
+    $VERBOSE = 1 if ($$cmdline{'verbose'});
+
+    my $config = read_config_file ($$cmdline{'file'})
+       unless ($$cmdline{'jserver'} && $$cmdline{'username'} && $$cmdline{'password'});        
+    
+    # login to xmpp
+    my $cnx =  xmpp_login ($$cmdline{'jserver'}  || $$config{'jserver'},
+                          $$cmdline{'username'} || $$config{'username'},
+                          $$cmdline{'password'} || $$config{'password'},
+                          $$cmdline{'resource'},
+                          $$cmdline{'tls'},
+                          $$cmdline{'debug'})
+       or error_exit("cannot login: $!");
+    
+    
+    unless ($$cmdline{'chatroom'}) {
+       xmpp_send_message ($cnx,
+                          $$cmdline{'recipient'},
+                          $$cmdline{'subject'},
+                          $$cmdline{'message'});
+    } else {
+       xmpp_send_chatroom_message ($cnx,
+                                $$cmdline{'resource'},
+                                $$cmdline{'subject'},
+                                $$cmdline{'recipient'},
+                                $$cmdline{'message'});
+    }
+
+    xmpp_logout($cnx);
+    exit(0);
+}
+
+
+#
+# read_config_file: read the configuration file
+# input: filename
+# output: hash with 'user', 'jserver' and 'password' keys
+#
+sub read_config_file ($) {
+   
+    # check permissions
+    my $cfg_file = shift;
+    error_exit ("cannot read $cfg_file: $!") 
+       unless (-r $cfg_file);    
+    my $owner  = (stat($cfg_file))[4];
+    error_exit ("you must own $cfg_file")
+       unless ($owner == $>); 
+    my $mode = (stat($cfg_file))[2] & 07777;
+    error_exit ("$cfg_file must have mode 0600")
+       unless ($mode == 0600);
+    
+    open (CFG,"<$cfg_file")
+       or error_exit("cannot open $cfg_file for reading: $!");
+
+    my %config;
+    my $line = 0;
+    while (<CFG>) {
+       
+       ++$line;
+       
+       next if (/^\s*$/);     # ignore empty lines
+       next if (/^\s*\#.*/);  # ignore comment lines
+       
+       s/\#.*$//; # ignore comments in lines
+       
+       if (/([-\.\w]+)@([-\.\w]+)\s+(\S+)\s*$/) {
+           %config = ('username'=>$1,
+                      'jserver'=>$2, 
+                      'password'=>$3);
+
+       } else {
+           close(CFG);
+           error_exit ("syntax error in line $line of $cfg_file");
+       }
+    }
+
+    close(CFG);
+    
+    error_exit ("no correct config found in $cfg_file") 
+       unless (scalar(%config));       
+
+    if ($DEBUG || $VERBOSE) {
+       while (my ($key,$val) = each %config) {
+           debug_print ("config: '$key' => '$val'");
+       }
+    }      
+
+    return \%config;              
+}
+
+
+
+#
+# parse_cmdline: parse commandline options
+# output: hash with commandline options
+#
+sub parse_cmdline () {
+    
+   usage() unless (scalar(@ARGV));
+           
+    my ($subject,$file,$resource,$jserver,$username,$password,
+       $message,$chatroom,$debug,$tls,$help,$verbose);
+    my $res = GetOptions ('subject|s=s'    => \$subject,
+                         'file|f=s'       => \$file,
+                         'resource|r=s'   => \$resource,
+                         'jserver|j=s'    => \$jserver,
+                         'username|u=s'   => \$username,
+                         'password|p=s'   => \$password,
+                         'message|m=s'    => \$message,
+                         'chatroom|c'     => \$chatroom,
+                         'tls|t'          => \$tls,
+                         'help|usage|h'   => \$help,
+                         'debug|d'        => \$debug,
+                         'verbose|v'      => \$verbose);
+    usage () 
+       if ($help);   
+   
+    my $rcpt = $ARGV[0]
+       or error_exit("no recipient specified");
+
+    # read message from STDIN or or from -m/--message parameter
+    my $txt;
+    if ($message) {
+       open (MSG, "<$message")
+           or error_exit ("cannot open message file '$message': $!");
+       while (<MSG>) {$txt.=$_};
+       close(MSG);
+    } else {
+       while (<STDIN>) {$txt.=$_};
+    }
+    
+    my %dict = ('subject'    => ($subject  or ''),
+               'resource'   => ($resource or $RESOURCE),
+               'jserver'    => ($jserver or ''),
+               'username'   => ($username or ''),
+               'password'   => ($password or ''),
+               'chatroom'   => ($chatroom or 0),
+               'tls'        => ($tls or 0),
+               'debug'      => ($debug or 0),
+               'message'    => ($txt or ''),
+               'verbose'    => ($verbose or 0),
+               'file'       => ($file or ($ENV{'HOME'}.'/.sendxmpprc')),
+               'recipient'  => $rcpt);
+
+   if ($DEBUG || $VERBOSE) {
+       while (my ($key,$val) = each %dict) {
+          debug_print ("cmdline: '$key' => '$val'");
+       }
+   }       
+    
+   return \%dict;    
+}
+
+
+
+#
+# xmpp_login: login to the xmmp (jabber) server
+# input: hostname,username,password,resource,tls,debug
+# output: an XMPP connection object
+#
+sub xmpp_login ($$$$$$) {
+
+    my ($host,$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);
+    xmpp_check_result("Connect",\@res,$cnx);
+
+    
+    @res = $cnx->AuthSend('hostname'=>$host,
+                         'username'=>$user,
+                         'password'=>$pw,
+                         'resource'=>$res);
+    xmpp_check_result('AuthSend',\@res,$cnx);
+        
+    #@res = $cnx->PresenceSend(type=>'unavailable');
+    #mpp_check_result("PresenceSend",\@res,$cnx);
+    
+    return $cnx;    
+}
+
+
+#
+# xmmp_send_message: send a message to some xmmp user
+# input: connection,recipient,subject,msg
+#
+sub xmpp_send_message ($$$$) {
+    
+    my ($cnx,$rcpt,$subject,$msg) = @_;
+    # for some reason, MessageSend does not return anything
+    $cnx->MessageSend('to'=>$rcpt,
+                     'subject'=>$subject,
+                     'body'=>$msg);
+    
+    xmpp_check_result('MessageSend',0,$cnx);
+}
+    
+    
+#
+# xmpp_send_chatroom_message: send a message to a chatroom
+# input: connection,resource,subject,recipient,message
+#
+sub xmpp_send_chatroom_message ($$$$$) {
+
+    my ($cnx,$resource,$subject,$rcpt,$msg) =  @_;
+    
+    # set the presence
+    my $pres = new Net::XMPP::Presence;
+    my $res = $pres->SetTo("$rcpt/$resource");
+
+    $cnx->Send($pres); 
+
+    # create/send the message
+    my $groupmsg = new Net::XMPP::Message;
+    $groupmsg->SetMessage(to=>$rcpt, 
+                         body=>$msg,
+                         subject=>$subject,
+                         type=>'groupchat');
+
+    $res = $cnx->Send($groupmsg);
+    xmpp_check_result ('Send',$res,$cnx); 
+    
+    # leave the group
+    $pres->SetPresence (Type=>'unavailable',To=>$rcpt);
+}
+
+
+#
+# xmmp_logout: log out from the xmpp server
+# input: connection
+#
+sub xmpp_logout($) {
+    
+    # HACK
+    # messages may not be received if we log out too quickly...
+    sleep 1; 
+    
+    my $cnx = shift;
+    $cnx->Disconnect();
+    xmpp_check_result ('Disconnect',0); # well, nothing to check, really
+}
+
+
+
+#
+# xmpp_check_result: check the return value from some xmpp function execution
+# input: text, result, [connection]                   
+#
+sub xmpp_check_result {
+
+    my ($txt,$res,$cnx)=@_;
+    
+    error_exit ("Error '$txt': result undefined")
+       unless (defined $res);  
+
+    # res may be 0
+    if ($res == 0) {
+       debug_print "$txt";
+    # result can be true or 'ok' 
+    } elsif ((@$res == 1 && $$res[0]) || $$res[0] eq 'ok') {   
+       debug_print "$txt: " .  $$res[0];
+    # otherwise, there is some error
+    } else {   
+       my $errmsg = $cnx->GetErrorCode() || '?';
+       error_exit ("Error '$txt': " . join (': ',@$res) . "[$errmsg]", $cnx);
+    }
+}
+
+
+#
+# debug_print: print the data if defined and DEBUG || VERBOSE is TRUE
+# input: [array of strings]
+#
+sub debug_print {
+    print STDERR "sendxmpp: " . (join ' ',@_) . "\n"
+       if (@_ && ($DEBUG ||$VERBOSE));
+}
+
+
+#
+# error_exit: print error message and exit the program
+#             logs out if there is a connection 
+# input: error, [connection]
+#
+sub error_exit {
+    
+    my ($err,$cnx) = @_;
+    print STDERR "$err\n";   
+    xmpp_logout ($cnx) 
+       if ($cnx);
+    exit 1;
+}
+
+
+#
+# usage: print short usage message and exit
+#
+sub usage () {
+   
+    print 
+       "sendxmpp version $VERSION, (c) 2004 Dirk-Jan C. Binnema\n" .
+       "usage: sendxmpp [options] <recipient>\n" .
+       "or refer to the the sendxmpp manpage\n";
+    
+    exit 0;
+}
+
+
+
+#
+# the fine manual
+#
+=head1 NAME
+
+sendxmpp - send xmpp messages from the commandline.
+
+=head1 SYNOPSIS
+
+sendxmpp [options] <recipient>
+
+=head1 DESCRIPTION
+
+sendxmpp is a program to send XMPP (Jabber) messages from the commandline, not
+unlike L<mail(1)>. Messages can be sent both to individual recipients and chatrooms.
+
+the recipient is either another jabber-account or a jabber-chatroom (use '-c' to tell 
+sendxmpp it's a chatroom)
+
+=head1 OPTIONS
+
+B<-f>,B<--file> <file>
+use <file> configuration file instead of ~/.sendxmpprc
+
+B<-u>,B<--username> <user>
+use <user> instead of the one in the configuration file
+
+B<-p>,B<--password> <password>
+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
+
+B<-r>,B<--resource> <res>
+use resource <res> for the sender [default: 'sendxmpp']; when sending to a chatroom, this determines the 'alias'
+
+B<-t>,B<--tls>
+connect securely, using TLS
+
+B<-c>,B<--chatroom>
+send the message to a chatroom 
+
+B<-s>,B<--subject> <subject> 
+set the subject for the message to <subject> [default: '']; when sending to a chatroom,
+this will set the subject for the chatroom
+
+B<-m>,B<--message> <message>
+read the message from <message> (a file) instead of stdin
+
+B<-v>,B<--verbose>
+give verbose output about what is happening
+
+B<-h>,B<--help>,B<--usage>
+show a 'Usage' message
+
+B<-d>,B<--debug>
+show debugging info while running. B<WARNING>: This will include passwords etc. so be careful with the output!
+
+=head1 CONFIGURATION FILE
+
+You may define a '~/.sendxmpprc' file with the necessary data for your 
+xmmp-account, with a line of the format:
+
+   <user>@<host> <password>
+
+e.g.:
+
+    # my account
+    alice@jabber.org  secret
+
+('#' and newlines are allowed like in shellscripts)
+    
+B<NOTE>: for your security, sendxmpp demands that the configuration
+file is owned by you and has file permissions 600.
+
+=head1 EXAMPLE
+
+   $ echo "hello bob!" | sendxmpp -s hello someone@jabber.org
+
+     or to send to a chatroom:
+
+   $ echo "Dinner Time" | sendxmpp -r TheCook --chatroom test2@conference.jabber.org    
+
+=head1 SEE ALSO
+
+Documentation for the L<Net::XMPP> module
+
+The jabber homepage: http://www.jabber.org/
+
+The sendxmpp homepage: http://www.djcbsoftware.nl/code/sendxmmp (the xmmp homepage)
+
+=head1 AUTHOR
+
+sendxmpp has been written by Dirk-Jan C. Binnema <dirk-jan@djcbsoftware.nl>, and uses
+the L<Net::XMPP> modules written by Ryan Eatmon.
+
+=cut
+
+
+
+