コード例 #1
0
function getRenderedIPv4NetCapacity($range)
{
    $class = 'net-usage';
    if (isset($range['addrc'])) {
        // full mode
        // $a is "aquamarine zone", $b is "gray zone"
        $total = ip4_range_size($range);
        // compute $a_total: own range size, without subranges
        if (!isset($range['kidc']) or $range['kidc'] == 0) {
            $a_total = $total;
        } else {
            $a_total = 0;
            foreach ($range['spare_ranges'] as $mask => $spare_list) {
                $a_total = bcadd($a_total, bcmul(count($spare_list), ip4_mask_size($mask)), 0);
            }
        }
        $a_used = $range['own_addrc'];
        $b_total = bcsub($total, $a_total, 0);
        $b_used = $range['addrc'] - $a_used;
        // generate link to progress bar image
        $width = 100;
        if ($total != 0) {
            $px_a = round(bcdiv($a_total, $total, 4) * $width);
            $px1 = round(bcdiv($a_used, $total, 4) * $width);
            $px2 = $px_a - $px1;
            $px3 = round(bcdiv($b_used, $total, 4) * $width);
            if ($px3 + $px1 + $px2 > $width) {
                $px3 = $width - $px1 - $px2;
            }
        } else {
            $px1 = $px2 = $px3 = 0;
        }
        $title_items = array();
        $title2_items = array();
        if ($a_total != 0) {
            $title_items[] = "{$a_used} / {$a_total}";
            $title2_items[] = sprintf("%d%% used", bcdiv($a_used, $a_total, 4) * 100);
        }
        if ($b_total != 0) {
            $title_items[] = ($b_used ? "{$b_used} / " : "") . $b_total;
            $title2_items[] = sprintf("%d%% sub-allocated", bcdiv($b_total, $total, 4) * 100);
        }
        $title = implode(', ', $title_items);
        $title2 = implode(', ', $title2_items);
        $text = "<img width='{$width}' height=10 border=0 title='{$title2}' src='?module=progressbar4&px1={$px1}&px2={$px2}&px3={$px3}'>" . " <small class='title'>{$title}</small>";
    } else {
        // fast mode
        $class .= ' pending';
        addJS('js/net-usage.js');
        $free_text = '';
        if (isset($range['kidc']) and $range['kidc'] > 0) {
            $free_masks = array_keys($range['spare_ranges']);
            sort($free_masks, SORT_NUMERIC);
            if ($mask = array_shift($free_masks)) {
                $cnt = count($range['spare_ranges'][$mask]);
                $free_text = ', ' . ($cnt > 1 ? "<small>{$cnt}x</small>" : "") . "/{$mask} free";
            }
        }
        $text = ip4_range_size($range) . $free_text;
    }
    $div_id = $range['ip'] . '/' . $range['mask'];
    return "<div class=\"{$class}\" id=\"{$div_id}\">" . $text . "</div>";
}
コード例 #2
0
ファイル: functions.php プロジェクト: rhysm/racktables
function getIPv4OwnRangeSize($range)
{
    if (empty($range['spare_ranges'])) {
        return ip4_range_size($range);
    } else {
        $ret = 0;
        foreach ($range['spare_ranges'] as $mask => $spare_list) {
            $ret += count($spare_list) * ip4_mask_size($mask);
        }
        return $ret;
    }
}