This file is indexed.

/usr/share/httpry/parse_log.pl is in httpry-tools 0.1.7-3.

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

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
#!/usr/bin/perl -w

#
#  ----------------------------------------------------
#  httpry - HTTP logging and information retrieval tool
#  ----------------------------------------------------
#
#  Copyright (c) 2005-2012 Jason Bittel <jason.bittel@gmail.com>
#

use strict;
use warnings;
use Getopt::Std;
use File::Basename;

# -----------------------------------------------------------------------------
# GLOBAL CONSTANTS
# -----------------------------------------------------------------------------
my $DEFAULT_PLUGIN_DIR = "plugins";

# -----------------------------------------------------------------------------
# GLOBAL VARIABLES
# -----------------------------------------------------------------------------
my %enabled = ();
my %disabled = ();

# Command line arguments
my %opts;
my $verbose = 0;
my $plugin_dir = "";
my $plugin_list = "";
my @input_files = ();

# -----------------------------------------------------------------------------
# Main Program
# -----------------------------------------------------------------------------
get_arguments();

read_plugin_line($plugin_list) if ($plugin_list);
read_plugin_dir($plugin_dir) if ($plugin_dir);
read_plugin_dir() if (!$plugin_list && !$plugin_dir);

die "Error: No plugins loaded\n" if (keys %enabled == 0);
print "Info: " . (keys %enabled) . " plugins loaded\n" if $verbose;

process_logfiles();

end_plugins();

# -----------------------------------------------------------------------------
# Parse a comma-delmited string for plugins to initialize
# -----------------------------------------------------------------------------
sub read_plugin_line {
        my $plugin_list = shift;
        my $i = 0;

        foreach (split /,/, $plugin_list) {
                $_ =~ s/^\s+//;
                $_ =~ s/\s+$//;
                next if ($_ =~ /^$/);

                load_plugin($_);
                $i++;
        }

        warn "Warning: No plugins found in plugin list\n" if ($i == 0);
        print "Info: $i plugins found in plugin list\n" if $verbose;

        return;
}

# -----------------------------------------------------------------------------
# Search a directory for plugins to initialize
# -----------------------------------------------------------------------------
sub read_plugin_dir {
        my $custom_dir = shift;
        my $plugin_dir;
        my $i = 0;

        # If a custom plugin directory, assume the user knows best; otherwise,
        # search the current dir and script base dir for a default plugin folder
        if ($custom_dir) {
                $custom_dir =~ s/\/$//;
                $plugin_dir = $custom_dir;

                die "Error: '$plugin_dir' is not a valid directory\n" unless (-d $plugin_dir);
        } else {
                if (-d './' . $DEFAULT_PLUGIN_DIR) {
                        $plugin_dir = './' . $DEFAULT_PLUGIN_DIR;
                } elsif (-d dirname($0) . '/' . basename($DEFAULT_PLUGIN_DIR)) {
                        $plugin_dir = dirname($0) . '/' . basename($DEFAULT_PLUGIN_DIR);
                } else {
                        die "Error: Cannot find the default '$DEFAULT_PLUGIN_DIR' plugin directory\n";
                }
        }

        print "Info: Reading plugin directory '$plugin_dir'\n" if $verbose;

        # Load all plugins found in directory
        opendir PLUGINDIR, $plugin_dir or die "Error: Cannot find or access '$plugin_dir': $!\n";

        foreach (grep /\.pm$/, readdir(PLUGINDIR)) {
                load_plugin($plugin_dir . '/' . $_);
                $i++;
        }

        closedir(PLUGINDIR);

        warn "Warning: No plugins found in $plugin_dir\n" if ($i == 0);
        print "Info: $i plugins found in '$plugin_dir' directory\n" if $verbose;

        return;
}

# -----------------------------------------------------------------------------
# Load and initialize plugin from a file
# -----------------------------------------------------------------------------
sub load_plugin {
        my $path = shift;
        my $p = (fileparse($path, '\.pm'))[0];
        my $dir = dirname($path);

        print "Info: Loading plugin file '$path'\n" if $verbose;

        if (! -e $path) {
                warn "Warning: $p: Cannot find or access '$path'\n";
                return;
        }

        if (exists $enabled{$p}) {
                warn "Warning: $p: Name already registered\n";
                return;
        }

        eval 'require $path';
        if ($@) {
                warn "Warning: $p: $@" if $verbose;
                warn "Warning: $p: Failed to load...disabling\n";
                delete $enabled{$p};
                return;
        }

        unless ($enabled{$p}->can('main')) {
                warn "Warning: $p: Cannot find a required main() function...disabling\n";
                delete $enabled{$p};
                return;
        }

        if ($enabled{$p}->can('init')) {
                eval '$enabled{$p}->init($dir)';
                if ($@) {
                        warn "Warning: $p: $@" if $verbose;
                        warn "Warning: $p: Failed to initialize...disabling\n";
                        delete $enabled{$p};
                        return;
                }
        }

        print "Info: Initialized plugin '$p'\n" if $verbose;

        return;
}

# -----------------------------------------------------------------------------
# Create list of each plugin's callback information
# -----------------------------------------------------------------------------
sub register_plugin {
        my $package = (caller)[0];
        my $p = (fileparse((caller)[1], '\.pm'))[0];

        if ($package ne $p) {
                die "Warning: $p: Package name does not match filename\n";
        }

        if ($package->can('new')) {
                $enabled{$p} = $package->new();
        } else {
                die "Warning: $p: Cannot find a required new() function\n";
        }

        return;
}

# -----------------------------------------------------------------------------
# Process all files, passing each line to all registered plugins
# -----------------------------------------------------------------------------
sub process_logfiles {
        my $curr_file;
        my $curr_line;
        my @header;
        my %record;

        FILE: foreach $curr_file (@input_files) {
                unless (open INFILE, "$curr_file") {
                        warn "Error: Cannot open $curr_file: $!\n";
                        next FILE;
                }

                print "Info: Processing file '$curr_file'\n" if $verbose;

                LINE: while ($curr_line = <INFILE>) {
                        chomp $curr_line;
                        $curr_line =~ s/[^[:print:]\t]//g; # Strip unprintable characters
                        next LINE if $curr_line =~ /^$/;

                        # Handle comment lines
                        if ($curr_line =~ /^#/) {
                                # Check the comment for a field specifier line
                                next LINE unless $curr_line =~ /^# Fields: (.*)$/;
                                @header = map { s/\s//g; lc; } split /\,/, $1;

                                check_fields(@header);

                                if (keys %enabled == 0) {
                                        warn "Error: All plugins are disabled...skipping file\n";
                                        next FILE;
                                }

                                %record = ();
                                next LINE;
                        }

                        if (scalar @header == 0) {
                                warn "Error: No field description line found...skipping file\n";
                                next FILE;
                        }

                        @record{@header} = split /\t/, $curr_line;

                        foreach (keys %enabled) {
                                $enabled{$_}->main(\%record);
                        }
                }

                close INFILE or die "Error: Cannot close $curr_file: $!\n";;
        }

        return;
}

# -----------------------------------------------------------------------------
# Check required fields for each plugin against the current header fields
# -----------------------------------------------------------------------------
sub check_fields {
        my @keys = @_;
        my %fields = map { $keys[$_] => 1 } 0..$#keys;
        my $p;

        # Check active plugins to see if they have the required fields
        PLUGIN: foreach $p (keys %enabled) {
                next unless $enabled{$p}->can('list');

                foreach ($enabled{$p}->list()) {
                        next if $_ eq '';

                        if (!exists $fields{$_}) {
                                warn "Warning: $p: Required field '$_' not found...disabling\n";
                                $disabled{$p} = $enabled{$p};
                                delete $enabled{$p};
                                next PLUGIN;
                        }
                }
        }

        # Check disabled plugins to see if any should be enabled
        PLUGIN: foreach $p (keys %disabled) {
                next unless $disabled{$p}->can('list');

                foreach ($disabled{$p}->list()) {
                        next if $_ eq '';
                        next PLUGIN if (!exists $fields{$_});
                }

                print "Info: Plugin $p has been re-enabled\n" if $verbose;
                $enabled{$p} = $disabled{$p};
                delete $disabled{$p};
        }

        return;
}

# -----------------------------------------------------------------------------
# Call termination function in each loaded plugin
# -----------------------------------------------------------------------------
sub end_plugins {
        my $p;

        # Enable all disabled plugins so they can be properly ended
        foreach $p (keys %disabled) {
                $enabled{$p} = $disabled{$p};
                delete $disabled{$p};
        }

        foreach $p (keys %enabled) {
                if ($enabled{$p}->can('end')) {
                        print "Info: Ending plugin $p\n" if $verbose;
                        eval '$enabled{$p}->end()';
                        if ($@) {
                                warn "Warning: $p: $@" if $verbose;
                                warn "Warning: $p: Failed to end\n";
                        }
                }
        }

        return;
}

# -----------------------------------------------------------------------------
# Retrieve and process command line arguments
# -----------------------------------------------------------------------------
sub get_arguments {
        getopts('d:hp:v', \%opts) or print_usage();

        # Print help/usage information to the screen if necessary
        print_usage() if ($opts{h});
        unless ($ARGV[0]) {
                warn "Error: No input file(s) provided\n";
                print_usage();
        }

        # Copy command line arguments to internal variables
        @input_files = @ARGV;
        $plugin_list = $opts{p} if ($opts{p});
        $plugin_dir = $opts{d} if ($opts{d});
        $verbose = 1 if ($opts{v});

        return;
}

# -----------------------------------------------------------------------------
# Print usage/help information to the screen and exit
# -----------------------------------------------------------------------------
sub print_usage {
        die <<USAGE;
Usage: $0 [ -hv ] [ -d dir ] [ -p plugins ] file1 [ file2 ... ]
  -d dir       load plugins from specified directory
  -h           print this help information
  -p plugins   load plugins from comma-delimited list
  -v           print verbose run-time information

USAGE
}