function renderObjectPortRow($port, $is_highlighted) { // highlight port name with yellow if it's name is not canonical $canon_pn = shortenPortName($port['name'], $port['object_id']); $name_class = $canon_pn == $port['name'] ? '' : 'trwarning'; echo '<tr'; if ($is_highlighted) { echo ' class=highlight'; } $a_class = isEthernetPort($port) ? 'port-menu' : ''; echo "><td class='tdleft {$name_class}' NOWRAP><a name='port-{$port['id']}' class='interactive-portname nolink {$a_class}'>{$port['name']}</a></td>"; echo "<td class=tdleft>{$port['label']}</td>"; echo "<td class=tdleft>" . formatPortIIFOIF($port) . "</td><td class=tdleft><tt>{$port['l2address']}</tt></td>"; if ($port['remote_object_id']) { echo "<td class=tdleft>" . formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL) . "</td>"; echo "<td class=tdleft>" . formatLoggedSpan($port['last_log'], $port['remote_name'], 'underline') . "</td>"; $editable = permitted('object', 'ports', 'editPort') ? 'editable' : ''; echo "<td class=tdleft><span class='rsvtext {$editable} id-{$port['id']} op-upd-reservation-cable'>{$port['cableid']}</span></td>"; } else { echo implode('', formatPortReservation($port)) . '<td></td>'; } echo "</tr>"; }
function renderObject($object_id) { global $nextorder, $virtual_obj_types; $info = spotEntity('object', $object_id); amplifyCell($info); $has_children = count($info['children']) ? TRUE : FALSE; // Main layout starts. echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>"; echo "<tr><td colspan=2 align=center><h1>{$info['dname']}</h1></td></tr>\n"; // left column with uknown number of portlets echo "<tr><td class=pcleft>"; // display summary portlet $summary = array(); if (strlen($info['name'])) { $summary['Common name'] = $info['name']; } elseif (considerConfiguredConstraint($info, 'NAMEWARN_LISTSRC')) { $summary[] = array('<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>'); } $summary['Object type'] = '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'cfe' => '{$typeid_' . $info['objtype_id'] . '}')) . '">' . decodeObjectType($info['objtype_id'], 'o') . '</a>'; if (strlen($info['label'])) { $summary['Visible label'] = $info['label']; } if (strlen($info['asset_no'])) { $summary['Asset tag'] = $info['asset_no']; } elseif (considerConfiguredConstraint($info, 'ASSETWARN_LISTSRC')) { $summary[] = array('<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>'); } $parents = getEntityRelatives('parents', 'object', $object_id); if (count($parents)) { $fmt_parents = array(); foreach ($parents as $parent) { $fmt_parents[] = "<a href='" . makeHref(array('page' => $parent['page'], $parent['id_name'] => $parent['entity_id'])) . "'>{$parent['name']}</a>"; } $summary[count($parents) > 1 ? 'Containers' : 'Container'] = implode('<br>', $fmt_parents); } if ($has_children) { $children = getEntityRelatives('children', 'object', $object_id); $fmt_children = array(); foreach ($children as $child) { $fmt_children[] = "<a href='" . makeHref(array('page' => $child['page'], $child['id_name'] => $child['entity_id'])) . "'>{$child['name']}</a>"; } $summary['Contains'] = implode('<br>', $fmt_children); } if ($info['has_problems'] == 'yes') { $summary[] = array('<tr><td colspan=2 class=msg_error>Has problems</td></tr>'); } foreach (getAttrValuesSorted($object_id) as $record) { if (strlen($record['value']) and permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) { $summary['{sticker}' . $record['name']] = formatAttributeValue($record); } } $summary[] = array(getOutputOf('printTagTRs', $info, makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => '{$typeid_' . $info['objtype_id'] . '}')) . "&")); renderEntitySummary($info, 'Summary', $summary); if (strlen($info['comment'])) { startPortlet('Comment'); echo '<div class=commentblock>' . string_insert_hrefs($info['comment']) . '</div>'; finishPortlet(); } $logrecords = getLogRecordsForObject($_REQUEST['object_id']); if (count($logrecords)) { startPortlet('Log records'); echo "<table cellspacing=0 cellpadding=5 align=center class=widetable width='100%'>"; $order = 'odd'; foreach ($logrecords as $row) { echo "<tr class=row_{$order} valign=top>"; echo '<td class=tdleft>' . $row['date'] . '<br>' . $row['user'] . '</td>'; echo '<td class="logentry">' . string_insert_hrefs(htmlspecialchars($row['content'], ENT_NOQUOTES)) . '</td>'; echo '</tr>'; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); } switchportInfoJS($object_id); // load JS code to make portnames interactive renderFilesPortlet('object', $object_id); if (count($info['ports'])) { startPortlet('Ports and links'); $hl_port_id = 0; if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = $_REQUEST['hl_port_id']; addAutoScrollScript("port-{$hl_port_id}"); } echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>"; echo '<tr>'; if ($has_children) { echo '<th class=tdleft>Object</th>'; } echo '<th class=tdleft>Local name</th><th class=tdleft>Visible label</th>'; echo '<th class=tdleft>Interface</th><th class=tdleft>L2 address</th>'; echo '<th class=tdcenter colspan=2>Remote object and port</th>'; echo '<th class=tdleft>Cable ID</th></tr>'; // note how many ports each object has if ($has_children) { $port_count = array(); foreach ($info['ports'] as $port) { $port_count[$port['object_id']] = isset($port_count[$port['object_id']]) ? $port_count[$port['object_id']] + 1 : 1; } $last_object_id = 0; } foreach ($info['ports'] as $port) { // highlight port name with yellow if it's name is not canonical $canon_pn = shortenPortName($port['name'], $port['object_id']); $name_class = $canon_pn == $port['name'] ? '' : 'trwarning'; $tr_class = $hl_port_id == $port['id'] ? 'class=highlight' : ''; echo "<tr {$tr_class} valign=top>"; if ($has_children and $last_object_id != $port['object_id']) { $rowspan = $port_count[$port['object_id']] > 1 ? 'rowspan="' . $port_count[$port['object_id']] . '"' : ''; $object_name = $port['object_id'] == $object_id ? $port['object_name'] : formatPortLink($port['object_id'], $port['object_name'], NULL, NULL); echo "<td class=tdleft {$rowspan}>{$object_name}</td>"; $last_object_id = $port['object_id']; } $a_class = isEthernetPort($port) ? 'port-menu' : ''; echo "<td class='tdleft {$name_class}' NOWRAP><a name='port-{$port['id']}' class='interactive-portname nolink {$a_class}'>{$port['name']}</a></td>"; echo "<td class=tdleft>{$port['label']}</td>"; echo "<td class=tdleft>" . formatPortIIFOIF($port) . "</td><td class=tdleft><tt>{$port['l2address']}</tt></td>"; if ($port['remote_object_id']) { echo "<td class=tdleft>" . formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL) . "</td>"; echo "<td class=tdleft>" . formatLoggedSpan($port['last_log'], $port['remote_name'], 'underline') . "</td>"; $editable = permitted('object', 'ports', 'editPort') ? 'editable' : ''; echo "<td class=tdleft><span class='rsvtext {$editable} id-{$port['id']} op-upd-reservation-cable'>{$port['cableid']}</span></td>"; } else { echo implode('', formatPortReservation($port)) . '<td></td>'; } echo "</tr>"; } if (permitted(NULL, 'ports', 'set_reserve_comment')) { addJS('js/inplace-edit.js'); } echo '</table><br>'; finishPortlet(); } if (count($info['ipv4']) + count($info['ipv6'])) { startPortlet('IP addresses'); echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n"; $object_header = $has_children ? '<th>Object</th>' : ''; $extended_header = getConfigVar('EXT_IPV4_VIEW') == 'yes' ? '<th>network</th><th>routed by</th>' : ''; echo "<tr class=tdleft>{$object_header}<th>OS interface</th><th>IP address</th>{$extended_header}<th>peers</th></tr>\n"; // group IP allocations by object and interface name instead of address family $allocs_by_object = array(); foreach (array('ipv4', 'ipv6') as $ip_v) { foreach ($info[$ip_v] as $alloc) { $allocs_by_object[$alloc['object_id']]['object_name'] = $alloc['object_name']; $allocs_by_object[$alloc['object_id']]['interfaces'][$alloc['osif']][$alloc['ip']] = $alloc; } } uasort($allocs_by_object, buildNatCmpFunction('object_name')); foreach ($allocs_by_object as $alloc_object_id => $allocs_by_iface) { $is_first_object_row = TRUE; $num_allocs = 0; foreach ($allocs_by_iface['interfaces'] as $iface_name => $alloclist) { $num_allocs += count($alloclist); } // display each interface (already sorted by amplifyAllocationList) foreach ($allocs_by_iface['interfaces'] as $iface_name => $alloclist) { $is_first_iface_row = TRUE; foreach ($alloclist as $alloc) { $rendered_alloc = callHook('getRenderedAlloc', $alloc['object_id'], $alloc); echo "<tr class='{$rendered_alloc['tr_class']}' valign=top>"; // display iface name, same values are grouped into single cell if ($has_children and $is_first_object_row) { $object_rowspan = $num_allocs > 1 ? 'rowspan="' . $num_allocs . '"' : ''; $object_name = $alloc['object_id'] == $object_id ? $alloc['object_name'] : formatPortLink($alloc['object_id'], $alloc['object_name'], NULL, NULL); echo "<td class=tdleft {$object_rowspan}>{$object_name}</td>"; $is_first_object_row = FALSE; } // display iface name, same values are grouped into single cell if ($is_first_iface_row) { $iface_rowspan = count($alloclist) > 1 ? 'rowspan="' . count($alloclist) . '"' : ''; echo "<td class=tdleft {$iface_rowspan}>" . $iface_name . $rendered_alloc['td_name_suffix'] . '</td>'; $is_first_iface_row = FALSE; } echo $rendered_alloc['td_ip']; if (getConfigVar('EXT_IPV4_VIEW') == 'yes') { echo $rendered_alloc['td_network']; echo $rendered_alloc['td_routed_by']; } echo $rendered_alloc['td_peers']; echo "</tr>\n"; } } } echo "</table><br>\n"; finishPortlet(); } $forwards = $info['nat4']; if (count($forwards['in']) or count($forwards['out'])) { startPortlet('NATv4'); if (count($forwards['out'])) { echo "<h3>locally performed NAT</h3>"; echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n"; echo "<tr><th>Proto</th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Rule comment</th></tr>\n"; foreach ($forwards['out'] as $pf) { $class = 'trerror'; $osif = ''; if (isset($alloclist[$pf['localip']])) { $class = $alloclist[$pf['localip']]['addrinfo']['class']; $osif = $alloclist[$pf['localip']]['osif'] . ': '; } echo "<tr class='{$class}'>"; echo "<td>{$pf['proto']}</td><td class=tdleft>{$osif}" . getRenderedIPPortPair($pf['localip'], $pf['localport']) . "</td>"; echo "<td class=tdleft>" . getRenderedIPPortPair($pf['remoteip'], $pf['remoteport']) . "</td>"; $address = getIPAddress(ip4_parse($pf['remoteip'])); echo "<td class='description'>"; if (count($address['allocs'])) { foreach ($address['allocs'] as $bond) { echo mkA("{$bond['object_name']}({$bond['name']})", 'object', $bond['object_id']) . ' '; } } elseif (strlen($pf['remote_addr_name'])) { echo '(' . $pf['remote_addr_name'] . ')'; } echo "</td><td class='description'>{$pf['description']}</td></tr>"; } echo "</table><br><br>"; } if (count($forwards['in'])) { echo "<h3>arriving NAT connections</h3>"; echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n"; echo "<tr><th>Matched endpoint</th><th>Source object</th><th>Translated to</th><th>Rule comment</th></tr>\n"; foreach ($forwards['in'] as $pf) { echo "<tr>"; echo "<td>{$pf['proto']}/" . getRenderedIPPortPair($pf['localip'], $pf['localport']) . "</td>"; echo '<td class="description">' . mkA($pf['object_name'], 'object', $pf['object_id']); echo "</td><td>" . getRenderedIPPortPair($pf['remoteip'], $pf['remoteport']) . "</td>"; echo "<td class='description'>{$pf['description']}</td></tr>"; } echo "</table><br><br>"; } finishPortlet(); } renderSLBTriplets2($info); renderSLBTriplets($info); echo "</td>\n"; // After left column we have (surprise!) right column with rackspace portlet only. echo "<td class=pcright>"; if (!in_array($info['objtype_id'], $virtual_obj_types)) { // rackspace portlet startPortlet('Rackspace allocation'); foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { renderRack($rack_id, $object_id); } echo '<br>'; finishPortlet(); } echo "</td></tr>"; echo "</table>\n"; }