Files
librenms-librenms/includes/html/pages/device/ports.inc.php
PipoCanaja 53bfb24ef9 Migrate xDSL code to module, and add support for VDSL2 MIB (#14207)
* use component to discover if xDSL polling is needed

use component to discover if xDSL polling is needed

* Components OK, Polling in correct files, no DB for VDSL

* GUI

GUI_suite

* per port as well

* rename

* interface listing

* draytek_snmpsim

* fix arraymerge

fix names and max value

* schema

schema

style

* remove one dbFetchRows

remove 2x dbFetchCell

style

style

remove Legacy dbFetchRow

tests

tests

eloquent

more eloquent

more eloquent

one more gone

* fix properties access

eloquent_insert_update

style

tests

tests

tests

tests

* tests

tests

tests

* adslLineCoding

* Models

* fix not nullable cols in DB from code

default values

typo

rename

typo

schema

fix

fix

vdsl fix now

typo

typo

fix size

fix size

* Power values for VDSL

Power values for VDSL

Power values for VDSL

DB

* cleanup

* Rrd::checkRrdExists

* always enable DSL discovery

style

* xdsl module

* cleanup and move to Module

cleanup and move to Module

cleanup and move to Module

cleanup and move to Module

* Fix display

* fix polling and tenth

* remove legacy poller

* Style and Cosmetics

Cosmetics

Cleanup

* Translations

Translations

* exists

exists

* add test support for xdsl

* remove last component call

unused

* translations

* remove non standard onclick event on xdsl line

* Update Discovery Support.md

Update Poller Support.md

toner_gone

* Notification for removal of lnms config:set enable_ports_adsl true

* enable on devices with potential DSL interfaces

* tests are working now

fix teldat tests

* os_schema

* teldat

* move to new module structure

* move to new module structure

* wrong dump function

* wrong dump function

* laravel_through_key hidden

* Update notifications.rss

* Update notifications.rss

Co-authored-by: Tony Murray <murraytony@gmail.com>
2022-09-07 19:29:17 -05:00

171 lines
4.7 KiB
PHP

<?php
use App\Models\Port;
use LibreNMS\Config;
use LibreNMS\Util\Url;
if (empty($vars['view'])) {
$vars['view'] = trim(Config::get('ports_page_default'), '/');
}
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
if (isset($vars['graph'])) {
$graph_type = 'port_' . $vars['graph'];
} else {
$graph_type = 'port_bits';
}
}
$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';
$menu_options['fdb'] = 'FDB Table';
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")) {
$menu_options['neighbours'] = 'Neighbours';
}
if (DeviceCache::getPrimary()->portsAdsl()->exists() || DeviceCache::getPrimary()->portsVdsl()->exists()) {
$menu_options['xdsl'] = 'xDSL';
}
$sep = '';
foreach ($menu_options as $option => $text) {
echo $sep;
if ($vars['view'] == $option) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link($text, $link_array, ['view' => $option]);
if ($vars['view'] == $option) {
echo '</span>';
}
$sep = ' | ';
}
unset($sep);
echo ' | Graphs: ';
$graph_types = [
'bits' => 'Bits',
'upkts' => 'Unicast Packets',
'nupkts' => 'Non-Unicast Packets',
'errors' => 'Errors',
];
if (Config::get('enable_ports_etherlike')) {
$graph_types['etherlike'] = 'Etherlike';
}
$type_sep = '';
$vars['graph'] = $vars['graph'] ?? '';
foreach ($graph_types as $type => $descr) {
echo $type_sep;
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
echo "<span class='pagemenu-selected'>";
}
echo generate_link($descr, $link_array, ['view' => 'graphs', 'graph' => $type]);
if ($vars['graph'] == $type && $vars['view'] == 'graphs') {
echo '</span>';
}
echo ' (';
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
echo "<span class='pagemenu-selected'>";
}
echo generate_link('Mini', $link_array, ['view' => 'minigraphs', 'graph' => $type]);
if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') {
echo '</span>';
}
echo ')';
$type_sep = ' | ';
}//end foreach
print_optionbar_end();
if ($vars['view'] == 'minigraphs') {
$timeperiods = [
'-1day',
'-1week',
'-1month',
'-1year',
];
$from = '-1day';
echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>";
unset($seperator);
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>';
}
echo '</div>';
} elseif ($vars['view'] == 'arp' || $vars['view'] == 'xdsl' || $vars['view'] == 'neighbours' || $vars['view'] == 'fdb') {
include 'ports/' . $vars['view'] . '.inc.php';
} else {
if ($vars['view'] == 'details') {
$port_details = 1;
} ?>
<div style='margin: 0px;'><table class='table'>
<tr>
<th width="350"><A href="<?php echo Url::generate($vars, ['sort' => 'port']); ?>">Port</a></th>
<th width="100">Port Group</a></th>
<th width="100"></th>
<th width="120"><a href="<?php echo Url::generate($vars, ['sort' => 'traffic']); ?>">Traffic</a></th>
<th width="75">Speed</th>
<th width="100">Media</th>
<th width="100">Mac Address</th>
<th width="375"></th>
</tr>
<?php
$i = '1';
global $port_index_cache;
/** @var \Illuminate\Support\Collection<\App\Models\Port> $ports */
$ports = DeviceCache::getPrimary()->ports()->orderBy('ifIndex')->isValid()->get();
// As we've dragged the whole database, lets pre-populate our caches :)
foreach ($ports as $key => $port) {
$port_index_cache[$port['device_id']][$port['ifIndex']] = $port;
}
if (isset($vars['sort']) && $vars['sort'] == 'traffic') {
$ports = $ports->sortByDesc(function (Port $port) {
return $port->ifInOctets_rate + $port->ifOutOctets_rate;
});
}
foreach ($ports as $port) {
include 'includes/html/print-interface.inc.php';
}
echo '</table></div>';
}//end if
$pagetitle[] = 'Ports';