Location: PHPKode > projects > Pothos > pothos-0.1.1/filter.php
<?
///////////////////////////////////////////////////////////////////////////////////////
// Pothos - IPTables Firewall Tool
// Copyright (c) 2004, Ken Stanley
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//  - Redistributions of source code must retain the above copyright notice, this list
//    of conditions and the following disclaimer.
//  - Redistributions in binary form must reproduce the above copyright notice, this
//    list of conditions and the following disclaimer in the documentation and/or other
//    materials provided with the distribution.
//  - Neither the name of the Author nor the names of its contributors may be
//    used to endorse or promote products derived from this software without specific
//    prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// Contact author : hide@address.com
///////////////////////////////////////////////////////////////////////////////////////
//error_reporting(0);
require_once('includes/config.inc');
require_once('includes/functions.inc');

include('includes/header.inc');

if ($preferences['mysql']['persist'] == "true") {
	$chandle = mysql_pconnect(
			$preferences['mysql']['host'],
			$preferences['mysql']['user'],
			$preferences['mysql']['pass']);
}
else {
	$chandle = mysql_connect(
			$preferences['mysql']['host'],
			$preferences['mysql']['user'],
			$preferences['mysql']['pass']);
}

if (!$chandle) {
	dberr($preferences['path']);
}
else {
	$mysql_query = "SELECT COUNT(*)";

	if ($_GET['field'] == "oob_time_sec") {
		list($month, $day, $year) = split(" ", date("m d Y", $_GET['val']));
		$day1 = mktime(0,0,0,$month,$day,$year);
		$day2 = $day1 + 86399;
		$mysql_query .= " FROM ulog WHERE ";
		$mysql_query .= $_GET['field'];
		$mysql_query .= " > $day1 AND ";
		$mysql_query .= $_GET['field'];
		$mysql_query .= " < $day2 $sort_by";
	}
	else {
		$mysql_query .= " FROM ulog WHERE " . $_GET['field'] . "='" . $_GET['val'] . "'";
	}

	$qhandle = mysql_db_query($preferences['mysql']['dbase'],$mysql_query,$chandle);

	if (!qhandle) {
		dberr($preferences['path']);
	}
	else {
		$total_records = mysql_result($qhandle, 0);
	}

	if (!empty($_GET['sort_by'])) {
		$sort_by = " ORDER BY " . $_GET['sort_by'];
	}

	$limit = $_GET['limit'];
	if (empty($limit) || $limit < 0) {
		foreach ($preferences['display']['limit'] as $key => $value) {
			if ($value == "true" && $key <> "All") {
				$limit = $key;
			}
		}
	}

	$start = $_GET['start'];
	if (empty($start) || $start < 0) {
		$start = 0;
	}
	if ($limit == "All") {
		$limit_by = "";
	}
	else {
		if ($start < $total_records) {
			$limit_by .= " LIMIT " . $start;
		}
		else {
			$limit_by .= " LIMIT 0";
		}
		$limit_by .= "," . $limit;
	}

	$mysql_query = "SELECT id,";
	foreach ($preferences['fields'] as $key => $var) {
		if ($key == (count($preferences['fields'])-1))
			$mysql_query .= "$var";
		else
			$mysql_query .= "$var,";
	}
	if ($_GET['field'] == "oob_time_sec") {
		list($month, $day, $year) = split(" ", date("m d Y", $_GET['val']));
		$day1 = mktime(0,0,0,$month,$day,$year);
		$day2 = $day1 + 86399;
		$mysql_query .= " FROM ulog WHERE ";
		$mysql_query .= $_GET['field'];
		$mysql_query .= " > $day1 AND ";
		$mysql_query .= $_GET['field'];
		$mysql_query .= " < $day2 $sort_by";
	}
	else {
		$mysql_query .= " FROM ulog WHERE " . $_GET['field'] . "='" . $_GET['val'] . "'" . $sort_by;
	}

	if (!empty($limit_by))
		$mysql_query .= $limit_by;

	$qhandle = mysql_db_query($preferences['mysql']['dbase'], $mysql_query, $chandle);

	if (!$qhandle) {
		dberr($preferences['path']);
	}
	else {
		$record_count = mysql_num_rows($qhandle);
		$qhandle = mysql_db_query($preferences['mysql']['dbase'], $mysql_query, $chandle);

		$results = "<table border=0 cellpadding=0 cellspacing=0 width=100%>\n";
		$results .= " <tr>\n";
		$results .= create_labels($preferences['fields'], "tcp");
		$results .= " </tr>\n";

		while ($record_row = mysql_fetch_array($qhandle, MYSQL_ASSOC)) {
			$results .= " <tr>\n";
			$results .= compile_data($record_row,$preferences);
			$results .= " </tr>\n";
		}

		$results .= "</table>\n";

		include('includes/layout.inc');
	}

	// Since using mysql_close with a persistent connection doesn't do anything, 
	// we just go ahead and call mysql_close regardless of the type of connection
	// we created (it saves a line or two of code).
	mysql_close($chandle);
}
include('includes/footer.inc');
?>
Return current item: Pothos