#!/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;
$id = clean_input($query->param("id"));
$remove_description = clean_input($query->param("remove_description"));
$searchtype = clean_input($query->param("search_type"));
$searchstring = clean_input($query->param("search_string"));
$showoptions = clean_input($query->param("showoptions"));


if ($searchtype eq "description_id" && $searchstring eq "") {
    $searchstring="\%";
}

if (length($searchtype) < 1) {
   $search_sql = "";
} else {
   $search_sql = "WHERE $searchtype like \"$searchstring\"";
}

$datetime = $query->param("date");
($date,$time) = split(" ",$datetime);
if ($remove_description eq "true") {
    $removeDescriptionAll=$db_handle->prepare("delete from traffic_description where description_id=\"$id\"");
    $removeDescriptionAll->execute();
}

if (length($showoptions) < 1) {
    $showoptions="0";
}


                                                                                                                                                                                                  
#
# HTML SECTION
#
printtitle();
                                                                                                                                                                                                  
print <<EOF;
<span class='titlehead'><b>PLA Configuration > Traffic Logs > Description</b></span>
<br><br>
EOF

if ($showoptions eq "0") {
print <<EOF;
<span class="main">
<a href="$pix_config_traffic_description?showoptions=1"><img src="images/pla_plus.gif" align="top"></a> <img src="images/config_description.gif" align="top" valign="top"></img> <b>Description Options</b> <i><font color="red">(Expand to create new description)</font></i><br><br>
EOF
}






if ($showoptions eq "1") {

print <<EOF;
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<td align="left" valign="top">
<span class="main">
<a href="$pix_config_traffic_description?showoptions=0"><img src="images/pla_minus.gif" align="top"></a> <img src="images/config_description.gif" align="top" valign="top"></img> <b>Description Options</b>

</td>
<tr>
<td height="2" bgcolor="#000000"></td>
<td height="2" bgcolor="#000000"></td>
<td height="2" bgcolor="#000000"></td>
<tr>
<td height="2" bgcolor="#ffffff"></td>
<td height="2" bgcolor="#ffffff"></td>
<td height="2" bgcolor="#ffffff"></td>
<tr>
<td align="left" valign="top">
<span class="main">
<img src="images/pla_blank.gif" align="top"> <a href="pix_config_description_create" class="bodylink"><img src="images/pla_create.gif" border="0" alt="Create Traffic Description"></img></a>
</td>

<td align="middle" valign="top">
<span class="main">
<form action="pix_config_traffic_description" name="" method="post">
<input type="hidden" name="showoptions" value="1">
Search Descriptions:

<select name="search_type">
<option selected value="description_id">id
<option value="description_name">description name
<option value="description_detail">description detail
<option value="traffic_type">traffic priority
<option value="log_src_ip">source IP
<option value="log_src_pt">source port
<option value="log_dst_ip">destination IP
<option value="log_dst_pt">destination port
<option value="log_protocol">protocol
<option value="log_action">action
<option value="log_resource">logging resource
</select>
 =
<input type="text" name="search_string"></input>
<input type="image" value="submit" src="images/pla_search_small.gif" align="top" border="0">
</form>

</td>

<td align="right" valign="top" width="25%">
<br>
</td>
<tr>
<td height="2" bgcolor="#ffffff"></td>
<td height="2" bgcolor="#ffffff"></td>
<td height="2" bgcolor="#ffffff"></td>
<tr>
<td height="2" bgcolor="#000000"></td>
<td height="2" bgcolor="#000000"></td>
<td height="2" bgcolor="#000000"></td>
</table>
<br>
EOF

}


print <<EOF;
<span class="main">
EOF
$getAllEvents = "SELECT description_id, traffic_type, description_entry_time, description_name, log_resource, log_protocol FROM traffic_description $search_sql order by description_name";
$statement2 = $db_handle->prepare($getAllEvents) or die "Couldn't prepare query '$getAllEvents': $DBI::errstr\n";
$statement2->execute();
print <<EOF;
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<td width="300" bgcolor="#5479d8"><span class="button">Description Name</td>
<td width="70" bgcolor="#5479d8"><span class="button">Traffic Type/Priority</td>
<td width="50" bgcolor="#5479d8"><span class="button">Logging Resource</td>
<td width="110" bgcolor="#5479d8"><span class="button">Entry Time</td>
<td width="40" bgcolor="#5479d8"><span class="button">Protocol</td>
<td width="140" bgcolor="#5479d8"><span class="button">Options</td>
EOF
while (($description_id, $traffic_type, $description_entry_time, $description_name, $log_resource, $log_protocol) = $statement2->fetchrow) {
if ($log_resource eq "\%") {
    $log_resource="any";
}
#$traffic_type="<font color='green'><b>Normal/Low</b></font>" if $traffic_type eq "Normal/Low";
#$traffic_type="<font color='#DAA520'><b>Normal/Medium</b></font>" if $traffic_type eq "Normal/Medium";
#$traffic_type="<font color='blue'><b>Normal/High</b></font>" if $traffic_type eq "Normal/High";
#$traffic_type="<font color='green'><b>Normal/Low</b></font>" if $traffic_type eq "Normal/Low";
#$traffic_type="<font color='green'><b>Normal/Low</b></font>" if $traffic_type eq "Normal/Low";
#$traffic_type="<font color='green'><b>Normal/Low</b></font>" if $traffic_type eq "Normal/Low";

print <<EOF;
<tr OnMouseOver="this.bgColor='#d9d9d9'" OnMouseOut="this.bgColor='#ffffff'">
<td width="300"><a href="pix_config_description_view?id=$description_id" class="bodylink">$description_name</a></td>
<td width="70"><span class="main">$traffic_type</td>
<td width="50"><span class="main">$log_resource</td>
<td width="110"><span class="main">$description_entry_time</td>
<td width="40"><span class="main">&nbsp;&nbsp;$log_protocol</td>
<td width="140"><a href="pix_config_description_edit?id=$description_id&type=traffic&clone=1" class="bodylink">[ clone ]</span></a> <a href="pix_config_description_edit?id=$description_id&type=traffic" class="bodylink">[ edit ]</span></a> <a href="pix_config_traffic_description?remove_description=true&id=$description_id" class="bodylink">[ remove ]</span</a></td>
<tr>
EOF
}

print <<EOF;
</table>
EOF
$db_handle->disconnect();

