summaryrefslogtreecommitdiffstats
path: root/jabberwall.pl
blob: 23267efbfd1c4a3d7b7d19767b2670befae17201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
use warnings;
use strict;
use Config::Simple;
use Net::Jabber qw(Client);
use File::Basename;
use Data::Dumper;

# config file syntax: "option value" 
# options are: server, port, username, password, ressource
# location: ~/.jabberwallrc

if(@ARGV != 3) {
  print "usage: ", basename($0), " <userlist> <subject> <body>\n";
  exit 1;
}

open FH, "<", $ARGV[0] or die "$ARGV[0]: $!";
my @recipients = <FH>;
close FH;

my %config;
Config::Simple->import_from("$ENV{HOME}/.jabberwallrc", \%config);

my $clnt = new Net::Jabber::Client;

my $status = $clnt->Connect(hostname=>$config{server}, port=>$config{port}, tls=>1);

if (!defined($status)) {
  die "Jabber connect error ($!)\n";
}

my @result = $clnt->AuthSend(username=>$config{username},
  password=>$config{password},
  resource=>$config{resource});

if ($result[0] ne "ok") {
  die "Jabber auth error: @result\n";
}

chomp(my $subject = $ARGV[1]);
my $body = $ARGV[2];

for my $to (@recipients) {
  chomp $to;
  next if ($to eq "");
  
  $clnt->MessageSend(to=>$to,
    subject=>$subject,
    body=>$body,
    type=>"message",
    priority=>0);
}

$clnt->Disconnect();