Пример #1
0
function get_subnet_usage_html($subnet_id, $width = 30, $height = 8)
{
    global $conf, $self, $mysql, $onadb;
    list($usage, $used, $total) = get_subnet_usage($subnet_id);
    $css = '';
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') != false) {
        $css = "font-size: " . ($height - 2) . "px;";
    }
    return <<<EOL
    <div style="white-space: nowrap; width: 100%; text-align: left; padding-top: 2px; padding-bottom: 2px; vertical-align: middle; font-size: 8px;">
        <div title="{$usage}% used" style="{$css} float: left; width: {$width}px; height: {$height}px; text-align: left; vertical-align: middle; background-color: #ABFFBC; border: 1px solid #000;">
            <div style="{$css} width: {$usage}%; height: {$height}px; vertical-align: middle; background-color: #FF3939;"></div>
        </div>
        <span style="font-size: 8px;">&nbsp;{$used} / {$total}</span>
    </div>
EOL;
}
Пример #2
0
function subnet_display($options = "")
{
    global $conf, $self, $onadb;
    printmsg('DEBUG => subnet_display(' . $options . ') called', 3);
    $text_array = array();
    // Version - UPDATE on every edit!
    $version = '1.03';
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !$options['subnet']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        $self['error'] = 'ERROR => Insufficient parameters';
        return array(1, <<<EOM

subnet_display-v{$version}
Displays an subnet record from the database

  Synopsis: subnet_display [KEY=VALUE] ...

  Required:
    subnet=[ID|IP]               display subnet by search string

  Optional:
    verbose=[yes|no]              display additional info (yes)

  Notes:
    * An error is returned if search string returns more than one subnet
    * IP can be in dotted, numeric, or IPv6 format


EOM
);
    }
    // Sanitize "options[verbose]" (yes is the default)
    $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
    // They provided a subnet ID or IP address
    // Find a subnet record
    list($status, $rows, $subnet) = ona_find_subnet($options['subnet']);
    if ($status or !$rows) {
        $self['error'] = "ERROR => Subnet not found";
        return array(2, $self['error'] . "\n");
    }
    // Gather sizing
    list($percent, $total_used, $size) = get_subnet_usage($subnet['id']);
    $subnet['total_allocated_percent'] = $percent;
    $subnet['total_allocated'] = $total_used;
    $subnet['total_available'] = $size;
    // get subnet type name
    list($status, $rows, $sntype) = ona_get_subnet_type_record(array('id' => $subnet['subnet_type_id']));
    $subnet['subnet_type_name'] = $sntype['display_name'];
    // Convert some data
    $text_array = $subnet;
    $text_array['ip_addr_text'] = ip_mangle($subnet['ip_addr'], 'dotted');
    $text_array['ip_mask_text'] = ip_mangle($subnet['ip_mask'], 'dotted');
    $text_array['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
    // Build text to return
    $text = "SUBNET RECORD\n";
    $text .= format_array($subnet);
    // If 'verbose' is enabled, grab some additional info to display
    if ($options['verbose'] == 'Y') {
        // Tag records
        list($status, $rows, $tags) = db_get_records($onadb, 'tags', array('type' => 'subnet', 'reference' => $subnet['id']));
        if ($rows) {
            $text .= "\nASSOCIATED TAG RECORDS\n";
            foreach ($tags as $tag) {
                $text_array['tags'][] = $tag['name'];
                $text .= "  {$tag['name']}\n";
            }
        }
        // VLAN record
        list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $subnet['vlan_id']));
        if ($rows) {
            $text_array['vlan'] = $vlan;
            $text .= "\nASSOCIATED VLAN RECORD\n";
            $text .= format_array($vlan);
        }
    }
    // cleanup some un-used junk
    unset($text_array['network_role_id']);
    unset($text_array['vlan_id']);
    // change the output format if other than default
    if ($options['format'] == 'json') {
        $text = $text_array;
    }
    if ($options['format'] == 'yaml') {
        $text = $text_array;
    }
    // Return the success notice
    return array(0, $text);
}