function CableIDTabHandler() { echo '<div class=portlet><h2>Cable ID Helper</h2></div>'; $rack = spotEntity('rack', $_REQUEST['rack_id']); $result = usePreparedSelectBlade('SELECT DISTINCT object_id FROM RackSpace WHERE rack_id = ? ', array($rack['id'])); $objects = $result->fetchAll(PDO::FETCH_ASSOC); $cableIDs = array(); foreach ($objects as $object) { $pals = getObjectPortsAndLinks($object['object_id']); foreach ($pals as $portLink) { if ($portLink['cableid']) { $new = true; $dublicate = false; foreach ($cableIDs as $key => $cableID) { if ($portLink['object_id'] == $cableID['object1_id'] && $portLink['name'] == $cableID['object1_port'] || $portLink['object_id'] == $cableID['object2_id'] && $portLink['name'] == $cableID['object2_port']) { $new = false; // Link already in List } // Check for duplicate cable ids if ($new && $portLink['cableid'] == $cableID['cableID']) { $dublicate = true; $cableIDs[$key]['dublicate'] = true; } } if ($new) { $cableID = array(); $cableID['cableID'] = $portLink['cableid']; $cableID['object1_id'] = $portLink['object_id']; $cableID['object1_name'] = $portLink['object_name']; $cableID['object1_port'] = $portLink['name']; $cableID['object2_id'] = $portLink['remote_object_id']; $cableID['object2_name'] = $portLink['remote_object_name']; $cableID['object2_port'] = $portLink['remote_name']; $cableID['dublicate'] = $dublicate; array_push($cableIDs, $cableID); } } } } // Sort by cableIDs usort($cableIDs, function ($elem1, $elem2) { return strnatcasecmp($elem1['cableID'], $elem2['cableID']); }); // Print table echo '<table class="cooltable" align="center" border="0" cellpadding="5" cellspacing="0">' . '<tbody>' . ' <tr>' . ' <th>CableID</th>' . ' <th>Object 1</th>' . ' <th>Object 2</th>' . ' </tr>'; $i = 0; foreach ($cableIDs as $cableID) { if ($i % 2) { $class = 'row_even tdleft'; } else { $class = 'row_odd tdleft'; } if ($cableID['dublicate']) { $class .= ' trerror'; } echo '<tr class="' . $class . '">' . '<td>' . $cableID['cableID'] . '</td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object1_id'])) . '">' . $cableID['object1_name'] . ': ' . $cableID['object1_port'] . '</a></td>' . '<td><a href="' . makeHref(array('page' => 'object', 'object_id' => $cableID['object2_id'])) . '">' . $cableID['object2_name'] . ': ' . $cableID['object2_port'] . '</a></td>' . '</tr>'; $i++; } echo ' </tbody>' . '</table>'; }
function formatPortMacHints($object_id) { $result = array(); if ($_REQUEST['ac'] == 'get-port-portmac') { $port_name = $_REQUEST['port_name']; $ports = reduceSubarraysToColumn(getObjectPortsAndLinks($_REQUEST['object_id']), 'name'); $macList = in_array($port_name, $ports) ? queryDevice($object_id, 'getportmaclist', array($port_name)) : array(); } else { $macList = queryDevice($object_id, 'getmaclist'); } foreach ($macList as $portname => $list) { $list = $macList[$portname]; $visible_part = count($list) . ' MACs'; $result[$portname]['inline'] = $visible_part; if (count($list)) { $hidden_part = '<table width="100%"><tr><th>MAC<th>VID</tr>'; foreach ($list as $mac) { $hidden_part .= '<tr><td>' . $mac['mac'] . '<td>' . $mac['vid'] . '</tr>'; } $result[$portname]['popup'] = $hidden_part; } } return $result; }
function renameObjectPorts() { $object_id = getBypassValue(); $n = 0; foreach (getObjectPortsAndLinks($object_id) as $port) { $canon_pn = shortenPortName($port['name'], $port['object_id']); if ($canon_pn != $port['name']) { commitUpdatePort($object_id, $port['id'], $canon_pn, $port['oif_id'], $port['label'], $port['l2address'], $port['reservation_comment']); $n++; } } if ($n) { showSuccess("Renamed {$n} ports"); } else { showNotice("Nothing renamed"); } }
function amplifyCell(&$record, $dummy = NULL) { switch ($record['realm']) { case 'object': $record['ports'] = getObjectPortsAndLinks($record['id']); $record['ipv4'] = getObjectIPv4Allocations($record['id']); $record['ipv6'] = getObjectIPv6Allocations($record['id']); $record['nat4'] = getNATv4ForObject($record['id']); $record['files'] = getFilesOfEntity($record['realm'], $record['id']); break; case 'file': $record['links'] = getFileLinks($record['id']); break; case 'location': $record['locations'] = getLocations($record['id']); $record['rows'] = getRows($record['id']); break; case 'row': $record['racks'] = getRacks($record['id']); case 'rack': $record['mountedObjects'] = array(); // start with default rackspace for ($i = $record['height']; $i > 0; $i--) { for ($locidx = 0; $locidx < 3; $locidx++) { $record[$i][$locidx]['state'] = 'F'; } } // load difference $query = "select unit_no, atom, state, object_id " . "from RackSpace where rack_id = ? and " . "unit_no between 1 and ? order by unit_no"; $result = usePreparedSelectBlade($query, array($record['id'], $record['height'])); global $loclist; $mounted_objects = array(); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $record[$row['unit_no']][$loclist[$row['atom']]]['state'] = $row['state']; $record[$row['unit_no']][$loclist[$row['atom']]]['object_id'] = $row['object_id']; if ($row['state'] == 'T' and $row['object_id'] != NULL) { $mounted_objects[$row['object_id']] = TRUE; } } $record['mountedObjects'] = array_keys($mounted_objects); unset($result); break; case 'vst': $record['rules'] = array(); $record['switches'] = array(); $result = usePreparedSelectBlade('SELECT rule_no, port_pcre, port_role, wrt_vlans, description ' . 'FROM VLANSTRule WHERE vst_id = ? ORDER BY rule_no', array($record['id'])); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $record['rules'][$row['rule_no']] = $row; } unset($result); $result = usePreparedSelectBlade('SELECT object_id, domain_id FROM VLANSwitch WHERE template_id = ?', array($record['id'])); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $record['switches'][$row['object_id']] = $row; } break; default: } }
function localpretrigger_PortLinker() { global $portLinkerPortTypes; $record = getObjectPortsAndLinks($_REQUEST['object_id']); if (count($record) > 0) { $linkok = 1; foreach ($record as $aPort) { if (in_array($aPort['oif_id'], $portLinkerPortTypes)) { if ($linkok == 1) { $linkok = 2; } if (strlen($aPort['remote_id']) > 0) { $linkok = 0; } } } } else { $linkok = -1; } return $linkok; }
function renderVMReport() { $aResult = array(); $iTotal = 0; $sFilter = '{$typeid_1504}'; # typeid_1504 = Virtual machines foreach (scanRealmByText('object', $sFilter) as $Result) { $aResult[$Result['id']] = array(); $aResult[$Result['id']]['sName'] = $Result['name']; // Create active links in comment $aResult[$Result['id']]['sComment'] = makeLinksInText($Result['comment']); // Load additional attributes: $attributes = getAttrValues($Result['id']); $aResult[$Result['id']]['sContact'] = ''; if (isset($attributes['14']['a_value'])) { $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value']; } $aResult[$Result['id']]['OEMSN'] = ''; if (isset($attributes['1']['a_value'])) { $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value']; } $aResult[$Result['id']]['sOS'] = ''; if (isset($attributes['4']['a_value'])) { $aResult[$Result['id']]['sOS'] = $attributes['4']['a_value']; } // IP Informations $aResult[$Result['id']]['ipV4List'] = getObjectIPv4AllocationList($Result['id']); $aResult[$Result['id']]['ipV6List'] = getObjectIPv6AllocationList($Result['id']); // Port (MAC) Informations $aResult[$Result['id']]['ports'] = getObjectPortsAndLinks($Result['id']); // Container $aResult[$Result['id']]['container'] = getObjectContainerList($Result['id']); $iTotal++; } if (isset($_GET['csv'])) { header('Content-type: text/csv'); header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv'); header('Pragma: no-cache'); header('Expires: 0'); $outstream = fopen("php://output", "w"); $aCSVRow = array('Name', 'MAC', 'IP(s)', 'Comment', 'Contact', 'OS', 'Hypervisor'); fputcsv($outstream, $aCSVRow); foreach ($aResult as $id => $aRow) { $aCSVRow = array(); $aCSVRow[0] = $aRow['sName']; $aCSVRow[1] = ''; foreach ($aRow['ports'] as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { $aCSVRow[1] .= $aPortDetails['l2address'] . ' '; } } $aCSVRow[1] = trim($aCSVRow[1]); $aCSVRow[2] = ''; foreach ($aRow['ipV4List'] as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { $aCSVRow[2] .= $key . ' '; } } foreach ($aRow['ipV6List'] as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } if (trim($key) != '') { $aCSVRow[2] .= $key . ' '; } } $aCSVRow[2] = trim($aCSVRow[2]); $aCSVRow[3] = str_replace('"', "'", $aRow['sComment']); $aCSVRow[4] = $aRow['sContact']; $aCSVRow[5] = $aRow['sOS']; $aCSVRow[6] = ''; foreach ($aRow['container'] as $key => $aDetails) { $aCSVRow[6] .= trim($aDetails['container_name']) . ' '; } $aCSVRow[6] = trim($aCSVRow[6]); fputcsv($outstream, $aCSVRow); } fclose($outstream); exit(0); # Exit normally after send CSV to browser } // Load stylesheet and jquery scripts addCSS('css/extensions/style.css'); addJS('js/extensions/jquery-latest.js'); addJS('js/extensions/jquery.tablesorter.js'); addJS('js/extensions/picnet.table.filter.min.js'); // Display the stat array echo "<h2>Virtual machines report ({$iTotal})</h2><ul>"; echo '<a href="index.php?page=reports&tab=vm&csv">CSV Export</a>'; echo '<table id="reportTable" class="tablesorter"> <thead> <tr> <th>Name</th> <th>MAC</th> <th>IP(s)</th> <th>Comment</th> <th>Contact</th> <th>OS</th> <th>Hypervisor</th> </tr> </thead> <tbody>'; foreach ($aResult as $id => $aRow) { echo '<tr> <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td> <td>'; foreach ($aRow['ports'] as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { echo $aPortDetails['l2address'] . '<br/>'; } } echo ' </td>' . ' <td>'; foreach ($aRow['ipV4List'] as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { echo $key . '<br/>'; } } foreach ($aRow['ipV6List'] as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } else { $key = new IPv6Address($key); } if (trim($key) != '') { echo $key . '<br/>'; } } echo ' </td> <td>' . $aRow['sComment'] . '</td> <td>' . $aRow['sContact'] . '</td> <td>' . $aRow['sOS'] . '</td> <td>'; foreach ($aRow['container'] as $key => $aDetails) { echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['container_name'] . '</a><br/>'; } echo '</td> </tr>'; } echo ' </tbody> </table>'; echo '<script type="text/javascript"> $(document).ready(function() { $.tablesorter.defaults.widgets = ["zebra"]; $("#reportTable").tablesorter( { headers: { 2: { sorter: "ipAddress" } }, sortList: [[0,0]] } ); $("#reportTable").tableFilter(); } ); </script>'; }
function renderDiscoveredNeighbors($object_id) { global $tabno; $opcode_by_tabno = array('livecdp' => 'getcdpstatus', 'livelldp' => 'getlldpstatus'); try { $neighbors = queryDevice($object_id, $opcode_by_tabno[$tabno]); $neighbors = sortPortList($neighbors); } catch (RTGatewayError $e) { showError($e->getMessage()); return; } $mydevice = spotEntity('object', $object_id); amplifyCell($mydevice); // reindex by port name $myports = array(); foreach ($mydevice['ports'] as $port) { if (mb_strlen($port['name'])) { $myports[$port['name']][] = $port; } } // scroll to selected port if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = intval($_REQUEST['hl_port_id']); addAutoScrollScript("port-{$hl_port_id}"); } switchportInfoJS($object_id); // load JS code to make portnames interactive printOpFormIntro('importDPData'); echo '<br><table cellspacing=0 cellpadding=5 align=center class=widetable>'; echo '<tr><th colspan=2>local port</th><th></th><th>remote device</th><th colspan=2>remote port</th><th><input type="checkbox" checked id="cb-toggle"></th></tr>'; $inputno = 0; foreach ($neighbors as $local_port => $remote_list) { $initial_row = TRUE; // if port has multiple neighbors, the first table row is initial // array of local ports with the name specified by DP $local_ports = isset($myports[$local_port]) ? $myports[$local_port] : array(); foreach ($remote_list as $dp_neighbor) { $error_message = NULL; $link_matches = FALSE; $portinfo_local = NULL; $portinfo_remote = NULL; $variants = array(); do { // once-cyle fake loop used only to break out of it if (!empty($local_ports)) { $portinfo_local = $local_ports[0]; } // find remote object by DP information $dp_remote_object_id = searchByMgmtHostname($dp_neighbor['device']); if (!$dp_remote_object_id) { $dp_remote_object_id = lookupEntityByString('object', $dp_neighbor['device']); } if (!$dp_remote_object_id) { $error_message = "No such neighbor <i>{$dp_neighbor['device']}</i>"; break; } $dp_remote_object = spotEntity('object', $dp_remote_object_id); $dp_neighbor['port'] = shortenIfName($dp_neighbor['port'], NULL, $dp_remote_object['id']); // get list of ports that have name matching CDP portname $remote_ports = array(); // list of remote (by DP info) ports foreach (getObjectPortsAndLinks($dp_remote_object_id) as $port) { if ($port['name'] == $dp_neighbor['port']) { $portinfo_remote = $port; $remote_ports[] = $port; } } // check if ports with such names exist on devices if (empty($local_ports)) { $error_message = "No such local port <i>{$local_port}</i>"; break; } if (empty($remote_ports)) { $error_message = "No such port on " . formatPortLink($dp_remote_object['id'], $dp_remote_object['name'], NULL, NULL); break; } // determine match or mismatch of local link foreach ($local_ports as $portinfo_local) { if ($portinfo_local['remote_id']) { if ($portinfo_local['remote_object_id'] == $dp_remote_object_id and $portinfo_local['remote_name'] == $dp_neighbor['port']) { // set $portinfo_remote to corresponding remote port foreach ($remote_ports as $portinfo_remote) { if ($portinfo_remote['id'] == $portinfo_local['remote_id']) { break; } } $link_matches = TRUE; unset($error_message); } elseif ($portinfo_local['remote_object_id'] != $dp_remote_object_id) { $error_message = "Remote device mismatch - port linked to " . formatLinkedPort($portinfo_local); } else { // ($portinfo_local['remote_name'] != $dp_neighbor['port']) $error_message = "Remote port mismatch - port linked to " . formatPortLink($portinfo_local['remote_object_id'], NULL, $portinfo_local['remote_id'], $portinfo_local['remote_name']); } break 2; } } // no local links found, try to search for remote links foreach ($remote_ports as $portinfo_remote) { if ($portinfo_remote['remote_id']) { $remote_link_html = formatLinkedPort($portinfo_remote); $remote_port_html = formatPortLink($portinfo_remote['object_id'], NULL, $portinfo_remote['id'], $portinfo_remote['name']); $error_message = "Remote port {$remote_port_html} is already linked to {$remote_link_html}"; break 2; } } // no links found on both sides, search for a compatible port pair $port_types = array(); foreach (array('left' => $local_ports, 'right' => $remote_ports) as $side => $port_list) { foreach ($port_list as $portinfo) { $tmp_types = $portinfo['iif_id'] == 1 ? array($portinfo['oif_id'] => $portinfo['oif_name']) : getExistingPortTypeOptions($portinfo); foreach ($tmp_types as $oif_id => $oif_name) { $port_types[$side][$oif_id][] = array('id' => $oif_id, 'name' => $oif_name, 'portinfo' => $portinfo); } } } foreach ($port_types['left'] as $left_id => $left) { foreach ($port_types['right'] as $right_id => $right) { if (arePortTypesCompatible($left_id, $right_id)) { foreach ($left as $left_port) { foreach ($right as $right_port) { $variants[] = array('left' => $left_port, 'right' => $right_port); } } } } } if (!count($variants)) { // no compatible ports found $error_message = "Incompatible port types"; } } while (FALSE); // do { $tr_class = $link_matches ? 'trok' : (isset($error_message) ? 'trerror' : 'trwarning'); echo "<tr class=\"{$tr_class}\">"; if ($initial_row) { $count = count($remote_list); $td_class = ''; if (isset($hl_port_id) and $hl_port_id == $portinfo_local['id']) { $td_class = "class='border_highlight'"; } echo "<td rowspan=\"{$count}\" {$td_class} NOWRAP>" . ($portinfo_local ? formatPortLink($mydevice['id'], NULL, $portinfo_local['id'], $portinfo_local['name'], 'interactive-portname port-menu') : "<a class='interactive-portname port-menu nolink'>{$local_port}</a>") . ($count > 1 ? "<br> ({$count} neighbors)" : '') . '</td>'; $initial_row = FALSE; } echo "<td>" . ($portinfo_local ? formatPortIIFOIF($portinfo_local) : ' ') . "</td>"; echo "<td>" . formatIfTypeVariants($variants, "ports_{$inputno}") . "</td>"; echo "<td>{$dp_neighbor['device']}</td>"; echo "<td>" . ($portinfo_remote ? formatPortLink($dp_remote_object_id, NULL, $portinfo_remote['id'], $portinfo_remote['name']) : $dp_neighbor['port']) . "</td>"; echo "<td>" . ($portinfo_remote ? formatPortIIFOIF($portinfo_remote) : ' ') . "</td>"; echo "<td>"; if (!empty($variants)) { echo "<input type=checkbox name=do_{$inputno} class='cb-makelink'>"; $inputno++; } echo "</td>"; if (isset($error_message)) { echo "<td style=\"background-color: white; border-top: none\">{$error_message}</td>"; } echo "</tr>"; } } if ($inputno) { echo "<input type=hidden name=nports value={$inputno}>"; echo '<tr><td colspan=7 align=center>' . getImageHREF('CREATE', 'import selected', TRUE) . '</td></tr>'; } echo '</table></form>'; addJS(<<<END \$(document).ready(function () { \t\$('#cb-toggle').click(function (event) { \t\tvar list = \$('.cb-makelink'); \t\tfor (var i in list) { \t\t\tvar cb = list[i]; \t\t\tcb.checked = event.target.checked; \t\t} \t}).triggerHandler('click'); }); END , TRUE); }
/** * getResult Function * * Call Racktables API to get Objects and filter the result if required * * @param array $post * @return array Result */ function getResult($post) { $sFilter = ''; if (isset($post['objectIDs'])) { foreach ($post['objectIDs'] as $sFilterValue) { $sFilter .= '{$typeid_' . $sFilterValue . '} or '; } $sFilter = substr($sFilter, 0, -4); $sFilter = '(' . $sFilter . ')'; } $aResult = scanRealmByText('object', $sFilter); // Add tags $aTemp = array(); foreach ($aResult as $Result) { $Result['tags'] = loadEntityTags('object', $Result['id']); $Result['itags'] = getImplicitTags($Result['tags']); array_push($aTemp, $Result); } $aResult = $aTemp; // Search / Filter by name if (isset($post['name_preg']) && $post['name_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['name_preg'] . '/', $Result['name'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Search / Filter by tag if (isset($post['tag_preg']) && $post['tag_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['tag_preg'] . '/', $Result['asset_no'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Search / Filter by comment if (isset($post['comment_preg']) && $post['comment_preg'] != '') { $aTemp = array(); foreach ($aResult as $Result) { if (preg_match('/' . $post['comment_preg'] . '/', $Result['comment'])) { array_push($aTemp, $Result); } } $aResult = $aTemp; } // Tags if (isset($post['tag']) && count($post['tag']) > 0) { $aTemp = array(); $aSearchTags = array_keys($post['tag']); foreach ($aResult as $Result) { foreach ($Result['tags'] as $aTag) { if (in_array($aTag['id'], $aSearchTags)) { array_push($aTemp, $Result); } } foreach ($Result['itags'] as $aTag) { if (in_array($aTag['id'], $aSearchTags)) { array_push($aTemp, $Result); } } } $aResult = $aTemp; } // Ports - Load port data if necessary if (isset($post['Ports'])) { $aTemp = array(); foreach ($aResult as $Result) { $Result['portsLinks'] = getObjectPortsAndLinks($Result['id']); foreach ($Result['portsLinks'] as $i => $port) { $Result['portsLinks'][$i]['remote_object_name'] = 'unknown'; if (!is_null($port['remote_object_id'])) { $remote_object = spotEntity('object', intval($port['remote_object_id'])); $Result['portsLinks'][$i]['remote_object_name'] = $remote_object['name']; } } array_push($aTemp, $Result); } $aResult = $aTemp; } return $aResult; }
function addlinkchainsobject($object_id) { $object['ports'] = getObjectPortsAndLinks($object_id); if (empty($object['ports'])) { $hl = false; $alpha = $this->alpha; if ($this->hl == 'o' && $this->object_id == $object_id) { $hl = true; $this->alpha = 'ff'; } $this->_addCluster($object_id, $hl, empty($object['ports'])); $this->alpha = $alpha; return; } $i = 0; foreach ($object['ports'] as $key => $port) { if (isset($this->pids[$port['id']])) { continue; } $i++; $lc = new lm_linkchain($port['id']); $this->pids += $lc->pids; if ($this->allports || $lc->linkcount > 0) { $this->addlinkchain($lc, $i); } } }
function localverify_PortGenerator($object) { global $tablePortGenerator, $errorText, $lookFor, $portList, $genText, $valueConfiguration, $searchIt; checkForTable(); $foundError = true; $record = getObjectPortsAndLinks($object['id']); // // Make sure that there are no ports configured // if (count($record) == 0) { // // Check whether the object type for the selected object has an attribute hardware type // If it does, use the hardware type for configuration. Otherwise use the generic object type // $lookFor = "Hardware type"; $q = "SELECT * FROM AttributeMap WHERE attr_id=" . _portGeneratorHWType . " AND objtype_id={$object['objtype_id']} "; $result = usePreparedSelectBlade($q); if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } if ($row = $result->fetch(PDO::FETCH_NUM)) { // // There is a hardware type available for this object type. Check whether it is set // If it is, search for the specific port configuration for that hardware type // If it is not set, use the generic port configuration for the object type // $q = "SELECT uint_value, dict_value FROM AttributeValue, Dictionary "; $q .= "WHERE attr_id=" . _portGeneratorHWType . " AND object_id={$object['id']} AND dict_key=uint_value "; $result = usePreparedSelectBlade($q); if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } if ($row = $result->fetch(PDO::FETCH_NUM)) { $searchIt = $row[0]; $searchText = "OK (based on hardware type)"; $searchType = 3; $genText = "{$object['objtype_name']}: {$row[1]}"; $genText = str_replace(array("%GPASS%"), " ", $genText); } else { $searchIt = $object['objtype_id']; $searchText = "Based on object type, hardware type not set"; $searchType = 2; $genText = "<b>GENERIC</b> {$object['objtype_name']}"; } } else { $searchIt = $object['objtype_id']; $searchText = "OK (based on object type)"; $searchType = 1; $genText = "{$object['objtype_name']}"; } $lookFor = "Autoport configuration"; $q = "SELECT autoportconfig FROM {$tablePortGenerator} WHERE dict_key={$searchIt} "; $result = usePreparedSelectBlade($q); if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } // // Check if there is an autoport configuration for the requested key // if ($valueConfiguration = $result->fetch(PDO::FETCH_NUM)) { $lookFor = "Configuration"; $q = "SELECT uint_value FROM AttributeValue "; $q .= "WHERE attr_id=" . _portGeneratorNumberOfPorts . " AND object_id={$_REQUEST['object_id']} "; // // Check for the value of the number of ports. If it is not found set it to 0 // $result = usePreparedSelectBlade($q); if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } if ($valueNumberOfPorts = $result->fetch(PDO::FETCH_NUM)) { } else { $valueNumberOfPorts[0] = 0; } // // $portList will contain the list of ports to be generated // $portList = array(); // // $portOrders array will be filled with individual port generation schemes // <start port #>|<port count, use %n for number of ports>|<port name, use %u for number>|<port type id>[|<port label, use %u for number>] // The configuration contains a semicolon seperated list of the schemes // // An example of this would be: // 1|2|pwr%u|16;1|%n|eth%u|24|%u // $portOrders = explode(";", $valueConfiguration[0]); if (count($portOrders) > 0) { $orderCnt = 0; foreach ($portOrders as $aPortOrder) { // // Split up each scheme and check for errors // If there are not errors, populate the $portList // $orderCnt++; $thisOrder = explode("|", $aPortOrder); if (count($thisOrder) == 4 || count($thisOrder) == 5) { if ($thisOrder[1] != "%n" || $valueNumberOfPorts[0] != 0) { if ($thisOrder[1] == "%n") { $thisOrder[1] = $valueNumberOfPorts[0]; } if ($thisOrder[1] == 1 || strpos($thisOrder[2], "%u") !== false) { if (preg_match('/^([[:digit:]]+)-([[:digit:]]+)$/', $thisOrder[3], $matches)) { $oif_id = $matches[2]; } else { $oif_id = $thisOrder[3]; } $q = "SELECT oif_name FROM PortOuterInterface WHERE id='{$oif_id}'"; $result = usePreparedSelectBlade($q); if ($result == NULL) { print_r($dbxlink->errorInfo()); die; } if ($row3 = $result->fetch(PDO::FETCH_NUM)) { for ($i = 1; $i <= $thisOrder[1]; $i++) { $ii = $thisOrder[0] + $i - 1; $name = str_replace("%u", $ii, $thisOrder[2]); if (count($thisOrder) == 5) { $label = str_replace("%u", $ii, $thisOrder[4]); } else { $label = ""; } $portList[] = array("name" => $name, "port_id" => $thisOrder[3], "port_name" => $row3[0], "label" => $label); } } else { $errorText = "Port type {$thisOrder[3]} is not found or not a port type."; } } else { $errorText = "Config part {$orderCnt} wants more than 1 port without using %u parameter."; } } else { $errorText = "Config part {$orderCnt} refers to <i>HW Number of Ports</i> but that is not defined or 0."; } } else { $errorText = "Config part {$orderCnt} does not have 4 parts seperated by a |"; } } if (!isset($errorText)) { $foundError = false; } } else { $errorText = "Autoport configuration for this dictionary key ({$searchIt}) is empty."; } } else { $errorText = "Autoport configuration for this dictionary key ({$searchIt}) not found."; } } else { $errorText = "Port generator only works if no ports have been configured yet."; } return !$foundError; }
function renderServerReport() { $aResult = array(); $iTotal = 0; $sFilter = '{$typeid_4}'; # typeid_4 = Server foreach (scanRealmByText('object', $sFilter) as $Result) { $aResult[$Result['id']] = array(); $aResult[$Result['id']]['sName'] = $Result['name']; // Create active links in comment $aResult[$Result['id']]['sComment'] = $Result['comment']; // Load additional attributes: $attributes = getAttrValues($Result['id']); $aResult[$Result['id']]['sContact'] = ''; if (isset($attributes['14']['a_value'])) { $aResult[$Result['id']]['sContact'] = $attributes['14']['a_value']; } $aResult[$Result['id']]['HWtype'] = ''; if (isset($attributes['2']['a_value'])) { $aResult[$Result['id']]['HWtype'] = $attributes['2']['a_value']; } $aResult[$Result['id']]['OEMSN'] = ''; if (isset($attributes['1']['a_value'])) { $aResult[$Result['id']]['OEMSN'] = $attributes['1']['a_value']; } $aResult[$Result['id']]['HWExpDate'] = ''; if (isset($attributes['22']['value'])) { $aResult[$Result['id']]['HWExpDate'] = date("Y-m-d", $attributes['22']['value']); } $aResult[$Result['id']]['sOS'] = ''; if (isset($attributes['4']['a_value'])) { $aResult[$Result['id']]['sOS'] = $attributes['4']['a_value']; } $aResult[$Result['id']]['sSlotNumber'] = 'unknown'; if (isset($attributes['28']['a_value']) && $attributes['28']['a_value'] != '') { $aResult[$Result['id']]['sSlotNumber'] = $attributes['28']['a_value']; } // Location $aResult[$Result['id']]['sLocation'] = getLocation($Result); // IP Informations $aResult[$Result['id']]['ipV4List'] = getObjectIPv4AllocationList($Result['id']); $aResult[$Result['id']]['ipV6List'] = getObjectIPv6AllocationList($Result['id']); // Port (MAC) Informations $aResult[$Result['id']]['ports'] = getObjectPortsAndLinks($Result['id']); $iTotal++; } if (isset($_GET['csv'])) { header('Content-type: text/csv'); header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv'); header('Pragma: no-cache'); header('Expires: 0'); $outstream = fopen("php://output", "w"); $aCSVRow = array('Name', 'MAC', 'IP(s)', 'Comment', 'Contact', 'Type', 'OEM', 'HW Expire Date', 'OS', 'Location'); fputcsv($outstream, $aCSVRow); foreach ($aResult as $id => $aRow) { $aCSVRow = array(); $aCSVRow[0] = $aRow['sName']; $aCSVRow[1] = ''; foreach ($aRow['ports'] as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { $aCSVRow[1] .= $aPortDetails['l2address'] . ' '; } } $aCSVRow[1] = trim($aCSVRow[1]); $aCSVRow[2] = ''; foreach ($aRow['ipV4List'] as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { $aCSVRow[2] .= $key . ' '; } } foreach ($aRow['ipV6List'] as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } if (trim($key) != '') { $aCSVRow[2] .= $key . ' '; } } $aCSVRow[2] = trim($aCSVRow[2]); $aCSVRow[3] = str_replace('"', "'", $aRow['sComment']); $aCSVRow[4] = $aRow['sContact']; $aCSVRow[5] = $aRow['HWtype']; $aCSVRow[6] = $aRow['OEMSN']; $aCSVRow[7] = $aRow['HWExpDate']; $aCSVRow[8] = $aRow['sOS']; $aCSVRow[9] = preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', $aRow['sLocation']); fputcsv($outstream, $aCSVRow); } fclose($outstream); exit(0); # Exit normally after send CSV to browser } // Load stylesheet and jquery scripts echo '<link rel="stylesheet" href="extensions/jquery/themes/racktables/style.css" type="text/css"/>'; echo '<script type="text/javascript" src="extensions/jquery/jquery-latest.js"></script>'; echo '<script type="text/javascript" src="extensions/jquery/jquery.tablesorter.js"></script>'; echo '<script type="text/javascript" src="extensions/jquery/picnet.table.filter.min.js"></script>'; // Display the stat array echo '<h2>Server report (' . $iTotal . ')</h2><ul>'; echo '<a href="index.php?page=reports&tab=server&csv">CSV Export</a>'; echo '<table id="reportTable" class="tablesorter"> <thead> <tr> <th>Name</th> <th>MAC</th> <th>IP(s)</th> <th>Comment</th> <th>Contact</th> <th>Type</th> <th>OEM S/N</th> <th>HW Expire Date</th> <th>OS</th> <th>Location</th> </tr> </thead> <tbody>'; foreach ($aResult as $id => $aRow) { echo '<tr> <td><a href="' . makeHref(array('page' => 'object', 'object_id' => $id)) . '">' . $aRow['sName'] . '</a></td> <td>'; foreach ($aRow['ports'] as $portNumber => $aPortDetails) { if (trim($aPortDetails['l2address']) != '') { echo $aPortDetails['l2address'] . '<br/>'; } } echo ' </td> <td>'; foreach ($aRow['ipV4List'] as $key => $aDetails) { if (function_exists('ip4_format')) { $key = ip4_format($key); } if (trim($key) != '') { echo $key . '<br/>'; } } foreach ($aRow['ipV6List'] as $key => $aDetails) { if (function_exists('ip6_format')) { $key = ip6_format($key); } if (trim($key) != '') { echo $key . '<br/>'; } } echo '</td> <td>' . makeLinksInText($aRow['sComment']) . '</td> <td>' . $aRow['sContact'] . '</td> <td>' . $aRow['HWtype'] . '</td> <td>' . $aRow['OEMSN'] . '</td> <td>' . $aRow['HWExpDate'] . '</td> <td>' . $aRow['sOS'] . '</td> <td>' . $aRow['sLocation'] . '</td> </tr>'; } echo ' </tbody> </table>'; echo '<script type="text/javascript"> $(document).ready(function() { $.tablesorter.defaults.widgets = ["zebra"]; $("#reportTable").tablesorter( { headers: { 2: { sorter: "ipAddress" }, }, sortList: [[0,0]] } ) $("#reportTable").tableFilter(); }); </script>'; }
function snmplive_opajax() { ob_start(); $object_id = $_REQUEST['object_id']; $object = spotEntity('object', $object_id); $object['ports'] = getObjectPortsAndLinks($object_id); if (isset($_GET['debug'])) { $debug = $_GET['debug']; } else { $debug = 0; } $object['iftable'] = sl_getsnmp($object, $debug); if ($object['iftable']) { foreach ($object['ports'] as $key => &$port) { // snmpinfos $port['snmpinfos'] = sl_getportsnmp($object, $port, $debug); if (!$port['snmpinfos']) { unset($object['ports'][$key]); } } } /* not needed anymore */ unset($object['iftable']); /* set debug output */ if (ob_get_length()) { $object['debug'] = ob_get_contents(); } ob_end_clean(); echo json_encode($object); exit; }