'; echo ''; echo 'VLAN IDVLAN Name'; echo 'Devices'; echo 'Tagged / Untagged'; echo 'Unique MACs'; echo ''; foreach (get_vlans($vars) as $vlan_id => $vlan) { if ($vlan_id === '') { continue; } if (is_array($vlan['names'])) { ksort($vlan['names']); $first_vlan = array_keys($vlan['names'])[0]; } else { $first_vlan = "VLAN $vlan_id"; } // Fixme - improve method of choosing which name to use. //r($vlan['names']); echo ''; echo '' . $vlan_id . ''; echo '' . generate_link($first_vlan, ['page' => 'vlan', 'vlan_id' => $vlan_id]) . ''; echo '' . $vlan['counts']['devices'] . ''; echo '' . $vlan['counts']['ports_tagged'] . ' ' . $vlan['counts']['ports_untagged'] . ''; echo '' . $vlan['counts']['macs'] . ''; echo ''; } echo ''; echo generate_box_close(); //r($vlans); } else { // Per-VLAN page /* FIXME. unsed here? foreach (dbFetchRows("SELECT `vlan_vlan`, `vlan_name` FROM `vlans`") as $vlan) { $vlans[$vlan['vlan_vlan']]['names'][$vlan['vlan_name']]++; } */ $count_untagged = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifVlan` = ?", [$vars['vlan_id']]); $count_device = dbFetchCell("SELECT COUNT(DISTINCT(`device_id`)) FROM `vlans` WHERE `vlan_vlan` = ?", [$vars['vlan_id']]); $count_tagged = dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `vlan` = ?", [$vars['vlan_id']]); $count_mac = dbFetchCell("SELECT COUNT(DISTINCT(`mac_address`)) AS `count` FROM `vlans_fdb` WHERE `vlan_id` = ?", [$vars['vlan_id']]); echo generate_box_open(); echo '
VLAN ' . escape_html($vars['vlan_id']) . '
Devices
' . $count_device . '
Tagged Ports
' . $count_tagged . '
Untagged Ports
' . $count_untagged . '
MACs
' . $count_mac . '
'; echo generate_box_close(); $navbar = ['brand' => "VLAN " . $vars['vlan_id'], 'class' => "navbar-narrow"]; $navbar['options']['devices']['text'] = 'Devices'; //$navbar['options']['untagged']['text'] = 'Untagged Ports'; //$navbar['options']['tagged']['text'] = 'Tagged Ports'; $navbar['options']['macs']['text'] = 'MAC Addresses'; foreach ($navbar['options'] as $option => $array) { if (!isset($vars['view'])) { $vars['view'] = "devices"; } if ($vars['view'] == $option) { $navbar['options'][$option]['class'] .= " active"; } $navbar['options'][$option]['url'] = generate_url($vars, ['view' => $option]); } $navbar['options']['vlans']['text'] = "Back to VLANs"; $navbar['options']['vlans']['icon'] = "icon-angle-left"; $navbar['options']['vlans']['url'] = generate_url(['page' => 'vlan']); $navbar['options']['vlans']['right'] = TRUE; print_navbar($navbar); unset($navbar); switch ($vars['view']) { case "tagged": break; case "untagged": break; case "macs": echo generate_box_open(); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $macs = dbFetchRows("SELECT *, COUNT(DISTINCT(`mac_address`)) AS `count`, COUNT(DISTINCT(`device_id`)) AS `device_count` FROM `vlans_fdb` WHERE `vlan_id` = ? GROUP BY `mac_address`", [$vars['vlan_id']]); $mac_list = array_column($macs, 'mac_address'); $sql = "SELECT * FROM ports, devices WHERE 1 "; $sql .= generate_query_values_and($mac_list, 'ifPhysAddress'); $sql .= " AND ports.device_id = devices.device_id"; $ports = []; foreach (dbFetchRows($sql) as $p) { $ports[$p['ifPhysAddress']] = $p; } foreach ($macs as $mac) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
MAC AddressDevicesEntriesDevicePort
' . format_mac($mac['mac_address']) . '' . $mac['device_count'] . '' . $mac['count'] . '' . (isset($ports[$mac['mac_address']]) ? generate_device_link($ports[$mac['mac_address']]) : '') . '' . (isset($ports[$mac['mac_address']]) ? generate_port_link($ports[$mac['mac_address']]) : '') . '' . ((isset($ports[$mac['mac_address']]) && strlen($ports[$mac['mac_address']]['ifAlias'])) ? '' . $ports[$mac['mac_address']]['ifAlias'] . '' : '') . '
'; break; case "devices": default: $devices = dbFetchRows("SELECT * FROM `vlans` LEFT JOIN `devices` USING (`device_id`) WHERE `vlan_vlan` = ? ORDER BY `hostname`", [ $vars['vlan_id'] ]); echo generate_box_open(); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($devices as $device) { //$device = device_by_id_cache($device_id); print_device_row($device, [], [ 'tab' => 'vlans' ]); } echo '
DeviceHardwareOSUptime
'; } } // EOF