This file is indexed.

/usr/sbin/awffull_history_regen is in awffull 3.10.2-4.

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
#!/usr/bin/perl
#****************************************************************************
#****************************************************************************
#
#   AWFFull - A Webalizer Fork, Full o' features
#
#   awffull_history_regen.pl
#       Pre-processing an old webalizer install prior to an upgrade
#       to AWFFull.
#
#   Copyright (C) 2005, 2008 by Stephen McInerney
#       (spm@stedee.id.au)
#
#   This file is part of AWFFull.
#
#   AWFFull 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 3 of the License, or
#   (at your option) any later version.
#
#   AWFFull 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 AWFFull.  If not, see <http://www.gnu.org/licenses/>.
#
#****************************************************************************
#****************************************************************************
#
#                     awffull_history_regen.pl
#
# DESCRIPTION
# --------------
# Given a directory, this script will parse all old weblizer html (per month)
# files and spit out a complete history file (via STDOUT).
# This new history file will contain all years/months from all the
# webalizer html files.
#
# Designed for pre-processing an old webalizer install prior to an
# upgrade to AWFFull.
#
#****************************************************************************
#****************************************************************************
#  Modification History
# 11-Sep-2005 steve     Initial Creation
# 17-Sep-2005 steve     major tidy and functionalise
#****************************************************************************
#****************************************************************************
#
###  *** Sample text to parse for
#
# <TR><TH COLSPAN=3 ALIGN=center BGCOLOR="#C0C0C0">Monthly Statistics for July 2005</TH></TR>
# <TR><TH HEIGHT=4></TH></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Hits</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>12217843</B></FONT></TD></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Files</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>5384438</B></FONT></TD></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Pages</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>1031846</B></FONT></TD></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Visits</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>226836</B></FONT></TD></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total KBytes</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>39965939</B></FONT></TD></TR>
# <TR><TH HEIGHT=4></TH></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Unique Sites</FONT></TD>
# <TD ALIGN=right COLSPAN=2><FONT SIZE="-1"><B>120135</B></FONT></TD></TR>
# <TR><TD WIDTH=380><FONT SIZE="-1">Total Unique URLs</FONT></TD>
#****************************************************************************

use strict;               # die on all bad programming
use Getopt::Long 2.33;    # Command Line Option Processing
use Pod::Usage;           # For inline documentation

###########################
## Global Variables
###########################
my $DATE        = '/bin/date';   # Location of the GNU Date Command - default
my $exit_status = 0;             # Script Return. 0 = success!

## Options
my $opt_UsageDir    = ".";       # Directory to look for webalizer usage files
my $opt_DateCommand = $DATE;     # Location of the GNU Date Command

###########################
###########################
##         MAIN
###########################
###########################

ProcessCommandLine();
$exit_status = RegenerateHistory();

if ($exit_status == 2) {
    printf(STDERR "Failed to find any Webalizer usage_YYYYMM.html files.\n");
}

exit($exit_status);

##########################################################################
##########################################################################
####                          END OF MAIN
##########################################################################
##########################################################################


####             SUBROUTINES

##########################################################################
##########################################################################
## ProcessCommandLine
##       Parse the Commandline Arguments
##########################################################################
sub ProcessCommandLine {
    my $result;    # result from Calling GetOptions

    my $opt_Help;  # Local options
    my $opt_Man;   #  use for man page, or help screen

    Getopt::Long::Configure("gnu_getopt");    # Configure to use GNU style Options

    $result =
        GetOptions("dir|d:s" => \$opt_UsageDir,
                   "help|\?" => \$opt_Help,
                   "man"     => \$opt_Man,
                   "date:s"  => \$opt_DateCommand,
                  )
        || pod2usage(-verbose => 0);
    if ($opt_Help) { pod2usage(-verbose => 1); }
    if ($opt_Man)  { pod2usage(-verbose => 2); }
    if (!-x $opt_DateCommand) {
        printf("Invalid Date command: %s\n", $opt_DateCommand);
        exit(1);
    }
} ## end sub ProcessCommandLine


##########################################################################
##########################################################################
## RegenerateHistory
##      Do the hard work - process the data, generate the output
##########################################################################
sub RegenerateHistory {
    my $usagefile;    # The current file we're processing

    # Up to Flags
    my $in_MonthlyStats = 0;    # We are currently in the right place for monthly stats in the page
    my $in_HitsStats    = 0;    # Now in Hits Stats
    my $in_FilesStats   = 0;    # Now in File Stats
    my $in_PageStats    = 0;    # Now in Page Stats
    my $in_VisitStats   = 0;    # Now in Visit Stats
    my $in_KByteStats   = 0;    # Now in KByte Stats
    my $in_SiteStats    = 0;    # Now in Site Stats

    my @line = ();              # The current input line
    my %History;                # The hash holding all the ripped data

    my $cur_month = "";         # The current month
    my $cur_year  = 0;          # The current year
    my $nofiles   = 2;          # Return the value 2 if no files are found

    ### Month stuff
    my @DinM = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    opendir(DIR, $opt_UsageDir) or die "Cannot open directory $opt_UsageDir";
    while ($usagefile = readdir DIR) {
        if ($usagefile =~ /^usage_[0-9]{6}\.html$/) {
            open(FILE, "<$opt_UsageDir/$usagefile") or die "Cannot open file $usagefile";

        ($cur_year, $cur_month) = $usagefile =~ /^usage_(....)(..)\.html$/;
        FILELINE:
            while (<FILE>) {
                if (/>(Monthly Statistics for|Monats-Statistik f&uuml;r|Maandoverzicht ) /) {
                    $in_MonthlyStats = 1;
                    $nofiles         = 0;
                } ## end if (/>Monthly Statistics for /)
                next FILELINE if (!$in_MonthlyStats);

                if ($in_MonthlyStats) {

                    # Exit this file, end of useful info
                    last FILELINE if (/>(Total Unique URLs|Summe unterschiedlicher URLs|Totaal verschillende URL\'s)</);

                    # HITS - set value
                    if ($in_HitsStats) {
                        @line                                           = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{HITS} = $line[12];
                        $in_HitsStats                                   = 0;
                    }

                    # FILES - set value
                    elsif ($in_FilesStats) {
                        @line                                            = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{FILES} = $line[12];
                        $in_FilesStats                                   = 0;
                    }

                    # PAGES - set value
                    elsif ($in_PageStats) {
                        @line                                            = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{PAGES} = $line[12];
                        $in_PageStats                                    = 0;
                    }

                    # VISITS - set value
                    elsif ($in_VisitStats) {
                        @line                                             = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{VISITS} = $line[12];
                        $in_VisitStats                                    = 0;
                    }

                    # KBYTES - set value
                    elsif ($in_KByteStats) {
                        @line                                             = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{KBYTES} = $line[12];
                        $in_KByteStats                                    = 0;
                    }

                    # SITES - set value
                    elsif ($in_SiteStats) {
                        @line                                            = split /(<|>)/;
                        $History{$cur_year}{$cur_month}{SITES} = $line[12];
                        $in_SiteStats                                    = 0;
                    }

                    # Else, all the checks for a next section
                    elsif (/>(Total Hits|Summe Anfragen|Totaal hits)</) {
                        $in_HitsStats = 1;
                    } elsif (/>(Total Files|Summe Dateien|Totaal bestanden)</) {
                        $in_FilesStats = 1;
                    } elsif (/>(Total Pages|Summe Seiten|Totaal Pagina\'s)</) {
                        $in_PageStats = 1;
                    } elsif (/>(Total Visits|Summe Besuche|Totaal Bezoeken)</) {
                        $in_VisitStats = 1;
                    } elsif (/>(Total KBytes|Summe kb|Total kB Files)</) {
                        $in_KByteStats = 1;
                    } elsif (/>(Total Unique Sites|Summe unterschiedlicher Rechner|Totaal verschillende hosts)</) {
                        $in_SiteStats = 1;
                    }
                }    ## if ($in_MonthlyStats) {
            }    ## while (<FILE>) {
            close(FILE);

        }    ## if ($usagefile =~ /^usage_[0-9]{6}\.html$/) {
    }    ## while (DIR) {
    closedir(DIR);

    my $key_year;
    my $key_month;
    foreach $key_year (sort (keys %History)) {
        foreach $key_month (sort numerically (keys %{$History{$key_year}})) {
            my $DaysInMonth = $DinM[$key_month - 1];
            if ($key_month == 2) {
                my $testmonth = `$opt_DateCommand "+%m" --date="29 feb $key_year" > /dev/null 2>&1`;
                if ($testmonth == 2) {
                    $DaysInMonth = 29;
                }
            } ## end if ($key_month == 2)
            printf("%d %d %d %d %d %d 1 %d %d %d\n",
                   $key_month,                             $key_year,
                   $History{$key_year}{$key_month}{HITS},  $History{$key_year}{$key_month}{FILES},
                   $History{$key_year}{$key_month}{SITES}, $History{$key_year}{$key_month}{KBYTES},
                   $DaysInMonth,                           $History{$key_year}{$key_month}{PAGES},
                   $History{$key_year}{$key_month}{VISITS}
                  );
        }    ## foreach $key_month
    }    ## foreach $key_year

    return ($nofiles);
} ## end sub RegenerateHistory


##########################################################################
##########################################################################
## numerically
##      Do a numerical sort
##########################################################################
sub numerically { $a <=> $b }


##########################################################################
##########################################################################
##########################################################################

__END__

=pod

=head1 NAME

awffull_history_regen.pl - Generate a history file from old Webalizer usage files

=head1 SYNOPSIS

awffull_history_regen.pl [options]

NB! Must have the GNU Date command!

=head1 OPTIONS

=over 8

=item B<--help>

Print a brief help message and exit.

=item B<--man>

Print the manual page and exit.

=item B<--dir directory>

The directory to use, looking for old webalizer usage_YYYYMM.html files. If
not present will use the current directory.

=item B<--date gnu-date-location>

This program requires the GNU date command, use this option, if it's in a non-standard place.

=head1 DESCRIPTION

Generate a history file from old Webalizer usage files.

The resulting history file is sent only to STDOUT. 

=cut