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;
}
Пример #2
0
// Is there a POST/GET query string?
if (isset($_REQUEST['queryString'])) {
    $queryString = mres($_REQUEST['queryString']);
    // Is the string length greater than 0?
    if (strlen($queryString) > 0) {
        $found = 0;
        /// SEARCH DEVICES
        $query_permitted_device = generate_query_permitted(array('device'), array('device_table' => 'devices'));
        $results = dbFetchRows("SELECT * FROM `devices`\n                            WHERE (`hostname` LIKE '%{$queryString}%' OR `location` LIKE '%{$queryString}%') {$query_permitted_device}\n                            ORDER BY `hostname` LIMIT 8");
        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;">' . getImage($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>
<?php

humanize_device($device);
/// These should be summed at poller time
$port_count = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?", array($device['device_id']));
$sensor_count = dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?", array($device['device_id']));
echo '  <tr class="' . $device['html_row_class'] . '" onclick="location.href=\'device/device=' . $device['device_id'] . '/\'" style="cursor: pointer;">
          <td style="width: 1px; background-color: ' . $device['html_tab_colour'] . '; margin: 0px; padding: 0px"></td>
          <td width="40"  style="padding: 10px; text-align: center; vertical-align: middle;">' . $device['icon'] . '</td>
          <td width="300" ><span class="entity-title">' . generate_device_link($device) . '</span>
          <br />' . truncate($device['location'], 32, '') . '</td>';
echo '<td>';
if (isset($config['os'][$device['os']]['over'])) {
    $graphs = $config['os'][$device['os']]['over'];
} elseif (isset($device['os_group']) && isset($config['os'][$device['os_group']]['over'])) {
    $graphs = $config['os'][$device['os_group']]['over'];
} else {
    $graphs = $config['os']['default']['over'];
}
$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";
foreach ($graphs as $entry) {
Пример #4
0
function device_by_id_cache($device_id, $refresh = '0')
{
    global $cache;
    if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
        $device = $cache['devices']['id'][$device_id];
    } else {
        $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
        humanize_device($device);
        $cache['devices']['id'][$device_id] = $device;
    }
    return $device;
}
Пример #5
0
function generate_device_link_header($device, $vars = array())
{
    global $config;
    if (isset($device['humanized_device']) == FALSE) {
        humanize_device($device);
    }
    if ($device['os'] == "ios") {
        formatCiscoHardware($device, true);
    }
    #  print_r($device);
    $contents = '
      <table class="table table-striped table-bordered table-rounded table-condensed">
        <tr class="' . $device['html_row_class'] . '" style="font-size: 10pt;">
          <td style="width: 10px; background-color: ' . $device['html_tab_colour'] . '; margin: 0px; padding: 0px"></td>
          <td width="40" style="padding: 10px; text-align: center; vertical-align: middle;">' . getImage($device) . '</td>
          <td width="200"><a href="#" class="' . $class . '" style="font-size: 15px; font-weight: bold;">' . $device['hostname'] . '</a><br />' . truncate($device['location'], 64, '') . '</td>
          <td>' . $device['hardware'] . ' <br /> ' . $device['os_text'] . ' ' . $device['version'] . '</td>
          <td>' . deviceUptime($device, 'short') . '<br />' . $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;
}
function device_by_id_cache($device_id, $refresh = '0')
{
    global $cache;
    if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) {
        $device = $cache['devices']['id'][$device_id];
    } else {
        $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
    }
    if (!empty($device)) {
        humanize_device($device);
        if ($refresh || !isset($device['graphs'])) {
            // Fetch device graphs
            $device['graphs'] = dbFetchRows("SELECT * FROM `device_graphs` WHERE `device_id` = ?", array($device_id));
        }
        $cache['devices']['id'][$device_id] = $device;
        return $device;
    } else {
        return FALSE;
    }
}