mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 00:25:06 +02:00
Fix coding style part 2
This commit is contained in:
@@ -2,56 +2,64 @@
|
||||
|
||||
$param = array();
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$perms_sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
$param[] = array($_SESSION['user_id']);
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$perms_sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = array($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
list($address,$prefix) = explode("/", $_POST['address']);
|
||||
list($address,$prefix) = explode('/', $_POST['address']);
|
||||
if ($_POST['search_type'] == 'ipv4') {
|
||||
$sql = " FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D";
|
||||
$sql = ' FROM `ipv4_addresses` AS A, `ports` AS I, `ipv4_networks` AS N, `devices` AS D';
|
||||
$sql .= $perms_sql;
|
||||
$sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv4_network_id = A.ipv4_network_id $where ";
|
||||
if (!empty($address)) {
|
||||
$sql .= " AND ipv4_address LIKE '%".$address."%'";
|
||||
}
|
||||
|
||||
if (!empty($prefix)) {
|
||||
$sql .= " AND ipv4_prefixlen='?'";
|
||||
$sql .= " AND ipv4_prefixlen='?'";
|
||||
$param[] = array($prefix);
|
||||
}
|
||||
} elseif ($_POST['search_type'] == 'ipv6') {
|
||||
$sql = " FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D";
|
||||
}
|
||||
else if ($_POST['search_type'] == 'ipv6') {
|
||||
$sql = ' FROM `ipv6_addresses` AS A, `ports` AS I, `ipv6_networks` AS N, `devices` AS D';
|
||||
$sql .= $perms_sql;
|
||||
$sql .= " WHERE I.port_id = A.port_id AND I.device_id = D.device_id AND N.ipv6_network_id = A.ipv6_network_id $where ";
|
||||
if (!empty($address)) {
|
||||
$sql .= " AND (ipv6_address LIKE '%".$address."%' OR ipv6_compressed LIKE '%".$address."%')";
|
||||
}
|
||||
|
||||
if (!empty($prefix)) {
|
||||
$sql .= " AND ipv6_prefixlen = '$prefix'";
|
||||
}
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
$sql = " FROM `ports` AS I, `devices` AS D";
|
||||
$sql .= $perms_sql;
|
||||
$sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%' $where ";
|
||||
}
|
||||
else if ($_POST['search_type'] == 'mac') {
|
||||
$sql = ' FROM `ports` AS I, `devices` AS D';
|
||||
$sql .= $perms_sql;
|
||||
$sql .= " WHERE I.device_id = D.device_id AND `ifPhysAddress` LIKE '%".str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address']))."%' $where ";
|
||||
}//end if
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= " AND I.device_id = ?";
|
||||
$sql .= ' AND I.device_id = ?';
|
||||
$param[] = array($_POST['device_id']);
|
||||
}
|
||||
|
||||
if ($_POST['interface']) {
|
||||
$sql .= " AND I.ifDescr LIKE '?'";
|
||||
$sql .= " AND I.ifDescr LIKE '?'";
|
||||
$param[] = array($_POST['interface']);
|
||||
}
|
||||
|
||||
if ($_POST['search_type'] == 'ipv4') {
|
||||
$count_sql = "SELECT COUNT(`ipv4_address_id`) $sql";
|
||||
} elseif ($_POST['search_type'] == 'ipv6') {
|
||||
$count_sql = "SELECT COUNT(`ipv6_address_id`) $sql";
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
$count_sql = "SELECT COUNT(`port_id`) $sql";
|
||||
}
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
else if ($_POST['search_type'] == 'ipv6') {
|
||||
$count_sql = "SELECT COUNT(`ipv6_address_id`) $sql";
|
||||
}
|
||||
else if ($_POST['search_type'] == 'mac') {
|
||||
$count_sql = "SELECT COUNT(`port_id`) $sql";
|
||||
}
|
||||
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -63,7 +71,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -75,31 +83,42 @@ $sql = "SELECT *,`I`.`ifDescr` AS `interface` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $interface) {
|
||||
$speed = humanspeed($interface['ifSpeed']);
|
||||
$type = humanmedia($interface['ifType']);
|
||||
$type = humanmedia($interface['ifType']);
|
||||
|
||||
if ($_POST['search_type'] == 'ipv6') {
|
||||
list($prefix, $length) = explode("/", $interface['ipv6_network']);
|
||||
$address = Net_IPv6::compress($interface['ipv6_address']) . '/'.$length;
|
||||
} elseif ($_POST['search_type'] == 'mac') {
|
||||
list($prefix, $length) = explode('/', $interface['ipv6_network']);
|
||||
$address = Net_IPv6::compress($interface['ipv6_address']).'/'.$length;
|
||||
}
|
||||
else if ($_POST['search_type'] == 'mac') {
|
||||
$address = formatMac($interface['ifPhysAddress']);
|
||||
} else {
|
||||
list($prefix, $length) = explode("/", $interface['ipv4_network']);
|
||||
$address = $interface['ipv4_address'] . '/' .$length;
|
||||
}
|
||||
else {
|
||||
list($prefix, $length) = explode('/', $interface['ipv4_network']);
|
||||
$address = $interface['ipv4_address'].'/'.$length;
|
||||
}
|
||||
|
||||
if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
|
||||
$error_img = generate_port_link($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
|
||||
} else {
|
||||
$error_img = "";
|
||||
$error_img = generate_port_link($interface, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", errors);
|
||||
}
|
||||
if (port_permitted($interface['port_id'])) {
|
||||
$interface = ifLabel ($interface, $interface);
|
||||
$response[] = array('hostname'=>generate_device_link($interface),
|
||||
'interface'=>generate_port_link($interface) . ' ' . $error_img,
|
||||
'address'=>$address,
|
||||
'description'=>$interface['ifAlias']);
|
||||
else {
|
||||
$error_img = '';
|
||||
}
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
if (port_permitted($interface['port_id'])) {
|
||||
$interface = ifLabel($interface, $interface);
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($interface),
|
||||
'interface' => generate_port_link($interface).' '.$error_img,
|
||||
'address' => $address,
|
||||
'description' => $interface['ifAlias'],
|
||||
);
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -16,8 +16,9 @@ $where = 1;
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM `alert_schedule` AS S WHERE $where";
|
||||
} else {
|
||||
$sql = " FROM `alert_schedule` AS S WHERE $where";
|
||||
}
|
||||
else {
|
||||
$sql = " FROM `alert_schedule` AS S WHERE $where";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
@@ -26,7 +27,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -38,7 +39,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -48,20 +49,29 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT `S`.`schedule_id`, DATE_FORMAT(`S`.`start`, '".$config['dateformat']['mysql']['compact']."') AS `start`, DATE_FORMAT(`S`.`end`, '".$config['dateformat']['mysql']['compact']."') AS `end`, `S`.`title` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql,$param) as $schedule) {
|
||||
foreach (dbFetchRows($sql, $param) as $schedule) {
|
||||
$status = 0;
|
||||
if ($schedule['end'] < date('dS M Y H:i::s')) {
|
||||
$status = 1;
|
||||
}
|
||||
|
||||
if (date('dS M Y H:i::s') >= $schedule['start'] && date('dS M Y H:i::s') < $schedule['end']) {
|
||||
$status = 2;
|
||||
}
|
||||
$response[] = array('title'=>$schedule['title'],
|
||||
'start'=>$schedule['start'],
|
||||
'end'=>$schedule['end'],
|
||||
'id'=>$schedule['schedule_id'],
|
||||
'status'=>$status);
|
||||
|
||||
$response[] = array(
|
||||
'title' => $schedule['title'],
|
||||
'start' => $schedule['start'],
|
||||
'end' => $schedule['end'],
|
||||
'id' => $schedule['schedule_id'],
|
||||
'status' => $status,
|
||||
);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
$where = 1;
|
||||
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$where .= ' AND E.device_id = ?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id WHERE $where";
|
||||
} else {
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
|
||||
}
|
||||
else {
|
||||
$sql = " FROM `alert_log` AS E LEFT JOIN devices AS D ON E.device_id=D.device_id RIGHT JOIN alert_rules AS R ON E.rule_id=R.id RIGHT JOIN devices_perms AS P ON E.device_id = P.device_id WHERE $where AND P.user_id = ?";
|
||||
$param[] = array($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`E`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -31,7 +32,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -42,42 +43,49 @@ if ($rowCount != -1) {
|
||||
$sql = "SELECT D.device_id,name AS alert,state,time_logged,DATE_FORMAT(time_logged, '".$config['dateformat']['mysql']['compact']."') as humandate,details $sql";
|
||||
|
||||
$rulei = 0;
|
||||
foreach (dbFetchRows($sql,$param) as $alertlog) {
|
||||
$dev = device_by_id_cache($alertlog['device_id']);
|
||||
foreach (dbFetchRows($sql, $param) as $alertlog) {
|
||||
$dev = device_by_id_cache($alertlog['device_id']);
|
||||
$fault_detail = alert_details($alertlog['details']);
|
||||
$alert_state = $alertlog['state'];
|
||||
if ($alert_state=='0') {
|
||||
$glyph_icon = 'ok';
|
||||
$alert_state = $alertlog['state'];
|
||||
if ($alert_state == '0') {
|
||||
$glyph_icon = 'ok';
|
||||
$glyph_color = 'green';
|
||||
$text = 'Ok';
|
||||
$text = 'Ok';
|
||||
}
|
||||
elseif ($alert_state=='1') {
|
||||
$glyph_icon = 'remove';
|
||||
else if ($alert_state == '1') {
|
||||
$glyph_icon = 'remove';
|
||||
$glyph_color = 'red';
|
||||
$text = 'Alert';
|
||||
$text = 'Alert';
|
||||
}
|
||||
elseif ($alert_state=='2') {
|
||||
$glyph_icon = 'info-sign';
|
||||
else if ($alert_state == '2') {
|
||||
$glyph_icon = 'info-sign';
|
||||
$glyph_color = 'lightgrey';
|
||||
$text = 'Ack';
|
||||
$text = 'Ack';
|
||||
}
|
||||
elseif ($alert_state=='3') {
|
||||
$glyph_icon = 'arrow-down';
|
||||
else if ($alert_state == '3') {
|
||||
$glyph_icon = 'arrow-down';
|
||||
$glyph_color = 'orange';
|
||||
$text = 'Worse';
|
||||
$text = 'Worse';
|
||||
}
|
||||
elseif ($alert_state=='4') {
|
||||
$glyph_icon = 'arrow-up';
|
||||
else if ($alert_state == '4') {
|
||||
$glyph_icon = 'arrow-up';
|
||||
$glyph_color = 'khaki';
|
||||
$text = 'Better';
|
||||
}
|
||||
$response[] = array('id'=>$rulei++,
|
||||
'time_logged'=>$alertlog['humandate'],
|
||||
'details'=>'<a class="glyphicon glyphicon-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname'=>'<div class="incident">'.generate_device_link($dev, shorthost($dev['hostname'])).'<div id="incident'.($rulei).'" class="collapse">'.$fault_detail.'</div></div>',
|
||||
'alert'=>htmlspecialchars($alertlog['alert']),
|
||||
'status'=>"<b><span class='glyphicon glyphicon-".$glyph_icon."' style='color:".$glyph_color."'></span> $text</b>");
|
||||
}
|
||||
$text = 'Better';
|
||||
}//end if
|
||||
$response[] = array(
|
||||
'id' => $rulei++,
|
||||
'time_logged' => $alertlog['humandate'],
|
||||
'details' => '<a class="glyphicon glyphicon-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname' => '<div class="incident">'.generate_device_link($dev, shorthost($dev['hostname'])).'<div id="incident'.($rulei).'" class="collapse">'.$fault_detail.'</div></div>',
|
||||
'alert' => htmlspecialchars($alertlog['alert']),
|
||||
'status' => "<b><span class='glyphicon glyphicon-".$glyph_icon."' style='color:".$glyph_color."'></span> $text</b>",
|
||||
);
|
||||
}//end foreach
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
echo _json_encode($output);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -10,18 +10,18 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql_search .= " AND (`timestamp` LIKE '%$searchPhrase%' OR `rule` LIKE '%$searchPhrase%' OR `name` LIKE '%$searchPhrase%' OR `hostname` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$sql = " FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`";
|
||||
$sql = ' FROM `alerts` LEFT JOIN `devices` ON `alerts`.`device_id`=`devices`.`device_id`';
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " RIGHT JOIN alert_rules ON alerts.rule_id=alert_rules.id WHERE $where AND `state` IN (1,2,3,4) $sql_search";
|
||||
|
||||
$count_sql = "SELECT COUNT(`alerts`.`id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -43,76 +43,86 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT `alerts`.*, `devices`.`hostname` AS `hostname`,`alert_rules`.`rule` AS `rule`, `alert_rules`.`name` AS `name`, `alert_rules`.`severity` AS `severity` $sql";
|
||||
|
||||
$rulei = 0;
|
||||
$rulei = 0;
|
||||
$format = $_POST['format'];
|
||||
foreach (dbFetchRows($sql,$param) as $alert) {
|
||||
$log = dbFetchCell("SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1", array($alert['rule_id'],$alert['device_id']));
|
||||
foreach (dbFetchRows($sql, $param) as $alert) {
|
||||
$log = dbFetchCell('SELECT details FROM alert_log WHERE rule_id = ? AND device_id = ? ORDER BY id DESC LIMIT 1', array($alert['rule_id'], $alert['device_id']));
|
||||
$fault_detail = alert_details($log);
|
||||
|
||||
$ico = "ok";
|
||||
$col = "green";
|
||||
$extra = "";
|
||||
$msg = "";
|
||||
if ( (int) $alert['state'] === 0 ) {
|
||||
$ico = "ok";
|
||||
$col = "green";
|
||||
$extra = "success";
|
||||
$msg = "ok";
|
||||
} elseif ( (int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) {
|
||||
$ico = "volume-up";
|
||||
$col = "red";
|
||||
$extra = "danger";
|
||||
$msg = "alert";
|
||||
if ( (int) $alert['state'] === 3) {
|
||||
$msg = "worse";
|
||||
} elseif ( (int) $alert['state'] === 4) {
|
||||
$msg = "better";
|
||||
}
|
||||
} elseif ( (int) $alert['state'] === 2) {
|
||||
$ico = "volume-off";
|
||||
$col = "#800080";
|
||||
$extra = "warning";
|
||||
$msg = "muted";
|
||||
$ico = 'ok';
|
||||
$col = 'green';
|
||||
$extra = '';
|
||||
$msg = '';
|
||||
if ((int) $alert['state'] === 0) {
|
||||
$ico = 'ok';
|
||||
$col = 'green';
|
||||
$extra = 'success';
|
||||
$msg = 'ok';
|
||||
}
|
||||
else if ((int) $alert['state'] === 1 || (int) $alert['state'] === 3 || (int) $alert['state'] === 4) {
|
||||
$ico = 'volume-up';
|
||||
$col = 'red';
|
||||
$extra = 'danger';
|
||||
$msg = 'alert';
|
||||
if ((int) $alert['state'] === 3) {
|
||||
$msg = 'worse';
|
||||
}
|
||||
else if ((int) $alert['state'] === 4) {
|
||||
$msg = 'better';
|
||||
}
|
||||
}
|
||||
else if ((int) $alert['state'] === 2) {
|
||||
$ico = 'volume-off';
|
||||
$col = '#800080';
|
||||
$extra = 'warning';
|
||||
$msg = 'muted';
|
||||
}//end if
|
||||
$alert_checked = '';
|
||||
$orig_ico = $ico;
|
||||
$orig_col = $col;
|
||||
$orig_class = $extra;
|
||||
$orig_ico = $ico;
|
||||
$orig_col = $col;
|
||||
$orig_class = $extra;
|
||||
|
||||
$severity = $alert['severity'];
|
||||
if ($alert['state'] == 3) {
|
||||
$severity .= " <strong>+</strong>";
|
||||
} elseif ($alert['state'] == 4) {
|
||||
$severity .= " <strong>-</strong>";
|
||||
$severity .= ' <strong>+</strong>';
|
||||
}
|
||||
else if ($alert['state'] == 4) {
|
||||
$severity .= ' <strong>-</strong>';
|
||||
}
|
||||
|
||||
$ack_ico = 'volume-up';
|
||||
$ack_col = 'success';
|
||||
if($alert['state'] == 2) {
|
||||
if ($alert['state'] == 2) {
|
||||
$ack_ico = 'volume-off';
|
||||
$ack_col = 'danger';
|
||||
}
|
||||
}
|
||||
|
||||
$hostname = '
|
||||
<div class="incident">
|
||||
'.generate_device_link($alert).'
|
||||
<div id="incident'.($rulei+1).'" class="collapse">'.$fault_detail.'</div>
|
||||
</div>';
|
||||
<div class="incident">
|
||||
'.generate_device_link($alert).'
|
||||
<div id="incident'.($rulei + 1).'" class="collapse">'.$fault_detail.'</div>
|
||||
</div>';
|
||||
|
||||
$response[] = array('id'=>$rulei++,
|
||||
'rule'=>"<i title=\"".htmlentities($alert['rule'])."\">".htmlentities($alert['name'])."</i>",
|
||||
'details'=>'<a class="glyphicon glyphicon-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname'=>$hostname,
|
||||
'timestamp'=>($alert['timestamp'] ? $alert['timestamp'] : "N/A"),
|
||||
'severity'=>$severity,
|
||||
'ack_col'=>$ack_col,
|
||||
'state'=>$alert['state'],
|
||||
'alert_id'=>$alert['id'],
|
||||
'ack_ico'=>$ack_ico,
|
||||
'extra'=>$extra,
|
||||
'msg'=>$msg);
|
||||
$response[] = array(
|
||||
'id' => $rulei++,
|
||||
'rule' => '<i title="'.htmlentities($alert['rule']).'">'.htmlentities($alert['name']).'</i>',
|
||||
'details' => '<a class="glyphicon glyphicon-plus incident-toggle" style="display:none" data-toggle="collapse" data-target="#incident'.($rulei).'" data-parent="#alerts"></a>',
|
||||
'hostname' => $hostname,
|
||||
'timestamp' => ($alert['timestamp'] ? $alert['timestamp'] : 'N/A'),
|
||||
'severity' => $severity,
|
||||
'ack_col' => $ack_col,
|
||||
'state' => $alert['state'],
|
||||
'alert_id' => $alert['id'],
|
||||
'ack_ico' => $ack_ico,
|
||||
'extra' => $extra,
|
||||
'msg' => $msg,
|
||||
);
|
||||
}//end foreach
|
||||
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -2,32 +2,33 @@
|
||||
|
||||
$param = array();
|
||||
|
||||
$sql .= " FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D ";
|
||||
$sql .= ' FROM `ipv4_mac` AS M, `ports` AS P, `devices` AS D ';
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " WHERE M.port_id = P.port_id AND P.device_id = D.device_id $where ";
|
||||
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == "ip") {
|
||||
$sql .= " AND `ipv4_address` LIKE ?";
|
||||
$param[] = "%".trim($_POST['address'])."%";
|
||||
} elseif (isset($_POST['searchby']) && $_POST['searchby'] == "mac") {
|
||||
$sql .= " AND `mac_address` LIKE ?";
|
||||
$param[] = "%".str_replace(array(':', ' ', '-', '.', '0x'),'',mres($_POST['address']))."%";
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == 'ip') {
|
||||
$sql .= ' AND `ipv4_address` LIKE ?';
|
||||
$param[] = '%'.trim($_POST['address']).'%';
|
||||
}
|
||||
else if (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') {
|
||||
$sql .= ' AND `mac_address` LIKE ?';
|
||||
$param[] = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['address'])).'%';
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= " AND P.device_id = ?";
|
||||
$sql .= ' AND P.device_id = ?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`M`.`port_id`) $sql";
|
||||
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -39,7 +40,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -51,39 +52,53 @@ $sql = "SELECT *,`P`.`ifDescr` AS `interface` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $entry) {
|
||||
if (!$ignore) {
|
||||
|
||||
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
|
||||
$error_img = generate_port_link($entry,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",port_errors);
|
||||
} else {
|
||||
$error_img = "";
|
||||
$error_img = generate_port_link($entry, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", port_errors);
|
||||
}
|
||||
else {
|
||||
$error_img = '';
|
||||
}
|
||||
|
||||
$arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address']));
|
||||
if ($arp_host) {
|
||||
$arp_name = generate_device_link($arp_host);
|
||||
} else {
|
||||
unset($arp_name);
|
||||
}
|
||||
if ($arp_host) {
|
||||
$arp_if = generate_port_link($arp_host);
|
||||
} else {
|
||||
unset($arp_if);
|
||||
}
|
||||
if ($arp_host['device_id'] == $entry['device_id']) {
|
||||
$arp_name = "Localhost";
|
||||
}
|
||||
if ($arp_host['port_id'] == $entry['port_id']) {
|
||||
$arp_if = "Local port";
|
||||
}
|
||||
$response[] = array('mac_address'=>formatMac($entry['mac_address']),
|
||||
'ipv4_address'=>$entry['ipv4_address'],
|
||||
'hostname'=>generate_device_link($entry),
|
||||
'interface'=>generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))) . ' ' . $error_img,
|
||||
'remote_device'=>$arp_name,
|
||||
'remote_interface'=>$arp_if);
|
||||
}
|
||||
unset($ignore);
|
||||
}
|
||||
$arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($entry['ipv4_address']));
|
||||
if ($arp_host) {
|
||||
$arp_name = generate_device_link($arp_host);
|
||||
}
|
||||
else {
|
||||
unset($arp_name);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
if ($arp_host) {
|
||||
$arp_if = generate_port_link($arp_host);
|
||||
}
|
||||
else {
|
||||
unset($arp_if);
|
||||
}
|
||||
|
||||
if ($arp_host['device_id'] == $entry['device_id']) {
|
||||
$arp_name = 'Localhost';
|
||||
}
|
||||
|
||||
if ($arp_host['port_id'] == $entry['port_id']) {
|
||||
$arp_if = 'Local port';
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
'mac_address' => formatMac($entry['mac_address']),
|
||||
'ipv4_address' => $entry['ipv4_address'],
|
||||
'hostname' => generate_device_link($entry),
|
||||
'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))).' '.$error_img,
|
||||
'remote_device' => $arp_name,
|
||||
'remote_interface' => $arp_if,
|
||||
);
|
||||
}//end if
|
||||
|
||||
unset($ignore);
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
+182
-118
@@ -3,11 +3,11 @@
|
||||
$where = 1;
|
||||
$param = array();
|
||||
|
||||
$sql = " FROM `devices`";
|
||||
$sql = ' FROM `devices`';
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `devices`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
@@ -17,48 +17,87 @@ if (!empty($_POST['location'])) {
|
||||
|
||||
$sql .= " WHERE $where ";
|
||||
|
||||
if (!empty($_POST['hostname'])) { $sql .= " AND hostname LIKE ?"; $param[] = "%".$_POST['hostname']."%"; }
|
||||
if (!empty($_POST['os'])) { $sql .= " AND os = ?"; $param[] = $_POST['os']; }
|
||||
if (!empty($_POST['version'])) { $sql .= " AND version = ?"; $param[] = $_POST['version']; }
|
||||
if (!empty($_POST['hardware'])) { $sql .= " AND hardware = ?"; $param[] = $_POST['hardware']; }
|
||||
if (!empty($_POST['features'])) { $sql .= " AND features = ?"; $param[] = $_POST['features']; }
|
||||
if (!empty($_POST['type'])) {
|
||||
if ($_POST['type'] == 'generic') {
|
||||
$sql .= " AND ( type = ? OR type = '')"; $param[] = $_POST['type'];
|
||||
} else {
|
||||
$sql .= " AND type = ?"; $param[] = $_POST['type'];
|
||||
}
|
||||
if (!empty($_POST['hostname'])) {
|
||||
$sql .= ' AND hostname LIKE ?';
|
||||
$param[] = '%'.$_POST['hostname'].'%';
|
||||
}
|
||||
if (!empty($_POST['state'])) {
|
||||
$sql .= " AND status= ?";
|
||||
if( is_numeric($_POST['state']) ) {
|
||||
$param[] = $_POST['state'];
|
||||
} else {
|
||||
$param[] = str_replace(array('up','down'),array(1,0),$_POST['state']);
|
||||
|
||||
if (!empty($_POST['os'])) {
|
||||
$sql .= ' AND os = ?';
|
||||
$param[] = $_POST['os'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['version'])) {
|
||||
$sql .= ' AND version = ?';
|
||||
$param[] = $_POST['version'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['hardware'])) {
|
||||
$sql .= ' AND hardware = ?';
|
||||
$param[] = $_POST['hardware'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['features'])) {
|
||||
$sql .= ' AND features = ?';
|
||||
$param[] = $_POST['features'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['type'])) {
|
||||
if ($_POST['type'] == 'generic') {
|
||||
$sql .= " AND ( type = ? OR type = '')";
|
||||
$param[] = $_POST['type'];
|
||||
}
|
||||
else {
|
||||
$sql .= ' AND type = ?';
|
||||
$param[] = $_POST['type'];
|
||||
}
|
||||
}
|
||||
if (!empty($_POST['disabled'])) { $sql .= " AND disabled= ?"; $param[] = $_POST['disabled']; }
|
||||
if (!empty($_POST['ignore'])) { $sql .= " AND `ignore`= ?"; $param[] = $_POST['ignore']; }
|
||||
if (!empty($_POST['location']) && $_POST['location'] == "Unset") { $location_filter = ''; }
|
||||
|
||||
if (!empty($_POST['state'])) {
|
||||
$sql .= ' AND status= ?';
|
||||
if (is_numeric($_POST['state'])) {
|
||||
$param[] = $_POST['state'];
|
||||
}
|
||||
else {
|
||||
$param[] = str_replace(array('up', 'down'), array(1, 0), $_POST['state']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['disabled'])) {
|
||||
$sql .= ' AND disabled= ?';
|
||||
$param[] = $_POST['disabled'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['ignore'])) {
|
||||
$sql .= ' AND `ignore`= ?';
|
||||
$param[] = $_POST['ignore'];
|
||||
}
|
||||
|
||||
if (!empty($_POST['location']) && $_POST['location'] == 'Unset') {
|
||||
$location_filter = '';
|
||||
}
|
||||
|
||||
if (!empty($_POST['location'])) {
|
||||
$sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)";
|
||||
$sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)";
|
||||
$param[] = mres($_POST['location']);
|
||||
$param[] = mres($_POST['location']);
|
||||
}
|
||||
if( !empty($_POST['group']) ) {
|
||||
require_once('../includes/device-groups.inc.php');
|
||||
$sql .= " AND ( ";
|
||||
foreach( GetDevicesFromGroup($_POST['group']) as $dev ) {
|
||||
$sql .= "`devices`.`device_id` = ? OR ";
|
||||
|
||||
if (!empty($_POST['group'])) {
|
||||
include_once '../includes/device-groups.inc.php';
|
||||
$sql .= ' AND ( ';
|
||||
foreach (GetDevicesFromGroup($_POST['group']) as $dev) {
|
||||
$sql .= '`devices`.`device_id` = ? OR ';
|
||||
$param[] = $dev['device_id'];
|
||||
}
|
||||
$sql = substr($sql, 0, strlen($sql)-3);
|
||||
$sql .= " )";
|
||||
|
||||
$sql = substr($sql, 0, (strlen($sql) - 3));
|
||||
$sql .= ' )';
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`devices`.`device_id`) $sql";
|
||||
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -70,7 +109,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -81,99 +120,124 @@ if ($rowCount != -1) {
|
||||
$sql = "SELECT DISTINCT(`devices`.`device_id`),`devices`.* $sql";
|
||||
|
||||
if (!isset($_POST['format'])) {
|
||||
$_POST['format'] = "list_detail";
|
||||
$_POST['format'] = 'list_detail';
|
||||
}
|
||||
list($format, $subformat) = explode("_", $_POST['format']);
|
||||
|
||||
list($format, $subformat) = explode('_', $_POST['format']);
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $device) {
|
||||
if (isset($bg) && $bg == $list_colour_b) {
|
||||
$bg = $list_colour_a;
|
||||
} else {
|
||||
$bg = $list_colour_b;
|
||||
}
|
||||
if (isset($bg) && $bg == $list_colour_b) {
|
||||
$bg = $list_colour_a;
|
||||
}
|
||||
else {
|
||||
$bg = $list_colour_b;
|
||||
}
|
||||
|
||||
if ($device['status'] == '0') {
|
||||
$extra = "danger";
|
||||
$msg = $device['status_reason'];
|
||||
} else {
|
||||
$extra = "success";
|
||||
$msg = "up";
|
||||
}
|
||||
if ($device['ignore'] == '1') {
|
||||
$extra = "default";
|
||||
$msg = "ignored";
|
||||
if ($device['status'] == '1') {
|
||||
$extra = "warning";
|
||||
$msg = "ignored";
|
||||
}
|
||||
}
|
||||
if ($device['disabled'] == '1') {
|
||||
$extra = "default";
|
||||
$msg = "disabled";
|
||||
}
|
||||
if ($device['status'] == '0') {
|
||||
$extra = 'danger';
|
||||
$msg = $device['status_reason'];
|
||||
}
|
||||
else {
|
||||
$extra = 'success';
|
||||
$msg = 'up';
|
||||
}
|
||||
|
||||
$type = strtolower($device['os']);
|
||||
$image = getImage($device);
|
||||
|
||||
if ($device['os'] == "ios") {
|
||||
formatCiscoHardware($device, true);
|
||||
}
|
||||
if ($device['ignore'] == '1') {
|
||||
$extra = 'default';
|
||||
$msg = 'ignored';
|
||||
if ($device['status'] == '1') {
|
||||
$extra = 'warning';
|
||||
$msg = 'ignored';
|
||||
}
|
||||
}
|
||||
|
||||
$device['os_text'] = $config['os'][$device['os']]['text'];
|
||||
$port_count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", array($device['device_id']));
|
||||
$sensor_count = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?", array($device['device_id']));
|
||||
if ($device['disabled'] == '1') {
|
||||
$extra = 'default';
|
||||
$msg = 'disabled';
|
||||
}
|
||||
|
||||
if (get_dev_attrib($device,'override_sysLocation_bool')) {
|
||||
$device['location'] = get_dev_attrib($device,'override_sysLocation_string');
|
||||
}
|
||||
$type = strtolower($device['os']);
|
||||
$image = getImage($device);
|
||||
|
||||
$actions = ('<div class="row">
|
||||
<div class="col-xs-1">');
|
||||
$actions .= '<a href="'.generate_device_url($device).'"> <img src="images/16/server.png" border="0" align="absmiddle" alt="View device" title="View device" /></a> ';
|
||||
$actions .= ('</div>
|
||||
<div class="col-xs-1">');
|
||||
$actions .= '<a href="'.generate_device_url($device, array('tab' => 'alerts')).'"> <img src="images/16/bell.png" border="0" align="absmiddle" alt="View alerts" title="View alerts" /></a> ';
|
||||
$actions .= '</div>';
|
||||
if ($_SESSION['userlevel'] >= "7") {
|
||||
$actions .= ('<div class="col-xs-1">
|
||||
<a href="'.generate_device_url($device, array('tab' => 'edit')).'"> <img src="images/16/wrench.png" border="0" align="absmiddle" alt="Edit device" title="Edit device" /></a>
|
||||
</div>');
|
||||
}
|
||||
$actions .= ('</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-1">
|
||||
<a href="telnet://' . $device['hostname'] . '"><img src="images/16/telnet.png" alt="telnet" title="Telnet to ' . $device['hostname'] . '" border="0" width="16" height="16"></a>
|
||||
</div>
|
||||
<div class="col-xs-1">
|
||||
<a href="ssh://' . $device['hostname'] . '"><img src="images/16/ssh.png" alt="ssh" title="SSH to ' . $device['hostname'] . '" border="0" width="16" height="16"></a>
|
||||
</div>
|
||||
<div class="col-xs-1">
|
||||
<a href="https://' . $device['hostname'] . '"><img src="images/16/http.png" alt="https" title="Launch browser https://' . $device['hostname'] . '" border="0" width="16" height="16" target="_blank"></a>
|
||||
</div>
|
||||
</div>');
|
||||
if ($device['os'] == 'ios') {
|
||||
formatCiscoHardware($device, true);
|
||||
}
|
||||
|
||||
$hostname = generate_device_link($device);
|
||||
$platform = $device['hardware'] . '<br />' . $device['features'];
|
||||
$os = $device['os_text'] . '<br />' . $device['version'];
|
||||
if (extension_loaded('mbstring')) {
|
||||
$location = mb_substr($device['location'], 0, 32, 'utf8');
|
||||
} else {
|
||||
$location = truncate($device['location'], 32, '');
|
||||
}
|
||||
$uptime = formatUptime($device['uptime'], 'short') . '<br />' . $location;
|
||||
if ($subformat == "detail") {
|
||||
$hostname .= '<br />' . $device['sysName'];
|
||||
if ($port_count) {
|
||||
$col_port = ' <img src="images/icons/port.png" align=absmiddle /> '.$port_count . '<br />';
|
||||
}
|
||||
if ($sensor_count) {
|
||||
$col_port .= ' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count;
|
||||
}
|
||||
} else {
|
||||
$device['os_text'] = $config['os'][$device['os']]['text'];
|
||||
$port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
|
||||
$sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id']));
|
||||
|
||||
}
|
||||
$response[] = array('extra'=>$extra,'msg'=>$msg,'icon'=>$image,'hostname'=>$hostname,'ports'=>$col_port,'hardware'=>$platform,'os'=>$os,'uptime'=>$uptime,'actions'=>$actions);
|
||||
}
|
||||
if (get_dev_attrib($device, 'override_sysLocation_bool')) {
|
||||
$device['location'] = get_dev_attrib($device, 'override_sysLocation_string');
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$actions = ('<div class="row">
|
||||
<div class="col-xs-1">');
|
||||
$actions .= '<a href="'.generate_device_url($device).'"> <img src="images/16/server.png" border="0" align="absmiddle" alt="View device" title="View device" /></a> ';
|
||||
$actions .= ('</div>
|
||||
<div class="col-xs-1">');
|
||||
$actions .= '<a href="'.generate_device_url($device, array('tab' => 'alerts')).'"> <img src="images/16/bell.png" border="0" align="absmiddle" alt="View alerts" title="View alerts" /></a> ';
|
||||
$actions .= '</div>';
|
||||
if ($_SESSION['userlevel'] >= '7') {
|
||||
$actions .= ('<div class="col-xs-1">
|
||||
<a href="'.generate_device_url($device, array('tab' => 'edit')).'"> <img src="images/16/wrench.png" border="0" align="absmiddle" alt="Edit device" title="Edit device" /></a>
|
||||
</div>');
|
||||
}
|
||||
|
||||
$actions .= ('</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-1">
|
||||
<a href="telnet://'.$device['hostname'].'"><img src="images/16/telnet.png" alt="telnet" title="Telnet to '.$device['hostname'].'" border="0" width="16" height="16"></a>
|
||||
</div>
|
||||
<div class="col-xs-1">
|
||||
<a href="ssh://'.$device['hostname'].'"><img src="images/16/ssh.png" alt="ssh" title="SSH to '.$device['hostname'].'" border="0" width="16" height="16"></a>
|
||||
</div>
|
||||
<div class="col-xs-1">
|
||||
<a href="https://'.$device['hostname'].'"><img src="images/16/http.png" alt="https" title="Launch browser https://'.$device['hostname'].'" border="0" width="16" height="16" target="_blank"></a>
|
||||
</div>
|
||||
</div>');
|
||||
|
||||
$hostname = generate_device_link($device);
|
||||
$platform = $device['hardware'].'<br />'.$device['features'];
|
||||
$os = $device['os_text'].'<br />'.$device['version'];
|
||||
if (extension_loaded('mbstring')) {
|
||||
$location = mb_substr($device['location'], 0, 32, 'utf8');
|
||||
}
|
||||
else {
|
||||
$location = truncate($device['location'], 32, '');
|
||||
}
|
||||
|
||||
$uptime = formatUptime($device['uptime'], 'short').'<br />'.$location;
|
||||
if ($subformat == 'detail') {
|
||||
$hostname .= '<br />'.$device['sysName'];
|
||||
if ($port_count) {
|
||||
$col_port = ' <img src="images/icons/port.png" align=absmiddle /> '.$port_count.'<br />';
|
||||
}
|
||||
|
||||
if ($sensor_count) {
|
||||
$col_port .= ' <img src="images/icons/sensors.png" align=absmiddle /> '.$sensor_count;
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
'extra' => $extra,
|
||||
'msg' => $msg,
|
||||
'icon' => $image,
|
||||
'hostname' => $hostname,
|
||||
'ports' => $col_port,
|
||||
'hardware' => $platform,
|
||||
'os' => $os,
|
||||
'uptime' => $uptime,
|
||||
'actions' => $actions,
|
||||
);
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
<?php
|
||||
|
||||
$where = "1";
|
||||
$where = '1';
|
||||
|
||||
if (is_numeric($_POST['device']))
|
||||
{
|
||||
$where .= ' AND E.host = ?';
|
||||
$param[] = $_POST['device'];
|
||||
if (is_numeric($_POST['device'])) {
|
||||
$where .= ' AND E.host = ?';
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
|
||||
if ($_POST['string'])
|
||||
{
|
||||
$where .= " AND E.message LIKE ?";
|
||||
$param[] = "%".$_POST['string']."%";
|
||||
if ($_POST['string']) {
|
||||
$where .= ' AND E.message LIKE ?';
|
||||
$param[] = '%'.$_POST['string'].'%';
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM `eventlog` AS E LEFT JOIN `devices` AS `D` ON `E`.`host`=`D`.`device_id` WHERE $where";
|
||||
} else {
|
||||
$sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?";
|
||||
}
|
||||
else {
|
||||
$sql = " FROM `eventlog` AS E, devices_perms AS P WHERE $where AND E.host = P.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
@@ -26,7 +25,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(datetime) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -38,7 +37,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -48,22 +47,28 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT `E`.*,DATE_FORMAT(datetime, '".$config['dateformat']['mysql']['compact']."') as humandate $sql";
|
||||
|
||||
foreach (dbFetchRows($sql,$param) as $eventlog) {
|
||||
foreach (dbFetchRows($sql, $param) as $eventlog) {
|
||||
$dev = device_by_id_cache($eventlog['host']);
|
||||
if ($eventlog['type'] == "interface") {
|
||||
if ($eventlog['type'] == 'interface') {
|
||||
$this_if = ifLabel(getifbyid($eventlog['reference']));
|
||||
$type = "<b>".generate_port_link($this_if, makeshortif(strtolower($this_if['label'])))."</b>";
|
||||
} else {
|
||||
$type = "System";
|
||||
$type = '<b>'.generate_port_link($this_if, makeshortif(strtolower($this_if['label']))).'</b>';
|
||||
}
|
||||
|
||||
$response[] = array('datetime'=>$eventlog['humandate'],
|
||||
'hostname'=>generate_device_link($dev, shorthost($dev['hostname'])),
|
||||
'type'=>$type,
|
||||
'message'=>htmlspecialchars($eventlog['message']));
|
||||
else {
|
||||
$type = 'System';
|
||||
}
|
||||
|
||||
$response[] = array(
|
||||
'datetime' => $eventlog['humandate'],
|
||||
'hostname' => generate_device_link($dev, shorthost($dev['hostname'])),
|
||||
'type' => $type,
|
||||
'message' => htmlspecialchars($eventlog['message']),
|
||||
);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
$where = "1";
|
||||
$where = '1';
|
||||
$param = array();
|
||||
|
||||
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = " FROM entPhysical AS E, devices AS D WHERE $where AND D.device_id = E.device_id";
|
||||
} else {
|
||||
$sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?";
|
||||
}
|
||||
else {
|
||||
$sql = " FROM entPhysical AS E, devices AS D, devices_perms AS P WHERE $where AND D.device_id = E.device_id AND P.device_id = D.device_id AND P.user_id = ?";
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
@@ -17,32 +18,32 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
}
|
||||
|
||||
if (isset($_POST['string']) && strlen($_POST['string'])) {
|
||||
$sql .= " AND E.entPhysicalDescr LIKE ?";
|
||||
$param[] = "%".$_POST['string']."%";
|
||||
$sql .= ' AND E.entPhysicalDescr LIKE ?';
|
||||
$param[] = '%'.$_POST['string'].'%';
|
||||
}
|
||||
|
||||
if (isset($_POST['device_string']) && strlen($_POST['device_string'])) {
|
||||
$sql .= " AND D.hostname LIKE ?";
|
||||
$param[] = "%".$_POST['device_string']."%";
|
||||
$sql .= ' AND D.hostname LIKE ?';
|
||||
$param[] = '%'.$_POST['device_string'].'%';
|
||||
}
|
||||
|
||||
if (isset($_POST['part']) && strlen($_POST['part'])) {
|
||||
$sql .= " AND E.entPhysicalModelName = ?";
|
||||
$param[] = $_POST['part'];
|
||||
$sql .= ' AND E.entPhysicalModelName = ?';
|
||||
$param[] = $_POST['part'];
|
||||
}
|
||||
|
||||
if (isset($_POST['serial']) && strlen($_POST['serial'])) {
|
||||
$sql .= " AND E.entPhysicalSerialNum LIKE ?";
|
||||
$param[] = "%".$_POST['serial']."%";
|
||||
$sql .= ' AND E.entPhysicalSerialNum LIKE ?';
|
||||
$param[] = '%'.$_POST['serial'].'%';
|
||||
}
|
||||
|
||||
if (isset($_POST['device']) && is_numeric($_POST['device'])) {
|
||||
$sql .= " AND D.device_id = ?";
|
||||
$param[] = $_POST['device'];
|
||||
$sql .= ' AND D.device_id = ?';
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`entPhysical_id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -54,7 +55,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -65,12 +66,19 @@ if ($rowCount != -1) {
|
||||
$sql = "SELECT `D`.`device_id` AS `device_id`, `D`.`hostname` AS `hostname`,`entPhysicalDescr` AS `description`, `entPhysicalName` AS `name`, `entPhysicalModelName` AS `model`, `entPhysicalSerialNum` AS `serial` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $invent) {
|
||||
$response[] = array('hostname'=>generate_device_link($invent, shortHost($invent['hostname'])),
|
||||
'description'=>$invent['description'],
|
||||
'name'=>$invent['name'],
|
||||
'model'=>$invent['model'],
|
||||
'serial'=>$invent['serial']);
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($invent, shortHost($invent['hostname'])),
|
||||
'description' => $invent['description'],
|
||||
'name' => $invent['name'],
|
||||
'model' => $invent['model'],
|
||||
'serial' => $invent['serial'],
|
||||
);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -1,72 +1,88 @@
|
||||
<?php
|
||||
$graph_type = "mempool_usage";
|
||||
$where = 1;
|
||||
$sql = " FROM `mempools` AS `M` LEFT JOIN `devices` AS `D` ON `M`.`device_id` = `D`.`device_id`";
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `M`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
$graph_type = 'mempool_usage';
|
||||
$where = 1;
|
||||
$sql = ' FROM `mempools` AS `M` LEFT JOIN `devices` AS `D` ON `M`.`device_id` = `D`.`device_id`';
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `M`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " WHERE $where";
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`hostname` LIKE '%$searchPhrase%' OR `mempool_descr` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`mempool_id`) $sql";
|
||||
$count = dbFetchCell($count_sql,$param);
|
||||
$count = dbFetchCell($count_sql, $param);
|
||||
if (empty($count)) {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`D`.`hostname`, `M`.`mempool_descr`';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
$sql = "SELECT * $sql";
|
||||
foreach (dbFetchRows($sql,$param) as $mempool) {
|
||||
$perc = round($mempool['mempool_perc'], 0);
|
||||
$total = formatStorage($mempool['mempool_total']);
|
||||
$free = formatStorage($mempool['mempool_free']);
|
||||
$used = formatStorage($mempool['mempool_used']);
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $mempool['mempool_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = "20";
|
||||
$graph_array['width'] = "80";
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = "150";
|
||||
$graph_array_zoom['width'] = "400";
|
||||
$link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/";
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL);
|
||||
|
||||
$response[] = array('hostname' => generate_device_link($mempool),
|
||||
'mempool_descr' => $mempool['mempool_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'mempool_used' => $bar_link,
|
||||
'mempool_perc' => $perc . "%");
|
||||
if ($_POST['view'] == "graphs") {
|
||||
$graph_array['height'] = "100";
|
||||
$graph_array['width'] = "216";
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $mempool['mempool_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$return_data = true;
|
||||
include("includes/print-graphrow.inc.php");
|
||||
unset($return_data);
|
||||
$response[] = array('hostname' => $graph_data[0],
|
||||
'mempool_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'mempool_used' => $graph_data[3],
|
||||
'mempool_perc' => '');
|
||||
} # endif graphs
|
||||
}
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count);
|
||||
$sql = "SELECT * $sql";
|
||||
foreach (dbFetchRows($sql, $param) as $mempool) {
|
||||
$perc = round($mempool['mempool_perc'], 0);
|
||||
$total = formatStorage($mempool['mempool_total']);
|
||||
$free = formatStorage($mempool['mempool_free']);
|
||||
$used = formatStorage($mempool['mempool_used']);
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $mempool['mempool_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = '20';
|
||||
$graph_array['width'] = '80';
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = '150';
|
||||
$graph_array_zoom['width'] = '400';
|
||||
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($mempool),
|
||||
'mempool_descr' => $mempool['mempool_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'mempool_used' => $bar_link,
|
||||
'mempool_perc' => $perc.'%',
|
||||
);
|
||||
if ($_POST['view'] == 'graphs') {
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '216';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $mempool['mempool_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$return_data = true;
|
||||
include 'includes/print-graphrow.inc.php';
|
||||
unset($return_data);
|
||||
$response[] = array(
|
||||
'hostname' => $graph_data[0],
|
||||
'mempool_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'mempool_used' => $graph_data[3],
|
||||
'mempool_perc' => '',
|
||||
);
|
||||
} //end if
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $count,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
$sql = " FROM `devices` AS D";
|
||||
$sql = ' FROM `devices` AS D';
|
||||
|
||||
if (is_admin() === FALSE) {
|
||||
$sql .= ", devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.ignore = '0'";
|
||||
} else {
|
||||
$sql .= " WHERE 1";
|
||||
if (is_admin() === false) {
|
||||
$sql .= ", devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '".$_SESSION['user_id']."' AND D.ignore = '0'";
|
||||
}
|
||||
else {
|
||||
$sql .= ' WHERE 1';
|
||||
}
|
||||
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
@@ -19,13 +20,13 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " AND D.status ='1' AND D.ignore='0' AND D.disabled='0' ORDER BY $sort";
|
||||
|
||||
$count_sql = "SELECT COUNT(`D`.`device_id`) $sql";
|
||||
$total = dbFetchCell($count_sql);
|
||||
$total = dbFetchCell($count_sql);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -36,12 +37,17 @@ if ($rowCount != -1) {
|
||||
$sql = "SELECT D.device_id,D.hostname AS `hostname`, D.last_polled AS `last_polled`, D.last_polled_timetaken AS `last_polled_timetaken` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql) as $device) {
|
||||
$response[] = array('hostname' => "<a class='list-device' href='" .generate_device_url($device, array('tab' => 'graphs', 'group' => 'poller')). "'>" .$device['hostname']. "</a>",
|
||||
'last_polled' => $device['last_polled'],
|
||||
'last_polled_timetaken' => $device['last_polled_timetaken']);
|
||||
$response[] = array(
|
||||
'hostname' => "<a class='list-device' href='".generate_device_url($device, array('tab' => 'graphs', 'group' => 'poller'))."'>".$device['hostname'].'</a>',
|
||||
'last_polled' => $device['last_polled'],
|
||||
'last_polled_timetaken' => $device['last_polled_timetaken'],
|
||||
);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,67 +1,83 @@
|
||||
<?php
|
||||
$graph_type = "processor_usage";
|
||||
$where = 1;
|
||||
$sql = " FROM `processors` AS `P` LEFT JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id`";
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `P`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
$graph_type = 'processor_usage';
|
||||
$where = 1;
|
||||
$sql = ' FROM `processors` AS `P` LEFT JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id`';
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `P`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " WHERE $where";
|
||||
if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
$sql .= " AND (`hostname` LIKE '%$searchPhrase%' OR `processor_descr` LIKE '%$searchPhrase%')";
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(`processor_id`) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`D`.`hostname`, `P`.`processor_descr`';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
$sql = "SELECT * $sql";
|
||||
foreach (dbFetchRows($sql,$param) as $processor) {
|
||||
$perc = round($processor['processor_usage'], 0);
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $processor['processor_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = "20";
|
||||
$graph_array['width'] = "80";
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = "150";
|
||||
$graph_array_zoom['width'] = "400";
|
||||
$link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/";
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, $perc."%", "ffffff", $background['left'], (100 - $perc)."%" , "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL);
|
||||
|
||||
$response[] = array('hostname' => generate_device_link($processor),
|
||||
'processor_descr' => $processor['processor_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'processor_usage' => $bar_link);
|
||||
if ($_POST['view'] == "graphs") {
|
||||
$graph_array['height'] = "100";
|
||||
$graph_array['width'] = "216";
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $processor['processor_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$return_data = true;
|
||||
include("includes/print-graphrow.inc.php");
|
||||
unset($return_data);
|
||||
$response[] = array('hostname' => $graph_data[0],
|
||||
'processor_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'processor_usage' => $graph_data[3]);
|
||||
} # endif graphs
|
||||
}
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$sql = "SELECT * $sql";
|
||||
foreach (dbFetchRows($sql, $param) as $processor) {
|
||||
$perc = round($processor['processor_usage'], 0);
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $processor['processor_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = '20';
|
||||
$graph_array['width'] = '80';
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = '150';
|
||||
$graph_array_zoom['width'] = '400';
|
||||
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, $perc.'%', 'ffffff', $background['left'], (100 - $perc).'%', 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
|
||||
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($processor),
|
||||
'processor_descr' => $processor['processor_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'processor_usage' => $bar_link,
|
||||
);
|
||||
if ($_POST['view'] == 'graphs') {
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '216';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $processor['processor_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$return_data = true;
|
||||
include 'includes/print-graphrow.inc.php';
|
||||
unset($return_data);
|
||||
$response[] = array(
|
||||
'hostname' => $graph_data[0],
|
||||
'processor_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'processor_usage' => $graph_data[3],
|
||||
);
|
||||
} //end if
|
||||
}//end foreach
|
||||
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
$graph_type = "storage_usage";
|
||||
$graph_type = 'storage_usage';
|
||||
|
||||
$where = 1;
|
||||
|
||||
$sql = " FROM `storage` AS `S` LEFT JOIN `devices` AS `D` ON `S`.`device_id` = `D`.`device_id`";
|
||||
$sql = ' FROM `storage` AS `S` LEFT JOIN `devices` AS `D` ON `S`.`device_id` = `D`.`device_id`';
|
||||
|
||||
if (is_admin() === FALSE && is_read() === FALSE) {
|
||||
$sql .= " LEFT JOIN `devices_perms` AS `DP` ON `S`.`device_id` = `DP`.`device_id`";
|
||||
$where .= " AND `DP`.`user_id`=?";
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `S`.`device_id` = `DP`.`device_id`';
|
||||
$where .= ' AND `DP`.`user_id`=?';
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) {
|
||||
|
||||
$count_sql = "SELECT COUNT(`storage_id`) $sql";
|
||||
|
||||
$count = dbFetchCell($count_sql,$param);
|
||||
$count = dbFetchCell($count_sql, $param);
|
||||
if (empty($count)) {
|
||||
$count = 0;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -42,50 +42,57 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT * $sql";
|
||||
|
||||
foreach (dbFetchRows($sql,$param) as $drive) {
|
||||
foreach (dbFetchRows($sql, $param) as $drive) {
|
||||
$perc = round($drive['storage_perc'], 0);
|
||||
$total = formatStorage($drive['storage_size']);
|
||||
$free = formatStorage($drive['storage_free']);
|
||||
$used = formatStorage($drive['storage_used']);
|
||||
|
||||
$perc = round($drive['storage_perc'], 0);
|
||||
$total = formatStorage($drive['storage_size']);
|
||||
$free = formatStorage($drive['storage_free']);
|
||||
$used = formatStorage($drive['storage_used']);
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $drive['storage_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = '20';
|
||||
$graph_array['width'] = '80';
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = '150';
|
||||
$graph_array_zoom['width'] = '400';
|
||||
$link = 'graphs/id='.$graph_array['id'].'/type='.$graph_array['type'].'/from='.$graph_array['from'].'/to='.$graph_array['to'].'/';
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), null);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar(400, 20, $perc, "$used / $total", 'ffffff', $background['left'], $free, 'ffffff', $background['right']), generate_graph_tag($graph_array_zoom), null);
|
||||
|
||||
$graph_array['type'] = $graph_type;
|
||||
$graph_array['id'] = $drive['storage_id'];
|
||||
$graph_array['from'] = $config['time']['day'];
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['height'] = "20";
|
||||
$graph_array['width'] = "80";
|
||||
$graph_array_zoom = $graph_array;
|
||||
$graph_array_zoom['height'] = "150";
|
||||
$graph_array_zoom['width'] = "400";
|
||||
$link = "graphs/id=" . $graph_array['id'] . "/type=" . $graph_array['type'] . "/from=" . $graph_array['from'] . "/to=" . $graph_array['to'] . "/";
|
||||
$mini_graph = overlib_link($link, generate_graph_tag($graph_array), generate_graph_tag($graph_array_zoom), NULL);
|
||||
$background = get_percentage_colours($perc);
|
||||
$bar_link = overlib_link($link, print_percentage_bar (400, 20, $perc, "$used / $total", "ffffff", $background['left'], $free, "ffffff", $background['right']), generate_graph_tag($graph_array_zoom), NULL);
|
||||
$response[] = array(
|
||||
'hostname' => generate_device_link($drive),
|
||||
'storage_descr' => $drive['storage_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'storage_used' => $bar_link,
|
||||
'storage_perc' => $perc.'%',
|
||||
);
|
||||
if ($_POST['view'] == 'graphs') {
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '216';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $drive['storage_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
|
||||
$response[] = array('hostname' => generate_device_link($drive),
|
||||
'storage_descr' => $drive['storage_descr'],
|
||||
'graph' => $mini_graph,
|
||||
'storage_used' => $bar_link,
|
||||
'storage_perc' => $perc . "%");
|
||||
if ($_POST['view'] == "graphs") {
|
||||
$graph_array['height'] = "100";
|
||||
$graph_array['width'] = "216";
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $drive['storage_id'];
|
||||
$graph_array['type'] = $graph_type;
|
||||
$return_data = true;
|
||||
include 'includes/print-graphrow.inc.php';
|
||||
unset($return_data);
|
||||
$response[] = array(
|
||||
'hostname' => $graph_data[0],
|
||||
'storage_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'storage_used' => $graph_data[3],
|
||||
'storage_perc' => '',
|
||||
);
|
||||
} //end if
|
||||
}//end foreach
|
||||
|
||||
$return_data = true;
|
||||
include("includes/print-graphrow.inc.php");
|
||||
unset($return_data);
|
||||
$response[] = array('hostname' => $graph_data[0],
|
||||
'storage_descr' => $graph_data[1],
|
||||
'graph' => $graph_data[2],
|
||||
'storage_used' => $graph_data[3],
|
||||
'storage_perc' => '');
|
||||
|
||||
} # endif graphs
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$count);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $count,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
|
||||
@@ -1,46 +1,44 @@
|
||||
<?php
|
||||
|
||||
$where = "1";
|
||||
$where = '1';
|
||||
|
||||
if (!empty($_POST['searchPhrase']))
|
||||
{
|
||||
$where .= ' AND S.msg LIKE "%'.mres($_POST['searchPhrase']).'%"';
|
||||
if (!empty($_POST['searchPhrase'])) {
|
||||
$where .= ' AND S.msg LIKE "%'.mres($_POST['searchPhrase']).'%"';
|
||||
}
|
||||
|
||||
if ($_POST['program'])
|
||||
{
|
||||
$where .= " AND S.program = ?";
|
||||
$param[] = $_POST['program'];
|
||||
if ($_POST['program']) {
|
||||
$where .= ' AND S.program = ?';
|
||||
$param[] = $_POST['program'];
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['device']))
|
||||
{
|
||||
$where .= " AND S.device_id = ?";
|
||||
$param[] = $_POST['device'];
|
||||
if (is_numeric($_POST['device'])) {
|
||||
$where .= ' AND S.device_id = ?';
|
||||
$param[] = $_POST['device'];
|
||||
}
|
||||
|
||||
if( !empty($_POST['from']) ) {
|
||||
$where .= " AND timestamp >= ?";
|
||||
$param[] = $_POST['from'];
|
||||
}
|
||||
if( !empty($_POST['to']) ) {
|
||||
$where .= " AND timestamp <= ?";
|
||||
$param[] = $_POST['to'];
|
||||
if (!empty($_POST['from'])) {
|
||||
$where .= ' AND timestamp >= ?';
|
||||
$param[] = $_POST['from'];
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5')
|
||||
{
|
||||
$sql = "FROM syslog AS S";
|
||||
$sql .= " WHERE ".$where;
|
||||
} else {
|
||||
$sql = "FROM syslog AS S, devices_perms AS P";
|
||||
$sql .= "WHERE S.device_id = P.device_id AND P.user_id = ?";
|
||||
$sql .= $where;
|
||||
$param = array_merge(array($_SESSION['user_id']), $param);
|
||||
if (!empty($_POST['to'])) {
|
||||
$where .= ' AND timestamp <= ?';
|
||||
$param[] = $_POST['to'];
|
||||
}
|
||||
|
||||
if ($_SESSION['userlevel'] >= '5') {
|
||||
$sql = 'FROM syslog AS S';
|
||||
$sql .= ' WHERE '.$where;
|
||||
}
|
||||
else {
|
||||
$sql = 'FROM syslog AS S, devices_perms AS P';
|
||||
$sql .= 'WHERE S.device_id = P.device_id AND P.user_id = ?';
|
||||
$sql .= $where;
|
||||
$param = array_merge(array($_SESSION['user_id']), $param);
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(timestamp) $sql";
|
||||
$total = dbFetchCell($count_sql,$param);
|
||||
$total = dbFetchCell($count_sql, $param);
|
||||
if (empty($total)) {
|
||||
$total = 0;
|
||||
}
|
||||
@@ -52,7 +50,7 @@ if (!isset($sort) || empty($sort)) {
|
||||
$sql .= " ORDER BY $sort";
|
||||
|
||||
if (isset($current)) {
|
||||
$limit_low = ($current * $rowCount) - ($rowCount);
|
||||
$limit_low = (($current * $rowCount) - ($rowCount));
|
||||
$limit_high = $rowCount;
|
||||
}
|
||||
|
||||
@@ -62,14 +60,20 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT S.*, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date $sql";
|
||||
|
||||
foreach (dbFetchRows($sql,$param) as $syslog) {
|
||||
$dev = device_by_id_cache($syslog['device_id']);
|
||||
$response[] = array('timestamp'=>$syslog['date'],
|
||||
'device_id'=>generate_device_link($dev, shorthost($dev['hostname'])),
|
||||
'program'=>$syslog['program'],
|
||||
'msg'=>htmlspecialchars($syslog['msg']));
|
||||
foreach (dbFetchRows($sql, $param) as $syslog) {
|
||||
$dev = device_by_id_cache($syslog['device_id']);
|
||||
$response[] = array(
|
||||
'timestamp' => $syslog['date'],
|
||||
'device_id' => generate_device_link($dev, shorthost($dev['hostname'])),
|
||||
'program' => $syslog['program'],
|
||||
'msg' => htmlspecialchars($syslog['msg']),
|
||||
);
|
||||
}
|
||||
|
||||
$output = array('current'=>$current,'rowCount'=>$rowCount,'rows'=>$response,'total'=>$total);
|
||||
$output = array(
|
||||
'current' => $current,
|
||||
'rowCount' => $rowCount,
|
||||
'rows' => $response,
|
||||
'total' => $total,
|
||||
);
|
||||
echo _json_encode($output);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user