Beispiel #1
0
function process_port_label(&$this_port, $device)
{
    global $config;
    // OS Specific rewrites (get your shit together, vendors)
    if ($device['os'] == 'zxr10') {
        $this_port['ifAlias'] = preg_replace("/^" . str_replace("/", "\\/", $this_port['ifName']) . "\\s*/", '', $this_port['ifDescr']);
    }
    if ($device['os'] == 'ciscosb' && $this_port['ifType'] == 'propVirtual' && is_numeric($this_port['ifDescr'])) {
        $this_port['ifName'] = 'Vl' . $this_port['ifDescr'];
    }
    $this_port['ifAlias'] = snmp_fix_string($this_port['ifAlias']);
    // Fix ord chars
    // Added for Brocade NOS. Will copy ifDescr -> ifAlias if ifDescr != ifName
    // ifAlias can be passed over SW-MIB
    if ($config['os'][$device['os']]['ifDescr_ifAlias'] && $this_port['ifAlias'] == '' && $this_port['ifDescr'] != $this_port['ifName']) {
        $this_port['ifAlias'] = $this_port['ifDescr'];
    }
    // Write port_label, port_label_base and port_label_num
    // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2
    // Note, only for 'calix' os now
    if ($device['os'] == 'calix') {
        unset($config['os'][$device['os']]['ifname']);
        $version_parts = explode('.', $device['version']);
        if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) {
            if ($this_port['ifName'] == '') {
                $this_port['port_label'] = $this_port['ifDescr'];
            } else {
                $this_port['port_label'] = $this_port['ifName'];
            }
        }
    }
    if ($this_port['ifDescr'] === '' && $config['os'][$device['os']]['ifType_ifDescr'] && $this_port['ifIndex']) {
        // This happen on some liebert UPS devices
        $type = rewrite_iftype($this_port['ifType']);
        if ($type) {
            $this_port['ifDescr'] = $type . ' ' . $this_port['ifIndex'];
            print_debug("Port 'ifDescr' rewritten: '' -> '" . $this_port['ifDescr'] . "'");
        }
    }
    if (isset($config['os'][$device['os']]['ifname'])) {
        if ($this_port['ifName'] == '') {
            $this_port['port_label'] = $this_port['ifDescr'];
        } else {
            $this_port['port_label'] = $this_port['ifName'];
        }
    } else {
        if (isset($config['os'][$device['os']]['ifalias'])) {
            $this_port['port_label'] = $this_port['ifAlias'];
        } else {
            $this_port['port_label'] = $this_port['ifDescr'];
            if (isset($config['os'][$device['os']]['ifindex'])) {
                $this_port['port_label'] .= ' ' . $this_port['ifIndex'];
            }
        }
    }
    if ($device['os'] == "speedtouch") {
        list($this_port['port_label']) = explode("thomson", $this_port['port_label']);
    }
    // Process label by os definition rewrites
    $oid = 'port_label';
    if (isset($config['os'][$device['os']][$oid])) {
        $oid_base = $oid . '_base';
        $oid_num = $oid . '_num';
        foreach ($config['os'][$device['os']][$oid] as $pattern) {
            if (preg_match($pattern, $this_port[$oid], $matches)) {
                print_debug("Port '{$oid}' rewritten: '" . $this_port[$oid] . "' -> '" . $matches[1] . "'");
                $this_port[$oid] = $matches[1];
                if (isset($matches[$oid_base])) {
                    $this_port[$oid_base] = $matches[$oid_base];
                }
                if (isset($matches[$oid_num])) {
                    $this_port[$oid_num] = $matches[$oid_num];
                }
                break;
            }
        }
    }
    // Extract bracket part from port label and remove it
    $label_bracket = '';
    if (preg_match('/\\s*(\\([^\\)]+\\))$/', $this_port['port_label'], $matches)) {
        // GigaVUE-212 Port  8/48 (Network Port)
        // rtif(172.20.30.46/28)
        $label_bracket = $matches[0];
        list($this_port['port_label']) = explode($matches[0], $this_port['port_label'], 2);
    }
    // Detect port_label_base and port_label_num
    if (isset($this_port['port_label_base'])) {
    } else {
        if (preg_match('/\\d+(?:(?:[\\/:](?:[a-z])?[\\d\\.:]+)+[a-z\\d\\.\\:]*(?:[\\-\\_][\\w\\.\\:]+)*|\\/\\w+$)/i', $this_port['port_label'], $matches)) {
            // Multipart numeric
            /*
            1/1/1
            e1-0/0/1.0
            e1-0/2/0:13.0
            dwdm0/1/0/6
            DTI1/1/0
            Cable8/1/4-upstream2
            Cable8/1/4
            16GigabitEthernet1/2/1
            cau4-0/2/0
            dot11radio0/0
            Dialer0/0.1
            Downstream 0/2/0
            1000BaseTX Port 8/48 Name
            Backplane-GigabitEthernet0/3
            Ethernet1/10
            FC port 0/19
            GigabitEthernet0/0/0/1
            GigabitEthernet0/1.ServiceInstance.206
            Integrated-Cable7/0/0:0
            Logical Upstream Channel 1/0.0/0
            Slot0/1
            sonet_12/1
            GigaVUE-212 Port  8/48 (Network Port)
            Stacking Port 1/StackA
            1:38
            1/4/x24, mx480-xe-0-0-0
            1/4/x24
            */
            $this_port['port_label_num'] = $matches[0];
            list($this_port['port_label_base']) = explode($matches[0], $this_port['port_label'], 2);
            $this_port['port_label'] = $this_port['port_label_base'] . $this_port['port_label_num'];
            // Remove additional part (after port number)
        } else {
            if (preg_match('/(?<port_label_num>(?:\\d+[a-z])?\\d[\\d\\.\\:]*(?:[\\-\\_]\\w+)?)(?: [a-z()\\[\\] ]+)?$/i', $this_port['port_label'], $matches)) {
                // Simple numeric
                /*
                GigaVUE-212 Port  1 (Network Port)
                MMC-A s3 SW Port
                Atm0_Physical_Interface
                wan1_phys
                fwbr101i0
                Nortel Ethernet Switch 325-24G Module - Port 1
                lo0.32768
                vlan.818
                jsrv.1
                Bundle-Ether1.1701
                Ethernet1
                ethernet_13
                eth0
                eth0.101
                BVI900
                A/1
                e1
                CATV-MAC 1
                16
                */
                $this_port['port_label_num'] = $matches['port_label_num'];
                $this_port['port_label_base'] = substr($this_port['port_label'], 0, 0 - strlen($matches[0]));
                $this_port['port_label'] = $this_port['port_label_base'] . $this_port['port_label_num'];
                // Remove additional part (after port number)
            } else {
                // All other (non-numeric)
                /*
                UniPing Server Solution v3/SMS Enet Port
                MMC-A s2 SW Port
                Control Plane
                */
                $this_port['port_label_base'] = $this_port['port_label'];
            }
        }
    }
    // When not empty label brackets and empty numeric part, re-add brackets to label
    if (!empty($label_bracket) && $this_port['port_label_num'] == '') {
        // rtif(172.20.30.46/28)
        $this_port['port_label'] .= $label_bracket;
    }
    $this_port['port_label_short'] = short_ifname($this_port['port_label']);
    // Set entity variables for use by code which uses entities
    // Base label part: TenGigabitEthernet3/3 -> TenGigabitEthernet, GigabitEthernet4/8.722 -> GigabitEthernet, Vlan2603 -> Vlan
    //$port['port_label_base'] = preg_replace('/^([A-Za-z ]*).*/', '$1', $port['port_label']);
    //$port['port_label_num']  = substr($port['port_label'], strlen($port['port_label_base'])); // Second label part
    //
    //  // Index example for TenGigabitEthernet3/10.324:
    //  //  $ports_links['Ethernet'][] = array('label_base' => 'TenGigabitEthernet', 'label_num0' => '3', 'label_num1' => '10', 'label_num2' => '324')
    //  $label_num  = preg_replace('![^\d\.\/]!', '', substr($data['port_label'], strlen($data['port_label_base']))); // Remove base part and all not-numeric chars
    //  preg_match('!^(\d+)(?:\/(\d+)(?:\.(\d+))*)*!', $label_num, $label_nums); // Split by slash and point (1/1.324)
    //  $ports_links[$data['human_type']][$data['ifIndex']] = array(
    //    'label'      => $data['port_label'],
    //    'label_base' => $data['port_label_base'],
    //    'label_num0' => $label_nums[0],
    //    'label_num1' => $label_nums[1],
    //    'label_num2' => $label_nums[2],
    //    'link'       => generate_port_link($data, $data['port_label_short'])
    //  );
    return TRUE;
}
<?php

$i = 0;
foreach (explode(",", $vars['id']) as $ifid) {
    $port = dbFetchRow("SELECT * FROM `ports` AS I, devices as D WHERE I.port_id = ? AND I.device_id = D.device_id", array($ifid));
    $rrdfile = get_port_rrdfilename($port, $port);
    if (is_file($rrdfile)) {
        humanize_port($port);
        $rrd_list[$i]['filename'] = $rrdfile;
        $rrd_list[$i]['descr'] = $port['hostname'] . " " . $port['ifDescr'];
        $rrd_list[$i]['descr_in'] = $port['hostname'];
        $rrd_list[$i]['descr_out'] = short_ifname($port['label']);
        $i++;
    }
}
$units = 'b';
$total_units = 'B';
$colours_in = 'greens';
$multiplier = "8";
$colours_out = 'blues';
$ds_in = "INOCTETS";
$ds_out = "OUTOCTETS";
include "includes/graphs/generic_multi_bits_separated.inc.php";
Beispiel #3
0
         echo "\n  [VRF {$vrf_name}] OID   - " . $vrf_oid;
         echo "\n  [VRF {$vrf_name}] RD    - " . $vrf_rd;
         echo "\n  [VRF {$vrf_name}] DESC  - " . $descr_table[$vrf_oid];
         if (dbFetchCell('SELECT COUNT(*) FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid))) {
             $update_array = array('mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd);
             dbUpdate($update_array, 'vrfs', '`device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid));
         } else {
             $insert_array = array('device_id' => $device['device_id'], 'vrf_oid' => $vrf_oid, 'vrf_name' => $vrf_name, 'mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd);
             dbInsert($insert_array, 'vrfs');
         }
         $vrf_id = dbFetchCell('SELECT vrf_id FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid));
         $valid_vrf[$vrf_id] = 1;
         echo "\n  [VRF {$vrf_name}] PORTS - ";
         foreach ($port_table[$vrf_oid] as $if_id) {
             $interface = dbFetchRow('SELECT ifDescr, port_id FROM ports WHERE ifIndex = ? AND device_id = ?', array($if_id, $device['device_id']));
             echo short_ifname($interface['ifDescr']) . " ";
             dbUpdate(array('ifVrf' => $vrf_id), 'ports', '`port_id` = ?', array($interface['port_id']));
             $if = $interface['port_id'];
             $valid_vrf_if[$vrf_id][$if] = 1;
         }
     }
 }
 echo "\n";
 foreach (dbFetchRows('SELECT * FROM ports WHERE device_id = ?', array($device['device_id'])) as $row) {
     $if = $row['port_id'];
     $vrf_id = $row['ifVrf'];
     if ($row['ifVrf']) {
         if (!$valid_vrf_if[$vrf_id][$if]) {
             echo "-";
             dbUpdate(array('ifVrf' => NULL), 'ports', '`port_id` = ?', array($if));
         } else {
Beispiel #4
0
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage graphs
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
// Generate a list of ports and then call the multi_bits grapher to generate from the list
$i = 0;
foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE `port_descr_type` = 'cust' AND `port_descr_descr` = ? AND D.device_id = I.device_id", array($vars['id'])) as $port) {
    $rrd_filename = get_port_rrdfilename($port, NULL, TRUE);
    if (is_file($rrd_filename)) {
        $rrd_list[$i]['filename'] = $rrd_filename;
        $rrd_list[$i]['descr'] = $port['hostname'] . "-" . $port['ifDescr'];
        $rrd_list[$i]['descr_in'] = short_hostname($port['hostname']);
        $rrd_list[$i]['descr_out'] = short_ifname($port['ifDescr'], NULL, FALSE);
        // Options sets for skip htmlentities
        $i++;
    }
}
$units = 'b';
$total_units = 'B';
$colours_in = 'greens';
$multiplier = "8";
$colours_out = 'blues';
$nototal = 1;
$ds_in = "INOCTETS";
$ds_out = "OUTOCTETS";
include "includes/graphs/generic_multi_bits_separated.inc.php";
<?php

// FIXME new url format
if (is_integer($i / 2)) {
    $bg_colour = $list_colour_a;
} else {
    $bg_colour = $list_colour_b;
}
echo "<tr bgcolor='{$bg_colour}'>";
echo "<td width=200 class=entity-title><a href='routing/vrf/" . $vrf['mplsVpnVrfRouteDistinguisher'] . "/'>" . $vrf['vrf_name'] . "</a></td>";
echo "<td width=150 class=small>" . $vrf['mplsVpnVrfDescription'] . "</td>";
echo "<td width=100 class=small>" . $vrf['mplsVpnVrfRouteDistinguisher'] . "</td>";
echo '<td class="entity">';
foreach (dbFetchRows("SELECT * FROM ports WHERE `device_id` = ? AND `ifVrf` = ?", array($device['device_id'], $vrf['vrf_id'])) as $port) {
    if ($vars['view'] == "graphs") {
        $graph_type = "port_" . $vars['graph'];
        echo "<div style='display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: #e9e9e9;'>\n    <div style='font-weight: bold;'>" . short_ifname($port['ifDescr']) . "</div>\n    <a href='device/" . $device['device_id'] . "/port/" . $port['port_id'] . "/' onmouseover=\"return overlib('\\\n    <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\\'>" . $device['hostname'] . " - " . $port['ifDescr'] . "</div>\\\n    " . $port['ifAlias'] . " \\\n    <img src=\\'graph.php?type={$graph_type}&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n    ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\"  >" . "<img src='graph.php?type={$graph_type}&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=132&amp;height=40&amp;legend=no'>\n    </a>\n    <div style='font-size: 9px;'>" . short_port_descr($port['ifAlias']) . "</div>\n   </div>";
    } else {
        echo $vrf['port_sep'] . generate_port_link($port, short_ifname($port['ifDescr']));
        $vrf['port_sep'] = ", ";
    }
}
echo "</td>";
echo "</tr>";
Beispiel #6
0
            if ($port_id) {
                $vars['id'] = $port_id;
            }
        } elseif (!empty($vars['ifalias'])) {
            // Get port by ifAlias
            $port_id = get_port_id_by_ifAlias($device['device_id'], $vars['ifalias']);
            if ($port_id) {
                $vars['id'] = $port_id;
            }
        }
    } elseif (!empty($vars['circuit'])) {
        // Get port by circuit id
        $port_id = get_port_id_by_customer(array('circuit' => $vars['circuit']));
        if ($port_id) {
            $vars['id'] = $port_id;
        }
    }
}
if (is_numeric($vars['id']) && ($auth || port_permitted($vars['id']))) {
    $port = get_port_by_id($vars['id']);
    $device = device_by_id_cache($port['device_id']);
    $title = generate_device_link($device);
    $title .= " :: Port  <b>" . generate_port_link($port) . "</b>";
    $title_array = array();
    $title_array[] = array('text' => $device['hostname'], 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'])));
    $title_array[] = array('text' => 'Ports', 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'ports')));
    $title_array[] = array('text' => rewrite_ifname($port['label']), 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id'])));
    $graph_title = short_hostname($device['hostname']) . " :: " . strtolower(short_ifname($port['ifDescr'], NULL, FALSE));
    $auth = TRUE;
    $rrd_filename = get_port_rrdfilename($port, NULL, TRUE);
}
Beispiel #7
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;
}
/**
 * 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;
    }
}
Beispiel #9
0
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
echo '<tr>';
echo '<td style="width: 100px;" class="entity-title"> Vlan ' . $vlan['vlan_vlan'] . '</td>';
echo '<td style="width: 200px;" class="small">' . $vlan['vlan_name'] . '</td>';
echo '<td class="strong">';
$vlan_ports = array();
$otherports = dbFetchRows("SELECT * FROM `ports_vlans` AS V, `ports` as P WHERE V.`device_id` = ? AND V.`vlan` = ? AND P.port_id = V.port_id", array($device['device_id'], $vlan['vlan_vlan']));
foreach ($otherports as $otherport) {
    $vlan_ports[$otherport['ifIndex']] = $otherport;
}
$otherports = dbFetchRows("SELECT * FROM ports WHERE `device_id` = ? AND `ifVlan` = ?", array($device['device_id'], $vlan['vlan_vlan']));
foreach ($otherports as $otherport) {
    $vlan_ports[$otherport['ifIndex']] = array_merge($otherport, array('untagged' => '1'));
}
ksort($vlan_ports);
foreach ($vlan_ports as $port) {
    humanize_port($port);
    if ($vars['view'] == "graphs") {
        echo "<div style='display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: " . $list_colour_b_b . ";'>\n    <div style='font-weight: bold;'>" . short_ifname($port['ifDescr']) . "</div>\n    <a href='device/device=" . $device['device_id'] . "/tab=port/port=" . $port['port_id'] . "/' onmouseover=\"return overlib('\\\n    <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\\'>" . $device['hostname'] . " - " . $port['ifDescr'] . "</div>\\\n    " . $port['ifAlias'] . " \\\n    <img src=\\'graph.php?type={$graph_type}&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n    ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\"  >" . "<img src='graph.php?type={$graph_type}&amp;id=" . $port['port_id'] . "&amp;from=" . $config['time']['twoday'] . "&amp;to=" . $config['time']['now'] . "&amp;width=132&amp;height=40&amp;legend=no'>\n    </a>\n    <div style='font-size: 9px;'>" . short_port_descr($port['ifAlias']) . "</div>\n   </div>";
    } else {
        echo $vlan['port_sep'] . generate_port_link($port, short_ifname($port['label']));
        $vlan['port_sep'] = ", ";
        if ($port['untagged']) {
            echo "(U)";
        }
    }
}
echo '</td></tr>';
// EOF
                     case 'bits':
                     case 'upkts':
                     case 'nupkts':
                     case 'errors':
                         $port['width'] = "130";
                         $port['height'] = "30";
                         $port['from'] = $config['time']['day'];
                         $port['to'] = $config['time']['now'];
                         $port['bg'] = "#" . $bg;
                         $port['graph_type'] = "port_" . $_GET['optc'];
                         echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 135px; max-width:135px; min-height:75px; max-height:75px;\n               text-align: center; float: left; background-color: " . $list_colour_b_b . ";'>\n               <div style='font-weight: bold;'>" . short_ifname($port['ifDescr']) . "</div>";
                         generate_port_thumbnail($port);
                         echo "<div style='font-size: 9px;'>" . short_port_descr($port['ifAlias']) . "</div>\n              </div>";
                         break;
                     default:
                         echo $seperator . generate_port_link($port, short_ifname($port['ifDescr']));
                         $seperator = ", ";
                         break;
                 }
             }
             echo "</td></tr>";
             $x++;
         }
         // End While
         echo "</table></td>";
         $i++;
     }
     echo "</table></div>";
 } else {
     echo "<div style='background: {$list_colour_a}; padding: 10px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>";
     $vrf = dbFetchRow("SELECT * FROM `vrfs` WHERE mplsVpnVrfRouteDistinguisher = ?", array($_GET['optb']));
    unset($sub);
    $hostname = $ip['hostname'];
    $real_hostname = $hostname;
    $hostname = str_replace(".jerseytelecom.net", "", $hostname);
    list($cc, $loc, $host) = explode(".", $hostname);
    if ($host) {
        $hostname = "{$host}.{$loc}.{$cc}.v4.data.net.uk";
    } else {
        $host = $cc;
        unset($cc);
        $hostname = "{$host}.v4.data.net.uk";
    }
    $interface = $ip['ifDescr'];
    $address = $ip['ipv4_address'];
    $cidr = $ip['ipv4_prefixlen'];
    $interface = short_ifname($interface);
    $interface = str_replace("/", "-", $interface);
    $interface = str_replace(":", "_", $interface);
    list($interface, $sub) = explode(".", $interface);
    if ($sub) {
        $sub = str_replace(" ", "", $sub);
        $sub = str_replace("aal5", "", $sub);
        $interface = "{$sub}.{$interface}";
    }
    $hostip = trim(gethostbyname($real_hostname));
    list($first, $second, $third, $fourth) = explode(".", $address);
    $revzone = "{$third}.{$second}.{$first}.in-addr.arpa";
    $reverse = "{$fourth}.{$revzone}";
    $dnsname = "{$interface}.{$hostname}";
    $dns_list[] = str_pad($revzone, 24) . "|" . str_pad($reverse, 30) . "IN ADDR  " . str_pad($dnsname, 30);
}
Beispiel #12
0
/**
 * Display IPv4/IPv6 addresses.
 *
 * Display pages with IP addresses from device Interfaces.
 *
 * @param array $vars
 * @return none
 *
 */
function print_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;
    switch ($vars['search']) {
        case '6':
        case 'ipv6':
        case 'v6':
            $address_type = 'ipv6';
            break;
        default:
            $address_type = 'ipv4';
    }
    $ip_array = array();
    $param = array();
    $where = ' WHERE 1 ';
    $param_netscaler = array();
    $where_netscaler = " WHERE `vsvr_ip` != '0.0.0.0' AND `vsvr_ip` != '' ";
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'I.device_id');
                    break;
                case 'interface':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'network':
                    $where .= generate_query_values($value, 'A.ip_network_id');
                    break;
                case 'address':
                    list($addr, $mask) = explode('/', $value);
                    if (is_numeric(stripos($addr, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    switch ($address_type) {
                        case 'ipv6':
                            $ip_valid = Net_IPv6::checkIPv6($addr);
                            break;
                        case 'ipv4':
                            $ip_valid = Net_IPv4::validateIP($addr);
                            break;
                    }
                    if ($ip_valid) {
                        // If address valid -> seek occurrence in network
                        if (!$mask) {
                            $mask = $address_type === 'ipv4' ? '32' : '128';
                        }
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip');
                    } else {
                        // If address not valid -> seek LIKE
                        $where .= generate_query_values($addr, 'A.ip_address', '%LIKE%');
                        $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%');
                    }
                    break;
            }
        }
    }
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Also search netscaler Vserver IPs
    $query_netscaler = 'FROM `netscaler_vservers` AS N ';
    $query_netscaler .= 'LEFT JOIN `devices` AS D ON N.`device_id` = D.`device_id` ';
    $query_netscaler .= $where_netscaler . $query_device_permitted;
    //$query_netscaler_count = 'SELECT COUNT(`vsvr_id`) ' . $query_netscaler;
    $query_netscaler = 'SELECT * ' . $query_netscaler;
    $query_netscaler .= ' ORDER BY N.`vsvr_ip`';
    // Override by address type
    if ($address_type == 'ipv6') {
        $query_netscaler = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler);
        //$query_netscaler_count = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler_count);
    }
    $entries = dbFetchRows($query_netscaler, $param_netscaler);
    // Rewrite netscaler addresses
    foreach ($entries as $entry) {
        $ip_address = $address_type == 'ipv4' ? $entry['vsvr_ip'] : $entry['vsvr_' . $address_type];
        $ip_network = $address_type == 'ipv4' ? $entry['vsvr_ip'] . '/32' : $entry['vsvr_' . $address_type] . '/128';
        $ip_array[] = array('type' => 'netscaler_vsvr', 'device_id' => $entry['device_id'], 'hostname' => $entry['hostname'], 'vsvr_id' => $entry['vsvr_id'], 'vsvr_label' => $entry['vsvr_label'], 'ifAlias' => 'Netscaler: ' . $entry['vsvr_type'] . '/' . $entry['vsvr_entitytype'], $address_type . '_address' => $ip_address, $address_type . '_network' => $ip_network);
    }
    //print_message($query_netscaler_count);
    $query = 'FROM `ip_addresses` AS A ';
    $query .= 'LEFT JOIN `ports`   AS I ON I.`port_id`   = A.`port_id` ';
    $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
    $query .= 'LEFT JOIN `ip_networks` AS N ON N.`ip_network_id` = A.`ip_network_id` ';
    $query .= $where . $query_port_permitted;
    //$query_count = 'SELECT COUNT(`ip_address_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY A.`ip_address`';
    if ($ip_valid) {
        $pagination = FALSE;
    }
    // Override by address type
    $query = str_replace(array('ip_address', 'ip_network'), array($address_type . '_address', $address_type . '_network'), $query);
    //$query_count = str_replace(array('ip_address', 'ip_network'), array($address_type.'_address', $address_type.'_network'), $query_count);
    // Query addresses
    $entries = dbFetchRows($query, $param);
    $ip_array = array_merge($ip_array, $entries);
    $ip_array = array_sort($ip_array, $address_type . '_address');
    // Query address count
    //if ($pagination) { $count = dbFetchCell($query_count, $param); }
    if ($pagination) {
        $count = count($ip_array);
        $ip_array = array_slice($ip_array, $start, $pagesize);
    }
    $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>Address</th>' . PHP_EOL;
        $string .= '      <th>Description</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($ip_array as $entry) {
        $address_show = TRUE;
        if ($ip_valid) {
            // If address not in specified network, don't show entry.
            if ($address_type === 'ipv4') {
                $address_show = Net_IPv4::ipInNetwork($entry[$address_type . '_address'], $addr . '/' . $mask);
            } else {
                $address_show = Net_IPv6::isInNetmask($entry[$address_type . '_address'], $addr, $mask);
            }
        }
        if ($address_show) {
            list($prefix, $length) = explode('/', $entry[$address_type . '_network']);
            if (port_permitted($entry['port_id']) || $entry['type'] == 'netscaler_vsvr') {
                if ($entry['type'] == 'netscaler_vsvr') {
                    $entity_link = generate_entity_link($entry['type'], $entry);
                } else {
                    humanize_port($entry);
                    if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                        $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
                    }
                    $entity_link = generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error;
                }
                $device_link = generate_device_link($entry);
                $string .= '  <tr>' . PHP_EOL;
                if ($list['device']) {
                    $string .= '    <td class="entity" style="white-space: nowrap">' . $device_link . '</td>' . PHP_EOL;
                }
                $string .= '    <td class="entity">' . $entity_link . '</td>' . PHP_EOL;
                if ($address_type === 'ipv6') {
                    $entry[$address_type . '_address'] = Net_IPv6::compress($entry[$address_type . '_address']);
                }
                $string .= '    <td>' . $entry[$address_type . '_address'] . '/' . $length . '</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 addresses
    echo $string;
}
Beispiel #13
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;
}
$pagetitle[] = "客户";
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` = 'cust' GROUP BY `port_descr_descr` ORDER BY `port_descr_descr`") as $customer) {
    $customer_name = $customer['port_descr_descr'];
    foreach (dbFetchRows("SELECT * FROM `ports` WHERE `port_descr_type` = 'cust' AND `port_descr_descr` = ?", array($customer['port_descr_descr'])) as $port) {
        $device = device_by_id_cache($port['device_id']);
        unset($class);
        $ifname = rewrite_ifname($device['ifDescr']);
        $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
        if ($device['os'] == "ios") {
            if ($port['ifTrunk']) {
                $vlan = "<span class=small><span class=red>" . $port['ifTrunk'] . "</span></span>";
            } elseif ($port['ifVlan']) {
                $vlan = "<span class=small><span class=blue>VLAN " . $port['ifVlan'] . "</span></span>";
            } else {
                $vlan = "";
            }
        }
        echo "\n           <tr>\n             <td width='250'><span style='font-weight: bold;' class=interface>" . $customer_name . "</span></td>\n             <td width='150'>" . generate_device_link($device) . "</td>\n             <td width='100'>" . generate_port_link($port, short_ifname($port['ifDescr'])) . "</td>\n             <td width='100'>" . $port['port_descr_speed'] . "</td>\n             <td width='100'>" . $port['port_descr_circuit'] . "</td>\n             <td>" . $port['port_descr_notes'] . "</td>\n           </tr>\n         ";
        unset($customer_name);
    }
    if ($config['int_customers_graphs']) {
        echo "<tr><td colspan=7>";
        $graph_array['type'] = "customer_bits";
        $graph_array['to'] = $config['time']['now'];
        $graph_array['id'] = $customer['port_descr_descr'];
        print_graph_row($graph_array);
        echo "</tr>";
    }
}
echo "</table>";
// EOF
$port = get_port_by_id($port);
$device = device_by_id_cache($port['device_id']);
$pluses = "";
$iter = '0';
$rrd_options .= " COMMENT:'                                     In\\: Current     Maximum      Total      Out\\: Current     Maximum     Total\\\\n'";
foreach ($mas as $ma) {
    $this_rrd = get_rrd_path($device, "mac_acc-" . $port['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
    if (is_file($this_rrd)) {
        $mac = format_mac($ma['mac']);
        $name = $mac;
        $addy = dbFetchRow("SELECT * FROM ipv4_mac where mac_address = ? AND port_id = ?", array($ma['mac'], $ma['port_id']));
        if ($addy) {
            $name = $addy['ipv4_address'] . " (" . $mac . ")";
            $peer = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D\n              WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($addy['ipv4_address']));
            if ($peer) {
                $name = $peer['hostname'] . " " . short_ifname($port['ifDescr'], NULL, FALSE) . " (" . $mac . ")";
            }
            if (dbFetchCell("SELECT COUNT(*) FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']))) {
                $peer_info = dbFetchRow("SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']));
                $name .= " - AS" . $peer_info['bgpPeerRemoteAs'];
            }
            if ($peer_info) {
                $asn = "AS" . $peer_info['bgpPeerRemoteAs'];
                $astext = $peer_info['astext'];
            } else {
                unset($as);
                unset($astext);
                unset($asn);
            }
        }
        $this_id = str_replace(".", "", $ma['mac']);
                        $ignore = TRUE;
                        break;
                    }
                }
            }
        }
    }
    $rrd_filename = get_port_rrdfilename($port, NULL, TRUE);
    if (!$ignore && is_file($rrd_filename)) {
        humanize_port($port);
        // Fix Labels! ARGH. This needs to be in the bloody database!
        $rrd_filenames[] = $rrd_filename;
        $rrd_list[$i]['filename'] = $rrd_filename;
        $rrd_list[$i]['descr'] = short_ifname($port['label'], NULL, FALSE);
        // Options sets for skip htmlentities
        $rrd_list[$i]['descr_in'] = short_ifname($port['label'], NULL, FALSE);
        // Options sets for skip htmlentities
        $rrd_list[$i]['descr_out'] = $port['ifAlias'];
        $rrd_list[$i]['ds_in'] = $ds_in;
        $rrd_list[$i]['ds_out'] = $ds_out;
        $i++;
    }
    unset($ignore);
}
$units = 'b';
$total_units = 'B';
$colours_in = 'greens';
$multiplier = "8";
$colours_out = 'blues';
#$nototal = 1;
$ds_in = "INOCTETS";
Beispiel #17
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;
    }
}
<?php

// Generate a list of ports and then call the multi_bits grapher to generate from the list
$i = 0;
foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE `port_descr_type` = 'cust' AND `port_descr_descr` = ? AND D.device_id = I.device_id", array($vars['id'])) as $port) {
    $rrd_filename = get_port_rrdfilename($port, $port);
    if (is_file($rrd_filename)) {
        $rrd_list[$i]['filename'] = $rrd_filename;
        $rrd_list[$i]['descr'] = $port['hostname'] . "-" . $port['ifDescr'];
        $rrd_list[$i]['descr_in'] = short_hostname($port['hostname']);
        $rrd_list[$i]['descr_out'] = short_ifname($port['ifDescr']);
        $i++;
    }
}
$units = 'b';
$total_units = 'B';
$colours_in = 'greens';
$multiplier = "8";
$colours_out = 'blues';
$nototal = 1;
$ds_in = "INOCTETS";
$ds_out = "OUTOCTETS";
include "includes/graphs/generic_multi_bits_separated.inc.php";
Beispiel #19
0
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D', 'hide_ignored' => TRUE));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I', 'hide_ignored' => TRUE));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            // Since reboot event more complicated than just device uptime less than some time
            //$query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= ' WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`last_rebooted` > ?';
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query, array($config['time']['now'] - $config['uptime_warning'] - 10));
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['neighbours']) {
        $status['neighbours'] = $status['neighbours'] && !$status['ports'];
        // Disable 'neighbours' if 'ports' already enabled
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['neighbours']) {
            $query .= 'INNER JOIN `neighbours` as L ON I.`port_id` = L.`port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE D.`status` = 1 AND D.ignore = 0 AND I.ignore = 0 AND I.deleted = 0 AND I.`ifAdminStatus` = 'up' AND (I.`ifOperStatus` = 'lowerLayerDown' OR I.`ifOperStatus` = 'down') ";
        if ($status['neighbours']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        if ($status['neighbours']) {
            $query .= 'GROUP BY L.`port_id` ';
        }
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            if (in_array($port_id, $cache['ports']['ignored'])) {
                continue;
            }
            // Skip ignored ports
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['port_label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.`device_id` = D.`device_id` ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `bgpPeers` AS B ';
            $query .= 'LEFT JOIN `devices` AS D ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE D.`status` = 1 AND (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                humanize_bgp($peer);
                $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']);
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
$port = get_port_by_id($port);
$device = device_by_id_cache($port['device_id']);
$pluses = "";
$iter = '0';
$rrd_options .= " COMMENT:'                                     In\\: Current     Maximum      Total      Out\\: Current     Maximum     Total\\\\n'";
foreach ($mas as $ma) {
    $this_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("mac_acc-" . $port['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd");
    if (is_file($this_rrd)) {
        $mac = formatmac($ma['mac']);
        $name = $mac;
        $addy = dbFetchRow("SELECT * FROM ipv4_mac where mac_address = ? AND port_id = ?", array($ma['mac'], $ma['port_id']));
        if ($addy) {
            $name = $addy['ipv4_address'] . " (" . $mac . ")";
            $peer = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D\n              WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($addy['ipv4_address']));
            if ($peer) {
                $name = $peer['hostname'] . " " . short_ifname($peer['ifDescr']) . " (" . $mac . ")";
            }
            if (dbFetchCell("SELECT COUNT(*) FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']))) {
                $peer_info = dbFetchRow("SELECT * FROM bgpPeers WHERE device_id = ? AND bgpPeerIdentifier = ?", array($ma['device_id'], $addy['ipv4_address']));
                $name .= " - AS" . $peer_info['bgpPeerRemoteAs'];
            }
            if ($peer_info) {
                $asn = "AS" . $peer_info['bgpPeerRemoteAs'];
                $astext = $peer_info['astext'];
            } else {
                unset($as);
                unset($astext);
                unset($asn);
            }
        }
        $this_id = str_replace(".", "", $ma['mac']);
     $ifname = rewrite_ifname($device['ifDescr']);
     $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
     if ($device['os'] == "ios") {
         if ($port['ifTrunk']) {
             $vlan = "<span class=small><span class=red>" . $port['ifTrunk'] . "</span></span>";
         } elseif ($port['ifVlan']) {
             $vlan = "<span class=small><span class=blue>VLAN " . $port['ifVlan'] . "</span></span>";
         } else {
             $vlan = "";
         }
     }
     echo '
        <tr>
          <td style="width: 250px;"><span style="font-weight: bold;" class="interface">' . $customer_name . '</span></td>
          <td style="width: 150px;">' . generate_device_link($device) . '</td>
          <td style="width: 100px;">' . generate_port_link($port, short_ifname($port['ifDescr'])) . '</td>
          <td style="width: 100px;">' . $port['port_descr_speed'] . '</td>
          <td style="width: 100px;">' . $port['port_descr_circuit'] . '</td>
          <td>' . $port['port_descr_notes'] . '</td>
        </tr>
      ';
     unset($customer_name);
 }
 if ($config['int_customers_graphs']) {
     echo '<tr><td colspan="7">';
     $graph_array['type'] = "customer_bits";
     $graph_array['to'] = $config['time']['now'];
     $graph_array['id'] = $customer['port_descr_descr'];
     print_graph_row($graph_array);
     echo "</tr>";
 }
/**
 * Display FDB table.
 *
 * @param array $vars
 * @return none
 *
 */
function print_fdbtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1;
    $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10;
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            $cond = array();
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= ' AND I.`device_id` = ?';
                    $param[] = $value;
                    break;
                case 'port':
                case 'port_id':
                    $where .= ' AND I.`port_id` = ?';
                    $param[] = $value;
                    break;
                case 'interface':
                    $where .= ' AND I.`ifDescr` LIKE ?';
                    $param[] = $value;
                    break;
                case 'vlan_id':
                    if (!is_array($value)) {
                        $value = array($value);
                    }
                    foreach ($value as $v) {
                        $cond[] = '?';
                        $param[] = $v;
                    }
                    $where .= " AND F.`vlan_id` IN (";
                    $where .= implode(', ', $cond);
                    $where .= ')';
                    break;
                case 'vlan_name':
                    if (!is_array($value)) {
                        $value = array($value);
                    }
                    foreach ($value as $v) {
                        $cond[] = '?';
                        $param[] = $v;
                    }
                    $where .= " AND V.`vlan_name` IN (";
                    $where .= implode(', ', $cond);
                    $where .= ')';
                    break;
                case 'address':
                    $where .= ' AND F.`mac_address` LIKE ?';
                    $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%';
                    break;
            }
        }
    }
    // Show FDB tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `vlans_fdb` AS F ';
    $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(*) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= ' ORDER BY F.`mac_address`';
    $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;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        $string .= '      <th>Interface</th>' . PHP_EOL;
        $string .= '      <th>VLAN ID</th>' . PHP_EOL;
        $string .= '      <th>VLAN Name</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        humanize_port($entry);
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" 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>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['vlan_name'] . '</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 FDB table
    echo $string;
}
/**
 * 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'];
    $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1;
    $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10;
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= ' AND I.`device_id` = ?';
                    $param[] = $value;
                    break;
                case 'port':
                case 'port_id':
                    $where .= ' AND I.`port_id` = ?';
                    $param[] = $value;
                    break;
                case 'ip_version':
                    $where .= ' AND `ip_version` = ?';
                    $param[] = $value;
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $where .= ' AND `ip_address` LIKE ?';
                        $value = trim($value);
                        ///FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                        if (Net_IPv6::checkIPv6($value)) {
                            $value = Net_IPv6::uncompress($value, true);
                        }
                        $param[] = '%' . $value . '%';
                    } else {
                        $where .= ' AND `mac_address` LIKE ?';
                        $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%';
                    }
                    break;
            }
        }
    }
    // 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 .= ' ORDER BY M.`mac_address`';
    $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 = '<table class="table table-bordered 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;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface</th>' . PHP_EOL;
        }
        $string .= '      <th>Remote Device</th>' . PHP_EOL;
        $string .= '      <th>Remote Interface</th>' . PHP_EOL;
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    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 width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL;
        $string .= '    <td width="140">' . $ip_address . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" 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, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" width="200">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</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 ARP/NDP table
    echo $string;
}
Beispiel #24
0
    } elseif ($vlan['state'] == "forwarding") {
        $class = "green";
    } else {
        $class = "none";
    }
    echo "<td>" . $vlan['cost'] . "</td><td>" . $vlan['priority'] . "</td><td class={$class}>" . $vlan['state'] . "</td>";
    $vlan_ports = array();
    $otherports = dbFetchRows("SELECT * FROM `ports_vlans` AS V, `ports` as P WHERE V.`device_id` = ? AND V.`vlan` = ? AND P.port_id = V.port_id", array($device['device_id'], $vlan['vlan']));
    foreach ($otherports as $otherport) {
        $vlan_ports[$otherport['ifIndex']] = $otherport;
    }
    $otherports = dbFetchRows("SELECT * FROM ports WHERE `device_id` = ? AND `ifVlan` = ?", array($device['device_id'], $vlan['vlan']));
    foreach ($otherports as $otherport) {
        $vlan_ports[$otherport['ifIndex']] = array_merge($otherport, array('untagged' => '1'));
    }
    ksort($vlan_ports);
    echo "<td>";
    $vsep = '';
    foreach ($vlan_ports as $otherport) {
        echo $vsep . generate_port_link($otherport, short_ifname($otherport['ifDescr']));
        if ($otherport['untagged']) {
            echo "(U)";
        }
        $vsep = ", ";
    }
    echo "</td>";
    echo "</tr>";
}
echo "</table>";
echo generate_box_close();
// EOF
Beispiel #25
0
        $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']);
        $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']);
        $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
        if ($bg == "#ffffff") {
            $bg = "#e5e5e5";
        } else {
            $bg = "#ffffff";
        }
        echo "<tr class='iftype'>\n             <td><span class=entity-title>" . generate_port_link($port, $port['port_descr_descr']) . "</span>";
        #            <span class=small style='float: left;'>".generate_device_link($port)." ".generate_port_link($port)." </span>");
        if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = ?", array($port['port_id']))) {
            echo "<span style='float: right;'><a href='device/device=" . $port['device_id'] . "/tab=port/port=" . $port['port_id'] . "/view=macaccounting/'><img src='images/16/chart_curve.png' align='absmiddle'> MAC Accounting</a></span>";
        }
        echo "</td>";
        echo '   <td style="width: 150px;" class="strong">' . generate_device_link($port) . '</td>
             <td style="width: 150px;" class="strong">' . generate_port_link($port, short_ifname($port['ifDescr'])) . '</td>
             <td style="width: 75px;">' . $port['port_descr_speed'] . '</td>
             <td style="width: 150px;">' . $port['port_descr_circuit'] . '</td>
             <td>' . $port['port_descr_notes'] . '</td>';
        echo '</tr><tr><td colspan="6">';
        $rrdfile = get_port_rrdfilename($port, NULL, TRUE);
        if (file_exists($rrdfile)) {
            $graph_type = "port_bits";
            include "includes/print-interface-graphs.inc.php";
        }
        echo "</td></tr>";
    }
} else {
    echo "None found.</td></tr>";
}
?>
Beispiel #26
0
        $navbar['options_right']['filters']['suboptions'][$option]['url'] = generate_url($vars, array('filters' => $option_array));
    }
}
print_navbar($navbar);
unset($navbar);
if ($vars['view'] == 'minigraphs') {
    $timeperiods = array('-1day', '-1week', '-1month', '-1year');
    $from = '-1day';
    echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>";
    unset($seperator);
    // FIXME - FIX THIS. UGLY.
    foreach (dbFetchRows("SELECT * FROM ports WHERE device_id = ? ORDER BY ifIndex", array($device['device_id'])) as $port) {
        if (is_filtered()) {
            continue;
        }
        echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 183px; max-width:183px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e9e9e9;'>\n    <div style='font-weight: bold;'>" . short_ifname($port['ifDescr']) . "</div>\n    <a href=\"" . generate_port_url($port) . "\" onmouseover=\"return overlib('\\\n    <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\\'>" . $device['hostname'] . " - " . $port['ifDescr'] . "</div>\\\n    " . $port['ifAlias'] . " \\\n    <img src=\\'graph.php?type=" . $graph_type . "&amp;id=" . $port['port_id'] . "&amp;from=" . $from . "&amp;to=" . $config['time']['now'] . "&amp;width=450&amp;height=150\\'>\\\n    ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\"  >" . "<img src='graph.php?type=" . $graph_type . "&amp;id=" . $port['port_id'] . "&amp;from=" . $from . "&amp;to=" . $config['time']['now'] . "&amp;width=180&amp;height=45&amp;legend=no'>\n    </a>\n    <div style='font-size: 9px;'>" . short_port_descr($port['ifAlias']) . "</div>\n    </div>";
    }
    echo "</div>";
} elseif ($vars['view'] == "arp" || $vars['view'] == "adsl" || $vars['view'] == "neighbours" || $vars['view'] == "fdb" || $vars['view'] == "map") {
    include "ports/" . $vars['view'] . ".inc.php";
} else {
    if ($vars['view'] == "details") {
        $port_details = 1;
    }
    if ($vars['view'] == "graphs") {
        $table_class = "table-striped-two";
    } else {
        $table_class = "table-striped";
    }
    echo '<table class="table table-hover table-bordered table-condensed table-rounded ' . $table_class . '"
             style="vertical-align: middle; margin-top: 5px; margin-bottom: 10px;">';
function get_status_array($status)
{
    // Mike: I know that there are duplicated variables, but later will remove global
    global $config, $cache;
    $max_interval = filter_var($status['max']['interval'], FILTER_VALIDATE_INT, array('options' => array('default' => 24, 'min_range' => 1)));
    $max_count = filter_var($status['max']['count'], FILTER_VALIDATE_INT, array('options' => array('default' => 200, 'min_range' => 1)));
    $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D'));
    $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    // Show Device Status
    if ($status['devices']) {
        $query = 'SELECT * FROM `devices` AS D ';
        $query .= 'WHERE D.`status` = 0' . $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $device) {
            $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'));
        }
    }
    // Uptime
    if ($status['uptime']) {
        if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'WHERE D.`status` = 1 AND D.`uptime` > 0 AND D.`uptime` < ' . $config['uptime_warning'];
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $device) {
                $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Ports Down
    if ($status['ports'] || $status['links']) {
        // warning about deprecated option: $config['warn']['ifdown']
        if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) {
            print_warning("<strong>Config option obsolete</strong>\n                    Please note that config option <strong>\$config['warn']['ifdown']</strong> is now obsolete.\n                    Use options: <strong>\$config['frontpage']['device_status']['ports']</strong> and <strong>\$config['frontpage']['device_status']['errors']</strong>\n                    To remove this message, delete <strong>\$config['warn']['ifdown']</strong> from configuration file.");
        }
        $query = 'SELECT * FROM `ports` AS I ';
        if ($status['links'] && !$status['ports']) {
            $query .= 'INNER JOIN `links` as L ON I.`port_id` = L.`local_port_id` ';
        }
        $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` ';
        $query .= "WHERE I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up' ";
        if ($status['links'] && !$status['ports']) {
            $query .= ' AND L.`active` = 1 ';
        }
        $query .= $query_port_permitted;
        $query .= ' AND I.`ifLastChange` >= DATE_SUB(NOW(), INTERVAL ' . $max_interval . ' HOUR) ';
        $query .= 'ORDER BY I.`ifLastChange` DESC, D.`hostname` ASC, I.`ifDescr` * 1 ASC ';
        $entries = dbFetchRows($query);
        $i = 1;
        foreach ($entries as $port) {
            if ($i > $max_count) {
                // Limit to 200 ports on overview page
                break;
            }
            humanize_port($port);
            $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, short_hostname($port['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
        }
    }
    // Ports Errors (only deltas)
    if ($status['errors']) {
        foreach ($cache['ports']['errored'] as $port_id) {
            $port = get_port_by_id($port_id);
            $device = device_by_id_cache($port['device_id']);
            humanize_port($port);
            if ($port['ifInErrors_delta']) {
                $port['string'] .= 'Rx: ' . format_number($port['ifInErrors_delta']);
            }
            if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
                $port['string'] .= ', ';
            }
            if ($port['ifOutErrors_delta']) {
                $port['string'] .= 'Tx: ' . format_number($port['ifOutErrors_delta']);
            }
            $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, short_hostname($device['hostname'])), 'entity_link' => generate_port_link($port, short_ifname($port['label'], 13)), 'time' => $port['string'], 'location' => $device['location']);
        }
    }
    // Services
    if ($status['services']) {
        $query = 'SELECT * FROM `services` AS S ';
        $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id ';
        $query .= "WHERE S.`service_status` = 'down' AND S.`service_ignore` = 0";
        $query .= $query_device_permitted;
        $query .= 'ORDER BY D.`hostname` ASC';
        $entries = dbFetchRows($query);
        foreach ($entries as $service) {
            $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, short_hostname($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']);
        }
    }
    // BGP
    if ($status['bgp']) {
        if (isset($config['enable_bgp']) && $config['enable_bgp']) {
            $query = 'SELECT * FROM `devices` AS D ';
            $query .= 'LEFT JOIN `bgpPeers` AS B ON B.`device_id` = D.`device_id` ';
            $query .= 'LEFT JOIN `bgpPeers-state` AS BS ON B.`bgpPeer_id` = BS.`bgpPeer_id` ';
            $query .= "WHERE (`bgpPeerAdminStatus` = 'start' OR `bgpPeerAdminStatus` = 'running') AND `bgpPeerState` != 'established' ";
            $query .= $query_device_permitted;
            $query .= 'ORDER BY D.`hostname` ASC';
            $entries = dbFetchRows($query);
            foreach ($entries as $peer) {
                $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr'];
                $peer['wide'] = strstr($peer['bgpPeerRemoteAddr'], ':') ? TRUE : FALSE;
                $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, short_hostname($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'short-3'), 'location' => $device['location']);
            }
        }
    }
    // Return boxes array
    return $boxes;
}
Beispiel #28
0
    $graph_array['legend'] = "no";
    $graph = generate_graph_tag($graph_array);
    $link_array = $graph_array;
    $link_array['page'] = "graphs";
    unset($link_array['height'], $link_array['width']);
    $link = generate_url($link_array);
    $graph_array['width'] = "210";
    $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Device Traffic");
    echo overlib_link($link, $graph, $overlib_content, NULL);
    echo '  <div style="height: 5px;"></div>';
    echo '<table class="table table-condensed table-striped table-bordered">
    <tr style="background-color: ' . $ports_colour . '; align: center;"><td></td>
      <td style="width: 25%"><img src="images/16/connect.png" alt="" /> ' . $ports['total'] . '</td>
      <td style="width: 25%" class="green"><img src="images/16/if-connect.png" alt="" /> ' . $ports['up'] . '</td>
      <td style="width: 25%" class="red"><img src="images/16/if-disconnect.png" alt="" /> ' . $ports['down'] . '</td>
      <td style="width: 25%" class="grey"><img src="images/16/if-disable.png" alt="" /> ' . $ports['disabled'] . '</td>
    </tr>
  </table>';
    echo '  <div style="margin: 8px; font-size: 11px; font-weight: bold;">';
    $ifsep = "";
    foreach (dbFetchRows("SELECT * FROM `ports` WHERE device_id = ? AND `deleted` != '1'", array($device['device_id'])) as $data) {
        humanize_port($data);
        $data = array_merge($data, $device);
        echo "{$ifsep}" . generate_port_link($data, short_ifname(strtolower($data['label'])));
        $ifsep = ", ";
    }
    unset($ifsep);
    echo "  </div>";
    echo "</div></div>";
}
// EOF
Beispiel #29
0
         if ($int_links_v4[$int_link]) {
             echo ' ', overlib_link('', '<span class="label label-info">IPv4</span>', implode("<br />", $int_links_v4[$int_link]), NULL);
         }
         $br = "<br />";
     }
 }
 if (!isset($ports_has_ext['pseudowires']) || in_array($port['port_id'], $ports_has_ext['pseudowires'])) {
     foreach (dbFetchRows("SELECT * FROM `pseudowires` WHERE `port_id` = ?", array($port['port_id'])) as $pseudowire) {
         //`port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`
         #    $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.`cpwVcID` = ? AND P.`port_id` = I.`port_id`", array($pseudowire['peer_device_id'], $pseudowire['cpwVcID']));
         #    $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);
             echo $br . '<i class="oicon-arrow-switch"></i> <strong>' . generate_port_link($pw_peer_int, short_ifname($pw_peer_int['label'])) . ' on ' . generate_device_link($pw_peer_dev, short_hostname($pw_peer_dev['hostname'])) . '</strong>';
         } else {
             echo $br . '<i class="oicon-arrow-switch"></i> <strong> VC ' . $pseudowire['cpwVcID'] . ' on ' . $pseudowire['peer_addr'] . '</strong>';
         }
         echo ' <span class="label">' . $pseudowire['pw_psntype'] . '</span>';
         echo ' <span class="label">' . $pseudowire['pw_type'] . '</span>';
         $br = "<br />";
     }
 }
 if (!isset($ports_has_ext['ports_pagp']) || in_array($port['ifIndex'], $ports_has_ext['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;
         echo $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>';
         $br = "<br />";
     }
        unset($class);
        $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']);
        $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']);
        $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']);
        if ($bg == "#ffffff") {
            $bg = "#e5e5e5";
        } else {
            $bg = "#ffffff";
        }
        echo "<tr class='iftype'>\n             <td><span class=entity-title>" . generate_port_link($port, $port['port_descr_descr']) . "</span>";
        #            <span class=small style='float: left;'>".generate_device_link($port)." ".generate_port_link($port)." </span>");
        if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = ?", array($port['port_id']))) {
            echo "<span style='float: right;'><a href='device/device=" . $port['device_id'] . "/tab=port/port=" . $port['port_id'] . "/view=macaccounting/'><img src='/images/16/chart_curve.png' align='absmiddle'> MAC Accounting</a></span>";
        }
        echo "</td>";
        echo "   <td width='150' class='strong'>" . generate_device_link($port) . "</td>\n             <td width='150' class='strong'>" . generate_port_link($port, short_ifname($port['ifDescr'])) . "</td>\n             <td width='75'>" . $port['port_descr_speed'] . "</td>\n             <td width='150'>" . $port['port_descr_circuit'] . "</td>\n             <td>" . $port['port_descr_notes'] . "</td>";
        echo '</tr><tr><td colspan=6>';
        $rrdfile = get_port_rrdfilename($port, $port);
        if (file_exists($rrdfile)) {
            $graph_type = "port_bits";
            include "includes/print-interface-graphs.inc.php";
        }
        echo "</td></tr>";
    }
} else {
    echo "没有发现.</td></tr>";
}
?>
</table>
<?php 
// EOF