commit version 22.12.12447

This commit is contained in:
2023-01-01 22:36:12 -05:00
parent af1b03d79f
commit b948283a96
744 changed files with 620715 additions and 27381 deletions

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -51,15 +50,15 @@ function print_addresses($vars)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'A.device_id');
$where_netscaler .= generate_query_values($value, 'N.device_id');
$where .= generate_query_values_and($value, 'A.device_id');
$where_netscaler .= generate_query_values_and($value, 'N.device_id');
break;
case 'interface':
$where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
$where .= generate_query_values_and($value, 'I.ifDescr', 'LIKE%');
$join_ports = TRUE;
break;
case 'type':
$where .= generate_query_values($value, 'A.ip_type');
$where .= generate_query_values_and($value, 'A.ip_type');
break;
case 'network':
if (!is_array($value))
@ -69,7 +68,7 @@ function print_addresses($vars)
if ($ids = get_entity_ids_ip_by_network($address_type, $value))
{
// Full network with prefix
$where .= generate_query_values($ids, 'A.ip_address_id');
$where .= generate_query_values_and($ids, 'A.ip_address_id');
} else {
// Part of network string
$where .= ' AND 0'; // Nothing!
@ -87,16 +86,16 @@ function print_addresses($vars)
}
if ($ids = get_entity_ids_ip_by_network($address_type, $addr)) {
// Full network with prefix
$where .= generate_query_values($ids, 'A.ip_address_id');
$where .= generate_query_values_and($ids, 'A.ip_address_id');
} else {
$where .= ' AND 0'; // Nothing!
}
/// FIXME. Netscaller hack
if (count($addr) && get_ip_version($addr[0])) {
// Netscaller for valid IP address
$where_netscaler .= generate_query_values($addr, 'N.vsvr_ip');
$where_netscaler .= generate_query_values_and($addr, 'N.vsvr_ip');
} else {
$where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%');
$where_netscaler .= generate_query_values_and($addr, 'N.vsvr_ip', '%LIKE%');
}
break;
}

View File

@ -30,18 +30,18 @@ function build_alert_table_query($vars) {
switch ($var) {
// Search by device_id if we have a device or device_id
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'entity_type':
if ($value !== 'all') {
$where .= generate_query_values($value, 'entity_type');
$where .= generate_query_values_and($value, 'entity_type');
}
break;
case 'entity_id':
$where .= generate_query_values($value, 'entity_id');
$where .= generate_query_values_and($value, 'entity_id');
break;
case 'alert_test_id':
$where .= generate_query_values($value, 'alert_test_id');
$where .= generate_query_values_and($value, 'alert_test_id');
break;
case 'status':
if ($value === 'failed_delayed') {

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -77,35 +77,42 @@ function print_alert_log($vars)
// Functionize?
// Set colours and classes based on the status of the alert
if ($entry['log_type'] == 'OK')
{
$entry['class'] = "green"; $entry['html_row_class'] = "success";
} else if ($entry['log_type'] == 'RECOVER_NOTIFY') {
$entry['class'] = "green"; $entry['html_row_class'] = "info";
} else if ($entry['log_type'] == 'ALERT_NOTIFY') {
$entry['class'] = "red"; $entry['html_row_class'] = "error";
} elseif($entry['log_type'] == 'FAIL') {
$entry['class'] = "red"; $entry['html_row_class'] = "error";
} elseif($entry['log_type'] == 'FAIL_DELAYED') {
$entry['class'] = "purple"; $entry['html_row_class'] = "warning";
} elseif($entry['log_type'] == 'FAIL_SUPPRESSED') {
$entry['class'] = "purple"; $entry['html_row_class'] = "suppressed";
} elseif($entry['log_type'] == 'RECOVER_SUPPRESSED') {
$entry['class'] = "purple"; $entry['html_row_class'] = "suppressed";
} else {
// Anything else set the colour to grey and the class to disabled.
$entry['class'] = "gray"; $entry['html_row_class'] = "disabled";
switch ($entry['log_type']) {
case 'OK':
$entry['class'] = "green";
$entry['html_row_class'] = "success";
break;
case 'RECOVER_NOTIFY':
$entry['class'] = "green";
$entry['html_row_class'] = "info";
break;
case 'ALERT_NOTIFY':
case 'FAIL':
$entry['class'] = "red";
$entry['html_row_class'] = "error";
break;
case 'FAIL_DELAYED':
$entry['class'] = "purple";
$entry['html_row_class'] = "warning";
break;
case 'FAIL_SUPPRESSED':
case 'RECOVER_SUPPRESSED':
$entry['class'] = "purple";
$entry['html_row_class'] = "suppressed";
break;
default:
// Anything else set the colour to grey and the class to disabled.
$entry['class'] = "gray";
$entry['html_row_class'] = "disabled";
}
$string .= ' <tr class="'.$entry['html_row_class'].'">' . PHP_EOL;
$string .= '<td class="state-marker"></td>' . PHP_EOL;
if ($events['short'])
{
$string .= ' <td class="syslog" style="white-space: nowrap">';
$timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
$string .= generate_tooltip_link('', format_uptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
if ($events['short']) {
$string .= ' <td class="syslog text-nowrap">';
$string .= generate_tooltip_time($entry['timestamp']) . '</td>' . PHP_EOL;
} else {
$string .= ' <td>';
$string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
@ -217,26 +224,26 @@ function get_alert_log($vars)
switch ($var)
{
// case 'alert_entry':
// $where .= generate_query_values($value, 'alert_table_id');
// $where .= generate_query_values_and($value, 'alert_table_id');
// break;
case 'log_type':
$where .= generate_query_values($value, 'log_type');
$where .= generate_query_values_and($value, 'log_type');
break;
case 'alert_test_id':
$where .= generate_query_values($value, 'alert_test_id');
$where .= generate_query_values_and($value, 'alert_test_id');
break;
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'entity_id':
$where .= generate_query_values($value, 'entity_id');
$where .= generate_query_values_and($value, 'entity_id');
break;
case 'entity_type':
$where .= generate_query_values($value, 'entity_type');
$where .= generate_query_values_and($value, 'entity_type');
break;
case 'message':
$where .= generate_query_values($value, 'message', '%LIKE%');
$where .= generate_query_values_and($value, 'message', '%LIKE%');
break;
case 'timestamp_from':
$where .= ' AND `timestamp` >= ?';

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -38,33 +38,32 @@ function print_arptable($vars)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'port':
case 'port_id':
$where .= generate_query_values($value, 'I.port_id');
$where .= generate_query_values_and($value, 'I.port_id');
break;
case 'ip_version':
$where .= generate_query_values($value, 'ip_version');
$where .= generate_query_values_and($value, 'ip_version');
break;
case 'address':
if (isset($vars['searchby']) && $vars['searchby'] == 'ip')
if (isset($vars['searchby']) && $vars['searchby'] === 'ip')
{
$value = trim($value);
if (strpos($value, ':') !== FALSE)
{
if (Net_IPv6::checkIPv6($value))
if (str_contains($value, ':')) {
if (get_ip_version($value) === 5)
{
$value = Net_IPv6::uncompress($value, TRUE);
$value = ip_uncompress($value);
} else {
// FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
}
}
$where .= generate_query_values($value, 'ip_address', '%LIKE%');
$where .= generate_query_values_and($value, 'ip_address', '%LIKE%');
} else {
// MAC Addresses
$value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
$where .= generate_query_values($value, 'mac_address', '%LIKE%');
$value = str_replace([ ':', ' ', '-', '.', '0x' ], '', $value);
$where .= generate_query_values_and($value, 'mac_address', '%LIKE%');
}
break;
}

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -150,20 +149,20 @@ function generate_authlog_where($vars)
case "user":
case "username":
if ($value == '') { continue 2; }
$sql .= generate_query_values($value, 'user');
$sql .= generate_query_values_and($value, 'user');
break;
case "address":
case "ip":
if ($value == '') { continue 2; }
$sql .= generate_query_values($value, 'address', '%LIKE%');
$sql .= generate_query_values_and($value, 'address', '%LIKE%');
break;
case "useragent":
case "user_agent":
$sql .= generate_query_values($value, 'user_agent', '%LIKE%');
$sql .= generate_query_values_and($value, 'user_agent', '%LIKE%');
break;
case "result":
//case "action":
$sql .= generate_query_values($value, 'result', 'LIKE%');
$sql .= generate_query_values_and($value, 'result', 'LIKE%');
break;
}
}

View File

@ -211,6 +211,114 @@ function print_refresh($vars)
return $return;
}
/**
* This generates an HTML <thead> element based on the contents of the $header array, modified by the current request $vars
*
* @param array $header Array with table header definition including columns and classes.
* @param array $vars Array with current selected column ID and/or variables for generate column link
* @return string $string
*/
function generate_table_header($header = [], $vars = []) {
// Store current $vars sort variables
$sort = $vars['sort'];
$sort_order = strtolower($vars['sort_order']);
if (!in_array($sort_order, array('asc', 'desc', 'reset'))) {
$sort_order = 'asc';
}
// Reset current $vars sort variables
unset($vars['sort'], $vars['sort_order']);
$output = '<thead'.(isset($header['class']) ? ' class="'.$header['class'].'"' : '').
(isset($header['style']) ? ' style="'.$header['style'].'"' : '').
(isset($vars['show_header']) && !$vars['show_header'] ? 'style="line-height: 0; visibility: collapse;"' : '') . '>';
$output .= ' <tr>' . PHP_EOL;
//r($header);
// Loop each column generating a <th> element
foreach($header AS $id => $col)
{
//if (in_array($id, ['class', 'group', 'style'])) { continue; } // skip html metadata
if ($id === 'class' || $id === 'style') { continue; } // skip html data
$fields = []; // Empty array for fields
if(empty($col) || !is_array($col)) { $col = [ $id => $col ]; } // If col is not an array, make it one
if($id == 'state-marker') { $col['class'] = 'state-marker'; } // Hard code handling of state-marker
// Loop each field and generate an <a> element
foreach ($col as $field_id => $field) {
if ($field_id === 'class' || $field_id === 'style' || $field_id == 'subfields') { continue; } // skip html data
$header_field = generate_table_header_field($field_id, $field, $vars, $sort, $sort_order);
if(strlen($header_field) > 0) {
$fields[] = $header_field;
}
}
$output .= ' <th'.( isset($col['class']) ? ' class="'.$col['class'].'"' : '').'>';
$output .= implode(' / ', $fields);
$output .= '</th>' . PHP_EOL;
}
$output .= ' </tr>' . PHP_EOL;
$output .= ' </thead>' . PHP_EOL;
return $output;
}
function generate_table_header_field($field_id, $field, $vars, $sort, $sort_order)
{
if(empty($field)) { // No label, generate empty column header.
$return = '';
} elseif ( is_numeric($field_id) && !is_array($field)) { // Label without id, generate simple column header
$return = $field;
} else {
if(!is_array($field)) { $field = [ 'label' => $field ]; }
if(!isset($field['label'])) { $field['label'] = $field[0]; }
if($sort == $field_id) {
$field['label'] = '<span class="text-primary" style="font-style: italic">'.$field['label'].'</span>';
if($sort_order == 'asc') {
$new_vars = [ 'sort' => $field_id, 'sort_order' => 'desc' ];
$field['caret'] = '&nbsp;<i class="text-primary small glyphicon glyphicon-arrow-up"></i>';
} else {
$new_vars = [ 'sort' => NULL, 'sort_order' => NULL ];
$field['caret'] = '&nbsp;<i class="text-primary small glyphicon glyphicon-arrow-down"></i>';
}
} else {
$new_vars = [ 'sort' => $field_id ];
}
$return = '<a href="'.generate_url($vars, $new_vars).'">'.$field['label'].$field['caret'].'</a>';
// Generate slash separated links for subfields
if(isset($field['subfields']))
{
foreach($field['subfields'] as $subfield_id => $subfield)
{
//r($subfield); r($subfield_id);
$subfields[] = generate_table_header_field($subfield_id, $subfield, $vars, $sort, $sort_order);
}
$return .= ' ['.implode(" / ", $subfields).']';
}
}
return $return;
}
/**
* Helper function for generate table header with sort links
* This used in other print_* functions

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -37,19 +36,19 @@ function print_dot1xtable($vars)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'address':
if (isset($vars['searchby']) && $vars['searchby'] == 'ip')
if (isset($vars['searchby']) && $vars['searchby'] === 'ip')
{
$value = trim($value);
$where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
} else if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
$value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
$where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
$where .= generate_query_values_and($value, 'ipv4_addr', '%LIKE%');
} elseif (isset($vars['searchby']) && $vars['searchby'] === 'mac') {
$value = str_replace([ ':', ' ', '-', '.', '0x' ], '', $value);
$where .= generate_query_values_and($value, 'M.mac_addr', '%LIKE%');
} else {
$value = trim($value);
$where .= generate_query_values($value, 'username', '%LIKE%');
$where .= generate_query_values_and($value, 'username', '%LIKE%');
}
break;
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -90,9 +90,8 @@ function print_events($vars) {
$string .= '<td class="state-marker"></td>' . PHP_EOL;
if ($events['short']) {
$string .= ' <td class="syslog" style="white-space: nowrap">';
$timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
$string .= generate_tooltip_link('', format_uptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
$string .= ' <td class="syslog text-nowrap">';
$string .= generate_tooltip_time($entry['timestamp']) . '</td>' . PHP_EOL;
} else {
$string .= ' <td style="width: 160px">';
$string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
@ -215,22 +214,22 @@ function get_events_array($vars)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'port':
case 'entity':
case 'entity_id':
$where .= generate_query_values($value, 'entity_id');
$where .= generate_query_values_and($value, 'entity_id');
break;
case 'severity':
$where .= generate_query_values($value, 'severity');
$where .= generate_query_values_and($value, 'severity');
break;
case 'type':
case 'entity_type':
$where .= generate_query_values($value, 'entity_type');
$where .= generate_query_values_and($value, 'entity_type');
break;
case 'message':
$where .= generate_query_values($value, 'message', '%LIKE%');
$where .= generate_query_values_and($value, 'message', '%LIKE%');
break;
case 'timestamp_from':
$where .= ' AND `timestamp` >= ?';
@ -243,8 +242,8 @@ function get_events_array($vars)
case "group":
case "group_id":
$values = get_group_entities($value);
$where .= generate_query_values($values, 'entity_id');
$where .= generate_query_values(get_group_entity_type($value), 'entity_type');
$where .= generate_query_values_and($values, 'entity_id');
$where .= generate_query_values_and(get_group_entity_type($value), 'entity_type');
break;
}
}

View File

@ -18,6 +18,7 @@
*
*/
function print_fdbtable($vars) {
//r($vars);
$entries = get_fdbtable_array($vars);
if (!$entries['count']) {
@ -27,8 +28,13 @@ function print_fdbtable($vars) {
}
$list = array('device' => FALSE, 'port' => FALSE);
if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] === 'search') { $list['device'] = TRUE; }
if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] === 'search') { $list['port'] = TRUE; }
if (!isset($vars['device']) || is_array($vars['device']) || empty($vars['device']) || $vars['page'] === 'search') { $list['device'] = TRUE; }
if (!isset($vars['port']) || is_array($vars['port']) || empty($vars['port']) || $vars['page'] === 'search') { $list['port'] = TRUE; }
//r($list);
$string = generate_box_open();
@ -119,50 +125,54 @@ function get_fdbtable_array($vars) {
// Do not show deleted entries by default
$vars['deleted'] = 0;
}
//r($vars);
foreach ($vars as $var => $value) {
if ($value != '') {
switch ($var) {
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'F.device_id');
break;
case 'port':
case 'port_id':
$where .= generate_query_values($value, 'F.port_id');
break;
case 'interface':
case 'port_name':
$where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
// Skip empty variables (and array with empty first entry) when building query
if ($value == '' || (is_array($value) && count($value) == 1 && $value[0] == '')) { continue; }
switch ($var) {
case 'device':
case 'device_id':
$where .= generate_query_values_and($value, 'F.device_id');
break;
case 'port':
case 'port_id':
$where .= generate_query_values_and($value, 'F.port_id');
break;
case 'interface':
case 'port_name':
$where .= generate_query_values_and($value, 'I.ifDescr', 'LIKE%');
$join_ports = TRUE;
break;
case 'trunk':
if (get_var_true($value)) {
$where .= " AND (`I`.`ifTrunk` IS NOT NULL AND `I`.`ifTrunk` != '')";
$join_ports = TRUE;
break;
case 'trunk':
if (get_var_true($value)) {
$where .= " AND (`I`.`ifTrunk` IS NOT NULL AND `I`.`ifTrunk` != '')";
$join_ports = TRUE;
} elseif (in_array($value, [ 'none', 'no', '0' ])) {
$where .= " AND (`I`.`ifTrunk` IS NULL OR `I`.`ifTrunk` = '')";
$join_ports = TRUE;
}
break;
case 'vlan_id':
$where .= generate_query_values($value, 'F.vlan_id');
break;
case 'vlan_name':
$where .= generate_query_values($value, 'V.vlan_name');
break;
case 'address':
if (str_contains_array($value, [ '*', '?' ])) {
$like = 'LIKE';
} else {
$like = '%LIKE%';
}
$where .= generate_query_values(str_replace([ ':', ' ', '-', '.', '0x' ],'', $value), 'F.mac_address', $like);
break;
case 'deleted':
$where .= ' AND `deleted` = ?';
$params[] = $value;
}
}
else if (in_array($value, ['none', 'no', '0'])) {
$where .= " AND (`I`.`ifTrunk` IS NULL OR `I`.`ifTrunk` = '')";
$join_ports = TRUE;
}
break;
case 'vlan_id':
$where .= generate_query_values_and($value, 'F.vlan_id');
break;
case 'vlan_name':
$where .= generate_query_values_and($value, 'V.vlan_name');
break;
case 'address':
if (str_contains_array($value, ['*', '?'])) {
$like = 'LIKE';
}
else {
$like = '%LIKE%';
}
$where .= generate_query_values_and(str_replace([':', ' ', '-', '.', '0x'], '', $value), 'F.mac_address', $like);
break;
case 'deleted':
$where .= ' AND `deleted` = ?';
$params[] = $value;
}
}
@ -206,6 +216,9 @@ function get_fdbtable_array($vars) {
$query .= $sort;
$query .= " LIMIT $start,$pagesize";
//r($query);
//r($params);
// Query addresses
//$array['entries'] = dbFetchRows($query, $params, TRUE);
$array['entries'] = dbFetchRows($query, $params);

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -28,31 +28,31 @@ function generate_inventory_query($vars) {
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'os':
$where .= generate_query_values($value, 'os');
$where .= generate_query_values_and($value, 'os');
$select[] = 'devices.os';
$devices = TRUE;
break;
case 'parts':
case 'entPhysicalModelName':
$where .= generate_query_values($value, 'entPhysicalModelName', 'LIKE');
$where .= generate_query_values_and($value, 'entPhysicalModelName', 'LIKE');
break;
case 'serial':
case 'entPhysicalSerialNum':
$where .= generate_query_values($value, 'entPhysicalSerialNum', '%LIKE%');
$where .= generate_query_values_and($value, 'entPhysicalSerialNum', '%LIKE%');
break;
case 'description':
case 'entPhysicalDescr':
$where .= generate_query_values($value, 'entPhysicalDescr', '%LIKE%');
$where .= generate_query_values_and($value, 'entPhysicalDescr', '%LIKE%');
break;
case 'class':
case 'entPhysicalClass':
$where .= generate_query_values($value, 'entPhysicalClass', '%LIKE%');
$where .= generate_query_values_and($value, 'entPhysicalClass', '%LIKE%');
break;
case 'deleted':
$where .= generate_query_values($value, 'deleted', 'NOT NULL');
$where .= generate_query_values_and($value, 'deleted', 'NOT NULL');
break;
}
}
@ -371,15 +371,15 @@ relay
// vendor + model + hw
$ent_model = '';
if ($ent['entPhysicalModelName'] && !in_array($ent['entPhysicalModelName'], [ 'N/A' ])) {
if ($ent['entPhysicalMfgName'] && !in_array($ent['entPhysicalMfgName'], [ 'N/A' ])) {
if ($ent['entPhysicalModelName'] && is_valid_param($ent['entPhysicalModelName'], 'hardware')) {
if ($ent['entPhysicalMfgName'] && is_valid_param($ent['entPhysicalMfgName'], 'vendor')) {
$ent_model .= $ent['entPhysicalMfgName'];
}
$ent_model .= ' ' . $ent['entPhysicalModelName'];
if ($ent['entPhysicalHardwareRev'] && !in_array($ent['entPhysicalHardwareRev'], [ 'N/A' ])) {
$ent_model .= " ${ent['entPhysicalHardwareRev']}";
if ($ent['entPhysicalHardwareRev'] && is_valid_param($ent['entPhysicalHardwareRev'], 'revision')) {
$ent_model .= " " . $ent['entPhysicalHardwareRev'];
}
$ent_model = trim($ent_model);
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2020 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -113,17 +113,17 @@ function get_logalert_log($vars)
switch ($var)
{
case 'la_id':
$where .= generate_query_values($value, 'la_id');
$where .= generate_query_values_and($value, 'la_id');
break;
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'program':
$where .= generate_query_values($value, 'program', '%LIKE%');
$where .= generate_query_values_and($value, 'program', '%LIKE%');
break;
case 'message':
$where .= generate_query_values($value, 'message', '%LIKE%');
$where .= generate_query_values_and($value, 'message', '%LIKE%');
break;
case 'timestamp_from':
$where .= ' AND `timestamp` >= ?';

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -39,14 +38,14 @@ function print_mac_addresses($vars)
{
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'interface':
$where .= generate_query_values($value, 'ifDescr', 'LIKE');
$where .= generate_query_values_and($value, 'ifDescr', 'LIKE');
break;
case 'address':
$value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
$where .= generate_query_values($value, 'ifPhysAddress', '%LIKE%');
$value = str_replace([ ':', ' ', '-', '.', '0x' ], '', $value);
$where .= generate_query_values_and($value, 'ifPhysAddress', '%LIKE%');
break;
}
}

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -312,13 +312,12 @@ function navbar_location_menu($array) {
}
// DOCME needs phpdoc block
function navbar_submenu($entry, $level = 1)
{
function navbar_submenu($entry, $level = 1) {
if(isset($entry['text'])) { $entry['title'] = $entry['text']; }
if (isset($entry['text'])) { $entry['title'] = $entry['text']; }
// autoscroll set by navbar-narrow + dropdown-menu, but override max-height
echo(str_pad('',($level-1)*2) . ' <li class="dropdown-submenu">' . generate_menu_link($entry['url'], '<i class="' . $entry['icon'] . '"></i>&nbsp;' . $entry['title'], $entry['count'], 'label', NULL, $entry['alert_count']) . PHP_EOL);
echo(str_pad('',($level-1)*2) . ' <li class="dropdown-submenu">' . generate_menu_link($entry['url'], '<i class="' . $entry['icon'] . '"></i>&nbsp;' . escape_html($entry['title']), $entry['count'], 'label', NULL, $entry['alert_count']) . PHP_EOL);
echo(str_pad('',($level-1)*2) . ' <ul role="menu" class="dropdown-menu" style="max-height: 85vh;">' . PHP_EOL);
foreach ($entry['entries'] as $subentry) {
@ -369,14 +368,20 @@ function navbar_entry($entry, $level = 1) {
}
if (isset($entry['title'])) {
$entry_text .= $entry['title'];
$entry_text .= escape_html($entry['title']);
} elseif (isset($entry['text'])) {
$entry_text .= $entry['text'];
$entry_text .= escape_html($entry['text']);
}
if (isset($entry['class'])) {
$entry_class = ' class="'.$entry['class'].'"';
} else {
$entry_class = '';
}
$entry['text'] = $entry_text;
echo(str_pad('',($level-1)*2) . ' <li>' . generate_menu_link_new($entry) . '</li>' . PHP_EOL);
echo(str_pad('',($level-1)*2) . ' <li '.$entry_class.'>' . generate_menu_link_new($entry) . '</li>' . PHP_EOL);
}
}

View File

@ -1,5 +1,4 @@
<?php
/**
* Observium
*
@ -7,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -177,31 +176,33 @@ function get_neighbours_array($vars)
if ($value != '') {
switch ($var) {
case 'device':
case 'device_id':
case 'device_a':
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'port':
case 'port_id':
case 'port_a':
$where .= generate_query_values($value, 'port_id');
$where .= generate_query_values_and($value, 'port_id');
break;
case 'device_b':
$where .= generate_query_values($value, 'remote_hostname');
$where .= generate_query_values_and($value, 'remote_hostname');
break;
case 'port_b':
$where .= generate_query_values($value, 'remote_port');
$where .= generate_query_values_and($value, 'remote_port');
break;
case 'protocol':
$where .= generate_query_values($value, 'protocol');
$where .= generate_query_values_and($value, 'protocol');
break;
case 'platform':
$where .= generate_query_values($value, 'remote_platform');
$where .= generate_query_values_and($value, 'remote_platform');
break;
case 'version':
$where .= generate_query_values($value, 'remote_version');
$where .= generate_query_values_and($value, 'remote_version');
break;
case 'active':
$value = $value && $value != 'no' ? '1' : '0';
$where .= generate_query_values($value, 'active');
$value = !get_var_false($value, 'no') ? '1' : '0';
$where .= generate_query_values_and($value, 'active');
break;
case 'remote_port_id':
if ($value === 'NULL' || $value == 0) {

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -26,211 +26,198 @@
*
*/
function print_bgp_peer_table($vars) {
// Get bgp peers array
$entries = get_bgp_array($vars);
//r($entries);
if (!$entries['count']) {
// There have been no entries returned. Print the warning.
print_warning('<h4>No BGP peers found!</h4>');
return;
$entries = get_bgp_array($vars);
//r($entries);
if (!$entries['count']) {
// There have been no entries returned. Print the warning.
print_warning('<h4>No BGP peers found!</h4>');
return;
}
// Entries have been returned. Print the table.
$list = [ 'device' => FALSE ];
if ($vars['page'] !== 'device') {
$list['device'] = TRUE;
}
switch ($vars['graph']) {
case 'prefixes_ipv4unicast':
case 'prefixes_ipv4multicast':
case 'prefixes_ipv4vpn':
case 'prefixes_ipv6unicast':
case 'prefixes_ipv6multicast':
case 'macaccounting_bits':
case 'macaccounting_pkts':
case 'updates':
$table_class = 'table-striped-two';
$list['graph'] = TRUE;
break;
default:
$table_class = 'table-striped';
$list['graph'] = FALSE;
}
$string = generate_box_open();
$string .= '<table class="table ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL;
$cols = [
[ NULL, 'class="state-marker"' ],
[ NULL, 'style="width: 1px;"' ],
'device' => [ 'Local address', 'style="width: 150px;"' ],
'local_as' => [ 'Local AS / VRF', 'style="width: 110px;"' ],
[ NULL, 'style="width: 20px;"' ],
'peer_ip' => [ 'Peer address', 'style="width: 150px;"' ],
'peer_as' => [ 'Remote AS', 'style="width: 90px;"' ],
'type' => [ 'Type', 'style="width: 50px;"' ],
[ 'Family', 'style="width: 50px;"' ],
'state' => 'State',
'uptime' => 'Uptime / Updates',
];
//if (!$list['device']) { unset($cols['device']); }
$string .= get_table_header($cols, $vars);
$string .= ' <tbody>' . PHP_EOL;
foreach ($entries['entries'] as $peer) {
$local_dev = device_by_id_cache($peer['device_id']);
$local_as = ($list['device'] ? ' (AS' . $peer['human_local_as'] . ')' : '');
$local_name = generate_device_link_short($local_dev, [ 'tab' => 'routing', 'proto' => 'bgp' ], 18);
$local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, [ 'tab' => 'routing', 'proto' => 'bgp' ]);
$peer_as = 'AS' . $peer['human_remote_as'];
if ($peer['peer_device_id']) {
$peer_dev = device_by_id_cache($peer['peer_device_id']);
$peer_name = generate_device_link_short($peer_dev, [ 'tab' => 'routing', 'proto' => 'bgp' ], 18);
} else {
$peer_name = $peer['reverse_dns'];
}
$peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
$peer_afis = &$entries['afisafi'][$peer['device_id']][$peer['bgpPeer_id']];
$peer_afis_html = [];
// Generate AFI/SAFI labels
foreach ($peer_afis as $peer_afi) {
// $peer_afi_html = '<span class="label-group">';
if (isset($GLOBALS['config']['routing_afis_name'][$peer_afi['afi']])) {
$afi_num = $GLOBALS['config']['routing_afis_name'][$peer_afi['afi']];
$afi_class = $GLOBALS['config']['routing_afis'][$afi_num]['class'];
} else {
$afi_class = 'default';
}
if (isset($GLOBALS['config']['routing_safis_name'][$peer_afi['safi']])) {
// Named SAFI
$safi_num = $GLOBALS['config']['routing_safis_name'][$peer_afi['safi']];
$safi_class = $GLOBALS['config']['routing_safis'][$safi_num]['class'];
} elseif (isset($GLOBALS['config']['routing_safis'][$peer_afi['safi']])) {
// Numeric SAFI
$safi_num = $peer_afi['safi'];
$peer_afi['safi'] = $GLOBALS['config']['routing_safis'][$safi_num]['name'];
$safi_class = $GLOBALS['config']['routing_safis'][$safi_num]['class'];
} else {
$safi_class = 'default';
}
$peer_afi_items = [
[ 'event' => $afi_class, 'text' => $peer_afi['afi'] ],
[ 'event' => $safi_class, 'text' => $peer_afi['safi'] ],
];
$peer_afi_html = get_label_group($peer_afi_items);
//r($peer_afi_html);
$peer_afis_html[] = $peer_afi_html;
}
// Entries have been returned. Print the table.
$list = array('device' => FALSE);
if ($vars['page'] !== 'device') {
$list['device'] = TRUE;
$string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
$string .= ' <td class="state-marker"></td>' . PHP_EOL;
$string .= ' <td></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL;
$string .= ' <td><strong><span class="label label-' . $peer['peer_local_class'] . '">AS' . $peer['human_local_as'] . '</span></strong>';
if (!safe_empty($peer['virtual_name'])) {
$vitual_type = isset($GLOBALS['config']['os'][$local_dev['os']]['snmp']['virtual_type']) ? nicecase($GLOBALS['config']['os'][$local_dev['os']]['snmp']['virtual_type']) : 'VRF';
$string .= '<br /><span class="label">'.$vitual_type.': '.$peer['virtual_name'].'</span>';
}
switch ($vars['graph']) {
case 'prefixes_ipv4unicast':
case 'prefixes_ipv4multicast':
case 'prefixes_ipv4vpn':
case 'prefixes_ipv6unicast':
case 'prefixes_ipv6multicast':
case 'macaccounting_bits':
case 'macaccounting_pkts':
case 'updates':
$table_class = 'table-striped-two';
$list['graph'] = TRUE;
break;
default:
$table_class = 'table-striped';
$list['graph'] = FALSE;
}
$string = generate_box_open();
$string .= '<table class="table ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL;
$cols = array(
array(NULL, 'class="state-marker"'),
array(NULL, 'style="width: 1px;"'),
'device' => array('Local address', 'style="width: 150px;"'),
'local_as' => [ 'Local AS / VRF', 'style="width: 110px;"' ],
array(NULL, 'style="width: 20px;"'),
'peer_ip' => array('Peer address', 'style="width: 150px;"'),
'peer_as' => [ 'Remote AS', 'style="width: 90px;"' ],
'type' => array('Type', 'style="width: 50px;"'),
array('Family', 'style="width: 50px;"'),
'state' => 'State',
'uptime' => 'Uptime / Updates',
);
//if (!$list['device']) { unset($cols['device']); }
$string .= get_table_header($cols, $vars);
$string .= ' <tbody>' . PHP_EOL;
foreach ($entries['entries'] as $peer)
{
$local_dev = device_by_id_cache($peer['device_id']);
$local_as = ($list['device'] ? ' (AS' . $peer['human_local_as'] . ')' : '');
$local_name = generate_device_link_short($local_dev, [ 'tab' => 'routing', 'proto' => 'bgp' ], 18);
$local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, array('tab' => 'routing', 'proto' => 'bgp'));
$peer_as = 'AS' . $peer['human_remote_as'];
if ($peer['peer_device_id']) {
$peer_dev = device_by_id_cache($peer['peer_device_id']);
$peer_name = generate_device_link_short($peer_dev, [ 'tab' => 'routing', 'proto' => 'bgp' ], 18);
} else {
$peer_name = $peer['reverse_dns'];
}
$peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
$peer_afis = &$entries['afisafi'][$peer['device_id']][$peer['bgpPeer_id']];
$peer_afis_html = array();
// Generate AFI/SAFI labels
foreach ($peer_afis as $peer_afi)
{
// $peer_afi_html = '<span class="label-group">';
if (isset($GLOBALS['config']['routing_afis_name'][$peer_afi['afi']]))
{
$afi_num = $GLOBALS['config']['routing_afis_name'][$peer_afi['afi']];
$afi_class = $GLOBALS['config']['routing_afis'][$afi_num]['class'];
} else {
$afi_class = 'default';
}
if (isset($GLOBALS['config']['routing_safis_name'][$peer_afi['safi']]))
{
// Named SAFI
$safi_num = $GLOBALS['config']['routing_safis_name'][$peer_afi['safi']];
$safi_class = $GLOBALS['config']['routing_safis'][$safi_num]['class'];
}
else if (isset($GLOBALS['config']['routing_safis'][$peer_afi['safi']]))
{
// Numeric SAFI
$safi_num = $peer_afi['safi'];
$peer_afi['safi'] = $GLOBALS['config']['routing_safis'][$safi_num]['name'];
$safi_class = $GLOBALS['config']['routing_safis'][$safi_num]['class'];
} else {
$safi_class = 'default';
}
// $peer_afi_html .= '<span class="label label-' . $afi_class . '">' . $peer_afi['afi'] . '</span>';
// $peer_afi_html .= '<span class="label label-' . $safi_class . '">' . $peer_afi['safi'] . '</span>';
// $peer_afi_html .= '</span>';
$peer_afi_items = [
['event' => $afi_class, 'text' => $peer_afi['afi']],
['event' => $safi_class, 'text' => $peer_afi['safi']],
];
$peer_afi_html = get_label_group($peer_afi_items);
//r($peer_afi_html);
$peer_afis_html[] = $peer_afi_html;
}
$string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
$string .= ' <td class="state-marker"></td>' . PHP_EOL;
$string .= ' <td></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL;
$string .= ' <td><strong><span class="label label-' . $peer['peer_local_class'] . '">AS' . $peer['human_local_as'] . '</span></strong>';
if (!safe_empty($peer['virtual_name'])) {
$vitual_type = isset($GLOBALS['config']['os'][$local_dev['os']]['snmp']['virtual_type']) ? nicecase($GLOBALS['config']['os'][$local_dev['os']]['snmp']['virtual_type']) : 'VRF';
$string .= '<br /><span class="label">'.$vitual_type.': '.$peer['virtual_name'].'</span>';
}
$string .= '</td>' . PHP_EOL;
$string .= ' <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL;
$string .= ' <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL;
$string .= ' <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL;
$string .= ' <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL;
$string .= ' <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap">' . format_uptime($peer['bgpPeerFsmEstablishedTime']) . '<br />
$string .= '</td>' . PHP_EOL;
$string .= ' <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL;
$string .= ' <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL;
$string .= ' <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL;
$string .= ' <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL;
$string .= ' <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL;
$string .= ' <td style="white-space: nowrap">' . format_uptime($peer['bgpPeerFsmEstablishedTime']) . '<br />
Updates: <i class="icon-circle-arrow-down text-success"></i> ' . format_si($peer['bgpPeerInUpdates']) . ' <i class="icon-circle-arrow-up text-primary"></i> ' . format_si($peer['bgpPeerOutUpdates']) . '</td>' . PHP_EOL;
$string .= ' </tr>' . PHP_EOL;
$string .= ' </tr>' . PHP_EOL;
// Graphs
$peer_graph = FALSE;
switch ($vars['graph']) {
case 'prefixes_ipv4unicast':
case 'prefixes_ipv4multicast':
case 'prefixes_ipv4vpn':
case 'prefixes_ipv6unicast':
case 'prefixes_ipv6multicast':
$afisafi = preg_replace('/prefixes_(ipv[46])(\w+)/', '$1.$2', $vars['graph']); // prefixes_ipv6unicast ->> ipv6.unicast
if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id'])
{
$graph_array['type'] = 'bgp_' . $vars['graph'];
$graph_array['id'] = $peer['bgpPeer_id'];
$peer_graph = TRUE;
}
break;
case 'updates':
if ($peer['bgpPeer_id'])
{
$graph_array['type'] = 'bgp_updates';
$graph_array['id'] = $peer['bgpPeer_id'];
$peer_graph = TRUE;
}
break;
case 'macaccounting_bits':
case 'macaccounting_pkts':
//FIXME. I really still not know it works or not? -- mike
// This part copy-pasted from old code as is
$acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M
// Graphs
$peer_graph = FALSE;
switch ($vars['graph']) {
case 'prefixes_ipv4unicast':
case 'prefixes_ipv4multicast':
case 'prefixes_ipv4vpn':
case 'prefixes_ipv6unicast':
case 'prefixes_ipv6multicast':
$afisafi = preg_replace('/prefixes_(ipv[46])(\w+)/', '$1.$2', $vars['graph']); // prefixes_ipv6unicast ->> ipv6.unicast
if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id']) {
$graph_array['type'] = 'bgp_' . $vars['graph'];
$graph_array['id'] = $peer['bgpPeer_id'];
$peer_graph = TRUE;
}
break;
case 'updates':
if ($peer['bgpPeer_id']) {
$graph_array['type'] = 'bgp_updates';
$graph_array['id'] = $peer['bgpPeer_id'];
$peer_graph = TRUE;
}
break;
case 'macaccounting_bits':
case 'macaccounting_pkts':
// FIXME. I really still not know it works or not? -- mike
// This part copy-pasted from old code as is
$acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M
LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address
LEFT JOIN `ports` AS P ON P.port_id = M.port_id
LEFT JOIN `devices` AS D ON D.device_id = P.device_id
WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr']));
$database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
if (is_array($acc) && is_file($database))
{
$peer_graph = TRUE;
$graph_array['id'] = $acc['ma_id'];
$graph_array['type'] = $vars['graph'];
}
break;
}
if ($peer_graph) {
$graph_array['to'] = get_time();
$string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
$string .= ' <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL;
$string .= generate_graph_row($graph_array);
$string .= ' </td>' . PHP_EOL . ' </tr>' . PHP_EOL;
}
elseif ($list['graph'])
{
// Empty row for correct view class table-striped-two
$string .= ' <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></tr>' . PHP_EOL;
$database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd");
if (is_array($acc) && is_file($database)) {
$peer_graph = TRUE;
$graph_array['id'] = $acc['ma_id'];
$graph_array['type'] = $vars['graph'];
}
break;
}
$string .= ' </tbody>' . PHP_EOL;
$string .= '</table>';
if ($peer_graph) {
$graph_array['to'] = get_time();
$string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL;
$string .= ' <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL;
$string .= generate_box_close();
$string .= generate_graph_row($graph_array);
// Print pagination header
if ($entries['pagination_html'])
{
$string = $entries['pagination_html'] . $string . $entries['pagination_html'];
$string .= ' </td>' . PHP_EOL . ' </tr>' . PHP_EOL;
} elseif ($list['graph']) {
// Empty row for correct view class table-striped-two
$string .= ' <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></tr>' . PHP_EOL;
}
}
// Print
echo $string;
$string .= ' </tbody>' . PHP_EOL;
$string .= '</table>';
$string .= generate_box_close();
// Print pagination header
if ($entries['pagination_html']) {
$string = $entries['pagination_html'] . $string . $entries['pagination_html'];
}
// Print
echo $string;
}
@ -240,156 +227,172 @@ function print_bgp_peer_table($vars) {
* pagination, pageno, pagesize
* device, type, adminstatus, state
*/
function get_bgp_array($vars)
{
$array = [];
function get_bgp_array($vars) {
$array = [];
// With pagination? (display page numbers in header)
$array['pagination'] = (isset($vars['pagination']) && $vars['pagination']);
pagination($vars, 0, TRUE); // Get default pagesize/pageno
$array['pageno'] = $vars['pageno'];
$array['pagesize'] = $vars['pagesize'];
$start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
$pagesize = $array['pagesize'];
// With pagination? (display page numbers in header)
//$array['pagination'] = (isset($vars['pagination']) && $vars['pagination']);
$array['pagination'] = TRUE;
pagination($vars, 0, TRUE); // Get default pagesize/pageno
$array['pageno'] = $vars['pageno'];
$array['pagesize'] = $vars['pagesize'];
$start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
$pagesize = $array['pagesize'];
// Require cached IDs from html/includes/cache-data.inc.php
$cache_bgp = &$GLOBALS['cache']['bgp'];
// Require cached IDs from html/includes/cache-data.inc.php
$cache_bgp = &$GLOBALS['cache']['bgp'];
// Begin query generate
$param = array();
$where = ' WHERE 1 ';
foreach ($vars as $var => $value) {
if ($value != '') {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$where .= generate_query_values($values, 'bgpPeer_id');
break;
case 'device':
case 'device_id':
$where .= generate_query_values($value, 'device_id');
break;
case 'peer':
case 'peer_id':
$where .= generate_query_values($value, 'peer_device_id');
break;
case 'local_ip':
$where .= generate_query_values(ip_uncompress($value), 'bgpPeerLocalAddr');
break;
case 'peer_ip':
$where .= generate_query_values(ip_uncompress($value), 'bgpPeerRemoteAddr');
break;
case 'local_as':
$where .= generate_query_values(bgp_asdot_to_asplain($value), 'local_as');
break;
case 'peer_as':
$where .= generate_query_values(bgp_asdot_to_asplain($value), 'bgpPeerRemoteAs');
break;
case 'type':
if ($value === 'external' || $value === 'ebgp') {
$where .= generate_query_values($cache_bgp['external'], 'bgpPeer_id');
} elseif ($value === 'internal' || $value === 'ibgp') {
$where .= generate_query_values($cache_bgp['internal'], 'bgpPeer_id');
}
break;
case 'adminstatus':
if ($value === 'stop') {
$where .= generate_query_values($cache_bgp['start'], 'bgpPeer_id', '!='); // NOT IN
} elseif ($value === 'start') {
$where .= generate_query_values($cache_bgp['start'], 'bgpPeer_id');
}
break;
case 'state':
if ($value === 'down') {
$where .= generate_query_values($cache_bgp['up'], 'bgpPeer_id', '!='); // NOT IN
} elseif ($value === 'up') {
$where .= generate_query_values($cache_bgp['up'], 'bgpPeer_id');
}
break;
}
}
}
// Begin query generate
$param = [];
$where = [];
foreach ($vars as $var => $value) {
if (!safe_empty($value)) {
switch ($var) {
case "group":
case "group_id":
$values = get_group_entities($value);
$where[] = generate_query_values_ng($values, 'bgpPeer_id');
break;
// Show peers only for permitted devices
$query_permitted = generate_query_values($cache_bgp['permitted'], 'bgpPeer_id');
case 'device':
case 'device_id':
$where[] = generate_query_values_ng($value, 'device_id');
break;
$query = 'FROM `bgpPeers`';
$query_count = 'SELECT COUNT(*) ' . $query . $where . $query_permitted; // Use only bgpPeer_id and device_id in query!
case 'peer':
case 'peer_id':
$where[] = generate_query_values_ng($value, 'peer_device_id');
break;
$query .= ' JOIN `devices` USING (`device_id`) ';
case 'local_ip':
$where[] = generate_query_values_ng(ip_uncompress($value), 'bgpPeerLocalAddr');
break;
//$query .= ' LEFT JOIN `bgpPeers-state` AS S ON `bgpPeer_id` = S.`bgpPeer_id`';
//$query .= ' LEFT JOIN `devices` AS D ON `device_id` = D.`device_id`';
$query .= $where . $query_permitted;
case 'peer_ip':
$where[] = generate_query_values_ng(ip_uncompress($value), 'bgpPeerRemoteAddr');
break;
$query = 'SELECT `hostname`, `bgpLocalAs`, bgpPeers.* ' . $query;
$sort_dir = $vars['sort_order'] === 'desc' ? ' DESC' : '';
case 'local_as':
$where[] = generate_query_values_ng(bgp_asdot_to_asplain($value), 'local_as');
break;
switch($vars['sort']) {
case "device":
$sort = " ORDER BY `hostname`".$sort_dir;
break;
case 'peer_as':
if (is_string($value) && preg_match_all('/AS(?<as>[\d\.]+):/', $value, $matches)) {
//r($matches);
$value = $matches['as'];
}
$where[] = generate_query_values_ng(bgp_asdot_to_asplain($value), 'bgpPeerRemoteAs');
break;
case "local_as":
$sort = " ORDER BY `local_as`$sort_dir, `virtual_name`$sort_dir";
break;
case 'type':
if ($value === 'external' || $value === 'ebgp') {
$where[] = generate_query_values_ng($cache_bgp['external'], 'bgpPeer_id');
} elseif ($value === 'internal' || $value === 'ibgp') {
$where[] = generate_query_values_ng($cache_bgp['internal'], 'bgpPeer_id');
}
break;
case "peer_ip":
$sort = " ORDER BY `bgpPeerRemoteAddr`".$sort_dir;
break;
case "peer_as":
$sort = " ORDER BY `bgpPeerRemoteAs`".$sort_dir;
break;
case 'adminstatus':
if ($value === 'stop') {
$where[] = generate_query_values_ng($cache_bgp['start'], 'bgpPeer_id', '!='); // NOT IN
} elseif ($value === 'start') {
$where[] = generate_query_values_ng($cache_bgp['start'], 'bgpPeer_id');
}
break;
case 'state':
$sort = " ORDER BY `bgpPeerAdminStatus`".$sort_dir.", `bgpPeerState`".$sort_dir;
break;
case 'uptime':
$sort = " ORDER BY `bgpPeerFsmEstablishedTime`".$sort_dir;
break;
default:
$sort = " ORDER BY `hostname`".$sort_dir.", `bgpPeerRemoteAs`".$sort_dir.", `bgpPeerRemoteAddr`".$sort_dir;
if ($value === 'down') {
$where[] = generate_query_values_ng($cache_bgp['up'], 'bgpPeer_id', '!='); // NOT IN
} elseif ($value === 'up') {
$where[] = generate_query_values_ng($cache_bgp['up'], 'bgpPeer_id');
}
break;
}
}
}
$query .= $sort;
$query .= " LIMIT $start,$pagesize";
// Show peers only for permitted devices
if ($_SESSION['userlevel'] < 5) {
$where[] = generate_query_values_ng($cache_bgp['permitted'], 'bgpPeer_id');
} elseif (!$GLOBALS['config']['web_show_disabled'] && $GLOBALS['cache']['devices']['stat']['disabled']) {
// Exclude disabled devices for Global Read+
$where[] = generate_query_values_ng($GLOBALS['cache']['devices']['disabled'], 'device_id', '!=');
}
$peer_devices = array();
// Query BGP
foreach (dbFetchRows($query, $param) as $entry)
{
humanize_bgp($entry);
if (!safe_empty($where)) {
$where = 'WHERE ' . implode(' AND ', $where);
} else {
$where = '';
}
//r($where);
// Collect peer devices for AFI/SAFI
$peer_devices[$entry['device_id']] = 1;
$query_count = 'SELECT COUNT(*) FROM `bgpPeers` ' . $where; // Use only bgpPeer_id and device_id in query!
$array['count'] = dbFetchCell($query_count, $param);
//$array['count'] = dbFetchCell($query_count, $param, TRUE);
$array['entries'][] = $entry;
// Pagination
$array['pagination_html'] = pagination($vars, $array['count']);
$query = 'SELECT `hostname`, `bgpLocalAs`, `bgpPeers`.*';
$query .= ' FROM `bgpPeers`';
$query .= ' JOIN `devices` USING (`device_id`) ';
$query .= $where;
$sort_dir = $vars['sort_order'] === 'desc' ? ' DESC' : '';
switch($vars['sort']) {
case "device":
$sort = " ORDER BY `hostname`".$sort_dir;
break;
case "local_as":
$sort = " ORDER BY `local_as`$sort_dir, `virtual_name`$sort_dir";
break;
case "peer_ip":
$sort = " ORDER BY `bgpPeerRemoteAddr`".$sort_dir;
break;
case "peer_as":
$sort = " ORDER BY `bgpPeerRemoteAs`".$sort_dir;
break;
case 'state':
$sort = " ORDER BY `bgpPeerAdminStatus`".$sort_dir.", `bgpPeerState`".$sort_dir;
break;
case 'uptime':
$sort = " ORDER BY `bgpPeerFsmEstablishedTime`".$sort_dir;
break;
default:
$sort = " ORDER BY `hostname`".$sort_dir.", `bgpPeerRemoteAs`".$sort_dir.", `bgpPeerRemoteAddr`".$sort_dir;
}
$query .= $sort;
$query .= " LIMIT $start,$pagesize";
$peer_devices = [];
// Query BGP
foreach (dbFetchRows($query, $param) as $entry) {
humanize_bgp($entry);
// Collect peer devices for AFI/SAFI
$peer_devices[$entry['device_id']] = 1;
$array['entries'][] = $entry;
}
// Query AFI/SAFI
if (!safe_empty($peer_devices)) {
$query_afi = 'SELECT * FROM `bgpPeers_cbgp` WHERE 1' . generate_query_values_and(array_keys($peer_devices), 'device_id');
foreach (dbFetchRows($query_afi) as $entry) {
$array['afisafi'][$entry['device_id']][$entry['bgpPeer_id']][$entry['afi'] . '.' . $entry['safi']] = [ 'afi' => $entry['afi'], 'safi' => $entry['safi'] ];
}
}
// Query AFI/SAFI
if (count($peer_devices))
{
$query_afi = 'SELECT * FROM `bgpPeers_cbgp` WHERE 1' . generate_query_values(array_keys($peer_devices), 'device_id');
foreach (dbFetchRows($query_afi) as $entry)
{
$array['afisafi'][$entry['device_id']][$entry['bgpPeer_id']][$entry['afi'] . '.' . $entry['safi']] = array('afi' => $entry['afi'], 'safi' => $entry['safi']);
}
}
// Query BGP peers count
if ($array['pagination']) {
$array['count'] = dbFetchCell($query_count, $param);
$array['pagination_html'] = pagination($vars, $array['count']);
} else {
$array['count'] = safe_count($array['entries']);
}
return $array;
return $array;
}
// EOF

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -26,39 +26,54 @@ function generate_box_open($args = []) {
if (isset($args['title'])) {
$return .= ' <div class="box-header' . ($args['header-border'] ? ' with-border' : '') . '">'.PHP_EOL;
if (isset($args['url'])) { $return .= '<a href="'.$args['url'].'">'; }
if (isset($args['icon'])) { $return .= '<i class="'.$args['icon'].'"></i>'; }
if (isset($args['icon'])) { $return .= get_icon($args['icon']); }
$return .= '<' . (isset($args['title-element']) ? $args['title-element'] : 'h3').' class="box-title"';
$return .= isset($args['title-style']) ? ' style="'.$args['title-style'].'"' : '';
$return .= '>';
$return .= $args['title'].'</' . (isset($args['title-element']) ? $args['title-element'] : 'h3').'>'.PHP_EOL;
$return .= escape_html($args['title']).'</' . (isset($args['title-element']) ? $args['title-element'] : 'h3').'>'.PHP_EOL;
if (isset($args['url'])) { $return .= '</a>'; }
if (isset($args['header-controls']) && is_array($args['header-controls']['controls'])) {
$return .= ' <div class="box-tools pull-right">';
foreach($args['header-controls']['controls'] as $control) {
if (isset($control['anchor']) && $control['anchor'] == TRUE) {
$anchor = (isset($control['anchor']) && $control['anchor']) ||
(isset($control['config']) && !empty($control['config']));
if ($anchor) {
$return .= ' <a role="button"';
} else {
$return .= '<button type="button"';
}
if (isset($control['url']) && $control['url'] !== '#' && !empty($control['url'])) {
$return .= ' href="'.$control['url'].'"';
$return .= ' href="' . $control['url'] . '"';
} elseif (isset($control['config']) && !empty($control['config'])) {
// Check/get config option
$return .= ' href="#"'; // set config url
if (empty($control['data']) && isset($control['value'])) {
$control['data'] = [ 'onclick' => "ajax_settings('".$control['config']."', '".$control['value']."');" ];
}
} else {
//$return .= ' onclick="return false;"';
}
// Additional class
$return .= ' class="btn btn-box-tool';
if (isset($control['class'])) { $return .= ' '.$control['class']; }
if (isset($control['class'])) {
$return .= ' ' . escape_html($control['class']);
}
$return .= '"';
if (isset($control['data'])) { $return .= ' '.$control['data']; }
// Additional params (raw string or array with params
if (isset($control['data'])) {
$params = is_array($control['data']) ? generate_html_attribs($control['data']) : $control['data'];
$return .= ' '.$params;
}
$return .= '>';
if (isset($control['icon'])) { $return .= '<i class="'.$control['icon'].'"></i> '; }
if (isset($control['icon'])) { $return .= get_icon($control['icon']).' '; }
if (isset($control['text'])) { $return .= $control['text']; }
if (isset($control['anchor']) && $control['anchor'] == TRUE) {
if ($anchor) {
$return .= '</a>';
} else {
$return .= '</button>';
@ -455,7 +470,7 @@ SCRIPT;
foreach ($content as $key => $value) {
echo('<div id="'.$htmlname.'_clone_row" class="control-group text-nowrap" style="margin: 10px 0 10px 0;">'.PHP_EOL);
$item = [
'id' => "${htmlname}[key][]",
'id' => "{$htmlname}[key][]",
'name' => 'Key',
//'width' => '500px',
'class' => 'input-large',
@ -470,7 +485,7 @@ SCRIPT;
}
echo(generate_form_element($item));
$item = [
'id' => "${htmlname}[value][]",
'id' => "{$htmlname}[value][]",
'name' => 'Value',
//'width' => '500px',
'class' => 'input-xlarge',
@ -509,9 +524,9 @@ SCRIPT;
// https://metallurgical.github.io/jquery-metal-clone/
register_html_resource('js', 'jquery.metalClone.js'); // jquery.metalClone.min.js
register_html_resource('css', 'metalClone.css');
$clone_target = "${htmlname}_clone_row";
$clone_button = "${htmlname}[add]";
$clone_remove = "${htmlname}[remove]";
$clone_target = "{$htmlname}_clone_row";
$clone_button = "{$htmlname}[add]";
$clone_remove = "{$htmlname}[remove]";
$remove_text = ''; //'Remove';
if ($readonly || (bool)$locked) {
$clone_disabled = 'disabled: \'1\',';
@ -531,26 +546,26 @@ SCRIPT;
//console.log(element);
var regex = /(metalElement\d{0,})/g;
var eclass = element.attr('class');
var others = \$('[id=${clone_target}]').not(element);
var others = \$('[id={$clone_target}]').not(element);
$.each(others, function () {
\$(this).addClass(eclass);
// Add button icon
//console.log(\$(this).find('#${clone_button}'));
\$(this).find('[id=\"${clone_button}\"]').prepend(' ').prepend(\$('<i/>', { class: '${icon_add}' }));
//console.log(\$(this).find('#{$clone_button}'));
\$(this).find('[id=\"{$clone_button}\"]').prepend(' ').prepend(\$('<i/>', { class: '{$icon_add}' }));
// Remove button
\$(this).append(\$('<button/>', {
id: '${clone_remove}',
id: '{$clone_remove}',
type: 'button',
${clone_disabled}
{$clone_disabled}
class: eclass.match(regex) + 'BtnRemove metal-btn-remove btn btn-danger',
text: ' ${remove_text}',
text: ' {$remove_text}',
'data-metal-ref': '.' + element.attr('class').match(regex)
}));
// Remove button icon
\$(this).find('.metal-btn-remove').prepend(\$('<i/>', { class: '${icon_remove}' }));
\$(this).find('.metal-btn-remove').prepend(\$('<i/>', { class: '{$icon_remove}' }));
});
}";

View File

@ -111,7 +111,7 @@ function print_search($data, $title = NULL, $button = 'search', $url = NULL)
$string .= '<div class="navbar">' . PHP_EOL;
$string .= '<div class="navbar-inner">';
$string .= '<div class="container">';
if (isset($title)) { $string .= ' <a class="brand">' . $title . '</a>' . PHP_EOL; }
if (isset($title)) { $string .= ' <a class="brand">' . escape_html($title) . '</a>' . PHP_EOL; }
$string .= '<div class="nav" style="margin: 5px 0 5px 0;">';
@ -209,15 +209,13 @@ function generate_form_box($data)
*
* @return NULL
*/
function print_form($data, $return = FALSE)
{
function print_form($data, $return = FALSE) {
// Just return if safety requirements are not fulfilled
if (isset($data['userlevel']) && $data['userlevel'] > $_SESSION['userlevel']) { return; }
// Return if the user doesn't have write permissions to the relevant entity
if (isset($data['entity_write_permit']) &&
!is_entity_write_permitted($data['entity_write_permit']['entity_id'], $data['entity_write_permit']['entity_type']))
{
!is_entity_write_permitted($data['entity_write_permit']['entity_id'], $data['entity_write_permit']['entity_type'])) {
return;
}
@ -235,25 +233,22 @@ function print_form($data, $return = FALSE)
$form_id = (isset($data['id']) ? $data['id'] : 'form-'.strgen());
$form_class = 'form form-inline'; // default for rows and simple
if (isset($data['style']))
{
if (isset($data['style'])) {
$form_style = ' style="'.$data['style'].'"';
} else {
$form_style = ' style="margin-bottom: 0px;"';
}
$base_class = (array_key_exists('class', $data) ? $data['class'] : OBS_CLASS_BOX);
$base_space = ($data['space'] ? $data['space'] : '5px');
$used_vars = array();
$base_class = array_key_exists('class', $data) ? $data['class'] : OBS_CLASS_BOX;
$base_space = $data['space'] ?: '5px';
$used_vars = [];
// Cache permissions to session var
permissions_cache_session();
//r($_SESSION['cache']);
if ($data['submit_by_key'])
{
if ($data['submit_by_key']) {
$action = '';
if ($data['url'])
{
if ($data['url']) {
$action .= 'this.form.prop(\'action\', form_to_path(\'' . $form_id . '\'));';
}
register_html_resource('script', '$(function(){$(\'form#' . $form_id . '\').each(function(){$(this).find(\'input\').keypress(function(e){if(e.which==10||e.which==13){'.$action.'this.form.submit();}});});});');
@ -410,7 +405,7 @@ function print_form($data, $return = FALSE)
{
$div_begin .= ' <div class="title">';
$div_begin .= get_icon($data['icon']);
$div_begin .= '&nbsp;'.$data['title'].'</div>' . PHP_EOL;
$div_begin .= '&nbsp;'.escape_html($data['title']).'</div>' . PHP_EOL;
}
$div_end = '</div>' . PHP_EOL;
}
@ -582,7 +577,7 @@ function print_form($data, $return = FALSE)
$row_elements .= '
<div class="control-group">
<div class="controls">
<h3>'.$entry['title'].'</h3>
<h3>'.escape_html($entry['title']).'</h3>
</div>
</div>';
}
@ -622,11 +617,10 @@ function print_form($data, $return = FALSE)
}
// Add CSRF Token
if (!in_array('requesttoken', $used_vars) && isset($_SESSION['requesttoken']))
{
$string_elements .= generate_form_element(array('type' => 'hidden',
'id' => 'requesttoken',
'value' => $_SESSION['requesttoken'])) . PHP_EOL;
if (!in_array('requesttoken', $used_vars) && isset($_SESSION['requesttoken'])) {
$string_elements .= generate_form_element([ 'type' => 'hidden',
'id' => 'requesttoken',
'value' => $_SESSION['requesttoken'] ]) . PHP_EOL;
$used_vars[] = 'requesttoken';
}
@ -636,22 +630,29 @@ function print_form($data, $return = FALSE)
$used_vars[] = 'pagesize';
// Remove old vars from url
if ($data['url'])
{
foreach ($used_vars as $var)
{
if ($data['url']) {
foreach ($used_vars as $var) {
$data['url'] = preg_replace('/'.$var.'=[^\/]+\/?/', '', $data['url']);
}
}
// Form header
if (isset($data['right']) && $data['right'])
{
if (isset($data['right']) && $data['right']) {
$form_class .= ' pull-right';
}
// auto add some common html attribs
$form_attribs = [ 'class' => $form_class ];
foreach ([ 'onchange', 'oninput', 'onclick', 'ondblclick', 'onfocus', 'onsubmit' ] as $attrib) {
if (isset($data[$attrib])) {
$form_attribs[$attrib] = $data[$attrib];
}
}
$string = PHP_EOL . "<!-- START $form_id -->" . PHP_EOL;
$string .= $div_begin;
$string .= '<form method="POST" id="'.$form_id.'" name="'.$form_id.'" action="'.$data['url'].'" class="'.$form_class.'"'.$form_style.'>' . PHP_EOL;
$string .= '<form method="POST" id="' . $form_id . '" name="' . $form_id . '" action="' .$data['url'] . '" ' .
generate_html_attribs($form_attribs) . $form_style.'>' . PHP_EOL;
if ($data['brand']) { $string .= ' <a class="brand">' . $data['brand'] . '</a>' . PHP_EOL; }
if ($data['help']) { $string .= ' <span class="help-block">' . $data['help'] . '</span>' . PHP_EOL; }
@ -725,7 +726,7 @@ function print_form_box($data, $return = FALSE)
$header = '';
if (isset($data['title']))
{
$header .= ' <h2>' . $data['title'] . '</h2>' . PHP_EOL;
$header .= ' <h2>' . escape_html($data['title']) . '</h2>' . PHP_EOL;
}
// Form elements
@ -1057,8 +1058,7 @@ function print_form_box($data, $return = FALSE)
* @param string $type Type of form element, also can passed as $item['type']
* @return string Generated form element
*/
function generate_form_element($item, $type = '')
{
function generate_form_element($item, $type = '') {
// Check community edition
if (isset($item['community']) && !$item['community'] && OBSERVIUM_EDITION === 'community') {
return '';
@ -1066,8 +1066,7 @@ function generate_form_element($item, $type = '')
$value_isset = isset($item['value']);
if (!$value_isset) { $item['value'] = ''; }
if (is_array($item['value']))
{
if (is_array($item['value'])) {
// Passed from URI comma values always converted to array, re-implode it
$item['value_escaped'] = escape_html(implode(',', $item['value']));
} else {
@ -1499,37 +1498,33 @@ SCRIPT;
// Convert to data attribs and recursive call to checkbox
$item['attribs']['data-toggle'] = 'toggle';
// Convert switch style attr to toggle
$item_attribs = ['on-icon' => 'icon-check', 'on-text' => 'label-check', 'off-icon' => 'icon-uncheck', 'off-text' => 'label-uncheck'];
$item_attribs = [ 'on-icon' => 'icon-check', 'on-text' => 'label-check', 'off-icon' => 'icon-uncheck', 'off-text' => 'label-uncheck' ];
foreach($item_attribs as $attr => $data_attr)
{
if (isset($item[$attr]) && !isset($item[$data_attr])) { $item[$data_attr] = $item[$attr]; }
}
// Move placeholder to label
if (isset($item['placeholder']) && is_string($item['placeholder']))
{
if (isset($item['placeholder']) && is_string($item['placeholder'])) {
$item['attribs']['data-tt-label'] = get_markdown($item['placeholder'], TRUE, TRUE);
unset($item['placeholder']);
}
$item_attribs = array('size', 'palette', 'group', 'label', 'icon-check', 'label-check', 'icon-uncheck', 'label-uncheck');
foreach($item_attribs as $attr)
{
$item_attribs = [ 'size', 'palette', 'group', 'label', 'icon-check', 'label-check', 'icon-uncheck', 'label-uncheck' ];
foreach($item_attribs as $attr) {
if (isset($item[$attr])) { $item['attribs']['data-tt-'.$attr] = $item[$attr]; }
}
// Types: http://tinytoggle.simonerighi.net/#types
if (in_array($item['view'], array('toggle', 'check', 'circle', 'square', 'square_v', 'power', 'dot', 'like', 'watch', 'star', 'lock', 'heart', 'smile')))
{
if (in_array($item['view'], [ 'toggle', 'check', 'circle', 'square', 'square_v', 'power',
'dot', 'like', 'watch', 'star', 'lock', 'heart', 'smile' ])) {
$item['attribs']['data-tt-type'] = $item['view'];
} else {
$item['attribs']['data-tt-type'] = 'square'; // default type
}
// Onchange target id
if ($item['onchange-id'])
{
if ($item['onchange-id']) {
$item['attribs']['data-onchange-id'] = $item['onchange-id'];
}
// tiny-toggle not support readonly
if (isset($item['readonly']))
{
if (isset($item['readonly'])) {
$item['disabled'] = $item['readonly'] || $item['disabled'];
//unset($item['readonly']);
}
@ -1542,30 +1537,23 @@ SCRIPT;
case 'checkbox':
$string = ' <input type="checkbox" ';
$string .= ' name="'.$item['id'] . '" id="' .$item['id'] . '" ' . $item_switch;
if ($item['title'])
{
if ($item['title']) {
$string .= ' data-rel="tooltip" data-tooltip="'.escape_html($item['title']).'" title="'.escape_html($item['title']).'"';
}
if (get_var_true($item['value']))
{
$string .= ' value="1"';
if (get_var_true($item['value'])) {
$string .= ' checked';
}
if ($item['disabled'])
{
if ($item['disabled']) {
$string .= ' disabled="1"';
}
elseif ($item['readonly'])
{
} elseif ($item['readonly']) {
$string .= ' readonly="1" onclick="return false"';
}
if ($item['class'])
{
if ($item['class']) {
$string .= ' class="' . trim($item['class']) . '"';
}
$string .= $element_data; // Add custom data- attribs
$string .= ' value="1" />';
if (is_string($item['placeholder']))
{
$string .= $element_data . ' />'; // Add custom data- attribs
if (is_string($item['placeholder'])) {
// add placeholder text at right of the element
$string .= ' <label for="' . $item['id'] . '" class="help-inline" style="margin-top: 4px;">' .
get_markdown($item['placeholder'], TRUE, TRUE) . '</label>' . PHP_EOL;
@ -1752,8 +1740,8 @@ SCRIPT;
$string .= ' <select multiple data-toggle="tagsinput" name="'.$item['id'].'[]" ';
$string .= 'id="'.$item['id'].'" ';
if ($item['title']) { $string .= 'title="' . $item['title'] . '" '; }
else if (isset($item['name'])) { $string .= 'title="' . $item['name'] . '" '; }
if ($item['title']) { $string .= 'title="' . escape_html($item['title']) . '" '; }
elseif (isset($item['name'])) { $string .= 'title="' . escape_html($item['name']) . '" '; }
if (isset($item['placeholder']) && $item['placeholder'] !== FALSE)
{
if ($item['placeholder'] === TRUE)
@ -1873,8 +1861,8 @@ SCRIPT;
$string .= ' <select name="'.$item['id'].'" ';
}
$string .= 'id="'.$item['id'].'" ';
if ($item['title']) { $string .= 'title="' . $item['title'] . '" '; }
else if (isset($item['name'])) { $string .= 'title="' . $item['name'] . '" '; }
if ($item['title']) { $string .= 'title="' . escape_html($item['title']) . '" '; }
elseif (isset($item['name'])) { $string .= 'title="' . escape_html($item['name']) . '" '; }
$data_width = ($item['width']) ? ' data-width="'.$item['width'].'"' : ' data-width="auto"';
$data_size = (is_numeric($item['size'])) ? ' data-size="'.$item['size'].'"' : ' data-size="15"';
@ -2263,7 +2251,7 @@ function generate_modal_open(&$args)
$string .= '<div class="' . $base_class . '" id="' . $args['id'] . '" tabindex="-1"';
if ($args['role'] == 'dialog')
if ($args['role'] === 'dialog')
{
$string .= ' role="dialog" aria-labelledby="' . $args['id'] . '_label">' . PHP_EOL;
} else {
@ -2282,7 +2270,7 @@ function generate_modal_open(&$args)
{
$string .= get_icon($args['icon']) . '&nbsp;';
}
$string .= $args['title'] . '</h3>' . PHP_EOL;
$string .= escape_html($args['title']) . '</h3>' . PHP_EOL;
}
$string .= ' </div>' . PHP_EOL;
@ -2307,43 +2295,40 @@ function generate_modal_close($args)
}
// Modal specific form
function generate_form_modal($form)
{
function generate_form_modal($form) {
// Just return if safety requirements are not fulfilled
if (isset($form['userlevel']) && $form['userlevel'] > $_SESSION['userlevel']) { return; }
if (isset($form['userlevel']) && $form['userlevel'] > $_SESSION['userlevel']) { return ''; }
// Return if the user doesn't have write permissions to the relevant entity
if (isset($form['entity_write_permit']) &&
!is_entity_write_permitted($form['entity_write_permit']['entity_id'], $form['entity_write_permit']['entity_type']))
{
return;
!is_entity_write_permitted($form['entity_write_permit']['entity_id'], $form['entity_write_permit']['entity_type'])) {
return '';
}
// Generate only main modal form except header and close
$form_only = isset($form['form_only']) && $form['form_only'];
// Time our form filling.
$form_start = microtime(TRUE);
// Use modal with form
if (isset($form['modal_args']))
{
if (isset($form['modal_args'])) {
$modal_args = $form['modal_args'];
unset($form['modal_args']);
} else {
$modal_args = array();
$modal_args = [];
}
if (!isset($modal_args['id']) && isset($form['id']))
{
if (!isset($modal_args['id']) && isset($form['id'])) {
// Generate modal id from form id
if (str_starts($form['id'], 'modal-'))
{
if (str_starts($form['id'], 'modal-')) {
$modal_args['id'] = $form['id'];
$form['id'] = substr($form['id'], 6);
} else {
$modal_args['id'] = 'modal-' . $form['id'];
}
}
if (!isset($modal_args['title']) && isset($form['title']))
{
if (!isset($modal_args['title']) && isset($form['title'])) {
// Move form title to modal header
$modal_args['title'] = $form['title'];
unset($form['title']);
@ -2353,7 +2338,7 @@ function generate_form_modal($form)
$form['fieldset']['body']['class'] = 'modal-body'; // Required this class for modal body!
$form['fieldset']['footer']['class'] = 'modal-footer'; // Required this class for modal footer!
$modal = generate_modal_open($modal_args);
$modal = !$form_only ? generate_modal_open($modal_args) : '';
// Save generation time for profiling
$GLOBALS['form_time'] += utime() - $form_start;
@ -2363,7 +2348,9 @@ function generate_form_modal($form)
// Time our form filling.
$form_start = microtime(TRUE);
$modal .= generate_modal_close($modal_args);
if (!$form_only) {
$modal .= generate_modal_close($modal_args);
}
// Save generation time for profiling
$GLOBALS['form_time'] += utime() - $form_start;

View File

@ -6,7 +6,7 @@
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
@ -38,40 +38,39 @@ function print_syslogs($vars)
$device_single = FALSE; // Show syslog entries for single device or multiple (use approximate counts for multiple)
$param = array();
$param = [];
$where = ' WHERE 1 ';
foreach ($vars as $var => $value)
{
if ($value != '')
{
$cond = array();
switch ($var)
{
foreach ($vars as $var => $value) {
if (!safe_empty($value)) {
switch ($var) {
case 'device':
case 'device_id':
$device_single = is_numeric($value);
$where .= generate_query_values($value, 'device_id');
$where .= generate_query_values_and($value, 'device_id');
break;
case 'priority':
$value = get_var_csv($value);
foreach ($value as $k => $v)
{
foreach ($value as $k => $v) {
// Rewrite priority strings to numbers
$value[$k] = priority_string_to_numeric($v);
}
$where .= generate_query_values($value, $var);
$where .= generate_query_values_and($value, $var);
break;
case 'tag':
case 'program':
$condition = str_contains($value, '*') ? 'LIKE' : '=';
$value = get_var_csv($value);
$where .= generate_query_values($value, $var, $condition);
$where .= generate_query_values_and($value, $var, $condition);
break;
case 'message':
if (preg_match('/^!(=)?\s*(?<msg>.+)/', $value, $matches)) {
$where .= generate_query_values($matches['msg'], 'msg', '%!=LIKE%');
//FIXME: this should just be a function used for all "text" searchable fields
if (preg_match(OBS_PATTERN_REGEXP, $value, $matches)) {
// Match regular expression
$where .= generate_query_values_and($matches['pattern'], 'msg', 'REGEXP');
} elseif (preg_match('/^!(=)?\s*(?<msg>.+)/', $value, $matches)) {
$where .= generate_query_values_and($matches['msg'], 'msg', '%!=LIKE%');
} else {
$where .= generate_query_values($value, 'msg', '%LIKE%');
$where .= generate_query_values_and($value, 'msg', '%LIKE%');
}
break;
case 'timestamp_from':
@ -91,7 +90,7 @@ function print_syslogs($vars)
/*
// Convert NOT IN to IN for correctly use indexes
$devices_permitted = dbFetchColumn('SELECT DISTINCT `device_id` FROM `syslog` WHERE 1 '.$query_permitted, NULL, TRUE);
$query_permitted = generate_query_values($devices_permitted, 'device_id');
$query_permitted = generate_query_values_and($devices_permitted, 'device_id');
//r($devices_permitted);
*/
@ -120,6 +119,7 @@ function print_syslogs($vars)
dbQuery('ANALYZE TABLE `syslog`;'); // Update INFORMATION_SCHEMA for more correctly count
$tmp = dbFetchRow($query_count_approx, $param);
$count = $tmp['rows'];
$count_estimate = TRUE;
}
} else {
$count = safe_count($entries);
@ -187,6 +187,11 @@ See <a href="'.OBSERVIUM_DOCS_URL.'/syslog/" target="_blank">Syslog Integration<
// Print pagination header
if ($pagination && !$short) { $string = pagination($vars, $count) . $string . pagination($vars, $count); }
if(isset($count_estimate) && $count_estimate == TRUE)
{
print_message("The syslog entry counts shown below are an estimate due to SQL query performance limitations. There may be many fewer results than indicated.", "info");
}
// Print syslog
echo $string;
}
@ -217,13 +222,11 @@ function generate_syslog_row($entry, $vars, $list = NULL)
$string = ' <tr class="'.$row_class.'">' . PHP_EOL;
$string .= '<td class="state-marker"></td>' . PHP_EOL;
$timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
$timediff = get_time() - strtotime($entry['timestamp']);
if ($short || $timediff < 3600)
{
if ($short || $timediff < 3600) {
$string .= ' <td class="syslog text-nowrap">';
$timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
$string .= generate_tooltip_link('', format_uptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
$string .= generate_tooltip_time($entry['timestamp']) . '</td>' . PHP_EOL;
} else {
//$string .= ' <td style="width: 130px">';
$string .= ' <td>';
@ -455,4 +458,217 @@ function generate_syslog_form_values($form_filter = FALSE, $column = NULL)
return $form_items;
}
function print_syslog_rules_table($vars) {
if (isset($vars['la_id'])) {
$las = dbFetchRows("SELECT * FROM `syslog_rules` WHERE `la_id` = ?", [ $vars['la_id'] ]);
} else {
$las = dbFetchRows("SELECT * FROM `syslog_rules` ORDER BY `la_name`");
}
if (safe_count($las)) {
$modals = '';
$string = generate_box_open();
$string .= '<table class="table table-striped table-hover table-condensed">' . PHP_EOL;
$cols = array(
array(NULL, 'class="state-marker"'),
'name' => array('Name', 'style="width: 160px;"'),
'descr' => array('Description', 'style="width: 400px;"'),
'rule' => 'Rule',
'severity' => array('Severity', 'style="width: 60px;"'),
'disabled' => array('Status', 'style="width: 60px;"'),
'controls' => array('', 'style="width: 60px;"'),
);
$string .= get_table_header($cols, $vars);
foreach($las as $la) {
if ($la['disable'] == 0) { $la['html_row_class'] = "up"; } else { $la['html_row_class'] = "disabled"; }
$string .= '<tr class="' . $la['html_row_class'] . '">';
$string .= '<td class="state-marker"></td>';
$string .= ' <td><strong><a href="'.generate_url(array('page' => 'syslog_rules', 'la_id' => $la['la_id'])).'">' . escape_html($la['la_name']) . '</a></strong></td>' . PHP_EOL;
$string .= ' <td><a href="'.generate_url(array('page' => 'syslog_rules', 'la_id' => $la['la_id'])).'">' . escape_html($la['la_descr']) . '</a></td>' . PHP_EOL;
$string .= ' <td><code>' . escape_html($la['la_rule']) . '</code></td>' . PHP_EOL;
$string .= ' <td>' . escape_html($la['la_severity']) . '</td>' . PHP_EOL;
$string .= ' <td>' . ($la['la_disable'] ? '<span class="label label-error">disabled</span>' : '<span class="label label-success">enabled</span>') . '</td>' . PHP_EOL;
$string .= ' <td style="text-align: right;">';
if ($_SESSION['userlevel'] >= 10)
{
$string .= '
<div class="btn-group btn-group-xs" role="group" aria-label="Rule actions">
<a class="btn btn-default" role="group" title="Edit" href="#modal-edit_syslog_rule_'.$la['la_id'].'" data-toggle="modal"><i class="icon-cog text-muted"></i></a>
<a class="btn btn-danger" role="group" title="Delete" href="#modal-delete_syslog_rule_'.$la['la_id'].'" data-toggle="modal"><i class="icon-trash"></i></a>
</div>';
}
$string .= '</td>';
$string .= ' </tr>' . PHP_EOL;
// Delete Rule Modal
$modal_args = array(
'id' => 'modal-delete_syslog_rule_' . $la['la_id'],
'title' => 'Delete Syslog Rule "'.escape_html($la['la_descr']).'"',
//'hide' => TRUE,
//'fade' => TRUE,
//'role' => 'dialog',
//'class' => 'modal-md',
);
$form = array('type' => 'horizontal',
'id' => 'delete_syslog_rule_' . $la['la_id'],
'userlevel' => 10, // Minimum user level for display form
'modal_args' => $modal_args, // !!! This generate modal specific form
//'help' => 'This will completely delete the rule and all associations and history.',
'class' => '', // Clean default box class!
'url' => generate_url(array('page' => 'syslog_rules'))
);
$form['fieldset']['body'] = array('class' => 'modal-body'); // Required this class for modal body!
$form['fieldset']['footer'] = array('class' => 'modal-footer'); // Required this class for modal footer!
$form['row'][0]['la_id'] = array(
'type' => 'hidden',
'fieldset' => 'body',
'value' => $la['la_id']);
$form['row'][0]['action'] = array(
'type' => 'hidden',
'fieldset' => 'body',
'value' => 'delete_syslog_rule');
$form['row'][5]['confirm'] = array(
'type' => 'checkbox',
'fieldset' => 'body',
'name' => 'Confirm',
'placeholder' => 'Yes, please delete this rule.',
'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');",
'value' => 'confirm');
$form['row'][6]['warning_'.$la['la_id']] = array(
'type' => 'html',
'fieldset' => 'body',
'html' => '<h4 class="alert-heading"><i class="icon-warning-sign"></i> Warning!</h4>' .
' This rule and all history will be completely deleted!',
'div_class' => 'alert alert-warning',
'div_style' => 'display:none;');
$form['row'][8]['close'] = array(
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Close',
'icon' => '',
'attribs' => array('data-dismiss' => 'modal',
'aria-hidden' => 'true'));
$form['row'][9]['delete_button_'.$la['la_id']] = array(
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Delete Rule',
'icon' => 'icon-trash icon-white',
//'right' => TRUE,
'class' => 'btn-danger',
'disabled' => TRUE,
'value' => 'delete_syslog_rule');
$modals .= generate_form_modal($form);
unset($form);
// Edit Rule Modal
$modal_args = array(
'id' => 'modal-edit_syslog_rule_' . $la['la_id'],
'title' => 'Edit Syslog Rule "'.escape_html($la['la_descr']).'"',
//'hide' => TRUE,
//'fade' => TRUE,
//'role' => 'dialog',
'class' => 'modal-lg',
);
$form = array('type' => 'horizontal',
'id' => 'edit_syslog_rule_' . $la['la_id'],
'userlevel' => 10, // Minimum user level for display form
'modal_args' => $modal_args, // !!! This generate modal specific form
//'help' => 'This will completely delete the rule and all associations and history.',
'class' => '', // Clean default box class!
'url' => generate_url(array('page' => 'syslog_rules'))
);
$form['fieldset']['body'] = array('class' => 'modal-body'); // Required this class for modal body!
$form['fieldset']['footer'] = array('class' => 'modal-footer'); // Required this class for modal footer!
$form['row'][0]['la_id'] = array(
'type' => 'hidden',
'fieldset' => 'body',
'value' => $la['la_id']);
$form['row'][3]['la_name'] = array(
'type' => 'text',
'fieldset' => 'body',
'name' => 'Rule Name',
'class' => 'input-xlarge',
'value' => $la['la_name']);
$form['row'][4]['la_descr'] = array(
'type' => 'textarea',
'fieldset' => 'body',
'name' => 'Description',
'class' => 'input-xxlarge',
//'style' => 'margin-bottom: 10px;',
'value' => $la['la_descr']);
$form['row'][5]['la_rule'] = array(
'type' => 'textarea',
'fieldset' => 'body',
'name' => 'Regular Expression',
'class' => 'input-xxlarge',
'value' => $la['la_rule']);
$form['row'][6]['la_disable'] = array(
'type' => 'switch-ng',
'fieldset' => 'body',
'name' => 'Status',
'on-text' => 'Disabled',
'on-color' => 'danger',
'off-text' => 'Enabled',
'off-color' => 'success',
'size' => 'small',
'value' => $la['la_disable']);
$form['row'][8]['close'] = array(
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Close',
'icon' => '',
'attribs' => array('data-dismiss' => 'modal',
'aria-hidden' => 'true'));
$form['row'][9]['action'] = array(
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Save Changes',
'icon' => 'icon-ok icon-white',
//'right' => TRUE,
'class' => 'btn-primary',
'value' => 'edit_syslog_rule');
$modals .= generate_form_modal($form);
unset($form);
}
$string .= '</table>';
$string .= generate_box_close();
echo $string;
} else {
print_warning("There are currently no Syslog alerting filters defined.");
}
echo $modals;
}
// EOF

View File

@ -1,58 +1,69 @@
<?php
function get_vlans($vars)
{
$vlans = array();
$vls = dbFetchRows("SELECT * FROM `vlans`");
foreach ($vls as $vlan) {
if (safe_empty($vlan['vlan_name'])) {
// Empty vlan name
$vlan['vlan_name'] = 'Vlan ' . $vlan['vlan_vlan'];
}
$vlans[$vlan['vlan_vlan']]['names'][$vlan['vlan_name']]++;
$vlans[$vlan['vlan_vlan']]['counts']['devices'] = 0;
$vlans[$vlan['vlan_vlan']]['counts']['ports_tagged'] = 0;
$vlans[$vlan['vlan_vlan']]['counts']['ports_untagged'] = 0;
}
$otherports = dbFetchRows("SELECT `ifVlan`, COUNT(`ifVlan`) AS `count` FROM `ports` GROUP BY `ifVlan`");
foreach ($otherports as $otherport) {
if ($otherport['ifVlan'] == "") {
continue;
}
$vlans[$otherport['ifVlan']]['counts']['ports_untagged'] = $otherport['count'];
}
$dev_counts = dbFetchRows("SELECT `vlan_vlan`, COUNT(`vlan_vlan`) AS `count` FROM `vlans` GROUP BY `vlan_vlan`");
foreach ($dev_counts as $dev_count) {
$vlans[$dev_count['vlan_vlan']]['counts']['devices'] = $dev_count['count'];
}
$port_counts = dbFetchRows("SELECT `vlan`, COUNT(`vlan`) AS `count` FROM `ports_vlans` GROUP BY `vlan`");
foreach ($port_counts as $port_count) {
if (!isset($vlans[$port_count['vlan']])) {
print_error("Unknown VLAN ID '" . $port_count['vlan'] . "' with " . $port_count['count'] . " ports count.");
//print_debug("Unknown VLAN ID '".$port_count['vlan']."' with ".$port_count['count']." ports count.");
continue;
}
$vlans[$port_count['vlan']]['counts']['ports_tagged'] = $port_count['count'];
}
$mac_counts = dbFetchRows("SELECT `vlan_id`, COUNT(DISTINCT(`mac_address`)) AS `count` FROM `vlans_fdb` GROUP BY `vlan_id`");
foreach ($mac_counts as $mac_count) {
if (!isset($vlans[$mac_count['vlan_id']])) {
//print_error("Unknown VLAN ID '".$mac_count['vlan_id']."' with ".$mac_count['count']." mac count.");
print_debug("Unknown VLAN ID '" . $mac_count['vlan_id'] . "' with " . $mac_count['count'] . " mac count.");
continue;
}
$vlans[$mac_count['vlan_id']]['counts']['macs'] = $mac_count['count'];
}
ksort($vlans);
return $vlans;
}
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
*
*/
function get_vlans($vars) {
$vlans = [];
$vls = dbFetchRows("SELECT * FROM `vlans`");
foreach ($vls as $vlan) {
if (safe_empty($vlan['vlan_name'])) {
// Empty vlan name
$vlan['vlan_name'] = 'Vlan ' . $vlan['vlan_vlan'];
}
$vlans[$vlan['vlan_vlan']]['names'][$vlan['vlan_name']]++;
$vlans[$vlan['vlan_vlan']]['counts']['devices'] = 0;
$vlans[$vlan['vlan_vlan']]['counts']['ports_tagged'] = 0;
$vlans[$vlan['vlan_vlan']]['counts']['ports_untagged'] = 0;
}
$sql = 'SELECT `ifVlan`, COUNT(`ifVlan`) AS `count` FROM `ports` WHERE `deleted` != 1 GROUP BY `ifVlan`';
foreach (dbFetchRows($sql) as $otherport) {
if (safe_empty($otherport['ifVlan'])) {
continue;
}
$vlans[$otherport['ifVlan']]['counts']['ports_untagged'] = $otherport['count'];
}
$dev_counts = dbFetchRows("SELECT `vlan_vlan`, COUNT(`vlan_vlan`) AS `count` FROM `vlans` GROUP BY `vlan_vlan`");
foreach ($dev_counts as $dev_count) {
$vlans[$dev_count['vlan_vlan']]['counts']['devices'] = $dev_count['count'];
}
$port_counts = dbFetchRows("SELECT `vlan`, COUNT(`vlan`) AS `count` FROM `ports_vlans` GROUP BY `vlan`");
foreach ($port_counts as $port_count) {
if (!isset($vlans[$port_count['vlan']])) {
print_error("Unknown VLAN ID '" . $port_count['vlan'] . "' with " . $port_count['count'] . " ports count.");
//print_debug("Unknown VLAN ID '".$port_count['vlan']."' with ".$port_count['count']." ports count.");
continue;
}
$vlans[$port_count['vlan']]['counts']['ports_tagged'] = $port_count['count'];
}
$mac_counts = dbFetchRows("SELECT `vlan_id`, COUNT(DISTINCT(`mac_address`)) AS `count` FROM `vlans_fdb` GROUP BY `vlan_id`");
foreach ($mac_counts as $mac_count) {
if (!isset($vlans[$mac_count['vlan_id']])) {
//print_error("Unknown VLAN ID '".$mac_count['vlan_id']."' with ".$mac_count['count']." mac count.");
print_debug("Unknown VLAN ID '" . $mac_count['vlan_id'] . "' with " . $mac_count['count'] . " mac count.");
continue;
}
$vlans[$mac_count['vlan_id']]['counts']['macs'] = $mac_count['count'];
}
ksort($vlans);
return $vlans;
}
// EOF