version 1.1.1.5, 2006/10/04 21:06:45 |
version 1.1.1.6, 2006/10/04 21:07:15 |
|
|
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
|
|
|
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' |
|
if 0; # not running under some shell |
#-*-mode:perl-*- |
#-*-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), |
# script to send message using xmpp (aka jabber), |
# somewhat resembling mail(1) |
# somewhat resembling mail(1) |
Line 15 use Getopt::Long; |
|
Line 18 use Getopt::Long; |
|
use strict; |
use strict; |
|
|
# subroutines decls |
# subroutines decls |
sub xmpp_login($$$$$$); |
sub xmpp_login($$$$$$$); |
sub xmpp_send ($$$); |
sub xmpp_send ($$$); |
sub xmpp_send_message($$$$); |
sub xmpp_send_message($$$$); |
sub xmpp_send_chatroom_message($$$$$); |
sub xmpp_send_chatroom_message($$$$$); |
|
|
sub main(); |
sub main(); |
|
|
my # MakeMaker |
my # MakeMaker |
$VERSION = '0.0.7.1'; |
$VERSION = '0.0.8'; |
my $RESOURCE = 'sendxmpp'; |
my $RESOURCE = 'sendxmpp'; |
my $VERBOSE = 0; |
my $VERBOSE = 0; |
my $DEBUG = 0; |
my $DEBUG = 0; |
|
|
|
|
# login to xmpp |
# login to xmpp |
my $cnx = xmpp_login ($$cmdline{'jserver'} || $$config{'jserver'}, |
my $cnx = xmpp_login ($$cmdline{'jserver'} || $$config{'jserver'}, |
|
$$cmdline{'port'} || $$config{'port'}, |
$$cmdline{'username'} || $$config{'username'}, |
$$cmdline{'username'} || $$config{'username'}, |
$$cmdline{'password'} || $$config{'password'}, |
$$cmdline{'password'} || $$config{'password'}, |
$$cmdline{'resource'}, |
$$cmdline{'resource'}, |
Line 132 sub read_config_file ($) { |
|
Line 136 sub read_config_file ($) { |
|
|
|
s/\#.*$//; # ignore comments in lines |
s/\#.*$//; # ignore comments in lines |
|
|
if (/([-\.\w]+)@([-\.\w]+)\s+(\S+)\s*$/) { |
if (/([-\.\w]+)@([-\.\w:]+)\s+(\S+)\s*$/) { |
%config = ('username' => $1, |
%config = ('username' => $1, |
'jserver' => $2, |
'jserver' => $2, |
|
'port' => 0, |
'password' => $3); |
'password' => $3); |
|
|
|
if ($config{'jserver'} =~ /(.*):(\d+)/) { |
|
$config{'jserver'} = $1; |
|
$config{'port'} = $2; |
|
} |
} else { |
} else { |
close CFG; |
close CFG; |
error_exit ("syntax error in line $line of $cfg_file"); |
error_exit ("syntax error in line $line of $cfg_file"); |
Line 166 sub parse_cmdline () { |
|
Line 176 sub parse_cmdline () { |
|
|
|
usage() unless (scalar(@ARGV)); |
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); |
$message,$chatroom,$debug,$tls,$interactive,$help,$verbose); |
my $res = GetOptions ('subject|s=s' => \$subject, |
my $res = GetOptions ('subject|s=s' => \$subject, |
'file|f=s' => \$file, |
'file|f=s' => \$file, |
Line 187 sub parse_cmdline () { |
|
Line 197 sub parse_cmdline () { |
|
my $rcpt = $ARGV[0] |
my $rcpt = $ARGV[0] |
or error_exit "no recipient specified"; |
or error_exit "no recipient specified"; |
|
|
if ($message && $interactive) { |
if ($message && $interactive) { |
error_exit "cannot have both -m (--message) and -i (--interactive)\n"; |
error_exit "cannot have both -m (--message) and -i (--interactive)\n"; |
} |
} |
|
|
|
if ($jserver && $jserver =~ /(.*):(\d+)/) { |
|
$jserver = $1; |
|
$port = $2; |
|
} |
|
|
my %dict = ('subject' => ($subject or ''), |
my %dict = ('subject' => ($subject or ''), |
'resource' => ($resource or $RESOURCE), |
'resource' => ($resource or $RESOURCE), |
'jserver' => ($jserver or ''), |
'jserver' => ($jserver or ''), |
|
'port' => ($port or 0), |
'username' => ($username or ''), |
'username' => ($username or ''), |
'password' => ($password or ''), |
'password' => ($password or ''), |
'chatroom' => ($chatroom or 0), |
'chatroom' => ($chatroom or 0), |
Line 216 sub parse_cmdline () { |
|
Line 232 sub parse_cmdline () { |
|
|
|
# |
# |
# xmpp_login: login to the xmpp (jabber) server |
# 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 |
# 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)); |
my $cnx = new Net::XMPP::Client(debuglevel=>($debug?2:0)); |
error_exit "could not create XMPP client object: $!" |
error_exit "could not create XMPP client object: $!" |
unless ($cnx); |
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); |
xmpp_check_result("Connect",\@res,$cnx); |
|
|
|
|
@res = $cnx->AuthSend('hostname' => $host, |
@res = $cnx->AuthSend('hostname' => $host, |
'username' => $user, |
'username' => $user, |
'password' => $pw, |
'password' => $pw, |
Line 338 sub xmpp_check_result { |
|
Line 359 sub xmpp_check_result { |
|
my ($txt,$res,$cnx)=@_; |
my ($txt,$res,$cnx)=@_; |
|
|
error_exit ("Error '$txt': result undefined") |
error_exit ("Error '$txt': result undefined") |
unless (defined $res); |
unless (defined $res); |
|
|
# res may be 0 |
# res may be 0 |
if ($res == 0) { |
if ($res == 0) { |
debug_print "$txt"; |
debug_print "$txt"; |
Line 433 B<-p>,B<--password> <password> |
|
Line 454 B<-p>,B<--password> <password> |
|
use <password> instead of the one in the configuration file |
use <password> instead of the one in the configuration file |
|
|
B<-j>,B<--jserver> <server> |
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> |
B<-r>,B<--resource> <res> |
use resource <res> for the sender [default: 'sendxmpp']; when sending to a chatroom, this determines the 'alias' |
use resource <res> for the sender [default: 'sendxmpp']; when sending to a chatroom, this determines the 'alias' |
|
|
# my account |
# my account |
alice@jabber.org secret |
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 |
B<NOTE>: for your security, sendxmpp demands that the configuration |
file is owned by you and has file permissions 600. |
file is owned by you and has file permissions 600. |
Line 488 file is owned by you and has file permis |
|
Line 513 file is owned by you and has file permis |
|
|
|
$ echo "Dinner Time" | sendxmpp -r TheCook --chatroom test2@conference.jabber.org |
$ 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 |
=head1 SEE ALSO |
|
|
Documentation for the L<Net::XMPP> module |
Documentation for the L<Net::XMPP> module |