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
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl 
use Net::Jabber qw(Client); 
use strict; 
# Announce resources 
my %resource = ( online => "/announce/online", );

# default options 
my %option = ( 
  server => "moocow:5222", 
  user   => "admin", 
  type   => "online", 
);

# Default port if none specified 
$option{server} = "moocow:5222";

# Ask for password if none given 
unless ($option{pass}) { 
  print "Password: "; 
  system "stty -echo"; 
  $option{pass} = <STDIN>; 
  system "stty echo"; 
  chomp $option{pass}; 
  print "\n"; 
}

# Connect to Jabber server 
my ($host, $port) = split(":", $option{server}, 2); 
print "Connecting to $host:$port as $option{user}\n"; 
my $c = new Net::Jabber::Client; 
$c->Connect( 
  hostname => $host, 
  port     => $port, 
) or die "Cannot connect to Jabber server at $option{server}\n";

my @result; 
eval { 
  @result = $c->AuthSend( 
    username => $option{user}, 
    password => $option{pass}, 
    resource => "GAIM", 
  ); 
};

die "Cannot connect to Jabber server at $option{server}\n" if $@; 
if ($result[0] ne "ok") { 
  die "Authorisation failed ($result[1]) for user $option{user} on 
$option{server}\n"; 
} 
print "Sending $option{type} messages\n";

# The message.  Change the file name in this 'open' line to 
# the name of your fifo. 
open(STATUS, "cat /var/log/log-fifo 2>&1 |") || die "UGH: there's issues:  $!";

while (<STATUS>) { 
        my $xml .= qq[<subject>] . ($option{type} eq "online" ? "Admin Message" : "MOTD") . qq[</subject>]; 
        my $to = $host . $resource{$option{type}}; 
        $xml .= qq[<message to="$to">]; 
        $xml .= qq[<body>]; 
        my $message = $_; 
        $xml .= XML::Stream::EscapeXML($message); 
        $xml .= qq[</body>]; 
        $xml .= qq[</message>] ; 
        $c->SendXML($xml); 
        print $xml; 
}