mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 03:07:43 +02:00
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
7
html/cgi-bin/logs.cgi/CVS/Entries
Normal file
7
html/cgi-bin/logs.cgi/CVS/Entries
Normal file
@@ -0,0 +1,7 @@
|
||||
/config.dat/1.2.2.10/Tue Jun 14 12:32:07 2005//TIPCOP_v1_4_0
|
||||
/firewalllog.dat/1.4.2.18/Tue Aug 23 12:01:50 2005//TIPCOP_v1_4_0
|
||||
/ids.dat/1.6.2.16/Tue Jun 14 08:25:30 2005//TIPCOP_v1_4_0
|
||||
/log.dat/1.6.2.22/Tue Jan 3 12:47:17 2006//TIPCOP_v1_4_0
|
||||
/proxylog.dat/1.4.2.25/Thu Jul 7 17:32:24 2005//TIPCOP_v1_4_0
|
||||
/summary.dat/1.3.2.14/Sun Jul 10 00:48:42 2005//TIPCOP_v1_4_0
|
||||
D
|
||||
1
html/cgi-bin/logs.cgi/CVS/Repository
Normal file
1
html/cgi-bin/logs.cgi/CVS/Repository
Normal file
@@ -0,0 +1 @@
|
||||
ipcop/html/cgi-bin/logs.cgi
|
||||
1
html/cgi-bin/logs.cgi/CVS/Root
Normal file
1
html/cgi-bin/logs.cgi/CVS/Root
Normal file
@@ -0,0 +1 @@
|
||||
:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ipcop
|
||||
1
html/cgi-bin/logs.cgi/CVS/Tag
Normal file
1
html/cgi-bin/logs.cgi/CVS/Tag
Normal file
@@ -0,0 +1 @@
|
||||
TIPCOP_v1_4_0
|
||||
165
html/cgi-bin/logs.cgi/config.dat
Normal file
165
html/cgi-bin/logs.cgi/config.dat
Normal file
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# IPCop CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The IPCop Team
|
||||
#
|
||||
# $Id: config.dat,v 1.2.2.10 2005/06/14 12:32:07 eoberlander Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
my %logsettings=();
|
||||
my %checked=();
|
||||
my %selected=();
|
||||
my $errormessage='';
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
$logsettings{'LOGVIEW_REVERSE'} = 'off';
|
||||
$logsettings{'LOGVIEW_VIEWSIZE'} = '150';
|
||||
$logsettings{'LOGWATCH_LEVEL'} = 'Low';
|
||||
$logsettings{'LOGWATCH_KEEP'} = '56';
|
||||
my @VS = ('15','50','100','150','250','500');
|
||||
$logsettings{'ENABLE_REMOTELOG'} = 'off';
|
||||
$logsettings{'REMOTELOG_ADDR'} = '';
|
||||
$logsettings{'ACTION'} = '';
|
||||
&Header::getcgihash(\%logsettings);
|
||||
|
||||
if ($logsettings{'ACTION'} eq $Lang::tr{'save'})
|
||||
{
|
||||
if ($logsettings{'ENABLE_REMOTELOG'} eq 'on')
|
||||
{
|
||||
unless ( &General::validfqdn($logsettings{'REMOTELOG_ADDR'}) ||
|
||||
&General::validip ($logsettings{'REMOTELOG_ADDR'}))
|
||||
{
|
||||
$errormessage = $Lang::tr{'invalid logserver address'};
|
||||
}
|
||||
}
|
||||
unless ($logsettings{'LOGWATCH_KEEP'} =~ /^\d+$/)
|
||||
{
|
||||
$errormessage = $Lang::tr{'invalid keep time'};
|
||||
}
|
||||
unless ($logsettings{'LOGWATCH_LEVEL'} =~ /^Low|Med|High$/)
|
||||
{
|
||||
$errormessage = $Lang::tr{'invalid input'};
|
||||
}
|
||||
unless ($errormessage)
|
||||
{
|
||||
&General::writehash("${General::swroot}/logging/settings", \%logsettings);
|
||||
system('/usr/local/bin/restartsyslogd') == 0
|
||||
or $errormessage = "$Lang::tr{'bad return code'} " . $?/256;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
&General::readhash("${General::swroot}/logging/settings", \%logsettings);
|
||||
|
||||
$checked{'ENABLE_REMOTELOG'}{'off'} = '';
|
||||
$checked{'ENABLE_REMOTELOG'}{'on'} = '';
|
||||
$checked{'ENABLE_REMOTELOG'}{$logsettings{'ENABLE_REMOTELOG'}} = "checked='checked'";
|
||||
|
||||
$checked{'LOGVIEW_REVERSE'}{'off'} = '';
|
||||
$checked{'LOGVIEW_REVERSE'}{'on'} = '';
|
||||
$checked{'LOGVIEW_REVERSE'}{$logsettings{'LOGVIEW_REVERSE'}} = "checked='checked'";
|
||||
|
||||
$selected{'LOGWATCH_LEVEL'}{'Low'} = '';
|
||||
$selected{'LOGWATCH_LEVEL'}{'Med'} = '';
|
||||
$selected{'LOGWATCH_LEVEL'}{'High'} = '';
|
||||
$selected{'LOGWATCH_LEVEL'}{$logsettings{'LOGWATCH_LEVEL'}} = "selected='selected'";
|
||||
|
||||
map ($selected{'LOGVIEW_VIEWSIZE'}{$_} = '', @VS);
|
||||
$selected{'LOGVIEW_VIEWSIZE'}{$logsettings{'LOGVIEW_VIEWSIZE'}} = "selected='selected'";
|
||||
|
||||
&Header::openpage($Lang::tr{'log settings'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log viewing options'});
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td><input type='checkbox' name='LOGVIEW_REVERSE' $checked{'LOGVIEW_REVERSE'}{'on'} /></td>
|
||||
<td class='base' width='50%'>$Lang::tr{'reverse sort'}</td>
|
||||
<td class='base' width='25%' align='right'>$Lang::tr{'log lines per page'}: </td>
|
||||
<td width='25%'><select name='LOGVIEW_VIEWSIZE'>
|
||||
END
|
||||
;
|
||||
foreach my $vs (@VS) {
|
||||
print "\t<option value='$vs' $selected{'LOGVIEW_VIEWSIZE'}{$vs}>$vs</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select></td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log summaries'});
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td class='base' width='50%'>$Lang::tr{'summaries kept'}
|
||||
<input type='text' name='LOGWATCH_KEEP'
|
||||
value='$logsettings{'LOGWATCH_KEEP'}' size='4' /> $Lang::tr{'days'}</td>
|
||||
<td>$Lang::tr{'detail level'}:</td><td>
|
||||
<select name='LOGWATCH_LEVEL'>
|
||||
<option value='Low' $selected{'LOGWATCH_LEVEL'}{'Low'}>$Lang::tr{'low'}</option>
|
||||
<option value='Med' $selected{'LOGWATCH_LEVEL'}{'Med'}>$Lang::tr{'medium'}</option>
|
||||
<option value='High' $selected{'LOGWATCH_LEVEL'}{'High'}>$Lang::tr{'high'}</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'remote logging'});
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td class='base'>$Lang::tr{'enabled'}</td><td><input type='checkbox' name='ENABLE_REMOTELOG' $checked{'ENABLE_REMOTELOG'}{'on'} /></td>
|
||||
<td>$Lang::tr{'log server address'}</td><td><input type='text' name='REMOTELOG_ADDR' value='$logsettings{'REMOTELOG_ADDR'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
&Header::closebox();
|
||||
|
||||
|
||||
|
||||
print <<END
|
||||
<div align='center'>
|
||||
<table width='60%'>
|
||||
<tr>
|
||||
<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
END
|
||||
;
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
411
html/cgi-bin/logs.cgi/firewalllog.dat
Normal file
411
html/cgi-bin/logs.cgi/firewalllog.dat
Normal file
@@ -0,0 +1,411 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
# $Id: firewalllog.dat,v 1.4.2.18 2005/08/23 12:01:50 eoberlander Exp $
|
||||
#
|
||||
# July 28, 2003 - Darren Critchley - darren@kdi.ca
|
||||
# - added source mac adapter to layout
|
||||
#
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
use POSIX();
|
||||
|
||||
#workaround to suppress a warning when a variable is used only once
|
||||
my @dummy = ( ${Header::table2colour} );
|
||||
undef (@dummy);
|
||||
|
||||
my %cgiparams=();
|
||||
my %logsettings=();
|
||||
my $errormessage = '';
|
||||
|
||||
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'},
|
||||
$Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
|
||||
$Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
|
||||
$Lang::tr{'december'} );
|
||||
|
||||
my @now = localtime();
|
||||
my $dow = $now[6];
|
||||
my $doy = $now[7];
|
||||
my $tdoy = $now[7];
|
||||
my $year = $now[5]+1900;
|
||||
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
$cgiparams{'ACTION'} = '';
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
$logsettings{'LOGVIEW_REVERSE'} = 'off';
|
||||
&General::readhash("${General::swroot}/logging/settings", \%logsettings);
|
||||
${Header::viewsize} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ? $logsettings{'LOGVIEW_VIEWSIZE'} : 150;
|
||||
|
||||
my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ? 0x7FFFF000 : 0; #index of firts line number to display
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
|
||||
!($cgiparams{'DAY'} =~ /^(0|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)$/))
|
||||
{
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '>>')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
|
||||
## Retrieve the same time on the next day +
|
||||
## 86400 seconds in a day
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]+1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
$temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '<<')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the next day -
|
||||
## 86400 seconds in a day
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]-1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
$temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
|
||||
# Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
|
||||
my $gzindex;
|
||||
my $date = $cgiparams{'DAY'} == 0 ? '' : $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
{
|
||||
my $xday;
|
||||
|
||||
# Calculate time. If future date, calculate for past year !!!
|
||||
if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
( $cgiparams{'MONTH'} > $now[4] ) ) {
|
||||
$xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
|
||||
$date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
|
||||
} else {
|
||||
$xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
|
||||
$date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
|
||||
}
|
||||
|
||||
# calculate end of active week (saturday 23H59)
|
||||
my @then = ();
|
||||
@then = localtime(time());
|
||||
my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]);
|
||||
$sunday += (6-$then[6]) * 86400;
|
||||
|
||||
# Convert delta in second to full weeks
|
||||
$gzindex = int (($sunday-$xday)/604800 );
|
||||
}
|
||||
|
||||
my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
|
||||
my $daystr = $cgiparams{'DAY'} == 0 ? '..' : $cgiparams{'DAY'} <= 9 ? " $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
my $lines = 0;
|
||||
my @log=();
|
||||
|
||||
my $loop = 1;
|
||||
my $filestr = 0;
|
||||
my $lastdatetime; # for debug
|
||||
my $search_for_end = 0;
|
||||
|
||||
while ($gzindex >=0 && $loop) {
|
||||
# calculate file name
|
||||
if ($gzindex == 0) {
|
||||
$filestr = "/var/log/messages";
|
||||
} else {
|
||||
$filestr = "/var/log/messages.$gzindex";
|
||||
$filestr = "$filestr.gz" if -f "$filestr.gz";
|
||||
}
|
||||
# now read file if existing
|
||||
if (open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr))) {
|
||||
#&General::log("reading $filestr");
|
||||
READ:while (<FILE>) {
|
||||
my $line = $_;
|
||||
if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ kernel:.*IN=.*$/) {
|
||||
# when standart viewing, just keep in memory the correct slice
|
||||
# it starts a '$start' and size is $viewport
|
||||
# If export, then keep all lines...
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){
|
||||
$log[$lines++] = "$line";
|
||||
} else {
|
||||
if ($lines++ < ($start + $Header::viewsize)) {
|
||||
push(@log,"$line");
|
||||
if (@log > $Header::viewsize) {
|
||||
shift (@log);
|
||||
}
|
||||
#} else { dont do this optimisation, need to count lines !
|
||||
# $datetime = $maxtime; # we have read viewsize lines, stop main loop
|
||||
# last READ; # exit read file
|
||||
}
|
||||
}
|
||||
$search_for_end = 1; # we find the start of slice, can look for end now
|
||||
} else {
|
||||
if ($search_for_end == 1) {
|
||||
#finish read files when date is over (test month equality only)
|
||||
$line =~ /^(...) (..) ..:..:..*$/;
|
||||
$loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
$gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
|
||||
# for a long time
|
||||
}# while
|
||||
|
||||
# $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
|
||||
{
|
||||
print "Content-type: text/plain\n\n";
|
||||
print "IPCop firewall log\r\n";
|
||||
print "$Lang::{'date'}: $date\r\n\r\n";
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
|
||||
foreach $_ (@log)
|
||||
{
|
||||
/^... (..) (..:..:..) [\w\-]+ kernel:.*(IN=.*)$/;
|
||||
my $day = $1;
|
||||
$day =~ tr / /0/;
|
||||
my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
|
||||
print "$time $3\r\n";
|
||||
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'firewall log'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
|
||||
|
||||
print <<END
|
||||
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' class='base'>$Lang::tr{'month'}: </td>
|
||||
<td width='10%'>
|
||||
<select name='MONTH'>
|
||||
END
|
||||
;
|
||||
for (my $month = 0; $month < 12; $month++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($month == $cgiparams{'MONTH'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$month'>$longmonths[$month]</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
|
||||
<td width='40%'>
|
||||
<select name='DAY'>
|
||||
END
|
||||
;
|
||||
print "<option value='0'>$Lang::tr{'all'}</option>\n";
|
||||
for (my $day = 1; $day <= 31; $day++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($day == $cgiparams{'DAY'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$day'>$day</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
END
|
||||
;
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log'});
|
||||
print "<p><b>$Lang::tr{'firewall hits'} $date: $lines</b></p>";
|
||||
|
||||
$start = $lines - ${Header::viewsize} if ($start >= $lines - ${Header::viewsize});
|
||||
$start = 0 if ($start < 0);
|
||||
|
||||
my $prev;
|
||||
if ($start == 0) {
|
||||
$prev = -1;
|
||||
} else {
|
||||
$prev = $start - ${Header::viewsize};
|
||||
$prev = 0 if ( $prev < 0);
|
||||
}
|
||||
|
||||
my $next;
|
||||
if ($start == $lines - ${Header::viewsize}) {
|
||||
$next = -1;
|
||||
} else {
|
||||
$next = $start + ${Header::viewsize};
|
||||
$next = $lines - ${Header::viewsize} if ($next >= $lines - ${Header::viewsize});
|
||||
}
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
if ($lines != 0) { &oldernewer(); }
|
||||
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
|
||||
<td width='13%' align='center' class='boldbase'><b>$Lang::tr{'chain'}</b></td>
|
||||
<td width='5%' align='center' class='boldbase'><b>$Lang::tr{'iface'}</b></td>
|
||||
<td width='5%' align='center' class='boldbase'><b>$Lang::tr{'proto'}</b></td>
|
||||
<td width='16%' align='center' class='boldbase'><b>$Lang::tr{'source'}</b></td>
|
||||
<td width='10%' align='center' class='boldbase'><b>$Lang::tr{'src port'}</b></td>
|
||||
<td width='5%' align='center' class='boldbase'><b>$Lang::tr{'mac address'}</b></td>
|
||||
<td width='16%' align='center' class='boldbase'><b>$Lang::tr{'destination'}</b></td>
|
||||
<td width='20%' align='center' class='boldbase'><b>$Lang::tr{'dst port'}</b></td>
|
||||
</tr>
|
||||
END
|
||||
;
|
||||
|
||||
|
||||
$lines = 0;
|
||||
foreach $_ (@log)
|
||||
{
|
||||
/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/;
|
||||
my $day = $1;
|
||||
$day =~ tr / /0/;
|
||||
my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
|
||||
my $comment = $3;
|
||||
my $packet = $4;
|
||||
|
||||
|
||||
$packet =~ /IN=(\w+)/; my $iface=$1;
|
||||
$packet =~ /SRC=([\d\.]+)/; my $srcaddr=$1;
|
||||
$packet =~ /DST=([\d\.]+)/; my $dstaddr=$1;
|
||||
$packet =~ /MAC=([\w+\:]+)/; my $macaddr=$1;
|
||||
$packet =~ /PROTO=(\w+)/; my $proto=$1;
|
||||
$packet =~ /SPT=(\d+)/; my $srcport=$1;
|
||||
$packet =~ /DPT=(\d+)/; my $dstport=$1;
|
||||
my $servi = uc(getservbyport($srcport, lc($proto)));
|
||||
if ($servi ne '' && $srcport < 1024) {
|
||||
$srcport = "$srcport($servi)"; }
|
||||
$servi = uc(getservbyport($dstport, lc($proto)));
|
||||
if ($servi ne '' && $dstport < 1024) {
|
||||
$dstport = "$dstport($servi)";}
|
||||
my @mactemp = split(/:/,$macaddr);
|
||||
$macaddr = "$mactemp[6]:$mactemp[7]:$mactemp[8]:$mactemp[9]:$mactemp[10]:$mactemp[11]";
|
||||
if ($lines % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'>\n"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'>\n"; }
|
||||
print <<END
|
||||
|
||||
<td align='center'>$time</td>
|
||||
<td align='center'>$comment</td>
|
||||
<td align='center'>$iface</td>
|
||||
<td align='center'>$proto</td>
|
||||
<td align='center'>
|
||||
<table width='100%' cellpadding='0' cellspacing='0'><tr>
|
||||
<td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td>
|
||||
</tr></table>
|
||||
</td>
|
||||
<td align='center'>$srcport</td>
|
||||
<td align='center'>$macaddr</td>
|
||||
<td align='center'>
|
||||
<table width='100%' cellpadding='0' cellspacing='0'><tr>
|
||||
<td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td>
|
||||
</tr></table>
|
||||
</td>
|
||||
<td align='center'>$dstport</td>
|
||||
</tr>
|
||||
END
|
||||
;
|
||||
$lines++;
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
&oldernewer();
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
sub oldernewer
|
||||
{
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
END
|
||||
;
|
||||
|
||||
print "<td align='center' width='50%'>";
|
||||
if ($prev != -1) {
|
||||
print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$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/firewalllog.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a>"; }
|
||||
else {
|
||||
print "$Lang::tr{'newer'}"; }
|
||||
print "</td>\n";
|
||||
|
||||
print <<END
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
}
|
||||
458
html/cgi-bin/logs.cgi/ids.dat
Normal file
458
html/cgi-bin/logs.cgi/ids.dat
Normal file
@@ -0,0 +1,458 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
# Copyright (C) 18-03-2002 Mark Wormgoor <mark@wormgoor.com>
|
||||
# - Added links to Snort database and ipinfo.cgi
|
||||
#
|
||||
# $Id: ids.dat,v 1.6.2.16 2005/06/14 08:25:30 eoberlander Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
use POSIX();
|
||||
|
||||
#workaround to suppress a warning when a variable is used only once
|
||||
my @dummy = ( ${Header::table1colour}, ${Header::table2colour} );
|
||||
undef (@dummy);
|
||||
|
||||
my %cgiparams=();
|
||||
my %logsettings=();
|
||||
my @log=();
|
||||
my $errormessage = '';
|
||||
|
||||
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'},
|
||||
$Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
|
||||
$Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
|
||||
$Lang::tr{'december'} );
|
||||
|
||||
my @now = localtime(time);
|
||||
my $dow = $now[6];
|
||||
my $doy = $now[7];
|
||||
my $tdoy = $now[7];
|
||||
my $year = $now[5]+1900;
|
||||
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
$cgiparams{'ACTION'} = '';
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
$logsettings{'LOGVIEW_REVERSE'} = 'off';
|
||||
&General::readhash("${General::swroot}/logging/settings", \%logsettings);
|
||||
${Header::viewsize} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ? $logsettings{'LOGVIEW_VIEWSIZE'} : 150;
|
||||
$Header::viewsize /= 5; # each ids is displayed on 5 lines
|
||||
|
||||
$now[4] = $cgiparams{'MONTH'}+1;
|
||||
if($now[4] < 10) {
|
||||
$now[4] = "0$now[4]"; }
|
||||
|
||||
my $start = -1;
|
||||
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];
|
||||
}
|
||||
|
||||
if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
|
||||
!($cgiparams{'DAY'} =~ /^(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)$/))
|
||||
{
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '>>')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
|
||||
## Retrieve the same time on the next day +
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '<<')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the previous day -
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
|
||||
|
||||
if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
|
||||
{
|
||||
my @then = ();
|
||||
if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
( $cgiparams{'MONTH'} > $now[4] ) ) {
|
||||
@then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
|
||||
} else {
|
||||
@then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
|
||||
}
|
||||
$tdoy = $then[7];
|
||||
my $lastleap=($year-1)%4;
|
||||
if ($tdoy>$doy) {
|
||||
if ($lastleap == 0 && $tdoy < 60) {
|
||||
$doy=$doy+366;
|
||||
} else {
|
||||
$doy=$doy+365;
|
||||
}
|
||||
}
|
||||
}
|
||||
my $datediff=0;
|
||||
my $dowd=0;
|
||||
my $multifile=0;
|
||||
if ($tdoy ne $doy) {
|
||||
$datediff=int(($doy-$tdoy)/7);
|
||||
$dowd=($doy-$tdoy)%7;
|
||||
if (($dow-$dowd)<1) {
|
||||
$datediff=$datediff+1;
|
||||
}
|
||||
if (($dow-$dowd)==0) {
|
||||
$multifile=1;
|
||||
}
|
||||
}
|
||||
|
||||
my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
|
||||
my $monthnum = $cgiparams{'MONTH'} + 1;
|
||||
my $monthstr = $monthnum <= 9 ? "0$monthnum" : "$monthnum";
|
||||
my $daystr = $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
my $lines = 0;
|
||||
my ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
|
||||
|
||||
&processevent;
|
||||
|
||||
if ($multifile) {
|
||||
$datediff=$datediff-1;
|
||||
&processevent;
|
||||
}
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
|
||||
{
|
||||
print "Content-type: text/plain\n\n";
|
||||
print "IPCop IDS snort log\r\n";
|
||||
print "Date: $cgiparams{'DAY'} $longmonths[$cgiparams{'MONTH'}]\r\n";
|
||||
print "\r\n";
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
|
||||
foreach $_ (@log)
|
||||
{
|
||||
my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
|
||||
$refs =~ s/,$//;
|
||||
print "Date: $datetime\n";
|
||||
print "Name: $title\n";
|
||||
print "Priority: $priority\n";
|
||||
print "Type: $classification\n";
|
||||
print "IP Info: ";
|
||||
print "$srcip";
|
||||
if ($srcport != "n/a") {
|
||||
print ":$srcport";
|
||||
}
|
||||
print " -> ";
|
||||
print "$destip";
|
||||
if ($destport != "n/a") {
|
||||
print ":$destport";
|
||||
}
|
||||
print "\n";
|
||||
print "SID: $sid\n";
|
||||
print "Refs: $refs\n\n";
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'ids log viewer'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
|
||||
|
||||
print <<END
|
||||
<form method='post' action="$ENV{'SCRIPT_NAME'}">
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' class='base'>$Lang::tr{'month'}: </td>
|
||||
<td width='10%'>
|
||||
<select name='MONTH'>
|
||||
END
|
||||
;
|
||||
for (my $month = 0; $month < 12; $month++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($month == $cgiparams{'MONTH'}) {
|
||||
print 'selected="selected" '; }
|
||||
print "value='$month'>$longmonths[$month]</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
|
||||
<td width='40%'>
|
||||
<select name='DAY'>
|
||||
END
|
||||
;
|
||||
for (my $day = 1; $day <= 31; $day++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($day == $cgiparams{'DAY'}) {
|
||||
print 'selected="selected" '; }
|
||||
print "value='$day'>$day</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
END
|
||||
;
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log'});
|
||||
print "<p><b>$Lang::tr{'snort hits'} $longmonthstr $daystr: $lines</b></p>";
|
||||
|
||||
if ($start == -1) {
|
||||
$start = $lines - ${Header::viewsize}; }
|
||||
if ($start >= $lines - ${Header::viewsize}) { $start = $lines - ${Header::viewsize}; };
|
||||
if ($start < 0) { $start = 0; }
|
||||
|
||||
my $prev = $start - ${Header::viewsize};
|
||||
my $next = $start + ${Header::viewsize};
|
||||
|
||||
if ($prev < 0) { $prev = 0; }
|
||||
if ($next >= $lines) { $next = -1 }
|
||||
if ($start == 0) { $prev = -1; }
|
||||
my @slice = splice(@log, $start, ${Header::viewsize});
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
|
||||
|
||||
if ($lines != 0) {
|
||||
|
||||
&oldernewer();
|
||||
|
||||
$lines = 0;
|
||||
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
END
|
||||
;
|
||||
|
||||
foreach $_ (@slice)
|
||||
{
|
||||
if ($lines % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'><td>\n"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'><td>\n"; }
|
||||
my ($datetime,$title,$priority,$classification,$srcip,$srcport,$destip,$destport,$sid,$refs) = split(/\|/);
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='15%'><b>$Lang::tr{'date'}:</b></td><td width='25%'>$datetime</td>
|
||||
<td width='10%'><b>$Lang::tr{'name'}:</b></td><td width='50%'>$title</td>
|
||||
</tr>
|
||||
<tr><td><b>$Lang::tr{'priority'}:</b></td><td>$priority</td>
|
||||
<td><b>$Lang::tr{'type'}:</b></td><td>$classification</td>
|
||||
</tr>
|
||||
<tr><td><b>$Lang::tr{'ipinfo'}:</b></td>
|
||||
<td colspan='3'>
|
||||
END
|
||||
;
|
||||
if ($srcip ne "n/a") {
|
||||
print "<a href='/cgi-bin/ipinfo.cgi?ip=$srcip'>$srcip</a>";
|
||||
} else {
|
||||
print "$srcip";
|
||||
}
|
||||
print ":$srcport -> ";
|
||||
if ($destip ne "n/a") {
|
||||
print "<a href='/cgi-bin/ipinfo.cgi?ip=$destip'>$destip</a>";
|
||||
} else {
|
||||
print "$destip";
|
||||
}
|
||||
print ":$destport";
|
||||
print <<END
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td valign='top'><b>$Lang::tr{'references'}:</b></td><td valign='top'>
|
||||
END
|
||||
;
|
||||
foreach my $ref (split(/,/,$refs)) {
|
||||
if ($ref =~ m/url (.*)/) {
|
||||
print "<a href='http://$1'>$1</a><br />";
|
||||
} elsif ($ref =~ m/cve (.*)/) {
|
||||
print "<a href='http://cve.mitre.org/cgi-bin/cvename.cgi?name=$1'>$1</a><br />";
|
||||
} elsif ($ref =~ m/nessus (.*)/) {
|
||||
print "<a href='http://cgi.nessus.org/plugins/dump.php3?id=$1'>Nessus $1</a><br />";
|
||||
} elsif ($ref =~ m/bugtraq (.*)/) {
|
||||
print "<a href='http://www.securityfocus.com/bid/$1'>Bugtraq $1</a><br />";
|
||||
} else {
|
||||
print "$ref<br />";
|
||||
}
|
||||
}
|
||||
print $Lang::tr{'none found'} unless $refs =~ /,/;
|
||||
print <<END
|
||||
<td valign='top'><b>SID:</b></td>
|
||||
<td valign='top'>
|
||||
END
|
||||
;
|
||||
if ($sid ne "n/a") {
|
||||
print "<a href='http://www.snort.org/pub-bin/sigs.cgi?sid=$sid' ";
|
||||
print "target='_blank'>$sid</a></td>\n";
|
||||
} else {
|
||||
print $sid;
|
||||
}
|
||||
print <<END
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
END
|
||||
;
|
||||
$lines++;
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
}
|
||||
|
||||
&oldernewer();
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
sub processevent
|
||||
{
|
||||
our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
|
||||
|
||||
my $filestr='';
|
||||
if ($datediff==0) {
|
||||
$filestr="/var/log/snort/alert";
|
||||
} else {
|
||||
$filestr="/var/log/snort/alert.$datediff";
|
||||
$filestr = "$filestr.gz" if -f "$filestr.gz";
|
||||
}
|
||||
if (!(open (LOG,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) {
|
||||
$errormessage="$errormessage$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
|
||||
} else {
|
||||
my $line = 0;
|
||||
|
||||
while(<LOG>) {
|
||||
$line++;
|
||||
if ($_ =~ m/\[\*\*\]/) {
|
||||
unless ($line == 1 || $date ne "$monthstr/$daystr") {
|
||||
&append;
|
||||
$line = 1;
|
||||
}
|
||||
($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid) = ("n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a", "n/a");
|
||||
@refs = ();
|
||||
$_ =~ m/:([0-9]{1,4})\] (.*) \[\*\*\]/;
|
||||
$title = &Header::cleanhtml($2,"y");
|
||||
}
|
||||
if ($_ =~ m/Classification: (.*)\] \[Priority: (\d)\]/) {
|
||||
$classification = &Header::cleanhtml($1,"y");
|
||||
$priority = $2;
|
||||
}
|
||||
if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) {
|
||||
$srcip = $1 . "." . $2 . "." . $3 . "." . $4;
|
||||
$destip = $5 . "." . $6 . "." . $7 . "." . $8;
|
||||
}
|
||||
if ($_ =~ m/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6}) \-\> ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\:([0-9]{1,6})/) {
|
||||
$srcip = $1 . "." . $2 . "." . $3 . "." . $4;
|
||||
$srcport = $5;
|
||||
$destip = $6 . "." . $7 . "." . $8 . "." . $9;
|
||||
$destport = $10;
|
||||
}
|
||||
|
||||
if ($_ =~ m/^([0-9\/]{3,5})\-([0-9\:]{5,8})\.([0-9]{1,14})/) {
|
||||
($date,$time) = ($1,$2);
|
||||
}
|
||||
if ($_ =~ m/\[Xref \=\>.*\]/) {
|
||||
$_ =~ s/\]\[Xref \=\> /, /g;
|
||||
$_ =~ m/\[Xref \=\> (.*)\]/;
|
||||
push(@refs, $1);
|
||||
}
|
||||
if ($_ =~ m/\[1:([0-9]+):[0-9]+\]/) {
|
||||
$sid = $1;
|
||||
}
|
||||
}
|
||||
$line++;
|
||||
unless ($line == 1 || $date ne "$monthstr/$daystr") { &append; }
|
||||
close(LOG);
|
||||
}
|
||||
}
|
||||
|
||||
sub append
|
||||
{
|
||||
our ($title,$classification,$priority,$date,$time,$srcip,$srcport,$destip,$destport, $sid, @refs);
|
||||
|
||||
$log[$lines] = "$date $time|$title|$priority|$classification|$srcip|$srcport|$destip|$destport|$sid|";
|
||||
foreach $_ (@refs) {
|
||||
$log[$lines] = "$log[$lines]$_,"; }
|
||||
$lines++;
|
||||
}
|
||||
|
||||
sub oldernewer
|
||||
{
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
END
|
||||
;
|
||||
|
||||
print "<td align='center' width='50%'>";
|
||||
if ($prev != -1) {
|
||||
print "<a href='/cgi-bin/logs.cgi/ids.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'older'}</a>"; }
|
||||
else {
|
||||
print "$Lang::tr{'older'}"; }
|
||||
print "</td>\n";
|
||||
|
||||
print "<td align='center' width='50%'>";
|
||||
if ($next != -1) {
|
||||
print "<a href='/cgi-bin/logs.cgi/ids.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a>"; }
|
||||
else {
|
||||
print "$Lang::tr{'newer'}"; }
|
||||
print "</td>\n";
|
||||
|
||||
print <<END
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
}
|
||||
426
html/cgi-bin/logs.cgi/log.dat
Normal file
426
html/cgi-bin/logs.cgi/log.dat
Normal file
@@ -0,0 +1,426 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
# $Id: log.dat,v 1.6.2.22 2006/01/03 12:47:17 franck78 Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
use POSIX();
|
||||
|
||||
#workaround to suppress a warning when a variable is used only once
|
||||
my @dummy = ( ${Header::table2colour} );
|
||||
undef (@dummy);
|
||||
|
||||
my %cgiparams=();
|
||||
my %logsettings=();
|
||||
my $errormessage = '';
|
||||
|
||||
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'},
|
||||
$Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
|
||||
$Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
|
||||
$Lang::tr{'december'} );
|
||||
|
||||
my @now = localtime();
|
||||
my $dow = $now[6];
|
||||
my $doy = $now[7];
|
||||
my $tdoy = $now[7];
|
||||
my $year = $now[5]+1900;
|
||||
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
$cgiparams{'ACTION'} = '';
|
||||
$cgiparams{'SECTION'} = 'ipcop';
|
||||
|
||||
my %sections = (
|
||||
'ipcop' => '(ipcop)',
|
||||
'red' => '(red.*|kernel: usb.*|pppd\[.*\]|chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|kernel: eth.*|dhcpcd\[.*\]|modem_run\[.*\])',
|
||||
'dns' => '(dnsmasq\[.*\])',
|
||||
'dhcp' => '(dhcpd)',
|
||||
'cron' => '(fcron\[.*\])',
|
||||
'ntp' => '(ntpd(?:ate)?\[.*\])',
|
||||
'ssh' => '(sshd(?:\(.*\))?\[.*\])',
|
||||
'auth' => '(\w+\(pam_unix\)\[.*\])',
|
||||
'kernel' => '(kernel)',
|
||||
'ipsec' => '(ipsec_[\w_]+|pluto\[.*\])',
|
||||
'snort' => '(snort)',
|
||||
'installpackage' => '(installpackage\[.*\])'
|
||||
);
|
||||
|
||||
# Translations for the %sections array.
|
||||
my %trsections = (
|
||||
'ipcop' => 'IPCop',
|
||||
'red' => 'RED',
|
||||
'dns' => 'DNS',
|
||||
'dhcp' => "$Lang::tr{'dhcp server'}",
|
||||
'cron' => 'Cron',
|
||||
'ntp' => 'NTP',
|
||||
'ssh' => 'SSH',
|
||||
'auth' => "$Lang::tr{'loginlogout'}",
|
||||
'kernel' => "$Lang::tr{'kernel'}",
|
||||
'ipsec' => 'IPSec',
|
||||
'snort' => 'Snort',
|
||||
'installpackage' => "$Lang::tr{'update transcript'}"
|
||||
);
|
||||
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
$logsettings{'LOGVIEW_REVERSE'} = 'off';
|
||||
&General::readhash("${General::swroot}/logging/settings", \%logsettings);
|
||||
${Header::viewsize} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ? $logsettings{'LOGVIEW_VIEWSIZE'} : 150;
|
||||
|
||||
my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ? 0x7FFFF000 : 0; #index of firts line number to display
|
||||
|
||||
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{'SECTION'} = $temp[3];
|
||||
}
|
||||
|
||||
if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
|
||||
!($cgiparams{'DAY'} =~ /^(0|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)$/))
|
||||
{
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '>>')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
|
||||
## Retrieve the same time on the next day +
|
||||
## 86400 seconds in a day
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]+1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
$temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '<<')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the next day -
|
||||
## 86400 seconds in a day
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]-1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
$temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
|
||||
# Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
|
||||
my $gzindex;
|
||||
my $date = $cgiparams{'DAY'} == 0 ? '' : $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
{
|
||||
my $xday;
|
||||
|
||||
# Calculate time. If future date, calculate for past year !!!
|
||||
if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
( $cgiparams{'MONTH'} > $now[4] ) ) {
|
||||
$xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
|
||||
$date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
|
||||
} else {
|
||||
$xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
|
||||
$date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
|
||||
}
|
||||
|
||||
# calculate end of active week (saturday 23H59)
|
||||
my @then = ();
|
||||
@then = localtime(time());
|
||||
my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]);
|
||||
$sunday += (6-$then[6]) * 86400;
|
||||
|
||||
# Convert delta in second to full weeks
|
||||
$gzindex = int (($sunday-$xday)/604800 );
|
||||
}
|
||||
|
||||
my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
|
||||
my $daystr = $cgiparams{'DAY'} == 0 ? '..' : $cgiparams{'DAY'} <= 9 ? " $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
my $section = $sections{$cgiparams{'SECTION'}};
|
||||
|
||||
my $lines = 0;
|
||||
my @log=();
|
||||
|
||||
my $loop = 1;
|
||||
my $filestr = 0;
|
||||
my $lastdatetime; # for debug
|
||||
my $search_for_end = 0;
|
||||
|
||||
while ($gzindex >=0 && $loop) {
|
||||
# calculate file name
|
||||
if ($gzindex == 0) {
|
||||
$filestr = "/var/log/messages";
|
||||
} else {
|
||||
$filestr = "/var/log/messages.$gzindex";
|
||||
$filestr = "$filestr.gz" if -f "$filestr.gz";
|
||||
}
|
||||
# now read file if existing
|
||||
if (open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr))) {
|
||||
#&General::log("reading $filestr");
|
||||
READ:while (<FILE>) {
|
||||
my $line = $_;
|
||||
if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}: (.*)/) {
|
||||
# when standart viewing, just keep in memory the correct slice
|
||||
# it starts a '$start' and size is $viewport
|
||||
# If export, then keep all lines...
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){
|
||||
$log[$lines++] = "$line";
|
||||
} else {
|
||||
if ($lines++ < ($start + $Header::viewsize)) {
|
||||
push(@log,"$line");
|
||||
if (@log > $Header::viewsize) {
|
||||
shift (@log);
|
||||
}
|
||||
#} else { dont do this optimisation, need to count lines !
|
||||
# $datetime = $maxtime; # we have read viewsize lines, stop main loop
|
||||
# last READ; # exit read file
|
||||
}
|
||||
}
|
||||
$search_for_end = 1; # we find the start of slice, can look for end now
|
||||
} else {
|
||||
if ($search_for_end == 1) {
|
||||
#finish read files when date is over (test month equality only)
|
||||
$line =~ /^(...) (..) ..:..:..*$/;
|
||||
$loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
$gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
|
||||
# for a long time
|
||||
}# while
|
||||
|
||||
# $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
|
||||
{
|
||||
print "Content-type: text/plain\n\n";
|
||||
print "IPCop diagnostics\r\n";
|
||||
print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
|
||||
print "$Lang::tr{'date'}: $date\r\n\r\n";
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
|
||||
foreach $_ (@log)
|
||||
{
|
||||
/^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
|
||||
my $day = $1;
|
||||
$day =~ tr / /0/;
|
||||
my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
|
||||
print "$time $3 $4\r\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'firewall log'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
|
||||
|
||||
print <<END
|
||||
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' class='base'>$Lang::tr{'section'}: </td>
|
||||
<td width='20%'>
|
||||
<select name='SECTION'>
|
||||
END
|
||||
;
|
||||
foreach $section (keys %sections) {
|
||||
print "\t<option ";
|
||||
if ($section eq $cgiparams{'SECTION'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$section'>$trsections{$section}</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
|
||||
<td width='10%'>
|
||||
<select name='MONTH'>
|
||||
END
|
||||
;
|
||||
for (my $month = 0; $month < 12; $month++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($month == $cgiparams{'MONTH'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$month'>$longmonths[$month]</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
|
||||
<td width='40%'>
|
||||
<select name='DAY'>
|
||||
END
|
||||
;
|
||||
print "<option value='0'>$Lang::tr{'all'}</option>\n";
|
||||
for (my $day = 1; $day <= 31; $day++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($day == $cgiparams{'DAY'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$day'>$day</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
END
|
||||
;
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log'});
|
||||
print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
|
||||
|
||||
$start = $lines - ${Header::viewsize} if ($start >= $lines - ${Header::viewsize});
|
||||
$start = 0 if ($start < 0);
|
||||
|
||||
my $prev;
|
||||
if ($start == 0) {
|
||||
$prev = -1;
|
||||
} else {
|
||||
$prev = $start - ${Header::viewsize};
|
||||
$prev = 0 if ( $prev < 0);
|
||||
}
|
||||
|
||||
my $next;
|
||||
if ($start == $lines - ${Header::viewsize}) {
|
||||
$next = -1;
|
||||
} else {
|
||||
$next = $start + ${Header::viewsize};
|
||||
$next = $lines - ${Header::viewsize} if ($next >= $lines - ${Header::viewsize});
|
||||
}
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
if ($lines != 0) { &oldernewer(); }
|
||||
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
|
||||
<td width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
|
||||
<td width='75%'> </td>
|
||||
</tr>
|
||||
END
|
||||
;
|
||||
|
||||
$lines = 0;
|
||||
#print '<tt>';
|
||||
foreach $_ (@log)
|
||||
{
|
||||
/^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
|
||||
my $day = $1;
|
||||
$day =~ tr / /0/;
|
||||
my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
|
||||
my $sec = $3;
|
||||
my $data = $4;
|
||||
# correct the cut position, just when section=RED
|
||||
if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
|
||||
$sec = 'kernel';
|
||||
$data = $2.': '.$data;
|
||||
}
|
||||
my $d = substr ($data,0,80);
|
||||
while (length($data)>80){ #very basic breaking of lines...
|
||||
$data = substr ($data,80); #permit correct display in table cell
|
||||
$d .= ' ' . substr ($data,0,80);
|
||||
}
|
||||
|
||||
|
||||
if ($lines % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'>"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'>"; }
|
||||
print "<td>$time<td>$sec<td>" .&Header::cleanhtml ("$d", 'y') . "</td></tr>\n";
|
||||
$lines++;
|
||||
}
|
||||
#print '</tt>';
|
||||
print "</table>";
|
||||
|
||||
&oldernewer();
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
sub oldernewer
|
||||
{
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
END
|
||||
;
|
||||
|
||||
print "<td align='center' width='50%'>";
|
||||
if ($prev != -1) {
|
||||
print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$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/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
|
||||
else {
|
||||
print "$Lang::tr{'newer'}"; }
|
||||
print "</td>\n";
|
||||
|
||||
print <<END
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
}
|
||||
494
html/cgi-bin/logs.cgi/proxylog.dat
Normal file
494
html/cgi-bin/logs.cgi/proxylog.dat
Normal file
@@ -0,0 +1,494 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
# $Id: proxylog.dat,v 1.4.2.25 2005/07/07 17:32:24 eoberlander Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
use POSIX();
|
||||
|
||||
#workaround to suppress a warning when a variable is used only once
|
||||
my @dummy = ( ${Header::table2colour} );
|
||||
undef (@dummy);
|
||||
|
||||
my %cgiparams=();
|
||||
my %logsettings=();
|
||||
my %ips=();
|
||||
my %selected=();
|
||||
my %checked=();
|
||||
my @log=();
|
||||
my $errormessage = '';
|
||||
|
||||
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'},
|
||||
$Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
|
||||
$Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
|
||||
$Lang::tr{'december'} );
|
||||
|
||||
my @now = localtime();
|
||||
my $dow = $now[6]; # day of week
|
||||
my $doy = $now[7]; # day of year (0..364)
|
||||
my $tdoy = $now[7];
|
||||
my $year = $now[5]+1900;
|
||||
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
$cgiparams{'SOURCE_IP'} = 'ALL';
|
||||
$cgiparams{'FILTER'} = "[.](gif|jpeg|jpg|png|css|js)\$";
|
||||
$cgiparams{'ENABLE_FILTER'} = 'off';
|
||||
$cgiparams{'ACTION'} = '';
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
$logsettings{'LOGVIEW_REVERSE'} = 'off';
|
||||
&General::readhash("${General::swroot}/logging/settings", \%logsettings);
|
||||
${Header::viewsize} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ? $logsettings{'LOGVIEW_VIEWSIZE'} : 150;
|
||||
|
||||
if ($cgiparams{'ACTION'} eq '')
|
||||
{
|
||||
$cgiparams{'ENABLE_FILTER'} = 'on';
|
||||
}
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'restore defaults'})
|
||||
{
|
||||
$cgiparams{'FILTER'} = "[.](gif|jpeg|jpg|png|css|js)\$";
|
||||
$cgiparams{'ENABLE_FILTER'} = 'off';
|
||||
}
|
||||
|
||||
{
|
||||
my %save=();
|
||||
$save{'FILTER'} = $cgiparams{'FILTER'};
|
||||
$save{'ENABLE_FILTER'} = $cgiparams{'ENABLE_FILTER'};
|
||||
&General::writehash("${General::swroot}/proxy/viewersettings", \%save);
|
||||
&General::readhash("${General::swroot}/proxy/viewersettings", \%save);
|
||||
}
|
||||
|
||||
my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ? 0x7FFFF000 : 0; #index of first line number to display
|
||||
|
||||
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{'SOURCE_IP'} = $temp[3];
|
||||
}
|
||||
|
||||
if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
|
||||
!($cgiparams{'DAY'} =~ /^(0|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)$/))
|
||||
{
|
||||
$cgiparams{'DAY'} = $now[3];
|
||||
$cgiparams{'MONTH'} = $now[4];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '>>')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
|
||||
## Retrieve the same time on the next day +
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]+1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
@temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '<<')
|
||||
{
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ($cgiparams{'DAY'}) {
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the next day -
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
} else {
|
||||
$temp_now[3] = 1;
|
||||
$temp_now[4] = ($temp_now[4]-1) %12;
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) );
|
||||
@temp_then[3] = 0;
|
||||
}
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
|
||||
# Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of *.log
|
||||
my $gzindex;
|
||||
my $daystr = $cgiparams{'DAY'} == 0 ? '' :$cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
{
|
||||
my $xday;
|
||||
|
||||
# Calculate time. If future date, calculate for past year !!!
|
||||
if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
( $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 {
|
||||
$xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
|
||||
$daystr = "$longmonths[$cgiparams{'MONTH'}] $daystr, $year";
|
||||
}
|
||||
|
||||
# calculate end of active week (saturday 23H59)
|
||||
my @then = ();
|
||||
@then = localtime(time());
|
||||
my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]);
|
||||
$sunday += (6-$then[6]) * 86400;
|
||||
|
||||
# Convert delta in second to full weeks
|
||||
$gzindex = int (($sunday-$xday)/604800 );
|
||||
}
|
||||
|
||||
|
||||
my $filter = $cgiparams{'ENABLE_FILTER'} eq 'on' ? $cgiparams{'FILTER'} : '';
|
||||
my $sourceip = $cgiparams{'SOURCE_IP'};
|
||||
my $sourceall = $cgiparams{'SOURCE_IP'} eq 'ALL' ? 1 : 0;
|
||||
|
||||
my $lines = 0;
|
||||
my $temp = ();
|
||||
my $thiscode = '$temp =~ /$filter/;';
|
||||
eval($thiscode);
|
||||
if ($@ ne '')
|
||||
{
|
||||
$errormessage = "$Lang::tr{'bad ignore filter'}.$@<P>";
|
||||
$filter = '';
|
||||
} else {
|
||||
my $loop = 1;
|
||||
my $filestr = 0;
|
||||
my $lastdatetime; # for debug
|
||||
|
||||
while ($gzindex >=0 && $loop) {
|
||||
# calculate file name
|
||||
if ($gzindex == 0) {
|
||||
$filestr = "/var/log/squid/access.log";
|
||||
} else {
|
||||
$filestr = "/var/log/squid/access.log.$gzindex";
|
||||
$filestr = "$filestr.gz" if -f "$filestr.gz";
|
||||
}
|
||||
# now read file if existing
|
||||
if (open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr))) {
|
||||
#&General::log("reading $filestr");
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
if ( ( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
( $cgiparams{'MONTH'} > $now[4] ) ) {
|
||||
$temp_now[5]--; # past year
|
||||
}
|
||||
|
||||
$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 $maxtime;
|
||||
if ($cgiparams{'DAY'}==0) { # full month
|
||||
if ($temp_now[4]++ == 12){
|
||||
$temp_now[4] = 0;
|
||||
$temp_now[5]++;
|
||||
};
|
||||
$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}++;
|
||||
# for debug
|
||||
#$lastdatetime = $datetime;
|
||||
|
||||
# collect lines between date && filter
|
||||
if (( ($datetime>$mintime)&&($datetime<$maxtime)) && !($url =~ /$filter/) &&
|
||||
((($ip eq $sourceip) || $sourceall)))
|
||||
{
|
||||
# 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";
|
||||
} else {
|
||||
if ($lines++ < ($start + $Header::viewsize)) {
|
||||
push(@log,"$datetime $ip $url");
|
||||
if (@log > $Header::viewsize) {
|
||||
shift (@log);
|
||||
}
|
||||
#} else { dont do this optimisation, need to count lines !
|
||||
# $datetime = $maxtime; # we have read viewsize lines, stop main loop
|
||||
# last READ; # exit read file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# finish loop when date of lines are past maxtime
|
||||
$loop = ($datetime < $maxtime);
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
$gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
|
||||
# for a long time
|
||||
|
||||
}
|
||||
|
||||
#$errormessage="$errormessage$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
|
||||
if (0) { # print last date record read
|
||||
my ($SECdt, $MINdt, $HOURdt, $DAYdt, $MONTHdt, $YEARdt) = localtime($lastdatetime);
|
||||
$SECdt = sprintf ("%.02d",$SECdt);
|
||||
$MINdt = sprintf ("%.02d",$MINdt);
|
||||
$HOURdt = sprintf ("%.02d",$HOURdt);
|
||||
$DAYdt = sprintf ("%.02d",$DAYdt);
|
||||
$MONTHdt = sprintf ("%.02d",$MONTHdt+1);
|
||||
$YEARdt = sprintf ("%.04d",$YEARdt+1900);
|
||||
&General::log ("$HOURdt:$MINdt:$SECdt, $DAYdt/$MONTHdt/$YEARdt--");
|
||||
}
|
||||
}
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
|
||||
{
|
||||
print "Content-type: text/plain\n\n";
|
||||
print "IPCop proxy log\r\n";
|
||||
print "$Lang::tr{'date'}: $daystr\r\n";
|
||||
print "Source IP: $cgiparams{'SOURCE_IP'}\r\n";
|
||||
if ($cgiparams{'ENABLE_FILTER'} eq 'on') {
|
||||
print "Ignore filter: $cgiparams{'FILTER'}\r\n"; }
|
||||
print "\r\n";
|
||||
|
||||
if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
|
||||
|
||||
foreach $_ (@log) {
|
||||
my ($datetime,$ip,$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";
|
||||
} else {
|
||||
print "$HOURdt:$MINdt:$SECdt $ip $url\n";
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$selected{'SOURCE_IP'}{$cgiparams{'SOURCE_IP'}} = "selected='selected'";
|
||||
|
||||
$checked{'ENABLE_FILTER'}{'off'} = '';
|
||||
$checked{'ENABLE_FILTER'}{'on'} = '';
|
||||
$checked{'ENABLE_FILTER'}{$cgiparams{'ENABLE_FILTER'}} = "checked='checked'";
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'proxy log viewer'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
|
||||
|
||||
print <<END
|
||||
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' class='base'>$Lang::tr{'month'}:</td>
|
||||
<td width='20%'>
|
||||
<select name='MONTH'>
|
||||
END
|
||||
;
|
||||
|
||||
for (my $month = 0; $month < 12; $month++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($month == $cgiparams{'MONTH'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$month'>$longmonths[$month]</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base' align='right'>$Lang::tr{'day'}: </td>
|
||||
<td width='10%'>
|
||||
<select name='DAY'>
|
||||
END
|
||||
;
|
||||
print "<option value='0'>$Lang::tr{'all'}</option>";
|
||||
for (my $day = 1; $day <= 31; $day++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($day == $cgiparams{'DAY'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$day'>$day</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
|
||||
<td width='25%' class='base'>$Lang::tr{'source ip'}:</td>
|
||||
<td width='15%'>
|
||||
<select name='SOURCE_IP'>
|
||||
<option value='ALL' $selected{'SOURCE_IP'}{'ALL'}>$Lang::tr{'caps all'}</option>
|
||||
END
|
||||
;
|
||||
foreach my $ip (keys %ips) {
|
||||
print "<option value='$ip' $selected{'SOURCE_IP'}{$ip}>$ip</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>
|
||||
<td class='base'>$Lang::tr{'enable ignore filter'}:</td>
|
||||
<td><input type='checkbox' name='ENABLE_FILTER' value='on' $checked{'ENABLE_FILTER'}{'on'} /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div align='center'>
|
||||
<table width='50%'>
|
||||
<tr>
|
||||
<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'restore defaults'}' /></td>
|
||||
<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
|
||||
<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
END
|
||||
;
|
||||
|
||||
&Header::closebox();
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'log'});
|
||||
|
||||
|
||||
$start = $lines - ${Header::viewsize} if ($start >= $lines - ${Header::viewsize});
|
||||
$start = 0 if ($start < 0);
|
||||
|
||||
my $prev;
|
||||
if ($start == 0) {
|
||||
$prev = -1;
|
||||
} else {
|
||||
$prev = $start - ${Header::viewsize};
|
||||
$prev = 0 if ( $prev < 0);
|
||||
}
|
||||
|
||||
my $next;
|
||||
if ($start == $lines - ${Header::viewsize}) {
|
||||
$next = -1;
|
||||
} else {
|
||||
$next = $start + ${Header::viewsize};
|
||||
$next = $lines - ${Header::viewsize} if ($next >= $lines - ${Header::viewsize});
|
||||
}
|
||||
|
||||
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%'>
|
||||
<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>
|
||||
</tr>
|
||||
END
|
||||
;
|
||||
my $ll = 0;
|
||||
foreach $_ (@log)
|
||||
{
|
||||
if ($ll % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'>\n"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'>\n"; }
|
||||
my ($datetime,$ip,$url) = split;
|
||||
my ($SECdt, $MINdt, $HOURdt, $DAYdt, $MONTHdt, $YEARdt) = localtime($datetime);
|
||||
$SECdt = sprintf ("%.02d",$SECdt);
|
||||
$MINdt = sprintf ("%.02d",$MINdt);
|
||||
$HOURdt = sprintf ("%.02d",$HOURdt);
|
||||
|
||||
$url =~ /(^.{0,60})/;
|
||||
my $part = $1;
|
||||
unless (length($part) < 60) { $part = "${part}..."; }
|
||||
$url = &Header::cleanhtml($url,"y");
|
||||
$part = &Header::cleanhtml($part,"y");
|
||||
if ($cgiparams{'DAY'}==0) { # full month
|
||||
$DAYdt = sprintf ("%.02d/",$DAYdt);
|
||||
} else {
|
||||
$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>
|
||||
</tr>
|
||||
END
|
||||
;
|
||||
$ll++;
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
&oldernewer();
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
|
||||
|
||||
sub oldernewer
|
||||
{
|
||||
print <<END
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
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>"; }
|
||||
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>"; }
|
||||
else {
|
||||
print "$Lang::tr{'newer'}"; }
|
||||
print "</td>\n";
|
||||
|
||||
print <<END
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
;
|
||||
}
|
||||
|
||||
213
html/cgi-bin/logs.cgi/summary.dat
Normal file
213
html/cgi-bin/logs.cgi/summary.dat
Normal file
@@ -0,0 +1,213 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
# $Id: summary.dat,v 1.3.2.14 2005/07/10 00:48:42 franck78 Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
# enable only the following on debugging purpose
|
||||
#use warnings;
|
||||
#use CGI::Carp 'fatalsToBrowser';
|
||||
|
||||
require 'CONFIG_ROOT/general-functions.pl';
|
||||
require "${General::swroot}/lang.pl";
|
||||
require "${General::swroot}/header.pl";
|
||||
|
||||
use POSIX();
|
||||
|
||||
my %cgiparams=();
|
||||
my $errormessage = '';
|
||||
|
||||
my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
|
||||
$Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
|
||||
$Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
|
||||
$Lang::tr{'december'} );
|
||||
|
||||
my @now = localtime();
|
||||
my $year = $now[5]+1900;
|
||||
|
||||
$cgiparams{'MONTH'} = '';
|
||||
$cgiparams{'DAY'} = '';
|
||||
$cgiparams{'ACTION'} = '';
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
|
||||
my $start = -1;
|
||||
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];
|
||||
}
|
||||
|
||||
if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
|
||||
!($cgiparams{'DAY'} =~ /^(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)$/)) {
|
||||
# Reports are generated at the end of the day, so if nothing is selected
|
||||
# we need to display yesterdays (todays won't have been generated yet)
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $now[4];
|
||||
$temp_now[3] = $now[3];
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the previous day -
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '>>') {
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
|
||||
## Retrieve the same time on the next day +
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
elsif($cgiparams{'ACTION'} eq '<<') {
|
||||
my @temp_then=();
|
||||
my @temp_now = localtime(time);
|
||||
$temp_now[4] = $cgiparams{'MONTH'};
|
||||
$temp_now[3] = $cgiparams{'DAY'};
|
||||
@temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
|
||||
## Retrieve the same time on the previous day -
|
||||
## 86400 seconds in a day
|
||||
$cgiparams{'MONTH'} = $temp_then[4];
|
||||
$cgiparams{'DAY'} = $temp_then[3];
|
||||
}
|
||||
|
||||
if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4])) {
|
||||
if ( ($cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
|
||||
($cgiparams{'MONTH'} > $now[4]) ) {
|
||||
$year = $year - 1;
|
||||
}
|
||||
}
|
||||
|
||||
my $monthnum = $cgiparams{'MONTH'} + 1;
|
||||
my $monthstr = $monthnum <= 9 ? "0$monthnum" : "$monthnum";
|
||||
my $longmonthstr = $longmonths[$cgiparams{'MONTH'}];
|
||||
my $daystr = $cgiparams{'DAY'} <= 9 ? "0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
|
||||
|
||||
my $skip=0;
|
||||
my $filestr="/var/log/logwatch/$year-$monthstr-$daystr";
|
||||
|
||||
if (!(open (FILE,$filestr))) {
|
||||
$errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
|
||||
$skip=1;
|
||||
# Note: This is in case the log does not exist for that date
|
||||
}
|
||||
|
||||
if (! $skip && $cgiparams{'ACTION'} eq $Lang::tr{'export'}) {
|
||||
print "Content-type: text/plain\n\n";
|
||||
|
||||
while (<FILE>) {
|
||||
print "$_\r\n";
|
||||
}
|
||||
close (FILE);
|
||||
exit 0;
|
||||
}
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'log summary'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left', '', $errormessage);
|
||||
|
||||
if ($errormessage) {
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'error messages'});
|
||||
print "<font class='base'>$errormessage </font>\n";
|
||||
&Header::closebox();
|
||||
}
|
||||
|
||||
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
|
||||
|
||||
print <<END
|
||||
<form method='post' action='$ENV{'SCRIPT_NAME'}'>
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='10%' class='base'>$Lang::tr{'month'}:</td>
|
||||
<td width='25%'>
|
||||
<select name='MONTH'>
|
||||
END
|
||||
;
|
||||
for (my $month = 0; $month < 12; $month++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($month == $cgiparams{'MONTH'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$month'>$longmonths[$month]</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='10%' class='base'>$Lang::tr{'day'}:</td>
|
||||
<td width='25%'>
|
||||
<select name='DAY'>
|
||||
END
|
||||
;
|
||||
for (my $day = 1; $day <= 31; $day++)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($day == $cgiparams{'DAY'}) {
|
||||
print "selected='selected' "; }
|
||||
print "value='$day'>$day</option>\n";
|
||||
}
|
||||
print <<END
|
||||
</select>
|
||||
</td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
|
||||
<td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
|
||||
<td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
END
|
||||
;
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
my $header = 0;
|
||||
my @content=();
|
||||
|
||||
if(!$skip)
|
||||
{
|
||||
while (<FILE>) {
|
||||
if (/^\s*--+ ([^-]+) Begin --+\s*$/) {
|
||||
# New Section. open box
|
||||
@content = ();
|
||||
&Header::openbox('100%', 'left', $Lang::tr{"ls_\L$1"} ? $Lang::tr{"ls_\L$1"} : $1);
|
||||
print "<pre>";
|
||||
} elsif (/^\s*--+ ([^-]+) End --+\s*$/) {
|
||||
# End of Section, kill leading and trailing blanks, print info, close
|
||||
# box
|
||||
while ( $content[0] =~ /^\s*$/ ) { shift @content; }
|
||||
while ( $content[$#content] =~ /^\s*$/ ) { pop @content; }
|
||||
foreach $_ (@content) { $_ =~ s/\s*$//; print &Header::cleanhtml($_,"y")."\n"; }
|
||||
print "\n</pre>";
|
||||
&Header::closebox();
|
||||
} elsif (/^\s*#+ LogWatch [^#]+[)] #+\s*$/) {
|
||||
# Start of logwatch header, skip it
|
||||
$header = 1;
|
||||
} elsif (/^\s*#+\s*$/) {
|
||||
# End of logwatch header
|
||||
$header = 0;
|
||||
} elsif (/^\s*#+ LogWatch End #+\s*$/) {
|
||||
# End of report
|
||||
} elsif ($header eq 0) {
|
||||
push(@content,$_);
|
||||
}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
Reference in New Issue
Block a user