本文整理汇总了PHP中humanize_port函数的典型用法代码示例。如果您正苦于以下问题:PHP humanize_port函数的具体用法?PHP humanize_port怎么用?PHP humanize_port使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了humanize_port函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_port_link
function generate_port_link($port, $text = NULL, $type = NULL, $escape = FALSE)
{
global $config;
humanize_port($port);
//if (!isset($port['html_class'])) { $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); }
//if (!isset($text)) { $text = rewrite_ifname($port['label'], !$escape); } // Negative escape flag for exclude double escape
// Fixme -- does this function even need alternative $text? I think not. It's a hangover from before label.
if (!isset($text)) {
$text = $port['label'];
}
if (port_permitted($port['port_id'], $port['device_id'])) {
$url = generate_port_url($port);
if ($escape) {
$text = escape_html($text);
}
return '<a href="' . $url . '" class="entity-popup ' . $port['html_class'] . '" data-eid="' . $port['port_id'] . '" data-etype="port">' . $text . '</a>';
} else {
return rewrite_ifname($text);
}
}
示例2: get_port_by_ifIndex
function get_port_by_ifIndex($device_id, $ifIndex)
{
$port = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ? LIMIT 1", array($device_id, $ifIndex));
if (is_array($port)) {
humanize_port($port);
return $port;
}
return FALSE;
}
示例3: get_status_array
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']) {
//.........这里部分代码省略.........
示例4: get_status_array
function get_status_array($status)
{
// Mike: I know that there are duplicated variables, but later will remove global
global $config;
global $cache;
$param = array();
if ($_SESSION['userlevel'] >= 5) {
$query_perms = '';
$query_user = '';
} else {
$query_perms = 'LEFT JOIN devices_perms AS P ON D.device_id = P.device_id ';
$query_user = ' AND P.user_id = ? ';
$param[] = $_SESSION['user_id'];
}
// Don't show ignored and disabled devices
$query_device = ' AND D.ignore = 0 ';
if (!$config['web_show_disabled']) {
$query_device .= 'AND D.disabled = 0 ';
}
// Show Device Status
if ($status['devices']) {
$query = 'SELECT * FROM `devices` AS D ';
$query .= $query_perms;
$query .= 'WHERE D.status = 0' . $query_device . $query_user;
$query .= 'ORDER BY D.hostname ASC';
$entries = dbFetchRows($query, $param);
foreach ($entries as $device) {
$boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, shorthost($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 .= $query_perms;
$query .= 'WHERE D.status = 1 AND D.uptime > 0 AND D.uptime < ' . $config['uptime_warning'] . $query_device . $query_user;
$query .= 'ORDER BY D.hostname ASC';
$entries = dbFetchRows($query, $param);
foreach ($entries as $device) {
$boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, shorthost($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']) {
echo '
<div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<p><i class="oicon-bell"></i> <strong>Config option obsolete</strong></p>
<p>Please note that config option <strong>$config[\'warn\'][\'ifdown\']</strong> is now obsolete.<br />Use options: <strong>$config[\'frontpage\'][\'device_status\'][\'ports\']</strong> and <strong>$config[\'frontpage\'][\'device_status\'][\'errors\']</strong></p>
<p>To remove this message, delete <strong>$config[\'warn\'][\'ifdown\']</strong> from configuration file.</p>
</div>';
}
$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 .= $query_perms;
$query .= "WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = 0 AND I.deleted = 0 ";
if ($status['links'] && !$status['ports']) {
$query .= ' AND L.active = 1 ';
}
$query .= $query_device . $query_user;
$query .= ' AND I.ifLastChange >= DATE_SUB(NOW(), INTERVAL 24 HOUR) ';
$query .= 'ORDER BY I.ifLastChange DESC, D.hostname ASC, I.ifDescr * 1 ASC ';
$entries = dbFetchRows($query, $param);
//$count = count($entries);
$i = 1;
foreach ($entries as $port) {
if ($i > 200) {
// Limit to 200 ports on overview page
$string .= ' <tr><td></td><td><span class="badge badge-info">Port</span></td>';
$string .= '<td><span class="label label-important">Port Down</span></td>';
$string .= '<td colspan=3>Too many ports down. See <strong><a href="' . generate_url(array('page' => 'ports'), array('state' => 'down')) . '">All DOWN ports</a></strong>.</td></tr>' . PHP_EOL;
break;
}
humanize_port($port);
$boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, shorthost($port['hostname'])), 'entity_link' => generate_port_link($port, truncate(makeshortif($port['label']), 13, '')), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']);
// We don't do anything with this here at the moment. There is no comment on it, what is it for?
// if ($status['links'] && !$status['ports']) { $string .= ' ('.strtoupper($port['protocol']).': ' .$port['remote_hostname'].' / ' .$port['remote_port'] .')'; }
}
}
// Ports Errors (only deltas)
if ($status['errors']) {
foreach ($cache['ports_errored'] as $port_id) {
$port = get_port_by_id($port_id);
if (port_permitted($port)) {
$device = device_by_id_cache($port['device_id']);
humanize_port($port);
if ($port['ifInErrors_delta']) {
$port['string'] .= 'Rx: ' . $port['ifInErrors_delta'];
}
if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) {
$port['string'] .= ', ';
}
if ($port['ifOutErrors_delta']) {
$port['string'] .= 'Tx: ' . $port['ifOutErrors_delta'];
//.........这里部分代码省略.........
示例5: get_status_array
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);
//.........这里部分代码省略.........
示例6: foreach
<?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";
示例7: print_arptable
/**
* 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));
//.........这里部分代码省略.........
示例8: unset
* @author Adam Armstrong <adama@observium.org>
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
*
*/
?>
<div class="row">
<div class="col-md-12">
<?php
unset($search, $vlans, $vlan_names, $port_names);
// Select ports only present in FDB tables
foreach (dbFetchRows('SELECT `port_id`, `device_id`, `ifDescr`, `ifName`, `ifAlias`
FROM `vlans_fdb` AS F
LEFT JOIN `ports` as P USING (`port_id`, `device_id`)
WHERE `device_id` = ? AND `port_id` != 0 GROUP BY `port_id`;', array($device['device_id'])) as $data) {
humanize_port($data);
$form_items['ports'][$data['port_id']] = $data['port_label'];
}
natcasesort($form_items['ports']);
foreach (dbFetchRows('SELECT `vlan_vlan`, `vlan_name`
FROM `vlans_fdb` AS F
LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id`
WHERE F.`device_id` = ?
GROUP BY `vlan_vlan`', array($device['device_id'])) as $data) {
$form_items['vlans'][$data['vlan_vlan']] = 'Vlan ' . $data['vlan_vlan'];
$form_items['vlan_name'][$data['vlan_name']] = $data['vlan_name'];
}
ksort($form_items['vlans']);
natcasesort($form_items['vlan_name']);
$form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'search/search=fdb/');
$form['row'][0]['port'] = array('type' => 'multiselect', 'name' => 'Ports', 'width' => '100%', 'value' => $vars['port'], 'values' => $form_items['ports']);
示例9: print_addresses
//.........这里部分代码省略.........
//$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;
}
示例10: get_port_by_id
function get_port_by_id($port_id)
{
if (is_numeric($port_id)) {
$port = dbFetchRow("SELECT * FROM `ports` LEFT JOIN `ports-state` ON `ports`.`port_id` = `ports-state`.`port_id` WHERE `ports`.`port_id` = ?", array($port_id));
}
if (is_array($port)) {
humanize_port($port);
return $port;
} else {
return FALSE;
}
}
示例11: discover_new_device
function discover_new_device($hostname, $source = 'xdp', $protocol = NULL, $device = NULL, $port = NULL)
{
global $config, $debug;
# FIXME remodel function a bit like the one above? refactor so they share some parts?
if ($config['autodiscovery'][$source]) {
echo "Discovering new host {$hostname}\n";
if (!empty($config['mydomain']) && isDomainResolves($hostname . "." . $config['mydomain'])) {
if ($debug) {
echo "appending " . $config['mydomain'] . "!\n";
}
$dst_host = $hostname . "." . $config['mydomain'];
} else {
$dst_host = $hostname;
}
$ip = gethostbyname($dst_host);
if ($debug) {
echo "resolving {$dst_host} to {$ip}\n";
}
if (match_network($config['autodiscovery']['ip_nets'], $ip)) {
if ($debug) {
echo "found {$ip} inside configured nets, adding!\n";
}
$remote_device_id = add_device($dst_host);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
if (!$protocol) {
$protocol = strtoupper($source);
}
if ($port) {
humanize_port($port);
log_event("Device autodiscovered through {$protocol} on " . $device['hostname'] . " (port " . $port['label'] . ")", $remote_device_id, 'interface', $port['port_id']);
} else {
log_event("Device autodiscovered through {$protocol} on " . $device['hostname'], $remote_device_id);
}
array_push($GLOBALS['devices'], $remote_device);
return $remote_device_id;
}
}
} else {
if ($debug) {
echo "{$source} autodiscovery disabled";
}
return FALSE;
}
}
示例12: print_fdbtable
/**
* 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;
//.........这里部分代码省略.........
示例13: generate_port_row
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>';
//.........这里部分代码省略.........
示例14: discover_new_device
function discover_new_device($hostname, $source = 'xdp', $protocol = NULL, $device = NULL, $snmp_port = 161)
{
global $config;
$source = strtolower($source);
if ($config['autodiscovery'][$source]) {
if (!$protocol) {
$protocol = strtoupper($source);
}
print_message("发现新主机 {$hostname} 通过 {$protocol}");
// By first detect hostname is IP or domain name (IPv4/6 == 4/6, hostname == FALSE)
$ip_version = get_ip_version($hostname);
if ($ip_version) {
// Hostname is IPv4/IPv6
$use_ip = TRUE;
$ip = $hostname;
} else {
$use_ip = FALSE;
if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) {
$hostname .= '.' . $config['mydomain'];
}
$ip = gethostbyname6($hostname);
if ($ip) {
$ip_version = get_ip_version($ip);
print_debug("主机 {$hostname} 解析为 {$ip}");
} else {
// No DNS records
print_debug("主机 {$hostname} 无法解析, 自动发现失败.");
return FALSE;
}
}
if (match_network($ip, $config['autodiscovery']['ip_nets'])) {
print_debug("主机 {$hostname} ({$ip}) 内部网络创建配置, 尝试增加:");
if (isPingable($ip)) {
// Check if device duplicated by IP
$ip = $ip_version == 4 ? $ip : Net_IPv6::uncompress($ip, TRUE);
$db = dbFetchRow('SELECT D.`hostname` FROM ipv' . $ip_version . '_addresses AS A
LEFT JOIN `ports` AS P ON A.`port_id` = P.`port_id`
LEFT JOIN `devices` AS D ON D.`device_id` = P.`device_id`
WHERE D.`disabled` = 0 AND A.`ipv' . $ip_version . '_address` = ?', array($ip));
if ($db) {
print_debug('已经有设备 ' . $db['hostname'] . " 包含 {$ip}");
return FALSE;
}
// Detect snmp transport
$snmp_transport = $ip_version == 4 ? 'udp' : 'udp6';
$new_device = detect_device_snmpauth($ip, $snmp_port, $snmp_transport);
if ($new_device) {
if ($use_ip) {
// Detect FQDN hostname
// by sysName
$snmphost = snmp_get($new_device, "sysName.0", "-Oqv", "SNMPv2-MIB", mib_dirs());
if ($snmphost) {
$snmp_ip = gethostbyname6($snmphost);
}
if ($snmp_ip == $ip) {
$hostname = $snmphost;
} else {
// by PTR
$ptr = gethostbyaddr6($ip);
if ($ptr) {
$ptr_ip = gethostbyname6($ptr);
}
if ($ptr && $ptr_ip == $ip) {
$hostname = $ptr;
} else {
print_debug("设备 IP {$ip} 没有 FQDN 名称");
return FALSE;
}
}
print_debug("设备 IP {$ip} 发现 FQDN 名称: {$hostname}");
}
$new_device['hostname'] = $hostname;
if (!check_device_duplicated($new_device)) {
$snmp_v3 = array();
if ($new_device['snmp_version'] === 'v3') {
$snmp_v3['snmp_authlevel'] = $new_device['snmp_authlevel'];
$snmp_v3['snmp_authname'] = $new_device['snmp_authname'];
$snmp_v3['snmp_authpass'] = $new_device['snmp_authpass'];
$snmp_v3['snmp_authalgo'] = $new_device['snmp_authalgo'];
$snmp_v3['snmp_cryptopass'] = $new_device['snmp_cryptopass'];
$snmp_v3['snmp_cryptoalgo'] = $new_device['snmp_cryptoalgo'];
}
$remote_device_id = createHost($new_device['hostname'], $new_device['snmp_community'], $new_device['snmp_version'], $new_device['snmp_port'], $new_device['snmp_transport'], $snmp_v3);
if ($remote_device_id) {
$remote_device = device_by_id_cache($remote_device_id, 1);
if ($port) {
humanize_port($port);
log_event("设备自动发现通过 {$protocol} 在 " . $device['hostname'] . " (port " . $port['label'] . ")", $remote_device_id, 'port', $port['port_id']);
} else {
log_event("设备自动发现通过 {$protocol} 在 " . $device['hostname'], $remote_device_id, $protocol);
}
//array_push($GLOBALS['devices'], $remote_device); // createHost() already puth this
return $remote_device_id;
}
}
}
}
} else {
print_debug("IP {$ip} ({$hostname}) 不允许内部 \$config['autodiscovery']['ip_nets'] 位于 config.php");
}
//.........这里部分代码省略.........
示例15: print_mac_addresses
/**
* 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;
}