Example #1
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function generate_sla_query($vars)
{
    $sql = 'SELECT * FROM `slas` ';
    $sql .= ' LEFT JOIN `slas-state` USING (`sla_id`)';
    $sql .= ' WHERE `deleted` = 0';
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'slas.sla_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'slas.device_id');
                break;
            case "id":
                $sql .= generate_query_values($value, 'slas.sla_id');
                break;
            case "owner":
                $sql .= generate_query_values($value, 'slas.sla_owner');
                break;
            case "rtt_type":
                $sql .= generate_query_values($value, 'slas.rtt_type');
                break;
            case "event":
                $sql .= generate_query_values($value, 'rtt_event');
                break;
        }
    }
    $sql .= $GLOBALS['cache']['where']['devices_permitted'];
    return $sql;
}
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function generate_vm_query($vars)
{
    $sql = 'SELECT * FROM `vminfo` WHERE 1 ';
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'vm_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'device_id');
                break;
            case "os":
                $sql .= generate_query_values($value, 'vm_guestos');
                break;
            case "state":
                $sql .= generate_query_values($value, 'vm_state');
                break;
            case "memory":
                $sql .= generate_query_values($value, 'vm_memory');
                break;
            case "cpu":
                $sql .= generate_query_values($value, 'vm_cpucount');
                break;
        }
    }
    $sql .= $GLOBALS['cache']['where']['devices_permitted'];
    return $sql;
}
Example #3
0
function generate_status_query($vars)
{
    $sql = "SELECT * FROM `status`";
    $sql .= " LEFT JOIN `status-state` USING(`status_id`)";
    $sql .= " WHERE 1";
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'status.status_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'status.device_id');
                break;
            case "id":
                $sql .= generate_query_values($value, 'status.status_id');
                break;
            case "class":
                $sql .= generate_query_values($value, 'status.entPhysicalClass');
                break;
            case "event":
                $sql .= generate_query_values($value, 'status_event');
                break;
        }
    }
    $sql .= $GLOBALS['cache']['where']['devices_permitted'];
    return $sql;
}
Example #4
0
/**
 * Build devices where array
 *
 * This function returns an array of "WHERE" statements from a $vars array.
 * The returned array can be implode()d and used on the devices table.
 * Originally extracted from the /devices/ page
 *
 * @param array $vars
 * @return array
 */
function build_devices_where_array($vars)
{
    $where_array = array();
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'group':
                    $values = get_group_entities($value);
                    $where_array[$var] = generate_query_values($values, 'device_id');
                    break;
                case 'hostname':
                case 'sysname':
                    $where_array[$var] = generate_query_values($value, $var, '%LIKE%');
                    break;
                case 'location_text':
                    $where_array[$var] = generate_query_values($value, 'devices.location', '%LIKE%');
                    break;
                case 'location':
                    $where_array[$var] = generate_query_values($value, 'devices.location');
                    break;
                case 'location_lat':
                case 'location_lon':
                case 'location_country':
                case 'location_state':
                case 'location_county':
                case 'location_city':
                    if ($GLOBALS['config']['geocoding']['enable']) {
                        $where_array[$var] = generate_query_values($value, 'devices_locations.' . $var);
                    }
                    break;
                case 'os':
                case 'version':
                case 'hardware':
                case 'features':
                case 'type':
                case 'status':
                case 'ignore':
                case 'disabled':
                    $where_array[$var] = generate_query_values($value, $var);
                    break;
                case 'graph':
                    $where_array[$var] = generate_query_values(devices_with_graph($value), "devices.device_id");
            }
        }
    }
    return $where_array;
}
Example #5
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     functions
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function generate_p2pradio_query($vars)
{
    $sql = "SELECT * FROM `p2p_radios`";
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'radio_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'device_id');
                break;
        }
    }
    return $sql;
}
Example #6
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function generate_processor_query($vars)
{
    $sql = "SELECT * FROM `processors`";
    $sql .= " LEFT JOIN `processors-state` USING(`processor_id`)";
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'processor_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'device_id');
                break;
        }
    }
    return $sql;
}
Example #7
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     web
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function build_mempool_query($vars)
{
    global $config, $cache;
    $sql = 'SELECT *, `mempools`.`mempool_id` AS `mempool_id` FROM `mempools`';
    $sql .= ' LEFT JOIN `mempools-state` USING(`mempool_id`)';
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'mempools.mempool_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'mempools.device_id');
                break;
        }
    }
    return $sql;
}
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function build_printersupplies_query($vars)
{
    $sql = 'SELECT * FROM `printersupplies`';
    $sql .= ' WHERE 1' . generate_query_permitted(array('device'));
    // Build query
    foreach ($vars as $var => $value) {
        switch ($var) {
            case "group":
            case "group_id":
                $values = get_group_entities($value);
                $sql .= generate_query_values($values, 'printersupplies.supply_id');
                break;
            case "device":
            case "device_id":
                $sql .= generate_query_values($value, 'printersupplies.device_id');
                break;
            case "supply":
                $sql .= generate_query_values($value, 'printersupplies.supply_type');
                break;
        }
    }
    return $sql;
}
Example #9
0
/**
 * Params:
 *
 * pagination, pageno, pagesize
 * device, type, adminstatus, state
 */
function get_bgp_array($vars)
{
    $array = array();
    // With pagination? (display page numbers in header)
    $array['pagination'] = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $array['pageno'] = $vars['pageno'];
    $array['pagesize'] = $vars['pagesize'];
    $start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
    $pagesize = $array['pagesize'];
    // Require cached IDs from html/includes/cache-data.inc.php
    $cache_bgp =& $GLOBALS['cache']['bgp'];
    // Begin query generate
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'B.device_id');
                    break;
                case 'peer':
                case 'peer_id':
                    $where .= generate_query_values($value, 'B.peer_device_id');
                    break;
                case 'local_ip':
                    $where .= generate_query_values($value, 'B.bgpPeerLocalAddr');
                    break;
                case 'peer_ip':
                    $where .= generate_query_values($value, 'B.bgpPeerRemoteAddr');
                    break;
                case 'local_as':
                    $where .= generate_query_values($value, 'D.bgpLocalAs');
                    break;
                case 'peer_as':
                    $where .= generate_query_values($value, 'B.bgpPeerRemoteAs');
                    break;
                case 'type':
                    if ($value == 'external' || $value == 'ebgp') {
                        $where .= generate_query_values($cache_bgp['external'], 'B.bgpPeer_id');
                    } else {
                        if ($value == 'internal' || $value == 'ibgp') {
                            $where .= generate_query_values($cache_bgp['internal'], 'B.bgpPeer_id');
                        }
                    }
                    break;
                case 'adminstatus':
                    if ($value == 'stop') {
                        $where .= generate_query_values($cache_bgp['start'], 'B.bgpPeer_id', '!=');
                        // NOT IN
                    } else {
                        if ($value == 'start') {
                            $where .= generate_query_values($cache_bgp['start'], 'B.bgpPeer_id');
                        }
                    }
                    break;
                case 'state':
                    if ($value == 'down') {
                        $where .= generate_query_values($cache_bgp['up'], 'B.bgpPeer_id', '!=');
                        // NOT IN
                    } else {
                        if ($value == 'up') {
                            $where .= generate_query_values($cache_bgp['up'], 'B.bgpPeer_id');
                        }
                    }
                    break;
            }
        }
    }
    // Show peers only for permitted devices
    $query_permitted = generate_query_values($cache_bgp['permitted'], 'B.bgpPeer_id');
    $query = 'FROM `bgpPeers` AS B';
    $query_count = 'SELECT COUNT(*) ' . $query . $where . $query_permitted;
    // Use only bgpPeer_id and device_id in query!
    $query .= ' LEFT JOIN `bgpPeers-state` AS S ON B.`bgpPeer_id` = S.`bgpPeer_id`';
    $query .= ' LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id`';
    $query .= $where . $query_permitted;
    $query = 'SELECT D.`hostname`, D.`bgpLocalAs`, B.*, S.* ' . $query;
    $query .= ' ORDER BY D.`hostname`, B.`bgpPeerRemoteAs`, B.`bgpPeerRemoteAddr`';
    $query .= " LIMIT {$start},{$pagesize}";
    $peer_devices = array();
    // Query BGP
    foreach (dbFetchRows($query, $param) as $entry) {
        humanize_bgp($entry);
        // Collect peer devices for AFI/SAFI
        $peer_devices[$entry['device_id']] = 1;
        $array['entries'][] = $entry;
    }
    // Query AFI/SAFI
    if (count($peer_devices)) {
        $query_afi = 'SELECT * FROM `bgpPeers_cbgp` WHERE 1' . generate_query_values(array_keys($peer_devices), 'device_id');
        foreach (dbFetchRows($query_afi) as $entry) {
            $array['afisafi'][$entry['device_id']][$entry['bgpPeerRemoteAddr']][$entry['afi'] . '.' . $entry['safi']] = array('afi' => $entry['afi'], 'safi' => $entry['safi']);
        }
    }
    // Query BGP peers count
    if ($array['pagination']) {
        $array['count'] = dbFetchCell($query_count, $param);
        $array['pagination_html'] = pagination($vars, $array['count']);
    } else {
        $array['count'] = count($array['entries']);
    }
    return $array;
}
Example #10
0
/**
 * Display syslog messages.
 *
 * Display pages with device syslog messages.
 * Examples:
 * print_syslogs() - display last 10 syslog messages from all devices
 * print_syslogs(array('pagesize' => 99)) - display last 99 syslog messages from all device
 * print_syslogs(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 syslog messages from page 3 with pagination header
 * print_syslogs(array('pagesize' => 10, 'device' = 4)) - display last 10 syslog messages for device_id 4
 * print_syslogs(array('short' => TRUE)) - show small block with last syslog messages
 *
 * @param array $vars
 * @return none
 *
 */
function print_syslogs($vars)
{
    // Short events? (no pagination, small out)
    $short = isset($vars['short']) && $vars['short'];
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $priorities = $GLOBALS['config']['syslog']['priorities'];
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'priority':
                    if (!is_array($value)) {
                        $value = explode(',', $value);
                    }
                    foreach ($value as $k => $v) {
                        // Rewrite priority strings to numbers
                        $value[$k] = priority_string_to_numeric($v);
                    }
                    // Do not break here, it's true!
                // Do not break here, it's true!
                case 'program':
                    $where .= generate_query_values($value, $var);
                    break;
                case 'message':
                    $where .= generate_query_values($value, 'msg', '%LIKE%');
                    break;
                case 'timestamp_from':
                    $where .= ' AND `timestamp` > ?';
                    $param[] = $value;
                    break;
                case 'timestamp_to':
                    $where .= ' AND `timestamp` < ?';
                    $param[] = $value;
                    break;
            }
        }
    }
    // Show events only for permitted devices
    $query_permitted = generate_query_permitted();
    $query = 'FROM `syslog` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `seq` DESC ';
    $query .= "LIMIT {$start},{$pagesize}";
    // Query syslog messages
    $entries = dbFetchRows($query, $param);
    // Query syslog count
    if ($pagination && !$short) {
        $count = dbFetchCell($query_count, $param);
    } else {
        $count = count($entries);
    }
    if (!$count) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No syslog entries found!</h4>
Check that the syslog daemon and Observium configuration options are set correctly, that your devices are configured to send syslog to Observium and that there are no firewalls blocking the messages.

See <a href="' . OBSERVIUM_URL . '/wiki/Category:Documentation" target="_blank">documentation</a> and <a href="' . OBSERVIUM_URL . '/wiki/Configuration_Options#Syslog_Settings" target="_blank">configuration options</a> for more information.');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'priority' => TRUE);
        // For now (temporarily) priority always displayed
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'syslog') {
            $list['device'] = TRUE;
        }
        if ($short || !isset($vars['priority']) || empty($vars['priority'])) {
            $list['priority'] = TRUE;
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        if (!$short) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            #    $string .= '      <th></th>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['priority']) {
                $string .= '      <th>Priority</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($entries as $entry) {
            switch ($entry['priority']) {
                case "0":
                    // Emergency
                // Emergency
                case "1":
                    // Alert
                // Alert
                case "2":
                    // Critical
                // Critical
                case "3":
                    // Error
                    $entry['html_row_class'] = "error";
                    break;
                case "4":
                    // Warning
                    $entry['html_row_class'] = "warning";
                    break;
                case "5":
                    // Notification
                    $entry['html_row_class'] = "recovery";
                    break;
                case "6":
                    // Informational
                    $entry['html_row_class'] = "up";
                    break;
                case "7":
                    // Debugging
                    $entry['html_row_class'] = "suppressed";
                    break;
                default:
            }
            $string .= '  <tr class="' . $entry['html_row_class'] . '">' . PHP_EOL;
            $string .= '<td class="state-marker"></td>' . PHP_EOL;
            if ($short) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= generate_tooltip_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td width="130">';
                $string .= format_timestamp($entry['timestamp']) . '</td>' . PHP_EOL;
            }
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $device_vars = array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'logs', 'section' => 'syslog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['priority']) {
                if (!$short) {
                    $string .= '    <td style="color: ' . $priorities[$entry['priority']]['color'] . '; white-space: nowrap; width: 95px;"><span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . nicecase($priorities[$entry['priority']]['name']) . ' (' . $entry['priority'] . ')</span></td>' . PHP_EOL;
                }
            }
            $entry['program'] = empty($entry['program']) ? '[[EMPTY]]' : $entry['program'];
            if ($short) {
                $string .= '    <td class="syslog">';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '"><strong>' . $entry['program'] . '</strong></span> ';
            } else {
                $string .= '    <td>';
                $string .= '<span class="label label-' . $priorities[$entry['priority']]['label-class'] . '">' . $entry['program'] . '</span>';
            }
            $string .= escape_html($entry['msg']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>' . PHP_EOL;
        $string .= generate_box_close();
        // Print pagination header
        if ($pagination && !$short) {
            $string = pagination($vars, $count) . $string . pagination($vars, $count);
        }
        // Print syslog
        echo $string;
    }
}
Example #11
0
$neighbours_ports = dbFetchColumn('SELECT DISTINCT `port_id` FROM `neighbours` WHERE 1' . $cache['where']['ports_permitted']);
$where = ' WHERE 1 ';
$where .= generate_query_values($neighbours_ports, 'port_id');
//r($where);
$form_items = array();
foreach (dbFetchColumn('SELECT DISTINCT `device_id` FROM `ports`' . $where) as $device_id) {
    if ($cache['devices']['id'][$device_id]['hostname']) {
        $form_items['devices'][$device_id] = $cache['devices']['id'][$device_id]['hostname'];
    }
}
natcasesort($form_items['devices']);
// If device IDs passed, limit ports to specified devices
if ($vars['device']) {
    $neighbours_ports = dbFetchColumn('SELECT DISTINCT `port_id` FROM `ports`' . $where . generate_query_values($vars['device'], 'device_id'));
    $where = ' WHERE 1 ';
    $where .= generate_query_values($neighbours_ports, 'port_id');
    //r($where);
}
$form_params = array('platforms' => 'remote_platform', 'versions' => 'remote_version', 'protocols' => 'protocol');
foreach ($form_params as $param => $column) {
    foreach (dbFetchColumn('SELECT DISTINCT `' . $column . '` FROM `neighbours`' . $where) as $entry) {
        if (!empty($entry)) {
            $form_items[$param][$entry] = $param == 'protocols' ? nicecase($entry) : escape_html($entry);
        }
    }
}
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$form['row'][0]['device'] = array('type' => 'multiselect', 'name' => 'Device', 'width' => '100%', 'value' => $vars['device'], 'values' => $form_items['devices']);
$form['row'][0]['protocol'] = array('type' => 'multiselect', 'name' => 'Protocol', 'width' => '100%', 'value' => $vars['protocol'], 'values' => $form_items['protocols']);
$form['row'][0]['platform'] = array('type' => 'multiselect', 'name' => 'Platform', 'width' => '100%', 'value' => $vars['platform'], 'values' => $form_items['platforms']);
$form['row'][0]['version'] = array('type' => 'multiselect', 'name' => 'Version', 'width' => '100%', 'value' => $vars['version'], 'values' => $form_items['versions']);
//  dbFetchCell('TRUNCATE TABLE `eventlog`');
//  print_message('Event log truncated');
//}
unset($search, $devices_array, $types);
$where = ' WHERE 1 ' . generate_query_permitted();
//Device field
foreach ($cache['devices']['hostname'] as $hostname => $device_id) {
    if ($cache['devices']['id'][$device_id]['disabled'] && !$config['web_show_disabled']) {
        continue;
    }
    $devices_array[$device_id] = $hostname;
}
$search[] = array('type' => 'multiselect', 'name' => '设备', 'id' => 'device_id', 'width' => '125px', 'value' => $vars['device_id'], 'values' => $devices_array);
// Add device_id limit for other fields
if (isset($vars['device_id'])) {
    $where .= generate_query_values($vars['device_id'], 'device_id');
}
//Message field
$search[] = array('type' => 'text', 'name' => '信息', 'id' => 'message', 'width' => '150px', 'placeholder' => 'Message', 'value' => $vars['message']);
//Severity field
foreach (dbFetchColumn('SELECT DISTINCT `severity` FROM `eventlog`' . $where) as $severity) {
    $severities[$severity] = ucfirst($config['syslog']['priorities'][$severity]['name']);
}
krsort($severities);
$search[] = array('type' => 'multiselect', 'name' => '严重程度', 'id' => 'severity', 'width' => '110px', 'subtext' => TRUE, 'value' => $vars['severity'], 'values' => $severities);
//Types field
$types['device'] = '设备';
foreach (dbFetchColumn('SELECT DISTINCT `entity_type` FROM `eventlog` IGNORE INDEX (`type`)' . $where) as $type) {
    //$type = $data['type'];
    $types[$type] = ucfirst($type);
}
Example #13
0
/**
 * Display Interface MACs addresses.
 *
 * Display pages with MAC addresses from device Interfaces.
 *
 * @param array $vars
 * @return none
 *
 */
function print_mac_addresses($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'interface':
                    $where .= ' AND `ifDescr` LIKE ?';
                    $param[] = $value;
                    break;
                case 'address':
                    $where .= ' AND `ifPhysAddress` LIKE ?';
                    # FIXME hm? mres in a dbFacile parameter?
                    $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%';
                    break;
            }
        }
    }
    $where .= ' AND `ifPhysAddress` IS NOT NULL';
    //Exclude empty MACs
    // Show MACs only for permitted ports
    $query_permitted = generate_query_permitted(array('port'));
    $query = 'FROM `ports` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `ifPhysAddress`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        if (port_permitted($entry['port_id'])) {
            humanize_port($entry);
            $string .= '  <tr>' . PHP_EOL;
            if ($list['device']) {
                $dev = device_by_id_cache($entry['device_id']);
                $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
            }
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL;
            $string .= '    <td style="width: 160px;">' . $entry['human_mac'] . '</td>' . PHP_EOL;
            $string .= '    <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print MAC addresses
    echo $string;
}
Example #14
0
            $params = array('port_id' => $port_id, 'mac_address' => $clean_mac, 'ip_address' => $ip, 'ip_version' => $ip_version);
            dbInsert($params, 'ip_mac');
            print_debug("Added MAC address " . format_mac($clean_mac) . " for {$ip}");
            //log_event("MAC added: $ip : " . format_mac($clean_mac), $device, "port", $port_id);
            echo "+";
        }
    }
}
// Remove expired ARP/NDP entries
$remove_mac_ids = array();
foreach ($cache_arp as $entry) {
    $entry_mac_id = $entry['mac_id'];
    $entry_mac = $entry['mac_address'];
    $entry_ip = $entry['ip_address'];
    $entry_version = $entry['ip_version'];
    $entry_if = $entry['ifIndex'];
    $entry_port_id = $interface[$entry_if];
    if (!isset($mac_table[$entry_if][$entry_version][$entry_ip])) {
        $remove_mac_ids[] = $entry_mac_id;
        //dbDelete('ip_mac', 'mac_id = ?', array($entry_mac_id));
        print_debug("Removed MAC address " . format_mac($entry_mac) . " for {$entry_ip}");
        //log_event("MAC removed: $entry_ip : " . format_mac($entry_mac), $device, "port", $entry['port_id']);
        echo "-";
    }
}
if (count($remove_mac_ids)) {
    dbDelete('ip_mac', '1' . generate_query_values($remove_mac_ids, 'mac_id'));
}
echo PHP_EOL;
unset($interface, $remove_mac_ids);
// EOF
Example #15
0
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
$graph_type = "mempool_usage";
$sql = 'SELECT *, `mempools`.`mempool_id` AS `mempool_id` FROM `mempools`';
$sql .= ' LEFT JOIN `mempools-state` ON `mempools`.`mempool_id` = `mempools-state`.`mempool_id`';
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
// Groups
if (isset($vars['group'])) {
    $values = get_group_entities($vars['group']);
    $sql .= generate_query_values($values, 'mempools.mempool_id');
}
$mempools = array();
foreach (dbFetchRows($sql) as $mempool) {
    if (isset($cache['devices']['id'][$mempool['device_id']])) {
        $mempool['hostname'] = $cache['devices']['id'][$mempool['device_id']]['hostname'];
        $mempool['html_row_class'] = $cache['devices']['id'][$mempool['device_id']]['html_row_class'];
        $mempools[] = $mempool;
    }
}
$mempools = array_sort_by($mempools, 'hostname', SORT_ASC, SORT_STRING, 'mempool_descr', SORT_ASC, SORT_STRING);
$mempools_count = count($mempools);
// Pagination
$pagination_html = pagination($vars, $mempools_count);
echo $pagination_html;
if ($vars['pageno']) {
Example #16
0
/**
 * Params:
 *
 * pagination, pageno, pagesize
 * device, port
 */
function get_neighbours_array(&$vars)
{
    $array = array();
    // With pagination? (display page numbers in header)
    $array['pagination'] = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $array['pageno'] = $vars['pageno'];
    $array['pagesize'] = $vars['pagesize'];
    $start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
    $pagesize = $array['pagesize'];
    // Begin query generate
    $param = array();
    $where = ' WHERE `active` = 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_a':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_a':
                    $where .= generate_query_values($value, 'port_id');
                    break;
                case 'device_b':
                    $where .= generate_query_values($value, 'remote_hostname');
                    break;
                case 'port_b':
                    $where .= generate_query_values($value, 'remote_port');
                    break;
                case 'protocol':
                    $where .= generate_query_values($value, 'protocol');
                    break;
                case 'platform':
                    $where .= generate_query_values($value, 'remote_platform');
                    break;
                case 'version':
                    $where .= generate_query_values($value, 'remote_version');
                    break;
                case 'remote_port_id':
                    if ($value != 0) {
                        $where .= ' AND `remote_port_id` != 0';
                    } else {
                        $where .= generate_query_values($value, 'remote_port_id');
                    }
                    break;
            }
        }
    }
    // Show neighbours only for permitted devices and ports
    $query_permitted = $GLOBALS['cache']['where']['ports_permitted'];
    $query = 'FROM `neighbours` LEFT JOIN `ports` USING(`port_id`) ';
    $query .= $where . $query_permitted;
    //$query_count = 'SELECT COUNT(*) '.$query;
    $query = 'SELECT * ' . $query;
    //$query .= ' ORDER BY `event_id` DESC ';
    //$query .= " LIMIT $start,$pagesize";
    // Query neighbours
    $array['entries'] = dbFetchRows($query, $param);
    foreach ($array['entries'] as &$entry) {
        $device =& $GLOBALS['cache']['devices']['id'][$entry['device_id']];
        if (isset($device['status']) && !$device['status']) {
            $entry['row_class'] = 'error';
        } else {
            if (isset($device['disabled']) && $device['disabled']) {
                $entry['row_class'] = 'ignore';
            }
        }
        $entry['hostname'] = $device['hostname'];
        //$entry['row_class'] = $device['row_class'];
    }
    // Sorting
    // FIXME. Sorting can be as function, but in must before print_table_header and after get table from db
    switch ($vars['sort_order']) {
        case 'desc':
            $sort_order = SORT_DESC;
            $sort_neg = SORT_ASC;
            break;
        case 'reset':
            unset($vars['sort'], $vars['sort_order']);
            // no break here
        // no break here
        default:
            $sort_order = SORT_ASC;
            $sort_neg = SORT_DESC;
    }
    switch ($vars['sort']) {
        case 'device_a':
            $array['entries'] = array_sort_by($array['entries'], 'hostname', $sort_order, SORT_STRING);
            break;
        case 'port_a':
            $array['entries'] = array_sort_by($array['entries'], 'port_label', $sort_order, SORT_STRING);
            break;
        case 'device_b':
            $array['entries'] = array_sort_by($array['entries'], 'remote_hostname', $sort_order, SORT_STRING);
            break;
        case 'port_b':
            $array['entries'] = array_sort_by($array['entries'], 'remote_port', $sort_order, SORT_STRING);
            break;
        case 'protocol':
            $array['entries'] = array_sort_by($array['entries'], 'protocol', $sort_order, SORT_STRING);
            break;
        default:
            // Not sorted
    }
    // Query neighbours count
    $array['count'] = count($array['entries']);
    if ($array['pagination']) {
        $array['pagination_html'] = pagination($vars, $array['count']);
        $array['entries'] = array_chunk($array['entries'], $vars['pagesize']);
        $array['entries'] = $array['entries'][$vars['pageno'] - 1];
    }
    // Query for last timestamp
    //$array['updated'] = dbFetchCell($query_updated, $param);
    return $array;
}
Example #17
0
                $where_array[$var] = generate_query_values($value, 'location', '%LIKE%');
                break;
            case 'os':
            case 'version':
            case 'hardware':
            case 'features':
            case 'type':
            case 'status':
            case 'ignore':
            case 'disabled':
            case 'location_country':
            case 'location_state':
            case 'location_county':
            case 'location_city':
            case 'location':
                $where_array[$var] = generate_query_values($value, $var);
                break;
        }
    }
}
$where .= implode('', $where_array);
$pagetitle[] = "Devices";
if ($vars['searchbar'] != "hide") {
    // Generate array with form elements
    $search_items = array();
    foreach (array('os', 'hardware', 'version', 'features', 'type') as $entry) {
        $query = "SELECT `{$entry}` FROM `devices`";
        if (isset($where_array[$entry])) {
            $tmp = $where_array[$entry];
            unset($where_array[$entry]);
            $query .= ' WHERE 1 ' . implode('', $where_array);
Example #18
0
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
# enable/disable ports/interfaces on devices.
$device_id = intval($vars['device']);
if (!device_permitted($device_id)) {
    print_error_permission('You have insufficient permissions to edit settings.');
    return;
}
$rows_updated = 0;
//r($vars);
$ports_attribs = get_device_entities_attribs($device_id, 'port');
// Get all attribs
$where = generate_query_values($vars['port'], 'port_id');
foreach (dbFetchRows("SELECT `port_id`, `ignore`, `disabled` FROM `ports` WHERE `device_id` = ?" . $where, array($device_id)) as $port) {
    $updated = FALSE;
    $port_id = $port['port_id'];
    $update_array = array();
    if (isset($ports_attribs['port'][$port_id])) {
        $port = array_merge($port, $ports_attribs['port'][$port_id]);
    }
    // Check ignored and disabled port
    foreach (array('ignore', 'disabled') as $param) {
        $param_id = $param . '_' . $port_id;
        $old_param = $port[$param] ? 1 : 0;
        $new_param = isset($vars[$param_id]) && $vars[$param_id] ? 1 : 0;
        if ($old_param != $new_param) {
            $update_array[$param] = $new_param;
        }
Example #19
0
// Deleted
$cache['ports']['deleted'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . " AND `deleted` = 1");
$ports['deleted'] = count($cache['ports']['deleted']);
// Devices disabled
if (isset($cache['devices']['disabled']) && count($cache['devices']['disabled']) > 0) {
    $cache['ports']['device_disabled'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . generate_query_values($cache['devices']['disabled'], 'device_id'));
    if (!$config['web_show_disabled']) {
        $where_hide .= generate_query_values($cache['devices']['disabled'], 'device_id', '!=');
    }
}
// Devices ignored
$where_devices_ignored = '';
if (isset($cache['devices']['ignored']) && count($cache['devices']['ignored']) > 0) {
    $cache['ports']['device_ignored'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . $where_hide . generate_query_values($cache['devices']['ignored'], 'device_id'));
    $where_hide .= generate_query_values($cache['devices']['ignored'], 'device_id', '!=');
    $where_devices_ignored = generate_query_values($cache['devices']['ignored'], 'device_id');
}
// Ports poll disabled
$cache['ports']['poll_disabled'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . $where_hide . " AND `disabled` = '1'");
// Ports ignored
$cache['ports']['ignored'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . $where_hide . " AND (`ignore` = '1')");
$ports['ignored'] = count($cache['ports']['ignored']);
// r("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . $where_hide . " AND (`ignore` = '1'" . $where_devices_ignored . ")");
//r($cache['ports']['ignored']);
$where_hide .= " AND `ignore` = 0";
// Ports errored
$cache['ports']['errored'] = dbFetchColumn("SELECT `port_id` FROM `ports` WHERE 1 " . $where_permitted . $where_hide . " AND `ifAdminStatus` = 'up' AND (`ifOperStatus` = 'up' OR `ifOperStatus` = 'testing') AND (`ifOutErrors_delta` > 0 OR `ifInErrors_delta` > 0)");
//$cache['ports']['errored'] = dbFetchColumn("SELECT `port_id` FROM `ports` LEFT JOIN `ports-state` USING(`port_id`) WHERE 1 " . $where_permitted . $where_hide . " AND `ifAdminStatus` = 'up' AND (`ifOperStatus` = 'up' OR `ifOperStatus` = 'testing') AND (`ifOutErrors_delta` > 0 OR `ifInErrors_delta` > 0)");
$ports['errored'] = count($cache['ports']['errored']);
// Ports counts
$ports['count'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE 1 " . $where_permitted . $where_hide);
Example #20
0
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
$graph_type = "processor_usage";
$sql = "SELECT *, `processors`.`processor_id` AS `processor_id` FROM `processors`";
$sql .= " LEFT JOIN  `processors-state` ON `processors`.`processor_id` = `processors-state`.`processor_id`";
$sql .= ' WHERE 1' . generate_query_permitted(array('device'));
// Groups
if (isset($vars['group'])) {
    $values = get_group_entities($vars['group']);
    $sql .= generate_query_values($values, 'processors.processor_id');
}
$processors = array();
foreach (dbFetchRows($sql) as $proc) {
    if (isset($cache['devices']['id'][$proc['device_id']])) {
        $proc['hostname'] = $cache['devices']['id'][$proc['device_id']]['hostname'];
        $proc['html_row_class'] = $cache['devices']['id'][$proc['device_id']]['html_row_class'];
        $processors[] = $proc;
    }
}
$processors = array_sort_by($processors, 'hostname', SORT_ASC, SORT_STRING, 'processor_descr', SORT_ASC, SORT_STRING);
$processors_count = count($processors);
// Pagination
$pagination_html = pagination($vars, $processors_count);
echo $pagination_html;
if ($vars['pageno']) {
Example #21
0
/**
 * Display dot1x sessions
 *
 * @param array $vars
 * @return none
 *
 */
function print_dot1xtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
                    } else {
                        if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
                            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
                        } else {
                            $value = trim($value);
                            $where .= generate_query_values($value, 'username', '%LIKE%');
                        }
                    }
                    break;
            }
        }
    }
    // Check permissions
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M'));
    $query = 'FROM `wifi_sessions` AS M ';
    $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query;
    $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query;
    $query .= ' ORDER BY M.`timestamp` DESC';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query wireless  sessions table
    $entries = dbFetchRows($query, $param);
    // Query wireless  sessions table count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number`  FROM `wifi_accesspoints`");
    foreach ($aps_db as $ap_db) {
        $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db;
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    // A radio is like a port
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>IP Address</th>' . PHP_EOL;
        $string .= '      <th>Username</th>' . PHP_EOL;
        $string .= '      <th>SSID/VLAN</th>' . PHP_EOL;
        $string .= '      <th>Last Seen</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface/AP</th>' . PHP_EOL;
        }
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $ap_id = $entry['accesspoint_id'];
        $interface = $aps_sorted_db[$ap_id]['name'];
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '    <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL;
        }
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print wireless sessions
    echo $string;
}
Example #22
0
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'ip_version':
                    $where .= generate_query_values($value, 'ip_version');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        if (strpos($value, ':') !== FALSE) {
                            if (Net_IPv6::checkIPv6($value)) {
                                $value = Net_IPv6::uncompress($value, TRUE);
                            } else {
                                // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                            }
                        }
                        $where .= generate_query_values($value, 'ip_address', '%LIKE%');
                    } else {
                        // MAC Addresses
                        $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                        $where .= generate_query_values($value, 'mac_address', '%LIKE%');
                    }
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "ip_version":
                $sort = " ORDER BY `ip_version`";
                break;
            case "ip":
            case "address":
                $sort = " ORDER BY `ip_address`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = 'Self Device';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = 'Self Port';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
Example #23
0
function get_locations($filter = array())
{
    foreach ($filter as $var => $value) {
        switch ($var) {
            case 'location_lat':
            case 'location_lon':
            case 'location_country':
            case 'location_state':
            case 'location_county':
            case 'location_city':
                // Check geo params only when GEO enabled globally
                if (!$GLOBALS['config']['geocoding']['enable']) {
                    break;
                }
            case 'location':
                $where_array[$var] = generate_query_values($value, $var);
                break;
        }
    }
    if (count($where_array)) {
        // Return only founded locations
        $where = implode('', $where_array) . $GLOBALS['cache']['where']['devices_permitted'];
        $locations = dbFetchColumn("SELECT DISTINCT `location` FROM `devices_locations` WHERE 1 {$where};");
    } else {
        $locations = array();
        foreach ($GLOBALS['cache']['device_locations'] as $location => $count) {
            $locations[] = $location;
        }
    }
    sort($locations);
    return $locations;
}
Example #24
0
$param = array();
if (!isset($vars['sort'])) {
    $vars['sort'] = 'device';
}
//if (!isset($vars['ignore']))   { $vars['ignore'] = "0"; }
if (!isset($vars['disabled'])) {
    $vars['disabled'] = "0";
}
if (!isset($vars['deleted'])) {
    $vars['deleted'] = "0";
}
$select = "`ports`.`port_id` AS `port_id`, `devices`.`device_id` AS `device_id`";
$where_array = build_ports_where_array($vars);
$where = ' WHERE 1 ';
if (!$config['web_show_disabled'] && count($cache['devices']['disabled']) > 0) {
    $where_array[] = generate_query_values($cache['devices']['disabled'], 'ports.device_id', '!=');
}
$where .= implode('', $where_array);
//r($where_array);
$form_items = array();
foreach (get_locations() as $entry) {
    if ($entry === '') {
        $entry = OBS_VAR_UNSET;
    }
    $form_items['location'][$entry] = $entry;
}
foreach (get_type_groups('port') as $entry) {
    $form_items['group'][$entry['group_id']] = $entry['group_name'];
}
foreach (array('ifType', 'ifSpeed', 'port_descr_type') as $entry) {
    $query = "SELECT `{$entry}` FROM `ports`";
Example #25
0
 * @package    observium
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
if ($bg == "#ffffff") {
    $bg = "#e5e5e5";
} else {
    $bg = "#ffffff";
}
if (!is_array($vars['type'])) {
    $vars['type'] = array($vars['type']);
}
$where = 'WHERE 1';
$where .= generate_query_values($vars['type'], 'port_descr_type', 'LIKE');
$where .= generate_query_permitted(array('port'));
$ports = dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D {$where} AND I.`device_id` = D.`device_id` ORDER BY I.`ifAlias`");
$if_list = array();
foreach ($ports as $port) {
    $if_list[] = $port['port_id'];
}
$if_list = implode(',', $if_list);
for ($i = 0; $i < count($vars['type']); $i++) {
    $vars['type'][$i] = nicecase($vars['type'][$i]);
}
$types = implode(' + ', $vars['type']);
echo '<h4>Total Graph for ports of type : ' . $types . '</h4>';
if ($if_list) {
    $graph_type = "multiport_bits_separate";
    $port['port_id'] = $if_list;
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage webui
 * @copyright  (C) 2006-2015 Adam Armstrong
 *
 */
global $sensor_type;
$sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id` FROM `sensors`";
$sql .= " LEFT JOIN `sensors-state` ON `sensors`.`sensor_id` = `sensors-state`.`sensor_id`";
$sql .= " WHERE `sensors`.`sensor_class` = ?" . generate_query_permitted(array('device'));
// Groups
if (isset($vars['group'])) {
    $values = get_group_entities($vars['group']);
    $sql .= generate_query_values($values, 'sensors.sensor_id');
}
$sensors = array();
foreach (dbFetchRows($sql, array($sensor_type)) as $sensor) {
    if (isset($cache['devices']['id'][$sensor['device_id']])) {
        $sensor['hostname'] = $cache['devices']['id'][$sensor['device_id']]['hostname'];
        $sensor['html_row_class'] = $cache['devices']['id'][$sensor['device_id']]['html_row_class'];
        $sensors[] = $sensor;
    }
}
$sensors = array_sort_by($sensors, 'hostname', SORT_ASC, SORT_STRING, 'sensor_descr', SORT_ASC, SORT_STRING);
$sensors_count = count($sensors);
// Pagination
$pagination_html = pagination($vars, $sensors_count);
echo $pagination_html;
if ($vars['pageno']) {
Example #27
0
function get_logalert_log($vars)
{
    $array = array();
    // Short events? (no pagination, small out)
    $array['short'] = isset($vars['short']) && $vars['short'];
    // With pagination? (display page numbers in header)
    $array['pagination'] = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $array['pageno'] = $vars['pageno'];
    $array['pagesize'] = $vars['pagesize'];
    $start = $array['pagesize'] * $array['pageno'] - $array['pagesize'];
    $pagesize = $array['pagesize'];
    // Begin query generate
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'la_id':
                    $where .= generate_query_values($value, 'la_id');
                    break;
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'program':
                    $where .= generate_query_values($value, 'program', '%LIKE%');
                    break;
                case 'message':
                    $where .= generate_query_values($value, 'message', '%LIKE%');
                    break;
                case 'timestamp_from':
                    $where .= ' AND `timestamp` >= ?';
                    $param[] = $value;
                    break;
                case 'timestamp_to':
                    $where .= ' AND `timestamp` <= ?';
                    $param[] = $value;
                    break;
            }
        }
    }
    // Show events only for permitted devices
    $query_permitted = generate_query_permitted();
    //generate_query_permitted(array('entity'));
    $query = 'FROM `syslog_alerts` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`la_id`) ' . $query;
    $query_updated = 'SELECT MAX(`timestamp`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY `lal_id` DESC ';
    $query .= "LIMIT {$start},{$pagesize}";
    // Query events
    $array['entries'] = dbFetchRows($query, $param);
    // Query events count
    if ($array['pagination'] && !$array['short']) {
        $array['count'] = dbFetchCell($query_count, $param);
        $array['pagination_html'] = pagination($vars, $array['count']);
    } else {
        $array['count'] = count($array['entries']);
    }
    // Query for last timestamp
    $array['updated'] = dbFetchCell($query_updated, $param);
    //r($array);
    return $array;
}
Example #28
0
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
?>

<div class="row">
<div class="col-md-12">

<?php 
if (!is_array($alert_rules)) {
    $alert_rules = cache_alert_rules();
}
// Note, this form have more complex grid and class elements for responsive datetime field
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => generate_url($vars));
$where = ' WHERE 1 ' . generate_query_values($device['device_id'], 'device_id');
// Checkers Field
$form_filter = dbFetchColumn('SELECT DISTINCT `alert_test_id` FROM `alert_log`' . $where);
$form_items['checkers'] = generate_form_values('alert_log', $form_filter, 'alert_test_id');
$form['row'][0]['alert_test_id'] = array('type' => 'multiselect', 'name' => 'Checkers', 'width' => '100%', 'div_class' => 'col-lg-2 col-md-2 col-sm-4', 'subtext' => TRUE, 'value' => $vars['alert_test_id'], 'values' => $form_items['checkers']);
// Status Type Field
$form_filter = dbFetchColumn('SELECT DISTINCT `log_type` FROM `alert_log`' . $where);
$form_items['statuses'] = generate_form_values('alert_log', $form_filter, 'log_type');
$form['row'][0]['log_type'] = array('type' => 'multiselect', 'name' => 'Status Type', 'width' => '100%', 'div_class' => 'col-lg-2 col-md-2 col-sm-4', 'size' => '15', 'value' => $vars['log_type'], 'values' => $form_items['statuses']);
// Datetime Field
$form['row'][0]['timestamp'] = array('type' => 'datetime', 'div_class' => 'col-lg-5 col-md-7 col-sm-9', 'presets' => TRUE, 'min' => dbFetchCell('SELECT `timestamp` FROM `alert_log`' . $where . ' ORDER BY `timestamp` LIMIT 0,1;'), 'max' => dbFetchCell('SELECT `timestamp` FROM `alert_log`' . $where . ' ORDER BY `timestamp` DESC LIMIT 0,1;'), 'from' => $vars['timestamp_from'], 'to' => $vars['timestamp_to']);
// Second row with timestamp for sm
//$form['row_options'][1]  = array('class' => 'hidden-lg hidden-md hidden-xs');
//$form['row'][1]['timestamp'] = $form['row'][0]['timestamp'];
//$form['row'][1]['timestamp']['div_class'] = 'text-nowrap col-sm-9';
// search button
Example #29
0
/**
 * Display Devices Inventory.
 *
 * @param array $vars
 * @return none
 *
 */
function print_inventory($vars)
{
    // On "Inventory" device tab display hierarchical list
    if ($vars['page'] == 'device' && is_numeric($vars['device']) && device_permitted($vars['device'])) {
        echo '<table class="table table-striped table-bordered table-condensed table-rounded"><tr><td>';
        echo '<div class="btn-group pull-right" style="margin-top:5px; margin-right: 5px;">
      <button class="btn btn-small" onClick="expandTree(\'enttree\');return false;"><i class="icon-plus muted small"></i> Expand</button>
      <button class="btn btn-small" onClick="collapseTree(\'enttree\');return false;"><i class="icon-minus muted small"></i> Collapse</button>
    </div>';
        echo '<div style="clear: left; margin: 5px;"><ul class="mktree" id="enttree" style="margin-left: -10px;">';
        $level = 0;
        $ent['entPhysicalIndex'] = 0;
        print_ent_physical($ent['entPhysicalIndex'], $level, "liOpen");
        echo '</ul></div>';
        echo '</td></tr></table>';
        return TRUE;
    }
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'E.device_id');
                    break;
                case 'parts':
                    $where .= generate_query_values($value, 'E.entPhysicalModelName', 'LIKE');
                    break;
                case 'serial':
                    $where .= ' AND E.`entPhysicalSerialNum` LIKE ?';
                    $param[] = '%' . $value . '%';
                    break;
                case 'description':
                    $where .= ' AND E.`entPhysicalDescr` LIKE ?';
                    $param[] = '%' . $value . '%';
                    break;
            }
        }
    }
    // Show inventory only for permitted devices
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query = 'FROM `entPhysical` AS E ';
    $query .= 'LEFT JOIN `devices` AS D ON D.`device_id` = E.`device_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY D.`hostname`';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query inventories
    $entries = dbFetchRows($query, $param);
    // Query inventory count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'inventory') {
        $list['device'] = TRUE;
    }
    $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Name</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '      <th>Part #</th>' . PHP_EOL;
        $string .= '      <th>Serial #</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $string .= '  <tr>' . PHP_EOL;
        if ($list['device']) {
            $string .= '    <td class="entity" style="white-space: nowrap">' . generate_device_link($entry, NULL, array('page' => 'device', 'tab' => 'entphysical')) . '</td>' . PHP_EOL;
        }
        if ($entry['ifIndex']) {
            $interface = get_port_by_ifIndex($entry['device_id'], $entry['ifIndex']);
            $entry['entPhysicalName'] = generate_port_link($interface);
        } elseif ($entry['entPhysicalClass'] == "sensor") {
            $sensor = dbFetchRow("SELECT * FROM `sensors` AS S\n                            LEFT JOIN `sensors-state` AS ST ON S.`sensor_id` = ST.`sensor_id`\n                            WHERE `device_id` = ? AND (`entPhysicalIndex` = ? OR `sensor_index` = ?)", array($entry['device_id'], $entry['entPhysicalIndex'], $entry['entPhysicalIndex']));
            //$ent_text .= ' ('.$sensor['sensor_value'] .' '. $sensor['sensor_class'].')';
            $entry['entPhysicalName'] = generate_entity_link('sensor', $sensor);
        }
        $string .= '    <td style="width: 160px;">' . $entry['entPhysicalName'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['entPhysicalDescr'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['entPhysicalModelName'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['entPhysicalSerialNum'] . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print Inventories
    echo $string;
}
Example #30
0
     break;
 case 'deleted':
 case 'ignore':
 case 'disable':
 case 'ifSpeed':
     $where .= generate_query_values($value, 'ports.' . $var);
     break;
 case 'ifType':
     $where .= generate_query_values($value, 'ports.ifType');
     break;
 case 'ifAlias':
 case 'ifDescr':
     $where .= generate_query_values($value, $var, '%LIKE%');
     break;
 case 'port_descr_type':
     $where .= generate_query_values($value, $var, 'LIKE');
     break;
 case 'errors':
     if ($value == 1 || $value == "yes") {
         $where .= " AND (`ifInErrors_delta` > '0' OR `ifOutErrors_delta` > '0')";
     }
     break;
 case 'alerted':
     if ($value == "yes") {
         $where .= "AND `ifAdminStatus` = ? AND ( `ifOperStatus` = ? OR `ifOperStatus` = ? )";
         $param[] = "up";
         $param[] = "LowerLayerDown";
         $param[] = "down";
     }
 case 'state':
     if ($value == "down") {