diff --git a/html/pages/iftype.inc.php b/html/pages/iftype.inc.php
index b4357f19f..131104c20 100644
--- a/html/pages/iftype.inc.php
+++ b/html/pages/iftype.inc.php
@@ -7,16 +7,16 @@ if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; }
$type_where = " (";
foreach (explode(",", $_GET['opta']) as $type)
{
- $type_where .= " $or `port_descr_type` = '" . mres($type) . "' ";
+ $type_where .= " $or `port_descr_type` = ?";
$or = "OR";
+ $type_param[] = $type;
}
$type_where .= ") ";
+$ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param);
-$sql = "SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias";
-$query = mysql_query($sql);
-while ($interface = mysql_fetch_assoc($query))
+foreach ($ports as $interface)
{
$if_list .= $seperator . $interface['interface_id'];
$seperator = ",";
@@ -38,9 +38,7 @@ if ($if_list)
include("includes/print-interface-graphs.inc.php");
echo("");
- $sql = "select * from ports as I, devices as D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias";
- $query = mysql_query($sql);
- while ($interface = mysql_fetch_assoc($query))
+ foreach ($ports as $interface)
{
$done = "yes";
unset($class);
@@ -75,4 +73,4 @@ else
}
?>
-
\ No newline at end of file
+
diff --git a/html/pages/inventory.inc.php b/html/pages/inventory.inc.php
index 1d9da901d..af2c26e31 100644
--- a/html/pages/inventory.inc.php
+++ b/html/pages/inventory.inc.php
@@ -10,8 +10,7 @@
-
+
= '5')
{
- $sql = "SELECT * from entPhysical AS E, devices AS D WHERE E.device_id = D.device_id $where ORDER BY D.hostname";
+ $sql = "SELECT * from entPhysical AS E, devices AS D WHERE D.device_id = E.device_id";
} else {
- $sql = "SELECT * from entPhysical AS E, devices AS D, devices_perms AS P
- WHERE E.device_id = D.device_id AND D.device_id = P.device_id $where ORDER BY D.hostname";
+ $sql = "SELECT * from entPhysical AS E, devices AS D, devices_perms AS P WHERE D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?";
+ $param[] = $_SESSION['user_id'];
}
-$query = mysql_query($sql);
-echo("
\ No newline at end of file
+
diff --git a/html/pages/list.inc.php b/html/pages/list.inc.php
deleted file mode 100644
index d61079d58..000000000
--- a/html/pages/list.inc.php
+++ /dev/null
@@ -1,28 +0,0 @@
-");
-
-echo("
-
-
Hostname - Description
-
Operating System - Version
-
Hardware - Features
-
Uptime - Location
-
-
");
-
-while ($device = mysql_fetch_assoc($device_query))
-{
- include("includes/hostbox.inc.php");
-}
-
-echo("");
-
-?>
\ No newline at end of file
diff --git a/html/pages/locations.inc.php b/html/pages/locations.inc.php
index 1c2355342..4bc61e0fa 100644
--- a/html/pages/locations.inc.php
+++ b/html/pages/locations.inc.php
@@ -7,17 +7,17 @@ foreach (getlocations() as $location)
if ($_SESSION['userlevel'] == '10')
{
- $num = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "'");
- $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'network'");
- $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'server'");
- $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND type = 'firewall'");
- $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = '" . $location . "' AND status = '0'");
+ $num = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ?", array($location));
+ $net = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'network'", array($location));
+ $srv = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'server'", array($location));
+ $fwl = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND type = 'firewall'", array($location));
+ $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices WHERE location = ? AND status = '0'", array($location));
} else {
- $num = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "'");
- $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND D.type = 'network'");
- $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND type = 'server'");
- $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND location = '" . $location . "' AND type = 'firewall'");
- $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE location = '" . $location . "' AND status = '0'");
+ $num = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ?", array($_SESSION['user_id'], $location));
+ $net = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND D.type = 'network'", array($_SESSION['user_id'], $location));
+ $srv = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'server'", array($_SESSION['user_id'], $location));
+ $fwl = dbFetchCell("SELECT COUNT(D.device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND type = 'firewall'", array($_SESSION['user_id'], $location));
+ $hostalerts = dbFetchCell("SELECT COUNT(device_id) FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ? AND location = ? AND status = '0'", array($_SESSION['user_id'], $location));
}
if ($hostalerts) { $alert = ''; } else { $alert = ""; }
diff --git a/html/pages/preferences.inc.php b/html/pages/preferences.inc.php
index 99bdbd371..2c22549c0 100644
--- a/html/pages/preferences.inc.php
+++ b/html/pages/preferences.inc.php
@@ -52,9 +52,8 @@ if ($_SESSION['userlevel'] == '10') { echo("Global Administ
if ($_SESSION['userlevel'] == '5') { echo("Global Viewing Access"); }
if ($_SESSION['userlevel'] == '1')
{
- $perms = mysql_query("SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = '" . $user_id . "' AND P.device_id = D.device_id");
- while ($perm = mysql_fetch_assoc($perms))
+ foreach (dbFetchRows("SELECT * FROM `devices_perms` AS P, `devices` AS D WHERE `user_id` = ? AND P.device_id = D.device_id", array($user_id)) as $perm)
{
echo("" . $perm['hostname'] . " ");
$dev_access = 1;
@@ -67,4 +66,4 @@ echo("");
echo("");
echo("");
-?>
\ No newline at end of file
+?>
diff --git a/html/pages/services.inc.php b/html/pages/services.inc.php
index 2449263ef..58f9701e8 100644
--- a/html/pages/services.inc.php
+++ b/html/pages/services.inc.php
@@ -35,16 +35,16 @@ echo("
= '5')
{
$host_sql = "SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id GROUP BY D.hostname ORDER BY D.hostname";
+ $host_par = array();
} else {
- $host_sql = "SELECT * FROM devices AS D, services AS S, devices_perms AS P WHERE D.device_id = S.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' $where GROUP BY D.hostname ORDER BY D.hostname";
+ $host_sql = "SELECT * FROM devices AS D, services AS S, devices_perms AS P WHERE D.device_id = S.device_id AND D.device_id = P.device_id AND P.user_id = ? GROUP BY D.hostname ORDER BY D.hostname";
+ $host_par = array($_SESSION['user_id']);
}
- $host_query = mysql_query($host_sql);
- while ($host_data = mysql_fetch_assoc($host_query))
+ foreach (dbFetchRows($host_sql, $host_par) as $host_data)
{
$device_id = $host_data['device_id'];
$device_hostname = $host_data['hostname'];
- $service_query = mysql_query("SELECT * FROM `services` WHERE `device_id` = '" . $host_data['device_id'] . "' $where");
- while ($service = mysql_fetch_assoc($service_query))
+ foreach (dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?", array($host_data['device_id'])) as $service)
{
include("includes/print-service.inc.php");
# $samehost = 1;
diff --git a/includes/syslog.php b/includes/syslog.php
index c1b4c2b5e..3cc008216 100755
--- a/includes/syslog.php
+++ b/includes/syslog.php
@@ -1,5 +1,12 @@
+# reboot
+# log
+# help
+# down
+
message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);
+
+echo "VERSION\t\t". $config['version'] . "\n";
+
+mysql_close();
+
+ }
+
+###
+# Get status on !down devices
+###
+ function down_info(&$irc, &$data)
+ {
+
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ $query = mysql_query("SELECT * FROM `devices` where status=0");
+ unset($message);
+ while($device = mysql_fetch_assoc($query))
+ {
+ $message .= $sep . $device['hostname'];
+ $sep = ", ";
+ }
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
+ unset($sep);
+
+mysql_close();
+
+echo "DOWN\n";
+
+ }
+
+###
+# Get status on !device
+###
function device_info(&$irc, &$data)
{
+
$hostname = $data->messageex[1];
- $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($hostname));
+
+mysql_close();
if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; }
if ($device['ignore']) { $status = "*Ignored*"; }
@@ -22,15 +94,28 @@ class observiumbot
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
$device['features'] . " " . $status);
+
+echo "DEVICE\t\t". $device['hostname']."\n";
+
}
+
+###
+# Get status on !port
+###
function port_info(&$irc, &$data)
{
$hostname = $data->messageex[1];
$ifname = $data->messageex[2];
- $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
- $port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".mres($ifname)."' OR `ifDescr` = '".mres($ifname)."' AND device_id = '".$device['device_id']."'"));
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($device));
+ $port = dbFetchRow("SELECT * FROM `ports` WHERE `ifName` = ? OR `ifDescr` = ? AND device_id = ?", array($ifname, $ifname, $device['device_id']));
+
+mysql_close();
$bps_in = formatRates($port['ifInOctets_rate']);
$bps_out = formatRates($port['ifOutOctets_rate']);
@@ -39,19 +124,36 @@ class observiumbot
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");
+
+echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";
+
}
+
+###
+# !listdevices lists all devices
+###
function list_devices(&$irc, &$data)
{
- $query = mysql_query("SELECT * FROM `devices`");
- unset($message);
- while($device = mysql_fetch_assoc($query))
+ unset ($message);
+
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ foreach (dbFetchRows("SELECT `hostname` FROM `devices`") as $device)
{
$message .= $sep . $device['hostname'];
$sep = ", ";
}
+
+mysql_close();
+
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
unset($sep);
+
+echo "LISTDEVICES\n";
+
}
}
@@ -62,6 +164,8 @@ $irc->setUseSockets(TRUE);
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!listdevices', $bot, 'list_devices');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');
$irc->connect($config['irc_host'], $config['irc_port']);
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);