Exemplo n.º 1
0
function renderPopupPortSelector()
{
    if (isset($_REQUEST['do_link'])) {
        return handlePopupPortLink();
    }
    assertPermission('depot', 'default');
    assertUIntArg('port');
    $port_id = $_REQUEST['port'];
    $port_info = getPortInfo($port_id);
    $in_rack = isCheckSet('in_rack');
    // fill port filter structure
    $filter = array('racks' => array(), 'objects' => '', 'ports' => '', 'asset_no' => '');
    if (isset($_REQUEST['filter-obj'])) {
        $filter['objects'] = trim($_REQUEST['filter-obj']);
    }
    if (isset($_REQUEST['filter-port'])) {
        $filter['ports'] = trim($_REQUEST['filter-port']);
    }
    if (isset($_REQUEST['filter-asset_no'])) {
        $filter['asset_no'] = trim($_REQUEST['filter-asset_no']);
    }
    if ($in_rack) {
        $object = spotEntity('object', $port_info['object_id']);
        if ($object['rack_id']) {
            // the object itself is mounted in a rack
            $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE'));
        } elseif ($object['container_id']) {
            $container = spotEntity('object', $object['container_id']);
            if ($container['rack_id']) {
                $filter['racks'] = getProximateRacks($container['rack_id'], getConfigVar('PROXIMITY_RANGE'));
            }
        }
    }
    $spare_ports = array();
    if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports']) || !empty($filter['asset_no'])) {
        $spare_ports = findSparePorts($port_info, $filter);
    }
    // display search form
    echo 'Link ' . formatPort($port_info) . ' to...';
    echo '<form method=GET>';
    startPortlet('Port list filter');
    echo '<input type=hidden name="module" value="popup">';
    echo '<input type=hidden name="helper" value="portlist">';
    echo '<input type=hidden name="port" value="' . $port_id . '">';
    echo '<table align="center" valign="bottom"><tr>';
    echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft"><label>Asset tag:<br><input type=text size=8 name="filter-asset_no" value="' . htmlspecialchars($filter['asset_no'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>';
    echo '<td valign="bottom"><input type=submit value="show ports"></td>';
    echo '</tr></table>';
    finishPortlet();
    // display results
    startPortlet('Compatible spare ports');
    if (empty($spare_ports)) {
        echo '(nothing found)';
    } else {
        echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE);
        echo "<p>Cable ID: <input type=text id=cable name=cable>";
        // suggest patch cables where it makes sense
        $heaps = getPatchCableHeapOptionsForOIF($port_info['oif_id']);
        if (count($heaps)) {
            // Use + instead of array_merge() to avoid renumbering the keys.
            echo '<p>Patch cable: ' . getSelect(array(0 => 'none') + $heaps, array('name' => 'heap_id'));
        }
        echo "<p><input type='submit' value='Link' name='do_link'>";
    }
    finishPortlet();
    echo '</form>';
}
Exemplo n.º 2
0
function renderVLANInfo($vlan_ck)
{
    global $vtoptions, $nextorder;
    $vlan = getVLANInfo($vlan_ck);
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>';
    echo "<tr><td class=pcleft width='50%'>";
    startPortlet('summary');
    echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>";
    echo "<tr><th width='50%' class=tdright>Domain:</th><td class=tdleft>";
    echo niftyString($vlan['domain_descr'], 0) . '</td></tr>';
    echo "<tr><th width='50%' class=tdright>VLAN ID:</th><td class=tdleft>{$vlan['vlan_id']}</td></tr>";
    if (strlen($vlan['vlan_descr'])) {
        echo "<tr><th width='50%' class=tdright>Description:</th><td class=tdleft>" . niftyString($vlan['vlan_descr'], 0) . "</td></tr>";
    }
    echo "<tr><th width='50%' class=tdright>Propagation:</th><td class=tdleft>" . $vtoptions[$vlan['vlan_prop']] . "</td></tr>";
    $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1);
    foreach ($others as $other) {
        if ($other['domain_id'] != $vlan['domain_id']) {
            echo '<tr><th class=tdright>Counterpart:</th><td class=tdleft>' . formatVLANAsHyperlink(getVLANInfo("{$other['domain_id']}-{$vlan['vlan_id']}")) . '</td></tr>';
        }
    }
    echo '</table>';
    finishPortlet();
    if (0 == count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) {
        startPortlet('no networks');
    } else {
        startPortlet('networks (' . (count($vlan['ipv4nets']) + count($vlan['ipv6nets'])) . ')');
        $order = 'odd';
        echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
        echo '<tr><th>';
        printImageHREF('net');
        echo '</th><th>';
        printImageHREF('text');
        echo '</th></tr>';
        foreach (array('ipv4net', 'ipv6net') as $nettype) {
            foreach ($vlan[$nettype . 's'] as $netid) {
                $net = spotEntity($nettype, $netid);
                #echo "<tr class=row_${order}><td>";
                echo '<tr><td>';
                renderCell($net);
                echo '</td><td>' . (mb_strlen($net['comment']) ? niftyString($net['comment']) : '&nbsp;');
                echo '</td></tr>';
                $order = $nextorder[$order];
            }
        }
        echo '</table>';
    }
    finishPortlet();
    $confports = getVLANConfiguredPorts($vlan_ck);
    // get non-switch device list
    $foreign_devices = array();
    foreach ($confports as $switch_id => $portlist) {
        $object = spotEntity('object', $switch_id);
        foreach ($portlist as $port_name) {
            if ($portinfo = getPortinfoByName($object, $port_name)) {
                if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) {
                    $foreign_devices[$portinfo['remote_object_id']][] = $portinfo;
                }
            }
        }
    }
    if (!empty($foreign_devices)) {
        startPortlet("Non-switch devices");
        echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>";
        echo '<tr><th>device</th><th>ports</th></tr>';
        $order = 'odd';
        foreach ($foreign_devices as $cell_id => $ports) {
            echo "<tr class=row_{$order} valign=top><td>";
            $cell = spotEntity('object', $cell_id);
            renderCell($cell);
            echo "</td><td><ul>";
            foreach ($ports as $portinfo) {
                echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' &mdash; ' . formatPort($portinfo) . "</li>";
            }
            echo "</ul></td></tr>";
            $order = $nextorder[$order];
        }
        echo '</table>';
        finishPortlet();
    }
    echo '</td><td class=pcright>';
    if (!count($confports)) {
        startPortlet('no ports');
    } else {
        startPortlet('Switch ports (' . count($confports) . ')');
        global $nextorder;
        $order = 'odd';
        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>switch</th><th>ports</th></tr>';
        foreach ($confports as $switch_id => $portlist) {
            usort_portlist($portlist);
            echo "<tr class=row_{$order} valign=top><td>";
            $object = spotEntity('object', $switch_id);
            renderCell($object);
            echo '</td><td class=tdleft><ul>';
            foreach ($portlist as $port_name) {
                echo '<li>';
                if ($portinfo = getPortinfoByName($object, $port_name)) {
                    echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']);
                } else {
                    echo $port_name;
                }
                echo '</li>';
            }
            echo '</ul></td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    echo '</td></tr></table>';
}
Exemplo n.º 3
0
function linkmgmt_renderPopupPortSelector()
{
    global $lm_multilink_port_types;
    assertUIntArg('port');
    $port_id = $_REQUEST['port'];
    $showlinktypeswitch = false;
    if (isset($_GET['linktype'])) {
        $linktype = $_GET['linktype'];
    } else {
        $linktype = 'front';
    }
    if ($linktype == 'both') {
        /*
         * 	use POST front/back_view to set linktype
         *	and show linktype switch button
         */
        $showlinktypeswitch = true;
        if (isset($_POST['front_view'])) {
            $linktype = 'front';
        } else {
            if (isset($_POST['back_view'])) {
                $linktype = 'back';
            } else {
                $linktype = 'front';
            }
        }
    }
    //	portlist::var_dump_html($_POST);
    $portcompat = true;
    if ($linktype == 'back') {
        if (isset($_POST['portcompat'])) {
            $portcompat = $_POST['portcompat'];
        }
    }
    $object_id = $_REQUEST['object_id'];
    $port_info = getPortInfo($port_id);
    $multilink = LM_MULTILINK && $linktype == 'back' && in_array($port_info['oif_id'], $lm_multilink_port_types);
    if (isset($_REQUEST['in_rack'])) {
        $in_rack = $_REQUEST['in_rack'] != 'off';
    } else {
        $in_rack = true;
    }
    //	portlist::var_dump_html($port_info);
    //	portlist::var_dump_html($_GET);
    //	portlist::var_dump_html($_POST);
    // fill port filter structure
    $filter = array('racks' => array(), 'objects' => '', 'object_id' => '', 'ports' => '');
    $remote_object = NULL;
    if (isset($_REQUEST['remote_object'])) {
        $remote_object = $_REQUEST['remote_object'];
        if ($remote_object != 'NULL') {
            $filter['object_id'] = $remote_object;
        }
    }
    if (isset($_REQUEST['filter-obj'])) {
        $filter['objects'] = $_REQUEST['filter-obj'];
    }
    if (isset($_REQUEST['filter-port'])) {
        $filter['ports'] = $_REQUEST['filter-port'];
    }
    if ($in_rack) {
        $object = spotEntity('object', $port_info['object_id']);
        if ($object['rack_id']) {
            $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE'));
        }
    }
    $objectlist = array('NULL' => '- Show All -');
    $objectlist = $objectlist + linkmgmt_findSparePorts($port_info, $filter, $linktype, $multilink, true, false, $portcompat);
    $spare_ports = linkmgmt_findSparePorts($port_info, $filter, $linktype, $multilink, false, false, $portcompat);
    $maxsize = getConfigVar('MAXSELSIZE');
    $objectcount = count($objectlist);
    if ($linktype == 'back') {
        $notlinktype = 'front';
    } else {
        $notlinktype = 'back';
    }
    // display search form
    echo 'Link ' . $linktype . ' of ' . formatPort($port_info) . ' to...';
    echo '<form method=POST>';
    startPortlet($linktype . ' Port list filter');
    // echo '<input type=hidden name="module" value="popup">';
    // echo '<input type=hidden name="helper" value="portlist">';
    echo '<input type=hidden name="port" value="' . $port_id . '">';
    echo '<table><tr><td valign="top"><table><tr><td>';
    echo '<table align="center"><tr>';
    //	echo '<td nowrap="nowrap"><input type="hidden" name="linktype" value="front" /><input type="checkbox" name="linktype" value="back"'.($linktype == 'back' ? ' checked="checked"' : '' ).'>link backend</input></td></tr><tr>';
    echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft" valign="bottom"><input type="hidden" name="in_rack" value="off" /><label><input type=checkbox value="1" name="in_rack"' . ($in_rack ? ' checked="checked"' : '') . ' onchange="this.form.submit();">Nearest racks</label></td>';
    echo '</tr></table>';
    echo '</td></tr><tr><td>';
    echo 'Object name (count ports)<br>';
    echo getSelect($objectlist, array('name' => 'remote_object', 'size' => $objectcount <= $maxsize ? $objectcount : $maxsize), $remote_object, FALSE);
    echo '</td></tr></table></td>';
    echo '<td valign="top"><table><tr><td><input type=submit value="update objects / ports"></td></tr>';
    if ($showlinktypeswitch) {
        echo '<tr height=150px><td><input type=submit value="Switch to ' . $notlinktype . ' view" name="' . $notlinktype . '_view"></tr></td>';
    }
    if ($linktype == 'back') {
        echo '<input type="hidden" name="portcompat" value="0">';
        echo '<tr height=150px><td><input type=checkbox onchange="this.form.submit();" name="portcompat"' . ($portcompat ? 'checked="checked" ' : '') . 'value="1">Port Compatibility</input></tr></td>';
        echo '<input type="hidden" name="back_view">';
    }
    echo '</table></td>';
    finishPortlet();
    echo '</td><td>';
    // display results
    startPortlet('Compatible spare ' . $linktype . ' ports');
    echo "spare {$linktype} Object:Port -- {$notlinktype} cableID -->  {$notlinktype} Port:Object<br>";
    if ($multilink) {
        echo "Multilink<br>";
    }
    if (empty($spare_ports)) {
        echo '(nothing found)';
    } else {
        $linkcount = count($spare_ports);
        $options = array('name' => 'remote_ports[]', 'size' => getConfigVar('MAXSELSIZE'), 'size' => $linkcount <= $maxsize ? $linkcount : $maxsize);
        if ($multilink) {
            $options['multiple'] = 'multiple';
        }
        echo getSelect($spare_ports, $options, NULL, FALSE);
        echo "<p>{$linktype} Cable ID: <input type=text id=cable name=cable>";
        echo "<p><input type='submit' value='Link {$linktype}' name='do_link'>";
    }
    finishPortlet();
    echo '</td></tr></table>';
    echo '</form>';
}
Exemplo n.º 4
0
function renderVLANInfo($vlan_ck)
{
    global $vtoptions, $nextorder;
    $vlan = getVLANInfo($vlan_ck);
    $group_members = getDomainGroupMembers($vlan['domain_id']);
    // list of VLANs to display linked nets and ports from.
    // If domain is a group master, this list contains all
    // the counterpart vlans from domain group members.
    // If domain is a group member, the list contains one
    // counterpart vlan from the domain master.
    $group_ck_list = array();
    echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
    echo '<tr><td colspan=2 align=center><h1>' . formatVLANAsRichText($vlan) . '</h1></td></tr>';
    echo "<tr><td class=pcleft width='50%'>";
    $summary = array();
    $summary['Domain'] = stringForTD($vlan['domain_descr'], 0);
    $summary['VLAN ID'] = $vlan['vlan_id'];
    if (strlen($vlan['vlan_descr'])) {
        $summary['Description'] = stringForTD($vlan['vlan_descr'], 0);
    }
    $summary['Propagation'] = $vtoptions[$vlan['vlan_prop']];
    $others = getSearchResultByField('VLANDescription', array('domain_id'), 'vlan_id', $vlan['vlan_id'], 'domain_id', 1);
    $counterparts = array();
    $group_counterparts = array();
    $domain_list = getVLANDomainOptions();
    foreach ($others as $other) {
        if ($other['domain_id'] != $vlan['domain_id']) {
            $counterpart_ck = "{$other['domain_id']}-{$vlan['vlan_id']}";
            $counterpart_vlan = getVlanRow($counterpart_ck);
            $counterpart_link = mkA($domain_list[$counterpart_vlan['domain_id']] . ': ' . $counterpart_vlan['vlan_descr'], 'vlan', $counterpart_ck);
            if ($counterpart_vlan['domain_id'] == $vlan['domain_group_id'] or in_array($counterpart_vlan['domain_id'], $group_members)) {
                $group_ck_list[$counterpart_ck] = $counterpart_vlan;
                $group_counterparts[] = $counterpart_link;
            } elseif ($vlan['domain_group_id'] and $counterpart_vlan['domain_group_id'] == $vlan['domain_group_id']) {
                $group_counterparts[] = $counterpart_link;
            } else {
                $counterparts[] = $counterpart_link;
            }
        }
    }
    if ($group_counterparts) {
        $group_id = $vlan['domain_group_id'] ? $vlan['domain_group_id'] : $vlan['domain_id'];
        $summary[$domain_list[$group_id] . ' counterparts'] = implode('<br>', $group_counterparts);
    }
    if ($counterparts) {
        $summary['Counterparts'] = implode('<br>', $counterparts);
    }
    renderEntitySummary($vlan, 'summary', $summary);
    $networks = array();
    $net_vlan_list = array($vlan);
    foreach (array_keys($group_ck_list) as $grouped_ck) {
        $net_vlan_list[] = getVLANInfo($grouped_ck);
    }
    foreach ($net_vlan_list as $net_vlan) {
        foreach (array('ipv4net' => 'ipv4nets', 'ipv6net' => 'ipv6nets') as $realm => $key) {
            foreach ($net_vlan[$key] as $net_id) {
                $networks["{$realm}-{$net_id}"] = spotEntity($realm, $net_id);
            }
        }
    }
    if (0 == count($networks)) {
        startPortlet('no networks');
    } else {
        startPortlet('networks (' . count($networks) . ')');
        $order = 'odd';
        echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
        echo '<tr><th>';
        printImageHREF('net');
        echo '</th><th>';
        printImageHREF('text');
        echo '</th></tr>';
        foreach ($networks as $net) {
            echo '<tr><td>';
            renderCell($net);
            echo '</td><td>' . stringForTD($net['comment']);
            echo '</td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    $confports = getVLANConfiguredPorts($vlan_ck);
    foreach (array_keys($group_ck_list) as $grouped_ck) {
        $confports += getVLANConfiguredPorts($grouped_ck);
    }
    if ($vlan['domain_group_id']) {
        // we should find configured port on master's members
        // even if master domain itself does not have such VLAN
        $master_ck = $vlan['domain_group_id'] . '-' . $vlan['vlan_id'];
        if (!isset($group_ck_list[$master_ck])) {
            $confports += getVLANConfiguredPorts($master_ck);
        }
    }
    // get non-switch device list
    $foreign_devices = array();
    foreach ($confports as $switch_id => $portlist) {
        $object = spotEntity('object', $switch_id);
        foreach ($portlist as $port_name) {
            if ($portinfo = getPortinfoByName($object, $port_name)) {
                if ($portinfo['linked'] && !isset($confports[$portinfo['remote_object_id']])) {
                    $foreign_devices[$portinfo['remote_object_id']][] = $portinfo;
                }
            }
        }
    }
    if (!empty($foreign_devices)) {
        startPortlet("Non-switch devices");
        echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>";
        echo '<tr><th>device</th><th>ports</th></tr>';
        $order = 'odd';
        foreach ($foreign_devices as $cell_id => $ports) {
            echo "<tr class=row_{$order} valign=top><td>";
            $cell = spotEntity('object', $cell_id);
            renderCell($cell);
            echo "</td><td><ul>";
            foreach ($ports as $portinfo) {
                echo "<li>" . formatPortLink($portinfo['remote_object_id'], NULL, $portinfo['remote_id'], $portinfo['remote_name']) . ' &mdash; ' . formatPort($portinfo) . "</li>";
            }
            echo "</ul></td></tr>";
            $order = $nextorder[$order];
        }
        echo '</table>';
        finishPortlet();
    }
    echo '</td><td class=pcright>';
    if (!count($confports)) {
        startPortlet('no ports');
    } else {
        startPortlet('Switch ports (' . count($confports) . ')');
        global $nextorder;
        $order = 'odd';
        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
        echo '<tr><th>switch</th><th>ports</th></tr>';
        foreach ($confports as $switch_id => $portlist) {
            usort_portlist($portlist);
            echo "<tr class=row_{$order} valign=top><td>";
            $object = spotEntity('object', $switch_id);
            renderCell($object);
            echo '</td><td class=tdleft><ul>';
            foreach ($portlist as $port_name) {
                echo '<li>';
                if ($portinfo = getPortinfoByName($object, $port_name)) {
                    echo formatPortLink($object['id'], NULL, $portinfo['id'], $portinfo['name']);
                    if ($portinfo['linked']) {
                        echo ' &mdash; ' . formatPortLink($portinfo['remote_object_id'], $portinfo['remote_object_name'], $portinfo['remote_id'], NULL);
                    }
                } else {
                    echo $port_name;
                }
                echo '</li>';
            }
            echo '</ul></td></tr>';
            $order = $nextorder[$order];
        }
        echo '</table>';
    }
    finishPortlet();
    echo '</td></tr></table>';
}
Exemplo n.º 5
0
function renderPopupPortSelector()
{
    assertUIntArg('port');
    $port_id = $_REQUEST['port'];
    $port_info = getPortInfo($port_id);
    $in_rack = isCheckSet('in_rack');
    // fill port filter structure
    $filter = array('racks' => array(), 'objects' => '', 'ports' => '');
    if (isset($_REQUEST['filter-obj'])) {
        $filter['objects'] = trim($_REQUEST['filter-obj']);
    }
    if (isset($_REQUEST['filter-port'])) {
        $filter['ports'] = trim($_REQUEST['filter-port']);
    }
    if ($in_rack) {
        $object = spotEntity('object', $port_info['object_id']);
        if ($object['rack_id']) {
            $filter['racks'] = getProximateRacks($object['rack_id'], getConfigVar('PROXIMITY_RANGE'));
        }
    }
    $spare_ports = array();
    if (!empty($filter['racks']) || !empty($filter['objects']) || !empty($filter['ports'])) {
        $spare_ports = findSparePorts($port_info, $filter);
    }
    // display search form
    echo 'Link ' . formatPort($port_info) . ' to...';
    echo '<form method=GET>';
    startPortlet('Port list filter');
    echo '<input type=hidden name="module" value="popup">';
    echo '<input type=hidden name="helper" value="portlist">';
    echo '<input type=hidden name="port" value="' . $port_id . '">';
    echo '<table align="center" valign="bottom"><tr>';
    echo '<td class="tdleft"><label>Object name:<br><input type=text size=8 name="filter-obj" value="' . htmlspecialchars($filter['objects'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft"><label>Port name:<br><input type=text size=6 name="filter-port" value="' . htmlspecialchars($filter['ports'], ENT_QUOTES) . '"></label></td>';
    echo '<td class="tdleft" valign="bottom"><label><input type=checkbox name="in_rack"' . ($in_rack ? ' checked' : '') . '>Nearest racks</label></td>';
    echo '<td valign="bottom"><input type=submit value="show ports"></td>';
    echo '</tr></table>';
    finishPortlet();
    // display results
    startPortlet('Compatible spare ports');
    if (empty($spare_ports)) {
        echo '(nothing found)';
    } else {
        echo getSelect($spare_ports, array('name' => 'remote_port', 'size' => getConfigVar('MAXSELSIZE')), NULL, FALSE);
        echo "<p>Cable ID: <input type=text id=cable name=cable>";
        echo "<p><input type='submit' value='Link' name='do_link'>";
    }
    finishPortlet();
    echo '</form>';
}