2011-09-27 13:22:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-04-12 16:30:22 -05:00
|
|
|
use App\Models\Port;
|
|
|
|
|
use LibreNMS\Config;
|
|
|
|
|
use LibreNMS\Util\Url;
|
|
|
|
|
|
2022-08-30 12:55:37 -05:00
|
|
|
if (empty($vars['view'])) {
|
|
|
|
|
$vars['view'] = trim(Config::get('ports_page_default'), '/');
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
|
|
|
|
|
if (isset($vars['graph'])) {
|
|
|
|
|
$graph_type = 'port_' . $vars['graph'];
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2011-09-27 13:22:38 +00:00
|
|
|
$graph_type = 'port_bits';
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-08 23:49:24 +00:00
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
$link_array = [
|
|
|
|
|
'page' => 'device',
|
|
|
|
|
'device' => $device['device_id'],
|
|
|
|
|
'tab' => 'ports',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
print_optionbar_start();
|
|
|
|
|
|
|
|
|
|
$menu_options['basic'] = 'Basic';
|
|
|
|
|
$menu_options['details'] = 'Details';
|
|
|
|
|
$menu_options['arp'] = 'ARP Table';
|
2017-06-26 07:58:17 -05:00
|
|
|
$menu_options['fdb'] = 'FDB Table';
|
2011-09-27 13:22:38 +00:00
|
|
|
|
2012-05-16 13:25:50 +00:00
|
|
|
if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '" . $device['device_id'] . "' AND I.port_id = L.local_port_id")) {
|
2011-09-27 13:22:38 +00:00
|
|
|
$menu_options['neighbours'] = 'Neighbours';
|
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2022-09-08 02:29:17 +02:00
|
|
|
if (DeviceCache::getPrimary()->portsAdsl()->exists() || DeviceCache::getPrimary()->portsVdsl()->exists()) {
|
|
|
|
|
$menu_options['xdsl'] = 'xDSL';
|
2011-09-27 13:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sep = '';
|
|
|
|
|
foreach ($menu_options as $option => $text) {
|
|
|
|
|
echo $sep;
|
|
|
|
|
if ($vars['view'] == $option) {
|
|
|
|
|
echo "<span class='pagemenu-selected'>";
|
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
echo generate_link($text, $link_array, ['view' => $option]);
|
|
|
|
|
if ($vars['view'] == $option) {
|
|
|
|
|
echo '</span>';
|
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
$sep = ' | ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($sep);
|
|
|
|
|
|
|
|
|
|
echo ' | Graphs: ';
|
|
|
|
|
|
|
|
|
|
$graph_types = [
|
|
|
|
|
'bits' => 'Bits',
|
|
|
|
|
'upkts' => 'Unicast Packets',
|
|
|
|
|
'nupkts' => 'Non-Unicast Packets',
|
|
|
|
|
'errors' => 'Errors',
|
2015-07-13 20:10:26 +02:00
|
|
|
];
|
|
|
|
|
|
2022-04-12 16:30:22 -05:00
|
|
|
if (Config::get('enable_ports_etherlike')) {
|
2016-07-08 22:58:36 -05:00
|
|
|
$graph_types['etherlike'] = 'Etherlike';
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 12:55:37 -05:00
|
|
|
$type_sep = '';
|
|
|
|
|
$vars['graph'] = $vars['graph'] ?? '';
|
2011-09-27 13:22:38 +00:00
|
|
|
foreach ($graph_types as $type => $descr) {
|
2022-08-30 12:55:37 -05:00
|
|
|
echo $type_sep;
|
2011-09-27 13:22:38 +00:00
|
|
|
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
|
|
|
|
|
echo "<span class='pagemenu-selected'>";
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
echo generate_link($descr, $link_array, ['view' => 'graphs', 'graph' => $type]);
|
|
|
|
|
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
|
|
|
|
|
echo '</span>';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo ' (';
|
2011-09-27 13:22:38 +00:00
|
|
|
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
|
|
|
|
|
echo "<span class='pagemenu-selected'>";
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2011-09-27 13:22:38 +00:00
|
|
|
|
|
|
|
|
echo generate_link('Mini', $link_array, ['view' => 'minigraphs', 'graph' => $type]);
|
|
|
|
|
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
|
2012-05-25 12:24:34 +00:00
|
|
|
echo '</span>';
|
2012-05-02 22:02:30 +00:00
|
|
|
}
|
2012-05-02 15:06:12 +00:00
|
|
|
|
|
|
|
|
echo ')';
|
2011-09-27 13:22:38 +00:00
|
|
|
$type_sep = ' | ';
|
2012-05-02 15:06:12 +00:00
|
|
|
}//end foreach
|
2012-05-02 22:02:30 +00:00
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
print_optionbar_end();
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
if ($vars['view'] == 'minigraphs') {
|
|
|
|
|
$timeperiods = [
|
2015-07-13 20:10:26 +02:00
|
|
|
'-1day',
|
|
|
|
|
'-1week',
|
|
|
|
|
'-1month',
|
|
|
|
|
'-1year',
|
|
|
|
|
];
|
2011-09-27 13:22:38 +00:00
|
|
|
$from = '-1day';
|
|
|
|
|
echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>";
|
|
|
|
|
unset($seperator);
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2022-04-12 16:30:22 -05:00
|
|
|
foreach (Port::where('device_id', $device['device_id'])->where('disabled', 0)->orderBy('ifIndex')->get() as $port) {
|
|
|
|
|
echo '<div class="minigraph-div">'
|
|
|
|
|
. Url::portLink($port,
|
|
|
|
|
'<div style="font-weight: bold;">' . $port->getShortLabel() . '</div>' .
|
|
|
|
|
Url::graphTag([
|
|
|
|
|
'type' => $graph_type,
|
|
|
|
|
'id' => $port['port_id'],
|
|
|
|
|
'from' => $from,
|
|
|
|
|
'width' => 180,
|
|
|
|
|
'height' => 55,
|
|
|
|
|
'legend' => 'no',
|
|
|
|
|
]))
|
|
|
|
|
. '</div>';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-27 13:22:38 +00:00
|
|
|
echo '</div>';
|
2022-09-08 02:29:17 +02:00
|
|
|
} elseif ($vars['view'] == 'arp' || $vars['view'] == 'xdsl' || $vars['view'] == 'neighbours' || $vars['view'] == 'fdb') {
|
2011-09-27 13:22:38 +00:00
|
|
|
include 'ports/' . $vars['view'] . '.inc.php';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2011-09-27 13:22:38 +00:00
|
|
|
if ($vars['view'] == 'details') {
|
|
|
|
|
$port_details = 1;
|
2020-04-03 08:41:24 -05:00
|
|
|
} ?>
|
2015-11-26 17:56:14 +08:00
|
|
|
<div style='margin: 0px;'><table class='table'>
|
|
|
|
|
<tr>
|
2022-04-12 16:30:22 -05:00
|
|
|
<th width="350"><A href="<?php echo Url::generate($vars, ['sort' => 'port']); ?>">Port</a></th>
|
2021-04-07 00:25:08 +02:00
|
|
|
<th width="100">Port Group</a></th>
|
2015-11-26 17:56:14 +08:00
|
|
|
<th width="100"></th>
|
2022-04-12 16:30:22 -05:00
|
|
|
<th width="120"><a href="<?php echo Url::generate($vars, ['sort' => 'traffic']); ?>">Traffic</a></th>
|
2015-11-26 17:56:14 +08:00
|
|
|
<th width="75">Speed</th>
|
|
|
|
|
<th width="100">Media</th>
|
|
|
|
|
<th width="100">Mac Address</th>
|
|
|
|
|
<th width="375"></th>
|
|
|
|
|
</tr>
|
2020-04-03 08:41:24 -05:00
|
|
|
<?php
|
2015-07-13 20:10:26 +02:00
|
|
|
|
|
|
|
|
$i = '1';
|
|
|
|
|
|
2022-09-07 15:33:29 -05:00
|
|
|
global $port_index_cache;
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2022-09-07 15:33:29 -05:00
|
|
|
/** @var \Illuminate\Support\Collection<\App\Models\Port> $ports */
|
|
|
|
|
$ports = DeviceCache::getPrimary()->ports()->orderBy('ifIndex')->isValid()->get();
|
2015-11-26 17:56:14 +08:00
|
|
|
|
2022-09-07 15:33:29 -05:00
|
|
|
// As we've dragged the whole database, lets pre-populate our caches :)
|
2020-04-03 08:41:24 -05:00
|
|
|
foreach ($ports as $key => $port) {
|
|
|
|
|
$port_index_cache[$port['device_id']][$port['ifIndex']] = $port;
|
|
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2022-09-07 15:33:29 -05:00
|
|
|
if (isset($vars['sort']) && $vars['sort'] == 'traffic') {
|
|
|
|
|
$ports = $ports->sortByDesc(function (Port $port) {
|
|
|
|
|
return $port->ifInOctets_rate + $port->ifOutOctets_rate;
|
|
|
|
|
});
|
2020-04-03 08:41:24 -05:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2020-04-03 08:41:24 -05:00
|
|
|
foreach ($ports as $port) {
|
|
|
|
|
include 'includes/html/print-interface.inc.php';
|
|
|
|
|
}
|
2011-09-27 13:22:38 +00:00
|
|
|
|
2011-10-18 14:27:21 +00:00
|
|
|
echo '</table></div>';
|
2015-07-13 20:10:26 +02:00
|
|
|
}//end if
|
2011-10-18 14:27:21 +00:00
|
|
|
|
|
|
|
|
$pagetitle[] = 'Ports';
|