This file is indexed.

/usr/share/perl5/Paranoid/Log/Email.pm is in libparanoid-perl 0.36-2.

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Paranoid::Log::Email -- Log Facility Email for paranoid programs
#
# (c) 2005, Arthur Corliss <corliss@digitalmages.com>
#
# $Id: Email.pm,v 0.82 2010/04/15 23:23:28 acorliss Exp $
#
#    This software is licensed under the same terms as Perl, itself.
#    Please see http://dev.perl.org/licenses/ for more information.
#
#####################################################################

#####################################################################
#
# Environment definitions
#
#####################################################################

package Paranoid::Log::Email;

use strict;
use warnings;
use vars qw($VERSION);
use Paranoid::Debug qw(:all);
use Carp;
use Net::SMTP;
use Net::Domain qw(hostfqdn);

($VERSION) = ( q$Revision: 0.82 $ =~ /(\d+(?:\.(\d+))+)/sm );

#####################################################################
#
# Module code follows
#
#####################################################################

sub init () {

    # Purpose:  Exists purely for compliance.
    # Returns:  True (1)
    # Usage:    init();

    return 1;
}

sub remove ($) {

    # Purpose:  Exists purely for compliance.
    # Returns:  True (1)
    # Usage:    init();

    return 1;
}

sub log ($$$$$$$$$;$$) {

    # Purpose:  Mails the passed message to the named recipient
    # Returns:  True (1) if successful, False (0) if not
    # Usage:    log($msgtime, $severity, $message, $name, $facility, $level,
    #               $scope);
    # Usage:    log($msgtime, $severity, $message, $name, $facility, $level,
    #               $scope, $mailhost);
    # Usage:    log($msgtime, $severity, $message, $name, $facility, $level,
    #               $scope, $mailhost, $recipient);
    # Usage:    log($msgtime, $severity, $message, $name, $facility, $level,
    #               $scope, $mailhost, $recipient, $sender);
    # Usage:    log($msgtime, $severity, $message, $name, $facility, $level,
    #               $scope, $mailhost, $recipient, $sender, $subject);

    my $msgtime   = shift;
    my $severity  = shift;
    my $message   = shift;
    my $name      = shift;
    my $facility  = shift;
    my $level     = shift;
    my $scope     = shift;
    my $mailhost  = shift;
    my $recipient = shift;
    my $sender    = shift;
    my $subject   = shift;
    my $m         = defined $mailhost ? $mailhost : 'undef';
    my $r         = defined $recipient ? $recipient : 'undef';
    my $s1        = defined $sender ? $sender : 'undef';
    my $s2        = defined $subject ? $subject : 'undef';
    my $rv        = 0;
    my ( $smtp, $hostname, $data );

    # Validate arguments
    croak 'Mandatory third argument must be a valid message'
        unless defined $message;

    pdebug(
        "entering w/($msgtime)($severity)($message)($name)"
            . "($facility)($level)($scope)($m)($r)($s1)($s2)",
        PDLEVEL1
        );
    pIn();

    # We need a mailhost and recipient at a minimum
    if ( defined $mailhost && defined $recipient ) {

        # Get the system hostname
        $hostname = hostfqdn();

        # Make sure something is set for the sender
        $sender = "$ENV{USER}\@$hostname" unless defined $sender;

        # Make sure something is set for the subject
        $subject = "ALERT from $ENV{USER}\@$hostname" unless defined $subject;

        # Compose the data block
        $data = << "__EOF__";
To:      @{[ ref($recipient) eq 'ARRAY' ? join(', ', @$recipient) : $recipient ]}
From:    $sender
Subject: $subject

This alert was sent out from $hostname by 
$ENV{USER} because of a log event which met or exceeded the 
$level level.  The message of this event is as follows:

$message

__EOF__

        pdebug( "sending to $recipient to $mailhost", PDLEVEL2 );

        # Try to open an SMTP connection
        if ( $smtp = Net::SMTP->new( $mailhost, Timeout => 30 ) ) {

            # Start the transaction
            if ( $smtp->mail($sender) ) {

                # Send to all recipients
                if ( ref $recipient eq 'ARRAY' ) {
                    foreach (@$recipient) {
                        Paranoid::ERROR =
                            pdebug( "server rejected recipient: $_",
                            PDLEVEL1 )
                            unless $smtp->to($_);
                    }
                } else {
                    Paranoid::ERROR =
                        pdebug( "server rejected recipient: $recipient",
                        PDLEVEL1 )
                        unless $smtp->to($recipient);
                }

                # Send the message
                $rv = $smtp->data($data);

                # Log the error
            } else {
                Paranoid::ERROR =
                    pdebug( "server rejected sender: $sender", PDLEVEL1 );
                $rv = 0;
            }

            # Close the connection
            $smtp->quit;

        } else {

            # Failed to connect to the server!
            Paranoid::ERROR =
                pdebug( "couldn't connect to server: $mailhost", PDLEVEL1 );
            $rv = 0;
        }

    } else {

        # Who the hell activated this facility without at least that?!
        Paranoid::ERROR = pdebug(
            'Message logged with e-mail facility, but we have '
                . 'neither a mailhost or a recipient to send to -- ignoring',
            PDLEVEL1
            );
        $rv = 0;
    }

    pOut();
    pdebug( "leaving w/rv: $rv", PDLEVEL1 );

    return $rv;
}

sub dump ($) {

    # Purpose:  Exists purely for compliance.
    # Returns:  True (1)
    # Usage:    init();

    return ();
}

1;

__END__

=head1 NAME

Paranoid::Log::Email - Log Facility Email

=head1 VERSION

$Id: Email.pm,v 0.82 2010/04/15 23:23:28 acorliss Exp $

=head1 SYNOPSIS

  use Paranoid::Log;
  
  enableFacility('crit-alert', 'email', 'debug', '+', $mailhost, 
    $recipient);
  enableFacility('crit-alert', 'email', 'debug', '+', $mailhost, 
    [ @recipients ]);
  enableFacility('crit-alert', 'email', 'debug', '+', $mailhost, 
    $recipient, $sender, $subject);

=head1 DESCRIPTION

This module implements an e-mail transport for messages sent to the logger.
It supports one or more recipients as well as overriding the sender address
and subject line.  It also supports connecting to a remote mail server.

=head1 DEPENDENCIES

=over

=item o

L<Net::SMTP>

=item o

L<Net::Domain>

=item o

L<Paranoid::Debug>

=back

=head1 SUBROUTINES/METHODS

B<NOTE>:  Given that this module is not intended to be used directly nothing
is exported.

=head2 init

=head2 log

=head2 remove

=head2 dump

=head1 SEE ALSO

=over

=item o

L<Paranoid::Log>

=back

=head1 BUGS AND LIMITATIONS

No validation of any information, be it the mail server, recipient, or
anything else is done until a message actually needs to be sent.  Because of
this you may have no warning of any misconfigurations just by enabling the
facility.

=head1 AUTHOR

Arthur Corliss (corliss@digitalmages.com)

=head1 LICENSE AND COPYRIGHT

This software is licensed under the same terms as Perl, itself. 
Please see http://dev.perl.org/licenses/ for more information.

(c) 2005, Arthur Corliss (corliss@digitalmages.com)