Ejemplo n.º 1
0
 function printNewItemTR()
 {
     $all_vswitches = getVLANSwitches();
     global $pageno;
     $hintcodes = array('prev_vdid' => 'DEFAULT_VDOM_ID', 'prev_vstid' => 'DEFAULT_VST_ID', 'prev_objid' => NULL);
     $focus = array();
     foreach ($hintcodes as $hint_code => $option_name) {
         if (array_key_exists($hint_code, $_REQUEST)) {
             assertUIntArg($hint_code);
             $focus[$hint_code] = $_REQUEST[$hint_code];
         } elseif ($option_name != NULL) {
             $focus[$hint_code] = getConfigVar($option_name);
         } else {
             $focus[$hint_code] = NULL;
         }
     }
     printOpFormIntro('add');
     echo '<tr>';
     if ($pageno != 'object') {
         echo '<td>';
         // hide any object that is already in the table
         $options = array();
         foreach (getNarrowObjectList('VLANSWITCH_LISTSRC') as $object_id => $object_dname) {
             if (!in_array($object_id, $all_vswitches)) {
                 $ctx = getContext();
                 spreadContext(spotEntity('object', $object_id));
                 $decision = permitted(NULL, NULL, 'del');
                 restoreContext($ctx);
                 if ($decision) {
                     $options[$object_id] = $object_dname;
                 }
             }
         }
         printSelect($options, array('name' => 'object_id', 'tabindex' => 101, 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_objid']);
         echo '</td>';
     }
     if ($pageno != 'vlandomain') {
         echo '<td>' . getSelect(getVLANDomainOptions(), array('name' => 'vdom_id', 'tabindex' => 102, 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_vdid']) . '</td>';
     }
     if ($pageno != 'vst') {
         $options = array();
         foreach (listCells('vst') as $nominee) {
             $ctx = getContext();
             spreadContext($nominee);
             $decision = permitted(NULL, NULL, 'add');
             restoreContext($ctx);
             if ($decision) {
                 $options[$nominee['id']] = niftyString($nominee['description'], 30, FALSE);
             }
         }
         echo '<td>' . getSelect($options, array('name' => 'vst_id', 'tabindex' => 103, 'size' => getConfigVar('MAXSELSIZE')), $focus['prev_vstid']) . '</td>';
     }
     echo '<td>' . getImageHREF('Attach', 'set', TRUE, 104) . '</td></tr></form>';
 }
Ejemplo n.º 2
0
function trigger_ipv6net_vlanconfig()
{
    if (!count(getVLANDomainOptions())) {
        // no domains -- no VLANs to bind with
        return '';
    }
    $netinfo = spotEntity('ipv6net', $_REQUEST['id']);
    if ($netinfo['vlanc']) {
        return 'std';
    } elseif (considerConfiguredConstraint($netinfo, 'VLANIPV4NET_LISTSRC')) {
        return 'attn';
    } else {
        return '';
    }
}
Ejemplo n.º 3
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>';
}
function render8021QReport()
{
    if (!count($domains = getVLANDomainOptions())) {
        echo '<center><h3>(no VLAN configuration exists)</h3></center>';
        return;
    }
    $vlanstats = array();
    for ($i = VLAN_MIN_ID; $i <= VLAN_MAX_ID; $i++) {
        $vlanstats[$i] = array();
    }
    $header = '<tr><th>&nbsp;</th>';
    foreach ($domains as $domain_id => $domain_name) {
        foreach (getDomainVLANList($domain_id) as $vlan_id => $vlan_info) {
            $vlanstats[$vlan_id][$domain_id] = $vlan_info;
        }
        $header .= '<th>' . mkA($domain_name, 'vlandomain', $domain_id) . '</th>';
    }
    $header .= '</tr>';
    $output = $available = array();
    for ($i = VLAN_MIN_ID; $i <= VLAN_MAX_ID; $i++) {
        if (!count($vlanstats[$i])) {
            $available[] = $i;
        } else {
            $output[$i] = FALSE;
        }
    }
    foreach (listToRanges($available) as $span) {
        if ($span['to'] - $span['from'] < 4) {
            for ($i = $span['from']; $i <= $span['to']; $i++) {
                $output[$i] = FALSE;
            }
        } else {
            $output[$span['from']] = TRUE;
            $output[$span['to']] = FALSE;
        }
    }
    ksort($output, SORT_NUMERIC);
    $header_delay = 0;
    startPortlet('VLAN existence per domain');
    echo '<table border=1 cellspacing=0 cellpadding=5 align=center class=rackspace>';
    foreach ($output as $vlan_id => $tbc) {
        if (--$header_delay <= 0) {
            echo $header;
            $header_delay = 25;
        }
        echo '<tr class="state_' . (count($vlanstats[$vlan_id]) ? 'T' : 'F');
        echo '"><th class=tdright>' . $vlan_id . '</th>';
        foreach (array_keys($domains) as $domain_id) {
            echo '<td class=tdcenter>';
            if (array_key_exists($domain_id, $vlanstats[$vlan_id])) {
                echo mkA('&exist;', 'vlan', "{$domain_id}-{$vlan_id}");
            } else {
                echo '&nbsp;';
            }
            echo '</td>';
        }
        echo '</tr>';
        if ($tbc) {
            echo '<tr class="state_A"><th>...</th><td colspan=' . count($domains) . '>&nbsp;</td></tr>';
        }
    }
    echo '</table>';
    finishPortlet();
}