$value) {
if (!safe_empty($value)) {
switch ($var) {
case 'location':
$where[] = generate_query_values_and($value, $var);
break;
case 'device_id':
$where[] = generate_query_values_and($value, 'ports.device_id');
break;
case 'group':
case 'group_id':
$values = get_group_entities($value);
$where[] = generate_query_values_and($values, 'ports.port_id');
break;
case 'device_group_id':
case 'device_group':
$values = get_group_entities($value, 'device');
$where[] = generate_query_values_and($values, 'ports.device_id');
break;
case 'disable':
$var = 'disabled';
case 'disabled': // FIXME. 'disabled' column never used in ports..
case 'deleted':
case 'ignore':
case 'ifSpeed':
case 'ifType':
case 'ifVlan':
case 'port_id':
$where[] = generate_query_values_and($value, 'ports.' . $var);
break;
case 'hostname':
case 'ifAlias':
case 'ifDescr':
$where[] = generate_query_values_and($value, $var, '%LIKE%');
break;
case 'label':
case 'port_label':
$where[] = generate_query_values_and($value, 'port_label', '%LIKE%');
break;
case 'mac':
case 'ifPhysAddress':
$value = str_replace(['.', '-', ':'], '', $value);
$where[] = generate_query_values_and($value, 'ifPhysAddress', '%LIKE%');
break;
case 'port_descr_type':
$where[] = generate_query_values_and($value, $var, 'LIKE');
break;
case 'errors':
if (get_var_true($value)) {
$where[] = " AND (`ifInErrors_delta` > '0' OR `ifOutErrors_delta` > '0')";
}
break;
case 'alerted':
if (get_var_true($value)) {
// this is just state=down
//$where[] = ' AND `ifAdminStatus` = "up" AND (`ifOperStatus` = "lowerLayerDown" OR `ifOperStatus` = "down")';
$var = 'state';
$value = 'down';
}
// do not break here
case 'state':
// Allowed multiple states as array
$state_where = [];
foreach ((array)$value as $state) {
if ($state === "down") {
$state_where[] = '`ifAdminStatus` = "up" AND `ifOperStatus` IN ("lowerLayerDown", "down")';
//$state_where[] = generate_query_values_ng('up', 'ifAdminStatus') . generate_query_values_and(['down', 'lowerLayerDown'], 'ifOperStatus');
} elseif ($state === "up") {
$state_where[] = '`ifAdminStatus` = "up" AND `ifOperStatus` IN ("up", "testing", "monitoring")';
//$state_where[] = generate_query_values_ng('up', 'ifAdminStatus') . generate_query_values_and(['up', 'testing', 'monitoring'], 'ifOperStatus');
} elseif ($state === "admindown" || $state === "shutdown") {
$state_where[] = '`ifAdminStatus` = "down"';
//$state_where[] = generate_query_values_ng('down', 'ifAdminStatus');
}
}
switch (count($state_where)) {
case 0:
// incorrect state passed, ignore
break;
case 1:
$where[] = ' AND ' . $state_where[0];
break;
default:
$where[] = ' AND ((' . implode(') OR (', $state_where) . '))';
}
break;
case 'cbqos':
if ($value && $value !== 'no') {
$where[] = generate_query_values_and($GLOBALS['cache']['ports']['cbqos'], 'ports.port_id');
}
break;
case 'mac_accounting':
if ($value && $value !== 'no') {
$where[] = generate_query_values_and($GLOBALS['cache']['ports']['mac_accounting'], 'ports.port_id');
}
break;
}
}
}
return $where;
}
/**
* Returns a string containing an HTML table to be used in popups for the port entity type
*
* @param array $port array
*
* @return string Table containing port header for popups
*/
function generate_port_popup_header($port)
{
// Push through processing function to set attributes
humanize_port($port);
$contents = generate_box_open();
$contents .= '
';
//$content .= generate_box_open(array('body-style' => 'width: 700px;'));
$graph_array['type'] = $port['graph_type'];
$graph_array['legend'] = "yes";
$graph_array['height'] = "100";
$graph_array['width'] = "275";
$graph_array['to'] = $time['now'];
$graph_array['from'] = $time['day'];
$graph_array['id'] = $port['port_id'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $time['week'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $time['month'];
$content .= generate_graph_tag($graph_array);
$graph_array['from'] = $time['year'];
$content .= generate_graph_tag($graph_array);
$content .= "
";
//$content .= generate_box_close();
}
return $content;
}
/**
* Returns an HTML port page link with mouse-over popup to permitted users or a text label to non-permitted users
*
* @param array $port array
* @param string $text text to be used as port label
* @param string $type graph type to be used in graphs (bits, nupkts, etc)
*
* @return string HTML link or text string
*/
function generate_port_link($port, $text = NULL, $type = NULL, $escape = FALSE, $short = FALSE)
{
humanize_port($port);
// Fixme -- does this function even need alternative $text? I think not. It's a hangover from before label.
// Sometime in $text included html
if (empty($text)) {
$text = $short ? $port['port_label_short'] : $port['port_label'];
$escape = TRUE; // FORCE label escaping
}
if (port_permitted($port['port_id'], $port['device_id'])) {
$url = generate_port_url($port);
if ($escape) {
$text = escape_html($text);
}
return '';
} else {
return escape_html($text);
}
}
// Just simplify function call, instead generate_port_link($port, NULL, NULL, TRUE, TRUE)
function generate_port_link_short($port, $text = NULL, $type = NULL, $escape = FALSE, $short = TRUE)
{
return generate_port_link($port, $text, $type, $escape, $short);
}
/**
* Returns a string containing a page URL built from a $port array and an array of optional variables
*
* @param array $port array
* @param array optional variables used when building the URL
*
* @return string port page URL
*/
function generate_port_url($port, $vars = [])
{
return generate_url(['page' => 'device', 'device' => $port['device_id'], 'tab' => 'port', 'port' => $port['port_id']], $vars);
}
/**
* Returns or echos a port graph thumbnail
*
* @param array $args of arguments used to build the graph image tag URL
* @param boolean $echo variable defining wether output should be returned or echoed
*
* @return string HTML port popup contents
*/
function generate_port_thumbnail($args, $echo = TRUE)
{
if (!$args['bg']) {
$args['bg'] = "FFFFFF";
}
$graph_array = [];
$graph_array['from'] = $args['from'];
$graph_array['to'] = $args['to'];
$graph_array['id'] = $args['port_id'];
$graph_array['type'] = $args['graph_type'];
$graph_array['width'] = $args['width'];
$graph_array['height'] = $args['height'];
$graph_array['bg'] = 'FFFFFF00';
$mini_graph = generate_graph_tag($graph_array);
$img = generate_port_link($args, $mini_graph);
if ($echo) {
echo($img);
} else {
return $img;
}
}
function print_port_row($port, $vars = [])
{
echo generate_port_row($port, $vars);
}
function generate_port_row($port, $vars = [])
{
global $config, $cache;
$device = device_by_id_cache($port['device_id']);
humanize_port($port);
if (!isset($vars['view'])) {
$vars['view'] = "basic";
}
// Populate $port_adsl if the port has ADSL-MIB data
if (!isset($cache['ports_option']['ports_adsl']) || in_array($port['port_id'], $cache['ports_option']['ports_adsl'])) {
$port_adsl = dbFetchRow("SELECT * FROM `ports_adsl` WHERE `port_id` = ?", [$port['port_id']]);
}
// Populate $port['tags'] with various tags to identify port statuses and features
// Port Errors
if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) {
$port['tags'] .= generate_port_link($port, '
|
| ';
if ($vars['page'] !== "device" && !get_var_true($vars['popup'])) {
// Print device name link if we're not inside the device page hierarchy.
$table_cols++; // Increment table columns by one to make sure graph line draws correctly
$string .= ' ' . generate_device_link_short($device, [], 20) . '
' . escape_html(truncate($port['location'], 32, "")) . ' | ';
}
$string .=
' ' . generate_port_link($port) . ' ' . $port['tags'] . ' ' .
' ' . escape_html(truncate($port['ifAlias'], 50, '')) . ' | ' .
'' . get_icon('arrow-down', NULL, ['style' => $port['bps_in_style']]) . ' ' . format_bps($port['in_rate']) . ' ' .
get_icon('arrow-up', NULL, ['style' => $port['bps_out_style']]) . ' ' . format_bps($port['out_rate']) . '
| ' .
'' . get_icon('arrow-down', NULL, ['style' => $port['bps_in_style']]) . ' ' . $port['ifInOctets_perc'] . '% ' .
get_icon('arrow-up', NULL, ['style' => $port['bps_out_style']]) . ' ' . $port['ifOutOctets_perc'] . '%
| ' .
'' . get_icon('arrow-down', NULL, ['style' => $port['pps_in_style']]) . ' ' . format_bi($port['ifInUcastPkts_rate']) . 'pps ' .
get_icon('arrow-up', NULL, ['style' => $port['pps_out_style']]) . ' ' . format_bi($port['ifOutUcastPkts_rate']) . 'pps | ' .
'' . $port['human_speed'] . ' ' . $port['ifMtu'] . ' |
' . $port['human_type'] . ' ' . $port['human_mac'] . ' |
';
} elseif ($vars['view'] === "details" || $vars['view'] === "detail") {
// Print detailed view table row
$table_cols = '9';
$string .= '
' . escape_html(truncate($port['location'], 32, "")) . '';
}
$string .= '
';
$string .= '
' . generate_port_link($port) . ' ' . $port['tags'] . '
' . escape_html($port['ifAlias']) . '';
if ($port['ifAlias']) {
$string .= ' ';
}
unset($break);
$ignore_type = $GLOBALS['config']['ip-address']['ignore_type'];
if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) {
$sql = "SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?";
// Do not exclude IPv4 link-local
$sql .= generate_query_values_and(array_diff($ignore_type, ['link-local']), 'ipv4_type', '!='); // Do not show ignored ip types
foreach (dbFetchRows($sql, [$port['port_id']]) as $ip) {
$string .= $break . generate_popup_link('ip', $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'], NULL, 'small');
$break = " ";
}
}
if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) {
$sql = "SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?";
$sql .= generate_query_values_and($ignore_type, 'ipv6_type', '!='); // Do not show ignored ip types
foreach (dbFetchRows($sql, [$port['port_id']]) as $ip6) {
$string .= $break . generate_popup_link('ip', $ip6['ipv6_address'] . '/' . $ip6['ipv6_prefixlen'], NULL, 'small');
$break = " ";
}
}
//$string .= '';
$string .= ' | ';
// Print port graph thumbnails
$string .= '';
$port['graph_type'] = "port_bits";
$graph_array = [];
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $port['port_id'];
$graph_array['type'] = $port['graph_type'];
$graph_array['width'] = 100;
$graph_array['height'] = 20;
$graph_array['bg'] = 'ffffff00';
$graph_array['from'] = $config['time']['day'];
$string .= generate_port_link($port, generate_graph_tag($graph_array));
$port['graph_type'] = "port_upkts";
$graph_array['type'] = $port['graph_type'];
$string .= generate_port_link($port, generate_graph_tag($graph_array));
$port['graph_type'] = "port_errors";
$graph_array['type'] = $port['graph_type'];
$string .= generate_port_link($port, generate_graph_tag($graph_array));
$string .= ' | ';
$string .= '';
if ($port['ifOperStatus'] === "up" || $port['ifOperStatus'] === "monitoring") {
// Colours generated by humanize_port
$string .= ' ' . format_bps($port['in_rate']) . '
' . format_bps($port['out_rate']) . '
' . format_bi($port['ifInUcastPkts_rate']) . 'pps
' . format_bi($port['ifOutUcastPkts_rate']) . 'pps';
}
$string .= ' | ';
if ($port['ifType'] && $port['ifType'] != "") {
$string .= '' . $port['human_type'] . '';
} else {
$string .= '-';
}
$string .= ' ';
if ($port['ifSpeed']) {
$string .= '' . humanspeed($port['ifSpeed']) . '';
}
if ($port['ifDuplex'] && $port['ifDuplex'] !== "unknown") {
$string .= ' (' . str_replace("Duplex", "", $port['ifDuplex']) . ')';
}
$string .= ' ';
if ($port['ifMtu'] && $port['ifMtu'] != "") {
$string .= 'MTU ' . $port['ifMtu'] . '';
} else {
$string .= 'Unknown MTU';
}
//$string .= ' ';
// Set VLAN data if the port has ifTrunk populated
if (strlen($port['ifTrunk']) &&
!in_array($port['ifTrunk'], ['access', 'routed'])) { // Skip on routed (or access)
if ($port['ifVlan']) {
// Native VLAN
if (!isset($cache['ports_vlan'])) {
$native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', [$device['device_id'], $port['port_id']]);
$native_name = dbFetchCell('SELECT `vlan_name` FROM `vlans` WHERE `device_id` = ? AND `vlan_vlan` = ?', [$device['device_id'], $port['ifVlan']]);
} else {
$native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state'];
$native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name'];
}
switch ($native_state) {
case 'blocking':
$class = 'text-danger';
break;
case 'forwarding':
$class = 'text-success';
break;
default:
$class = 'muted';
}
if (empty($native_name)) {
$native_name = 'VLAN' . str_pad($port['ifVlan'], 4, '0', STR_PAD_LEFT);
}
$native_tooltip = 'NATIVE: ' . $port['ifVlan'] . ' [' . $native_name . '] ';
}
if (!isset($cache['ports_vlan'])) {
$vlans = dbFetchRows('SELECT * FROM `ports_vlans` AS PV
LEFT JOIN vlans AS V ON PV.`vlan` = V.`vlan_vlan` AND PV.`device_id` = V.`device_id`
WHERE PV.`port_id` = ? AND PV.`device_id` = ? ORDER BY PV.`vlan`;', [$port['port_id'], $device['device_id']]);
} else {
$vlans = $cache['ports_vlan'][$port['port_id']];
}
$vlans_count = safe_count($vlans);
$rel = ($vlans_count || $native_tooltip) ? 'tooltip' : ''; // Hide tooltip for empty
$string .= '' . $port['ifTrunk'] . ' ';
} elseif ($port['ifVlan']) {
if (!isset($cache['ports_vlan'])) {
$native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', [$device['device_id'], $port['port_id']]);
$native_name = dbFetchCell('SELECT `vlan_name` FROM `vlans` WHERE `device_id` = ? AND `vlan_vlan` = ?', [$device['device_id'], $port['ifVlan']]);
} else {
$native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state'];
$native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name'];
}
switch ($native_state) {
case 'blocking':
$class = 'label-error';
break;
case 'forwarding':
$class = 'label-success';
break;
default:
$class = '';
}
$rel = ($native_name) ? 'tooltip' : ''; // Hide tooltip for empty
$vlan_name = ($port['ifTrunk'] !== 'access') ? nicecase($port['ifTrunk']) . ' ' : '';
$vlan_name .= 'VLAN ' . $port['ifVlan'];
$string .= ' ' . $vlan_name . '';
} elseif ($port['ifVrf']) { // Print the VRF name if the port is assigned to a VRF
$vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", [$port['ifVrf']]);
$string .= ' ' . $vrf_name . '';
}
$string .= ' | ';
// If the port is ADSL, print ADSL port data.
if ($port_adsl['adslLineCoding']) {
$string .= '';
$string .= '' . $port_adsl['adslLineCoding'] . ' ' . rewrite_adslLineType($port_adsl['adslLineType']) . '';
$string .= ' ';
$string .= 'SYN ' . format_bps($port_adsl['adslAtucChanCurrTxRate']) . ' ' . format_bps($port_adsl['adslAturChanCurrTxRate']);
$string .= ' ';
//$string .= 'Max:'.formatRates($port_adsl['adslAtucCurrAttainableRate']) . '/'. formatRates($port_adsl['adslAturCurrAttainableRate']);
//$string .= ' ';
$string .= 'ATN ' . $port_adsl['adslAtucCurrAtn'] . 'dBm ' . $port_adsl['adslAturCurrAtn'] . 'dBm';
$string .= ' ';
$string .= 'SNR ' . $port_adsl['adslAtucCurrSnrMgn'] . 'dB ' . $port_adsl['adslAturCurrSnrMgn'] . 'dB';
$string .= '';
} else {
// Otherwise print normal port data
$string .= ' | ';
if (!safe_empty($port['ifPhysAddress'])) {
$string .= $port['human_mac'];
} else {
$string .= '-';
}
$string .= ' ' . $port['ifLastChange'] . '';
}
$string .= ' | ';
$string .= '';
if ($port['ifType'] !== 'softwareLoopback' && !str_contains($port['port_label'], 'oopback') &&
safe_empty($graph_type)) {
$br = '';
// Populate links array for ports with direct links
if (!isset($cache['ports_option']['neighbours']) || in_array($port['port_id'], $cache['ports_option']['neighbours'])) {
foreach (dbFetchRows('SELECT * FROM `neighbours` WHERE `port_id` = ? AND `active` = ?', [$port['port_id'], 1]) as $neighbour) {
// print_r($neighbour);
if ($neighbour['remote_port_id']) {
// Do not show some "non-physical" interfaces links,
// see: https://jira.observium.org/browse/OBS-2979
$remote_port = get_port_by_id_cache($neighbour['remote_port_id']);
if (!in_array($remote_port['ifType'], ['propVirtual', 'ieee8023adLag'])) {
$int_links[$neighbour['remote_port_id']] = $neighbour['remote_port_id'];
$int_links_phys[$neighbour['remote_port_id']] = $neighbour['protocol'];
}
} else {
$int_links_unknown[] = $neighbour;
}
}
} // else { }
// Populate links array for devices which share an IPv4 subnet
if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) {
$ignore_type = $GLOBALS['config']['ip-address']['ignore_type'];
$ignore_type[] = 'loopback'; // Always ignore loopback on links
$sql = 'SELECT DISTINCT(`ipv4_network_id`), `ipv4_network` FROM `ipv4_addresses` ' .
'LEFT JOIN `ipv4_networks` USING(`ipv4_network_id`) ' .
'WHERE `port_id` = ?';
$sql .= generate_query_values_and($ignore_type, 'ipv4_type', '!=');
if (!safe_empty($config['ignore_common_subnet'])) {
// If it's still exist (non default list)
$sql .= generate_query_values_and($config['ignore_common_subnet'], 'ipv4_network', '!=');
}
foreach (dbFetchRows($sql, [ $port['port_id'] ]) as $network) {
//r($network);
$link_sql = 'SELECT `device_id`, `port_id` FROM `ipv4_addresses` ' .
'LEFT JOIN `ports` USING (`device_id`, `port_id`) ' .
'WHERE `device_id` != ? AND `ipv4_network_id` = ? AND `ifAdminStatus` = "up"';
$params = [ $device['device_id'], $network['ipv4_network_id'] ];
foreach (dbFetchRows($link_sql, $params) as $new) {
//r($new);
if (!$config['web_show_disabled'] &&
in_array($new['device_id'], $cache['devices']['disabled'])) {
continue;
}
$int_links[$new['port_id']] = $new['port_id'];
$int_links_v4[$new['port_id']][] = $network['ipv4_network'];
}
}
}
// Populate links array for devices which share an IPv6 subnet
if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) {
$ignore_type = $GLOBALS['config']['ip-address']['ignore_type'];
$ignore_type[] = 'loopback'; // Always ignore loopback on links
$sql = 'SELECT DISTINCT(`ipv6_network_id`), `ipv6_network` FROM `ipv6_addresses` ' .
'LEFT JOIN `ipv6_networks` USING(`ipv6_network_id`) ' .
'WHERE `port_id` = ?';
$sql .= generate_query_values_and($ignore_type, 'ipv6_type', '!=');
if (!safe_empty($config['ignore_common_subnet'])) {
// If it's still exist (non default list)
$sql .= generate_query_values_and($config['ignore_common_subnet'], 'ipv6_network', '!=');
}
foreach (dbFetchRows($sql, [$port['port_id']]) as $network) {
//r($network);
$link_sql = 'SELECT `device_id`, `port_id` FROM `ipv6_addresses` ' .
'LEFT JOIN `ports` USING (`device_id`, `port_id`) ' .
'WHERE `device_id` != ? AND `ipv6_network_id` = ? AND `ifAdminStatus` = "up"';
$link_sql .= generate_query_values_and([ 'linklayer', 'wellknown' ], 'ipv6_origin', '!=');
$params = [ $device['device_id'], $network['ipv6_network_id'] ];
foreach (dbFetchRows($link_sql, $params) as $new) {
//r($new);
if (!$config['web_show_disabled'] &&
in_array($new['device_id'], $cache['devices']['disabled'])) {
continue;
}
$int_links[$new['port_id']] = $new['port_id'];
$int_links_v6[$new['port_id']][] = $network['ipv6_network'];
}
}
}
// Output contents of links array
foreach ($int_links as $int_link) {
//r($int_link);
//r($int_links_phys);
$link_if = get_port_by_id_cache($int_link);
if (!device_permitted($link_if['device_id'])) {
continue;
} // Skip not permitted links
$link_dev = device_by_id_cache($link_if['device_id']);
$string .= $br;
if ($int_links_phys[$int_link]) {
$string .= generate_tooltip_link(NULL, NULL, 'Directly connected', $config['icon']['connected']) . ' ';
} else {
$string .= generate_tooltip_link(NULL, NULL, 'Same subnet', $config['icon']['network']) . ' ';
}
// for port_label_short - generate_port_link($link_if, NULL, NULL, TRUE, TRUE)
$string .= '' . generate_port_link_short($link_if) . ' on ' . generate_device_link_short($link_dev) . '';
if (isset($int_links_phys[$int_link]) && !is_numeric($int_links_phys[$int_link])) {
$string .= ' ' . nicecase($int_links_phys[$int_link]) . '';
}
## FIXME -- do something fancy here.
if ($int_links_v6[$int_link]) {
$string .= ' ' . overlib_link('', 'IPv6', implode(" ", $int_links_v6[$int_link]), NULL);
}
if ($int_links_v4[$int_link]) {
$string .= ' ' . overlib_link('', 'IPv4', implode(" ", $int_links_v4[$int_link]), NULL);
}
$br = " ";
}
// Output content of unknown links array (where ports don't exist in our database, or they weren't matched)
foreach ($int_links_unknown as $int_link) {
//r($int_link);
$string .= generate_tooltip_link(NULL, NULL, 'Directly connected', $config['icon']['connected']) . ' ';
$string .= '' . short_ifname($int_link['remote_port']) . ' on ';
$text = '';
if (!safe_empty($int_link['remote_platform'])) {
$text .= '' . $int_link['remote_platform'] . ' ';
}
$text .= $int_link['remote_version'] . ' ';
$string .= '' . generate_tooltip_link(NULL, $int_link['remote_hostname'], $text) . '';
$string .= ' ' . nicecase($int_link['protocol']) . ' ';
}
}
if (!isset($cache['ports_option']['pseudowires']) || in_array($port['port_id'], $cache['ports_option']['pseudowires'])) {
foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", [$port['port_id']]) as $pseudowire) {
//`port_id`,`peer_device_id`,`peer_ldp_id`,`pwID`,`pwIndex`
# $pw_peer_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($pseudowire['peer_device_id']));
$pw_peer_int = dbFetchRow("SELECT * FROM `ports` AS I, `pseudowires` AS P WHERE I.`device_id` = ? AND P.`pwID` = ? AND P.`port_id` = I.`port_id`", [$pseudowire['peer_device_id'], $pseudowire['pwID']]);
# $pw_peer_int = get_port_by_id_cache($pseudowire['peer_device_id']);
$pw_peer_dev = device_by_id_cache($pseudowire['peer_device_id']);
if (is_array($pw_peer_int)) {
humanize_port($pw_peer_int);
$string .= $br . ' ' . generate_port_link_short($pw_peer_int) . ' on ' . generate_device_link_short($pw_peer_dev) . '';
} else {
$string .= $br . ' VC ' . $pseudowire['pwID'] . ' on ' . $pseudowire['peer_addr'] . '';
}
$string .= ' ' . $pseudowire['pwPsnType'] . '';
$string .= ' ' . $pseudowire['pwType'] . '';
$br = " ";
}
}
/** Disabled pending database rejigging to add it back
*
* if (!isset($cache['ports_option']['ports_pagp']) || in_array($port['ifIndex'], $cache['ports_option']['ports_pagp']))
* {
* foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? AND `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member)
* {
* humanize_port($member);
* $pagp[$device['device_id']][$port['ifIndex']][$member['ifIndex']] = TRUE;
* $string .= $br.' ' . generate_port_link($member) . ' [PAgP]';
* $br = " ";
* }
* }
*
* if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex'])
* {
* $pagp[$device['device_id']][$port['pagpGroupIfIndex']][$port['ifIndex']] = TRUE;
* $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id']));
* humanize_port($parent);
* $string .= $br.' ' . generate_port_link($parent) . ' [PAgP]';
* $br = " ";
* }
**/
if (!isset($cache['ports_option']['ports_stack_low']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_low'])) {
foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? AND `device_id` = ? AND `ifStackStatus` = ?", [$port['ifIndex'], $device['device_id'], 'active']) as $higher_if) {
if (!$higher_if['port_id_high']) {
continue;
}
//if (isset($pagp[$device['device_id']][$higher_if['port_id_high']][$port['ifIndex']])) { continue; } // Skip if same PAgP port
if ($this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high'])) {
$label = '';
if ($this_port['ifType'] === 'l2vlan') {
$label = 'L2 VLAN ';
} elseif ($this_port['ifType'] === 'l3ipvlan' || $this_port['ifType'] === 'l3ipxvlan') {
$label = 'L3 VLAN ';
} elseif ($this_port['ifType'] === 'ieee8023adLag') {
$label = 'LAG ';
} elseif (str_starts($this_port['port_label'], 'Stack')) {
$label = 'STACK ';
} else {
$label = '' . $this_port['human_type'] . ' ';
//r($this_port);
}
$string .= $br . ' ' . generate_port_link($this_port) . ' ' . $label;
$br = " ";
}
}
}
if (!isset($cache['ports_option']['ports_stack_high']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_high'])) {
foreach (dbFetchRows("SELECT * FROM `ports_stack`
WHERE `port_id_high` = ? AND `device_id` = ? AND `ifStackStatus` = ?",
[$port['ifIndex'], $device['device_id'], 'active']) as $lower_if) {
if (!$lower_if['port_id_low']) {
continue;
}
//if (isset($pagp[$device['device_id']][$port['ifIndex']][$lower_if['port_id_low']])) { continue; } // Skip if same PAgP ports
if ($this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low'])) {
$string .= $br . ' ' . generate_port_link($this_port) . '';
$br = " ";
}
}
}
unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
$string .= ' |
';
} // End Detailed View
// If we're showing graphs, generate the graph and print the img tags
if ($vars['graph'] === "etherlike") {
$graph_file = get_port_rrdfilename($port, "dot3", TRUE);
} else {
$graph_file = get_port_rrdfilename($port, NULL, TRUE);
}
if ($vars['graph'] && is_file($graph_file)) {
$string .= '