Exemplo n.º 1
0
/**
 * Display authentication log.
 *
 * @param array $vars
 * @return none
 *
 */
function print_authlog($vars)
{
    $authlog = get_authlog_array($vars);
    if (!$authlog['count']) {
        // There have been no entries returned. Print the warning. Shouldn't happen, how did you get here without auth?!
        print_warning('<h4>No authentication entries found!</h4>');
    } else {
        $string = generate_box_open($vars['header']);
        // Entries have been returned. Print the table.
        $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED_MORE . '">' . PHP_EOL;
        $cols = array('date' => array('Date', 'style="width: 150px;"'), 'user' => 'User', 'from' => 'From', 'ua' => array('User-Agent', 'style="width: 200px;"'), 'NONE' => 'Action');
        if ($vars['page'] == 'preferences') {
            unset($cols['user']);
        }
        $string .= get_table_header($cols);
        //, $vars); // Currently sorting is not available
        $string .= '<tbody>' . PHP_EOL;
        foreach ($authlog['entries'] as $entry) {
            if (strlen($entry['user_agent']) > 1) {
                $entry['detect_browser'] = detect_browser($entry['user_agent']);
                //r($entry['detect_browser']);
                $entry['user_agent'] = '<i class="' . $entry['detect_browser']['icon'] . '"></i>&nbsp;' . $entry['detect_browser']['browser_full'];
                if ($entry['detect_browser']['platform']) {
                    $entry['user_agent'] .= ' (' . $entry['detect_browser']['platform'] . ')';
                }
            }
            if (strstr(strtolower($entry['result']), 'fail', true)) {
                $class = " class=\"error\"";
            } else {
                $class = "";
            }
            $string .= '
      <tr' . $class . '>
        <td>' . $entry['datetime'] . '</td>';
            if (isset($cols['user'])) {
                $string .= '
        <td>' . escape_html($entry['user']) . '</td>';
            }
            $string .= '
        <td>' . ($_SESSION['userlevel'] > 5 ? generate_popup_link('ip', $entry['address']) : preg_replace('/^\\d+/', '*', $entry['address'])) . '</td>
        <td>' . $entry['user_agent'] . '</td>
        <td>' . $entry['result'] . '</td>
      </tr>' . PHP_EOL;
        }
        $string .= '  </tbody>' . PHP_EOL;
        $string .= '</table>';
        $string .= generate_box_close();
        // Add pagination header
        if ($authlog['pagination_html']) {
            $string = $authlog['pagination_html'] . $string . $authlog['pagination_html'];
        }
        // Print authlog
        echo $string;
    }
}
/**
 * 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 ?';
                    $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', $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>设备</th>' . PHP_EOL;
        }
        $string .= '      <th>接口</th>' . PHP_EOL;
        $string .= '      <th>MAC地址</th>' . PHP_EOL;
        $string .= '      <th>说明</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;">' . generate_popup_link('mac', $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;
}
Exemplo n.º 3
0
/**
 * Display dot1x sessions
 *
 * @param array $vars
 * @return none
 *
 */
function print_dot1xtable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        $where .= generate_query_values($value, 'ipv4_addr', '%LIKE%');
                    } else {
                        if (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
                            $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                            $where .= generate_query_values($value, 'M.mac_addr', '%LIKE%');
                        } else {
                            $value = trim($value);
                            $where .= generate_query_values($value, 'username', '%LIKE%');
                        }
                    }
                    break;
            }
        }
    }
    // Check permissions
    $query_permitted = generate_query_permitted(array('device'), array('device_table' => 'M'));
    $query = 'FROM `wifi_sessions` AS M ';
    $query .= 'LEFT JOIN `wifi_radios` AS I ON I.`wifi_radio_id` = M.`radio_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`wifi_session_id`) ' . $query;
    $query = 'SELECT *, M.`mac_addr` AS `session_mac` ' . $query;
    $query .= ' ORDER BY M.`timestamp` DESC';
    $query .= " LIMIT {$start},{$pagesize}";
    // Query wireless  sessions table
    $entries = dbFetchRows($query, $param);
    // Query wireless  sessions table count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $aps_db = dbFetchRows("SELECT `wifi_accesspoint_id`, `name`, `ap_number`  FROM `wifi_accesspoints`");
    foreach ($aps_db as $ap_db) {
        $aps_sorted_db[$ap_db['wifi_accesspoint_id']] = $ap_db;
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    // A radio is like a port
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    if (!$short) {
        $string .= '  <thead>' . PHP_EOL;
        $string .= '    <tr>' . PHP_EOL;
        $string .= '      <th>MAC Address</th>' . PHP_EOL;
        $string .= '      <th>IP Address</th>' . PHP_EOL;
        $string .= '      <th>Username</th>' . PHP_EOL;
        $string .= '      <th>SSID/VLAN</th>' . PHP_EOL;
        $string .= '      <th>Last Seen</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>Device</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>Interface/AP</th>' . PHP_EOL;
        }
        $string .= '    </tr>' . PHP_EOL;
        $string .= '  </thead>' . PHP_EOL;
    }
    $string .= '  <tbody>' . PHP_EOL;
    foreach ($entries as $entry) {
        $ap_id = $entry['accesspoint_id'];
        $interface = $aps_sorted_db[$ap_id]['name'];
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('mac', format_mac($entry['session_mac'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $entry['ipv4_addr']) . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['username'] . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $entry['ssid'] . '</td>' . PHP_EOL;
        $string .= '    <td style="white-space: nowrap;">' . $entry['timestamp'] . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '    <td class="entity"><a href="' . generate_url(array('page' => 'device', 'device' => $entry['device_id'], 'tab' => 'wifi', 'view' => 'accesspoint', 'accesspoint' => $ap_id)) . '">' . $interface . '</a></td>' . PHP_EOL;
        }
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print wireless sessions
    echo $string;
}
Exemplo n.º 4
0
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'ip_version':
                    $where .= generate_query_values($value, 'ip_version');
                    break;
                case 'address':
                    if (isset($vars['searchby']) && $vars['searchby'] == 'ip') {
                        $value = trim($value);
                        if (strpos($value, ':') !== FALSE) {
                            if (Net_IPv6::checkIPv6($value)) {
                                $value = Net_IPv6::uncompress($value, TRUE);
                            } else {
                                // FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike
                            }
                        }
                        $where .= generate_query_values($value, 'ip_address', '%LIKE%');
                    } else {
                        // MAC Addresses
                        $value = str_replace(array(':', ' ', '-', '.', '0x'), '', $value);
                        $where .= generate_query_values($value, 'mac_address', '%LIKE%');
                    }
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "ip_version":
                $sort = " ORDER BY `ip_version`";
                break;
            case "ip":
            case "address":
                $sort = " ORDER BY `ip_address`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // Show ARP tables only for permitted ports
    $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I'));
    $query = 'FROM `ip_mac` AS M ';
    $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` ';
    $query .= $where . $query_permitted;
    $query_count = 'SELECT COUNT(`mac_id`) ' . $query;
    $query = 'SELECT * ' . $query;
    $query .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query ARP/NDP table addresses
    $entries = dbFetchRows($query, $param);
    // Query ARP/NDP table address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('mac' => 'MAC Address', 'ip' => 'IP Address', 'device' => 'Device', 'port' => 'Port', '!remote_device' => 'Remote Device', '!remote_port' => 'Remote Port');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $ip_version = $entry['ip_version'];
        $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address'];
        $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A
                           LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id`
                           LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id`
                           WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address));
        $arp_name = $arp_host ? generate_device_link($arp_host) : '';
        $arp_if = $arp_host ? generate_port_link($arp_host) : '';
        if ($arp_host['device_id'] == $entry['device_id']) {
            $arp_name = 'Self Device';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = 'Self Port';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;" class="entity">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . generate_popup_link('ip', $ip_address) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
Exemplo n.º 5
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;
    if (in_array($vars['search'], array('6', 'v6', 'ipv6')) || in_array($vars['view'], array('6', 'v6', 'ipv6'))) {
        $address_type = 'ipv6';
    } else {
        $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');
                    $where_netscaler .= generate_query_values($value, 'N.device_id');
                    break;
                case 'interface':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'network':
                    list($net, $mask) = explode('/', $value);
                    if (is_numeric(stripos($net, ':abcdef'))) {
                        $address_type = 'ipv6';
                    }
                    $where .= generate_query_values($value, 'N.ip_network', 'LIKE%');
                    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 = generate_box_open($vars['header']);
    $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED . '">' . 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, $entry['port_label_short']) . ' ' . $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>' . generate_popup_link('ip', $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>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print addresses
    echo $string;
}
Exemplo n.º 6
0
       $tunnel['row_class'] = 'disabled';
   }
   // FIXME - Solves leading zeros in IPs - This should maybe be in ipsec polling instead
   //$local_addr = preg_replace('/\b0+\B/','',$tunnel['local_addr']);
   //$peer_addr  = preg_replace('/\b0+\B/','',$tunnel['peer_addr']);
   $tunnel_endpoint = array();
   foreach (json_decode($tunnel['tunnel_endpoint'], TRUE) as $entry) {
       $tunnel_endpoint[] = 'Local: ' . generate_popup_link('ip', $entry['local']) . ', Remote: ' . generate_popup_link('ip', $entry['remote']);
   }
   $tunnel_endpoint = implode('<br />', $tunnel_endpoint);
   $timediff = $GLOBALS['config']['time']['now'] - $tunnel['tunnel_added'];
   echo '<tr class="' . $tunnel['row_class'] . '">
 <td class="state-marker"></td>
 <td>' . generate_popup_link('ip', $tunnel['local_addr']) . '</td>
 <td><b>&#187;</b></td>
 <td>' . generate_popup_link('ip', $tunnel['peer_addr']) . '</td>
 <td>' . $tunnel['tunnel_name'] . '</td>
 <td><span>' . $tunnel_endpoint . '</span></td>
 <td><span>' . generate_tooltip_link(NULL, formatUptime($tunnel['tunnel_lifetime'], 'short-3'), $tunnel['tunnel_lifetime'] . ' sec') . '</span></td>
 <td><span class="label ' . $tunnel['ike_label_class'] . '">' . $tunnel['tunnel_ike_alive'] . '</span></td>
 <td><span>' . generate_tooltip_link(NULL, formatUptime($tunnel['tunnel_ike_lifetime'], 'short-3'), $tunnel['tunnel_ike_lifetime'] . ' sec') . '</span></td>
 <td><span>' . generate_tooltip_link(NULL, formatUptime($timediff, "short-3") . ' ago', format_unixtime($tunnel['tunnel_added'])) . '</span></td>
 </tr>';
   switch ($vars['graph']) {
       case 'bits':
       case 'pkts':
           $graph_array['type'] = 'ipsectunnel_' . $vars['graph'];
           $graph_array['id'] = $tunnel['tunnel_id'];
   }
   if ($vars['graph'] == 'bits' || $vars['graph'] == 'pkts') {
       $tunnel['graph'] = 1;
/**
 * Display ARP/NDP table addresses.
 *
 * Display pages with ARP/NDP tables addresses from devices.
 *
 * @param array $vars
 * @return none
 *
 */
function print_arptable($vars)
{
    // With pagination? (display page numbers in header)
    $pagination = isset($vars['pagination']) && $vars['pagination'];
    pagination($vars, 0, TRUE);
    // Get default pagesize/pageno
    $pageno = $vars['pageno'];
    $pagesize = $vars['pagesize'];
    $start = $pagesize * $pageno - $pagesize;
    $param = array();
    $where = ' WHERE 1 ';
    foreach ($vars as $var => $value) {
        if ($value != '') {
            switch ($var) {
                case 'device':
                case 'device_id':
                    $where .= generate_query_values($value, 'device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= ' 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'), '', $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地址</th>' . PHP_EOL;
        $string .= '      <th>IP地址</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>设备</th>' . PHP_EOL;
        }
        if ($list['port']) {
            $string .= '      <th>接口</th>' . PHP_EOL;
        }
        $string .= '      <th>远程设备</th>' . PHP_EOL;
        $string .= '      <th>远程接口</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 = '自设备';
        }
        if ($arp_host['port_id'] == $entry['port_id']) {
            $arp_if = '自端口';
        }
        $string .= '  <tr>' . PHP_EOL;
        $string .= '    <td style="width: 160px;">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td style="width: 140px;">' . $ip_address . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($list['port']) {
            if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
                $port_error = generate_port_link($entry, '<span class="label label-important">错误</span>', 'port_errors');
            }
            $string .= '    <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL;
        }
        $string .= '    <td class="entity" style="width: 200px;">' . $arp_name . '</td>' . PHP_EOL;
        $string .= '    <td class="entity">' . $arp_if . '</td>' . PHP_EOL;
        $string .= '  </tr>' . PHP_EOL;
    }
    $string .= '  </tbody>' . PHP_EOL;
    $string .= '</table>';
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print ARP/NDP table
    echo $string;
}
Exemplo n.º 8
0
function generate_pseudowire_row($pw, $vars)
{
    global $config;
    humanize_pseudowire($pw);
    $table_cols = 11;
    $graph_array = array();
    $graph_array['to'] = $config['time']['now'];
    $graph_array['id'] = $pw['pseudowire_id'];
    $graph_array['type'] = $pw['graph'];
    $graph_array['legend'] = "no";
    $graph_array['width'] = 80;
    $graph_array['height'] = 20;
    $graph_array['bg'] = 'ffffff00';
    $graph_array['from'] = $config['time']['day'];
    if ($pw['event'] && $pw['pwOperStatus']) {
        $mini_graph = generate_graph_tag($graph_array);
    } else {
        // Do not show "Draw Error" minigraph
        $mini_graph = '';
    }
    $out = '<tr class="' . $pw['row_class'] . '"><td class="state-marker"></td>';
    $out .= '<td class="entity" style="text-align: right;">' . generate_entity_link('pseudowire', $pw, NULL, NULL, TRUE, TRUE) . '</td>';
    $out .= '<td>' . nicecase($pw['pwType']) . '/' . nicecase($pw['pwPsnType']) . '</td>';
    if ($vars['page'] != "device" && $vars['popup'] != TRUE) {
        $out .= '<td class="entity">' . generate_device_link($pw, NULL, array('tab' => 'pseudowires')) . '</td>';
        $table_cols++;
    }
    $out .= '<td class="entity">' . generate_entity_link('port', $pw['port_id']) . '</td>';
    $out .= '<td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>';
    if ($pw['peer_port_id']) {
        $out .= '<td class="entity">' . generate_entity_link('device', $pw['peer_device_id']) . '</td>';
        $out .= '<td class="entity">' . generate_entity_link('port', $pw['peer_port_id']) . '</td>';
    } else {
        $out .= '<td class="entity">' . generate_popup_link('ip', $pw['peer_addr']) . '</td>';
        $out .= '<td>' . $pw['pwRemoteIfString'] . '</td>';
    }
    $out .= '<td>' . generate_entity_link('pseudowire', $pw, $mini_graph, NULL, FALSE) . '</td>';
    $out .= '<td style="white-space: nowrap">' . generate_tooltip_link(NULL, formatUptime($config['time']['now'] - $pw['last_change'], 'short-2') . ' ago', format_unixtime($pw['last_change'])) . '</td>';
    $out .= '<td style="text-align: right;"><strong><span class="' . $pw['pw_class'] . '">' . $pw['event'] . '</span></strong></td>';
    $out .= '<td style="text-align: right;"><strong><span class="' . $pw['pw_class'] . '">' . $pw['pwOperStatus'] . '</span></strong></td>';
    $out .= '<td>' . formatUptime($pw['pwUptime'], 'short-2') . '</td>';
    $out .= '</tr>';
    if ($vars['graph'] || $vars['view'] == "graphs" || $vars['id'] == $pw['pseudowire_id']) {
        // If id set in vars, display only specific graphs
        $graph_array = array();
        $graph_array['type'] = $vars['graph'] ? $vars['graph'] : $pw['graph'];
        $graph_array['id'] = $pw['pseudowire_id'];
        $out .= '<tr class="' . $pw['row_class'] . '">';
        $out .= '  <td class="state-marker"></td>';
        $out .= '  <td colspan="' . $table_cols . '">';
        $out .= generate_graph_row($graph_array, TRUE);
        $out .= '  </td>';
        $out .= '</tr>';
    }
    return $out;
}
Exemplo n.º 9
0
/**
 * 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'];
    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, 'I.device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'interface':
                case 'port_name':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'vlan_id':
                    $where .= generate_query_values($value, 'F.vlan_id');
                    break;
                case 'vlan_name':
                    $where .= generate_query_values($value, 'V.vlan_name');
                    break;
                case 'address':
                    $where .= generate_query_values(str_replace(array(':', ' ', '-', '.', '0x'), '', $value), 'F.mac_address', '%LIKE%');
                    break;
            }
        }
    }
    if (isset($vars['sort'])) {
        switch ($vars['sort']) {
            case "vlan_id":
                $sort = " ORDER BY `V`.`vlan_vlan`";
                break;
            case "vlan_name":
                $sort = " ORDER BY `V`.`vlan_name`";
                break;
            case "port":
                $sort = " ORDER BY `I`.`port_label`";
                break;
            case "mac":
            default:
                $sort = " ORDER BY `mac_address`";
        }
    }
    // 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 .= $sort;
    $query .= " LIMIT {$start},{$pagesize}";
    // Query addresses
    $entries = dbFetchRows($query, $param);
    // Query address count
    if ($pagination) {
        $count = dbFetchCell($query_count, $param);
    }
    $list = array('device' => FALSE, 'port' => FALSE);
    if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') {
        $list['device'] = TRUE;
    }
    if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') {
        $list['port'] = TRUE;
    }
    $string = generate_box_open();
    $string .= '<table class="table  table-striped table-hover table-condensed">' . PHP_EOL;
    $cols = array('device' => 'Device', 'mac' => array('MAC Address', 'style="width: 160px;"'), 'status' => array('Status', 'style="width: 100px;"'), 'port' => 'Port', 'vlan_id' => 'VLAN ID', 'vlan_name' => 'VLAN NAME');
    if (!$list['device']) {
        unset($cols['device']);
    }
    if (!$list['port']) {
        unset($cols['port']);
    }
    if (!$short) {
        $string .= get_table_header($cols, $vars);
        // Currently sorting is not available
    }
    foreach ($entries as $entry) {
        humanize_port($entry);
        $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;
        }
        $string .= '    <td>' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        $string .= '    <td>' . $entry['fdb_status'] . '</td>' . PHP_EOL;
        if ($list['port']) {
            $string .= '    <td class="entity">' . generate_port_link($entry, $entry['port_label_short']) . ' ' . $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>';
    $string .= generate_box_close();
    // Print pagination header
    if ($pagination) {
        $string = pagination($vars, $count) . $string . pagination($vars, $count);
    }
    // Print FDB table
    echo $string;
}
Exemplo n.º 10
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;
}
    $error_img = "";
}
echo "<tr valign=top onmouseover=\"this.style.backgroundColor='{$list_highlight}';\" onmouseout=\"this.style.backgroundColor='{$row_colour}';\"\nonclick=\"openLink('device/" . $device['device_id'] . "/port/" . $port['port_id'] . "/')\" style='cursor: pointer;'>\n <td valign=top width=350>";
echo "        <span class=entity-title>\n              " . generate_port_link($port, $port['ifIndex'] . ". " . rewrite_ifname($port['port_label'])) . "\n           </span><br /><span class=small>" . $port['ifAlias'] . "</span>";
if ($port['ifAlias']) {
    echo "<br />";
}
unset($break);
if ($port_details) {
    foreach (dbFetchRows("SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip) {
        echo $break . ' ' . generate_popup_link('ip', $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'], NULL, 'small');
        $break = ",";
    }
    foreach (dbFetchRows("SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?", array($port['port_id'])) as $ip6) {
    }
    echo $break . ' ' . generate_popup_link('ip', $ip6['ipv6_address'] . '/' . $ip6['ipv6_prefixlen'], NULL, 'small');
    $break = ",";
}
echo "</span>";
$width = "120";
$height = "40";
$from = $config['time']['day'];
echo "</td><td width=135>";
echo formatRates($port['ifInOctets_rate'] * 8) . " <img class='optionicon' src='images/icons/arrow_updown.png' /> " . formatRates($port['ifOutOctets_rate'] * 8);
echo "<br />";
$port['graph_type'] = "port_bits";
echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&amp;id=" . $port['port_id'] . "&amp;from=" . $from . "&amp;to=" . $config['time']['now'] . "&amp;width=" . $width . "&amp;height=" . $height . "&amp;legend=no&amp;bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']);
echo "</td><td width=135>";
echo "" . formatRates($port['adslAturChanCurrTxRate']) . "/" . formatRates($port['adslAtucChanCurrTxRate']);
echo "<br />";
$port['graph_type'] = "port_adsl_speed";
/**
 * 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'];
    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, 'I.device_id');
                    break;
                case 'port':
                case 'port_id':
                    $where .= generate_query_values($value, 'I.port_id');
                    break;
                case 'interface':
                case 'port_name':
                    $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%');
                    break;
                case 'vlan_id':
                    $where .= generate_query_values($value, 'F.vlan_id');
                    break;
                case 'vlan_name':
                    $where .= generate_query_values($value, 'V.vlan_name');
                    break;
                case 'address':
                    $where .= generate_query_values(str_replace(array(':', ' ', '-', '.', '0x'), '', $value), 'F.mac_address', '%LIKE%');
                    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地址</th>' . PHP_EOL;
        if ($list['device']) {
            $string .= '      <th>设备</th>' . PHP_EOL;
        }
        $string .= '      <th>接口</th>' . PHP_EOL;
        $string .= '      <th>VLAN ID</th>' . PHP_EOL;
        $string .= '      <th>VLAN名称</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 style="width: 160px;">' . generate_popup_link('mac', format_mac($entry['mac_address'])) . '</td>' . PHP_EOL;
        if ($list['device']) {
            $dev = device_by_id_cache($entry['device_id']);
            $string .= '    <td class="entity" style="white-space: nowrap;">' . generate_device_link($dev) . '</td>' . PHP_EOL;
        }
        if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) {
            $port_error = generate_port_link($entry, '<span class="label label-important">错误</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;
}