This file is indexed.

/usr/share/perl5/Lire/OutputJob.pm is in lire 2:2.1.1-2.1.

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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
package Lire::OutputJob;

use strict;

use Lire::OutputFormat;
use Lire::Utils qw/check_param check_object_param/;
use Lire::PluginManager;

use Carp;

=pod

=head1 NAME

Lire::OutputJob - Object used to represent a configured formatting of a report

=head1 SYNOPSIS

  use Lire::OutputJob;
  use Lire::OutputFormat;

  my $email = new Lire::OutputJob( 'email', $output, $output_cfg,
                                   'emails' => [ 'email@domain.org' ] );

  $email->run( 'report.xml' );

  my $file = new Lire::OutputJob( 'file', $output, $output_cfg,
                                  'filename' => '/var/www/reports/daily-%Y%m%d'  );
  $file->run( 'report.xml' );

=head1 DESCRIPTION

The Lire::OutputJob objects are used to represent how a report should
formatted. These objects are most often created from the Lire
configuration. (The 'output_jobs' specification.)

=head1 new( $destination_type, $format, $format_cfg, ... );

Create a new Lire::OutputJob object. Two parameters are required:

=over

=item $destination_type

Can be either 'email' or 'file'.

=item $format

A Lire::OutputFormat object.

=item $format

The configuration data that will be passed to the OutputFormat
object.

=back

The method will returns an instance of Lire::EmailOutputJob or
Lire::FileOutputJob.

=cut

sub new {
    my ( $pkg, $type, $format, $format_cfg, %args ) = @_;

    check_param( $type, 'type', qr/^(email|file)$/,
                 "'type' parameter should be one of 'email' or 'file'" );
    check_object_param( $format, 'format', 'Lire::OutputFormat' );
    check_param( $format_cfg, 'format_cfg' );

    my $self = { '_format' => $format,
                 '_format_cfg' => $format_cfg,
               };
    if ( $type eq 'email' ) {
        bless $self, 'Lire::EmailOutputJob';
    } else {
        bless $self, 'Lire::FileOutputJob';
    }
    $self->init( %args );

    return $self;
}

=pod

=head2 format

Returns the Lire::OutputFormat associated with this OutputJob.

=cut

sub format {
    return $_[0]{'_format'};
}

=pod

=head2 format_cfg

Returns the configuration data that will be used when formatting the
report.

=cut

sub format_cfg {
    return $_[0]{'_format_cfg'};
}

=pod

=head2 run( $report_file )

Formats and sends or save the XML report $report_file according the
OutputJob parameters.

=cut

sub run {
    croak ref shift, "::run unimplemented";
}

sub new_from_config {
    my ( $pkg, $value ) = @_;

    my $format =
      Lire::PluginManager->get_plugin( 'output_format',
                                       $value->get( 'format' )->get_plugin() );
    return new Lire::OutputJob( $value->get( 'destination' )->get_plugin(),
                                $format,
                                $value->get( 'format' )->get_properties()->as_value(),
                                %{$value->get( 'destination' )->get_properties()->as_value()} );
}

package Lire::EmailOutputJob;

use base qw/Lire::OutputJob/;

use Lire::Utils qw/check_object_param file_content/;
eval "use MIME::Entity";

sub init {
    my ( $self,  %args ) = @_;

    check_object_param( $args{'emails'}, 'emails', 'ARRAY' );
    $self->{'_emails'} = $args{'emails'};
    $self->{'_subject'} = $args{'subject'} ? $args{'subject'} : '';
    $self->{'_subject'} = $args{'subject'} ? $args{'subject'} : '';
    $self->{'_extra_file'} = $args{'extra_file'};

    return;
}

=pod

=head1 Lire::EmailOutputJob

=head2 Extra parameters for 'email' type

=over

=item emails

An array reference to the emails that will receive the formatted report.

=item subjet

The subject of the email.

=item extra_file

An additional text file that will be appended to text report or attach
to other report types.

=back

=head2 emails()

Returns as an array the emails to which the report will be sent.

=cut


sub emails {
    return @{$_[0]{'_emails'}};
}

=pod

=head2 subject()

Returns the subject of the email.

=cut

sub subject {
    return $_[0]{'_subject'};
}

=pod

=head2 extra_file()

Returns the filename that will be appended to the text report or
attach to the message for other report's type.

=cut

sub extra_file {
    return $_[0]{'_extra_file'};
}

sub run {
    my ( $self, $report_file ) = @_;

    my $msg = $self->format()->mime_report( $report_file,
                                            $self->format_cfg() );
    if ( $self->{'_extra_file'} ) {
        if ( $msg->mime_type() eq 'text/plain' ) {
            my $new_content = $msg->bodyhandle()->as_string() 
              . "\n" . file_content( $self->{'_extra_file'} );
            my $io = $msg->open( 'w' );
            $io->print( $new_content );
            $io->close();
        } else {
            my $entity = MIME::Entity->build( 'Type' => 'multipart/mixed' );
            $entity->add_part( $msg );
            $msg = $entity;
            $msg->attach( 'Type' => 'text/plain',
                          'Path' => $self->{'_extra_file'} );
        }
    }
    $msg->head()->set( 'To', join( ", ", @{$self->{'_emails'}} ) );
    my $from = Lire::Config->get( 'lr_mail_from' ) || $ENV{'EMAIL'};
    $msg->head()->set( 'From', $from )
      if $from;
    $msg->head()->set( 'Subject', $self->subject() );
    my $reply_to = Lire::Config->get( 'lr_mail_reply_to' );
    $msg->head()->set( 'Reply-To', $reply_to )
      if $reply_to;

    my $pid = open( my $fh, "|-" );
    die "can't fork: $!\n"  unless defined $pid;
    if ( $pid ) {
	# Parent
	$msg->print( $fh );
	close $fh
	  or die "error: sendmail exited with non zero status: $?\n";
    } else {
	# Children, execute sendmail
	# We use this form of exec so that @to can't be used to trick 
	# a shell.
	exec( Lire::Config->get( 'sendmail_path' ), @{$self->{'_emails'}} )
          or do {
              print STDERR "error executing sendmail: $!\n";
              # Since we are a fork, we don't want our die trapped.
              CORE::exit(1);
          };
    }

    return;
}

package Lire::FileOutputJob;

use base qw/Lire::OutputJob/;

use Lire::Utils qw/check_param/;

use POSIX qw/strftime/;

sub init {
    my ( $self,  %args ) = @_;

    check_param( $args{'file'}, 'file' );
    $self->{'_file'} = $args{'file'};

    return;
}

=pod

=head1 Lire::FileOutputJob

=head2 Extra parameters for 'file' type.

=over 4

=item file

A file path with possible strftime(3pm) interpolation. This will be
were the formatted report will be saved.

=back

=head2 file()

Returns this OutputJob destination file.

=cut

sub file {
    return $_[0]{'_file'};
}

=pod

=head2 output_file( [$time] )

Returns the  destination file with strftime(3) specifier interpolated.

=cut

sub output_file {
    my ( $self, $time ) = @_;

    $time ||= time();
    return strftime( $self->{'_file'}, localtime $time );
}

sub run {
    my ( $self, $report, $time ) = @_;

    check_param( $report, 'report' );

    $time ||= time();

    $self->format()->format_report( $report, $self->output_file( $time ),
                                    $self->format_cfg() );

    return;
}

# keep perl happy
1;

__END__

=pod

=head1 SEE ALSO

Lire::ReportJob(3pm) Lire::OutputFormat(3pm)

=head1 AUTHOR

  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

$Id: OutputJob.pm,v 1.8 2006/07/23 13:16:29 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2004 Stichting LogReport Foundation LogReport@LogReport.org

This file is part of Lire.

Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.

=cut