function trigger_autoports() { $object = spotEntity('object', getBypassValue()); amplifyCell($object); if (count($object['ports'])) { return ''; } return count(getAutoPorts($object['objtype_id'])) ? 'attn' : ''; }
function formatPortLinkHints($object_id) { $result = array(); $linkStatus = queryDevice($object_id, 'getportstatus'); foreach ($linkStatus as $portname => $link_info) { $link_info = $linkStatus[$portname]; switch ($link_info['status']) { case 'up': $img_filename = 'link-up.png'; break; case 'down': $img_filename = 'link-down.png'; break; case 'disabled': $img_filename = 'link-disabled.png'; break; } $hidden_lines = array(); $hidden_lines[] = $portname . ': ' . $link_info['status']; if (isset($link_info['speed'])) { $hidden_lines[] = 'Speed: ' . $link_info['speed']; } if (isset($link_info['duplex'])) { $hidden_lines[] = 'Duplex: ' . $link_info['duplex']; } if (count($hidden_lines)) { $result[$portname]['popup'] = implode('<br>', $hidden_lines); } $visible_part = "<img width=16 height=16 src='?module=chrome&uri=pix/{$img_filename}'>"; $result[$portname]['inline'] = $visible_part; } // put empty pictures for not-found ports $object = spotEntity('object', $object_id); amplifyCell($object); foreach ($object['ports'] as $port) { if (!isset($result[$port['name']])) { $result[$port['name']]['inline'] = "<img width=16 height=16 src='?module=chrome&uri=pix/1x1t.gif'>"; } } return $result; }
function initRackTablesObject($rackDatas) { // zabbix host data $params = array('output' => 'extend'); $result = doPost('host.get', $params); $hosts = isset($result['result']) ? $result['result'] : array(); $objectDatas = array(); foreach ($hosts as $host) { $object_type_id = 4; $object_name = isset($host['host']) ? $host['host'] : ""; $object_label = ""; $object_asset_no = ""; $taglist = array(); $has_problems = $host['status'] == 0 ? 'no' : 'yes'; $object_id = commitAddObject($object_name, $object_label, $object_type_id, $object_asset_no, $taglist); usePreparedUpdateBlade('Object', array('has_problems' => $has_problems), array('id' => $object_id)); $objectDatas[$host['hostid']] = $object_id; // set hostgroup $params = array('output' => array('name'), 'hostids' => array($host['hostid'])); $result = doPost('hostgroup.get', $params); $hostgroups = isset($result['result']) ? $result['result'] : array(); $rack_ids = array(); $_REQUEST = array(); foreach ($hostgroups as $hostgroup) { if (isset($rackDatas[$hostgroup['name']])) { $rack = $rackDatas[$hostgroup['name']]; amplifyCell($rack); array_push($rack_ids, $rack['id']); $height = $rack['height']; for ($i = 0; $i < 3; $i++) { for ($j = $height; $j > 0; $j--) { if ($rack[$j][$i]['state'] == 'F') { # state == "T" : mounted $_REQUEST['atom_' . $rack['id'] . "_{$j}" . "_{$i}"] = 'on'; break 2; } } } } } $_REQUEST['object_id'] = $object_id; $_REQUEST['rackmulti'] = $rack_ids; $object = spotEntity('object', $object_id); $changecnt = 0; // Get a list of rack ids which are parents of the object $parentRacks = reduceSubarraysToColumn(getParents($object, 'rack'), 'id'); $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } else { $rackData = $workingRacksData[$cand_id]; } $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { if ($is_ro) { continue; } $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { $is_ro = !rackModificationPermitted($rackData, 'updateObjectAllocation', FALSE); if ($is_ro || !processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); global $remote_username, $sic; usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } // set IP $params = array('output' => 'extend', 'hostids' => $host['hostid']); $result = doPost('hostinterface.get', $params); $hostinterfaces = isset($result['result']) ? $result['result'] : array(); foreach ($hostinterfaces as $interface) { if (isset($interface['ip']) && $interface['ip'] != '127.0.0.1') { $allocs = getObjectIPAllocations($object_id); $current_ips = array(); foreach ($allocs as $alloc) { $ip = $alloc["addrinfo"]["ip"]; $current_ips[$ip] = $ip; } $ip = $interface['ip']; if (!in_array($ip, array_values($current_ips))) { // new IP $ip_bin = ip_parse($ip); if (null == getIPAddressNetworkId($ip_bin)) { // if ip is not exists, adding it into RackTables IPv4Prefix. $range = substr($ip, 0, strripos($ip, '.')) . '.0/24'; $vlan_ck = NULL; $net_id = createIPv4Prefix($range, 'admim', isCheckSet('is_connected'), $taglist); $net_cell = spotEntity('ipv4net', $net_id); if (isset($vlan_ck)) { if (considerConfiguredConstraint($net_cell, 'VLANIPV4NET_LISTSRC')) { commitSupplementVLANIPv4($vlan_ck, $net_id); } } } bindIPToObject($ip_bin, $object_id, "", ""); } } } } return $objectDatas; }
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); amplifyCell($dp_remote_object); $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 ($dp_remote_object['ports'] 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['id']); 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); }
function renderSLBFormAJAX() { global $pageno, $tabno; parse_str(assertStringArg('form'), $orig_request); parse_str(ltrim(assertStringArg('action'), '?'), $action); $pageno = $action['page']; $tabno = $action['tab']; printOpFormIntro($action['op'], $orig_request); $realm_list = array_diff(array('ipvs', 'object', 'ipv4rspool'), array($pageno)); echo '<table align=center><tr class="tdleft">'; foreach ($realm_list as $realm) { switch ($realm) { case 'object': $slb_cell = spotEntity('object', $orig_request['object_id']); break; case 'ipv4rspool': $slb_cell = spotEntity('ipv4rspool', $orig_request['rspool_id']); break; case 'ipvs': $slb_cell = spotEntity('ipvs', $orig_request['vs_id']); break; } echo '<td>'; renderSLBEntityCell($slb_cell); echo '</td>'; } $vsinfo = spotEntity('ipvs', $orig_request['vs_id']); amplifyCell($vsinfo); echo '<td><ul style="list-style: none">'; foreach ($vsinfo['ports'] as $port) { $key = $port['proto'] . '-' . $port['vport']; echo '<li><label><input type=checkbox name="enabled_ports[]" value="' . htmlspecialchars($key, ENT_QUOTES) . '" checked>' . formatVSPort($port) . '</label></li>'; } echo '</ul></td>'; echo '<td><ul style="list-style: none">'; foreach ($vsinfo['vips'] as $vip) { $key = ip_format($vip['vip']); echo '<li><label><input type=checkbox name="enabled_vips[]" value="' . htmlspecialchars($key, ENT_QUOTES) . '" checked>' . $key . '</label></li>'; } echo '</ul></td>'; echo '<td>'; printImageHREF('ADD', 'Configure LB', TRUE); echo '</td>'; echo '</tr></table>'; echo '</form>'; }
function printRackThumbImage($rack_id, $scale = 1) { $rackData = spotEntity('rack', $rack_id); amplifyCell($rackData); global $rtwidth; $offset[0] = 3; $offset[1] = 3 + $rtwidth[0]; $offset[2] = 3 + $rtwidth[0] + $rtwidth[1]; $totalheight = 3 + 3 + $rackData['height'] * 2; $totalwidth = $offset[2] + $rtwidth[2] + 3; $img = createTrueColorOrThrow('rack_php_gd_error', $totalwidth, $totalheight); # It was measured, that caching palette in an array is faster, than # calling colorFromHex() multiple times. It matters, when user's # browser is trying to fetch many minirack images in parallel. $color = array('F' => colorFromHex($img, '8fbfbf'), 'A' => colorFromHex($img, 'bfbfbf'), 'U' => colorFromHex($img, 'bf8f8f'), 'T' => colorFromHex($img, '408080'), 'Th' => colorFromHex($img, '80ffff'), 'Tw' => colorFromHex($img, '804040'), 'Thw' => colorFromHex($img, 'ff8080'), 'black' => colorFromHex($img, '000000'), 'gray' => colorFromHex($img, 'c0c0c0')); $border_color = $rackData['has_problems'] == 'yes' ? $color['Thw'] : $color['gray']; imagerectangle($img, 0, 0, $totalwidth - 1, $totalheight - 1, $color['black']); imagerectangle($img, 1, 1, $totalwidth - 2, $totalheight - 2, $border_color); imagerectangle($img, 2, 2, $totalwidth - 3, $totalheight - 3, $color['black']); for ($unit_no = 1; $unit_no <= $rackData['height']; $unit_no++) { for ($locidx = 0; $locidx < 3; $locidx++) { $colorcode = $rackData[$unit_no][$locidx]['state']; if (isset($rackData[$unit_no][$locidx]['hl'])) { $colorcode = $colorcode . $rackData[$unit_no][$locidx]['hl']; } imagerectangle($img, $offset[$locidx], 3 + ($rackData['height'] - $unit_no) * 2, $offset[$locidx] + $rtwidth[$locidx] - 1, 3 + ($rackData['height'] - $unit_no) * 2 + 1, $color[$colorcode]); } } if ($scale > 1) { $resized = imagecreate($totalwidth * $scale, $totalheight * $scale); imagecopyresized($resized, $img, 0, 0, 0, 0, $totalwidth * $scale, $totalheight * $scale, $totalwidth, $totalheight); imagedestroy($img); $img = $resized; } imagepng($img); imagedestroy($img); }
redirectUser($_SERVER['SCRIPT_NAME'] . "?method=get_depot"); break; // get all objects // UI equivalent: /index.php?page=depot&tab=default // UI handler: renderDepot() // get all objects // UI equivalent: /index.php?page=depot&tab=default // UI handler: renderDepot() case 'get_depot': require_once 'inc/init.php'; $cellfilter = getCellFilter(); $objects = filterCellList(listCells('object'), $cellfilter['expression']); // get details if requested if (isset($_REQUEST['include_attrs'])) { foreach ($objects as $object_id => $object) { amplifyCell($object); // return the attributes in an array keyed on 'name', unless otherwise requested $key_attrs_on = 'name'; if (isset($_REQUEST['key_attrs_on'])) { $key_attrs_on = $_REQUEST['key_attrs_on']; } $attrs = array(); foreach (getAttrValues($object_id) as $record) { // check that the key exists for this record if (!isset($record[$key_attrs_on])) { throw new InvalidRequestArgException('key_attrs_on', $_REQUEST['key_attrs_on'], 'requested keying value not set for all attributes'); } if (strlen($record['value'])) { $attrs[$record[$key_attrs_on]] = $record; } }
function getVSIDsByGroup($group_id) { $ret = array(); $vsinfo = spotEntity('ipvs', $group_id); amplifyCell($vsinfo); if (count($vsinfo['vips'])) { $ips = reduceSubarraysToColumn($vsinfo['vips'], 'vip'); $qm = questionMarks(count($ips)); $result = usePreparedSelectBlade("SELECT id FROM IPv4VS WHERE vip IN ({$qm}) ORDER BY vip", $ips); $ret = array_merge($ret, $result->fetchAll(PDO::FETCH_COLUMN, 0)); unset($result); } $bin_marks = array(); foreach ($vsinfo['ports'] as $port) { if ($port['proto'] == 'MARK') { $bin_marks[] = pack('N', $port['vport']); } } if (count($bin_marks)) { $qm = questionMarks(count($bin_marks)); $result = usePreparedSelectBlade("SELECT id FROM IPv4VS WHERE proto = 'MARK' AND vip IN ({$qm}) ORDER BY vip", $bin_marks); $ret = array_merge($ret, $result->fetchAll(PDO::FETCH_COLUMN, 0)); } return $ret; }
function linkmgmt_renderObjectLinks($object_id) { $object = spotEntity('object', $object_id); $object['attr'] = getAttrValues($object_id); /* get ports */ /* calls getObjectPortsAndLinks */ amplifyCell($object); //$ports = getObjectPortsAndLinks($object_id); $ports = $object['ports']; /* reindex array so key starts at 0 */ $ports = array_values($ports); /* URL param handling */ if (isset($_GET['allports'])) { $allports = $_GET['allports']; } else { $allports = FALSE; } if (isset($_GET['allback'])) { $allback = $_GET['allback']; } else { $allback = FALSE; } echo '<table><tr>'; if ($allports) { echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '0', '0')) . '">Hide Ports without link</a></td>'; } else { echo '<td width=200><a href="' . makeHref(portlist::urlparams('allports', '1', '0')) . '">Show All Ports</a></td>'; } echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'PortLinkDialog', 'linktype' => 'back', 'byname' => '1'))) . '","name","height=700,width=800,scrollbars=yes");><a>Link Object Ports by Name</a></span></td>'; if ($allback) { echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '0', '0')) . '">Collapse Backend Links on same Object</a></td>'; } else { echo '<td width=200><a href="' . makeHref(portlist::urlparams('allback', '1', '0')) . '">Expand Backend Links on same Object</a></td>'; } /* Graphviz map */ echo '<td width=100><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'map', 'usemap' => 1))) . '","name","height=800,width=800,scrollbars=yes");><a>Object Map</a></span></td>'; /* Help */ echo '<td width=200><span onclick=window.open("' . makeHrefProcess(portlist::urlparamsarray(array('op' => 'Help'))) . '","name","height=400,width=500");><a>Help</a></span></td>'; if (isset($_REQUEST['hl_port_id'])) { $hl_port_id = $_REQUEST['hl_port_id']; } else { $hl_port_id = NULL; } echo '</tr></table>'; echo '<br><br><table id=renderobjectlinks0>'; /* switch display order depending on backend links */ $first = portlist::hasbackend($object_id); $rowcount = 0; foreach ($ports as $key => $port) { $plist = new portlist($port, $object_id, $allports, $allback); //echo "<td><img src=\"index.php?module=redirect&page=object&tab=linkmgmt&op=map&object_id=$object_id&port_id=${port['id']}&allports=$allports\" ></td>"; if ($plist->printportlistrow($first, $hl_port_id, $rowcount % 2 ? portlist::ALTERNATE_ROW_BGCOLOR : "#ffffff")) { $rowcount++; } } echo "</table>"; }
function renderVLANMembership($object_id) { try { $data = getSwitchVLANs($object_id); } catch (RTGatewayError $re) { showWarning('Device configuration unavailable:<br>' . $re->getMessage()); return; } list($vlanlist, $portlist, $maclist) = $data; $vlanpermissions = array(); foreach ($portlist as $port) { if (array_key_exists($port['vlanid'], $vlanpermissions)) { continue; } $vlanpermissions[$port['vlanid']] = array(); foreach (array_keys($vlanlist) as $to) { if (permitted(NULL, NULL, 'setPortVLAN', array(array('tag' => '$fromvlan_' . $port['vlanid']), array('tag' => '$vlan_' . $port['vlanid']))) and permitted(NULL, NULL, 'setPortVLAN', array(array('tag' => '$tovlan_' . $to), array('tag' => '$vlan_' . $to)))) { $vlanpermissions[$port['vlanid']][] = $to; } } } if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = intval($_REQUEST['hl_port_id']); $object = spotEntity('object', $object_id); amplifyCell($object); foreach ($object['ports'] as $port) { if (mb_strlen($port['name']) && $port['id'] == $hl_port_id) { $hl_port_name = $port['name']; break; } } } echo '<table border=0 width="100%"><tr><td colspan=3>'; startPortlet('Current status'); echo "<table class=widetable cellspacing=3 cellpadding=5 align=center width='100%'><tr>"; printOpFormIntro('setPortVLAN'); $portcount = count($portlist); echo "<input type=hidden name=portcount value=" . $portcount . ">\n"; $portno = 0; $ports_per_row = 12; foreach ($portlist as $port) { // Don't let wide forms break our fancy pages. if ($portno % $ports_per_row == 0) { if ($portno > 0) { echo "</tr>\n"; } echo "<tr><th>" . ($portno + 1) . "-" . ($portno + $ports_per_row > $portcount ? $portcount : $portno + $ports_per_row) . "</th>"; } $td_class = 'port_'; if ($port['status'] == 'notconnect') { $td_class .= 'notconnect'; } elseif ($port['status'] == 'disabled') { $td_class .= 'disabled'; } elseif ($port['status'] != 'connected') { $td_class .= 'unknown'; } elseif (!isset($maclist[$port['portname']])) { $td_class .= 'connected_none'; } else { $maccount = 0; foreach ($maclist[$port['portname']] as $vlanid => $addrs) { $maccount += count($addrs); } if ($maccount == 1) { $td_class .= 'connected_single'; } else { $td_class .= 'connected_multi'; } } if (isset($hl_port_name) and strcasecmp($hl_port_name, $port['portname']) == 0) { $td_class .= (strlen($td_class) ? ' ' : '') . 'border_highlight'; } echo "<td class='{$td_class}'>" . $port['portname'] . '<br>'; echo "<input type=hidden name=portname_{$portno} value=" . $port['portname'] . '>'; if ($port['vlanid'] == 'trunk') { echo "<input type=hidden name=vlanid_{$portno} value='trunk'>"; echo "<select disabled multiple='multiple' size=1><option>TRUNK</option></select>"; } elseif ($port['vlanid'] == 'routed') { echo "<input type=hidden name=vlanid_{$portno} value='routed'>"; echo "<select disabled multiple='multiple' size=1><option>ROUTED</option></select>"; } elseif (!array_key_exists($port['vlanid'], $vlanpermissions) or !count($vlanpermissions[$port['vlanid']])) { echo "<input type=hidden name=vlanid_{$portno} value={$port['vlanid']}>"; echo "<select disabled name=vlanid_{$portno}>"; echo "<option value={$port['vlanid']} selected>{$port['vlanid']}</option>"; echo "</select>"; } else { echo "<select name=vlanid_{$portno}>"; // A port may belong to a VLAN, which is absent from the VLAN table, this is normal. // We must be able to render its SELECT properly at least. $in_table = FALSE; foreach ($vlanpermissions[$port['vlanid']] as $v) { echo "<option value={$v}"; if ($v == $port['vlanid']) { echo ' selected'; $in_table = TRUE; } echo ">{$v}</option>\n"; } if (!$in_table) { echo "<option value={$port['vlanid']} selected>{$port['vlanid']}</option>\n"; } echo "</select>"; } $portno++; echo "</td>"; } echo "</tr><tr><td colspan=" . ($ports_per_row + 1) . "><input type=submit value='Save changes'></form></td></tr></table>"; finishPortlet(); echo '</td></tr><tr><td class=pcleft>'; startPortlet('VLAN table'); echo '<table class=cooltable cellspacing=0 cellpadding=5 align=center width="100%">'; echo "<tr><th>ID</th><th>Description</th></tr>"; $order = 'even'; global $nextorder; foreach ($vlanlist as $id => $descr) { echo "<tr class=row_{$order}><td class=tdright>{$id}</td><td class=tdleft>{$descr}</td></tr>"; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); echo '</td><td class=pcright>'; startPortlet('Color legend'); echo '<table>'; echo "<tr><th>port state</th><th>color code</th></tr>"; echo "<tr><td>not connected</td><td class=port_notconnect>SAMPLE</td></tr>"; echo "<tr><td>disabled</td><td class=port_disabled>SAMPLE</td></tr>"; echo "<tr><td>unknown</td><td class=port_unknown>SAMPLE</td></tr>"; echo "<tr><td>connected with none MAC addresses active</td><td class=port_connected_none>SAMPLE</td></tr>"; echo "<tr><td>connected with 1 MAC addresses active</td><td class=port_connected_single>SAMPLE</td></tr>"; echo "<tr><td>connected with 1+ MAC addresses active</td><td class=port_connected_multi>SAMPLE</td></tr>"; echo '</table>'; finishPortlet(); echo '</td><td class=pcright>'; if (count($maclist)) { startPortlet('MAC address table'); echo '<table border=0 class=cooltable align=center cellspacing=0 cellpadding=5>'; echo "<tr><th>Port</th><th>VLAN ID</th><th>MAC address</th></tr>\n"; $order = 'even'; foreach ($maclist as $portname => $portdata) { foreach ($portdata as $vlanid => $addrgroup) { foreach ($addrgroup as $addr) { echo "<tr class=row_{$order}><td class=tdleft>{$portname}</td><td class=tdleft>{$vlanid}</td>"; echo "<td class=tdleft>{$addr}</td></tr>\n"; $order = $nextorder[$order]; } } } echo '</table>'; finishPortlet(); } // End of main table. echo '</td></tr></table>'; }
function snmpgeneric_list($object_id) { global $sg_create_noconnector_ports, $sg_known_sysObjectIDs, $sg_portoifoptions, $sg_ifType_ignore; if (isset($_POST['snmpconfig'])) { $snmpconfig = $_POST; } else { showError("Missing SNMP Config"); return; } // sg_var_dump_html($snmpconfig); echo '<body onload="document.getElementById(\'createbutton\').focus();">'; addJS('function setchecked(classname) { var boxes = document.getElementsByClassName(classname); var value = document.getElementById(classname).checked; for(i=0;i<boxes.length;i++) { if(boxes[i].disabled == false) boxes[i].checked=value; } };', TRUE); $object = spotEntity('object', $object_id); $object['attr'] = getAttrValues($object_id); $snmpdev = new mySNMP($snmpconfig['version'], $snmpconfig['host'], $snmpconfig['community']); if ($snmpconfig['version'] == "v3") { $snmpdev->setSecurity($snmpconfig['sec_level'], $snmpconfig['auth_protocol'], $snmpconfig['auth_passphrase'], $snmpconfig['priv_protocol'], $snmpconfig['priv_passphrase']); } $snmpdev->init(); if ($snmpdev->getErrno()) { showError($snmpdev->getError()); return; } /* SNMP connect successfull */ showSuccess("SNMP " . $snmpconfig['version'] . " connect to {$snmpconfig['host']} successfull"); echo '<form name=CreatePorts method=post action=' . $_SERVER['REQUEST_URI'] . '&module=redirect&op=create>'; echo "<strong>System Informations</strong>"; echo "<table>"; // echo "<tr><th>OID</th><th>Value</th></tr>"; $systemoids = array('sysDescr', 'sysObjectID', 'sysUpTime', 'sysContact', 'sysName', 'sysLocation'); foreach ($systemoids as $shortoid) { $value = $snmpdev->{$shortoid}; if ($shortoid == 'sysUpTime') { /* in hundredths of a second */ $secs = (int) ($value / 100); $days = (int) ($secs / (60 * 60 * 24)); $secs -= $days * 60 * 60 * 24; $hours = (int) ($secs / (60 * 60)); $secs -= $hours * 60 * 60; $mins = (int) ($secs / 60); $secs -= $mins * 60; $value = "{$value} ({$days} {$hours}:{$mins}:{$secs})"; } echo "<tr><td title=\"" . $snmpdev->lastgetoid . "\" align=\"right\">{$shortoid}: </td><td>{$value}</td></tr>"; } unset($shortoid); echo "</table>"; /* sysObjectID Attributes and Ports */ $sysObjectID['object'] =& $object; /* get sysObjectID */ $sysObjectID['raw_value'] = $snmpdev->sysObjectID; //$sysObjectID['raw_value'] = 'NET-SNMP-MIB::netSnmpAgentOIDs.10'; $sysObjectID['value'] = preg_replace('/^.*enterprises\\.([\\.[:digit:]]+)$/', '\\1', $sysObjectID['raw_value']); /* try snmptranslate to numeric */ if (preg_match('/[^\\.0-9]+/', $sysObjectID['value'])) { $numeric_value = $snmpdev->translatetonumeric($sysObjectID['value']); if (!empty($numeric_value)) { showSuccess("sysObjectID: " . $sysObjectID['value'] . " translated to {$numeric_value}"); $sysObjectID['value'] = preg_replace('/^.1.3.6.1.4.1.([\\.[:digit:]]+)$/', '\\1', $numeric_value); } } /* array_merge doesn't work with numeric keys !! */ $sysObjectID['attr'] = array(); $sysObjectID['port'] = array(); $sysobjid = $sysObjectID['value']; $count = 1; while ($count) { if (isset($sg_known_sysObjectIDs[$sysobjid])) { $sysObjectID = $sysObjectID + $sg_known_sysObjectIDs[$sysobjid]; if (isset($sg_known_sysObjectIDs[$sysobjid]['attr'])) { $sysObjectID['attr'] = $sysObjectID['attr'] + $sg_known_sysObjectIDs[$sysobjid]['attr']; } if (isset($sg_known_sysObjectIDs[$sysobjid]['port'])) { $sysObjectID['port'] = $sysObjectID['port'] + $sg_known_sysObjectIDs[$sysobjid]['port']; } if (isset($sg_known_sysObjectIDs[$sysobjid]['text'])) { showSuccess("found sysObjectID ({$sysobjid}) " . $sg_known_sysObjectIDs[$sysobjid]['text']); } } $sysobjid = preg_replace('/\\.[[:digit:]]+$/', '', $sysobjid, 1, $count); /* add default sysobjectid */ if ($count == 0 && $sysobjid != 'default') { $sysobjid = 'default'; $count = 1; } } $sysObjectID['vendor_number'] = $sysobjid; /* device pf */ if (isset($sysObjectID['pf'])) { foreach ($sysObjectID['pf'] as $function) { if (function_exists($function)) { /* call device pf */ $function($snmpdev, $sysObjectID, NULL); } else { showWarning("Missing processor function " . $function . " for device {$sysobjid}"); } } } /* sort attributes maintain numeric keys */ ksort($sysObjectID['attr']); /* DEBUG */ //sg_var_dump_html($sysObjectID['attr'], "Before processing"); /* needs PHP >= 5 foreach call by reference */ /* php 5.1.6 doesn't seem to work */ //foreach($sysObjectID['attr'] as $attr_id => &$attr) foreach ($sysObjectID['attr'] as $attr_id => $value) { $attr =& $sysObjectID['attr'][$attr_id]; if (isset($object['attr'][$attr_id])) { if (array_key_exists('key', $object['attr'][$attr_id])) { $attr['key'] = $object['attr'][$attr_id]['key']; } switch (TRUE) { case isset($attr['pf']): if (function_exists($attr['pf'])) { $attr['pf']($snmpdev, $sysObjectID, $attr_id); } else { showWarning("Missing processor function " . $attr['pf'] . " for attribute {$attr_id}"); } break; case isset($attr['oid']): $attrvalue = $snmpdev->get($attr['oid']); if (isset($attr['regex'])) { $regex = $attr['regex']; if (isset($attr['replacement'])) { $replacement = $attr['replacement']; $attrvalue = preg_replace($regex, $replacement, $attrvalue); } else { if (!preg_match($regex, $attrvalue)) { if (!isset($attr['uncheck'])) { $attr['uncheck'] = "regex doesn't match"; } } else { unset($attr['uncheck']); } } } $attr['value'] = $attrvalue; break; case isset($attr['value']): break; default: showError("Error handling attribute id: {$attr_id}"); } } else { showWarning("Object has no attribute id: {$attr_id}"); unset($sysObjectID['attr'][$attr_id]); } } unset($attr_id); /* sort again in case there where attribs added ,maintain numeric keys */ ksort($sysObjectID['attr']); /* print attributes */ echo '<br>Attributes<br><table>'; echo '<tr><th><input type="checkbox" id="attribute" checked="checked" onclick="setchecked(this.id)"></td>'; echo '<th>Name</th><th>Current Value</th><th>new value</th></tr>'; /* DEBUG */ //sg_var_dump_html($sysObjectID['attr'], "After processing"); foreach ($sysObjectID['attr'] as $attr_id => &$attr) { $attr['id'] = $attr_id; if (isset($object['attr'][$attr_id]) && isset($attr['value'])) { if ($attr['value'] == $object['attr'][$attr_id]['value']) { $attr['uncheck'] = 'Current = new value'; } if (isset($attr['key']) && isset($object['attr'][$attr_id]['key'])) { if ($attr['key'] == $object['attr'][$attr_id]['key']) { $attr['uncheck'] = 'Current = new key'; } } $value = $attr['value']; $val_key = isset($object['attr'][$attr_id]['key']) ? ' (' . $object['attr'][$attr_id]['key'] . ')' : ''; $comment = ''; if (isset($attr['comment'])) { if (!empty($attr['comment'])) { $comment = $attr['comment']; } } if (isset($attr['uncheck'])) { $checked = ''; $comment .= ', ' . $attr['uncheck']; } else { $checked = ' checked="checked"'; } $updateattrcheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:#00ff00" class="attribute" type="checkbox" name="updateattr[' . $attr_id . ']" value="' . $value . '"' . $checked . '></b>'; $comment = trim($comment, ', '); echo "<tr><td>{$updateattrcheckbox}</td><td title=\"id: {$attr_id}\">" . $object['attr'][$attr_id]['name'] . '</td><td style="background-color:#d8d8d8">' . $object['attr'][$attr_id]['value'] . $val_key . '</td><td>' . $value . '</td>' . '<td style="color:#888888">' . $comment . '</td></tr>'; } } unset($attr_id); echo '</table>'; $object['breed'] = sg_detectDeviceBreedByObject($sysObjectID); if (!empty($object['breed'])) { echo "Found Breed: " . $object['breed'] . "<br>"; } /* ports */ /* get ports */ amplifyCell($object); /* set array key to lowercase port name */ foreach ($object['ports'] as $key => $values) { $object['ports'][strtolower(shortenIfName($values['name'], $object['breed']))] = $values; unset($object['ports'][$key]); } $newporttypeoptions = getNewPortTypeOptions(); // sg_var_dump_html($sysObjectID['port']); if (!empty($sysObjectID['port'])) { echo '<br>Vendor / Device specific ports<br>'; echo '<table><tr><th><input type="checkbox" id="moreport" checked="checked" onclick="setchecked(this.id)"></th><th>ifName</th><th>porttypeid</th></tr>'; foreach ($sysObjectID['port'] as $name => $port) { if (array_key_exists(strtolower($name), $object['ports'])) { $disableport = TRUE; } else { $disableport = FALSE; } $comment = ''; if (isset($port['comment'])) { if (!empty($port['comment'])) { $comment = $port['comment']; } } if (isset($port['uncheck'])) { $checked = ''; $comment .= ', ' . $port['uncheck']; } else { $checked = ' checked="checked"'; } $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" class="moreport" type="checkbox" name="portcreate[' . $name . ']" value="' . $name . '"' . ($disableport ? ' disabled="disbaled"' : $checked) . '></b>'; $formfield = '<input type="hidden" name="ifName[' . $name . ']" value="' . $name . '">'; echo "<tr>{$formfield}<td>{$portcreatecheckbox}</td><td>{$name}</td>"; if (isset($port['disabled'])) { $disabledselect = array('disabled' => "disabled"); } else { $disabledselect = array(); } foreach ($port as $key => $value) { if ($key == 'uncheck' || $key == 'comment') { continue; } /* TODO iif_name */ if ($key == 'porttypeid') { $displayvalue = getNiftySelect($newporttypeoptions, array('name' => "porttypeid[{$name}]") + $disabledselect, $value); } else { $displayvalue = $value; } $formfield = '<input type="hidden" name="' . $key . '[' . $name . ']" value="' . $value . '">'; echo "{$formfield}<td>{$displayvalue}</td>"; } $comment = trim($comment, ', '); echo "<td style=\"color:#888888\">{$comment}</td></tr>"; } unset($name); unset($port); echo '</table>'; } /* snmp ports */ $ifsnmp = new ifSNMP($snmpdev); // needed for shortenIfName() $ifsnmp->object_breed = $object['breed']; /* ip spaces */ $ipspace = NULL; foreach ($ifsnmp->ipaddress as $ifindex => $ipaddresses) { foreach ($ipaddresses as $ipaddr => $value) { $addrtype = $value['addrtype']; $netaddr = $value['net']; $maskbits = $value['maskbits']; $netid = NULL; $linklocal = FALSE; //echo "<br> - DEBUG: ipspace $ipaddr - $netaddr - $addrtype - $maskbits<br>"; /* check for ip space */ switch ($addrtype) { case 'ipv4': case 'ipv4z': if ($maskbits == 32) { $netid = 'host'; } else { $netid = getIPv4AddressNetworkId(ip_parse($ipaddr)); } break; case 'ipv6': if (ip_checkparse($ipaddr) === false) { /* format ipaddr for ip6_parse */ $ipaddr = preg_replace('/((..):(..))/', '\\2\\3', $ipaddr); $ipaddr = preg_replace('/%.*$/', '', $ipaddr); } if (ip_checkparse($ipaddr) === false) { continue 2; } // 2 because of switch $ip6_bin = ip6_parse($ipaddr); $ip6_addr = ip_format($ip6_bin); $netid = getIPv6AddressNetworkId($ip6_bin); $node = constructIPRange($ip6_bin, $maskbits); $netaddr = $node['ip']; $linklocal = substr($ip6_addr, 0, 5) == "fe80:"; //echo "<br> - DEBUG: ipspace $ipaddr - $addrtype - $maskbits - $netaddr - >$linklocal<<br>"; break; case 'ipv6z': /* link local */ $netid = 'ignore'; break; default: } if (empty($netid) && $netaddr != '::1' && $netaddr != '127.0.0.1' && $netaddr != '127.0.0.0' && $netaddr != '0.0.0.0' && !$linklocal) { $netaddr .= "/{$maskbits}"; $ipspace[$netaddr] = array('addrtype' => $addrtype, 'checked' => $maskbits > 0 ? true : false); } } unset($ipaddr); unset($value); unset($addrtype); } unset($ifindex); unset($ipaddresses); /* print ip spaces table */ if (!empty($ipspace)) { echo '<br><br>Create IP Spaces'; echo '<table><tr><th><input type="checkbox" id="ipspace" onclick="setchecked(this.id)" checked=\\"checked\\"></th>'; echo '<th>Type</th><th>prefix</th><th>name</th><th width=150 title="reserve network and router addresses">reserve network / router addresses</th></tr>'; $i = 1; foreach ($ipspace as $prefix => $ipspace) { $netcreatecheckbox = '<b style="background-color:#00ff00">' . '<input class="ipspace" style="background-color:#00ff00" type="checkbox" name="netcreate[' . $i . ']" value="' . $ipspace['addrtype'] . '"' . ($ipspace['checked'] ? ' checked=\\"checked\\"' : '') . '></b>'; $netprefixfield = '<input type="text" size=50 name="netprefix[' . $i . ']" value="' . $prefix . '">'; $netnamefield = '<input type="text" name="netname[' . $i . ']">'; $netreservecheckbox = '<input type="checkbox" name="netreserve[' . $i . ']" checked="checked">'; echo "<tr><td>{$netcreatecheckbox}</td><td style=\"color:#888888\">{$ipspace['addrtype']}</td><td>{$netprefixfield}</td><td>{$netnamefield}</td><td>{$netreservecheckbox}</td></tr>"; $i++; } unset($prefix); unset($addrtype); unset($i); echo '</table>'; } echo "<br><br>ifNumber: " . $ifsnmp->ifNumber . "<br>indexcount: " . $ifsnmp->indexcount . "<br><table><tbody valign=\"top\">"; $portcompat = getPortInterfaceCompat(); $ipnets = array(); $ifsnmp->printifInfoTableHeader("<th>add ip</th><th>add port</th><th>upd label</th><th title=\"update mac\">upd mac</th><td>upd port type</th><th>porttypeid</th><th>comment</th></tr>"); echo '<tr><td colspan="11"></td> <td><input type="checkbox" id="ipaddr" onclick="setchecked(this.id);" checked="checked">IPv4<br> <input type="checkbox" id="ipv6addr" onclick="setchecked(this.id);" checked="checked">IPv6</td> <td><input type="checkbox" id="ports" onclick="setchecked(this.id)"></td> <td><input type="checkbox" id="label" onclick="setchecked(this.id);" checked="checked"></td> <td><input type="checkbox" id="mac" onclick="setchecked(this.id);" checked="checked"></td> <td><input type="checkbox" id="porttype" onclick="setchecked(this.id);"></td></tr>'; foreach ($ifsnmp as $if) { $createport = TRUE; $disableport = FALSE; $ignoreport = FALSE; $port_info = NULL; $updatelabel = false; $updateporttype = false; $updatemaccheckbox = ''; $hrefs = array(); $comment = ""; if (trim($ifsnmp->ifName($if)) == '') { $comment .= "no ifName"; $createport = FALSE; } else { if (array_key_exists($ifsnmp->ifName($if), $object['ports'])) { $port_info =& $object['ports'][$ifsnmp->ifName($if)]; $comment .= "Name exists"; /* ifalias change */ if ($port_info['label'] != $ifsnmp->ifAlias($if)) { $updatelabel = true; } $createport = FALSE; $disableport = TRUE; } } if ($ifsnmp->ifPhysAddress($if) != '') { $ifPhysAddress = $ifsnmp->ifPhysAddress($if); $l2port = sg_checkL2Address($ifPhysAddress); if (!empty($l2port)) { $l2object_id = key($l2port); $porthref = makeHref(array('page' => 'object', 'tab' => 'ports', 'object_id' => $l2object_id, 'hl_port_id' => $l2port[$l2object_id])); $comment .= ", L2Address exists"; $hrefs['ifPhysAddress'] = $porthref; $createport = FALSE; // $disableport = TRUE; $updatemaccheckbox = ''; } $disablemac = true; if ($disableport) { if ($port_info !== NULL) { if (str_replace(':', '', $port_info['l2address']) != $ifPhysAddress) { $disablemac = false; } else { $disablemac = true; } } } else { /* port create always updates mac */ $updatemaccheckbox = '<b style="background-color:#00ff00">' . '<input style="background-color:' . '#00ff00" type="checkbox"' . ' checked="checked"' . ' disabled=\\"disabled\\"></b>'; } if (!$disablemac) { $updatemaccheckbox = '<b style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '">' . '<input class="mac" style="background-color:' . ($disablemac ? '#ff0000' : '#00ff00') . '" type="checkbox" name="updatemac[' . $if . ']" value="' . $object['ports'][$ifsnmp->ifName($if)]['id'] . '" checked="checked"' . ($disablemac ? ' disabled=\\"disabled\\"' : '') . '></b>'; } } $porttypeid = guessRToif_id($ifsnmp->ifType($if), $ifsnmp->ifDescr($if)); if (in_array($ifsnmp->ifType($if), $sg_ifType_ignore)) { $comment .= ", ignore if type"; $createport = FALSE; $ignoreport = TRUE; } else { if ($port_info) { $ptid = $port_info['iif_id'] . "-" . $port_info['oif_id']; if ($porttypeid != $ptid) { $comment .= ", Update Type {$ptid} -> {$porttypeid}"; $updateporttype = true; } } } /* ignore ports without an Connector */ if (!$sg_create_noconnector_ports && $ifsnmp->ifConnectorPresent($if) == 2) { $comment .= ", no Connector"; $createport = FALSE; } /* Allocate IPs ipv4 and ipv6 */ $ipaddresses = $ifsnmp->ipaddress($if); if (!empty($ipaddresses)) { $ipaddrcell = '<table>'; foreach ($ipaddresses as $ipaddr => $value) { $createipaddr = FALSE; $disableipaddr = FALSE; $ipaddrhref = ''; $linklocal = FALSE; $addrtype = $value['addrtype']; $maskbits = $value['maskbits']; $bcast = $value['bcast']; //echo "<br> - DEBUG: ip $ipaddr - $addrtype - $maskbits - $bcast<br>"; switch ($addrtype) { case 'ipv4z': case 'ipv4': if ($maskbits == 32) { $bcast = "host"; } $inputname = 'ip'; break; case 'ipv6z': $disableipaddr = TRUE; case 'ipv6': $inputname = 'ipv6'; if (ip_checkparse($ipaddr) === false) { /* format ipaddr for ip6_parse */ $ipaddr = preg_replace('/((..):(..))/', '\\2\\3', $ipaddr); $ipaddr = preg_replace('/%.*$/', '', $ipaddr); } if (ip_checkparse($ipaddr) === false) { continue 2; } // 2 because of switch /* ip_parse throws exception on parse errors */ $ip6_bin = ip_parse($ipaddr); $ipaddr = ip_format($ip6_bin); $node = constructIPRange($ip6_bin, $maskbits); $linklocal = $node['ip'] == 'fe80::'; $createipaddr = FALSE; break; } //switch $address = getIPAddress(ip_parse($ipaddr)); /* only if ip not already allocated */ if (empty($address['allocs'])) { if (!$ignoreport) { $createipaddr = TRUE; } } else { $disableipaddr = TRUE; $ipobject_id = $address['allocs'][0]['object_id']; $ipaddrhref = makeHref(array('page' => 'object', 'object_id' => $ipobject_id, 'hl_ipv4_addr' => $ipaddr)); } /* reserved addresses */ if ($address['reserved'] == 'yes') { $comment .= ', ' . $address['ip'] . ' reserved ' . $address['name']; $createipaddr = FALSE; // $disableipaddr = TRUE; } if ($ipaddr == '127.0.0.1' || $ipaddr == '0.0.0.0' || $ipaddr == '::1' || $ipaddr == '::' || $linklocal) { $createipaddr = FALSE; $disableipaddr = TRUE; } if ($ipaddr === $bcast) { $comment .= ", {$ipaddr} broadcast"; $createipaddr = FALSE; $disableipaddr = TRUE; } if (!$disableipaddr) { $ipaddrcheckbox = '<b style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '"><input class="' . $inputname . 'addr" style="background-color:' . ($disableipaddr ? '#ff0000' : '#00ff00') . '" type="checkbox" name="' . $inputname . 'addrcreate[' . $ipaddr . ']" value="' . $if . '"' . ($disableipaddr ? ' disabled="disabled"' : '') . ($createipaddr ? ' checked="checked"' : '') . '></b>'; } else { $ipaddrcheckbox = ''; } $ipaddrcell .= "<tr><td>{$ipaddrcheckbox}</td>"; if (!empty($ipaddrhref)) { $ipaddrcell .= "<td><a href={$ipaddrhref}>{$ipaddr}/{$maskbits}</a></td></tr>"; } else { $ipaddrcell .= "<td>{$ipaddr}/{$maskbits}</td></tr>"; } } // foreach unset($ipaddr); unset($value); $ipaddrcell .= '</table>'; // if(!empty($ipaddresses)) } else { $ipaddrcreatecheckbox = ''; $ipaddrcell = ''; } /* checkboxes for add port and add ip */ /* FireFox needs <b style=..>, IE and Opera work with <td style=..> */ if (!$disableport) { $portcreatecheckbox = '<b style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '"><input class="ports" style="background-color:' . ($disableport ? '#ff0000' : '#00ff00') . '" type="checkbox" name="portcreate[' . $if . ']" value="' . $if . '"' . ($disableport ? ' disabled="disbaled"' : '') . ($createport ? ' checked="checked"' : '') . '></b>'; } else { $portcreatecheckbox = ''; } /* port type id */ /* add port type to newporttypeoptions if missing */ if (strpos(serialize($newporttypeoptions), $porttypeid) === FALSE) { $portids = explode('-', $porttypeid); $oif_name = $sg_portoifoptions[$portids[1]]; $newporttypeoptions['auto'] = array($porttypeid => "*{$oif_name}"); } $selectoptions = array('name' => "porttypeid[{$if}]"); if ($disableport && !$updateporttype) { $selectoptions['disabled'] = "disabled"; } $updateporttypecheckbox = ""; if ($updateporttype) { $updateporttypecheckbox = '<b style="background-color:#00ff00;">' . '<input class="porttype" style="background-color:#00ff00;" type="checkbox" name="updateporttype[' . $if . ']" value="' . $port_info['id'] . '"></b>'; } $porttypeidselect = getNiftySelect($newporttypeoptions, $selectoptions, $porttypeid); $updatelabelcheckbox = ""; if ($updatelabel) { $updatelabelcheckbox = '<b style="background-color:#00ff00;">' . '<input class="label" style="background-color:#00ff00;" type="checkbox" name="updatelabel[' . $if . ']" value="' . $port_info['id'] . ($updatelabel ? '" checked="checked"' : '') . '></b>'; } $comment = trim($comment, ', '); $ifsnmp->printifInfoTableRow($if, "<td>{$ipaddrcell}</td><td>{$portcreatecheckbox}</td><td>{$updatelabelcheckbox}</td><td>{$updatemaccheckbox}</td><td>{$updateporttypecheckbox}</td><td>{$porttypeidselect}</td><td nowrap=\"nowrap\">{$comment}</td>", $hrefs); } unset($if); /* preserve snmpconfig */ foreach ($_POST as $key => $value) { echo '<input type=hidden name=' . $key . ' value=' . $value . ' />'; } unset($key); unset($value); echo '<tr><td colspan=15 align="right"><p><input id="createbutton" type=submit value="Create Ports and IPs" onclick="return confirm(\'Create selected items?\')"></p></td></tr></tbody></table></form>'; }
function updateObjectAllocation() { global $remote_username, $sic; if (!isset($_REQUEST['got_atoms'])) { unset($_GET['page']); unset($_GET['tab']); unset($_GET['op']); unset($_POST['page']); unset($_POST['tab']); unset($_POST['op']); return buildRedirectURL(NULL, NULL, $_REQUEST); } $object_id = getBypassValue(); $rf1 = $_REQUEST['rfid']; if (isset($_REQUEST['rfid'])) { // $rf1 = 1000000;//$_REQUEST['rfid']; $result = usePreparedSelectBlade("SELECT object_id FROM objecttorf WHERE rf_id = ?", array($rf1)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row)) { $object_id = $row['object_id']; } //получить значение из базы где rf1=njvenj //showError ('Permission deniedddddddd, "' . $object_id . '" left unchanged'); } $changecnt = 0; // Get a list of all of this object's parents, // then trim the list to only include parents that are racks $objectParents = getEntityRelatives('parents', 'object', $object_id); $parentRacks = array(); foreach ($objectParents as $parentData) { if ($parentData['entity_type'] == 'rack') { $parentRacks[] = $parentData['entity_id']; } } $workingRacksData = array(); foreach ($_REQUEST['rackmulti'] as $cand_id) { if (!isset($workingRacksData[$cand_id])) { $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); $workingRacksData[$cand_id] = $rackData; } // It's zero-U mounted to this rack on the form, but not in the DB. Mount it. if (isset($_REQUEST["zerou_{$cand_id}"]) && !in_array($cand_id, $parentRacks)) { $changecnt++; commitLinkEntities('rack', $cand_id, 'object', $object_id); } // It's not zero-U mounted to this rack on the form, but it is in the DB. Unmount it. if (!isset($_REQUEST["zerou_{$cand_id}"]) && in_array($cand_id, $parentRacks)) { $changecnt++; commitUnlinkEntities('rack', $cand_id, 'object', $object_id); } } foreach ($workingRacksData as &$rd) { applyObjectMountMask($rd, $object_id); } $oldMolecule = getMoleculeForObject($object_id); foreach ($workingRacksData as $rack_id => $rackData) { if (!processGridForm($rackData, 'F', 'T', $object_id)) { continue; } $changecnt++; // Reload our working copy after form processing. $rackData = spotEntity('rack', $cand_id); amplifyCell($rackData); applyObjectMountMask($rackData, $object_id); $workingRacksData[$rack_id] = $rackData; } if ($changecnt) { // Log a record. $newMolecule = getMoleculeForObject($object_id); usePreparedInsertBlade('MountOperation', array('object_id' => $object_id, 'old_molecule_id' => count($oldMolecule) ? createMolecule($oldMolecule) : NULL, 'new_molecule_id' => count($newMolecule) ? createMolecule($newMolecule) : NULL, 'user_name' => $remote_username, 'comment' => empty($sic['comment']) ? NULL : $sic['comment'])); } showFuncMessage(__FUNCTION__, 'OK', array($changecnt)); }
function renderReducedRack($rack_id, $hl_obj_id = 0) { $rackData = spotEntity('rack', $rack_id); amplifyCell($rackData); markAllSpans($rackData); if ($hl_obj_id > 0) { highlightObject($rackData, $hl_obj_id); } // markupObjectProblems ($rackData); // Function removed in 0.20.5 echo "<center><table border=0><tr valign=middle>"; echo '<td><h2>' . mkA($rackData['name'], 'rack', $rackData['id']) . '</h2></td>'; echo "</h2></td></tr></table>\n"; echo "<table class=rackphg border=0 cellspacing=0 cellpadding=1>\n"; echo "<tr><th width='10%'> </th><th width='20%'>Front</th>"; echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n"; for ($i = $rackData['height']; $i > 0; $i--) { echo "<tr><td>" . inverseRackUnit($i, $rackData) . "</td>"; for ($locidx = 0; $locidx < 3; $locidx++) { if (isset($rackData[$i][$locidx]['skipped'])) { continue; } $state = $rackData[$i][$locidx]['state']; echo "<td class='atom state_{$state}"; if (isset($rackData[$i][$locidx]['hl'])) { echo $rackData[$i][$locidx]['hl']; } echo "'"; if (isset($rackData[$i][$locidx]['colspan'])) { echo ' colspan=' . $rackData[$i][$locidx]['colspan']; } if (isset($rackData[$i][$locidx]['rowspan'])) { echo ' rowspan=' . $rackData[$i][$locidx]['rowspan']; } echo ">"; switch ($state) { case 'T': printObjectDetailsForRenderRack($rackData[$i][$locidx]['object_id']); // TODO set background color based on the tag $o = spotEntity('object', $rackData[$i][$locidx]['object_id']); while (list($key, $val) = each($o['etags'])) { echo "<div style='font: 8px Verdana,sans-serif; text-decoration:none; color=black'>"; echo $val['tag']; echo "</div>"; break; } break; case 'A': echo '<div title="This rackspace does not exist"> </div>'; break; case 'F': echo '<div title="Free rackspace"> </div>'; break; case 'U': echo '<div title="Problematic rackspace, you CAN\'T mount here"> </div>'; break; default: echo '<div title="No data"> </div>'; break; } echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; // Get a list of all of objects Zero-U mounted to this rack $zeroUObjects = getEntityRelatives('children', 'rack', $rack_id); if (count($zeroUObjects) > 0) { echo "<br><table width='75%' class=rack border=0 cellspacing=0 cellpadding=1>\n"; echo "<tr><th>Zero-U:</th></tr>\n"; foreach ($zeroUObjects as $zeroUObject) { $state = $zeroUObject['entity_id'] == $hl_obj_id ? 'Th' : 'T'; echo "<tr><td class='atom state_{$state}'>"; printObjectDetailsForRenderRack($zeroUObject['entity_id']); echo "</td></tr>\n"; } echo "</table>\n"; } echo "</center>\n"; }
function _add($gv, $object_id, $port_id = NULL) { global $lm_multilink_port_types; if ($port_id !== NULL) { if (isset($this->ports[$port_id])) { return; } } if ($this->back != 'front' || $port_id === NULL || $this->allports) { $front = $this->_getObjectPortsAndLinks($object_id, 'front', $port_id, $this->allports); } else { $front = array(); } if ($this->back != 'back' || $port_id === NULL || $this->allports) { $backend = $this->_getObjectPortsAndLinks($object_id, 'back', $port_id, $this->allports); } else { $backend = array(); } $ports = array_merge($front, $backend); /* used only for Graphviz ... * !! numeric ids cause Image_Graphviz problems on nested clusters !! */ $cluster_id = "c{$object_id}"; if (empty($ports)) { /* needed because of gv_image empty cluster bug (invalid foreach argument) */ $gv->addNode("dummy{$cluster_id}", array('label' => '', 'fontsize' => 0, 'size' => 0, 'width' => 0, 'height' => 0, 'shape' => 'point', 'style' => 'invis'), $cluster_id); /* show objects without ports */ if ($object_id === NULL) { return; } } $object = NULL; if ($object_id !== NULL) { if (!isset($gv->graph['clusters'][$cluster_id]) && !isset($gv->graph['subgraphs'][$cluster_id])) { $object = spotEntity('object', $object_id); // ip addresses amplifyCell($object); $object['portip'] = array(); foreach ($object['ipv4'] as $ipv4) { $object['portip'][$ipv4['osif']] = $ipv4['addrinfo']['ip']; } // $object['attr'] = getAttrValues($object_id); $clusterattr = array(); $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'color'); $this->_getcolor('cluster', 'default', $this->alpha, $clusterattr, 'fontcolor'); if ($this->object_id == $object_id) { $clusterattr['rank'] = 'source'; $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'color'); $this->_getcolor('cluster', 'current', $this->alpha, $clusterattr, 'fontcolor'); } $clustertitle = "{$object['dname']}"; $text = "{$object['dname']}"; $clusterattr['tooltip'] = $clustertitle; unset($_GET['module']); // makeHrefProcess adds this unset($_GET['port_id']); unset($_GET['remote_id']); $_GET['object_id'] = $object_id; //$_GET['hl'] = 'o'; $clusterattr['URL'] = $this->_makeHrefProcess($_GET); //has_problems if ($object['has_problems'] != 'no') { $clusterattr['style'] = 'filled'; $this->_getcolor('cluster', 'problem', $this->alpha, $clusterattr, 'fillcolor'); } if (!empty($object['container_name'])) { $clustertitle .= "<BR/>{$object['container_name']}"; $text .= "\n{$object['container_name']}"; } if ($object['rack_id']) { $rack = spotEntity('rack', $object['rack_id']); if (!empty($rack['row_name']) || !empty($rack['name'])) { $clustertitle .= "<BR/>{$rack['row_name']} / {$rack['name']}"; $text .= "\n{$rack['row_name']} / {$rack['name']}"; } } $embedin = $object['container_id']; if (empty($embedin)) { $embedin = 'default'; } else { $embedin = "c{$embedin}"; /* see cluster_id */ /* add container / cluster if not already exists */ $this->_add($gv, $object['container_id'], NULL); } $clusterattr['id'] = "{$object_id}----"; /* used for js context menu */ $gv->addCluster($cluster_id, $clustertitle, $clusterattr, $embedin); } /* isset cluster_id */ } /* object_id !== NULL */ foreach ($ports as $key => $port) { $this->back = $port['linktype']; if (!isset($this->ports[$port['id']])) { $nodelabel = htmlspecialchars("{$port['name']}"); $text = $nodelabel; if ($port['iif_id'] != '1') { $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">{$port['iif_name']}</FONT>"; $text .= "\n" . $port['iif_name']; } $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">{$port['oif_name']}</FONT>"; $text .= "\n" . $port['oif_name']; // add ip address if ($object) { if (isset($object['portip'][$port['name']])) { $nodelabel .= "<BR/><FONT POINT-SIZE=\"8\">" . $object['portip'][$port['name']] . "</FONT>"; $text .= "\n" . $object['portip'][$port['name']]; } } $nodeattr = array('label' => $nodelabel); $this->_getcolor('port', 'default', $this->alpha, $nodeattr, 'fontcolor'); $this->_getcolor('oif_id', $port['oif_id'], $this->alpha, $nodeattr, 'color'); if ($this->port_id == $port['id']) { $nodeattr['style'] = 'filled'; $nodeattr['fillcolor'] = $this->_getcolor('port', 'current', $this->alpha); } if ($this->remote_id == $port['id']) { $nodeattr['style'] = 'filled'; $nodeattr['fillcolor'] = $this->_getcolor('port', 'remote', $this->alpha); } $nodeattr['tooltip'] = htmlspecialchars("{$port['name']}"); unset($_GET['module']); unset($_GET['remote_id']); $_GET['object_id'] = $port['object_id']; $_GET['port_id'] = $port['id']; $_GET['hl'] = 'p'; $nodeattr['URL'] = $this->_makeHrefProcess($_GET); $nodeattr['id'] = "{$port['object_id']}-{$port['id']}--"; /* for js context menu */ $gv->addNode($port['id'], $nodeattr, "c{$port['object_id']}"); /* see cluster_id */ $this->ports[$port['id']] = true; } /* isset port */ if (!empty($port['remote_id'])) { if ($this->object_id !== NULL) { $this->_add($gv, $port['remote_object_id'], $port['remote_id']); } if (!isset($gv->graph['edgesFrom'][$port['id']][$port['remote_id']]) && !isset($gv->graph['edgesFrom'][$port['remote_id']][$port['id']])) { $linktype = $port['linktype']; $edgetooltip = $port['object_name'] . ':' . $port['name'] . ' - ' . $port['cableid'] . ' -> ' . $port['remote_name'] . ':' . $port['remote_object_name']; $edgeattr = array('fontsize' => 8, 'label' => htmlspecialchars($port['cableid']), 'tooltip' => $edgetooltip, 'sametail' => $linktype, 'samehead' => $linktype); $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'color'); $this->_getcolor('edge', 'default', $this->alpha, $edgeattr, 'fontcolor'); if ($linktype == 'back') { $edgeattr['style'] = 'dashed'; $edgeattr['arrowhead'] = 'none'; $edgeattr['arrowtail'] = 'none'; /* multilink ports */ if (in_array($port['oif_id'], $lm_multilink_port_types)) { $edgeattr['dir'] = 'both'; $edgeattr['arrowtail'] = 'dot'; } if (in_array($port['remote_oif_id'], $lm_multilink_port_types)) { $edgeattr['dir'] = 'both'; $edgeattr['arrowhead'] = 'dot'; } } if ($port['id'] == $this->port_id && $port['remote_id'] == $this->remote_id || $port['id'] == $this->remote_id && $port['remote_id'] == $this->port_id) { $this->_getcolor('edge', 'highlight', 'ff', $edgeattr, 'color'); $edgeattr['penwidth'] = 2; /* bold */ } unset($_GET['module']); $_GET['object_id'] = $port['object_id']; $_GET['port_id'] = $port['id']; $_GET['remote_id'] = $port['remote_id']; $edgeattr['URL'] = $this->_makeHrefProcess($_GET); $edgeattr['id'] = $port['object_id'] . "-" . $port['id'] . "-" . $port['remote_id'] . "-" . $linktype; /* for js context menu */ $gv->addEdge(array($port['id'] => $port['remote_id']), $edgeattr, array($port['id'] => $linktype, $port['remote_id'] => $linktype)); } } } // portlist::var_dump_html($port); }
function cloneVST() { assertUIntArg('mutex_rev', TRUE); assertUIntArg('from_id'); $src_vst = spotEntity('vst', $_REQUEST['from_id']); amplifyCell($src_vst); commitUpdateVSTRules(getBypassValue(), $_REQUEST['mutex_rev'], $src_vst['rules']); return showFuncMessage(__FUNCTION__, 'OK'); }
function copyLotOfObjects() { global $dbxlink; $dbrollback = 0; if (!$dbxlink->beginTransaction()) { throw new RTDatabaseError("can not start transaction"); } // do we need this ? $log = emptyLog(); $taglist = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); assertUIntArg('global_type_id', TRUE); assertStringArg('namelist', TRUE); $global_type_id = $_REQUEST['global_type_id']; $source_object_id = $_REQUEST['object_id']; $source_object = spotEntity('object', $source_object_id); amplifyCell($source_object); // only call amplifyCell_object_Backend_Port if we have function linkmgmt_linkPorts from linkmgmt.php if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) { amplifyCell_object_Backend_Port($source_object); } if ($global_type_id == 0 or !strlen($_REQUEST['namelist'])) { // Log something reasonable with showError Here // We do not have names to copy our object to ! // Pls check what makes $global_type_id == 0 an error $log = mergeLogs($log, oneLiner(186)); return; } // The name extractor below was stolen from ophandlers.php:addMultiPorts() $names1 = explode("\n", $_REQUEST['namelist']); $names2 = array(); foreach ($names1 as $line) { $parts = explode('\\r', $line); reset($parts); if (!strlen($parts[0])) { continue; } else { $names2[] = rtrim($parts[0]); } } foreach ($names2 as $name_or_csv) { $label = ''; $asset_no = ''; $object_name = ''; $regexp = '/^\\"([^\\"]*)\\","([^\\"]*)\\","([^\\"]*)\\"/'; $object_name_or_csv = htmlspecialchars_decode($name_or_csv, ENT_QUOTES); // error_log( "$regexp $object_name" ); if (preg_match($regexp, $object_name_or_csv, $matches)) { $object_name = $matches[1]; $label = $matches[2]; $asset_no = $matches[3]; } else { $object_name = $name_or_csv; } try { $object_id = commitAddObject($object_name, $label, $global_type_id, $asset_no, $taglist); if (!$object_id) { throw new RTDatabaseError("could not create {$object_name}"); } $info = spotEntity('object', $object_id); amplifyCell($info); foreach ($source_object['ports'] as $source_port) { $update_port = 0; foreach ($info['ports'] as $new_port) { if ($new_port['name'] == $source_port['name']) { commitUpdatePort($object_id, $new_port['id'], $new_port['name'], $new_port['oif_id'], $source_port['label'], ""); $update_port = 1; } } if ($update_port) { true; } else { commitAddPort($object_id, $source_port['name'], sprintf("%s-%s", $source_port['iif_id'], $source_port['oif_id']), $source_port['label'], ""); } } // Copy Backendlinks only start if we ghave function linkmgmt_linkPorts from linkmgmt.php if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) { $info = spotEntity('object', $object_id); amplifyCell($info); amplifyCell_object_Backend_Port($info); /* showError( '<div align="left"><pre>\n===== Source Object ======\n\n' . varDumpToString ( $source_object ) . '\n\n===== New Object ======\n\n' . varDumpToString ( $info ) . '</pre></div>' ); */ $name_by_id = array(); foreach ($info['BackendPorts'] as $new_be_port) { $name_by_id[$new_be_port['name']] = $new_be_port['id']; } $linked_ports = array(); foreach ($source_object['BackendPorts'] as $source_be_port) { if ($source_be_port['object_id'] == $source_be_port['remote_object_id']) { // We have a Port that has the own object as remote object we want to copy this type of Linko // We have backend Links $new_be_port_a = $name_by_id[$source_be_port['name']]; $new_be_port_b = $name_by_id[$source_be_port['remote_name']]; if ($new_be_port_a && $new_be_port_b && !array_key_exists($new_be_port_a, $linked_ports) && !array_key_exists($new_be_port_b, $linked_ports)) { // error_log ( sprintf ('new_be_port_a %s // new_be_port_b %s // cableid %s', $new_be_port_a , $new_be_port_b, $source_be_port['cableid'] )); $ret_val = linkmgmt_linkPorts($new_be_port_a, $new_be_port_b, 'back', $source_be_port['cableid']); // error_log ( sprintf (' linkmgmt_linkPorts ret val: "%s" ', $ret_val)) ; if ($ret_val) { throw new RTDatabaseError("could not copy Backend Links for {$object_name} because: {$ret_val}"); } else { $linked_ports[$new_be_port_a] = True; $linked_ports[$new_be_port_b] = True; } } } } } // Copy attributes foreach (getAttrValues($source_object_id) as $record) { $value = $record['value']; switch ($record['type']) { case 'uint': case 'float': case 'string': $value = $record['value']; break; case 'dict': $value = $record['key']; break; default: } if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) { if (empty($value)) { commitUpdateAttrValue($object_id, $record['id']); } else { commitUpdateAttrValue($object_id, $record['id'], $value); } } else { showError('Permission denied, "' . $record['name'] . '" can not be set'); } } //$log = mergeLogs ($log, oneLiner (5, array ('<a href="' . // makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . // '">' . $info['dname'] . '</a>')) //); showSuccess(sprintf("Copied Object %s ; new Object: %s", $source_object['name'], formatPortLink($object_id, $info['dname'], 1, '', ''))); } catch (RTDatabaseError $e) { error_log("rolling back DB"); $dbrollback = 1; $dbxlink->rollBack(); $log = mergeLogs($log, oneLiner(147, array($object_name))); throw new RTDatabaseError($e->getMessage() . sprintf(' (%s)', $name_or_csv)); } } if (!$dbrollback) { $dbxlink->commit(); } // return buildWideRedirectURL ($log); }
function getPortinfoByName(&$object, $portname) { if (!isset($object['ports'])) { amplifyCell($object); } foreach ($object['ports'] as $portinfo) { if ($portinfo['name'] == $portname) { return $portinfo; } } return NULL; }
function renderPortletWattConsumption($info) { $rackTotalWattage = 0; $rackData = spotEntity('rack', $info['id']); amplifyCell($rackData); $objectChildren = getEntityRelatives('children', 'object', $objectData['id']); foreach ($rackData['mountedObjects'] as $object) { $objectData = spotEntity('object', $object); amplifyCell($objectData); foreach (getAttrValues($objectData['id']) as $record) { if ($record['name'] == 'Wattage consumption') { $rackTotalWattage += $record['value']; } } } startPortlet('Wattage Consumption'); echo "<table border=0 cellspacing=5 align='center'><tr>"; echo "<td>The total for attribute Wattage consuption is: <b>{$rackTotalWattage}</b></td>\n"; echo "</tr></table>\n"; finishPortlet(); }
function getResidentRacksData($object_id = 0, $fetch_rackdata = TRUE) { // Include racks that the object is directly mounted in, racks that it's parent is mounted in, // and racks that it is 'Zero-U' mounted in $result = usePreparedSelectBlade('SELECT DISTINCT RS.rack_id FROM RackSpace RS LEFT JOIN EntityLink EL ON RS.object_id = EL.parent_entity_id AND EL.parent_entity_type = ? ' . 'WHERE RS.object_id = ? or EL.child_entity_id = ? ' . 'UNION ' . "SELECT parent_entity_id AS rack_id FROM EntityLink where parent_entity_type = 'rack' AND child_entity_type = 'object' AND child_entity_id = ? " . 'ORDER BY rack_id', array('rack', $object_id, $object_id, $object_id)); $rows = $result->fetchAll(PDO::FETCH_NUM); unset($result); $ret = array(); foreach ($rows as $row) { if (!$fetch_rackdata) { $ret[$row[0]] = $row[0]; continue; } $rackData = spotEntity('rack', $row[0]); amplifyCell($rackData); $ret[$row[0]] = $rackData; } return $ret; }
function renderRack($rack_id, $hl_obj_id = 0) { $rackData = spotEntity('rack', $rack_id); amplifyCell($rackData); markAllSpans($rackData); if ($hl_obj_id > 0) { highlightObject($rackData, $hl_obj_id); } $prev_id = getPrevIDforRack($rackData['row_id'], $rack_id); $next_id = getNextIDforRack($rackData['row_id'], $rack_id); echo "<center><table border=0><tr valign=middle>"; echo '<td><h2>' . mkA($rackData['row_name'], 'row', $rackData['row_id']) . ' :</h2></td>'; if ($prev_id != NULL) { echo '<td>' . mkA(getImageHREF('prev', 'previous rack'), 'rack', $prev_id) . '</td>'; } echo '<td><h2>' . mkA($rackData['name'], 'rack', $rackData['id']) . '</h2></td>'; if ($next_id != NULL) { echo '<td>' . mkA(getImageHREF('next', 'next rack'), 'rack', $next_id) . '</td>'; } echo "</h2></td></tr></table>\n"; $result = usePreparedSelectBlade("SELECT * FROM racktemperature WHERE rackid = ?", array($rack_id)); $row = $result->fetch(PDO::FETCH_ASSOC); if (isset($row['top'])) { echo "<table align=left border=1>\n"; echo "<tr><th>Sensor</th><th>Temperature</th></tr>\n"; for ($i = $rackData['height']; $i > 5; $i--) { if ($i == 40) { echo "<tr><td>top</td><td>{$row['top']}</td></tr>\n"; } else { if ($i == 23) { echo "<tr><td>middle</td><td>{$row['middle']}</td></tr>\n"; } else { if ($i == 11) { echo "<tr><td>bottom</td><td>{$row['bottom']}</td></tr>\n"; } else { echo "<tr><td> </td><td> </td></tr>\n"; } } } } echo "</table>"; } echo "<table class=rack align=center border=0 cellspacing=0 cellpadding=1>\n"; echo "<tr><th width='10%'> </th><th width='20%'>Front</th>"; echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n"; for ($i = $rackData['height']; $i > 0; $i--) { echo "<tr><th>" . inverseRackUnit($i, $rackData) . "</th>"; for ($locidx = 0; $locidx < 3; $locidx++) { if (isset($rackData[$i][$locidx]['skipped'])) { continue; } $state = $rackData[$i][$locidx]['state']; echo "<td class='atom state_{$state}"; if (isset($rackData[$i][$locidx]['hl'])) { echo $rackData[$i][$locidx]['hl']; } echo "'"; if (isset($rackData[$i][$locidx]['colspan'])) { echo ' colspan=' . $rackData[$i][$locidx]['colspan']; } if (isset($rackData[$i][$locidx]['rowspan'])) { echo ' rowspan=' . $rackData[$i][$locidx]['rowspan']; } echo ">"; switch ($state) { case 'T': printObjectDetailsForRenderRack($rackData[$i][$locidx]['object_id'], $hl_obj_id); break; case 'A': echo '<div title="This rackspace does not exist"> </div>'; break; case 'F': echo '<div title="Free rackspace"> </div>'; break; case 'U': echo '<div title="Problematic rackspace, you CAN\'T mount here"> </div>'; break; default: echo '<div title="No data"> </div>'; break; } echo '</td>'; } echo "</tr>\n"; } echo "</table>\n"; // Get a list of all of objects Zero-U mounted to this rack $zeroUObjects = getEntityRelatives('children', 'rack', $rack_id); if (count($zeroUObjects) > 0) { echo "<br><table width='75%' class=rack border=0 cellspacing=0 cellpadding=1>\n"; echo "<tr><th>Zero-U:</th></tr>\n"; foreach ($zeroUObjects as $zeroUObject) { $state = $zeroUObject['entity_id'] == $hl_obj_id ? 'Th' : 'T'; echo "<tr><td class='atom state_{$state}'>"; printObjectDetailsForRenderRack($zeroUObject['entity_id']); echo "</td></tr>\n"; } echo "</table>\n"; } echo "</center>\n"; }
function doVSMigrate() { global $dbxlink; $vs_id = assertUIntArg('vs_id'); $vs_cell = spotEntity('ipvs', $vs_id); amplifyCell($vs_cell); $tag_ids = genericAssertion('taglist', 'array0'); $old_vs_list = genericAssertion('vs_list', 'array'); $plan = callHook('buildVSMigratePlan', $vs_id, $old_vs_list); $dbxlink->beginTransaction(); // remove all triplets usePreparedDeleteBlade('VSEnabledIPs', array('vs_id' => $vs_id)); usePreparedDeleteBlade('VSEnabledPorts', array('vs_id' => $vs_id)); // remove all VIPs and ports that are in $plan and create new ones foreach ($plan['vips'] as $vip) { usePreparedDeleteBlade('VSIPs', array('vs_id' => $vs_id, 'vip' => $vip['vip'])); usePreparedInsertBlade('VSIPs', array('vs_id' => $vs_id) + $vip); } foreach ($plan['ports'] as $port) { usePreparedDeleteBlade('VSPorts', array('vs_id' => $vs_id, 'proto' => $port['proto'], 'vport' => $port['vport'])); usePreparedInsertBlade('VSPorts', array('vs_id' => $vs_id) + $port); } // create triplets foreach ($plan['triplets'] as $triplet) { $tr_key = array('vs_id' => $triplet['vs_id'], 'object_id' => $triplet['object_id'], 'rspool_id' => $triplet['rspool_id']); foreach ($triplet['ports'] as $port) { addSLBPortLink($tr_key + $port); } foreach ($triplet['vips'] as $vip) { addSLBIPLink($tr_key + $vip); } } // update configs usePreparedUpdateBlade('VS', $plan['properties'], array('id' => $vs_id)); // replace tags global $taglist; $chain = array(); foreach ($tag_ids as $tid) { if (!isset($taglist[$tid])) { $dbxlink->rollback(); showError("Unknown tag id {$tid}"); } else { $chain[] = $taglist[$tid]; } } rebuildTagChainForEntity('ipvs', $vs_id, $chain, TRUE); $dbxlink->commit(); showSuccess("old VS configs were copied to VS group"); return buildRedirectURL(NULL, 'default'); }
function generateMiniRack($rack_id) { if (NULL === ($rackData = spotEntity('rack', $rack_id))) { return FALSE; } amplifyCell($rackData); markupObjectProblems($rackData); global $rtwidth; $rtdepth = 9; $offset[0] = 3; $offset[1] = 3 + $rtwidth[0]; $offset[2] = 3 + $rtwidth[0] + $rtwidth[1]; $totalheight = 3 + 3 + $rackData['height'] * 2; $totalwidth = $offset[2] + $rtwidth[2] + 3; $img = @imagecreatetruecolor($totalwidth, $totalheight) or die("Cannot Initialize new GD image stream"); # It was measured, that caching palette in an array is faster, than # calling colorFromHex() multiple times. It matters, when user's # browser is trying to fetch many minirack images in parallel. $color = array('F' => colorFromHex($img, '8fbfbf'), 'A' => colorFromHex($img, 'bfbfbf'), 'U' => colorFromHex($img, 'bf8f8f'), 'T' => colorFromHex($img, '408080'), 'Th' => colorFromHex($img, '80ffff'), 'Tw' => colorFromHex($img, '804040'), 'Thw' => colorFromHex($img, 'ff8080'), 'black' => colorFromHex($img, '000000'), 'gray' => colorFromHex($img, 'c0c0c0')); $border_color = $rackData['has_problems'] == 'yes' ? $color['Thw'] : $color['gray']; imagerectangle($img, 0, 0, $totalwidth - 1, $totalheight - 1, $color['black']); imagerectangle($img, 1, 1, $totalwidth - 2, $totalheight - 2, $border_color); imagerectangle($img, 2, 2, $totalwidth - 3, $totalheight - 3, $color['black']); for ($unit_no = 1; $unit_no <= $rackData['height']; $unit_no++) { for ($locidx = 0; $locidx < 3; $locidx++) { $colorcode = $rackData[$unit_no][$locidx]['state']; if (isset($rackData[$unit_no][$locidx]['hl'])) { $colorcode = $colorcode . $rackData[$unit_no][$locidx]['hl']; } imagerectangle($img, $offset[$locidx], 3 + ($rackData['height'] - $unit_no) * 2, $offset[$locidx] + $rtwidth[$locidx] - 1, 3 + ($rackData['height'] - $unit_no) * 2 + 1, $color[$colorcode]); } } imagepng($img); imagedestroy($img); return TRUE; }
function trigger_autoports() { assertUIntArg('object_id'); $object = spotEntity('object', $_REQUEST['object_id']); amplifyCell($object); if (count($object['ports'])) { return ''; } return count(getAutoPorts($object['objtype_id'])) ? 'attn' : ''; }
function snmplive_tabhandler($object_id) { addCSS(<<<ENDCSS .ifoperstatus-default { background-color:#ddd; } .ifoperstatus-1, .ifoperstatus-up { background-color:#00ff00; } .ifoperstatus-2, .ifoperstatus-down { background-color:#ff0000; } .ifoperstatus-3, .ifoperstatus-testing { background-color:#ffff66; } .ifoperstatus-4, .ifoperstatus-unknown { background-color:#ffffff; } .ifoperstatus-5, .ifoperstatus-dormant { background-color:#90bcf5; } .ifoperstatus-6, .ifoperstatus-notPresent { } .ifoperstatus-7, .ifoperstatus-lowerLayerDown { } .port-groups { border-spacing:1px;display:table; } .port-group { display:table-cell;border:3px solid #000;background-color:#c0c0c0; } .port-column { display:table-cell;position:relative; } .port { position:relative;width:42px;height:100px;border:2px solid #000;overflow:hidden; } .port-pos-1 { margin-bottom:1px; } .port-pos-2 { } .port-pos-0 { margin-top:1px; } .port-header { position:absolute } .port-header-pos-1 { top:0px; } .port-header-pos-0 { bottom:0px; } .port-status { position:absolute;min-width:42px;text-align:center;font-size:10pt; } .port-status-pos-1 { top:35px; } .port-status-pos-0 { bottom:35px; } .port-info { position:absolute;width:90%;background-color:#ddd;overflow:hidden; } .port-info-pos-1 { top: 80px; } .port-info-pos-0 { bottom: 80px;} .port-name { font-size:10pt;margin:0px auto;width:40px;text-align:center; } .port-number { font-size:8pt;color:#eee; } .port-detail { position:fixed;z-index:1000;top:0px;right:0px;border:3px solid #000;background-color:#fff } .port-detail-links { background-color:#ccc } .hidden { visibility:hidden; } .info-footer { } ENDCSS , TRUE); echo "<div id=\"info\"></div>"; if (isset($_GET['debug'])) { $debug = $_GET['debug']; } else { $debug = 0; } $object = spotEntity('object', $object_id); amplifyCell($object); if (isset($_GET['modules'])) { $modules = $_GET['modules']; } else { $modules = false; } if ($modules) { unset($_GET['modules']); } else { $_GET['modules'] = 1; } echo "<a href=" . makeHref($_GET) . ">" . ($modules ? "Hide" : "Show") . " Modules</a>"; pl_layout_default($object, 0, false, $modules); addJS(<<<ENDJS function togglevisibility(elem, hide) { if(hide) elem.css('visibility', 'hidden'); else elem.css('visibility', 'visible'); //a.show(); //a.hide(); } function setdetail(elem, hide) { var a = \$( "#port" + elem.id + "-detail"); togglevisibility(a, hide); } function setports( data, textStatus, jqHXR ) { if(data.debug) \$( "#info" ).html(\$( "#info" ).html() + "DEBUG: " + data.name + ": " + data.debug); for(var index in data.ports) { setport(data, data.ports[index]); } } function setportstatus( obj, port , id , detail) { tagidsuffix = ""; if(detail) tagidsuffix = tagidsuffix + "-detail"; if(!detail) { \$( "#port" + id + "-status" + tagidsuffix ).html("<table class=\\"ifoperstatus-" + port.snmpinfos. operstatus + "\\"><tr><td>" + port.snmpinfos.operstatus + "<br>" + port.snmpinfos.speed \t\t\t\t\t+ ( port.snmpinfos.vlan ? "<br>" + port.snmpinfos.vlan : "" ) + "</td></tr></table>"); return; } \$( "#port" + id + "-status" + tagidsuffix ).html(port.snmpinfos.alias + "<table class=\\"ifoperstatus-" + port.snmpinfos.operstatus + "\\"><tr><td>" + (port.snmpinfos.ipv4 ? port.snmpinfos.ipv4 : "") \t\t\t\t\t+ "<br>" + port.snmpinfos.operstatus \t\t\t\t\t+ ( port.snmpinfos.vlan ? "<br>" + port.snmpinfos.vlan_name + " (" + port.snmpinfos.vlan + ")" : "" ) + "</td></tr></table>"); } function setport( obj, port ) { if(port.debug) \$( "#info" ).html(\$( "#info" ).html() + port.name + " " + port.debug); if(port.snmpinfos) { setportstatus(obj, port, port.id, false); setportstatus(obj, port, port.id, true); } } function ajaxerror(jqHXR, textStatus, qXHR, errorThrown) { \$( "#info" ).html(\$( "#info" ).html() + "<br>" + textStatus + " " + qXHR + " " + errorThrown); } \t\$.ajax({ \t\tdataType: "json", \t\turl: "index.php", \t\tdata: { \t\t\tpage: "object", \t\t\ttab: "snmplive", \t\t\tmodule: "redirect", \t\t\top: "ajax", \t\t\tjson: "get", \t\t\tobject_id: "{$object_id}", \t\t\tdebug: {$debug} \t\t}, \t\terror: ajaxerror, \t\tsuccess: setports \t}); ENDJS , TRUE); }