This file is indexed.

/usr/share/perl5/AAT/XMPP.pm is in octopussy 1.0.6-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# $HeadURL$
# $Revision: 502 $
# $Date: 2011-10-24 00:04:51 +0100 (Mon, 24 Oct 2011) $
# $Author: sebthebert $

=head1 NAME

AAT::XMPP - AAT XMPP module

(Extensible Messaging and Presence Protocol (Jabber))

=head1 BUGS

Net::XMPP is buggy with OpenFire & TLS
-> comment 3 lines in Net::XMPP::Protocol (approx. line 1800) 
& disable TLS:

#if($self->{STREAM}->GetStreamFeature($self->GetStreamID(),
# "xmpp-sasl"))
#{
#    return $self->AuthSASL(%args);
#}

=cut

package AAT::XMPP;

use strict;
use warnings;
use Readonly;

use Net::XMPP;

use AAT::Application;
use AAT::Syslog;
use AAT::Utils qw( NOT_NULL );
use AAT::XML;

Readonly my $XMPP_RESOURCE => 'Octopussy'; 
Readonly my $XMPP_TIMEOUT => 3;

my %conf_file = ();

=head1 FUNCTIONS

=head2 Configuration($appli)

Returns the XMPP configuration

=cut

sub Configuration
{
  my $appli = shift;

  $conf_file{$appli} ||= AAT::Application::File($appli, 'xmpp');
  my $conf = AAT::XML::Read($conf_file{$appli}, 1);

  return ($conf->{xmpp});
}


=head2 Configured($appli)

Returns '1' if XMPP is configured (server & port) else '0'

=cut

sub Configured
{
	my $appli = shift;

  $conf_file{$appli} ||= AAT::Application::File($appli, 'xmpp');
  my $conf = AAT::XML::Read($conf_file{$appli}, 1);
  
  return ((defined $conf->{server} && defined $conf->{port}) ? 1 : 0);
}


=head2 Connection_Test($appli)

Checks the XMPP Connection

=cut

sub Connection_Test
{
  	my $appli  = shift;
  	my $status = 0;

  	my $conf_xmpp = Configuration($appli);
  	if (NOT_NULL($conf_xmpp->{server}))
  	{
   		my $client = new Net::XMPP::Client();
    	my @res    = $client->Connect(
      		hostname 		=> $conf_xmpp->{server},
      		port     		=> $conf_xmpp->{port},
			componentname 	=> $conf_xmpp->{component_name},
    		connectiontype 	=> $conf_xmpp->{connection_type} || 'tcpip',
      		tls      		=> $conf_xmpp->{tls},
      		timeout  		=> $XMPP_TIMEOUT,
    );
    if (@res)
    {
      my @res = $client->AuthSend(
        username => $conf_xmpp->{user},
        password => $conf_xmpp->{password},
        resource => $XMPP_RESOURCE
      );
      $status = 1
        if ((\@res == 0)
        || ((@res == 1 && $res[0]) || $res[0] eq 'ok'));
    }
  }

  return ($status);
}

=head2 Send_Message($appli, $msg, @dests)

Sends message '$msg' to '@dests' through XMPP

=cut

sub Send_Message
{
  	my ($appli, $msg, @dests) = @_;

  	my $conf_xmpp = Configuration($appli);
  	my $client    = new Net::XMPP::Client();
  	my @res       = $client->Connect(
    	hostname 		=> $conf_xmpp->{server},
    	port     		=> $conf_xmpp->{port},
		componentname   => $conf_xmpp->{component_name},
        connectiontype 	=> $conf_xmpp->{connection_type} || 'tcpip',
    	tls      		=> $conf_xmpp->{tls},
		timeout         => $XMPP_TIMEOUT,
  	);
  	if (@res)
  	{
		my $sid = $client->{SESSION}->{id};
    	$client->{STREAM}->{SIDS}->{$sid}->{hostname} = $conf_xmpp->{component_name};
    	$client->AuthSend(
      		username => $conf_xmpp->{user},
      		password => $conf_xmpp->{password},
      		resource => $XMPP_RESOURCE
    		);
    	foreach my $dest (@dests)
    	{
      		if (NOT_NULL($dest))
      		{
        		$client->MessageSend('to' => $dest, 'body' => "$msg", 
					resource => $XMPP_RESOURCE);
      		}
    	}
    	sleep 1;
    	$client->Disconnect();

    	return (1);
  	}
  	else
  	{
    	AAT::Syslog::Message('AAT_XMPP', 'XMPP_INVALID_CONFIG');
  	}

	return (0);
}

1;

=head1 AUTHOR

Sebastien Thebert <octo.devel@gmail.com>

=cut