This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "IPFire 2.x development tree".
The branch, next has been updated via cf82da6b376e4c7456a0690968ad2e879029a70c (commit) via c97698a8f4b2520e198521c3d67a25efc3ad3776 (commit) via 665f79926d025fec413531c397ccd6998583237e (commit) via 43638be58b2ae99bd07a420c5f340222e2744feb (commit) via 1b5b6c91dae0316c9453fe7560c1d39fc453ebcb (commit) via a249e865bd15f8f9041db8e3894cdae4dc4b25ca (commit) via f97c6774ef3e4bd4cf77b5e6ff1870bc0f7e271b (commit) via 9877d28d9e2daf49324cbf2120d00ab7169da0d3 (commit) via c26171b4b4d6606e2e64bb9c4de36223fea0924d (commit) via 32dd84e81722dfb6b3053b9643deef1e6113e68f (commit) via 1a781c8a29b2a8e758ec556d4e6f845b6db78dff (commit) via ff441e4d3fb96d71b4d547fb7b4ab65ef18a51bd (commit) from 92e4521572f0a5a6411ce74a7a70b9b65dcebb26 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit cf82da6b376e4c7456a0690968ad2e879029a70c Author: Michael Tremer michael.tremer@ipfire.org Date: Sat Jan 23 00:41:02 2016 +0000
core97: Ship updated CGI files
Signed-off-by: Michael Tremer michael.tremer@ipfire.org
commit c97698a8f4b2520e198521c3d67a25efc3ad3776 Merge: 665f799 43638be Author: Michael Tremer michael.tremer@ipfire.org Date: Sat Jan 23 00:39:24 2016 +0000
Merge remote-tracking branch 'meitelwein/web-gui-ipv6' into next
commit 665f79926d025fec413531c397ccd6998583237e Merge: 92e4521 c26171b Author: Michael Tremer michael.tremer@ipfire.org Date: Sat Jan 23 00:39:19 2016 +0000
Merge remote-tracking branch 'origin/master' into next
commit 43638be58b2ae99bd07a420c5f340222e2744feb Author: Michael Eitelwein michael@eitelwein.net Date: Sat Jan 9 20:09:58 2016 +0100
No code changes, fixed formatting by replacing spaces with tabs
commit 1b5b6c91dae0316c9453fe7560c1d39fc453ebcb Author: Michael Eitelwein michael@eitelwein.net Date: Thu Jan 7 19:40:24 2016 +0100
Fixed detection of firewall chain when bridge is used for ipv6
Signed-off-by: Michael Eitelwein michael@eitelwein.net
commit a249e865bd15f8f9041db8e3894cdae4dc4b25ca Author: Michael Eitelwein michael@eitelwein.net Date: Thu Jan 7 16:55:11 2016 +0100
Firewall chain was not extracted correctly when ipv6 uses bridge
Signed-off-by: Michael Eitelwein michael@eitelwein.net
commit f97c6774ef3e4bd4cf77b5e6ff1870bc0f7e271b Author: Michael Eitelwein michael@eitelwein.net Date: Thu Jan 7 15:24:13 2016 +0100
Fix regex to extract firewall chain for ipv6 in showrequestfrom*.dat
If bridged ipv6 is used, $iface is taken from PHYSIN In the log line the order of fields is "... IN=XY OUT=XY PHYSIN=XY ..."
Signed-off-by: Michael Eitelwein michael@eitelwein.net
commit 9877d28d9e2daf49324cbf2120d00ab7169da0d3 Author: Michael Eitelwein michael@eitelwein.net Date: Thu Jan 7 14:00:01 2016 +0100
Enable correct display of ipv6 entries in Firewall log pages of web UI.
3 main changes: - Fill $iface and $out from PHYSIN and PHYSOUT when looking at bridged packets, othwerwise fill from IN and OUT - Recognize ipv4 and ipv6 address style for $srcaddr and $dstaddr - Match color coding of tables to pie charts (see seperate patch sent earlier)
I am using the bridged ipv6 setup as proposed in the wiki. I do not think this breaks anything when not using ipv6. So it would be nice to include this even if ipv6 is not officially supported yet. It is quite useful when using the ipv6 setup.
Signed-off-by: Michael Eitelwein michael@eitelwein.net ---
-----------------------------------------------------------------------
Summary of changes: config/rootfiles/core/97/filelists/files | 7 + config/rootfiles/oldcore/96/update.sh | 11 +- html/cgi-bin/logs.cgi/firewalllog.dat | 492 ++++++++++----------- html/cgi-bin/logs.cgi/firewalllogcountry.dat | 520 ++++++++++++----------- html/cgi-bin/logs.cgi/firewalllogip.dat | 435 ++++++++++--------- html/cgi-bin/logs.cgi/firewalllogport.dat | 405 +++++++++--------- html/cgi-bin/logs.cgi/showrequestfromcountry.dat | 378 ++++++++-------- html/cgi-bin/logs.cgi/showrequestfromip.dat | 300 ++++++------- html/cgi-bin/logs.cgi/showrequestfromport.dat | 302 ++++++------- 9 files changed, 1473 insertions(+), 1377 deletions(-)
Difference in files: diff --git a/config/rootfiles/core/97/filelists/files b/config/rootfiles/core/97/filelists/files index 3d9d483..8586e6a 100644 --- a/config/rootfiles/core/97/filelists/files +++ b/config/rootfiles/core/97/filelists/files @@ -2,6 +2,13 @@ etc/system-release etc/issue etc/rc.d/init.d/firewall etc/modprobe.d/nf_conntrack.conf +srv/web/ipfire/cgi-bin/logs.cgi/firewalllog.dat +srv/web/ipfire/cgi-bin/logs.cgi/firewalllogcountry.dat +srv/web/ipfire/cgi-bin/logs.cgi/firewalllogip.dat +srv/web/ipfire/cgi-bin/logs.cgi/firewalllogport.dat +srv/web/ipfire/cgi-bin/logs.cgi/showrequestfromcountry.dat +srv/web/ipfire/cgi-bin/logs.cgi/showrequestfromip.dat +srv/web/ipfire/cgi-bin/logs.cgi/showrequestfromport.dat srv/web/ipfire/cgi-bin/optionsfw.cgi srv/web/ipfire/cgi-bin/ovpnmain.cgi srv/web/ipfire/cgi-bin/qos.cgi diff --git a/config/rootfiles/oldcore/96/update.sh b/config/rootfiles/oldcore/96/update.sh index a3cf5cf..fa53cea 100644 --- a/config/rootfiles/oldcore/96/update.sh +++ b/config/rootfiles/oldcore/96/update.sh @@ -34,13 +34,13 @@ done # Stop services /etc/init.d/fcron stop /etc/init.d/collectd stop -qosctrl stop +/usr/local/bin/qosctrl stop
# Backup RRDs if [ -d "/var/log/rrd.bak" ]; then # Umount ramdisk umount -l "/var/log/rrd" - rm -f "/var/log/rrd" + rm -rf "/var/log/rrd"
mv "/var/log/rrd.bak/vnstat" "/var/log/vnstat" mv "/var/log/rrd.bak" "/var/log/rrd" @@ -56,7 +56,10 @@ rm -f /etc/rc.d/init.d/tmpfs \ extract_files
# Update Language cache -# /usr/local/bin/update-lang-cache +/usr/local/bin/update-lang-cache + +# Remove Ramdisk entry from fstab +sed -i -e "s|^none\s/var/log/rrd.*||g" /etc/fstab
# Keep (almost) old ramdisk behaviour if [ ! -e "/etc/sysconfig/ramdisk" ]; then @@ -83,7 +86,7 @@ fi /etc/init.d/vnstat start /etc/init.d/fcron start /etc/init.d/dnsmasq restart -qosctrl start +/usr/local/bin/qosctrl start
# Disable loading of cryptodev sed -e "s/^cryptodev/# &/g" -i /etc/sysconfig/modules diff --git a/html/cgi-bin/logs.cgi/firewalllog.dat b/html/cgi-bin/logs.cgi/firewalllog.dat index 5a584d6..5c9722b 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"; - } - - # calculate end of active week (saturday 23H59) - my @then = (); - @then = localtime(time()); - my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]); - $sunday += (6-$then[6]) * 86400; - - # Convert delta in second to full weeks - $gzindex = int (($sunday-$xday)/604800 ); + my $xday; + + # Calculate time. If future date, calculate for past year !!! + if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) || + ( $cgiparams{'MONTH'} > $now[4] ) ) { + $xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ); + $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1); + } else { + $xday = POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ); + $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year"; + } + + # calculate end of active week (saturday 23H59) + my @then = (); + @then = localtime(time()); + my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]); + $sunday += (6-$then[6]) * 86400; + + # Convert delta in second to full weeks + $gzindex = int (($sunday-$xday)/604800 ); } - + my $monthstr = $shortmonths[$cgiparams{'MONTH'}]; my $daystr = $cgiparams{'DAY'} == 0 ? '..' : $cgiparams{'DAY'} <= 9 ? " $cgiparams{'DAY'}" : "$cgiparams{'DAY'}"; - + my $lines = 0; my @log=();
my $loop = 1; my $filestr = 0; -my $lastdatetime; # for debug +my $lastdatetime; # for debug my $search_for_end = 0; - + while ($gzindex >=0 && $loop) { - # calculate file name - if ($gzindex == 0) { - $filestr = "/var/log/messages"; - } else { - $filestr = "/var/log/messages.$gzindex"; - $filestr = "$filestr.gz" if -f "$filestr.gz"; - } - # now read file if existing - if (open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr))) { - #&General::log("reading $filestr"); - READ:while (<FILE>) { - my $line = $_; - if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w-]+ kernel:.*IN=.*$/) { - # when standart viewing, just keep in memory the correct slice - # it starts a '$start' and size is $viewport - # If export, then keep all lines... - if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){ - $log[$lines++] = "$line"; - } else { - if ($lines++ < ($start + $Header::viewsize)) { - push(@log,"$line"); - if (@log > $Header::viewsize) { - shift (@log); - } - #} else { dont do this optimisation, need to count lines ! - # $datetime = $maxtime; # we have read viewsize lines, stop main loop - # last READ; # exit read file - } - } - $search_for_end = 1; # we find the start of slice, can look for end now - } else { - if ($search_for_end == 1) { - #finish read files when date is over (test month equality only) - $line =~ /^(...) (..) ..:..:..*$/; - $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) ); - } - } - } - close (FILE); - } - $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped - # for a long time + # calculate file name + if ($gzindex == 0) { + $filestr = "/var/log/messages"; + } else { + $filestr = "/var/log/messages.$gzindex"; + $filestr = "$filestr.gz" if -f "$filestr.gz"; + } + # now read file if existing + if (open (FILE,($filestr =~ /.gz$/ ? "gzip -dc $filestr |" : $filestr))) { + #&General::log("reading $filestr"); + READ:while (<FILE>) { + my $line = $_; + if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w-]+ kernel:.*IN=.*$/) { + # when standart viewing, just keep in memory the correct slice + # it starts a '$start' and size is $viewport + # If export, then keep all lines... + if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){ + $log[$lines++] = "$line"; + } else { + if ($lines++ < ($start + $Header::viewsize)) { + push(@log,"$line"); + if (@log > $Header::viewsize) { + shift (@log); + } + #} else { dont do this optimisation, need to count lines ! + # $datetime = $maxtime; # we have read viewsize lines, stop main loop + # last READ; # exit read file + } + } + $search_for_end = 1; # we find the start of slice, can look for end now + } else { + if ($search_for_end == 1) { + #finish read files when date is over (test month equality only) + $line =~ /^(...) (..) ..:..:..*$/; + $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) ); + } + } + } + close (FILE); + } + $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped + # for a long time }# while
# $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}) { - print "Content-type: text/plain\n\n"; - print "IPFire firewall log\r\n"; - print "$Lang::{'date'}: $date\r\n\r\n"; - - if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; } - - foreach $_ (@log) - { - /^... (..) (..:..:..) [\w-]+ kernel:.*(IN=.*)$/; - my $day = $1; - $day =~ tr / /0/; - my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ; - print "$time $3\r\n"; - - } - exit 0; + 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; } + + 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 "<font class='base'>$errormessage </font>\n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "<font class='base'>$errormessage </font>\n"; + &Header::closebox(); }
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -240,33 +240,35 @@ print <<END <form method='post' action='$ENV{'SCRIPT_NAME'}'> <table width='100%'> <tr> - <td width='10%' class='base'>$Lang::tr{'month'}: </td> - <td width='10%'> - <select name='MONTH'> + <td width='10%' class='base'>$Lang::tr{'month'}: </td> + <td width='10%'> + <select name='MONTH'> END ; for (my $month = 0; $month < 12; $month++) { - print "\t<option "; - if ($month == $cgiparams{'MONTH'}) { - print "selected='selected' "; } - print "value='$month'>$longmonths[$month]</option>\n"; + print "\t<option "; + if ($month == $cgiparams{'MONTH'}) { + print "selected='selected' "; + } + print "value='$month'>$longmonths[$month]</option>\n"; } print <<END - </select> - </td> - <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> - <td width='40%'> - <select name='DAY'> + </select> + </td> + <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> + <td width='40%'> + <select name='DAY'> END ; print "<option value='0'>$Lang::tr{'all'}</option>\n"; for (my $day = 1; $day <= 31; $day++) { - print "\t<option "; - if ($day == $cgiparams{'DAY'}) { - print "selected='selected' "; } - print "value='$day'>$day</option>\n"; + print "\t<option "; + if ($day == $cgiparams{'DAY'}) { + print "selected='selected' "; + } + print "value='$day'>$day</option>\n"; } print <<END </select> @@ -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 <<END <table width='100%' class='tbl'> <tr> - <th align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'chain'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'iface'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'proto'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'source'}<br/>$Lang::tr{'destination'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'src port'}<br />$Lang::tr{'dst port'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'country'}</b></th> - <th align='center' class='boldbase'><b>$Lang::tr{'mac address'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'chain'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'iface'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'proto'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'source'}<br/>$Lang::tr{'destination'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'src port'}<br />$Lang::tr{'dst port'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'country'}</b></th> + <th align='center' class='boldbase'><b>$Lang::tr{'mac address'}</b></th> </tr> END ; @@ -328,66 +330,76 @@ END $lines = 0; foreach $_ (@log) { - /^... (..) (..:..:..) [\w-]+ kernel:(.*)(IN=.*)$/; - my $day = $1; - $day =~ tr / /0/; - my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ; - my $comment = $3; - my $packet = $4; - - my ($iface, $srcaddr, $dstaddr, $macaddr, $proto, $srcport, $dstport); - $iface=$1 if $packet =~ /IN=(\w+)/; - $srcaddr=$1 if $packet =~ /SRC=([\d.]+)/; - $dstaddr=$1 if $packet =~ /DST=([\d.]+)/; - $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 $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 "<tr>"; - $col="bgcolor='$color{'color20'}'"; } - else { - print "<tr>"; - $col="bgcolor='$color{'color22'}'"; } - print <<END - - <td align='center' $col>$time</td> - <td align='center' $col>$comment</td> - <td align='center' $col>$iface</td> - <td align='center' $col>$proto</td> - <td align='center' $col><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a><br /><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> - <td align='center' $col>$srcport<br/>$dstport</td> + # 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 ($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 $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 "<tr>"; + $col="bgcolor='$color{'color20'}'"; + } + else { + print "<tr>"; + $col="bgcolor='$color{'color22'}'"; + } + print <<END + + <td align='center' $col>$time</td> + <td align='center' $col>$chain</td> + <td align='center' $col>$iface</td> + <td align='center' $col>$proto</td> + <td align='center' $col><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a><br /><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> + <td align='center' $col>$srcport<br/>$dstport</td> END -; + ; # Get flag icon for of the country. my $flag_icon = &GeoIP::get_flag_icon($fcode);
- if ( $flag_icon) { + if ( $flag_icon) { print "<td align='center' $col><a href='../country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode'></a></td>"; } else { print "<td align='center' $col></td>"; }
- print <<END - <td align='center' $col>$macaddr</td> -</tr> + print <<END + <td align='center' $col>$macaddr</td> + </tr> END - ; - $lines++; + ; + $lines++; }
print "</table>"; @@ -402,32 +414,36 @@ print "</table>";
sub oldernewer { -print <<END -<table width='100%'> -<tr> + print <<END + <table width='100%'> + <tr> END -; + ;
-print "<td align='center' width='50%'>"; -if ($prev != -1) { - print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?0,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'first'}</a> "; - print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'older'}</a>"; } -else { - print "$Lang::tr{'first'} $Lang::tr{'older'}"; } -print "</td>\n"; - -print "<td align='center' width='50%'>"; -if ($next >= 0) { - print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a> "; - print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$lastPageIndex,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'last'}</a>"; } -else { - print "$Lang::tr{'newer'} $Lang::tr{'last'} "; } -print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($prev != -1) { + print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?0,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'first'}</a> "; + print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'older'}</a>"; + } + else { + print "$Lang::tr{'first'} $Lang::tr{'older'}"; + } + print "</td>\n";
-print <<END -</tr> -</table> + print "<td align='center' width='50%'>"; + if ($next >= 0) { + print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'newer'}</a> "; + print "<a href='/cgi-bin/logs.cgi/firewalllog.dat?$lastPageIndex,$cgiparams{'MONTH'},$cgiparams{'DAY'}'>$Lang::tr{'last'}</a>"; + } + else { + print "$Lang::tr{'newer'} $Lang::tr{'last'} "; + } + print "</td>\n"; + + print <<END + </tr> + </table> END -; + ; }
diff --git a/html/cgi-bin/logs.cgi/firewalllogcountry.dat b/html/cgi-bin/logs.cgi/firewalllogcountry.dat index f998a62..26920b5 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 (<FILE>) - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while (<FILE>) + { + 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 (<FILE>) { - 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 (<FILE>) { + 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 "<font class='base'>$errormessage </font>\n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "<font class='base'>$errormessage </font>\n"; + &Header::closebox(); }
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,40 +229,39 @@ print <<END <form method='post' action='$ENV{'SCRIPT_NAME'}'> <table width='100%'> <tr> - <td width='10%' class='base'>$Lang::tr{'month'}: </td> - <td width='10%'> - <select name='MONTH'> + <td width='10%' class='base'>$Lang::tr{'month'}: </td> + <td width='10%'> + <select name='MONTH'> END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t<option "; - if ($month == $cgiparams{'MONTH'}) { - print "selected='selected' "; } - print "value='$month'>$longmonths[$month]</option>\n"; + print "\t<option "; + if ($month == $cgiparams{'MONTH'}) { + print "selected='selected' "; } + print "value='$month'>$longmonths[$month]</option>\n"; } print <<END - </select> - </td> - <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> - <td width='40%'> - <select name='DAY'> + </select> + </td> + <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> + <td width='40%'> + <select name='DAY'> END ; for ($day = 1; $day <= 31; $day++) { - print "\t<option "; - if ($day == $cgiparams{'DAY'}) { - print "selected='selected' "; } - print "value='$day'>$day</option>\n"; + print "\t<option "; + if ($day == $cgiparams{'DAY'}) { + print "selected='selected' "; } + print "value='$day'>$day</option>\n"; }
if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} if( $cgiparams{'otherspie'} != 0){$otherspie=$cgiparams{'otherspie'};} if( $cgiparams{'showpie'} != 0){$showpie=$cgiparams{'showpie'};} if( $cgiparams{'sortcolumn'} != 0){$sortcolumn=$cgiparams{'sortcolumn'};} - print <<END </select> </td> @@ -294,29 +294,43 @@ $lines = 0;
foreach $_ (@log) { - /^... (..) (..:..:..) [\w-]+ kernel:(.*)(IN=.*)$/; - my $packet = $4; - $packet =~ /IN=(\w+)/; my $iface=$1; if ( $1 =~ /2./ ){ $iface="";} - $packet =~ /SRC=([\d.]+)/; my $srcaddr=$1; - - if($iface eq $red_interface) { - if($srcaddr ne '') { - 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 { - if($iface ne '') { - $tabjc{$iface} = $tabjc{$iface} + 1 ; - if(($tabjc{$iface} == 1) && ($lines < $pienumber)) { $lines = $lines + 1; } - $linesjc++; - } - } + # 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)? + } + } }
$pienumber = $lines; @@ -336,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; @@ -354,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; @@ -379,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); @@ -400,30 +410,29 @@ 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; - - $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 "<div style='text-align:center;'>"; - print "<img src='/graphs/fwlog-country$imagerandom.png'>"; - print "</div>"; + 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; + + 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 "<div style='text-align:center;'>"; + print "<img src='/graphs/fwlog-country$imagerandom.png'>"; + print "</div>"; } - print <<END <table width='100%' class='tbl'> <tr> @@ -444,73 +453,72 @@ my $col="";
for($s=0;$s<$lines;$s++) { - $show++; - $percent = $value[$s] * 100 / $linesjc; - $percent = sprintf("%.f", $percent); - $total = $total + $value[$s]; - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - $color++; - print "<tr>"; - - print "<td align='center' $col>"; - - # Dont show details button for "unknown" location. - if ($key[$s] ne 'unknown') { - print"<form method='post' action='showrequestfromcountry.dat'>"; - print"<input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'>"; - print"<input type='hidden' name='DAY' value='$cgiparams{'DAY'}'>"; - print"<input type='hidden' name='country' value='$key[$s]'>"; - print"<input type='submit' value='details'></form>"; - } - - if($key[$s] eq 'blue0' || $key[$s] eq 'green0' || $key[$s] eq 'orange0') { - print "<td align='center' $col>$key[$s]</td>"; - } - 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 "<td align='center' $col><a href='/cgi-bin/country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$key[$s]' title='$key[$s]'></a></td>"; - } else { + $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 "<tr>"; + + print "<td align='center' $col>"; + + # Dont show details button for "unknown" location. + if ($key[$s] ne 'unknown') { + print"<form method='post' action='showrequestfromcountry.dat'>"; + print"<input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'>"; + print"<input type='hidden' name='DAY' value='$cgiparams{'DAY'}'>"; + print"<input type='hidden' name='country' value='$key[$s]'>"; + print"<input type='submit' value='details'></form>"; + } + 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 "<td align='center' $col>$key[$s]</td>"; - } - } - print "<td align='center' $col>$value[$s]</td>"; - print "<td align='center' $col>$percent</td>"; - print "</tr>"; + } + 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 "<td align='center' $col><a href='/cgi-bin/country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$key[$s]' title='$key[$s]'></a></td>"; + } else { + print "<td align='center' $col>$key[$s]</td>"; + } + } + print "<td align='center' $col>$value[$s]</td>"; + print "<td align='center' $col>$percent</td>"; + print "</tr>"; }
if($cgiparams{'otherspie'} == 2 ){} else{ - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - print "<tr>"; - -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print <<END -<td align='center' $col></TD> -<td align='center' $col>$Lang::tr{'other countries'}</td> -<td align='center' $col>$dif</TD> -<td align='center' $col>$percent</TD> -</tr> + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{"color$colorIndex"}'"; + print "<tr>"; + + if ( $linesjc ne "0") + { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print <<END + <td align='center' $col></TD> + <td align='center' $col>$Lang::tr{'other countries'}</td> + <td align='center' $col>$dif</TD> + <td align='center' $col>$percent</TD> + </tr> END -; -} + ; + } } print <<END </TABLE> @@ -522,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 7d82d20..08ef1c4 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 (<FILE>) - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while (<FILE>) + { + 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 (<FILE>) { - 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 (<FILE>) { + 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 "<font class='base'>$errormessage </font>\n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "<font class='base'>$errormessage </font>\n"; + &Header::closebox(); }
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,33 +228,35 @@ print <<END <form method='post' action='$ENV{'SCRIPT_NAME'}'> <table width='100%'> <tr> - <td width='10%' class='base'>$Lang::tr{'month'}: </td> - <td width='10%'> - <select name='MONTH'> + <td width='10%' class='base'>$Lang::tr{'month'}: </td> + <td width='10%'> + <select name='MONTH'> END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t<option "; - if ($month == $cgiparams{'MONTH'}) { - print "selected='selected' "; } - print "value='$month'>$longmonths[$month]</option>\n"; + print "\t<option "; + if ($month == $cgiparams{'MONTH'}) { + print "selected='selected' "; + } + print "value='$month'>$longmonths[$month]</option>\n"; } print <<END - </select> - </td> - <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> - <td width='40%'> - <select name='DAY'> + </select> + </td> + <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> + <td width='40%'> + <select name='DAY'> END ; for ($day = 1; $day <= 31; $day++) { - print "\t<option "; - if ($day == $cgiparams{'DAY'}) { - print "selected='selected' "; } - print "value='$day'>$day</option>\n"; + print "\t<option "; + if ($day == $cgiparams{'DAY'}) { + print "selected='selected' "; + } + print "value='$day'>$day</option>\n"; }
if( $cgiparams{'pienumber'} != 0){$pienumber=$cgiparams{'pienumber'};} @@ -291,11 +293,12 @@ if ($pienumber == -1 || $pienumber > $lines || $sortcolumn == 2) { $pienumber = $lines = 0; foreach $_ (@log) { - if($_ =~ /SRC=([\d.]+)/){ - $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; @@ -317,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; @@ -335,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; @@ -358,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); @@ -379,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; - - $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 "<div style='text-align:center'>"; - print "<img src='/graphs/fwlog-ip$imagerandom.png'>"; - print "</div>"; + 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; + + 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 "<div style='text-align:center'>"; + print "<img src='/graphs/fwlog-ip$imagerandom.png'>"; + print "</div>"; }
print <<END @@ -424,64 +427,60 @@ my $col="";
for($s=0;$s<$lines;$s++) { - $show++; - $percent = $value[$s] * 100 / $linesjc; - $percent = sprintf("%.f", $percent); - $total = $total + $value[$s]; - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - print "<tr>"; + $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 "<tr>"; + + 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 "<td align='center' $col><form method='post' action='showrequestfromip.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='ip' value='$key[$s]'> <input type='submit' value='$Lang::tr{'details'}'></form></td>"; - print "<td align='center' $col><a href='/cgi-bin/ipinfo.cgi?ip=$key[$s]'>$key[$s]</a></td>"; - - # Get flag icon for of the country. - my $flag_icon = &GeoIP::get_flag_icon($ccode); - - if ( $flag_icon ) { - print "<td align='center' $col><a href='/cgi-bin/country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode'></a></td>"; - } else { - print "<td align='center' $col></td>"; - } - - print "<td align='center' $col>$value[$s]</td>"; - print "<td align='center' $col>$percent</td>"; - print "</tr>"; - } + $color++; + print "<td align='center' $col><form method='post' action='showrequestfromip.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='ip' value='$key[$s]'> <input type='submit' value='$Lang::tr{'details'}'></form></td>"; + print "<td align='center' $col><a href='/cgi-bin/ipinfo.cgi?ip=$key[$s]'>$key[$s]</a></td>"; + + # Get flag icon for of the country. + my $flag_icon = &GeoIP::get_flag_icon($ccode); + + if ( $flag_icon ) { + print "<td align='center' $col><a href='/cgi-bin/country.cgi#$fcode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode'></a></td>"; + } else { + print "<td align='center' $col></td>"; + } + + print "<td align='center' $col>$value[$s]</td>"; + print "<td align='center' $col>$percent</td>"; + print "</tr>"; +}
if($cgiparams{'otherspie'} == 2 ){} else{ - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - print "<tr>"; - -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print <<END -<td align='center' $col></td> -<td align='center' $col>$Lang::tr{'otherip'}</td> -<td align='center' $col></td> -<td align='center' $col>$dif</td> -<td align='center' $col>$percent</td> -</tr> + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{"color$colorIndex"}'"; + print "<tr>"; + + if ( $linesjc ne "0") + { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print <<END + <td align='center' $col></td> + <td align='center' $col>$Lang::tr{'otherip'}</td> + <td align='center' $col></td> + <td align='center' $col>$dif</td> + <td align='center' $col>$percent</td> + </tr> END -; -} + ; + } } print <<END </table> @@ -493,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 5b0db62..fbc92e4 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 (<FILE>) - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - $log[$lines] = $_; - $lines++; - } - } - close (FILE); + while (<FILE>) + { + 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 (<FILE>) { - 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 (<FILE>) { + 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 "<font class='base'>$errormessage </font>\n"; - &Header::closebox(); + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "<font class='base'>$errormessage </font>\n"; + &Header::closebox(); }
&Header::openbox('100%', 'left', "$Lang::tr{'settings'}"); @@ -228,33 +228,33 @@ print <<END <form method='post' action='$ENV{'SCRIPT_NAME'}'> <table width='100%'> <tr> - <td width='10%' class='base'>$Lang::tr{'month'}: </td> - <td width='10%'> - <select name='MONTH'> + <td width='10%' class='base'>$Lang::tr{'month'}: </td> + <td width='10%'> + <select name='MONTH'> END ; my $month; for ($month = 0; $month < 12; $month++) { - print "\t<option "; - if ($month == $cgiparams{'MONTH'}) { - print "selected='selected' "; } - print "value='$month'>$longmonths[$month]</option>\n"; + print "\t<option "; + if ($month == $cgiparams{'MONTH'}) { + print "selected='selected' "; } + print "value='$month'>$longmonths[$month]</option>\n"; } print <<END - </select> - </td> - <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> - <td width='40%'> - <select name='DAY'> + </select> + </td> + <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td> + <td width='40%'> + <select name='DAY'> END ; for ($day = 1; $day <= 31; $day++) { - print "\t<option "; - if ($day == $cgiparams{'DAY'}) { - print "selected='selected' "; } - print "value='$day'>$day</option>\n"; + print "\t<option "; + if ($day == $cgiparams{'DAY'}) { + print "selected='selected' "; } + print "value='$day'>$day</option>\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; - - $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 "<div style='text-align:center'>"; - print "<img src='/graphs/fwlog-port$imagerandom.png'>"; - print "</div>"; + 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; + + 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 "<div style='text-align:center'>"; + print "<img src='/graphs/fwlog-port$imagerandom.png'>"; + print "</div>"; }
print <<END @@ -425,49 +425,44 @@ my $col="";
for($s=0;$s<$lines;$s++) { - $show++; - $percent = $value[$s] * 100 / $linesjc; - $percent = sprintf("%.f", $percent); - $total = $total + $value[$s]; - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - print "<tr>"; - - $color++; - print "<td align='center' $col><form method='post' action='showrequestfromport.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='port' value='$key[$s]'> <input type='submit' value='$Lang::tr{'details'}'></form></td>"; - print "<td align='center' $col>$key[$s]</td>"; - print "<td align='center' $col>$value[$s]</td>"; - print "<td align='center' $col>$percent</td>"; - print "</tr>"; + $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 "<tr>"; + + $color++; + print "<td align='center' $col><form method='post' action='showrequestfromport.dat'><input type='hidden' name='MONTH' value='$cgiparams{'MONTH'}'> <input type='hidden' name='DAY' value='$cgiparams{'DAY'}'> <input type='hidden' name='port' value='$key[$s]'> <input type='submit' value='$Lang::tr{'details'}'></form></td>"; + print "<td align='center' $col>$key[$s]</td>"; + print "<td align='center' $col>$value[$s]</td>"; + print "<td align='center' $col>$percent</td>"; + print "</tr>"; }
if($cgiparams{'otherspie'} == 2 ){} else{ - my $colorIndex = $color % 10; - if($colorIndex == 0) { - $colorIndex = 10; - } - $col="bgcolor='$color{"color$colorIndex"}'"; - print "<tr>"; - -if ( $linesjc ne "0") -{ -my $dif; -$dif = $linesjc - $total; -$percent = $dif * 100 / $linesjc; -$percent = sprintf("%.f", $percent); -print <<END -<td align='center' $col></td> -<td align='center' $col>$Lang::tr{'otherport'}</td> -<td align='center' $col>$dif</td> -<td align='center' $col>$percent</td> -</tr> + # colors are numbered 1 to 10 + my $colorIndex = ($color % 10) + 1; + $col="bgcolor='$color{"color$colorIndex"}'"; + print "<tr>"; + + if ( $linesjc ne "0") { + my $dif; + $dif = $linesjc - $total; + $percent = $dif * 100 / $linesjc; + $percent = sprintf("%.f", $percent); + print <<END + <td align='center' $col></td> + <td align='center' $col>$Lang::tr{'otherport'}</td> + <td align='center' $col>$dif</td> + <td align='center' $col>$percent</td> + </tr> END -; -} + ; + } } print <<END </table> @@ -479,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 5283c42..cd97f87 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,24 +156,35 @@ my $gi = Geo::IP::PurePerl->new();
if (!$skip) { - while (<FILE>) - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - my $packet = $2; - $packet =~ /IN=(\w+)/; my $iface=$1; if ( $1 =~ /2./ ){ $iface="";} - $packet =~ /SRC=([\d.]+)/; my $srcaddr=$1; - - if($iface eq $country) { - $log[$lines] = $_; - $lines++; - } - elsif($srcaddr ne '') { - my $ccode = $gi->country_code_by_name($srcaddr); - if($ccode eq $country){ - $log[$lines] = $_; - $lines++; - } - } + while (<FILE>) { + # 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++; + } + } } } close (FILE); @@ -181,28 +192,40 @@ 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 (<FILE>) { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /SRC=([\d.]+)/){ - my $srcaddr=$1; - my $ccode = $gi->country_code_by_name($srcaddr); - if($ccode eq $country){ - $log[$lines] = $_; - $lines++; - } - } + # 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++; + } + } } } close (FILE); @@ -235,7 +258,8 @@ for ($month = 0; $month < 12; $month++) { print "\t<option "; if ($month == $cgiparams{'MONTH'}) { - print "selected='selected' "; } + print "selected='selected' "; + } print "value='$month'>$longmonths[$month]</option>\n"; } print <<END @@ -272,7 +296,8 @@ END print "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
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; }
@@ -307,65 +332,80 @@ if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; } $lines = 0; foreach $_ (@slice) { - $a = $_; - /^... (..) (..:..:..) [\w-]+ kernel:(.*)(IN=.*)$/; - my $packet = $4; - $packet =~ /IN=(\w+)/; my $iface=$1; if ( $1 =~ /2./ ){ $iface="";} - $packet =~ /SRC=([\d.]+)/; my $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 $country) { - my $chain = ''; - my $in = '-'; my $out = '-'; - my $srcaddr = ''; my $dstaddr = ''; - my $protostr = ''; - my $srcport = ''; my $dstport = ''; - - $_ =~ /(^.* ..:..:..) [\w-]+ kernel:(.*)(IN=.*)$/; - my $timestamp = $1; my $chain = $2; my $packet = $3; - $timestamp =~ /(...) (..) (..:..:..)/; - my $month = $1; my $day = $2; my $time = $3; - - if ($a =~ /IN=(\w+)/) { $iface = $1; } - if ($a =~ /OUT=(\w+)/) { $out = $1; } - if ($a =~ /SRC=([\d.]+)/) { $srcaddr = $1; } - if ($a =~ /DST=([\d.]+)/) { $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 "<tr bgcolor='${Header::table1colour}'>\n"; } - else { - print "<tr bgcolor='${Header::table2colour}'>\n"; } - print <<END - <td align='center'>$time</td> - <td align='center'>$chain</td> - <td align='center'>$iface</td> - <td align='center'>$protostr</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> - </tr></table> - </td> - <td align='center'>$srcport</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> - </tr></table> - </td> - <td align='center'>$dstport</td> - </tr> + $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 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 ($lines % 2) { + print "<tr bgcolor='${Header::table1colour}'>\n"; + } + else { + print "<tr bgcolor='${Header::table2colour}'>\n"; + } + print <<END + <td align='center'>$time</td> + <td align='center'>$chain</td> + <td align='center'>$iface</td> + <td align='center'>$protostr</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> + </tr></table> + </td> + <td align='center'>$srcport</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> + </tr></table> + </td> + <td align='center'>$dstport</td> + </tr> END - ; - $lines++; - } - } + ; + $lines++; + } + } }
print <<END @@ -383,30 +423,34 @@ END
sub oldernewer { - print <<END - <table width='100%'> - <tr> + print <<END + <table width='100%'> + <tr> END -; + ;
- print "<td align='center' width='50%'>"; - if ($prev != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromcountry.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{country}'>$Lang::tr{'older'}</a>"; } - else { - print "$Lang::tr{'older'}"; } - print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($prev != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromcountry.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{country}'>$Lang::tr{'older'}</a>"; + } + else { + print "$Lang::tr{'older'}"; + } + print "</td>\n";
- print "<td align='center' width='50%'>"; - if ($next != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromcountry.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{country}'>$Lang::tr{'newer'}</a>"; } - else { - print "$Lang::tr{'newer'}"; } - print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($next != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromcountry.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{country}'>$Lang::tr{'newer'}</a>"; + } + else { + print "$Lang::tr{'newer'}"; + }
-print <<END - </tr> - </table> + print "</td>\n"; + print <<END + </tr> + </table> END -; + ; }
diff --git a/html/cgi-bin/logs.cgi/showrequestfromip.dat b/html/cgi-bin/logs.cgi/showrequestfromip.dat index 09a60b5..154fa40 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 (<FILE>) - { + while (<FILE>) { if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /SRC=([\d.]+)/){ - 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 (<FILE>) { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /SRC=([\d.]+)/){ - 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 "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
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,58 +290,64 @@ my @slice = splice(@log, $start, ${Header::viewsize}); if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
$lines = 0; -foreach $_ (@slice) -{ - $a = $_; - if($_ =~ /SRC=([\d.]+)/){ - if($1 eq $ip){ - my $chain = ''; - my $in = '-'; my $out = '-'; - my $srcaddr = ''; my $dstaddr = ''; - my $protostr = ''; - my $srcport = ''; my $dstport = ''; - - $_ =~ /(^.* ..:..:..) [\w-]+ kernel:(.*)(IN=.*)$/; - my $timestamp = $1; my $chain = $2; my $packet = $3; - $timestamp =~ /(...) (..) (..:..:..)/; - my $month = $1; my $day = $2; my $time = $3; - - if ($a =~ /IN=(\w+)/) { $iface = $1; } - if ($a =~ /OUT=(\w+)/) { $out = $1; } - if ($a =~ /SRC=([\d.]+)/) { $srcaddr = $1; } - if ($a =~ /DST=([\d.]+)/) { $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 "<tr bgcolor='${Header::table1colour}'>\n"; } - else { - print "<tr bgcolor='${Header::table2colour}'>\n"; } - print <<END - <td align='center'>$time</td> - <td align='center'>$chain</td> - <td align='center'>$iface</td> - <td align='center'>$protostr</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> - </tr></table> - </td> - <td align='center'>$srcport</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> - </tr></table> - </td> - <td align='center'>$dstport</td> -</tr> +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 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 "<tr bgcolor='${Header::table1colour}'>\n"; + } + else { + print "<tr bgcolor='${Header::table2colour}'>\n"; + } + print <<END + <td align='center'>$time</td> + <td align='center'>$chain</td> + <td align='center'>$iface</td> + <td align='center'>$protostr</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> + </tr></table> + </td> + <td align='center'>$srcport</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> + </tr></table> + </td> + <td align='center'>$dstport</td> + </tr> END - ; - $lines++; - } - } + ; + $lines++; + } + } }
print <<END @@ -359,29 +365,33 @@ END
sub oldernewer { -print <<END -<table width='100%'> -<tr> + print <<END + <table width='100%'> + <tr> END -; + ;
-print "<td align='center' width='50%'>"; -if ($prev != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'older'}</a>"; } -else { - print "$Lang::tr{'older'}"; } -print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($prev != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'older'}</a>"; + } + else { + print "$Lang::tr{'older'}"; + } + print "</td>\n";
-print "<td align='center' width='50%'>"; -if ($next != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'newer'}</a>"; } -else { - print "$Lang::tr{'newer'}"; } -print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($next != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromip.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{ip}'>$Lang::tr{'newer'}</a>"; + } + else { + print "$Lang::tr{'newer'}"; + } + print "</td>\n";
-print <<END -</tr> -</table> + print <<END + </tr> + </table> END -; + ; } diff --git a/html/cgi-bin/logs.cgi/showrequestfromport.dat b/html/cgi-bin/logs.cgi/showrequestfromport.dat index ad9823c..e1f00ae 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 (<FILE>) - { - if (/(^${monthstr} ${daystr} ..:..:..) [\w-]+ kernel:.*(IN=.*)$/) { - if($_ =~ /DPT=([\d.]+)/){ - if($1 eq $port){ - $log[$lines] = $_; - $lines++; - } - } + while (<FILE>) + { + 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 (<FILE>) { - 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 "<p><b>$Lang::tr{'firewall hits'} $longmonthstr $daystr: $lines</b></p>";
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,56 +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 = ''; - - $_ =~ /(^.* ..:..:..) [\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 ($a =~ /IN=(\w+)/) { $iface = $1; } - if ($a =~ /OUT=(\w+)/) { $out = $1; } - if ($a =~ /SRC=([\d.]+)/) { $srcaddr = $1; } - if ($a =~ /DST=([\d.]+)/) { $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 "<tr bgcolor='${Header::table1colour}'>\n"; } - else { - print "<tr bgcolor='${Header::table2colour}'>\n"; } - print <<END - <td align='center'>$time</td> - <td align='center'>$chain</td> - <td align='center'>$iface</td> - <td align='center'>$protostr</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> - </tr></table> - </td> - <td align='center'>$srcport</td> - <td align='center'> - <table width='100%' cellpadding='0' cellspacing='0'><tr> - <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> - </tr></table> - </td> - <td align='center'>$dstport</td> -</tr> + $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 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 "<tr bgcolor='${Header::table1colour}'>\n"; + } + else { + print "<tr bgcolor='${Header::table2colour}'>\n"; + } + print <<END + <td align='center'>$time</td> + <td align='center'>$chain</td> + <td align='center'>$iface</td> + <td align='center'>$protostr</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$srcaddr'>$srcaddr</a></td> + </tr></table> + </td> + <td align='center'>$srcport</td> + <td align='center'> + <table width='100%' cellpadding='0' cellspacing='0'><tr> + <td align='center'><a href='/cgi-bin/ipinfo.cgi?ip=$dstaddr'>$dstaddr</a></td> + </tr></table> + </td> + <td align='center'>$dstport</td> + </tr> END - ; - $lines++; - } - } + ; + $lines++; + } + } }
print <<END @@ -365,30 +375,34 @@ END
sub oldernewer { -print <<END -<table width='100%'> -<tr> + print <<END + <table width='100%'> + <tr> END -; + ;
-print "<td align='center' width='50%'>"; -if ($prev != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromport.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{port}'>$Lang::tr{'older'}</a>"; } -else { - print "$Lang::tr{'older'}"; } -print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($prev != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromport.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{port}'>$Lang::tr{'older'}</a>"; + } + else { + print "$Lang::tr{'older'}"; + } + print "</td>\n";
-print "<td align='center' width='50%'>"; -if ($next != -1) { - print "<a href='/cgi-bin/logs.cgi/showrequestfromport.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{port}'>$Lang::tr{'newer'}</a>"; } -else { - print "$Lang::tr{'newer'}"; } -print "</td>\n"; + print "<td align='center' width='50%'>"; + if ($next != -1) { + print "<a href='/cgi-bin/logs.cgi/showrequestfromport.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{port}'>$Lang::tr{'newer'}</a>"; + } + else { + print "$Lang::tr{'newer'}"; + } + print "</td>\n";
-print <<END -</tr> -</table> + print <<END + </tr> + </table> END -; + ; }
hooks/post-receive -- IPFire 2.x development tree