예제 #1
0
/**
 * Display neighbours.
 *
 * Display pages with device neighbours in some formats.
 * Examples:
 * print_neighbours() - display all neighbours from all devices
 * print_neighbours(array('pagesize' => 99)) - display 99 neighbours from all device
 * print_neighbours(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 neighbours from page 3 with pagination header
 * print_neighbours(array('pagesize' => 10, 'device' = 4)) - display 10 neighbours for device_id 4
 *
 * @param array $vars
 * @return none
 *
 */
function print_neighbours($vars)
{
    // Get neighbours array
    $neighbours = get_neighbours_array($vars);
    if (!$neighbours['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No neighbours found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE);
        if ($vars['page'] != 'device') {
            $list['device'] = TRUE;
        }
        if (in_array($vars['graph'], array('bits', 'upkts', 'nupkts', 'pktsize', 'percent', 'errors', 'etherlike', 'fdb_count'))) {
            $graph_types = array($vars['graph']);
        } else {
            $graph_types = array('bits', 'upkts', 'errors');
        }
        $string = generate_box_open($vars['header']);
        $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
        $cols = array(array(NULL, 'class="state-marker"'), 'device_a' => 'Local Device', 'port_a' => 'Local Port', 'NONE' => NULL, 'device_b' => 'Remote Device', 'port_b' => 'Remote Port', 'protocol' => 'Protocol');
        if (!$list['device']) {
            unset($cols[0], $cols['device_a']);
        }
        $string .= get_table_header($cols, $vars);
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($neighbours['entries'] as $entry) {
            $string .= '  <tr class="' . $entry['row_class'] . '">' . PHP_EOL;
            if ($list['device']) {
                $string .= '   <td class="state-marker"></td>';
                $string .= '    <td class="entity">' . generate_device_link($entry, NULL, array('tab' => 'ports', 'view' => 'neighbours')) . '</td>' . PHP_EOL;
            }
            $string .= '    <td><span class="entity">' . generate_port_link($entry) . '</span><br />' . $entry['ifAlias'] . '</td>' . PHP_EOL;
            $string .= '    <td><i class="icon-resize-horizontal text-success"></i></td>' . PHP_EOL;
            if (is_numeric($entry['remote_port_id']) && $entry['remote_port_id']) {
                $remote_port = get_port_by_id_cache($entry['remote_port_id']);
                $remote_device = device_by_id_cache($remote_port['device_id']);
                $string .= '    <td><span class="entity">' . generate_device_link($remote_device) . '</span><br />' . $remote_device['hardware'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . generate_port_link($remote_port) . '</span><br />' . $remote_port['ifAlias'] . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td><span class="entity">' . $entry['remote_hostname'] . '</span><br />' . $entry['remote_platform'] . '</td>' . PHP_EOL;
                $string .= '    <td><span class="entity">' . $entry['remote_port'] . '</span></td>' . PHP_EOL;
            }
            $string .= '    <td>' . strtoupper($entry['protocol']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Print pagination header
        if ($neighbours['pagination_html']) {
            $string = $neighbours['pagination_html'] . $string . $neighbours['pagination_html'];
        }
        // Print
        echo $string;
    }
}
예제 #2
0
function port_by_id_cache($port_id)
{
    return get_port_by_id_cache('port', $port_id);
}
function log_event($text, $device = NULL, $type = NULL, $reference = NULL, $severity = 6)
{
    if (!is_array($device)) {
        $device = device_by_id_cache($device);
    }
    if ($device['ignore'] && $type != 'device') {
        return FALSE;
    }
    // Do not log events if device ignored
    if ($type == 'port') {
        if (is_array($reference)) {
            $port = $reference;
            $reference = $port['port_id'];
        } else {
            $port = get_port_by_id_cache($reference);
        }
        if ($port['ignore']) {
            return FALSE;
        }
        // Do not log events if interface ignored
    }
    $severity = priority_string_to_numeric($severity);
    // Convert named severities to numeric
    if ($type == 'device' && $severity == 5 || isset($_SESSION['username'])) {
        $severity = $severity == 6 ? 5 : $severity;
        // If severity default, change to notification
        if (isset($_SESSION['username'])) {
            $text .= ' (用户: ' . $_SESSION['username'] . ')';
        } else {
            if (is_cli()) {
                if (is_cron()) {
                    $text .= ' (自动运行)';
                } else {
                    $text .= ' (控制台)';
                }
            }
        }
    }
    $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'entity_id' => is_numeric($reference) ? $reference : array('NULL'), 'entity_type' => $type ? $type : array('NULL'), 'timestamp' => array("NOW()"), 'severity' => $severity, 'message' => $text);
    $id = dbInsert($insert, 'eventlog');
    return $id;
}
예제 #4
0
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
{
    if (!is_array($device)) {
        $device = device_by_id_cache($device);
    }
    if ($device['ignore'] && $type != 'device') {
        return FALSE;
    }
    // Do not log events if device ignored
    if ($type == 'port') {
        if (is_array($reference)) {
            $port = $reference;
            $reference = $port['port_id'];
        } else {
            $port = get_port_by_id_cache($reference);
        }
        if ($port['ignore']) {
            return FALSE;
        }
        // Do not log events if interface ignored
    }
    if ($type == 'device') {
        // For events with type 'device' add info about username or cli
        if (isset($_SESSION['username'])) {
            $text .= ' (by user: '******'username'] . ')';
        } else {
            if (is_cli()) {
                if (is_cron()) {
                    $text .= ' (by cron)';
                } else {
                    $text .= ' (by console)';
                }
            }
        }
    }
    $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'reference' => $reference ? $reference : "NULL", 'type' => $type ? $type : "NULL", 'timestamp' => array("NOW()"), 'message' => $text);
    $id = dbInsert($insert, 'eventlog');
    return $id;
}
예제 #5
0
    var_dump($GLOBALS['cache']['discovery-protocols']);
}
$table_rows = array();
$neighbours_db = dbFetchRows('SELECT * FROM `neighbours` LEFT JOIN `ports` USING(`port_id`) WHERE `device_id` = ?', array($device['device_id']));
foreach ($neighbours_db as $neighbour) {
    $local_port_id = $neighbour['port_id'];
    $remote_hostname = $neighbour['remote_hostname'];
    $remote_port = $neighbour['remote_port'];
    print_debug("{$local_port_id} -> {$remote_hostname} -> {$remote_port}");
    if (!$valid['neighbours'][$local_port_id][$remote_hostname][$remote_port]) {
        dbDelete('neighbours', '`neighbour_id` = ?', array($neighbour['neighbour_id']));
        $GLOBALS['module_stats'][$module]['deleted']++;
    } else {
        $port = get_port_by_id_cache($local_port_id);
        if (is_numeric($neighbour['remote_port_id'])) {
            $remote_port_array = get_port_by_id_cache($neighbour['remote_port_id']);
            $remote_port = $remote_port_array['port_label'];
        }
        $table_rows[] = array(nicecase($neighbour['protocol']), $port['port_label'], $remote_hostname, $remote_port, truncate($neighbour['remote_platform'], 20), truncate($neighbour['remote_version'], 40));
    }
}
echo PHP_EOL;
$table_headers = array('%WProtocol%n', '%WifName%n', '%WRemote: hostname%n', '%Wport%n', '%Wplatform%n', '%Wversion%n');
print_cli_table($table_rows, $table_headers);
$GLOBALS['module_stats'][$module]['status'] = count($valid[$module]);
if (OBS_DEBUG && $GLOBALS['module_stats'][$module]['status']) {
    print_vars($valid[$module]);
}
unset($valid['neighbours']);
echo PHP_EOL;
// EOF
예제 #6
0
 $query .= 'LEFT JOIN `ports` ON `A`.`port_id` = `ports`.`port_id` ';
 $query .= 'WHERE deleted=0 ';
 $query .= $where;
 $query .= ' ORDER BY A.`ipv4_address` LIMIT 8';
 #  $debug=1;
 // Query addresses
 $results = dbFetchRows($query, $param);
 if (count($results)) {
     $found = 1;
     foreach ($results as $result) {
         $addr_ports[$result['port_id']][] = $result;
     }
     echo '<li class="nav-header">IPs found: ' . count($results) . ' (on ' . count($addr_ports) . ' ports)</li>';
     #      foreach ($addr_ports as $port_id => $result)
     foreach ($results as $result) {
         $port = get_port_by_id_cache($result['port_id']);
         $device = device_by_id_cache($port['device_id']);
         echo '<li class="divider" style="margin: 0px;"></li>';
         echo '<li>';
         echo '<a href="' . generate_port_url($port) . '">';
         $descr = $device['hostname'] . ' | ' . rewrite_ifname($port['label']);
         $name = $result['ipv4_address'] . '/' . $result['ipv4_prefixlen'];
         if (strlen($name) > 35) {
             $name = substr($name, 0, 35) . "...";
         }
         /// FIXME: once we have alerting, colour this to the sensor's status
         $tab_colour = '#194B7F';
         // FIXME: This colour pulled from functions.inc.php humanize_device, maybe set it centrally in definitions?
         echo '<dl style="border-left: 10px solid ' . $tab_colour . '; " class="dl-horizontal dl-search">
         <dt style="padding-left: 10px; text-align: center;">
           <i class="oicon-magnifier-zoom-actual"></i></dt>
예제 #7
0
function discover_neighbour($protocol, $local_port_id, $neighbour)
{
    $port = get_port_by_id_cache($local_port_id);
    print_debug("Discover neighbour: " . $port['device_id'] . " -> {$protocol}, {$local_port_id}, " . implode(', ', $neighbour));
    $neighbour['protocol'] = $protocol;
    $params = array('protocol', 'remote_port_id', 'remote_hostname', 'remote_port', 'remote_platform', 'remote_version', 'remote_address');
    $neighbour_db = dbFetchRow("SELECT * FROM `neighbours` WHERE `port_id` = ? AND `protocol` = ? AND `remote_hostname` = ? AND `remote_port` = ?", array($local_port_id, $protocol, $neighbour['remote_hostname'], $neighbour['remote_port']));
    if (!isset($neighbour_db['neighbour_id'])) {
        $update = array('port_id' => $local_port_id);
        foreach ($params as $param) {
            $update[$param] = $neighbour[$param];
            if ($neighbour[$param] == NULL) {
                $update[$param] = array('NULL');
            }
        }
        $id = dbInsert($update, 'neighbours');
        $GLOBALS['module_stats']['neighbours']['added']++;
        //echo('+');
    } else {
        $update = array();
        foreach ($params as $param) {
            if (dbEscape($neighbour[$param]) != $neighbour_db[$param]) {
                $update[$param] = $neighbour[$param];
            }
        }
        if (count($update)) {
            dbUpdate($update, 'neighbours', '`neighbour_id` = ?', array($neighbour_db['neighbour_id']));
            $GLOBALS['module_stats']['neighbours']['updated']++;
            //echo('U');
        } else {
            $GLOBALS['module_stats']['neighbours']['unchanged']++;
            //echo('.');
        }
    }
    $GLOBALS['valid']['neighbours'][$local_port_id][$neighbour['remote_hostname']][$neighbour['remote_port']] = 1;
}
예제 #8
0
function generate_port_row($port, $vars = array())
{
    global $config, $cache;
    $device = device_by_id_cache($port['device_id']);
    humanize_port($port);
    if (!isset($vars['view'])) {
        $vars['view'] = "basic";
    }
    // Populate $port_adsl if the port has ADSL-MIB data
    if (!isset($cache['ports_option']['ports_adsl']) || in_array($port['port_id'], $cache['ports_option']['ports_adsl'])) {
        $port_adsl = dbFetchRow("SELECT * FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id']));
    }
    // Populate $port['tags'] with various tags to identify port statuses and features
    // Port Errors
    if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) {
        $port['tags'] .= generate_port_link($port, '<span class="label label-important">Errors</span>', 'port_errors');
    }
    // Port Deleted
    if ($port['deleted'] == '1') {
        $port['tags'] .= '<a href="' . generate_url(array('page' => 'deleted-ports')) . '"><span class="label label-important">Deleted</span></a>';
    }
    // Port CBQoS
    if (isset($cache['ports_option']['ports_cbqos'])) {
        if (in_array($port['port_id'], $cache['ports_option']['ports_cbqos'])) {
            $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'cbqos')) . '"><span class="label label-info">CBQoS</span></a>';
        }
    } else {
        if (dbFetchCell("SELECT COUNT(*) FROM `ports_cbqos` WHERE `port_id` = ?", array($port['port_id']))) {
            $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'cbqos')) . '"><span class="label label-info">CBQoS</span></a>';
        }
    }
    // Port MAC Accounting
    if (isset($cache['ports_option']['mac_accounting'])) {
        if (in_array($port['port_id'], $cache['ports_option']['mac_accounting'])) {
            $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'macaccounting')) . '"><span class="label label-info">MAC</span></a>';
        }
    } else {
        if (dbFetchCell("SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?", array($port['port_id']))) {
            $port['tags'] .= '<a href="' . generate_port_url($port, array('view' => 'macaccounting')) . '"><span class="label label-info">MAC</span></a>';
        }
    }
    // Populated formatted versions of port rates.
    $port['bps_in'] = formatRates($port['ifInOctets_rate'] * 8);
    $port['bps_out'] = formatRates($port['ifOutOctets_rate'] * 8);
    $port['pps_in'] = format_si($port['ifInUcastPkts_rate']) . "pps";
    $port['pps_out'] = format_si($port['ifOutUcastPkts_rate']) . "pps";
    $string = '';
    if ($vars['view'] == "basic" || $vars['view'] == "graphs") {
        $table_cols = '8';
        $string .= '<tr class="' . $port['row_class'] . '">
            <td class="state-marker"></td>
            <td style="width: 1px;"></td>';
        if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
            $table_cols++;
            // Increment table columns by one to make sure graph line draws correctly
            $string .= '    <td style="width: 200px;"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
                <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>';
        }
        $string .= '    <td><span class="entity">' . generate_port_link($port, rewrite_ifname($port['port_label'])) . ' ' . $port['tags'] . '</span><br />
                <span class="em">' . escape_html(truncate($port['ifAlias'], 50, '')) . '</span></td>' . '<td style="width: 110px;"> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i>  <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /></td>' . '<td style="width: 90px;"> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i>  <span class="small" style="' . $port['bps_in_style'] . '">' . $port['ifInOctets_perc'] . '%</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . $port['ifOutOctets_perc'] . '%</span><br /></td>' . '<td style="width: 110px;"><i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i>  <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span></td>' . '<td style="width: 110px;"><small>' . $port['human_speed'] . '<br />' . $port['ifMtu'] . '</small></td>
            <td ><small>' . $port['human_type'] . '<br />' . $port['human_mac'] . '</small></td>
          </tr>';
    } else {
        if ($vars['view'] == "details" || $vars['view'] == "detail") {
            $table_cols = '9';
            $string .= '<tr class="' . $port['row_class'] . '"';
            if ($vars['tab'] != "port") {
                $string .= ' onclick="openLink(\'' . generate_port_url($port) . '\')" style="cursor: pointer;"';
            }
            $string .= '>';
            $string .= '         <td class="state-marker"></td>
         <td style="width: 1px;"></td>';
            if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
                $table_cols++;
                // Increment table columns by one to make sure graph line draws correctly
                $string .= '    <td width="200"><span class="entity">' . generate_device_link($device, short_hostname($device['hostname'], "20")) . '</span><br />
                <span class="em">' . escape_html(truncate($port['location'], 32, "")) . '</span></td>';
            }
            $string .= '
         <td style="min-width: 250px;">';
            $string .= '        <span class="entity-title">
              ' . generate_port_link($port) . ' ' . $port['tags'] . '
           </span><br /><span class="small">' . escape_html($port['ifAlias']) . '</span>';
            if ($port['ifAlias']) {
                $string .= '<br />';
            }
            unset($break);
            if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) {
                foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip) {
                    $string .= $break . generate_popup_link('ip', $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'], NULL, 'small');
                    $break = "<br />";
                }
            }
            if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) {
                foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6) {
                    $string .= $break . generate_popup_link('ip', $ip6['ipv6_address'] . '/' . $ip6['ipv6_prefixlen'], NULL, 'small');
                    $break = "<br />";
                }
            }
            //$string .= '</span>';
            $string .= '</td>';
            // Print port graph thumbnails
            $string .= '<td style="width: 147px;">';
            $port['graph_type'] = "port_bits";
            $graph_array = array();
            $graph_array['to'] = $config['time']['now'];
            $graph_array['id'] = $port['port_id'];
            $graph_array['type'] = $port['graph_type'];
            $graph_array['width'] = 100;
            $graph_array['height'] = 20;
            $graph_array['bg'] = 'ffffff00';
            $graph_array['from'] = $config['time']['day'];
            $string .= generate_port_link($port, generate_graph_tag($graph_array));
            $port['graph_type'] = "port_upkts";
            $graph_array['type'] = $port['graph_type'];
            $string .= generate_port_link($port, generate_graph_tag($graph_array));
            $port['graph_type'] = "port_errors";
            $graph_array['type'] = $port['graph_type'];
            $string .= generate_port_link($port, generate_graph_tag($graph_array));
            $string .= '</td>';
            $string .= '<td style="width: 100px; white-space: nowrap;">';
            if ($port['ifOperStatus'] == "up" || $port['ifOperStatus'] == "monitoring") {
                // Colours generated by humanize_port
                $string .= '<i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />
      <i class="icon-circle-arrow-up"   style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br />
      <i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i> <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />
      <i class="icon-circle-arrow-up"   style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span>';
            }
            $string .= '</td><td style="width: 110px;">';
            if ($port['ifType'] && $port['ifType'] != "") {
                $string .= '<span class="small">' . $port['human_type'] . '</span>';
            } else {
                $string .= '-';
            }
            $string .= '<br />';
            if ($port['ifSpeed']) {
                $string .= '<span class="small">' . humanspeed($port['ifSpeed']) . '</span>';
            }
            if ($port['ifDuplex'] && $port['ifDuplex'] != "unknown") {
                $string .= '<span class="small"> (' . str_replace("Duplex", "", $port['ifDuplex']) . ')</span>';
            }
            $string .= '<br />';
            if ($port['ifMtu'] && $port['ifMtu'] != "") {
                $string .= '<span class="small">MTU ' . $port['ifMtu'] . '</span>';
            } else {
                $string .= '<span class="small">Unknown MTU</span>';
            }
            // if ($ifHardType && $ifHardType != "") { $string .= '<span class="small">" . $ifHardType . "</span>"); } else { $string .= '-'; }
            //$string .= '<br />';
            // Set VLAN data if the port has ifTrunk populated
            if ($port['ifTrunk']) {
                if ($port['ifVlan']) {
                    // Native VLAN
                    if (!isset($cache['ports_vlan'])) {
                        $native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port['port_id']));
                        $native_name = dbFetchCell('SELECT `vlan_name` FROM vlans     WHERE `device_id` = ? AND `vlan_vlan` = ?;', array($device['device_id'], $port['ifVlan']));
                    } else {
                        $native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state'];
                        $native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name'];
                    }
                    switch ($native_state) {
                        case 'blocking':
                            $class = 'text-danger';
                            break;
                        case 'forwarding':
                            $class = 'text-success';
                            break;
                        default:
                            $class = 'muted';
                    }
                    if (empty($native_name)) {
                        $native_name = 'VLAN' . str_pad($port['ifVlan'], 4, '0', STR_PAD_LEFT);
                    }
                    $native_tooltip = 'NATIVE: <strong class=' . $class . '>' . $port['ifVlan'] . ' [' . $native_name . ']</strong><br />';
                }
                if (!isset($cache['ports_vlan'])) {
                    $vlans = dbFetchRows('SELECT * FROM `ports_vlans` AS PV
                         LEFT JOIN vlans AS V ON PV.`vlan` = V.`vlan_vlan` AND PV.`device_id` = V.`device_id`
                         WHERE PV.`port_id` = ? AND PV.`device_id` = ? ORDER BY PV.`vlan`;', array($port['port_id'], $device['device_id']));
                } else {
                    $vlans = $cache['ports_vlan'][$port['port_id']];
                }
                $vlans_count = count($vlans);
                $rel = $vlans_count || $native_tooltip ? 'tooltip' : '';
                // Hide tooltip for empty
                $string .= '<p class="small"><a class="label label-info" data-rel="' . $rel . '" data-tooltip="<div class=\'small\' style=\'max-width: 320px; text-align: justify;\'>' . $native_tooltip;
                if ($vlans_count) {
                    $string .= 'ALLOWED: ';
                    $vlans_aggr = array();
                    foreach ($vlans as $vlan) {
                        if ($vlans_count > 20) {
                            // Aggregate VLANs
                            $vlans_aggr[] = $vlan['vlan'];
                        } else {
                            // List VLANs
                            switch ($vlan['state']) {
                                case 'blocking':
                                    $class = 'text-danger';
                                    break;
                                case 'forwarding':
                                    $class = 'text-success';
                                    break;
                                default:
                                    $class = 'muted';
                            }
                            if (empty($vlan['vlan_name'])) {
                                'VLAN' . str_pad($vlan['vlan'], 4, '0', STR_PAD_LEFT);
                            }
                            $string .= '<strong class=' . $class . '>' . $vlan['vlan'] . ' [' . $vlan['vlan_name'] . ']</strong><br />';
                        }
                    }
                    if ($vlans_count > 20) {
                        // End aggregate VLANs
                        $string .= '<strong>' . range_to_list($vlans_aggr, ', ') . '</strong>';
                    }
                }
                $string .= '</div>">' . $port['ifTrunk'] . '</a></p>';
            } else {
                if ($port['ifVlan']) {
                    if (!isset($cache['ports_vlan'])) {
                        $native_state = dbFetchCell('SELECT `state` FROM `ports_vlans` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port['port_id']));
                        $native_name = dbFetchCell('SELECT `vlan_name` FROM vlans     WHERE `device_id` = ? AND `vlan_vlan` = ?;', array($device['device_id'], $port['ifVlan']));
                    } else {
                        $native_state = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['state'];
                        $native_name = $cache['ports_vlan'][$port['port_id']][$port['ifVlan']]['vlan_name'];
                    }
                    switch ($native_state) {
                        case 'blocking':
                            $class = 'label-error';
                            break;
                        case 'forwarding':
                            $class = 'label-success';
                            break;
                        default:
                            $class = '';
                    }
                    $rel = $native_name ? 'tooltip' : '';
                    // Hide tooltip for empty
                    $string .= '<br /><span data-rel="' . $rel . '" class="label ' . $class . '"  data-tooltip="<strong class=\'small\'>' . $port['ifVlan'] . ' [' . $native_name . ']</strong>">VLAN ' . $port['ifVlan'] . '</span>';
                } else {
                    if ($port['ifVrf']) {
                        $vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", array($port['ifVrf']));
                        $string .= '<br /><span class="label label-success" data-rel="tooltip" data-tooltip="VRF">' . $vrf_name . '</span>';
                    }
                }
            }
            $string .= '</td>';
            // If the port is ADSL, print ADSL port data.
            if ($port_adsl['adslLineCoding']) {
                $string .= '<td style="width: 200px;"><span class="small">';
                $string .= '<span class="label">' . $port_adsl['adslLineCoding'] . '</span> <span class="label">' . rewrite_adslLineType($port_adsl['adslLineType']) . '</span>';
                $string .= '<br />';
                $string .= 'SYN <i class="icon-circle-arrow-down green"></i> ' . formatRates($port_adsl['adslAtucChanCurrTxRate']) . ' <i class="icon-circle-arrow-up blue"></i> ' . formatRates($port_adsl['adslAturChanCurrTxRate']);
                $string .= '<br />';
                //$string .= 'Max:'.formatRates($port_adsl['adslAtucCurrAttainableRate']) . '/'. formatRates($port_adsl['adslAturCurrAttainableRate']);
                //$string .= '<br />';
                $string .= 'ATN <i class="icon-circle-arrow-down green"></i> ' . $port_adsl['adslAtucCurrAtn'] . 'dBm <i class="icon-circle-arrow-up blue"></i> ' . $port_adsl['adslAturCurrAtn'] . 'dBm';
                $string .= '<br />';
                $string .= 'SNR <i class="icon-circle-arrow-down green"></i> ' . $port_adsl['adslAtucCurrSnrMgn'] . 'dB <i class="icon-circle-arrow-up blue"></i> ' . $port_adsl['adslAturCurrSnrMgn'] . 'dB';
                $string .= '</span>';
            } else {
                // Otherwise print normal port data
                $string .= '<td style="width: 150px;"><span class="small">';
                if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") {
                    $string .= $port['human_mac'];
                } else {
                    $string .= '-';
                }
                $string .= '<br />' . $port['ifLastChange'] . '</span>';
            }
            $string .= '</td>';
            $string .= '<td style="min-width: 200px" class="small">';
            if (strpos($port['port_label'], "oopback") === FALSE && !$graph_type) {
                unset($br);
                // Populate links array for ports with direct links
                if (!isset($cache['ports_option']['neighbours']) || in_array($port['port_id'], $cache['ports_option']['neighbours'])) {
                    foreach (dbFetchRows('SELECT * FROM `neighbours` WHERE `port_id` = ?', array($port['port_id'])) as $neighbour) {
                        // print_r($link);
                        if ($neighbour['remote_port_id']) {
                            $int_links[$neighbour['remote_port_id']] = $neighbour['remote_port_id'];
                            $int_links_phys[$neighbour['remote_port_id']] = 1;
                        } else {
                            $int_links_unknown[] = $neighbour;
                        }
                    }
                } else {
                }
                // Populate links array for devices which share an IPv4 subnet
                if (!isset($cache['ports_option']['ipv4_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv4_addresses'])) {
                    foreach (dbFetchColumn('SELECT DISTINCT(`ipv4_network_id`) FROM `ipv4_addresses`
                                 LEFT JOIN `ipv4_networks` USING(`ipv4_network_id`)
                                 WHERE `port_id` = ? AND `ipv4_network` NOT IN (?);', array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) {
                        $sql = 'SELECT N.*, P.`port_id`, P.`device_id` FROM `ipv4_addresses` AS A, `ipv4_networks` AS N, `ports` AS P
                   WHERE A.`port_id` = P.`port_id` AND P.`device_id` != ?
                   AND A.`ipv4_network_id` = ? AND N.`ipv4_network_id` = A.`ipv4_network_id`
                   AND P.`ifAdminStatus` = "up"';
                        $params = array($device['device_id'], $network_id);
                        foreach (dbFetchRows($sql, $params) as $new) {
                            if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) {
                                continue;
                            }
                            $int_links[$new['port_id']] = $new['port_id'];
                            $int_links_v4[$new['port_id']][] = $new['ipv4_network'];
                        }
                    }
                }
                // Populate links array for devices which share an IPv6 subnet
                if (!isset($cache['ports_option']['ipv6_addresses']) || in_array($port['port_id'], $cache['ports_option']['ipv6_addresses'])) {
                    foreach (dbFetchColumn("SELECT DISTINCT(`ipv6_network_id`) FROM `ipv6_addresses`\n                                 LEFT JOIN `ipv6_networks` USING(`ipv6_network_id`)\n                                 WHERE `port_id` = ? AND `ipv6_network` NOT IN (?);", array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) {
                        $sql = "SELECT N.*, P.`port_id`, P.`device_id` FROM `ipv6_addresses` AS A, `ipv6_networks` AS N, `ports` AS P\n                   WHERE A.`port_id` = P.`port_id` AND P.device_id != ?\n                   AND A.`ipv6_network_id` = ? AND N.`ipv6_network_id` = A.`ipv6_network_id`\n                   AND P.`ifAdminStatus` = 'up' AND A.`ipv6_origin` != 'linklayer' AND A.`ipv6_origin` != 'wellknown'";
                        $params = array($device['device_id'], $network_id);
                        foreach (dbFetchRows($sql, $params) as $new) {
                            if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) {
                                continue;
                            }
                            $int_links[$new['port_id']] = $new['port_id'];
                            $int_links_v6[$new['port_id']][] = $new['ipv6_network'];
                        }
                    }
                }
                // Output contents of links array
                foreach ($int_links as $int_link) {
                    $link_if = get_port_by_id_cache($int_link);
                    if (!device_permitted($link_if['device_id'])) {
                        continue;
                    }
                    // Skip not permitted links
                    $link_dev = device_by_id_cache($link_if['device_id']);
                    $string .= $br;
                    if ($int_links_phys[$int_link]) {
                        $string .= '<a data-alt="Directly connected" class="oicon-connect"></a> ';
                    } else {
                        $string .= '<a data-alt="Same subnet" class="oicon-network-hub"></a> ';
                    }
                    $string .= '<b>' . generate_port_link($link_if, $link_if['port_label_short']) . ' on ' . generate_device_link($link_dev, short_hostname($link_dev['hostname'])) . '</b>';
                    ## FIXME -- do something fancy here.
                    if ($int_links_v6[$int_link]) {
                        $string .= '&nbsp;' . overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL);
                    }
                    if ($int_links_v4[$int_link]) {
                        $string .= '&nbsp;' . overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL);
                    }
                    $br = "<br />";
                }
                // Output content of unknown links array (where ports don't exist in our database, or they weren't matched)
                foreach ($int_links_unknown as $int_link) {
                    // FIXME -- Expose platform and version here.
                    $string .= '<a data-alt="Directly connected" class="oicon-plug-connect"></a> ';
                    $string .= '<b><i>' . short_ifname($int_link['remote_port']) . '</i></b> on ';
                    $string .= '<i><b>' . generate_tooltip_link(NULL, $int_link['remote_hostname'], '<div class="small" style="max-width: 500px;"><b>' . $int_link['remote_platform'] . '</b><br />' . $int_link['remote_version'] . '</div>') . '</b></i>';
                    $string .= '<br />';
                }
            }
            if (!isset($cache['ports_option']['pseudowires']) || in_array($port['port_id'], $cache['ports_option']['pseudowires'])) {
                foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) {
                    //`port_id`,`peer_device_id`,`peer_ldp_id`,`pwID`,`pwIndex`
                    #    $pw_peer_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($pseudowire['peer_device_id']));
                    $pw_peer_int = dbFetchRow("SELECT * FROM `ports` AS I, `pseudowires` AS P WHERE I.`device_id` = ? AND P.`pwID` = ? AND P.`port_id` = I.`port_id`", array($pseudowire['peer_device_id'], $pseudowire['pwID']));
                    #    $pw_peer_int = get_port_by_id_cache($pseudowire['peer_device_id']);
                    $pw_peer_dev = device_by_id_cache($pseudowire['peer_device_id']);
                    if (is_array($pw_peer_int)) {
                        humanize_port($pw_peer_int);
                        $string .= $br . '<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, $pw_peer_int['port_label_short']) . ' on ' . generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>';
                    } else {
                        $string .= $br . '<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['pwID'] . ' on ' . $pseudowire['peer_addr'] . '</strong>';
                    }
                    $string .= ' <span class="label">' . $pseudowire['pwPsnType'] . '</span>';
                    $string .= ' <span class="label">' . $pseudowire['pwType'] . '</span>';
                    $br = "<br />";
                }
            }
            if (!isset($cache['ports_option']['ports_pagp']) || in_array($port['ifIndex'], $cache['ports_option']['ports_pagp'])) {
                foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? AND `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) {
                    humanize_port($member);
                    $pagp[$device['device_id']][$port['ifIndex']][$member['ifIndex']] = TRUE;
                    $string .= $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>';
                    $br = "<br />";
                }
            }
            if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) {
                $pagp[$device['device_id']][$port['pagpGroupIfIndex']][$port['ifIndex']] = TRUE;
                $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id']));
                humanize_port($parent);
                $string .= $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($parent) . ' [PAgP]</strong>';
                $br = "<br />";
            }
            if (!isset($cache['ports_option']['ports_stack_low']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_low'])) {
                foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $higher_if) {
                    if ($higher_if['port_id_high']) {
                        if ($pagp[$device['device_id']][$higher_if['port_id_high']][$port['ifIndex']]) {
                            continue;
                        }
                        // Skip if same PAgP port
                        $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
                        if (is_array($this_port)) {
                            $string .= $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($this_port) . '</strong>';
                            $br = "<br />";
                        }
                    }
                }
            }
            if (!isset($cache['ports_option']['ports_stack_high']) || in_array($port['ifIndex'], $cache['ports_option']['ports_stack_high'])) {
                foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $lower_if) {
                    if ($lower_if['port_id_low']) {
                        if ($pagp[$device['device_id']][$port['ifIndex']][$lower_if['port_id_low']]) {
                            continue;
                        }
                        // Skip if same PAgP ports
                        $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']);
                        if (is_array($this_port)) {
                            $string .= $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($this_port) . '</strong>';
                            $br = "<br />";
                        }
                    }
                }
            }
            unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
            $string .= '</td></tr>';
        }
    }
    // End Detailed View
    // If we're showing graphs, generate the graph and print the img tags
    if ($vars['graph'] == "etherlike") {
        $graph_file = get_port_rrdfilename($port, "dot3", TRUE);
    } else {
        $graph_file = get_port_rrdfilename($port, NULL, TRUE);
    }
    if ($vars['graph'] && is_file($graph_file)) {
        $string .= '<tr><td colspan="' . $table_cols . '">';
        $graph_array['to'] = $config['time']['now'];
        $graph_array['id'] = $port['port_id'];
        $graph_array['type'] = 'port_' . $vars['graph'];
        $string .= generate_graph_row($graph_array);
        $string .= '</td></tr>';
    }
    return $string;
}
예제 #9
0
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>No eventlog entries found!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['port'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th>Date</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>Device</th>' . PHP_EOL;
            }
            if ($list['port']) {
                $string .= '      <th>Entity</th>' . PHP_EOL;
            }
            $string .= '      <th>Message</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            $icon = geteventicon($entry['message']);
            if ($icon) {
                $icon = '<img src="images/16/' . $icon . '" />';
            }
            $string .= '  <tr>' . PHP_EOL;
            if ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $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' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['port']) {
                if ($entry['type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['reference']);
                    $entry['link'] = '<span class="entity">' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>';
                } else {
                    $entry['link'] = ucfirst($entry['type']);
                }
                if (!$events['short']) {
                    $string .= '    <td>' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">' . $entry['link'] . ' ';
            } else {
                $string .= '    <td>';
            }
            $string .= htmlspecialchars($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
예제 #10
0
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
{
    if (!is_array($device)) {
        $device = device_by_id_cache($device);
    }
    if ($device['ignore']) {
        return FALSE;
    }
    // Do not log events if device ignored
    if ($type == 'interface') {
        if (is_array($reference)) {
            $port = $reference;
            $reference = $port['port_id'];
        } else {
            $port = get_port_by_id_cache($reference);
        }
        if ($port['ignore']) {
            return FALSE;
        }
        // Do not log events if interface ignored
    }
    $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'reference' => $reference ? $reference : "NULL", 'type' => $type ? $type : "NULL", 'timestamp' => array("NOW()"), 'message' => $text);
    $id = dbInsert($insert, 'eventlog');
    return $id;
}
/**
 * Params:
 *
 * pagination, pageno, pagesize
 * device, port
 */
function get_pseudowires_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 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 'type':
                    //  $where .= generate_query_values($value, 'type');
                    //  break;
                    //case 'message':
                    //  $where .= generate_query_values($value, 'message', '%LIKE%');
                    //  break;
            }
        }
    }
    // Show pseudowires only for permitted devices and ports
    $query_permitted = generate_query_permitted(array('device', 'port'));
    $query = 'FROM `pseudowires` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    //$query_updated = 'SELECT MAX(`timestamp`) '.$query;
    $query = 'SELECT * ' . $query;
    //$query .= ' ORDER BY `event_id` DESC ';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query pseudowires
    foreach (dbFetchRows($query, $param) as $entry) {
        if ($entry['peer_addr']) {
            $peer_addr = $entry['peer_addr'];
        } else {
            if ($entry['pwMplsPeerLdpID']) {
                $peer_addr = preg_replace('/:\\d+$/', '', $pw['pwMplsPeerLdpID']);
            }
        }
        $peer_addr_type = get_ip_version($peer_addr);
        if ($peer_addr_type) {
            if ($peer_addr_type == 6) {
                $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE);
            }
            $peer_addr_type = 'ipv' . $peer_addr_type;
            $entry['peer_addr'] = $peer_addr;
            $entry['peer_addr_type'] = $peer_addr_type;
        } else {
            continue;
            // Peer address unknown
        }
        if (!is_array($cache_pseudowires['ips'][$peer_addr])) {
            $cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . generate_query_values($GLOBALS['cache']['ports']['pseudowires'], 'port_id') . ' LIMIT 1;', array($peer_addr));
            if (!is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id'])) {
                $cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . $GLOBALS['cache']['where']['ports_permitted'] . ' LIMIT 1;', array($peer_addr));
                if (is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id'])) {
                    // If we found port on remote device, than both devices in DB and will try to fix real port
                    $peer_port_tmp = get_port_by_id_cache($cache_pseudowires['ips'][$peer_addr]['port_id']);
                    $peer_port_fix = dbFetchCell('SELECT `port_id` FROM `pseudowires` WHERE `device_id` = ? AND `pwID` = ? LIMIT 1;', array($peer_port_tmp['device_id'], $entry['pwID']));
                    if (is_numeric($peer_port_fix)) {
                        $cache_pseudowires['ips'][$peer_addr]['port_id'] = $peer_port_fix;
                    }
                }
            }
            //$cache_pseudowires['ips'][$peer_addr]['host'] = $entry['reverse_dns'];
        }
        $entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id'];
        //$entry['peer_port']      = get_port_by_id_cache($entry['peer_port_id']);
        //$entry['peer_device_id'] = $entry['peer_port']['device_id'];
        //$entry['peer_device']    = device_by_id_cache($entry['peer_device_id']);
        $array['entries'][] = $entry;
    }
    // Query pseudowires count
    if ($array['pagination']) {
        $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);
    return $array;
}
예제 #12
0
/**
 * Display events.
 *
 * Display pages with device/port/system events on some formats.
 * Examples:
 * print_events() - display last 10 events from all devices
 * print_events(array('pagesize' => 99)) - display last 99 events from all device
 * print_events(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 events from page 3 with pagination header
 * print_events(array('pagesize' => 10, 'device' = 4)) - display last 10 events for device_id 4
 * print_events(array('short' => TRUE)) - show small block with last events
 *
 * @param array $vars
 * @return none
 *
 */
function print_events($vars)
{
    global $config;
    // Get events array
    $events = get_events_array($vars);
    if (!$events['count']) {
        // There have been no entries returned. Print the warning.
        print_warning('<h4>没有发现事件内容!</h4>');
    } else {
        // Entries have been returned. Print the table.
        $list = array('device' => FALSE, 'port' => FALSE);
        if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'eventlog') {
            $list['device'] = TRUE;
        }
        if ($events['short'] || !isset($vars['port']) || empty($vars['port'])) {
            $list['entity'] = TRUE;
        }
        $string = '<table class="table table-bordered table-striped table-hover table-condensed-more">' . PHP_EOL;
        if (!$events['short']) {
            $string .= '  <thead>' . PHP_EOL;
            $string .= '    <tr>' . PHP_EOL;
            $string .= '      <th class="state-marker"></th>' . PHP_EOL;
            $string .= '      <th>日期</th>' . PHP_EOL;
            if ($list['device']) {
                $string .= '      <th>设备</th>' . PHP_EOL;
            }
            if ($list['entity']) {
                $string .= '      <th>单位</th>' . PHP_EOL;
            }
            $string .= '      <th>信息</th>' . PHP_EOL;
            $string .= '    </tr>' . PHP_EOL;
            $string .= '  </thead>' . PHP_EOL;
        }
        $string .= '  <tbody>' . PHP_EOL;
        foreach ($events['entries'] as $entry) {
            #$icon = geteventicon($entry['message']);
            #if ($icon) { $icon = '<img src="images/16/' . $icon . '" />'; }
            switch ($entry['severity']) {
                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 ($events['short']) {
                $string .= '    <td class="syslog" style="white-space: nowrap">';
                $timediff = $GLOBALS['config']['time']['now'] - strtotime($entry['timestamp']);
                $string .= overlib_link('', formatUptime($timediff, "short-3"), format_timestamp($entry['timestamp']), NULL) . '</td>' . PHP_EOL;
            } else {
                $string .= '    <td style="width: 160px">';
                $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' => 'eventlog');
                $string .= '    <td class="entity">' . generate_device_link($dev, short_hostname($dev['hostname']), $device_vars) . '</td>' . PHP_EOL;
            }
            if ($list['entity']) {
                if ($entry['entity_type'] == 'device' && !$entry['entity_id']) {
                    $entry['entity_id'] = $entry['device_id'];
                }
                if ($entry['entity_type'] == 'port') {
                    $this_if = get_port_by_id_cache($entry['entity_id']);
                    $entry['link'] = '<span class="entity"><i class="' . $config['entities']['port']['icon'] . '"></i> ' . generate_port_link($this_if, short_ifname($this_if['label'])) . '</span>';
                } else {
                    if (!empty($config['entities'][$entry['entity_type']]['icon'])) {
                        $entry['link'] = '<i class="' . $config['entities'][$entry['entity_type']]['icon'] . '"></i> ' . generate_entity_link($entry['entity_type'], $entry['entity_id']);
                    } else {
                        $entry['link'] = nicecase($entry['entity_type']);
                    }
                }
                if (!$events['short']) {
                    $string .= '    <td>' . $entry['link'] . '</td>' . PHP_EOL;
                }
            }
            if ($events['short']) {
                $string .= '    <td class="syslog">';
                if (strpos($entry['message'], $entry['link']) !== 0) {
                    $string .= $entry['link'] . ' ';
                }
            } else {
                $string .= '    <td>';
            }
            $string .= escape_html($entry['message']) . '</td>' . PHP_EOL;
            $string .= '  </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        // Print pagination header
        if ($events['pagination_html']) {
            $string = $events['pagination_html'] . $string . $events['pagination_html'];
        }
        // Print events
        echo $string;
    }
}
예제 #13
0
function get_port_by_index_cache($device, $ifIndex)
{
    global $cache;
    if (is_array($device) && isset($device['device_id'])) {
        $device_id = $device['device_id'];
    } else {
        if (is_numeric($device)) {
            $device_id = $device;
        }
    }
    if (!isset($device_id) || !is_numeric($ifIndex)) {
        print_error("无效的参数通过函数 get_port_by_index_cache(). 请报告给开发小组.");
    }
    if (isset($cache['port_index'][$device_id][$ifIndex]) && is_numeric($cache['port_index'][$device_id][$ifIndex])) {
        $id = $cache['port_index'][$device_id][$ifIndex];
    } else {
        $id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device_id, $ifIndex));
        if (is_numeric($id)) {
            $cache['port_index'][$device_id][$ifIndex] = $id;
        }
    }
    $port = get_port_by_id_cache($id);
    if (is_array($port)) {
        return $port;
    }
    return FALSE;
}
예제 #14
0
function get_pseudowire_table($vars)
{
    $sql = generate_pseudowire_query($vars);
    $entries = array();
    foreach (dbFetchRows($sql) as $entry) {
        if (!isset($GLOBALS['cache']['devices']['id'][$entry['device_id']])) {
            continue;
        }
        // Device hostname
        $entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname'];
        // Remote Peer
        $peer_addr = $entry['peer_addr'];
        $peer_addr_type = get_ip_version($peer_addr);
        if ($peer_addr_type && $entry['peer_device_id']) {
            if ($peer_addr_type == 6) {
                $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE);
            }
            $peer_addr_type = 'ipv' . $peer_addr_type;
            //$entry['peer_addr']      = $peer_addr;
            //$entry['peer_addr_type'] = $peer_addr_type;
            if (!is_array($cache_pseudowires['ips'][$peer_addr])) {
                $cache_pseudowires['ips'][$peer_addr]['port_id'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . generate_query_values($GLOBALS['cache']['ports']['pseudowires'], 'port_id') . ' LIMIT 1;', array($peer_addr));
                if (!is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id'])) {
                    // Separate entry for find correct port
                    $cache_pseudowires['ips'][$peer_addr]['port_id_fix'] = dbFetchCell('SELECT `port_id` FROM `' . $peer_addr_type . '_addresses` WHERE `' . $peer_addr_type . '_address` = ? ' . $GLOBALS['cache']['where']['ports_permitted'] . ' LIMIT 1;', array($peer_addr));
                }
                //$cache_pseudowires['ips'][$peer_addr]['host'] = $entry['reverse_dns'];
            }
            $entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id'];
            if (is_numeric($cache_pseudowires['ips'][$peer_addr]['port_id_fix'])) {
                // If we found port on remote device, than both devices in DB and will try to fix real port
                $peer_port_tmp = get_port_by_id_cache($cache_pseudowires['ips'][$peer_addr]['port_id_fix']);
                $peer_port_fix = dbFetchCell('SELECT `port_id` FROM `pseudowires` WHERE `device_id` = ? AND `pwID` = ? LIMIT 1;', array($peer_port_tmp['device_id'], $entry['pwID']));
                if (is_numeric($peer_port_fix)) {
                    $entry['peer_port_id'] = $peer_port_fix;
                } else {
                    $entry['peer_port_id'] = $cache_pseudowires['ips'][$peer_addr]['port_id_fix'];
                }
            }
            //r($entry['peer_port_id']);
            if ($entry['peer_port_id']) {
                $entry['peer_port'] = get_port_by_id_cache($entry['peer_port_id']);
                //r($entry['peer_port']);
                $entry['peer_device_id'] = $entry['peer_port']['device_id'];
                //r($entry['peer_device_id']);
                $entry['peer_device'] = device_by_id_cache($entry['peer_device_id']);
            }
        }
        $entry['hostname'] = $GLOBALS['cache']['devices']['id'][$entry['device_id']]['hostname'];
        // Attach hostname for sorting
        $entries[] = $entry;
    }
    // Sorting
    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':
            $entries = array_sort_by($entries, 'hostname', $sort_order, SORT_STRING);
            break;
        case 'pwid':
            $entries = array_sort_by($entries, 'pwID', $sort_order, SORT_NUMERIC);
            break;
        case 'pwtype':
            $entries = array_sort_by($entries, 'pwType', $sort_order, SORT_STRING, 'pwPsnType', $sort_order, SORT_STRING);
            //$pws = array_sort_by($pws, 'pwType',  $sort_order, SORT_STRING);
            break;
        case 'peer_addr':
            $entries = array_sort_by($entries, 'peer_addr', $sort_order, SORT_NUMERIC);
            break;
        case 'event':
            $entries = array_sort_by($entries, 'event', $sort_order, SORT_STRING);
            break;
        case 'uptime':
            $entries = array_sort_by($entries, 'pwUptime', $sort_order, SORT_NUMERIC);
            break;
        case 'last_change':
            $entries = array_sort_by($entries, 'last_change', $sort_neg, SORT_NUMERIC);
            break;
        case 'status':
            $entries = array_sort_by($entries, 'pwOperStatus', $sort_order, SORT_STRING);
            break;
        default:
            // Not sorted
    }
    return $entries;
}
예제 #15
0
function get_port_by_index_cache($device_id, $ifIndex)
{
    global $cache;
    if (isset($cache['port_index'][$device_id][$ifIndex]) && is_numeric($cache['port_index'][$device_id][$ifIndex])) {
        $id = $cache['port_index'][$device_id][$ifIndex];
    } else {
        $id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device_id, $ifIndex));
        if (is_numeric($id)) {
            $cache['port_index'][$device_id][$ifIndex] = $id;
        }
    }
    $port = get_port_by_id_cache($id);
    if (is_array($port)) {
        return $port;
    }
    return FALSE;
}
예제 #16
0
 if (!isset($ports_has_ext['ipv6_addresses']) || in_array($port['port_id'], $ports_has_ext['ipv6_addresses'])) {
     foreach (dbFetchColumn("SELECT A6.`ipv6_network_id` FROM `ipv6_addresses` AS A6\n         LEFT JOIN `ipv6_networks` AS N6 ON A6.`ipv6_network_id` = N6.`ipv6_network_id`\n         WHERE `port_id` = ? AND `ipv6_network` NOT IN (?) GROUP BY A6.`ipv6_network_id`", array($port['port_id'], $config['ignore_common_subnet'])) as $network_id) {
         $ipv6_network_id = $net['ipv6_network_id'];
         $sql = "SELECT P.`port_id`, P.`device_id` FROM `ipv6_addresses` AS A, `ipv6_networks` AS N, `ports` AS P\n                WHERE A.`port_id` = P.`port_id` AND P.device_id != ?\n                AND A.`ipv6_network_id` = ? AND N.`ipv6_network_id` = A.`ipv6_network_id`\n                AND P.`ifAdminStatus` = 'up' AND A.`ipv6_origin` != 'linklayer' AND A.`ipv6_origin` != 'wellknown'";
         $params = array($device['device_id'], $network_id);
         foreach (dbFetchRows($sql, $params) as $new) {
             if ($cache['devices']['id'][$new['device_id']]['disabled'] && !$config['web_show_disabled']) {
                 continue;
             }
             $int_links[$new['port_id']] = $new['port_id'];
             $int_links_v6[$new['port_id']][] = $new['port_id'];
         }
     }
 }
 foreach ($int_links as $int_link) {
     $link_if = get_port_by_id_cache($int_link);
     $link_dev = device_by_id_cache($link_if['device_id']);
     echo $br;
     if ($int_links_phys[$int_link]) {
         echo '<a alt="Directly connected" class="oicon-connect"></a> ';
     } else {
         echo '<a alt="Same subnet" class="oicon-network-hub"></a> ';
     }
     echo "<b>" . generate_port_link($link_if, short_ifname($link_if['label'])) . " on " . generate_device_link($link_dev, short_hostname($link_dev['hostname'])) . "</b>";
     ## FIXME -- do something fancy here.
     if ($int_links_v6[$int_link]) {
         echo ' ', overlib_link('', '<span class="label label-success">IPv6</span>', implode("<br />", $int_links_v6[$int_link]), NULL);
     }
     if ($int_links_v4[$int_link]) {
         echo ' ', overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL);
     }
예제 #17
0
function get_port_id_by_customer($customer)
{
    $where = ' WHERE 1';
    if (is_array($customer)) {
        foreach ($customer as $var => $value) {
            if ($value != '') {
                switch ($var) {
                    case 'device':
                    case 'device_id':
                        $where .= generate_query_values($value, 'device_id');
                        break;
                    case 'type':
                    case 'descr':
                    case 'circuit':
                    case 'speed':
                    case 'notes':
                        $where .= generate_query_values($value, 'port_descr_' . $var);
                        break;
                }
            }
        }
    } else {
        return FALSE;
    }
    $query = 'SELECT `port_id` FROM `ports` ' . $where . ' ORDER BY `ifOperStatus` DESC';
    $ids = dbFetchColumn($query);
    //print_vars($ids);
    switch (count($ids)) {
        case 0:
            return FALSE;
        case 1:
            return $ids[0];
            break;
        default:
            foreach ($ids as $port_id) {
                $port = get_port_by_id_cache($port_id);
                $device = device_by_id_cache($port['device_id']);
                if ($device['disabled'] || !$device['status']) {
                    continue;
                    // switch to next ID
                }
                break;
            }
            return $port_id;
    }
    return FALSE;
}