This file is indexed.

/usr/share/popfile/POPFile/Logger.pm is in popfile 1.1.3+dfsg-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
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
# POPFILE LOADABLE MODULE
package POPFile::Logger;

use POPFile::Module;
@ISA = ("POPFile::Module");

#----------------------------------------------------------------------------
#
# This module handles POPFile's logger.  It is used to save debugging
# information to disk or to send it to the screen.
#
# Copyright (c) 2001-2011 John Graham-Cumming
#
#   This file is part of POPFile
#
#   POPFile is free software; you can redistribute it and/or modify it
#   under the terms of version 2 of the GNU General Public License as
#   published by the Free Software Foundation.
#
#   POPFile 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 POPFile; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------------------

use strict;
use warnings;
use locale;

# Constant used by the log rotation code
my $seconds_per_day = 60 * 60 * 24;

#----------------------------------------------------------------------------
# new
#
#   Class new() function
#----------------------------------------------------------------------------
sub new
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = POPFile::Module->new();

    # The name of the debug file

    $self->{debug_filename__} = '';

    # The last ten lines sent to the logger

    $self->{last_ten__} = ();

    $self->{initialize_called__} = 0;

    bless($self, $class);

    $self->name( 'logger' );

    return $self;
}

#----------------------------------------------------------------------------
#
# initialize
#
# Called to initialize the interface
#
# ---------------------------------------------------------------------------
sub initialize
{
    my ( $self ) = @_;

    $self->{initialize_called__} = 1;

    # Start with debugging to file

    $self->global_config_( 'debug', 1 );

    # The default location for log files

    $self->config_( 'logdir', '/var/log/popfile/' );

    # The output format for log files, can be default, tabbed or csv

    $self->config_( 'format', 'default' );

    # The log level.  There are three levels of log:
    #
    # 0   Critical log messages
    # 1   Verbose logging
    # 2   Maximum verbosity

    $self->config_( 'level', 0 );

    $self->{last_tickd__} = time;

    $self->mq_register_( 'TICKD', $self );

    return 1;
}

# ---------------------------------------------------------------------------
#
# deliver
#
# Called by the message queue to deliver a message
#
# There is no return value from this method
#
# ---------------------------------------------------------------------------
sub deliver
{
    my ( $self, $type, @message ) = @_;

    # If a day has passed then clean up log files

    if ( $type eq 'TICKD' ) {
        $self->remove_debug_files();
    }
}

#----------------------------------------------------------------------------
#
# start
#
# Called to start the logger running
#
#----------------------------------------------------------------------------
sub start
{
    my ( $self ) = @_;

    $self->calculate_today__();

    $self->debug( 0, '-----------------------' );
    $self->debug( 0, 'POPFile ' . $self->version() . ' starting' );

    return 1;
}

#----------------------------------------------------------------------------
#
# stop
#
# Called to stop the logger module
#
#----------------------------------------------------------------------------
sub stop
{
    my ( $self ) = @_;

    $self->debug( 0, 'POPFile stopped' );
    $self->debug( 0, '---------------' );
}

# ---------------------------------------------------------------------------
#
# service
#
# ---------------------------------------------------------------------------
sub service
{
    my ( $self ) = @_;

    $self->calculate_today__();

    # We send out a TICKD message every hour so that other modules
    # can do clean up tasks that need to be done regularly but not
    # often

    if ( $self->time > ( $self->{last_tickd__} + 3600 ) ) {
        $self->mq_post_( 'TICKD' );
        $self->{last_tickd__} = $self->time;
    }

    return 1;
}


# ---------------------------------------------------------------------------
#
# time
#
# Does the same as the built-in time function but can be overriden
# by the test suite to trick the module into thinking that a lot
# of time has passed.
#
# ---------------------------------------------------------------------------
sub time {
    return time;
}

# ---------------------------------------------------------------------------
#
# calculate_today
#
# Set the global $self->{today} variable to the current day in seconds
#
# ---------------------------------------------------------------------------
sub calculate_today__
{
    my ( $self ) = @_;

    # Create the name of the debug file for the debug() function
    $self->{today__} = int( $self->time / $seconds_per_day ) * $seconds_per_day;  # just to make this work in Eclipse: /

    # Note that 0 parameter than allows the logdir to be outside the user
    # sandbox

    $self->{debug_filename__} = $self->get_user_path_(                   # PROFILE BLOCK START
        $self->config_( 'logdir' ) . "popfile$self->{today__}.log", 0 ); # PROFILE BLOCK STOP
}

# ---------------------------------------------------------------------------
#
# remove_debug_files
#
# Removes popfile log files that are older than 3 days
#
# ---------------------------------------------------------------------------
sub remove_debug_files
{
    my ( $self ) = @_;

    my @debug_files = glob( $self->get_user_path_(                            # PROFILE BLOCK START
                          $self->config_( 'logdir' ) . 'popfile*.log', 0 ) ); # PROFILE BLOCK STOP

    foreach my $debug_file (@debug_files) {
        # Extract the epoch information from the popfile log file name
        if ( $debug_file =~ /popfile([0-9]+)\.log/ )  {
            # If older than now - 3 days then delete
            unlink($debug_file) if ( $1 < ($self->time - 3 * $seconds_per_day) );
        }
    }
}

# ----------------------------------------------------------------------------
#
# debug
#
# $level      The level of this message
# $message    A string containing a debug message that may or may not be
#             printed
#
# Prints the passed string if the global $debug is true
#
# ----------------------------------------------------------------------------
sub debug
{
    my ( $self, $level, $message ) = @_;

    if ( $self->{initialize_called__} == 0 ) {
        return;
    }

    if ( ( !defined( $self->config_( 'level' ) ) ) ||   # PROFILE BLOCK START
         ( $level > $self->config_( 'level' ) ) ) {     # PROFILE BLOCK STOP
        return;
    }

    if ( $self->{debug_filename__} eq '' ) {
        return;
    }

    if ( $self->global_config_( 'debug' ) > 0 ) {

        # Check to see if we are handling the USER/PASS command and if
        # we are then obscure the account information

        if ( $message =~ /((--)?)(USER|PASS)\s+\S*(\1)/i ) {
            $message = "$`$1$3 XXXXXX$4";
        }

        $message =~ s/([\x00-\x1f])/sprintf("[%2.2x]", ord($1))/eg;

        my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =   # PROFILE BLOCK START
            localtime;                                                         # PROFILE BLOCK STOP
        $year += 1900;
        $mon  += 1;

        $min  = "0$min"  if ( $min  < 10 );
        $hour = "0$hour" if ( $hour < 10 );
        $sec  = "0$sec"  if ( $sec  < 10 );

        my $delim = ' ';
        $delim = "\t" if ( $self->config_( 'format' ) eq 'tabbed' );
        $delim = ',' if ( $self->config_( 'format' ) eq 'csv' );

        my $msg =                                                             # PROFILE BLOCK START
            "$year/$mon/$mday$delim$hour:$min:$sec$delim$$:$delim$message\n"; # PROFILE BLOCK STOP

        if ( $self->global_config_( 'debug' ) & 1 )  {
            if ( open DEBUG, ">>$self->{debug_filename__}" ) {
                print DEBUG $msg;
                close DEBUG;
            }
        }

        print $msg if ( $self->global_config_( 'debug' ) & 2 );

        # Add the line to the in memory collection of the last ten
        # logger entries and then remove the first one if we now have
        # more than 10

        push @{$self->{last_ten__}}, ($msg);

        if ( $#{$self->{last_ten__}} > 9 ) {
            shift @{$self->{last_ten__}};
        }
    }
}

# GETTERS/SETTERS

sub debug_filename
{
    my ( $self ) = @_;

    return $self->{debug_filename__};
}

sub last_ten
{
    my ( $self ) = @_;

    if ( $#{$self->{last_ten__}} >= 0 ) {
        return @{$self->{last_ten__}};
    } else {
        my @temp = ( 'log empty' );
        return @temp;
    }
}

1;