Location: PHPKode > projects > Cancerbero - The watchdog of the ports > cancerbero-0.6/site/alerts.php
<?php

include_once('include/class_history_links.inc');
include_once("include/dbconnect.php");
include_once("include/functions.php");
include_once("menu.html");
include_once ("include/classListbox.php");

$config = new ReadConfig;
$general = $config->General('gui_debug');
if ($general['gui_debug'] == 1) {
	echo "<div align='center' class='orange'><h2><blink>Debug mode activated</blink></h2></div>\n";
}

$query_description = mysql_query("SHOW COLUMNS FROM alerts LIKE 'alert_checked'") or die (mysql_error());
$descrition = mysql_fetch_assoc($query_description);
if ($descrition['Type'] != "enum('unchecked','checked')") {
	mysql_query("ALTER TABLE alerts MODIFY `alert_checked` ENUM( 'unchecked', 'checked' ) NOT NULL") or die (mysql_error());
	mysql_query("UPDATE `alerts` SET `alert_checked` = 'unchecked'") or die (mysql_error());
} 

$alertid = "";
if (isset($_GET["alertid"])) $alertid = $_GET["alertid"];
$checked = "";
if (isset($_GET["check"])) $check =  $_GET["check"];

If ( $alertid >= 1 ) {
	$result = mysql_query("SELECT alert_checked FROM alerts WHERE alert_id = '$alertid'") or die (mysql_error());
	$status = mysql_result($result,0);
	if ($status == 'unchecked') {
		mysql_query("UPDATE alerts SET alert_checked = 'checked' WHERE alert_id = '$alertid'") or die (mysql_error());
	} elseif ($status == 'checked') {
		mysql_query("UPDATE alerts SET alert_checked = 'unchecked' WHERE alert_id = '$alertid'") or die (mysql_error());
	}
}

echo "<div class='row'>\n
<table class='cancerbero' width = 800>\n
<tbody>
<tr>\n
<th style='text-align:left;'>\n
Alert Filters\n
</th>\n
</tr>\n
<tr>\n
<td>\n
<table class='trans' width = 800>\n
<tbody>
<tr>\n
<form id='form1' name='form1' method='get' action=''>";

	echo "<td>\n";
	echo "<strong>Sensor:</strong> ";
	echo "</td>\n";
	echo "<td>\n";
	$oListBox= new classListBox("sensors");
	$oListBox->set_query("select sensor_name,sensor_id from sensors","sensor_id");
	$oListBox->set_getback(true);
	$oListBox->display();
	echo "</td>\n";
	echo "<td style='text-align:center;'>\n";
	echo "<strong>Filters:</strong>";
	echo "</td>\n";
	echo "<td>\n";
	echo "&nbsp;<strong>(</strong>&nbsp;";
	$oListBox3 = new classListbox("levels");
	$oListBox3->set_query("SELECT alert_level FROM alert_type GROUP BY alert_level","alert_level");
	$oListBox3->set_getback(true);
	$oListBox3->display();
	echo "&nbsp;<strong>OR</strong>&nbsp;";
	$oListBox4 = new classListbox("alerts");
	$oListBox4->set_query("SELECT alert_name FROM alert_type","alert_name");
	$oListBox4->set_getback(true);
	$oListBox4->display();
	echo "&nbsp;<strong>)</strong>&nbsp;";
	echo "&nbsp;<strong>AND</strong>&nbsp;";
	$oListBox5 = new classListbox("status");
	$oListBox5->set_query("SELECT alert_checked FROM alerts GROUP BY alert_checked","alert_checked");
	$oListBox5->set_getback(true);
	$oListBox5->display();
	echo "</td>\n";
	echo "</tr>\n";

	echo "<tr>\n";
	if ( $_GET[$oListBox->LB_name] != 'null' ) {
		echo "<td>\n";
		echo "<strong>Range: </strong>";
		echo "</td>\n";
		echo "<td>\n";
		$oListBox2= new classListBox("ranges");
		$oListBox2->set_query("select range,range_id from ranges where sensor_id='".$oListBox->get_selectedItemKey()."'","range_id");
		$oListBox2->set_getback(true);
		$oListBox2->display();
		echo "</td>\n";
	} else {
		echo "<td>\n";
		echo "&nbsp;";
		echo "</td>\n";
		echo "<td>\n";
		echo "&nbsp;";
		echo "</td>\n";
	}
	echo "<td style='text-align:center;'>\n";
	echo "<strong>Order:</strong>";
	echo "</td>\n";
	echo "<td>\n";
	$field_list = array('ID', 'Date', 'Hostname', 'Ip', 'Alert', 'Message', 'Level', 'Checked');
	$order_by = "";
	if (isset($_GET["order_by"])) $order_by = $_GET["order_by"];
	echo "<select class='input' name='order_by' class='lbStyle' onchange='this.form.submit()'>";
			foreach ($field_list as $field) {
				if ($order_by == $field || $order_by == "") {
					echo "<option class='input' value=".$field." selected>".$field."</option>";
					$order_by = " ORDER BY $field";
				} else {
					echo "<option class='input' value=".$field.">".$field."</option>";
				}
			}
	echo "</select>";
	echo "&nbsp;&nbsp;";
	$way_list = array ('ASC', 'DESC');
	$order_way = "";
	if (isset($_GET["order_way"])) $order_way = $_GET["order_way"];
	echo "<select class='input' name='order_way' class='lbStyle' onchange='this.form.submit()'>";
			foreach ($way_list as $way) {
				if ($order_way == $way || $order_way == "") {
					echo "<option class='input' value=".$way." selected>".$way."</option>";
					$order_way = " $way";
				} else {
					echo "<option class='input' value=".$way.">".$way."</option>";
				}
			}
	echo "</select>";
	echo "</td>";
	echo "</tr>\n";
	echo "</tbody>\n";
	echo "</table>\n";
echo "</p>
</td>\n
</form>\n
</tr>\n
</tbody>\n
</table>\n
&nbsp;
";

$query = "SELECT scan_rec_id, alert_id as ID,FROM_UNIXTIME(d_scan, '%Y-%m-%d / %k:%i ') as Date,hosts.host_id, hostname AS Hostname, ip AS Ip, alerts.alert_name AS Alert, message AS Message, alert_level AS Level, alert_checked AS Checked FROM hosts, scans, alerts, alert_type, ranges WHERE hosts.host_id = scans.host_id AND hosts.range_id = ranges.range_id AND scans.scan_rec_id = alerts.last_scan_id AND alerts.alert_name = alert_type.alert_name";

if ( $_GET[$oListBox->LB_name] != 'null') {
	$query.= " AND ranges.sensor_id = '".$oListBox->get_selectedItemKey()."'";
	if ( isset($_GET[$oListBox2->LB_name]) && $_GET[$oListBox2->LB_name] != 'null'){
			$query.= " AND ranges.range_id = '".$oListBox2->get_selectedItemKey()."'";
	}
}

if ( $_GET[$oListBox3->LB_name] != 'null' ) {
	$query.= " AND (alert_level = '".$oListBox3->get_selectedItemValue()."'";
}

if ( $_GET[$oListBox4->LB_name] != 'null' ) {
	if ( $_GET[$oListBox3->LB_name] != 'null' ) {
		$query.= " OR alert_type.alert_name = '".$oListBox4->get_selectedItemValue()."'";
	} else {
		$query.= " AND (alert_type.alert_name = '".$oListBox4->get_selectedItemValue()."'";
	}
}

if ( $_GET[$oListBox3->LB_name] != 'null' && $_GET[$oListBox4->LB_name] != 'null' ) {
	$query.= ")";
} elseif ( $_GET[$oListBox4->LB_name] != 'null') {
	$query.= ")";
} elseif ( $_GET[$oListBox3->LB_name] != 'null' ) {
	$query.= ")";
}

if ( $_GET[$oListBox5->LB_name] != 'null' ) {
	if ( $_GET[$oListBox3->LB_name] != 'null' || $_GET[$oListBox4->LB_name] != 'null') {
		$query.= " AND alerts.alert_checked = '".$oListBox5->get_selectedItemValue()."'";
	} else {
		$query.= " AND alerts.alert_checked = '".$oListBox5->get_selectedItemValue()."'";
	}
}


$query .= $order_by . $order_way;


#echo "$query<br>";


$title = "<h1>Alerts</h1>";
draw_table ($title,$query,800);

?>
</div>
</body>
</html>
Return current item: Cancerbero - The watchdog of the ports