function generate_device_popup_header($device, $vars = array())
{
    global $config;
    humanize_device($device);
    if ($device['os'] == "ios") {
        formatCiscoHardware($device, TRUE);
    }
    // FIXME or generic function for more than just IOS? [and/or do this at poll time]
    $contents = '
<table class="table table-striped table-bordered table-rounded table-condensed">
  <tr class="' . $device['html_row_class'] . '" style="font-size: 10pt;">
    <td class="state-marker"></td>
    <td width="40" style="padding: 10px; text-align: center; vertical-align: middle;">' . get_device_icon($device) . '</td>
    <td width="200"><a href="#" class="' . $class . '" style="font-size: 15px; font-weight: bold;">' . escape_html($device['hostname']) . '</a><br />' . escape_html(truncate($device['location'], 64, '')) . '</td>
    <td>' . escape_html($device['hardware']) . ' <br /> ' . $device['os_text'] . ' ' . escape_html($device['version']) . '</td>
    <td>' . deviceUptime($device, 'short') . '<br />' . escape_html($device['sysName']) . '
  </tr>
</table>
';
    return $contents;
}
function print_device_hostbox($device, $mode = 'basic')
{
    global $config;
    if (!is_array($device)) {
        print_error("Invalid device passed to print_device_hostbox()!");
    }
    if ($device['os'] == "ios") {
        formatCiscoHardware($device, TRUE);
    }
    humanize_device($device);
    $hostbox_tags = array('html_row_class' => $device['html_row_class'], 'device_id' => $device['device_id'], 'device_link' => generate_device_link($device), 'hardware' => escape_html($device['hardware']), 'features' => escape_html($device['features']), 'os_text' => $device['os_text'], 'version' => escape_html($device['version']), 'sysName' => escape_html($device['sysName']), 'device_uptime' => deviceUptime($device, 'short'), 'location' => escape_html(truncate($device['location'], 32, '')));
    switch ($mode) {
        case 'detail':
        case 'details':
            $hostbox_tags['device_image'] = get_device_icon($device);
            $hostbox_tags['ports_count'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?;", array($device['device_id']));
            $hostbox_tags['sensors_count'] = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?;", array($device['device_id']));
            $hostbox = '
  <tr class="' . $hostbox_tags['html_row_class'] . '" onclick="location.href=\'device/device=' . $hostbox_tags['device_id'] . '/\'" style="cursor: pointer;">
    <td class="state-marker"></td>
    <td style="width: 64px; text-align: center; vertical-align: middle;">' . $hostbox_tags['device_image'] . '</td>
    <td style="width: 300px;"><span class="entity-title">' . $hostbox_tags['device_link'] . '</span><br />' . $hostbox_tags['location'] . '</td>
    <td style="width: 55px;">';
            if ($hostbox_tags['ports_count']) {
                $hostbox .= '<i class="oicon-network-ethernet"></i> ' . $hostbox_tags['ports_count'];
            }
            $hostbox .= '<br />';
            if ($hostbox_tags['sensors_count']) {
                $hostbox .= '<i class="oicon-dashboard"></i> ' . $hostbox_tags['sensors_count'];
            }
            $hostbox .= '</td>
    <td>' . $hostbox_tags['hardware'] . '<br />' . $hostbox_tags['features'] . '</td>
    <td>' . $hostbox_tags['os_text'] . '<br />' . $hostbox_tags['version'] . '</td>
    <td>' . $hostbox_tags['device_uptime'] . '<br />' . $hostbox_tags['sysName'] . '</td>
  </tr>';
            break;
        case 'status':
            $hostbox_tags['device_image'] = get_device_icon($device);
            // Graphs
            $graph_array = array();
            $graph_array['height'] = "100";
            $graph_array['width'] = "310";
            $graph_array['to'] = $config['time']['now'];
            $graph_array['device'] = $device['device_id'];
            $graph_array['type'] = "device_bits";
            $graph_array['from'] = $config['time']['day'];
            $graph_array['legend'] = "no";
            $graph_array['height'] = "45";
            $graph_array['width'] = "175";
            $graph_array['bg'] = "FFFFFF00";
            if (isset($config['os'][$device['os']]['over'])) {
                $graphs = $config['os'][$device['os']]['over'];
            } else {
                if (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) {
                    $graphs = $config['os'][$device['os_group']]['over'];
                } else {
                    $graphs = $config['os']['default']['over'];
                }
            }
            // Preprocess device graphs array
            foreach ($GLOBALS['device_graphs'][$device['device_id']] as $graph) {
                $graphs_enabled[] = $graph['graph'];
            }
            foreach ($graphs as $entry) {
                if ($entry['graph'] && in_array(str_replace('device_', '', $entry['graph']), $graphs_enabled)) {
                    $graph_array['type'] = $entry['graph'];
                    $graph_array['popup_title'] = $entry['text'];
                    $hostbox_tags['graphs'][] = generate_graph_popup($graph_array);
                }
            }
            $hostbox = '
  <tr class="' . $hostbox_tags['html_row_class'] . '" onclick="location.href=\'device/device=' . $hostbox_tags['device_id'] . '/\'" style="cursor: pointer;">
    <td class="state-marker"></td>
    <td style="width: 64px; text-align: center; vertical-align: middle;">' . $hostbox_tags['device_image'] . '</td>
    <td style="width: 300px;"><span class="entity-title">' . $hostbox_tags['device_link'] . '</span><br />' . $hostbox_tags['location'] . '</td>
    <td>';
            if ($hostbox_tags['graphs']) {
                $hostbox .= '<div class="pull-right" style="height: 50px; padding: 2px; margin: 0;">' . implode($hostbox_tags['graphs']) . '</div>';
            }
            $hostbox .= '</td>
  </tr>';
            break;
        default:
            // basic
            $hostbox = '
  <tr class="' . $hostbox_tags['html_row_class'] . '" onclick="location.href=\'device/device=' . $hostbox_tags['device_id'] . '/\'" style="cursor: pointer;">
    <td style="width: 300;"><span class="entity-title">' . $hostbox_tags['device_link'] . '</span><br />' . $hostbox_tags['location'] . '</td>
    <td>' . $hostbox_tags['hardware'] . ' ' . $hostbox_tags['features'] . '</td>
    <td>' . $hostbox_tags['os_text'] . ' ' . $hostbox_tags['version'] . '</td>
    <td>' . $hostbox_tags['device_uptime'] . '</td>
  </tr>';
    }
    echo $hostbox;
}
}
?>

<h3>设备图标</h3>

<table cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <form id="edit" name="edit" method="post" action="">
        <input type="hidden" name="editing" value="yes">
        <table border="0">
<?php 
$numicons = 1;
echo "          <tr>\n";
// Default icon
$icon = get_device_icon($device, TRUE);
echo '            <td width="64" align="center"><img src="images/os/' . $icon . '.png"><br /><i>' . nicecase($icon) . '</i><p />';
echo '<input name="icon" type="radio" value="' . $icon . '"' . ($device['icon'] == '' || $device['icon'] == $icon ? ' checked="1"' : '') . ' /></td>' . "\n";
foreach ($config['os'][$device['os']]['icons'] as $icon_new) {
    if ($icon_new != $icon) {
        echo '            <td align="center"><img src="images/os/' . $icon_new . '.png"><br /><i>' . ucwords(strtr($icon_new, '_', ' ')) . '</i><p />';
        echo '<input name="icon" type="radio" value="' . $icon_new . '"' . ($device['icon'] == $icon ? ' checked="1"' : '') . ' /></td>' . "\n";
        $numicons++;
    }
}
if ($numicons % 10 == 0) {
    echo "          </tr>\n";
    echo "          <tr>\n";
}
?>
          </tr>
 /**
  * @dataProvider providerGetDeviceIcon
  * @group device
  */
 public function testGetDeviceIcon($device, $base_icon, $result)
 {
     $GLOBALS['config']['base_url'] = 'http://localhost';
     $this->assertSame($result, get_device_icon($device, $base_icon));
 }
示例#5
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage search
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
/// SEARCH DEVICES
$results = dbFetchRows("SELECT * FROM `devices`\n                        WHERE (`hostname` LIKE ? OR `location` LIKE ?) {$query_permitted_device}\n                        ORDER BY `hostname` LIMIT {$query_limit}", array($query_param, $query_param));
if (count($results)) {
    foreach ($results as $result) {
        humanize_device($result);
        $name = $result['hostname'];
        if (strlen($name) > 35) {
            $name = substr($name, 0, 35) . "...";
        }
        $num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id']));
        $device_search_results[] = array('url' => generate_device_url($result), 'name' => $name, 'colour' => $result['html_tab_colour'], 'icon' => get_device_icon($result), 'data' => array(escape_html($result['hardware'] . ' | ' . $config['os'][$result['os']]['text'] . ' ' . $result['version']), highlight_search(escape_html($result['location'])) . ' | ' . $num_ports . ' ports'));
    }
    $search_results['devices'] = array('descr' => 'Devices found', 'results' => $device_search_results);
}
// EOF
        $query_permitted_device = generate_query_permitted(array('device'), array('device_table' => 'devices'));
        $results = dbFetchRows("SELECT * FROM `devices`\n                            WHERE (`hostname` LIKE ? OR `location` LIKE ?) {$query_permitted_device}\n                            ORDER BY `hostname` LIMIT {$query_limit}", array($query_param, $query_param));
        if (count($results)) {
            $found = 1;
            echo '<li class="nav-header">Devices found: ' . count($results) . '</li>' . PHP_EOL;
            foreach ($results as $result) {
                echo '<li class="divider" style="margin: 0px;"></li>' . PHP_EOL;
                echo '<li style="margin: 0px;">' . PHP_EOL . '  <a href="' . generate_device_url($result) . '">' . PHP_EOL;
                humanize_device($result);
                $name = $result['hostname'];
                if (strlen($name) > 35) {
                    $name = substr($name, 0, 35) . "...";
                }
                $num_ports = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE device_id = ?", array($result['device_id']));
                echo '    <dl style="border-left: 10px solid ' . $result['html_tab_colour'] . '; " class="dl-horizontal dl-search">
      <dt style="padding-left: 10px; text-align: center;">' . get_device_icon($result) . '</dt>
        <dd>
          <strong>' . highlight_search(htmlentities($name)) . '
            <small>' . htmlentities($result['hardware']) . ' | ' . htmlentities($config['os'][$result['os']]['text']) . ' ' . htmlentities($result['version']) . '
            <br /> ' . highlight_search(htmlentities($result['location'], 0, 'UTF-8')) . ' | ' . $num_ports . ' ports</small>
          </strong>
        </dd>
    </dl>
  </a>
</li>' . PHP_EOL;
            }
        }
        /// SEARCH PORTS
        $query_permitted_port = generate_query_permitted(array('port'));
        $results = dbFetchRows("SELECT * FROM `ports`\n                            LEFT JOIN `devices` ON `ports`.`device_id` = `devices`.`device_id`\n                            WHERE (`ifAlias` LIKE ? OR `ifDescr` LIKE ?) {$query_permitted_port}\n                            ORDER BY `ifDescr` LIMIT {$query_limit}", array($query_param, $query_param));
        if (count($results)) {