diff --git a/html/cgi-bin/logs.cgi/firewalllog.dat b/html/cgi-bin/logs.cgi/firewalllog.dat index df9b48812..5c9722b85 100644 --- a/html/cgi-bin/logs.cgi/firewalllog.dat +++ b/html/cgi-bin/logs.cgi/firewalllog.dat @@ -41,11 +41,11 @@ my %logsettings=(); my $errormessage = ''; my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', - 'Sep', 'Oct', 'Nov', 'Dec' ); + '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'} ); + $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]; @@ -66,55 +66,55 @@ my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ? 0x7FFFF000 : 0; #index o 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]; + 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'} =~ /^(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]; + $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]; + 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]; + 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 @@ -122,104 +122,104 @@ 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"; - } + 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; + # 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 ); + # 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 $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 () { - 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 + # 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 () { + 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 "IPFire firewall log\r\n"; - print "$Lang::{'date'}: $date\r\n\r\n"; + print "Content-type: text/plain\n\n"; + print "IPFire firewall log\r\n"; + print "$Lang::{'date'}: $date\r\n\r\n"; - if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; } + 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; + 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(); @@ -229,9 +229,9 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}) &Header::openbigbox('100%', 'left', '', $errormessage); if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); } &Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -240,33 +240,35 @@ print < - $Lang::tr{'month'}: - - + $Lang::tr{'month'}: + + END ; for (my $month = 0; $month < 12; $month++) { - print "\t$longmonths[$month]\n"; + print "\t$longmonths[$month]\n"; } print < - - $Lang::tr{'day'}: - - + + + $Lang::tr{'day'}: + + END ; print "$Lang::tr{'all'}\n"; for (my $day = 1; $day <= 31; $day++) { - print "\t$day\n"; + print "\t$day\n"; } print < @@ -291,20 +293,20 @@ $start = $lastPageIndex if ($start >= $lastPageIndex); $start = 0 if ($start < 0); my $prev; - if ($start == 0) { - $prev = -1; - } else { - $prev = $start - ${Header::viewsize}; - $prev = 0 if ( $prev < 0); - } - +if ($start == 0) { + $prev = -1; +} else { + $prev = $start - ${Header::viewsize}; + $prev = 0 if ( $prev < 0); +} + my $next; - if ($start == $lastPageIndex) { - $next = -1; - } else { - $next = $start + ${Header::viewsize}; - $next = $lines - ${Header::viewsize} if ($next >= $lines - ${Header::viewsize}); - } +if ($start == $lastPageIndex) { + $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(); } @@ -312,14 +314,14 @@ if ($lines != 0) { &oldernewer(); } print < - $Lang::tr{'time'} - $Lang::tr{'chain'} - $Lang::tr{'iface'} - $Lang::tr{'proto'} - $Lang::tr{'source'}$Lang::tr{'destination'} - $Lang::tr{'src port'}$Lang::tr{'dst port'} - $Lang::tr{'country'} - $Lang::tr{'mac address'} + $Lang::tr{'time'} + $Lang::tr{'chain'} + $Lang::tr{'iface'} + $Lang::tr{'proto'} + $Lang::tr{'source'}$Lang::tr{'destination'} + $Lang::tr{'src port'}$Lang::tr{'dst port'} + $Lang::tr{'country'} + $Lang::tr{'mac address'} END ; @@ -330,70 +332,74 @@ foreach $_ (@log) { # If ipv6 uses a bridge, PHYSIN= contains the relevant iface information # otherwise use IN= - my $packet = ''; - if ($_ =~ /^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) { $packet = $5; } - elsif ($_ =~ /^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) { $packet = $4; } - my $day = $1; - $day =~ tr / /0/; - my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ; - my $chain = $3; + my $packet = ''; + if ($_ =~ /^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) { $packet = $5; } + elsif ($_ =~ /^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) { $packet = $4; } + my $day = $1; + $day =~ tr / /0/; + my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ; + my $chain = $3; - my ($iface, $srcaddr, $dstaddr, $macaddr, $proto, $srcport, $dstport); - if ($packet =~ /PHYSIN=(\w+)/) { $iface=$1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } - # Identify whether ipv4 or ipv6. Both are mutally exclusive. - if ($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $srcaddr=$1; } - if ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $srcaddr=$1; } - if ($packet =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $dstaddr=$1; } - if ($packet =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $dstaddr=$1; } - $macaddr=$1 if $packet =~ /MAC=([\w+\:]+)/; - $proto=$1 if $packet =~ /PROTO=(\w+)/; - $srcport=$1 if $packet =~ /SPT=(\d+)/; - $dstport=$1 if $packet =~ /DPT=(\d+)/; + my ($iface, $srcaddr, $dstaddr, $macaddr, $proto, $srcport, $dstport); + if ($packet =~ /PHYSIN=(\w+)/) { $iface=$1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } + # Identify whether ipv4 or ipv6. Both are mutally exclusive. + if ($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $srcaddr=$1; } + if ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $srcaddr=$1; } + if ($packet =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $dstaddr=$1; } + if ($packet =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $dstaddr=$1; } + $macaddr=$1 if $packet =~ /MAC=([\w+\:]+)/; + $proto=$1 if $packet =~ /PROTO=(\w+)/; + $srcport=$1 if $packet =~ /SPT=(\d+)/; + $dstport=$1 if $packet =~ /DPT=(\d+)/; - my $gi = Geo::IP::PurePerl->new(); - my $ccode = $gi->country_code_by_name($srcaddr); - my $fcode = lc($ccode); + my $gi = Geo::IP::PurePerl->new(); + my $ccode = $gi->country_code_by_name($srcaddr); + my $fcode = lc($ccode); - 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]"; - my $col=""; - if ($lines % 2) { - print ""; - $col="bgcolor='$color{'color20'}'"; } - else { - print ""; - $col="bgcolor='$color{'color22'}'"; } - print <"; + $col="bgcolor='$color{'color20'}'"; + } + else { + print ""; + $col="bgcolor='$color{'color22'}'"; + } + print <$time - $chain - $iface - $proto - $srcaddr$dstaddr - $srcport$dstport + $time + $chain + $iface + $proto + $srcaddr$dstaddr + $srcport$dstport END -; + ; # Get flag icon for of the country. my $flag_icon = &GeoIP::get_flag_icon($fcode); - if ( $flag_icon) { + if ( $flag_icon) { print ""; } else { print ""; } - print <$macaddr - + print <$macaddr + END - ; - $lines++; + ; + $lines++; } print ""; @@ -408,32 +414,36 @@ print ""; sub oldernewer { -print < - + print < + END -; + ; -print ""; -if ($prev != -1) { - print "$Lang::tr{'first'} "; - print "$Lang::tr{'older'}"; } -else { - print "$Lang::tr{'first'} $Lang::tr{'older'}"; } -print "\n"; + print ""; + if ($prev != -1) { + print "$Lang::tr{'first'} "; + print "$Lang::tr{'older'}"; + } + else { + print "$Lang::tr{'first'} $Lang::tr{'older'}"; + } + print "\n"; -print ""; -if ($next >= 0) { - print "$Lang::tr{'newer'} "; - print "$Lang::tr{'last'}"; } -else { - print "$Lang::tr{'newer'} $Lang::tr{'last'} "; } -print "\n"; + print ""; + if ($next >= 0) { + print "$Lang::tr{'newer'} "; + print "$Lang::tr{'last'}"; + } + else { + print "$Lang::tr{'newer'} $Lang::tr{'last'} "; + } + print "\n"; -print < - + print < + END -; + ; } diff --git a/html/cgi-bin/logs.cgi/firewalllogcountry.dat b/html/cgi-bin/logs.cgi/firewalllogcountry.dat index 087b84443..26920b5da 100644 --- a/html/cgi-bin/logs.cgi/firewalllogcountry.dat +++ b/html/cgi-bin/logs.cgi/firewalllogcountry.dat @@ -8,7 +8,7 @@ # page inspired from the initial firewalllog.dat # # Modified for IPFire by Christian Schmidt -# and Michael Tremer (www.ipfire.org) +# and Michael Tremer (www.ipfire.org) use strict; use Geo::IP::PurePerl; @@ -39,11 +39,11 @@ $cgiparams{'showpie'} = 1; $cgiparams{'sortcolumn'} = 1; my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', - 'Sep', 'Oct', 'Nov', 'Dec' ); + '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'} ); + $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]; @@ -69,81 +69,81 @@ if ($cgiparams{'sortcolumn'} != 0) { $settings{'sortcolumn'} = $cgiparams{'sortc if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { - &General::writehash("${General::swroot}/fwlogs/ipsettings", \%settings); + &General::writehash("${General::swroot}/fwlogs/ipsettings", \%settings); } 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]; + 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]; + $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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -151,62 +151,63 @@ my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; my $day = $cgiparams{'DAY'}; my $daystr=''; if ($day <= 9) { - $daystr = " $day"; } + $daystr = " $day"; +} else { - $daystr = $day; + $daystr = $day; } my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); if (!$skip) { - while () - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while () + { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); } $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { - while () { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); - } + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { + while () { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); + } } my $MODNAME="fwlogs"; @@ -217,9 +218,9 @@ my $MODNAME="fwlogs"; if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); } &Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,33 +229,33 @@ print < - $Lang::tr{'month'}: - - + $Lang::tr{'month'}: + + END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t$longmonths[$month]\n"; + print "\t$longmonths[$month]\n"; } print < - - $Lang::tr{'day'}: - - + + + $Lang::tr{'day'}: + + END ; for ($day = 1; $day <= 31; $day++) { - print "\t$day\n"; + print "\t$day\n"; } if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} @@ -293,43 +294,43 @@ $lines = 0; foreach $_ (@log) { - # If ipv6 uses bridge, use PHYSIN for iface, otherwise IN - if (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(PHYSIN=.*)$/) {} - elsif (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} - my $packet = $4; - my $iface = ''; - if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } - if ( $1 =~ /2./ ) { $iface=''; } - my $srcaddr = ''; - # Find ipv4 and ipv6 addresses - if ($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $srcaddr = $1; } - elsif ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $srcaddr = $1; } + # If ipv6 uses bridge, use PHYSIN for iface, otherwise IN + if (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(PHYSIN=.*)$/) {} + elsif (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} + my $packet = $4; + my $iface = ''; + if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } + if ( $1 =~ /2./ ) { $iface=''; } + my $srcaddr = ''; + # Find ipv4 and ipv6 addresses + if ($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) { $srcaddr = $1; } + elsif ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/) { $srcaddr = $1; } - if($iface eq $red_interface) { - # Traffic from red - if($srcaddr ne '') { - # srcaddr is set - my $ccode = $gi->country_code_by_name($srcaddr); - if ($ccode eq '') { - $ccode = 'unknown'; - } - $tabjc{$ccode} = $tabjc{$ccode} + 1 ; - if(($tabjc{$ccode} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } - $linesjc++; - } - } - else { - # Traffic not from red - if($iface ne '') { - $tabjc{$iface} = $tabjc{$iface} + 1 ; - if(($tabjc{$iface} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } - $linesjc++; - } - else { - # What to do with empty iface lines? - # This probably is traffic from ipfire itself (IN= OUT=XY)? - } - } + if($iface eq $red_interface) { + # Traffic from red + if($srcaddr ne '') { + # srcaddr is set + my $ccode = $gi->country_code_by_name($srcaddr); + if ($ccode eq '') { + $ccode = 'unknown'; + } + $tabjc{$ccode} = $tabjc{$ccode} + 1; + if(($tabjc{$ccode} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } + $linesjc++; + } + } + else { + # Traffic not from red + if($iface ne '') { + $tabjc{$iface} = $tabjc{$iface} + 1 ; + if(($tabjc{$iface} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } + $linesjc++; + } + else { + # What to do with empty iface lines? + # This probably is traffic from ipfire itself (IN= OUT=XY)? + } + } } $pienumber = $lines; @@ -349,13 +350,11 @@ my @value; my $indice=0; my @tabjc2; -if ($sortcolumn == 1) -{ - @tabjc2 = sort { $b <=> $a } values (%tabjc); +if ($sortcolumn == 1) { + @tabjc2 = sort { $b <=> $a } values (%tabjc); } -else -{ - @tabjc2 = sort { $a <=> $b } keys (%tabjc); +else { + @tabjc2 = sort { $a <=> $b } keys (%tabjc); } my $colour=1; @@ -367,19 +366,17 @@ use GD::Graph::colour; #ips sort by hits number my $v; -if ($sortcolumn == 1) -{ - for ($v=0;$v<$pienumber;$v++){ - findkey($tabjc2[$v]); - } +if ($sortcolumn == 1) { + for ($v=0;$v<$pienumber;$v++){ + findkey($tabjc2[$v]); + } } -else -{ - foreach $v (@tabjc2) { - $key[$indice] = $v; - $value[$indice] = $tabjc{$v}; - $indice++; - } +else { + foreach $v (@tabjc2) { + $key[$indice] = $v; + $value[$indice] = $tabjc{$v}; + $indice++; + } } my @ips; @@ -392,15 +389,15 @@ my $o; if($cgiparams{'otherspie'} == 2 ){} else{ - my $numothers; - for($o=0;$o<$pienumber;$o++){ - $numothers = $numothers + $numb[$o]; - } - $numothers = $linesjc - $numothers; - if ($numothers > 0) { - $ips[$pienumber]="$Lang::tr{'otherip'}"; - $numb[$pienumber] = $numothers; - } + my $numothers; + for($o=0;$o<$pienumber;$o++){ + $numothers = $numothers + $numb[$o]; + } + $numothers = $linesjc - $numothers; + if ($numothers > 0) { + $ips[$pienumber]="$Lang::tr{'otherip'}"; + $numb[$pienumber] = $numothers; + } } my @data = (\@ips,\@numb); @@ -413,28 +410,28 @@ my %mainsettings = (); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); if ($showpie != 2 && $pienumber <= 50 && $pienumber != 0) { - my $mygraph = GD::Graph::pie->new(500, 350); - $mygraph->set( - 'title' => '', - 'pie_height' => 50, - 'start_angle' => 89 - ) or warn $mygraph->error; + my $mygraph = GD::Graph::pie->new(500, 350); + $mygraph->set( + 'title' => '', + 'pie_height' => 50, + 'start_angle' => 89 + ) or warn $mygraph->error; - $mygraph->set_value_font(GD::gdMediumBoldFont); - $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); - my $myimage = $mygraph->plot(\@data) or die $mygraph->error; + $mygraph->set_value_font(GD::gdMediumBoldFont); + $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); + my $myimage = $mygraph->plot(\@data) or die $mygraph->error; - my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-country*.png"); - unlink(@filenames); - my $imagerandom = rand(1000000); - my $imagename = "/srv/web/ipfire/html/graphs/fwlog-country$imagerandom.png"; - open(FILE,">$imagename"); - print FILE $myimage->png; - close(FILE); - ##################################################### - print ""; - print ""; - print ""; + my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-country*.png"); + unlink(@filenames); + my $imagerandom = rand(1000000); + my $imagename = "/srv/web/ipfire/html/graphs/fwlog-country$imagerandom.png"; + open(FILE,">$imagename"); + print FILE $myimage->png; + close(FILE); + ##################################################### + print ""; + print ""; + print ""; } print < @@ -456,72 +453,72 @@ my $col=""; for($s=0;$s<$lines;$s++) { - $show++; - $percent = $value[$s] * 100 / $linesjc; - $percent = sprintf("%.f", $percent); - $total = $total + $value[$s]; - # colors are numbered 1 to 10 - my $colorIndex = ($color % 10) + 1; - $col="bgcolor='$color{\"color$colorIndex\"}'"; - $color++; - print ""; + $show++; + $percent = $value[$s] * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + $total = $total + $value[$s]; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + $color++; + print ""; - print ""; + print ""; - # Dont show details button for "unknown" location. - if ($key[$s] ne 'unknown') { - print""; - print""; - print""; - print""; - print""; - } - elsif ($key[$s] eq 'unknown') { - print "unknown"; - } - # Looks dangerous to use hardcoded interface names here. Probably needs fixing. - if ($key[$s] eq 'blue0' || $key[$s] eq 'green0' || $key[$s] eq 'orange0' ) { - print "$key[$s]"; - } - else { - my $fcode = lc($key[$s]); - - # Get flag icon for of the country. - my $flag_icon = &GeoIP::get_flag_icon($fcode); - - if($flag_icon) { - print ""; - } else { + # Dont show details button for "unknown" location. + if ($key[$s] ne 'unknown') { + print""; + print""; + print""; + print""; + print""; + } + elsif ($key[$s] eq 'unknown') { + print "unknown"; + } + # Looks dangerous to use hardcoded interface names here. Probably needs fixing. + if ($key[$s] eq 'blue0' || $key[$s] eq 'green0' || $key[$s] eq 'orange0' ) { print "$key[$s]"; - } - } - print "$value[$s]"; - print "$percent"; - print ""; + } + else { + my $fcode = lc($key[$s]); + + # Get flag icon for of the country. + my $flag_icon = &GeoIP::get_flag_icon($fcode); + + if($flag_icon) { + print ""; + } else { + print "$key[$s]"; + } + } + print "$value[$s]"; + print "$percent"; + print ""; } if($cgiparams{'otherspie'} == 2 ){} else{ - # colors are numbered 1 to 10 - my $colorIndex = ($color % 10) + 1; - $col="bgcolor='$color{\"color$colorIndex\"}'"; - print ""; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + print ""; -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print < -$Lang::tr{'other countries'} -$dif -$percent - + if ( $linesjc ne "0") + { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print < + $Lang::tr{'other countries'} + $dif + $percent + END -; -} + ; + } } print < @@ -533,19 +530,19 @@ END &Header::closepage(); sub findkey { - my $v; - foreach $v (@keytabjc) { - if ($tabjc{$v} eq $_[0]) { - delete $tabjc{$v}; - $key[$indice] = "$v"; - $value[$indice] = $_[0]; - $indice++; - last; - } - } + my $v; + foreach $v (@keytabjc) { + if ($tabjc{$v} eq $_[0]) { + delete $tabjc{$v}; + $key[$indice] = "$v"; + $value[$indice] = $_[0]; + $indice++; + last; + } + } } sub checkversion { - #Automatic Updates is disabled - return "0","0"; + #Automatic Updates is disabled + return "0","0"; } diff --git a/html/cgi-bin/logs.cgi/firewalllogip.dat b/html/cgi-bin/logs.cgi/firewalllogip.dat index 6fc34223e..08ef1c4be 100644 --- a/html/cgi-bin/logs.cgi/firewalllogip.dat +++ b/html/cgi-bin/logs.cgi/firewalllogip.dat @@ -8,7 +8,7 @@ # page inspired from the initial firewalllog.dat # # Modified for IPFire by Christian Schmidt -# and Michael Tremer (www.ipfire.org) +# and Michael Tremer (www.ipfire.org) use strict; use Geo::IP::PurePerl; @@ -39,11 +39,11 @@ $cgiparams{'showpie'} = 1; $cgiparams{'sortcolumn'} = 1; my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', - 'Sep', 'Oct', 'Nov', 'Dec' ); + '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'} ); + $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]; @@ -69,81 +69,81 @@ if ($cgiparams{'sortcolumn'} != 0) { $settings{'sortcolumn'} = $cgiparams{'sortc if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { - &General::writehash("${General::swroot}/fwlogs/ipsettings", \%settings); + &General::writehash("${General::swroot}/fwlogs/ipsettings", \%settings); } 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]; + 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]; + $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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -151,62 +151,62 @@ my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; my $day = $cgiparams{'DAY'}; my $daystr=''; if ($day <= 9) { - $daystr = " $day"; } + $daystr = " $day"; } else { - $daystr = $day; + $daystr = $day; } my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { $filestr="/var/log/messages.$datediff"; $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); if (!$skip) { - while () - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while () + { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); } $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { - while () { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); - } + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { + while () { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); + } } my $MODNAME="fwlogs"; @@ -217,9 +217,9 @@ my $MODNAME="fwlogs"; if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); } &Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,33 +228,35 @@ print < - $Lang::tr{'month'}: - - + $Lang::tr{'month'}: + + END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t$longmonths[$month]\n"; + print "\t$longmonths[$month]\n"; } print < - - $Lang::tr{'day'}: - - + + + $Lang::tr{'day'}: + + END ; for ($day = 1; $day <= 31; $day++) { - print "\t$day\n"; + print "\t$day\n"; } if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} @@ -291,12 +293,12 @@ if ($pienumber == -1 || $pienumber > $lines || $sortcolumn == 2) { $pienumber = $lines = 0; foreach $_ (@log) { - # Extract ipv4 or ipv6 address - if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - $tabjc{$1} = $tabjc{$1} + 1 ; - if(($tabjc{$1} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } - $linesjc++; - } + # Extract ipv4 or ipv6 address + if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + $tabjc{$1} = $tabjc{$1} + 1 ; + if(($tabjc{$1} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } + $linesjc++; + } } $pienumber = $lines; @@ -318,11 +320,11 @@ my @tabjc2; if ($sortcolumn == 1) { - @tabjc2 = sort { $b <=> $a } values (%tabjc); + @tabjc2 = sort { $b <=> $a } values (%tabjc); } else { - @tabjc2 = sort { $a <=> $b } keys (%tabjc); + @tabjc2 = sort { $a <=> $b } keys (%tabjc); } my $colour=1; @@ -336,17 +338,17 @@ my $v; if ($sortcolumn == 1) { - for ($v=0;$v<$pienumber;$v++){ - findkey($tabjc2[$v]); - } + for ($v=0;$v<$pienumber;$v++){ + findkey($tabjc2[$v]); + } } else { - foreach $v (@tabjc2) { - $key[$indice] = $v; - $value[$indice] = $tabjc{$v}; - $indice++; - } + foreach $v (@tabjc2) { + $key[$indice] = $v; + $value[$indice] = $tabjc{$v}; + $indice++; + } } my @ips; @@ -359,15 +361,15 @@ my $o; if($cgiparams{'otherspie'} == 2 ){} else{ - my $numothers; - for($o=0;$o<$pienumber;$o++){ - $numothers = $numothers + $numb[$o]; - } - $numothers = $linesjc - $numothers; - if ($numothers > 0) { - $ips[$pienumber]="$Lang::tr{'otherip'}"; - $numb[$pienumber] = $numothers; - } + my $numothers; + for($o=0;$o<$pienumber;$o++){ + $numothers = $numothers + $numb[$o]; + } + $numothers = $linesjc - $numothers; + if ($numothers > 0) { + $ips[$pienumber]="$Lang::tr{'otherip'}"; + $numb[$pienumber] = $numothers; + } } my @data = (\@ips,\@numb); @@ -380,28 +382,28 @@ my %mainsettings = (); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); if ($showpie != 2 && $pienumber <= 50 && $pienumber != 0) { - my $mygraph = GD::Graph::pie->new(500, 350); - $mygraph->set( - 'title' => '', - 'pie_height' => 50, - 'start_angle' => 89 - ) or warn $mygraph->error; + my $mygraph = GD::Graph::pie->new(500, 350); + $mygraph->set( + 'title' => '', + 'pie_height' => 50, + 'start_angle' => 89 + ) or warn $mygraph->error; - $mygraph->set_value_font(GD::gdMediumBoldFont); - $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); - my $myimage = $mygraph->plot(\@data) or die $mygraph->error; + $mygraph->set_value_font(GD::gdMediumBoldFont); + $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); + my $myimage = $mygraph->plot(\@data) or die $mygraph->error; - my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-ip*.png"); - unlink(@filenames); - my $imagerandom = rand(1000000); - my $imagename = "/srv/web/ipfire/html/graphs/fwlog-ip$imagerandom.png"; - open(FILE,">$imagename"); - print FILE $myimage->png; - close(FILE); - ##################################################### - print ""; - print ""; - print ""; + my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-ip*.png"); + unlink(@filenames); + my $imagerandom = rand(1000000); + my $imagename = "/srv/web/ipfire/html/graphs/fwlog-ip$imagerandom.png"; + open(FILE,">$imagename"); + print FILE $myimage->png; + close(FILE); + ##################################################### + print ""; + print ""; + print ""; } print <"; + $show++; + $percent = $value[$s] * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + $total = $total + $value[$s]; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + print ""; + + my $gi = Geo::IP::PurePerl->new(); + my $ccode = $gi->country_code_by_name($key[$s]); + my $fcode = lc($ccode); - my $gi = Geo::IP::PurePerl->new(); - my $ccode = $gi->country_code_by_name($key[$s]); - my $fcode = lc($ccode); - - $color++; - print " "; - print "$key[$s]"; + $color++; + print " "; + print "$key[$s]"; - # Get flag icon for of the country. - my $flag_icon = &GeoIP::get_flag_icon($ccode); + # Get flag icon for of the country. + my $flag_icon = &GeoIP::get_flag_icon($ccode); - if ( $flag_icon ) { - print ""; - } else { - print ""; - } + if ( $flag_icon ) { + print ""; + } else { + print ""; + } - print "$value[$s]"; - print "$percent"; - print ""; - } + print "$value[$s]"; + print "$percent"; + print ""; +} if($cgiparams{'otherspie'} == 2 ){} else{ - # colors are numbered 1 to 10 - my $colorIndex = ($color % 10) + 1; - $col="bgcolor='$color{\"color$colorIndex\"}'"; - print ""; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + print ""; -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print < -$Lang::tr{'otherip'} - -$dif -$percent - + if ( $linesjc ne "0") + { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print < + $Lang::tr{'otherip'} + + $dif + $percent + END -; -} + ; + } } print < @@ -490,20 +492,20 @@ END &Header::closepage(); sub findkey { - my $v; - foreach $v (@keytabjc) { - if ($tabjc{$v} eq $_[0]) { - delete $tabjc{$v}; - $key[$indice] = "$v"; - $value[$indice] = $_[0]; - $indice++; - last; - } - } + my $v; + foreach $v (@keytabjc) { + if ($tabjc{$v} eq $_[0]) { + delete $tabjc{$v}; + $key[$indice] = "$v"; + $value[$indice] = $_[0]; + $indice++; + last; + } + } } sub checkversion { - #Automatic Updates is disabled - return "0","0"; + #Automatic Updates is disabled + return "0","0"; } diff --git a/html/cgi-bin/logs.cgi/firewalllogport.dat b/html/cgi-bin/logs.cgi/firewalllogport.dat index 583c1b3d3..fbc92e43b 100644 --- a/html/cgi-bin/logs.cgi/firewalllogport.dat +++ b/html/cgi-bin/logs.cgi/firewalllogport.dat @@ -8,7 +8,7 @@ # page inspired from the initial firewalllog.dat # # Modified for IPFire by Christian Schmidt -# and Michael Tremer (www.ipfire.org) +# and Michael Tremer (www.ipfire.org) use strict; @@ -40,11 +40,11 @@ $cgiparams{'showpie'} = 1; $cgiparams{'sortcolumn'} = 1; my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', - 'Sep', 'Oct', 'Nov', 'Dec' ); + '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'} ); + $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]; @@ -70,81 +70,81 @@ if ($cgiparams{'sortcolumn'} != 0) { $settings{'sortcolumn'} = $cgiparams{'sortc if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { - &General::writehash("${General::swroot}/fwlogs/portsettings", \%settings); + &General::writehash("${General::swroot}/fwlogs/portsettings", \%settings); } 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]; + 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]; + $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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -152,62 +152,62 @@ my $longmonthstr = $longmonths[$cgiparams{'MONTH'}]; my $day = $cgiparams{'DAY'}; my $daystr=''; if ($day <= 9) { - $daystr = " $day"; } + $daystr = " $day"; } else { - $daystr = $day; + $daystr = $day; } my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); if (!$skip) { - while () - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while () + { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); } $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { - while () { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); - } + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { + while () { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + $log[$lines] = $_; + $lines++; + } + } + close (FILE); + } } my $MODNAME="fwlogs"; @@ -217,9 +217,9 @@ my $MODNAME="fwlogs"; &Header::openbigbox('100%', 'left', '', $errormessage); if ($errormessage) { - &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); - print "$errormessage \n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "$errormessage \n"; + &Header::closebox(); } &Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,33 +228,33 @@ print < - $Lang::tr{'month'}: - - + $Lang::tr{'month'}: + + END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t$longmonths[$month]\n"; + print "\t$longmonths[$month]\n"; } print < - - $Lang::tr{'day'}: - - + + + $Lang::tr{'day'}: + + END ; for ($day = 1; $day <= 31; $day++) { - print "\t$day\n"; + print "\t$day\n"; } if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} @@ -291,11 +291,11 @@ if ($pienumber == -1 || $pienumber > $lines || $sortcolumn == 2) { $pienumber = $lines = 0; foreach $_ (@log) { - if($_ =~ /DPT\=([\d\.]+)/){ - $tabjc{$1} = $tabjc{$1} + 1 ; - if(($tabjc{$1} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } - $linesjc++; - } + if($_ =~ /DPT\=([\d\.]+)/){ + $tabjc{$1} = $tabjc{$1} + 1 ; + if(($tabjc{$1} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } + $linesjc++; + } } $pienumber = $lines; @@ -317,11 +317,11 @@ my @tabjc2; if ($sortcolumn == 1) { - @tabjc2 = sort { $b <=> $a } values (%tabjc); + @tabjc2 = sort { $b <=> $a } values (%tabjc); } else { - @tabjc2 = sort { $a <=> $b } keys (%tabjc); + @tabjc2 = sort { $a <=> $b } keys (%tabjc); } my $color=10; @@ -338,17 +338,17 @@ my $v; if ($sortcolumn == 1) { - for ($v=0;$v<$pienumber;$v++){ - findkey($tabjc2[$v]); - } + for ($v=0;$v<$pienumber;$v++){ + findkey($tabjc2[$v]); + } } else { - foreach $v (@tabjc2) { - $key[$indice] = $v; - $value[$indice] = $tabjc{$v}; - $indice++; - } + foreach $v (@tabjc2) { + $key[$indice] = $v; + $value[$indice] = $tabjc{$v}; + $indice++; + } } my @ports; @@ -361,15 +361,15 @@ my $o; if($cgiparams{'otherspie'} == 2 ){} else{ - my $numothers; - for($o=0;$o<$pienumber;$o++){ - $numothers = $numothers + $numb[$o]; - } - $numothers = $linesjc - $numothers; - if ($numothers > 0) { - $ports[$pienumber]="$Lang::tr{'otherport'}"; - $numb[$pienumber] = $numothers; - } + my $numothers; + for($o=0;$o<$pienumber;$o++){ + $numothers = $numothers + $numb[$o]; + } + $numothers = $linesjc - $numothers; + if ($numothers > 0) { + $ports[$pienumber]="$Lang::tr{'otherport'}"; + $numb[$pienumber] = $numothers; + } } my @data = (\@ports,\@numb); @@ -381,28 +381,28 @@ my %mainsettings = (); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); if ($showpie != 2 && $pienumber <= 50 && $pienumber != 0) { - my $mygraph = GD::Graph::pie->new(500, 350); - $mygraph->set( - 'title' => '', - 'pie_height' => 50, - 'start_angle' => 89 - ) or warn $mygraph->error; + my $mygraph = GD::Graph::pie->new(500, 350); + $mygraph->set( + 'title' => '', + 'pie_height' => 50, + 'start_angle' => 89 + ) or warn $mygraph->error; - $mygraph->set_value_font(GD::gdMediumBoldFont); - $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); - my $myimage = $mygraph->plot(\@data) or die $mygraph->error; + $mygraph->set_value_font(GD::gdMediumBoldFont); + $mygraph->set( dclrs => [ "$color{'color1'}" , "$color{'color2'}" , "$color{'color3'}" , "$color{'color4'}" , "$color{'color5'}" , "$color{'color6'}" , "$color{'color7'}" , "$color{'color8'}" , "$color{'color9'}" , "$color{'color10'}" ] ); + my $myimage = $mygraph->plot(\@data) or die $mygraph->error; - my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-port*.png"); - unlink(@filenames); - my $imagerandom = rand(1000000); - my $imagename = "/srv/web/ipfire/html/graphs/fwlog-port$imagerandom.png"; - open(FILE,">$imagename"); - print FILE $myimage->png; - close(FILE); - ##################################################### - print ""; - print ""; - print ""; + my @filenames = glob("/srv/web/ipfire/html/graphs/fwlog-port*.png"); + unlink(@filenames); + my $imagerandom = rand(1000000); + my $imagename = "/srv/web/ipfire/html/graphs/fwlog-port$imagerandom.png"; + open(FILE,">$imagename"); + print FILE $myimage->png; + close(FILE); + ##################################################### + print ""; + print ""; + print ""; } print <"; + $show++; + $percent = $value[$s] * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + $total = $total + $value[$s]; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + print ""; - $color++; - print " "; - print "$key[$s]"; - print "$value[$s]"; - print "$percent"; - print ""; + $color++; + print " "; + print "$key[$s]"; + print "$value[$s]"; + print "$percent"; + print ""; } if($cgiparams{'otherspie'} == 2 ){} else{ - # colors are numbered 1 to 10 - my $colorIndex = ($color % 10) + 1; - $col="bgcolor='$color{\"color$colorIndex\"}'"; - print ""; + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{\"color$colorIndex\"}'"; + print ""; -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print < -$Lang::tr{'otherport'} -$dif -$percent - + if ( $linesjc ne "0") { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print < + $Lang::tr{'otherport'} + $dif + $percent + END -; -} + ; + } } print < @@ -475,20 +474,20 @@ END &Header::closepage(); sub findkey { - my $v; - foreach $v (@keytabjc) { - if ($tabjc{$v} eq $_[0]) { - delete $tabjc{$v}; - $key[$indice] = "$v"; - $value[$indice] = $_[0]; - $indice++; - last; - } - } + my $v; + foreach $v (@keytabjc) { + if ($tabjc{$v} eq $_[0]) { + delete $tabjc{$v}; + $key[$indice] = "$v"; + $value[$indice] = $_[0]; + $indice++; + last; + } + } } sub checkversion { - #Automatic Updates is disabled - return "0","0"; + #Automatic Updates is disabled + return "0","0"; } diff --git a/html/cgi-bin/logs.cgi/showrequestfromcountry.dat b/html/cgi-bin/logs.cgi/showrequestfromcountry.dat index 27e76971a..cd97f8780 100644 --- a/html/cgi-bin/logs.cgi/showrequestfromcountry.dat +++ b/html/cgi-bin/logs.cgi/showrequestfromcountry.dat @@ -69,60 +69,60 @@ if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || } 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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -138,16 +138,16 @@ else { my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); @@ -156,78 +156,77 @@ my $gi = Geo::IP::PurePerl->new(); if (!$skip) { - while () - { - # First check whether valid log line (date, day) - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - # If ipv6 uses bridge, then use PHYSIN otherwise use IN - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(PHYSIN=.*)$/) {} - elsif (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {} - my $packet = $2; - my $iface = ''; - my $srcaddr = ''; - # If ipv6 uses bridge, use PHYSIN otherwise IN - if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } - # Extract ipv4 and ipv6 addresses - if (($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - $srcaddr = $1; - }; + while () { + # First check whether valid log line (date, day) + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + # If ipv6 uses bridge, then use PHYSIN otherwise use IN + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(PHYSIN=.*)$/) {} + elsif (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) {} + my $packet = $2; + my $iface = ''; + my $srcaddr = ''; + # If ipv6 uses bridge, use PHYSIN otherwise IN + if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } + # Extract ipv4 and ipv6 addresses + if (($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + $srcaddr = $1; + } - if($iface eq $country) { - # iface matches country code - $log[$lines] = $_; - $lines++; - } - elsif($srcaddr ne '') { - # or srcaddr matches country code - my $ccode = $gi->country_code_by_name($srcaddr); - if($ccode eq uc($country)){ - $log[$lines] = $_; - $lines++; - } - } - } + if($iface eq $country) { + # iface matches country code + $log[$lines] = $_; + $lines++; + } + elsif($srcaddr ne '') { + # or srcaddr matches country code + my $ccode = $gi->country_code_by_name($srcaddr); + if($ccode eq uc($country)){ + $log[$lines] = $_; + $lines++; + } + } + } } close (FILE); } $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { while () { - # Check if valid log line (date, day) - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - my $iface = ''; - # If ipv6 uses bridge, then use PHYSIN otherwise IN - if ($_ =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($_ =~ /IN=(\w+)/) { $iface = $1; } + # Check if valid log line (date, day) + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + my $iface = ''; + # If ipv6 uses bridge, then use PHYSIN otherwise IN + if ($_ =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($_ =~ /IN=(\w+)/) { $iface = $1; } - if($iface eq $country) { - # iface matches country code - $log[$lines] = $_; - $lines++; - } - # extract ipv4 and ipv6 address - elsif (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - my $srcaddr=$1; - my $ccode = $gi->country_code_by_name($srcaddr); - if($ccode eq uc($country)){ - # or srcaddr matches country code - $log[$lines] = $_; - $lines++; - } - } - } + if($iface eq $country) { + # iface matches country code + $log[$lines] = $_; + $lines++; + } + # extract ipv4 and ipv6 address + elsif (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + my $srcaddr=$1; + my $ccode = $gi->country_code_by_name($srcaddr); + if($ccode eq uc($country)){ + # or srcaddr matches country code + $log[$lines] = $_; + $lines++; + } + } + } } close (FILE); } @@ -259,7 +258,8 @@ for ($month = 0; $month < 12; $month++) { print "\t$longmonths[$month]\n"; } print <$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines"; if ($start == -1) { - $start = $lines - ${Header::viewsize}; } + $start = $lines - ${Header::viewsize}; +} if ($start >= $lines - ${Header::viewsize}) { $start = $lines - ${Header::viewsize}; }; if ($start < 0) { $start = 0; } @@ -331,78 +332,80 @@ if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } $lines = 0; foreach $_ (@slice) { - $a = $_; - # If ipv6 uses bridge, use PHYSIN otherwise use IN - if (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(PHYSIN=.*)$/) {} - elsif (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {}; - my $packet = $4; - my $iface = ''; - # If ipv6 uses bridge, use PHYSIN otherwise use IN - if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } - if ( $1 =~ /2./ ){ $iface=""; } - my $srcaddr = ''; - # Extract ipv4 and ipv6 addresses - if (($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - $srcaddr = $1; - }; + $a = $_; + # If ipv6 uses bridge, use PHYSIN otherwise use IN + if (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(PHYSIN=.*)$/) {} + elsif (/^... (..) (..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {}; + my $packet = $4; + my $iface = ''; + # If ipv6 uses bridge, use PHYSIN otherwise use IN + if ($packet =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($packet =~ /IN=(\w+)/) { $iface = $1; } + if ( $1 =~ /2./ ){ $iface=""; } + my $srcaddr = ''; + # Extract ipv4 and ipv6 addresses + if (($packet =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($packet =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + $srcaddr = $1; + }; - if($iface eq $country || $srcaddr ne '') { - my $ccode=''; - if($iface ne $country) { - $ccode = $gi->country_code_by_name($srcaddr); - } - if($iface eq $country || $ccode eq uc($country)) { - my $chain = ''; - my $in = '-'; my $out = '-'; - my $srcaddr = ''; my $dstaddr = ''; - my $protostr = ''; - my $srcport = ''; my $dstport = ''; + if($iface eq $country || $srcaddr ne '') { + my $ccode=''; + if($iface ne $country) { + $ccode = $gi->country_code_by_name($srcaddr); + } + if($iface eq $country || $ccode eq uc($country)) { + my $chain = ''; + my $in = '-'; my $out = '-'; + my $srcaddr = ''; my $dstaddr = ''; + my $protostr = ''; + my $srcport = ''; my $dstport = ''; - # If ipv6 uses bridge, the use PHYSIN otherwise use IN - if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} - elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} - my $timestamp = $1; my $chain = $2; my $packet = $3; - $timestamp =~ /(...) (..) (..:..:..)/; - my $month = $1; my $day = $2; my $time = $3; + # If ipv6 uses bridge, the use PHYSIN otherwise use IN + if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} + elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} + my $timestamp = $1; my $chain = $2; my $packet = $3; + $timestamp =~ /(...) (..) (..:..:..)/; + my $month = $1; my $day = $2; my $time = $3; - # If ipv6 uses bridge, use PHYSIN and PHYSOUT, otherwise use IN and OUT - if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; } - if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; } - # Extract ipv4 and ipv6 addresses - if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } - if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } - if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } - my $protostrlc = lc($protostr); - if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } - if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } + # If ipv6 uses bridge, use PHYSIN and PHYSOUT, otherwise use IN and OUT + if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; } + if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; } + # Extract ipv4 and ipv6 addresses + if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } + if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } + if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } + my $protostrlc = lc($protostr); + if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } + if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } - if ($lines % 2) { - print "\n"; } - else { - print "\n"; } - print <$time - $chain - $iface - $protostr - - - $srcaddr - - - $srcport - - - $dstaddr - - - $dstport - + if ($lines % 2) { + print "\n"; + } + else { + print "\n"; + } + print <$time + $chain + $iface + $protostr + + + $srcaddr + + + $srcport + + + $dstaddr + + + $dstport + END - ; - $lines++; - } - } + ; + $lines++; + } + } } print < - + print < + END -; + ; - print ""; - if ($prev != -1) { - print "$Lang::tr{'older'}"; } - else { - print "$Lang::tr{'older'}"; } - print "\n"; + print ""; + if ($prev != -1) { + print "$Lang::tr{'older'}"; + } + else { + print "$Lang::tr{'older'}"; + } + print "\n"; - print ""; - if ($next != -1) { - print "$Lang::tr{'newer'}"; } - else { - print "$Lang::tr{'newer'}"; } - print "\n"; + print ""; + if ($next != -1) { + print "$Lang::tr{'newer'}"; + } + else { + print "$Lang::tr{'newer'}"; + } -print < - + print "\n"; + print < + END -; + ; } diff --git a/html/cgi-bin/logs.cgi/showrequestfromip.dat b/html/cgi-bin/logs.cgi/showrequestfromip.dat index d7d1ace91..154fa4030 100644 --- a/html/cgi-bin/logs.cgi/showrequestfromip.dat +++ b/html/cgi-bin/logs.cgi/showrequestfromip.dat @@ -66,60 +66,60 @@ if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || } 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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -135,16 +135,16 @@ else { my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { $filestr="/var/log/messages.$datediff"; $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); @@ -152,15 +152,14 @@ my $ip = $cgiparams{ip}; if (!$skip) { - while () - { + while () { if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - if($1 eq $ip){ - $log[$lines] = $_; - $lines++; - } - } + if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + if($1 eq $ip){ + $log[$lines] = $_; + $lines++; + } + } } } close (FILE); @@ -168,26 +167,26 @@ if (!$skip) $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { while () { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - if($1 eq $ip){ - $log[$lines] = $_; - $lines++; - } - } + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + if($1 eq $ip){ + $log[$lines] = $_; + $lines++; + } + } } } close (FILE); @@ -257,7 +256,8 @@ END print "$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines"; if ($start == -1) { - $start = $lines - ${Header::viewsize}; } + $start = $lines - ${Header::viewsize}; +} if ($start >= $lines - ${Header::viewsize}) { $start = $lines - ${Header::viewsize}; }; if ($start < 0) { $start = 0; } @@ -290,63 +290,64 @@ my @slice = splice(@log, $start, ${Header::viewsize}); if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } $lines = 0; -foreach $_ (@slice) -{ - $a = $_; - # Check whether valid ipv4 or ipv6 address - if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { - if($1 eq $ip){ - my $chain = ''; - my $in = '-'; my $out = '-'; - my $srcaddr = ''; my $dstaddr = ''; - my $protostr = ''; - my $srcport = ''; my $dstport = ''; +foreach $_ (@slice) { + $a = $_; + # Check whether valid ipv4 or ipv6 address + if (($_ =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($_ =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { + if($1 eq $ip) { + my $chain = ''; + my $in = '-'; my $out = '-'; + my $srcaddr = ''; my $dstaddr = ''; + my $protostr = ''; + my $srcport = ''; my $dstport = ''; - # If ipv6 uses bridge, the use PHYSIN, otherwise use IN - if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} - elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} - my $timestamp = $1; my $chain = $2; my $packet = $3; - $timestamp =~ /(...) (..) (..:..:..)/; - my $month = $1; my $day = $2; my $time = $3; + # If ipv6 uses bridge, the use PHYSIN, otherwise use IN + if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} + elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} + my $timestamp = $1; my $chain = $2; my $packet = $3; + $timestamp =~ /(...) (..) (..:..:..)/; + my $month = $1; my $day = $2; my $time = $3; - # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT - if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; } - if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; } - # Detect ipv4 and ipv6 addresses - if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } - if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } - if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } - my $protostrlc = lc($protostr); - if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } - if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } + # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT + if ($a =~ /PHYSIN=(\w+)/) { $iface = $1; } elsif ($a =~ /IN=(\w+)/) { $iface = $1; } + if ($a =~ /PHYSOUT=(\w+)/) { $out = $1; } elsif ($a =~ /OUT=(\w+)/) { $out = $1; } + # Detect ipv4 and ipv6 addresses + if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } + if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } + if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } + my $protostrlc = lc($protostr); + if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } + if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } - if ($lines % 2) { - print "\n"; } - else { - print "\n"; } - print <$time - $chain - $iface - $protostr - - - $srcaddr - - - $srcport - - - $dstaddr - - - $dstport - + if ($lines % 2) { + print "\n"; + } + else { + print "\n"; + } + print <$time + $chain + $iface + $protostr + + + $srcaddr + + + $srcport + + + $dstaddr + + + $dstport + END - ; - $lines++; - } - } + ; + $lines++; + } + } } print < - + print < + END -; + ; -print ""; -if ($prev != -1) { - print "$Lang::tr{'older'}"; } -else { - print "$Lang::tr{'older'}"; } -print "\n"; + print ""; + if ($prev != -1) { + print "$Lang::tr{'older'}"; + } + else { + print "$Lang::tr{'older'}"; + } + print "\n"; -print ""; -if ($next != -1) { - print "$Lang::tr{'newer'}"; } -else { - print "$Lang::tr{'newer'}"; } -print "\n"; + print ""; + if ($next != -1) { + print "$Lang::tr{'newer'}"; + } + else { + print "$Lang::tr{'newer'}"; + } + print "\n"; -print < - + print < + END -; + ; } diff --git a/html/cgi-bin/logs.cgi/showrequestfromport.dat b/html/cgi-bin/logs.cgi/showrequestfromport.dat index 6f5f63bfb..e1f00aed8 100644 --- a/html/cgi-bin/logs.cgi/showrequestfromport.dat +++ b/html/cgi-bin/logs.cgi/showrequestfromport.dat @@ -73,60 +73,60 @@ if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) || } 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]; + 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]; + 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=$tdoy+366; - } else { - $doy=$doy+365; - } - } + 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=$tdoy+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; - } + $datediff=int(($doy-$tdoy)/7); + $dowd=($doy-$tdoy)%7; + if (($dow-$dowd)<1) { + $datediff=$datediff+1; + } + if (($dow-$dowd)==0) { + $multifile=1; + } } my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; @@ -142,16 +142,16 @@ else { my $skip=0; my $filestr=''; if ($datediff==0) { - $filestr="/var/log/messages"; + $filestr="/var/log/messages"; } else { $filestr="/var/log/messages.$datediff"; $filestr = "$filestr.gz" if -f "$filestr.gz"; } if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $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 + $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 } my $lines = 0; my @log=(); @@ -159,15 +159,15 @@ my $port = $cgiparams{port}; if (!$skip) { - while () - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /DPT\=([\d\.]+)/){ - if($1 eq $port){ - $log[$lines] = $_; - $lines++; - } - } + while () + { + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + if($_ =~ /DPT\=([\d\.]+)/){ + if($1 eq $port){ + $log[$lines] = $_; + $lines++; + } + } } } close (FILE); @@ -175,26 +175,26 @@ if (!$skip) $skip=0; if ($multifile) { - $datediff=$datediff-1; - if ($datediff==0) { - $filestr="/var/log/messages"; - } else { - $filestr="/var/log/messages.$datediff"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { - $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; - $skip=1; - } - if (!$skip) { + $datediff=$datediff-1; + if ($datediff==0) { + $filestr="/var/log/messages"; + } else { + $filestr="/var/log/messages.$datediff"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + if (!(open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr)))) { + $errormessage="$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}"; + $skip=1; + } + if (!$skip) { while () { - if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /DPT\=([\d\.]+)/){ - if($1 eq $port){ - $log[$lines] = $_; - $lines++; - } - } + if (/(^${monthstr} ${daystr} ..:..:..) [\w\-]+ kernel:.*(IN=.*)$/) { + if($_ =~ /DPT\=([\d\.]+)/){ + if($1 eq $port){ + $log[$lines] = $_; + $lines++; + } + } } } close (FILE); @@ -264,7 +264,8 @@ END print "$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines"; if ($start == -1) { - $start = $lines - ${Header::viewsize}; } + $start = $lines - ${Header::viewsize}; +} if ($start >= $lines - ${Header::viewsize}) { $start = $lines - ${Header::viewsize}; }; if ($start < 0) { $start = 0; } @@ -298,60 +299,65 @@ if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } $lines = 0; foreach $_ (@slice) { - $a = $_; - if($_ =~ /DPT\=([\d\.]+)/){ - if($1 eq $port){ - my $chain = ''; - my $in = '-'; my $out = '-'; - my $srcaddr = ''; my $dstaddr = ''; - my $protostr = ''; - my $srcport = ''; my $dstport = ''; + $a = $_; + if($_ =~ /DPT\=([\d\.]+)/){ + if($1 eq $port){ + my $chain = ''; + my $in = '-'; + my $out = '-'; + my $srcaddr = ''; + my $dstaddr = ''; + my $protostr = ''; + my $srcport = ''; + my $dstport = ''; - # If ipv6 uses bridge, the use PHYSIN, otherwise use IN - if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} - elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} - my $timestamp = $1; my $chain = $2; my $packet = $3; - $timestamp =~ /(...) (..) (..:..:..)/; - my $month = $1; my $day = $2; my $time = $3; my $iface; + # If ipv6 uses bridge, the use PHYSIN, otherwise use IN + if ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)(PHYSIN=.*)$/) {} + elsif ($_ =~ /(^.* ..:..:..) [\w\-]+ kernel:(.*)(IN=.*)$/) {} + my $timestamp = $1; my $chain = $2; my $packet = $3; + $timestamp =~ /(...) (..) (..:..:..)/; + my $month = $1; my $day = $2; my $time = $3; my $iface; - # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT - if ($a =~ /PHYSIN\=(\w+)/) { $iface = $1; } elsif ($a =~ /IN\=(\w+)/) { $iface = $1; } - if ($a =~ /PHYSOUT\=(\w+)/) { $out = $1; } elsif ($a =~ /OUT\=(\w+)/) { $out = $1; } - # Detect ipv4 and ipv6 addresses - if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } - if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } - if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } - my $protostrlc = lc($protostr); - if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } - if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } + # If ipv6 uses bridge, the use PHYSIN and PHYSOUT, otherwise use IN and OUT + if ($a =~ /PHYSIN\=(\w+)/) { $iface = $1; } elsif ($a =~ /IN\=(\w+)/) { $iface = $1; } + if ($a =~ /PHYSOUT\=(\w+)/) { $out = $1; } elsif ($a =~ /OUT\=(\w+)/) { $out = $1; } + # Detect ipv4 and ipv6 addresses + if (($a =~ /SRC\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /SRC\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $srcaddr = $1; } + if (($a =~ /DST\=(([\d]{1,3})(\.([\d]{1,3})){3})/) or ($a =~ /DST\=(([0-9a-fA-F]{0,4})(\:([0-9a-fA-F]{0,4})){2,7})/)) { $dstaddr = $1; } + if ($a =~ /PROTO\=(\w+)/) { $protostr = $1; } + my $protostrlc = lc($protostr); + if ($a =~ /SPT\=([\d\.]+)/){ $srcport = $1; } + if ($a =~ /DPT\=([\d\.]+)/){ $dstport = $1; } - if ($lines % 2) { - print "\n"; } - else { - print "\n"; } - print <$time - $chain - $iface - $protostr - - - $srcaddr - - - $srcport - - - $dstaddr - - - $dstport - + if ($lines % 2) { + print "\n"; + } + else { + print "\n"; + } + print <$time + $chain + $iface + $protostr + + + $srcaddr + + + $srcport + + + $dstaddr + + + $dstport + END - ; - $lines++; - } - } + ; + $lines++; + } + } } print < - + print < + END -; + ; -print ""; -if ($prev != -1) { - print "$Lang::tr{'older'}"; } -else { - print "$Lang::tr{'older'}"; } -print "\n"; + print ""; + if ($prev != -1) { + print "$Lang::tr{'older'}"; + } + else { + print "$Lang::tr{'older'}"; + } + print "\n"; -print ""; -if ($next != -1) { - print "$Lang::tr{'newer'}"; } -else { - print "$Lang::tr{'newer'}"; } -print "\n"; + print ""; + if ($next != -1) { + print "$Lang::tr{'newer'}"; + } + else { + print "$Lang::tr{'newer'}"; + } + print "\n"; -print < - + print < + END -; + ; }
$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines