Exemple #1
0
function renderCell($cell)
{
    switch ($cell['realm']) {
        case 'user':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('USER');
            echo '</td><td>' . mkA($cell['user_name'], 'user', $cell['user_id']) . '</td></tr>';
            if (strlen($cell['user_realname'])) {
                echo "<tr><td><strong>" . niftyString($cell['user_realname']) . "</strong></td></tr>";
            } else {
                echo "<tr><td class=sparenetwork>no name</td></tr>";
            }
            echo '<td>';
            if (!isset($cell['etags'])) {
                $cell['etags'] = getExplicitTagsOnly(loadEntityTags('user', $cell['user_id']));
            }
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'file':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            switch ($cell['type']) {
                case 'text/plain':
                    printImageHREF('text file');
                    break;
                case 'image/jpeg':
                case 'image/png':
                case 'image/gif':
                    printImageHREF('image file');
                    break;
                default:
                    printImageHREF('empty file');
                    break;
            }
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'file', $cell['id']);
            echo "</td><td rowspan=3 valign=top>";
            if (isset($cell['links']) and count($cell['links'])) {
                printf("<small>%s</small>", serializeFileLinks($cell['links']));
            }
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo '</td></tr><tr><td>';
            if (isolatedPermission('file', 'download', $cell)) {
                // FIXME: reuse renderFileDownloader()
                echo "<a href='?module=download&file_id={$cell['id']}'>";
                printImageHREF('download', 'Download file');
                echo '</a>&nbsp;';
            }
            echo formatFileSize($cell['size']);
            echo "</td></tr></table>";
            break;
        case 'ipv4vs':
        case 'ipvs':
        case 'ipv4rspool':
            renderSLBEntityCell($cell);
            break;
        case 'ipv4net':
        case 'ipv6net':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('NET');
            echo '</td><td>' . mkA("{$cell['ip']}/{$cell['mask']}", $cell['realm'], $cell['id']);
            echo getRenderedIPNetCapacity($cell);
            echo '</td></tr>';
            echo "<tr><td>";
            if (strlen($cell['name'])) {
                echo "<strong>" . niftyString($cell['name']) . "</strong>";
            } else {
                echo "<span class=sparenetwork>no name</span>";
            }
            // render VLAN
            renderNetVLAN($cell);
            echo "</td></tr>";
            echo '<tr><td>';
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'rack':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            $thumbwidth = getRackImageWidth();
            $thumbheight = getRackImageHeight($cell['height']);
            echo "<img border=0 width={$thumbwidth} height={$thumbheight} title='{$cell['height']} units' ";
            echo "src='?module=image&img=minirack&rack_id={$cell['id']}'>";
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'rack', $cell['id']);
            echo "</td></tr><tr><td>";
            echo niftyString($cell['comment']);
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'location':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('LOCATION');
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'location', $cell['id']);
            echo "</td></tr><tr><td>";
            echo niftyString($cell['comment']);
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'object':
            echo "<table class='slbcell vscell'><tr><td rowspan=2 width='5%'>";
            printImageHREF('OBJECT');
            echo '</td><td>';
            echo mkA('<strong>' . niftyString($cell['dname']) . '</strong>', 'object', $cell['id']);
            echo '</td></tr><tr><td>';
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        default:
            throw new InvalidArgException('realm', $cell['realm']);
    }
}
function getNetUsageAJAX()
{
    assertStringArg('net_id');
    list($ip, $mask) = explode('/', $_REQUEST['net_id']);
    $ip_bin = ip_parse($ip);
    $net = spotNetworkByIP($ip_bin, $mask + 1);
    if (!isset($net) or $net['mask'] != $mask) {
        $net = constructIPRange($ip_bin, $mask);
    }
    loadIPAddrList($net);
    echo getRenderedIPNetCapacity($net);
}
function renderNetCellForAlloc($cell, $needed_mask = NULL)
{
    if (empty($cell['spare_ranges']) and $cell['kidc'] == 0 and $cell['mask'] < 31) {
        $cell['spare_ranges'][$cell['mask'] + 1][] = $cell['ip_bin'];
        $cell['spare_ranges'][$cell['mask'] + 1][] = ip_last($cell) & ip4_mask($cell['mask'] + 1);
    }
    $ranges = array_keys($cell['spare_ranges']);
    sort($ranges, SORT_NUMERIC);
    foreach ($ranges as &$range) {
        $suffix = count($cell['spare_ranges'][$range]) <= 1 ? '' : '<small> x ' . count($cell['spare_ranges'][$range]) . '</small>';
        $range = '<a href="' . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => ip_format($cell['spare_ranges'][$range][0]) . '/' . $range)) . '">/' . $range . '</a>' . $suffix;
    }
    $spare_cidr = NULL;
    if (isset($needed_mask)) {
        for ($i = $needed_mask; $i > 0; $i--) {
            if (!empty($cell['spare_ranges'][$i])) {
                $spare_cidr = ip_format($cell['spare_ranges'][$i][0]) . '/' . $needed_mask;
                break;
            }
        }
    }
    echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
    printImageHREF('NET');
    echo '</td>';
    echo "<td><a href='index.php?page={$cell['realm']}&id={$cell['id']}'>{$cell['ip']}/{$cell['mask']}</a>";
    echo getRenderedIPNetCapacity($cell);
    echo '</td></tr>';
    echo "<tr><td>";
    if (strlen($cell['name'])) {
        echo "<strong>" . niftyString($cell['name']) . "</strong>";
    } else {
        echo "<span class=sparenetwork>no name</span>";
    }
    // render VLAN
    echo '<div class="vlan">' . implode(', ', $ranges) . '</div>';
    renderNetVLAN($cell);
    echo "</td></tr>";
    echo '<tr><td>';
    echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
    if (isset($spare_cidr)) {
        echo "<div class='vlan'><a href=\"" . makeHref(array('page' => 'ipv4space', 'tab' => 'newrange', 'set-prefix' => $spare_cidr)) . "\">Allocate /{$needed_mask}</a></div>";
    }
    echo "</td></tr></table>";
}