#!/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 DBI;
use CGI;
                                                                                                                                                                                    
                                                                                                                                                                                    
#
# include configuration
#
require "conf.pl";      # General Configuration
require "subs.pl";      # Subroutines
                                                                                                                                                                                    
                                                                                                                                                                                    
#
# Make Database Connection
#
db_connect();

#
# Get CGI Parameters
#
$query = new CGI;
$filter_name = clean_input($query->param("filter_name"));
$log_resource = clean_input($query->param("log_resource"));
$log_action = clean_input($query->param("log_action"));
$log_protocol = clean_input($query->param("log_protocol"));
$log_src_ip = clean_input($query->param("src_ip"));
$log_src_pt = clean_input($query->param("src_pt"));
$log_dst_ip = clean_input($query->param("dst_ip"));
$log_dst_pt = clean_input($query->param("dst_pt"));
$type = clean_input($query->param("type"));
$filter_description = clean_input($query->param("filter_description"));
$date=`date +%Y"-"%m"-"%d" "%H":"%M":"%S`;
$date=~s/\n//g;

if ($log_action eq "any") {
    $log_action="any";
}

if ($log_protocol eq "any") {
    $log_protocol="any";
}
 
if (length($log_resource) < "1") {
    $log_resource="any";
}

if (length($log_src_ip) < "1") {
    $log_src_ip="any";
}

if (length($log_src_pt) < "1") {
    $log_src_pt="any";
}

if (length($log_dst_ip) < "1") {
    $log_dst_ip="any";
}

if (length($log_dst_pt) < "1") {
    $log_dst_pt="any";
}


#$filter_description=~s/'/\\'/g;
#$filter_description=~s/"/\\"/g;
$filter_description=~s/\<url\>(.*)\<\/url\>/\<a href\=\"$1\" class=\"bodylink\"\>$1\<\/a\>/g;


#
# DB Query Parameters
#
 
$addFilter_query=$db_handle->prepare("insert into parse_filter values(\'\', \'active\', \'$date\', \'$date\', \'$log_resource\',\'$log_action\',\'$log_protocol\', \'$log_src_ip\', \'$log_src_pt\', \'$log_dst_ip\',\'$log_dst_pt\',\'$filter_name\',\'$filter_description\')");
$rc=$addFilter_query->execute();

#
# HTML SECTION
#
printtitle();
                                                                                                                                                                                    
               
print <<EOF;
<span class='titlehead'><b>PLA Configuration > Parse Filter Details</b></span>
<br><br>
<span class="main"><font color="green"><b><u>SUCCESS:</u></b> PARSE FILTER HAS BEEN CREATED</font></span>
<br><br>
EOF
$viewFilter = "SELECT parse_id, parse_name, parse_add_time, parse_update_time, log_protocol, log_src_ip, log_src_pt, log_dst_ip, log_dst_pt, log_action, log_resource, parse_description FROM parse_filter where parse_add_time like \"$date\"";
$statement2 = $db_handle->prepare($viewFilter) or die "Couldn't prepare query '$viewFilter': $DBI::errstr\n";
$statement2->execute();
while (($id, $filter_name, $filter_add_time, $filter_update_time, $log_protocol, $log_src_ip, $log_src_pt, $log_dst_ip, $log_dst_pt, $log_action, $log_resource, $filter_description) = $statement2->fetchrow) {
if ($log_src_ip eq "any") {
     $log_src_ip="any";
}
if ($log_src_pt eq "any") {
     $log_src_pt="any";
}
if ($log_dst_pt eq "any") {
     $log_dst_pt="any";
}
if ($log_dst_ip eq "any") {
     $log_dst_ip ="any";
}
if ($log_resource eq "any") {
     $log_resource="any";
}
if ($log_resource ne "any") {
     $log_resource="<img src='images/pix_device.png' align='top'></img> $log_resource";
}
if ($log_action eq "any") {
    $log_action="any";
}
if ($log_action eq "ACCEPT") {
    $log_action="<img src='images/accept.png' align='top'></img> $log_action";
}
if ($log_action eq "DROP") {
    $log_action="<img src='images/drop.png' align='top'></img> $log_action";
}
if ($log_protocol eq "TCP") {
    $log_protocol="<img src='images/tcp_service.png' align='top'></img> $log_protocol";
}
if ($log_protocol eq "UDP") {
    $log_protocol="<img src='images/udp_service.png' align='top'></img> $log_protocol";
}
if ($log_protocol eq "ICMP") {
    $log_protocol="<img src='images/icmp_service.png' align='top'></img> $log_protocol";
}

print <<EOF;
<table width="600" cellpadding="0" cellspacing="0">
<td width="200" height="2" bgcolor="#000000"></td>
<td width="400" height="2" bgcolor="#000000"></td>
<tr>
<td width="200" bgcolor="#d9d9d9"><span class="main"><b>Parse Filter Configuration</b></span></td>
<td width="400" bgcolor="#d9d9d9"><br></td>
<tr>
<td width="200" height="2" bgcolor="#000000"></td>
<td width="400" height="2" bgcolor="#000000"></td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200" bgcolor="#5479d8"><span class="button">General Details<span></td>
<td width="400"><br></td>
<tr>
<td width="200"><span class="main">Filter Name:</td>
<td width="400"><span class="main"><b>$filter_name</b></td>
<tr>
<td width="200"><span class="main">Filter Entry Time:</td>
<td width="400"><span class="main"><i>$filter_add_time</i></td>
<tr>
<td width="200"><span class="main">Filter Update Time:</td>
<td width="400"><span class="main"><i>$filter_update_time</i></td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200" bgcolor="#5479d8"><span class="button">Specific Details<span></td>
<td width="400"><br></td>
<tr>
<td width="200"><span class="main">Source IP/Source Port:</td>
<td width="400"><span class="main">$log_src_ip/$log_src_pt</td>
<tr>
<td width="200"><span class="main">Dest. IP/Dest. Port:</td>
<td width="400"><span class="main">$log_dst_ip/$log_dst_pt</td>
<tr>
<td width="200"><span class="main">Protocol:</td>
<td width="400"><span class="main">$log_protocol</td>
<tr>
<td width="200"><span class="main">Action:</td>
<td width="400"><span class="main">$log_action</td>
<tr>
<td width="200"><span class="main">Logging Resource:</td>
<td width="400"><span class="main">$log_resource</td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200" bgcolor="#5479d8"><span class="button">Description Details<span></td>
<td width="400"><br></td>
<tr>
<td width="200" align="left" valign="top"><span class="main">Filter Description:</td>
<td width="400"><span class="main">$filter_description</td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200" height="2" bgcolor="#000000"></td>
<td width="400" height="2" bgcolor="#000000"></td>
<tr>
<td width="200" bgcolor="#d9d9d9"><span class="main"><b>Parse Filter Options</b></span></td>
<td width="400" bgcolor="#d9d9d9"><br></td>
<tr>
<td width="200" height="2" bgcolor="#000000"></td>
<td width="400" height="2" bgcolor="#000000"></td>
<tr>
<td width="200"><br></td>
<td width="400"><br></td>
<tr>
<td width="200" bgcolor="#5479d8"><span class="button">Available Options<span></td>
<td width="400"><br></td>
<tr>
<td width="200" align="left" valign="top"><a href="pix_config_parse_filter_edit?id=$id&type=traffic&clone=1" class="bodylink">Clone Parse Filter</span></a></td>
<td width="400"><span class="main">Parse Filter can be cloned to create a new/similar parse filter.</td>
<tr>
<td width="200" align="left" valign="top"><a href="pix_config_parse_filter_edit?id=$id&type=traffic" class="bodylink">Edit Parse Filter</span></a></td>
<td width="400"><span class="main">Parse Filter can be edited to modify its parameters.</td>
<tr>
</table>
<br><br>
<b>>></b> <a href="pix_config_parse_filter" class="bodylink">Back to Parse Filter Configuration</a>
<br><br>
EOF
}
$db_handle->disconnect();

