summaryrefslogtreecommitdiffstats
path: root/jabberwall.pl
blob: c8c4897ee05a795e9658a6bde3e58e6fe3c8d1a8 (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
56
57
58
#!/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 != 1) {
  print "usage: ", basename($0), " <userlist>\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});

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";
}

my $body = '';
while (<STDIN>) {
  $body .= $_;
}
chomp($body);

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

$clnt->Disconnect();