"Fossies" - the Fresh Open Source Software Archive

Member "squid-graph/apacheconv" (2 Oct 2006, 2048 Bytes) of package /linux/privat/old/squid-graph-3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 
    3 ######################################################################
    4 #
    5 # Squid Graph Apache to Squid Logfile Convertor 
    6 #
    7 # Supplementary Tool for Squid Graph v3
    8 #
    9 # Please refer to the Squid Graph v3 documentation for more info
   10 # http://squid-graph.sourceforge.net/
   11 #
   12 #####################################################################
   13 
   14 use strict;
   15 
   16 foreach (<STDIN>) {
   17     my @parts = split(' ');
   18 
   19     my $IP = $parts[0];
   20     my $DATETIME = $parts[3];
   21     my $OFFSET = $parts[4];
   22     my $METHOD = $parts[5];
   23     my $URL = $parts[6];
   24     my $CODE = $parts[8];
   25     my $SIZE = $parts[9];
   26     my ($DATE, $HOUR, $MIN, $SEC) = split(/\:/, $DATETIME);
   27     $DATE =~ s/\[//;
   28     $OFFSET =~ s/\]//;
   29     $METHOD =~ s/\"//;
   30     $SIZE = 0 if ($SIZE eq "-"); 
   31 
   32     my $JTIME = convert("$HOUR:$MIN:SEC",$DATE,($OFFSET/100));
   33 
   34     print "$JTIME.000 0 $IP TCP_UNKNOWN/$CODE $SIZE $METHOD $URL - NONE/- -\n";
   35 
   36     undef @parts;
   37 }
   38 
   39 sub convert($$$) {
   40     my $TIME = shift;
   41     my $DATE = shift;
   42     my $OFFSET = shift;
   43 
   44     $DATE =~ s/Jan/01/;
   45     $DATE =~ s/Feb/02/;
   46     $DATE =~ s/Mar/03/;
   47     $DATE =~ s/Apr/04/;
   48     $DATE =~ s/May/05/;
   49     $DATE =~ s/Jun/06/;
   50     $DATE =~ s/Jul/07/;
   51     $DATE =~ s/Aug/08/;
   52     $DATE =~ s/Sep/09/;
   53     $DATE =~ s/Oct/10/;
   54     $DATE =~ s/Nov/11/;
   55     $DATE =~ s/Dec/12/;
   56 
   57     my ($HOUR, $MIN, $SEC) = split(/:/, $TIME);
   58     my ($DAY, $MONTH, $YEAR) = split(/\//, $DATE);
   59 
   60     my $TOTAL = 0;
   61 
   62     my $i = 0;
   63     for ($i = 1; $i <= ($YEAR - 1970); $i++) {
   64         $TOTAL += 31536000;
   65         $TOTAL += 86400 if (isleap($i + 1970));
   66     }
   67     for ($i = 1; $i < $MONTH; $i++) {
   68         $TOTAL += daysinmonth($i) * 86400;
   69         $TOTAL += 86400 if ((isleap($YEAR)) && ($i == 2));
   70     }
   71     undef $i;
   72 
   73     $TOTAL += ($DAY - 1) * 86400;
   74     $TOTAL += $HOUR * 3600;
   75     $TOTAL += $MIN * 60;
   76     $TOTAL += $SEC;
   77     $TOTAL -= $OFFSET * 3600;
   78     
   79     sub isleap($) {
   80         my $YEAR = shift;
   81         if ($YEAR%4 != 0) { return 0; }
   82         elsif ($YEAR%400 == 0) { return 1; }
   83         elsif ($YEAR%100 == 0) { return 0; }
   84         else { return 1; }
   85     }
   86 
   87     sub daysinmonth($$) {
   88         my $MONTH = shift;
   89         my @DAYS = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   90         return $DAYS[$MONTH];
   91     }
   92 
   93     return $TOTAL;
   94 }