#!/usr/bin/perl
#
# PIX Logging Architecture
# [Kristof Philipsen]
#
# This file is part of PIX Logging Architecture
#
# PIX Logging Architecture is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PIX Logging Architecture is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PIX Logging Architecture; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
use CGI;
use DBI;

#
# include configuration
#
require "conf.pl";      # General Configuration
require "subs.pl";      # Subroutines
                                                                                                                                                                                                  
db_connect();

#
# HTML SECTION
#
printtitle();

$date=`date +%Y"-"%m"-"%d`;
$date=~s/\n//g;

$stat_limit = "5";
$info_limit = "10";

$query = new CGI;
$fw = clean_input($query->param("firewall"));
$id = clean_input($query->param("id"));
$log_id = clean_input($query->param("log_id"));
$var_fld = clean_input($query->param("var_fld"));
$datetime = clean_input($query->param("datetime"));
$fwo = $fw;

if ($fw eq "") {
        $fw="\%";
}

if (!$datetime || $datetime eq "" || $datetime eq "YYYY-MM-DD") {
        $date=`date +%Y"-"%m"-"%d`;
} else {
        $date=$datetime;
}

if ($id eq "srcip") {
 $maxvars="1";
 $tbl_fld="log_src_ip";
 $tblval=$var_fld;
 $legend="Source IP: $var_fld";
 $title="Statistics for Source IP: $var_fld";
}

if ($id eq "dstip") {
 $maxvars="1";
 $tbl_fld="log_dst_ip";
 $tblval=$var_fld;
 $legend="Destination IP: $var_fld";
 $title="Statistics for Destination IP: $var_fld";
}

if ($id eq "srcpt") {
 $maxvars="1";
 $tbl_fld="log_src_pt";
 $tblval=$var_fld;
 $legend="Source Port: $var_fld";
 $title="Statistics for Source Port: $var_fld";
}

if ($id eq "dstpt") {
 $maxvars="1";
 $tbl_fld="log_dst_pt";
 $tblval=$var_fld;
 $legend="Destination Port: $var_fld";
 $title="Statistics for Destination Port: $var_fld";
}

if ($id eq "xsrcip") {
 $maxvars="1";
 $tbl_fld="log_xlate_src_ip";
 $tblval=$var_fld;
 $legend="Translated Source IP: $var_fld";
 $title="Statistics for Translated Source IP: $var_fld";
}

if ($id eq "xdstip") {
 $maxvars="1";
 $tbl_fld="log_xlate_dst_ip";
 $tblval=$var_fld;
 $legend="Translated Destination IP: $var_fld";
 $title="Statistics for Translated Destination IP: $var_fld";
}

if ($id eq "xsrcpt") {
 $maxvars="1";
 $tbl_fld="log_xlate_src_pt";
 $tblval=$var_fld;
 $legend="Translated Source Port: $var_fld";
 $title="Statistics for Translated Source Port: $var_fld";
}

if ($id eq "xdstpt") {
 $maxvars="1";
 $tbl_fld="log_xlate_dst_pt";
 $tblval=$var_fld;
 $legend="Translated Destination Port: $var_fld";
 $title="Statistics for Translated Destination Port: $var_fld";
}




print <<EOF;
<script language="JavaScript">
<!-- Original script borrowed from http://web.uvic.ca/atrsweb/vikes/default.html -->
<!-- Implemented at Kwantlen 26 June 2000 DMH -->
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<span class="titlehead"><b>PIX Logging Architecture > Security Dashboard</b></span>
<br><br>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#000000" width="200">&nbsp;&nbsp; <b><span class="main"><font color="white">PLA Statistics: $date</font></span></b></td>
<form action="pla_main" method="post" align="right" valign="top">
<td bgcolor="#fffffff" align="right"><a href="pix_traffic_id?id=$log_id" class="bodylink"><< Back to PIX Traffic Log Details</a> &nbsp; <font color="#000000">|</font> &nbsp; <a href="javascript:window.location.reload()" class="bodylink">Refresh <img src="images/reload.gif" align="bottom" border="0"></img></a>&nbsp;&nbsp;
<select name="firewall" style="background-color: #5479d8; color: #ffffff;" onChange="MM_jumpMenu('parent',this,0)">
<option value="?firewall=&id=$id&log_id=$log_id&var_fld=$var_fld&datetime=$datetime" selected>-customize view-
<option value="?firewall=&id=$id&log_id=$log_id&var_fld=$var_fld&datetime=$datetime">-
<option value="?firewall=&id=$id&log_id=$log_id&var_fld=$var_fld&datetime=$datetime">Global Statistics 
<option value="?firewall=&id=$id&log_id=$log_id&var_fld=$var_fld&datetime=$datetime">-
EOF
$getAllResources="SELECT high_priority distinct log_resource from traffic_log group by log_resource";
$AllResources = $db_handle->prepare($getAllResources) or die "Couldn't prepare query '$getAllResources': $DBI::errstr\n";
$AllResources->execute();
while ($log_resource = $AllResources->fetchrow) {
print <<EOF;
<option value="?firewall=$log_resource&id=$id&log_id=$log_id&var_fld=$var_fld&datetime=$datetime"> $log_resource
EOF
}
print <<EOF;
</td>
</select>
</form>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#5479d8" height="6"></td>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#d9d9d9" align="right"><span class="main"><b>Security Dashboard</b> > $title Drilldown</span></td>
</table>
<br>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td align="left"><li type="square"><span class="main">Last 24 Hours $title</span></li></td>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#5479d8" height="2"></td>
</table>
<br>
<img src="stats/pla-grapher?interval=hours&num=24&firewall=$fwo&maxvars=$maxvars&tblfld=$tbl_fld&tblval=$tblval&legend=$legend&datetime=$date&compare=1" alt="Accepts & Drops"></img>
<br><br>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td align="left"><li type="square"><span class="main">Last 7 Days $title</span></li></td>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#5479d8" height="2"></td>
</table>
<br>
<img src="stats/pla-grapher?interval=days&num=7&date_shift=0&firewall=$fwo&maxvars=$maxvars&tblfld=$tbl_fld&tblval=$tblval&legend=$legend&datetime=$date&compare=1" alt="Day of the Week"></img>
<br><br>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td align="left"><li type="square"><span class="main">Last 30 Days $title</span></li></td>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#5479d8" height="2"></td>
</table>
<br>
<img src="stats/pla-grapher?interval=days&num=30&date_shift=0&firewall=$fwo&maxvars=$maxvars&tblfld=$tbl_fld&tblval=$tblval&legend=$legend&datetime=$date&compare=1"></img>
<br><br>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td align="left"><li type="square"><span class="main">Last 12 Months $title</span></li></td>
</table>
<table width="100%" bgcolor="white" cellpadding="0" cellspacing="0" border="0">
<td bgcolor="#5479d8" height="2"></td>
</table>
<br>
<img src="stats/pla-grapher?interval=months&num=12&date_shift=1&firewall=$fwo&maxvars=$maxvars&tblfld=$tbl_fld&tblval=$tblval&legend=$legend&datetime=$date&compare=1"></img>
<br><br>
</td></table>
EOF

