Ejemplo n.º 1
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>';
}
Ejemplo n.º 2
0
function renderSearchResults($terms, $summary)
{
    // calculate the number of found objects
    $nhits = 0;
    foreach ($summary as $realm => $list) {
        $nhits += count($list);
    }
    if ($nhits == 0) {
        echo "<center><h2>Nothing found for '{$terms}'</h2></center>";
        return;
    } elseif ($nhits == 1) {
        foreach ($summary as $realm => $record) {
            if (is_array($record)) {
                $record = array_shift($record);
            }
            break;
        }
        $url = buildSearchRedirectURL($realm, $record);
        if (isset($url)) {
            redirectUser($url);
        }
    }
    global $nextorder;
    $order = 'odd';
    echo "<center><h2>{$nhits} result(s) found for '{$terms}'</h2></center>";
    foreach ($summary as $where => $what) {
        switch ($where) {
            case 'object':
                startPortlet("<a href='index.php?page=depot'>Objects</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                echo '<tr><th>what</th><th>why</th></tr>';
                foreach ($what as $obj) {
                    echo "<tr class=row_{$order} valign=top><td>";
                    $object = spotEntity('object', $obj['id']);
                    renderCell($object);
                    echo "</td><td class=tdleft>";
                    if (isset($obj['by_attr'])) {
                        // only explain non-obvious reasons for listing
                        echo '<ul>';
                        foreach ($obj['by_attr'] as $attr_name) {
                            if ($attr_name != 'name') {
                                echo "<li>{$attr_name} matched</li>";
                            }
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_sticker'])) {
                        echo '<table>';
                        $aval = getAttrValues($obj['id']);
                        foreach ($obj['by_sticker'] as $attr_id) {
                            $record = $aval[$attr_id];
                            echo "<tr><th width='50%' class=sticker>{$record['name']}:</th>";
                            echo "<td class=sticker>" . formatAttributeValue($record) . "</td></tr>";
                        }
                        echo '</table>';
                    }
                    if (isset($obj['by_port'])) {
                        echo '<table>';
                        amplifyCell($object);
                        foreach ($obj['by_port'] as $port_id => $text) {
                            foreach ($object['ports'] as $port) {
                                if ($port['id'] == $port_id) {
                                    $port_href = '<a href="' . makeHref(array('page' => 'object', 'object_id' => $object['id'], 'hl_port_id' => $port_id)) . '">port ' . $port['name'] . '</a>';
                                    echo "<tr><td>{$port_href}:</td>";
                                    echo "<td class=tdleft>{$text}</td></tr>";
                                    break;
                                    // next reason
                                }
                            }
                        }
                        echo '</table>';
                    }
                    if (isset($obj['by_iface'])) {
                        echo '<ul>';
                        foreach ($obj['by_iface'] as $ifname) {
                            echo "<li>interface {$ifname}</li>";
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_nat'])) {
                        echo '<ul>';
                        foreach ($obj['by_nat'] as $comment) {
                            echo "<li>NAT rule: {$comment}</li>";
                        }
                        echo '</ul>';
                    }
                    if (isset($obj['by_cableid'])) {
                        echo '<ul>';
                        foreach ($obj['by_cableid'] as $cableid) {
                            echo "<li>link cable ID: {$cableid}</li>";
                        }
                        echo '</ul>';
                    }
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4net':
            case 'ipv6net':
                if ($where == 'ipv4net') {
                    startPortlet("<a href='index.php?page=ipv4space'>IPv4 networks</a>");
                } elseif ($where == 'ipv6net') {
                    startPortlet("<a href='index.php?page=ipv6space'>IPv6 networks</a>");
                }
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order} valign=top><td>";
                    renderCell($cell);
                    echo "</td></tr>\n";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4addressbydescr':
            case 'ipv6addressbydescr':
                if ($where == 'ipv4addressbydescr') {
                    startPortlet('IPv4 addresses');
                } elseif ($where == 'ipv6addressbydescr') {
                    startPortlet('IPv6 addresses');
                }
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                // FIXME: address, parent network, routers (if extended view is enabled)
                echo '<tr><th>Address</th><th>Description</th><th>Comment</th></tr>';
                foreach ($what as $addr) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    $fmt = ip_format($addr['ip']);
                    $parentnet = getIPAddressNetworkId($addr['ip']);
                    if ($parentnet !== NULL) {
                        echo "<a href='" . makeHref(array('page' => strlen($addr['ip']) == 16 ? 'ipv6net' : 'ipv4net', 'id' => $parentnet, 'tab' => 'default', 'hl_ip' => $fmt)) . "'>{$fmt}</a></td>";
                    } else {
                        echo "<a href='index.php?page=ipaddress&tab=default&ip={$fmt}'>{$fmt}</a></td>";
                    }
                    echo "<td class=tdleft>{$addr['name']}</td><td>{$addr['comment']}</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4rspool':
                startPortlet("<a href='index.php?page=ipv4slb&tab=rspools'>RS pools</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipvs':
                startPortlet("<a href='index.php?page=ipv4slb&tab=vs'>VS groups</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'ipv4vs':
                startPortlet("<a href='index.php?page=ipv4slb&tab=default'>Virtual services</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'user':
                startPortlet("<a href='index.php?page=userlist'>Users</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $item) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($item);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'file':
                startPortlet("<a href='index.php?page=files'>Files</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'rack':
                startPortlet("<a href='index.php?page=rackspace'>Racks</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'row':
                startPortlet("<a href='index.php?page=rackspace'>Rack rows</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    echo mkCellA($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'location':
                startPortlet("<a href='index.php?page=rackspace'>Locations</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $cell) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    renderCell($cell);
                    echo "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            case 'vlan':
                startPortlet("<a href='index.php?page=8021q'>VLANs</a>");
                echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                foreach ($what as $vlan) {
                    echo "<tr class=row_{$order}><td class=tdleft>";
                    echo formatVLANAsHyperlink(getVlanRow($vlan['id'])) . "</td></tr>";
                    $order = $nextorder[$order];
                }
                echo '</table>';
                finishPortlet();
                break;
            default:
                // you can use that in your plugins to add some non-standard search results
                startPortlet($where);
                echo $what;
                finishPortlet();
        }
    }
}