function renderVLANInfo($vlan_ck) { global $vtoptions, $nextorder; $vlan = getVLANInfo($vlan_ck); echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>'; echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>'; echo "<tr><td class=pcleft width='50%'>"; startPortlet('summary'); echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>"; echo "<tr><th width='50%' class=tdright>Domain:</th><td class=tdleft>"; echo niftyString($vlan['domain_descr'], 0) . '</td></tr>'; echo "<tr><th width='50%' class=tdright>VLAN ID:</th><td class=tdleft>{$vlan['vlan_id']}</td></tr>"; if (strlen($vlan['vlan_descr'])) { echo "<tr><th width='50%' class=tdright>Description:</th><td class=tdleft>" . niftyString($vlan['vlan_descr'], 0) . "</td></tr>"; } echo "<tr><th width='50%' class=tdright>Propagation:</th><td class=tdleft>" . $vtoptions[$vlan['vlan_prop']] . "</td></tr>"; $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1); foreach ($others as $other) { if ($other['domain_id'] != $vlan['domain_id']) { echo '<tr><th class=tdright>Counterpart:</th><td class=tdleft>' . formatVLANAsHyperlink(getVLANInfo("{$other['domain_id']}-{$vlan['vlan_id']}")) . '</td></tr>'; } } echo '</table>'; finishPortlet(); if (0 == count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) { startPortlet('no networks'); } else { startPortlet('networks (' . (count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) . ')'); $order = 'odd'; echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th>'; printImageHREF('net'); echo '</th><th>'; printImageHREF('text'); echo '</th></tr>'; foreach (array('ipv4net', 'ipv6net') as $nettype) { foreach ($vlan[$nettype . 's'] as $netid) { $net = spotEntity($nettype, $netid); #echo "<tr class=row_${order}><td>"; echo '<tr><td>'; renderCell($net); echo '</td><td>' . (mb_strlen($net['comment']) ? niftyString($net['comment']) : ' '); echo '</td></tr>'; $order = $nextorder[$order]; } } echo '</table>'; } finishPortlet(); $confports = getVLANConfiguredPorts($vlan_ck); // get non-switch device list $foreign_devices = array(); foreach ($confports as $switch_id => $portlist) { $object = spotEntity('object', $switch_id); foreach ($portlist as $port_name) { if ($portinfo = getPortinfoByName($object, $port_name)) { if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) { $foreign_devices[$portinfo['remote_object_id']][] = $portinfo; } } } } if (!empty($foreign_devices)) { startPortlet("Non-switch devices"); echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>"; echo '<tr><th>device</th><th>ports</th></tr>'; $order = 'odd'; foreach ($foreign_devices as $cell_id => $ports) { echo "<tr class=row_{$order} valign=top><td>"; $cell = spotEntity('object', $cell_id); renderCell($cell); echo "</td><td><ul>"; foreach ($ports as $portinfo) { echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' — ' . formatPort($portinfo) . "</li>"; } echo "</ul></td></tr>"; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); } echo '</td><td class=pcright>'; if (!count($confports)) { startPortlet('no ports'); } else { startPortlet('Switch ports (' . count($confports) . ')'); global $nextorder; $order = 'odd'; echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>'; echo '<tr><th>switch</th><th>ports</th></tr>'; foreach ($confports as $switch_id => $portlist) { usort_portlist($portlist); echo "<tr class=row_{$order} valign=top><td>"; $object = spotEntity('object', $switch_id); renderCell($object); echo '</td><td class=tdleft><ul>'; foreach ($portlist as $port_name) { echo '<li>'; if ($portinfo = getPortinfoByName($object, $port_name)) { echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']); } else { echo $port_name; } echo '</li>'; } echo '</ul></td></tr>'; $order = $nextorder[$order]; } echo '</table>'; } finishPortlet(); echo '</td></tr></table>'; }
function renderVLANInfo($vlan_ck) { global $vtoptions, $nextorder; $vlan = getVLANInfo($vlan_ck); $group_members = getDomainGroupMembers($vlan['domain_id']); // list of VLANs to display linked nets and ports from. // If domain is a group master, this list contains all // the counterpart vlans from domain group members. // If domain is a group member, the list contains one // counterpart vlan from the domain master. $group_ck_list = array(); echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>'; echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>'; echo "<tr><td class=pcleft width='50%'>"; $summary = array(); $summary['Domain'] = stringForTD($vlan['domain_descr'], 0); $summary['VLAN ID'] = $vlan['vlan_id']; if (strlen($vlan['vlan_descr'])) { $summary['Description'] = stringForTD($vlan['vlan_descr'], 0); } $summary['Propagation'] = $vtoptions[$vlan['vlan_prop']]; $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1); $counterparts = array(); $group_counterparts = array(); $domain_list = getVLANDomainOptions(); foreach ($others as $other) { if ($other['domain_id'] != $vlan['domain_id']) { $counterpart_ck = "{$other['domain_id']}-{$vlan['vlan_id']}"; $counterpart_vlan = getVlanRow($counterpart_ck); $counterpart_link = mkA($domain_list[$counterpart_vlan['domain_id']] . ': ' . $counterpart_vlan['vlan_descr'], 'vlan', $counterpart_ck); if ($counterpart_vlan['domain_id'] == $vlan['domain_group_id'] or in_array($counterpart_vlan['domain_id'], $group_members)) { $group_ck_list[$counterpart_ck] = $counterpart_vlan; $group_counterparts[] = $counterpart_link; } elseif ($vlan['domain_group_id'] and $counterpart_vlan['domain_group_id'] == $vlan['domain_group_id']) { $group_counterparts[] = $counterpart_link; } else { $counterparts[] = $counterpart_link; } } } if ($group_counterparts) { $group_id = $vlan['domain_group_id'] ? $vlan['domain_group_id'] : $vlan['domain_id']; $summary[$domain_list[$group_id] . ' counterparts'] = implode('<br>', $group_counterparts); } if ($counterparts) { $summary['Counterparts'] = implode('<br>', $counterparts); } renderEntitySummary($vlan, 'summary', $summary); $networks = array(); $net_vlan_list = array($vlan); foreach (array_keys($group_ck_list) as $grouped_ck) { $net_vlan_list[] = getVLANInfo($grouped_ck); } foreach ($net_vlan_list as $net_vlan) { foreach (array('ipv4net' => 'ipv4nets', 'ipv6net' => 'ipv6nets') as $realm => $key) { foreach ($net_vlan[$key] as $net_id) { $networks["{$realm}-{$net_id}"] = spotEntity($realm, $net_id); } } } if (0 == count($networks)) { startPortlet('no networks'); } else { startPortlet('networks (' . count($networks) . ')'); $order = 'odd'; echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th>'; printImageHREF('net'); echo '</th><th>'; printImageHREF('text'); echo '</th></tr>'; foreach ($networks as $net) { echo '<tr><td>'; renderCell($net); echo '</td><td>' . stringForTD($net['comment']); echo '</td></tr>'; $order = $nextorder[$order]; } echo '</table>'; } finishPortlet(); $confports = getVLANConfiguredPorts($vlan_ck); foreach (array_keys($group_ck_list) as $grouped_ck) { $confports += getVLANConfiguredPorts($grouped_ck); } if ($vlan['domain_group_id']) { // we should find configured port on master's members // even if master domain itself does not have such VLAN $master_ck = $vlan['domain_group_id'] . '-' . $vlan['vlan_id']; if (!isset($group_ck_list[$master_ck])) { $confports += getVLANConfiguredPorts($master_ck); } } // get non-switch device list $foreign_devices = array(); foreach ($confports as $switch_id => $portlist) { $object = spotEntity('object', $switch_id); foreach ($portlist as $port_name) { if ($portinfo = getPortinfoByName($object, $port_name)) { if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) { $foreign_devices[$portinfo['remote_object_id']][] = $portinfo; } } } } if (!empty($foreign_devices)) { startPortlet("Non-switch devices"); echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>"; echo '<tr><th>device</th><th>ports</th></tr>'; $order = 'odd'; foreach ($foreign_devices as $cell_id => $ports) { echo "<tr class=row_{$order} valign=top><td>"; $cell = spotEntity('object', $cell_id); renderCell($cell); echo "</td><td><ul>"; foreach ($ports as $portinfo) { echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' — ' . formatPort($portinfo) . "</li>"; } echo "</ul></td></tr>"; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); } echo '</td><td class=pcright>'; if (!count($confports)) { startPortlet('no ports'); } else { startPortlet('Switch ports (' . count($confports) . ')'); global $nextorder; $order = 'odd'; echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>'; echo '<tr><th>switch</th><th>ports</th></tr>'; foreach ($confports as $switch_id => $portlist) { usort_portlist($portlist); echo "<tr class=row_{$order} valign=top><td>"; $object = spotEntity('object', $switch_id); renderCell($object); echo '</td><td class=tdleft><ul>'; foreach ($portlist as $port_name) { echo '<li>'; if ($portinfo = getPortinfoByName($object, $port_name)) { echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']); if ($portinfo['linked']) { echo ' — ' . formatPortLink($portinfo['remote_object_id'], $portinfo['remote_object_name'], $portinfo['remote_id'], NULL); } } else { echo $port_name; } echo '</li>'; } echo '</ul></td></tr>'; $order = $nextorder[$order]; } echo '</table>'; } finishPortlet(); echo '</td></tr></table>'; }