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']) . '→'; $delim = '<br>'; } foreach ($addr['vsglist'] as $vs_id) { $vs = spotEntity('ipvs', $vs_id); echo $delim . mkA($vs['name'], 'ipvs', $vs['id']) . '→'; $delim = '<br>'; } foreach ($addr['rsplist'] as $rsp_id) { $rsp = spotEntity('ipv4rspool', $rsp_id); echo "{$delim}→" . 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'); } }
function getRenderedIPv6NetCapacity($range) { $div_id = $range['ip'] . '/' . $range['mask']; $class = 'net-usage'; if (isset($range['addrlist'])) { $used = markupIPAddrList($range['addrlist']); } else { $used = NULL; $class .= ' pending'; addJS('js/net-usage.js'); } static $prefixes = array(0 => '', 3 => 'k', 6 => 'M', 9 => 'G', 12 => 'T', 15 => 'P', 18 => 'E', 21 => 'Z', 24 => 'Y'); if ($range['mask'] <= 64) { $what = 'net'; $preposition = 'in'; $range['mask'] += 64; } else { $what = 'IP'; $preposition = 'of'; } $what .= 0 == $range['mask'] % 64 ? '' : 's'; $addrc = isset($used) ? "{$used} {$preposition} " : ''; $dec_order = intval((128 - $range['mask']) / 10) * 3; $mult = isset($prefixes[$dec_order]) ? $prefixes[$dec_order] : '??'; $cnt = 1 << (128 - $range['mask']) % 10; if ($cnt == 1 && $mult == '') { $cnt = '1'; } return "<div class=\"{$class}\" id=\"{$div_id}\">" . "{$addrc}{$cnt}{$mult} {$what}" . "</div>"; }
function getIPAddress($ip_bin) { $scanres = scanIPSpace(array(array('first' => $ip_bin, 'last' => $ip_bin))); if (empty($scanres)) { return constructIPAddress($ip_bin); } markupIPAddrList($scanres); return $scanres[$ip_bin]; }