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

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

//------------------------------------------------------------------------
// 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 = DEFAULTSYSLOGTABLE;
		$selected = 'selected';
	}
?>
				<table class="searchform">
				<tr class="lighter">
					<td><b>SELECT TABLE:</b>
						<SELECT name="table" id="table">
<?php
	echo "<OPTION $selected>", DEFAULTSYSLOGTABLE, '</OPTION>';
	if($mergelogtable) {
		echo '<OPTION>', MERGESYSLOGTABLE, '</OPTION>';
	}
	rsort($logTableArray);
	foreach($logTableArray as $value) {
		if($value != DEFAULTSYSLOGTABLE && $value != MERGESYSLOGTABLE) {
			echo '<OPTION>', htmlentities($value), '</OPTION>';
		}
	}
?>
						</SELECT>
					</td>
				</tr>
				</table>
<?php
} else {
	if(!$table) {
		$table = DEFAULTSYSLOGTABLE;
	}
	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();
$facilityarray = array();
$programarray = array();

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

//------------------------------------------------------------------------
// 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, FACILITY, AND PROGRAM FIELDS.</b><br />Cache last updated on ', $cacheUpdate, '.</td></tr></table>';

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

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

	// Get the PROGRAM list
	$sql = 'SELECT DISTINCT value FROM ' . CACHETABLENAME . ' WHERE type=\'PROGRAM\'';
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($programarray, '<option>' . $line['value'] . '</option>');
	}
	sort($programarray);
} 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 facility FROM ' . $useTable;
	$queryresult = perform_query($sql, $dbLink);
	while ($line = fetch_array($queryresult)) {
		array_push($facilityarray, '<option>' . $line['facility'] . '</option>');
	}
	sort($facilityarray);

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

//------------------------------------------------------------------------
// 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('program', 'Program', $programarray); ?>
			<?php echo inputgroup('facility', 'Syslog Facility', $facilityarray); ?>
			<?php echo inputgroup('priority', 'Syslog Priority', array('<OPTION>debug</OPTION>','<OPTION>info</OPTION>','<OPTION>notice</OPTION>','<OPTION>warning</OPTION>','<OPTION>err</OPTION>','<OPTION>crit</OPTION>','<OPTION>alert</OPTION>','<OPTION>emerg</OPTION>'), false, false); ?>
		</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>TopX</b></td>
					<td><SELECT name="topx" id="topx">
							<OPTION selected>10</OPTION><OPTION>20</OPTION><OPTION>25</OPTION><OPTION>30</OPTION>
							<OPTION>35</OPTION><OPTION>40</OPTION><OPTION>50</OPTION><OPTION>100</OPTION>
						</SELECT>
					</td>
				</tr>
<?php } ?>
				<tr><td><b>ORDER BY</b></td>
					<td><SELECT name="orderby" id="orderby">
							<OPTION>seq</OPTION><OPTION>host</OPTION><OPTION>program</OPTION>
							<OPTION>facility</OPTION><OPTION>priority</OPTION><OPTION selected>datetime</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>
				<tr><td><b>DAILY LOGS BY</b></td>
					<td><SELECT name="dailylogs" id="dailylogs">
							<OPTION>Facility</OPTION><OPTION selected>Priority</OPTION>
						</SELECT>
					</td>
				</tr>
				<tr><td><b>DAILY LOGS Y AXIS SCALE</b></td>
					<td><SELECT name="yscale" id="yscale">
							<OPTION selected>textlin</OPTION><OPTION>textlog</OPTION>
						</SELECT>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
		<table class="searchform">
		<tr class="lighter">
			<?php echo msginputgroup('Search Message'); ?>
		</tr>
		<tr><td><table class="searchform">
				<tr><td class="darker">
						<input type="submit" name="pageId" value="Search Syslog-ng">
						<input type="submit" name="pageId" value="Stats">
						<input type="submit" name="pageId" value="Daily Log Stats">
						<input type="submit" name="pageId" value="Daily Log Graph">
<?php if(JPG_GRAPHS == 'ON'){ ?>
						<input type="submit" name="pageId" value="Graph" onMouseover="return overlib('<TABLE border=1 cellspacing=0 cellpadding=0 width=100%><TR><TD class=tooltip>Please be aware that some graph building searches can take a very long time.<br>Try to make searches as finite as possible (ie, do not try to build a graph for everything, if you do, it will probably just timeout on large databases...)</TD></TR></TABLE>');" onMouseout="nd();" >
<?php } ?>
						<input type="reset" value="Reset">
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
	</td>
</tr>
</table>
</form>
<?php
?>
Return current item: Php-Logging-System