Пример #1
0
function renderIPv6NetworkAddresses($netinfo)
{
    global $pageno, $tabno, $aac_left;
    echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center' width='100%'>\n";
    echo "<tr><th>Address</th><th>Name</th><th>Comment</th><th>Allocation</th></tr>\n";
    $hl_ip = NULL;
    if (isset($_REQUEST['hl_ip'])) {
        $hl_ip = ip6_parse($_REQUEST['hl_ip']);
        addAutoScrollScript('ip-' . ip6_format($hl_ip));
    }
    $addresses = $netinfo['addrlist'];
    ksort($addresses);
    markupIPAddrList($addresses);
    // pager
    $maxperpage = getConfigVar('IPV4_ADDRS_PER_PAGE');
    if (count($addresses) > $maxperpage && $maxperpage > 0) {
        $page = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : (isset($hl_ip) ? getPageNumOfIPv6($addresses, $hl_ip, $maxperpage) : 0);
        $numpages = ceil(count($addresses) / $maxperpage);
        echo "<center><h3>{$numpages} pages:</h3>";
        for ($i = 0; $i < $numpages; $i++) {
            if ($i == $page) {
                echo "<b>{$i}</b> ";
            } else {
                echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $i)) . "'>{$i}</a> ";
            }
        }
        echo "</center>";
    }
    $i = 0;
    $interruped = FALSE;
    $prev_ip = ip_prev($netinfo['ip_bin']);
    foreach ($addresses as $ip_bin => $addr) {
        if (isset($page)) {
            ++$i;
            if ($i <= $maxperpage * $page) {
                continue;
            } elseif ($i > $maxperpage * ($page + 1)) {
                $interruped = TRUE;
                break;
            }
        }
        if ($ip_bin != ip_next($prev_ip)) {
            renderSeparator(ip_next($prev_ip), ip_prev($ip_bin), $hl_ip);
        }
        $prev_ip = $ip_bin;
        // render IP change history
        $title = '';
        $history_class = '';
        if (isset($addr['last_log'])) {
            $title = ' title="' . htmlspecialchars($addr['last_log']['user'] . ', ' . formatAge($addr['last_log']['time']), ENT_QUOTES) . '"';
            $history_class = 'hover-history underline';
        }
        $tr_class = $addr['class'] . ' tdleft' . ($hl_ip === $ip_bin ? ' highlight' : '');
        echo "<tr class='{$tr_class}'>";
        echo "<td><a class='{$history_class}' {$title} name='ip-{$addr['ip']}' href='" . makeHref(array('page' => 'ipaddress', 'ip' => $addr['ip'])) . "'>{$addr['ip']}</a></td>";
        $editable = empty($addr['allocs']) || !empty($addr['name']) && permitted('ipaddress', 'properties', 'editAddress') ? 'editable' : '';
        echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-name'>{$addr['name']}</span></td>";
        echo "<td><span class='rsvtext {$editable} id-{$addr['ip']} op-upd-ip-comment'>{$addr['comment']}</span></td><td>";
        $delim = '';
        if ($addr['reserved'] == 'yes') {
            echo "<strong>RESERVED</strong> ";
            $delim = '; ';
        }
        foreach ($addr['allocs'] as $ref) {
            echo $delim . $aac_left[$ref['type']];
            echo makeIPAllocLink($ip_bin, $ref, TRUE);
            $delim = '; ';
        }
        if ($delim != '') {
            $delim = '<br>';
        }
        foreach ($addr['vslist'] as $vs_id) {
            $vs = spotEntity('ipv4vs', $vs_id);
            echo $delim . mkA("{$vs['name']}:{$vs['vport']}/{$vs['proto']}", 'ipv4vs', $vs['id']) . '&rarr;';
            $delim = '<br>';
        }
        foreach ($addr['vsglist'] as $vs_id) {
            $vs = spotEntity('ipvs', $vs_id);
            echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '&rarr;';
            $delim = '<br>';
        }
        foreach ($addr['rsplist'] as $rsp_id) {
            $rsp = spotEntity('ipv4rspool', $rsp_id);
            echo "{$delim}&rarr;" . mkA($rsp['name'], 'ipv4rspool', $rsp['id']);
            $delim = '<br>';
        }
        echo "</td></tr>\n";
    }
    if (!$interruped) {
        renderSeparator(ip_next($prev_ip), ip_last($netinfo), $hl_ip);
    }
    if (isset($page)) {
        // bottom pager
        echo "<tr><td colspan=3>";
        if ($page > 0) {
            echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page - 1)) . "'><< prev</a> ";
        }
        if ($page < $numpages - 1) {
            echo "<a href='" . makeHref(array('page' => $pageno, 'tab' => $tabno, 'id' => $netinfo['id'], 'pg' => $page + 1)) . "'>next >></a> ";
        }
        echo "</td></tr>";
    }
    echo "</table>";
    if (permitted(NULL, NULL, 'set_reserve_comment')) {
        addJS('js/inplace-edit.js');
    }
}
Пример #2
0
function fillIPNetsCorrelation(&$nets)
{
    $stack = array();
    foreach ($nets as &$net) {
        $last = NULL;
        // last element popped from the stack
        while (count($stack)) {
            $top =& $stack[count($stack) - 1];
            if (IPNetContains($top, $net)) {
                $top['kidc']++;
                break;
            }
            if (isset($last)) {
                // possible hole in the end of $top
                fillIPSpareListBstr($top, ip_next(ip_last($last)), ip_last($top));
            }
            $last = array_pop($stack);
        }
        if (count($stack)) {
            $top =& $stack[count($stack) - 1];
            if (isset($last)) {
                // possible hole in the middle of $top
                fillIPSpareListBstr($top, ip_next(ip_last($last)), ip_prev($net['ip_bin']));
            } else {
                // possible hole in the beginning of $top
                fillIPSpareListBstr($top, $top['ip_bin'], ip_prev($net['ip_bin']));
            }
        }
        $stack[] =& $net;
    }
    // final stack spin
    $last = NULL;
    while (count($stack)) {
        $top =& $stack[count($stack) - 1];
        if (isset($last)) {
            // possible hole in the end of $top
            fillIPSpareListBstr($top, ip_next(ip_last($last)), ip_last($top));
        }
        $last = array_pop($stack);
    }
}