Location: PHPKode > projects > Php-Logging-System > phplogsys-1.1.4/includes/iptables.php
<?php
//------------------------------------------------------------------------
// See if the MERGEIPTABLESTABLE is configured and available
//------------------------------------------------------------------------
$mergelogtable = FALSE;
if(defined('MERGEIPTABLESTABLE') && MERGEIPTABLESTABLE) {
	if(table_exists(MERGEIPTABLESTABLE, $dbLink)) {
		$mergelogtable = TRUE;
	}
}

// Get list of log tables
$logTableArray = get_logtables($dbLink, DEFAULTIPTABLESTABLE);

//------------------------------------------------------------------------
// Print the top of the form and the table SELECTion if there are multiple
// log tables.
//------------------------------------------------------------------------
$table = get_input('table');
if($table && !validate_input($table, 'table')) {
	echo 'The table has the wrong format.<p>';
	require_once(BASE_PATH . '/html_footer.php');
	exit;
}

?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="GET" name="results" target="_blank">
<table class="pagecontent">
<tr><td><table>
		<tr><td>
<?php
if(count($logTableArray) > 1) { // && !$table) {
	$selected = '';
	if (!$table) {
		$table = DEFAULTIPTABLESTABLE;
		$selected = 'selected';
	}
?>
				<table class="searchform">
				<tr class="lighter">
					<td><b>SELECT TABLE:</b>
						<SELECT name="table" id="table">
<?php
	echo "<OPTION $selected>", DEFAULTIPTABLESTABLE, '</OPTION>';
	if($mergelogtable) {
		echo '<OPTION>', MERGEIPTABLESTABLE, '</OPTION>';
	}
	rsort($logTableArray);
	foreach($logTableArray as $value) {
		if($value != DEFAULTIPTABLESTABLE && $value != MERGEIPTABLESTABLE) {
			echo '<OPTION>', htmlentities($value), '</OPTION>';
		}
	}
?>
						</SELECT>
					</td>
				</tr>
				</table>
<?php
} else {
	if(!$table) {
		$table = DEFAULTIPTABLESTABLE;
	}
	echo '<table class="searchform"><tr class="lighter"><td><b>USING TABLE: ', $table, '</b></td></tr></table>';
	echo '<input type="hidden" name="table" value="', $table, '">';
}

$hostarray = array();
$prefixarray = array();
$protocolarray = array();

// What table to use to fill in the HOST and FACILITY fields?
if($mergelogtable) {
	// $useTable = MERGEIPTABLESTABLE;
	$useTable = USEIPTABLESTABLE;
} elseif($table) {
	$useTable = $table;
} else {
	$useTable = DEFAULTIPTABLESTABLE;
}

//------------------------------------------------------------------------
// Use cache?
//------------------------------------------------------------------------
if(USE_CACHE && table_exists(CACHETABLENAME, $dbLink)) {
	// Get the timestamp for the last update.
	$sql = 'SELECT updatetime FROM ' . CACHETABLENAME . ' LIMIT 1';
	$queryresult = perform_query($sql, $dbLink);
	$row = fetch_array($queryresult);
	$cacheUpdate = $row['updatetime'];

	// Print info about the cache.
	echo '<table class="searchform"><tr class="lighter"><td><b>USING CACHE TO POPULATE HOST AND PREFIX FIELDS.</b><br />Cache last updated on ', $cacheUpdate, '.</td></tr></table>';

	// Get the HOST list
	$sql = 'SELECT DISTINCT value FROM ' . CACHETABLENAME . ' WHERE type=\'IPTABLESHOST\'';
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($hostarray, '<option>' . $line['value'] . '</option>');
	}
	sort($hostarray);

	// Get the PREFIX list
	$sql = 'SELECT DISTINCT value FROM ' . CACHETABLENAME . ' WHERE type=\'IPTABLESPREFIX\'';
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($prefixarray, '<option>' . $line['value'] . '</option>');
	}
	sort($prefixarray);

	// Get the PROTO list
	$sql = 'SELECT DISTINCT value FROM ' . CACHETABLENAME . ' WHERE type=\'IPTABLESPROTO\'';
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($protocolarray, '<option>' . $line['value'] . '</option>');
	}
	sort($protocolarray);

} else {
	//------------------------------------------------------------------------
	// If no cache then get possible values for facility and host from table.
	//------------------------------------------------------------------------
	$sql = 'SELECT DISTINCT host FROM ' . $useTable;
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($hostarray, '<option>' . $line['host'] . '</option>');
	}
	sort($hostarray);

	$sql = 'SELECT DISTINCT prefix FROM ' . $useTable;
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($prefixarray, '<option>' . $line['prefix'] . '</option>');
	}
	sort($prefixarray);

	$sql = 'SELECT DISTINCT proto FROM ' . $useTable;
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($protocolarray, '<option>' . $line['proto'] . '</option>');
	}
	sort($protocolarray);
}

//------------------------------------------------------------------------
// Print the rest of the form.
//------------------------------------------------------------------------
?>
		<table class="searchform">
		<tr class="lighter">
			<td><b>REPORT TITLE:</b> <input type=text name="title" id="title" size="75%" /></td>
		</tr>
		</table>
		<table class="searchform">
		<tr class="lighter">
			<?php echo inputgroup('host', 'Host', $hostarray); ?>
			<?php echo inputgroup('prefix', 'Prefix', $prefixarray); ?>
			<?php echo inputgroup('protocol', 'Protocol', $protocolarray, false, false); ?>
		</tr>
		</table>
		<table class="searchform">
		<tr class="lighter">
			<?php echo ipinputgroup('sourceip', 'Source IP'); ?>
			<?php echo ipinputgroup('destinationip', 'Destination IP'); ?>
			<?php echo portinputgroup('sourceport', 'Source Port'); ?>
			<?php echo portinputgroup('destinationport', 'Destination Port'); ?>
		</tr>
		</table>
		<table class="searchform">
		<tr class="lighter">
			<?php echo dateinputgroup(); ?>
			<td><table align="center" class="formentry">
				<tr><td><b>RECORDS PER PAGE</b></td>
					<td><SELECT name="limit" id="limit">
							<OPTION>10</OPTION><OPTION>25</OPTION><OPTION selected>50</OPTION>
							<OPTION>100</OPTION><OPTION>200</OPTION><OPTION>500</OPTION>
							<OPTION>1000</OPTION>
						</SELECT>
					</td>
				</tr>
<?php if(JPG_GRAPHS == "ON"){ ?>
				<tr><td><b>Graph Port</b></td>
					<td><SELECT name="graphport" id="graphport">
							<OPTION value="0">Source Port</OPTION>
							<OPTION value="1" selected>Destination Port</OPTION>
						</SELECT>
					</td>
				</tr>
				<tr><td><b>TopX</b></td>
					<td><SELECT name="topx" id="topx">
							<OPTION>5</OPTION><OPTION selected>10</OPTION><OPTION>15</OPTION>
							<OPTION>20</OPTION><OPTION>30</OPTION><OPTION>40</OPTION>
						</SELECT>
					</td>
				</tr>
				<tr><td><b>PORT GRAPH Y AXIS SCALE</b></td>
					<td><SELECT name="yscale" id="yscale">
							<OPTION selected>textlin</OPTION><OPTION>textlog</OPTION>
						</SELECT>
					</td>
				</tr>
<?php } ?>
				<tr><td><b>ORDER BY</b></td>
					<td><SELECT name="orderby" id="orderby">
							<OPTION>dpt</OPTION>
							<OPTION>dst</OPTION>
							<OPTION>host</OPTION>
							<OPTION>prefix</OPTION>
							<OPTION>proto</OPTION>
							<OPTION>seq</OPTION>
							<OPTION>spt</OPTION>
							<OPTION>src</OPTION>
							<OPTION selected>timestamp</OPTION>
						</SELECT>
					</td>
				</tr>
				<tr><td><b>SEARCH ORDER</b></td>
					<td><SELECT name="order" id="order">
							<OPTION>ASC</OPTION><OPTION selected>DESC</OPTION>
						</SELECT>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<table class="searchform">
		<tr><td><table class="searchform">
				<tr><td class="darker">
						<input type="submit" name="pageId" value="Search Iptables">
						<input type="submit" name="pageId" value="Iptables Port Graph">
						<input type="reset" value="Reset">
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
	</td>
</tr>
</table>
</form>
<?php
?>
Return current item: Php-Logging-System