]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/logs.cgi/proxylog.dat
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / logs.cgi / proxylog.dat
index 70208b9eda6d7bf8ac18b015fce36635ff86930d..5109ca4cf01f5d39c277e9c326125443887140d3 100644 (file)
@@ -6,8 +6,6 @@
 #
 # (c) The SmoothWall Team
 #
-# $Id: proxylog.dat,v 1.4.2.25 2005/07/07 17:32:24 eoberlander Exp $
-#
 
 use strict;
 
@@ -15,7 +13,7 @@ use strict;
 #use warnings;
 #use CGI::Carp 'fatalsToBrowser';
 
-require 'CONFIG_ROOT/general-functions.pl';
+require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
 
@@ -28,11 +26,17 @@ undef (@dummy);
 my %cgiparams=();
 my %logsettings=();
 my %ips=();
+my %users=();
 my %selected=();
 my %checked=();
 my @log=();
 my $errormessage = '';
 
+my %color = ();
+my %mainsettings = ();
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
+
 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
        'Sep', 'Oct', 'Nov', 'Dec' );
 my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
@@ -46,7 +50,7 @@ my $doy = $now[7];    # day of year (0..364)
 my $tdoy = $now[7];
 my $year = $now[5]+1900;
 
-$cgiparams{'DAY'} = $now[3]; 
+$cgiparams{'DAY'} = $now[3];
 $cgiparams{'MONTH'} = $now[4];
 $cgiparams{'SOURCE_IP'} = 'ALL';
 $cgiparams{'FILTER'} = "[.](gif|jpeg|jpg|png|css|js)\$";
@@ -66,7 +70,7 @@ if ($cgiparams{'ACTION'} eq '')
 if ($cgiparams{'ACTION'} eq $Lang::tr{'restore defaults'})
 {
        $cgiparams{'FILTER'} = "[.](gif|jpeg|jpg|png|css|js)\$";
-       $cgiparams{'ENABLE_FILTER'} = 'off'; 
+       $cgiparams{'ENABLE_FILTER'} = 'off';
 }
 
 {
@@ -84,8 +88,9 @@ if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'})
        my @temp = split(',',$ENV{'QUERY_STRING'});
        $start = $temp[0];
        $cgiparams{'MONTH'} = $temp[1];
-       $cgiparams{'DAY'} = $temp[2];  
+       $cgiparams{'DAY'} = $temp[2];
        $cgiparams{'SOURCE_IP'} = $temp[3];
+       $cgiparams{'USERNAME'} = &Header::escape($temp[4]);
 }
 
 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
@@ -146,7 +151,7 @@ my $daystr = $cgiparams{'DAY'} == 0 ? '' :$cgiparams{'DAY'} <= 9 ? "0$cgiparams{
 
     # Calculate time. If future date, calculate for past year !!!
     if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
-       ( $cgiparams{'MONTH'}  > $now[4] ) ) {  
+       ( $cgiparams{'MONTH'}  > $now[4] ) ) {
        $xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
        $daystr = "$longmonths[$cgiparams{'MONTH'}] $daystr, ". int($year-1);
     } else {
@@ -168,6 +173,8 @@ my $daystr = $cgiparams{'DAY'} == 0 ? '' :$cgiparams{'DAY'} <= 9 ? "0$cgiparams{
 my $filter = $cgiparams{'ENABLE_FILTER'} eq 'on' ? $cgiparams{'FILTER'} : '';
 my $sourceip = $cgiparams{'SOURCE_IP'};
 my $sourceall =  $cgiparams{'SOURCE_IP'} eq 'ALL' ? 1 : 0;
+my $username = $cgiparams{'USERNAME'};
+my $usersall =  $cgiparams{'USERNAME'} eq 'ALL' ? 1 : 0;
 
 my $lines = 0;
 my $temp = ();
@@ -175,7 +182,7 @@ my $thiscode = '$temp =~ /$filter/;';
 eval($thiscode);
 if ($@ ne '')
 {
-    $errormessage = "$Lang::tr{'bad ignore filter'}.$@<P>";
+    $errormessage = "$Lang::tr{'bad ignore filter'}.$@<p>";
     $filter = '';
 } else {
     my $loop = 1;
@@ -203,35 +210,37 @@ if ($@ ne '')
 
            $temp_now[2] = $temp_now[1] = $temp_now[0] = 0; # start at 00:00:00
            $temp_now[3] = 1 if ($cgiparams{'DAY'}==0); # All days selected, start at '1'
-            my $mintime = POSIX::mktime(@temp_now); 
+            my $mintime = POSIX::mktime(@temp_now);
            my $maxtime;
            if ($cgiparams{'DAY'}==0) {                 # full month
                if ($temp_now[4]++ == 12){
                    $temp_now[4] = 0;
                    $temp_now[5]++;
                };
-               $maxtime = POSIX::mktime(@temp_now); 
+               $maxtime = POSIX::mktime(@temp_now);
            } else {
                $maxtime = $mintime + 86400;            # full day
            }
            READ:while (<FILE>) {
                my ($datetime,$do,$ip,$ray,$me,$far,$url,$so) = split;
                $ips{$ip}++;
+               $users{$so}++;
                # for debug
                #$lastdatetime = $datetime;
 
                # collect lines between date && filter
                if (( ($datetime>$mintime)&&($datetime<$maxtime)) && !($url =~ /$filter/) &&
-                  ((($ip eq $sourceip) || $sourceall)))
+                  ((($ip eq $sourceip) || $sourceall)) &&
+                  ((($so eq $username) || $usersall)))
                {
                    # when standart viewing, just keep in memory the correct slices
                    # it starts a '$start' and size is $viewport
                    # If export, then keep all lines...
                    if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){
-                       $log[$lines++] = "$datetime $ip $url";
+                       $log[$lines++] = "$datetime $ip $so $url";
                    } else {
                        if ($lines++ < ($start + $Header::viewsize)) {
-                           push(@log,"$datetime $ip $url");
+                           push(@log,"$datetime $ip $so $url");
                            if (@log > $Header::viewsize) {
                                shift (@log);
                            }
@@ -239,7 +248,7 @@ if ($@ ne '')
                        #    $datetime = $maxtime; # we have read viewsize lines, stop main loop
                        #    last READ;           # exit read file
                        }
-                   }   
+                   }
                }
 
                # finish loop when date of lines are past maxtime
@@ -247,7 +256,7 @@ if ($@ ne '')
            }
            close (FILE);
        }
-       $gzindex--;     # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
+       $gzindex--;     # will try next gz file eg 40,39,38,.... because it may have holes when ipfire stopped
                        # for a long time
 
     }
@@ -269,8 +278,9 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
 {
        print "Content-type: text/plain\n\n";
        print "IPFire proxy log\r\n";
-       print "$Lang::tr{'date'}: $daystr\r\n"; 
+       print "$Lang::tr{'date'}: $daystr\r\n";
        print "Source IP: $cgiparams{'SOURCE_IP'}\r\n";
+       print "Username: $cgiparams{'USERNAME'}\r\n";
        if ($cgiparams{'ENABLE_FILTER'} eq 'on') {
                print "Ignore filter: $cgiparams{'FILTER'}\r\n"; }
        print "\r\n";
@@ -278,22 +288,23 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
        if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
 
        foreach $_ (@log) {
-           my ($datetime,$ip,$url) = split;
+           my ($datetime,$ip,$so,$url) = split;
            my ($SECdt, $MINdt, $HOURdt, $DAYdt, $MONTHdt, $YEARdt) = localtime($datetime);
            $SECdt = sprintf ("%.02d",$SECdt);
            $MINdt = sprintf ("%.02d",$MINdt);
            $HOURdt = sprintf ("%.02d",$HOURdt);
            if ($cgiparams{'DAY'}==0) {                 # full month
                $DAYdt = sprintf ("%.02d",$DAYdt);
-               print "$DAYdt/$HOURdt:$MINdt:$SECdt $ip $url\n";
+               print "$DAYdt/$HOURdt:$MINdt:$SECdt $ip $so $url\n";
            } else {
-               print "$HOURdt:$MINdt:$SECdt $ip $url\n";
+               print "$HOURdt:$MINdt:$SECdt $ip $so $url\n";
            }
        }
        exit;
 }
 
 $selected{'SOURCE_IP'}{$cgiparams{'SOURCE_IP'}} = "selected='selected'";
+$selected{'USERNAME'}{$cgiparams{'USERNAME'}} = "selected='selected'";
 
 $checked{'ENABLE_FILTER'}{'off'} = '';
 $checked{'ENABLE_FILTER'}{'on'} = '';
@@ -339,7 +350,7 @@ print <<END
 END
 ;
 print "<option value='0'>$Lang::tr{'all'}</option>";
-for (my $day = 1; $day <= 31; $day++) 
+for (my $day = 1; $day <= 31; $day++)
 {
        print "\t<option ";
        if ($day == $cgiparams{'DAY'}) {
@@ -357,12 +368,27 @@ print <<END
        <option value='ALL' $selected{'SOURCE_IP'}{'ALL'}>$Lang::tr{'caps all'}</option>
 END
 ;
-foreach my $ip (keys %ips) {
+foreach my $ip (sort keys %ips) {
        print "<option value='$ip' $selected{'SOURCE_IP'}{$ip}>$ip</option>\n"; }
 print <<END
        </select>
        </td>
 </tr>
+<tr>
+       <td width='60%' colspan='6'>&nbsp;</td>
+       <td width='25%' class='base'>$Lang::tr{'advproxy NCSA username'}:</td>
+       <td width='15%'>
+       <select name='USERNAME'>
+       <option value='ALL' $selected{'USERNAME'}{'ALL'}>$Lang::tr{'caps all'}</option>
+END
+;
+foreach my $so (sort keys %users) {
+       $so = &Header::escape($so);
+       print "<option value='$so' $selected{'USERNAME'}{$so}>$so</option>\n"; }
+print <<END
+       </select>
+       </td>
+</tr>
 <tr>
        <td class='base'>$Lang::tr{'ignore filter'}:</td>
        <td colspan='5'><input type='text' name='FILTER' value='$cgiparams{'FILTER'}' size='40' /></td>
@@ -411,22 +437,26 @@ if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
 print "<p><b>$Lang::tr{'web hits'} $daystr: $lines</b></p>";
 if ($lines != 0) { &oldernewer(); }
 print <<END
-<table width='100%'>
+<table width='100%' class='tbl'>
 <tr>
-<td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
-<td width='15%' align='center' class='boldbase'><b>$Lang::tr{'source ip'}</b></td>
-<td width='75%' align='center' class='boldbase'><b>$Lang::tr{'website'}</b></td>
+<th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
+<th width='15%' align='center' class='boldbase'><b>$Lang::tr{'source ip'}</b></th>
+<th width='12%' align='center' class='boldbase'><b>$Lang::tr{'advproxy NCSA username'}</b></th>
+<th width='63%' align='center' class='boldbase'><b>$Lang::tr{'website'}</b></th>
 </tr>
 END
 ;
 my $ll = 0;
+my $col='';
 foreach $_ (@log)
 {
        if ($ll % 2) {
-               print "<tr bgcolor='${Header::table1colour}'>\n"; }
+               print "<tr>";
+               $col="bgcolor='$color{'color20'}'"; }
        else {
-               print "<tr bgcolor='${Header::table2colour}'>\n"; }
-       my ($datetime,$ip,$url) = split;
+               print "<tr>";
+               $col="bgcolor='$color{'color22'}'"; }
+       my ($datetime,$ip,$so,$url) = split;
         my ($SECdt, $MINdt, $HOURdt, $DAYdt, $MONTHdt, $YEARdt) = localtime($datetime);
        $SECdt = sprintf ("%.02d",$SECdt);
        $MINdt = sprintf ("%.02d",$MINdt);
@@ -434,7 +464,7 @@ foreach $_ (@log)
 
        $url =~ /(^.{0,60})/;
        my $part = $1;
-       unless (length($part) < 60) { $part = "${part}..."; }  
+       unless (length($part) < 60) { $part = "${part}..."; }
        $url = &Header::cleanhtml($url,"y");
        $part = &Header::cleanhtml($part,"y");
        if ($cgiparams{'DAY'}==0) {                     # full month
@@ -443,9 +473,10 @@ foreach $_ (@log)
            $DAYdt='';
        }
        print <<END
-       <td align='center'>$DAYdt$HOURdt:$MINdt:$SECdt</td>
-       <td align='center'>$ip</td>
-       <td align='left'><a href='$url' title='$url' target='_new'>$part</a></td>
+       <td align='center' $col>$DAYdt$HOURdt:$MINdt:$SECdt</td>
+       <td align='center' $col>$ip</td>
+       <td align='center' $col>$so</td>
+       <td align='left' $col><a href='$url' title='$url' target='_new'>$part</a></td>
 </tr>
 END
        ;
@@ -473,14 +504,14 @@ END
 
 print "<td align='center' width='50%'>";
 if ($prev != -1) {
-        print "<a href='/cgi-bin/logs.cgi/proxylog.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SOURCE_IP'}'>$Lang::tr{'older'}</a>"; }
+        print "<a href='/cgi-bin/logs.cgi/proxylog.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SOURCE_IP'},$cgiparams{'USERNAME'}'>$Lang::tr{'older'}</a>"; }
 else {
         print "$Lang::tr{'older'}"; }
 print "</td>\n";
 
 print "<td align='center' width='50%'>";
 if ($next >= 0 ) {
-        print "<a href='/cgi-bin/logs.cgi/proxylog.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SOURCE_IP'}'>$Lang::tr{'newer'}</a>"; }
+        print "<a href='/cgi-bin/logs.cgi/proxylog.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SOURCE_IP'},$cgiparams{'USERNAME'}'>$Lang::tr{'newer'}</a>"; }
 else {
         print "$Lang::tr{'newer'}"; }
 print "</td>\n";