mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Convert Device>vlan view to Laravel (#12163)
* Convert Device>vlan view to Laravel
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
namespace App\Http\Controllers\Device\Tabs;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\PortVlan;
|
||||
use LibreNMS\Interfaces\UI\DeviceTab;
|
||||
|
||||
class VlansController implements DeviceTab
|
||||
@ -51,6 +52,37 @@ class VlansController implements DeviceTab
|
||||
|
||||
public function data(Device $device): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'vlans' => self::getVlans($device),
|
||||
'submenu' => [
|
||||
[
|
||||
['name' => 'Basic', 'url' => ''],
|
||||
],
|
||||
'Graphs' => [
|
||||
['name' => 'Bits', 'url' => 'bits'],
|
||||
['name' => 'Unicast Packets', 'url' => 'upkts'],
|
||||
['name' => 'Non-Unicast Packets', 'url' => 'nupkts'],
|
||||
['name' => 'Errors', 'url' => 'errors'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static function getVlans(Device $device)
|
||||
{
|
||||
// port.device needed to prevent loading device multiple times
|
||||
$portVlan = PortVlan::where('ports_vlans.device_id', $device->device_id)
|
||||
->join('vlans', function ($join) {
|
||||
$join
|
||||
->on('ports_vlans.vlan', 'vlans.vlan_vlan')
|
||||
->on('vlans.device_id', 'ports_vlans.device_id');
|
||||
})
|
||||
->with(['port.device'])
|
||||
->select('ports_vlans.*', 'vlans.vlan_name')
|
||||
->get();
|
||||
|
||||
$data = $portVlan->groupBy('vlan');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,15 @@ class PortVlan extends PortRelatedModel
|
||||
protected $table = 'ports_vlans';
|
||||
protected $primaryKey = 'port_vlan_id';
|
||||
public $timestamps = false;
|
||||
|
||||
public function getUntaggedAttribute($value)
|
||||
{
|
||||
if (! $value) {
|
||||
if ($this->vlan == $this->port->ifVlan) {
|
||||
$value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
$link_array = [
|
||||
'page' => 'device',
|
||||
'device' => $device['device_id'],
|
||||
'tab' => 'vlans',
|
||||
];
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
echo "<span style='font-weight: bold;'>VLANs</span> » ";
|
||||
|
||||
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') {
|
||||
if (isset($vars['graph'])) {
|
||||
$graph_type = 'port_' . $vars['graph'];
|
||||
} else {
|
||||
$graph_type = 'port_bits';
|
||||
}
|
||||
}
|
||||
|
||||
if (! $vars['view']) {
|
||||
$vars['view'] = 'basic';
|
||||
}
|
||||
|
||||
$menu_options['basic'] = 'Basic';
|
||||
// $menu_options['details'] = 'Details';
|
||||
$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',
|
||||
];
|
||||
|
||||
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['type'] == "minigraphs") { echo("<span class='pagemenu-selected'>"); }
|
||||
echo(generate_link('Mini',$link_array,array('type'=>'minigraphs','graph'=>$type)));
|
||||
if ($vars['graph'] == $type && $vars['type'] == "minigraphs") { echo("</span>"); }
|
||||
echo(')');
|
||||
*/
|
||||
$type_sep = ' | ';
|
||||
}
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
echo '<table border="0" cellspacing="0" cellpadding="5" width="100%">';
|
||||
|
||||
include 'includes/html/print-vlan.inc.php';
|
||||
|
||||
echo '</table>';
|
||||
|
||||
$pagetitle[] = 'VLANs';
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
$vlan_ports = [];
|
||||
$vlans_data = [];
|
||||
|
||||
foreach (dbFetchRows('SELECT * FROM `vlans` WHERE `device_id` = ? GROUP BY `vlan_vlan` ORDER BY `vlan_vlan`', [$device['device_id']]) as $vlan) {
|
||||
foreach ($vlan as $k => $v) {
|
||||
if ($k != 'vlan_vlan') {
|
||||
$vlans_data[$vlan['vlan_vlan']][$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$otherports = dbFetchRows('SELECT * FROM `ports_vlans` AS V, `ports` AS P WHERE V.`device_id` = ? AND P.port_id = V.port_id', [$device['device_id']]);
|
||||
foreach ($otherports as $n => $otherport) {
|
||||
if (! $otherport['untagged']) {
|
||||
if ($otherport['ifvlan'] == $otherport['vlan']) {
|
||||
$otherport['untagged'] = 1;
|
||||
}
|
||||
}
|
||||
$vlan_ports[$otherport['vlan']][$otherport['ifIndex']] = $otherport;
|
||||
}
|
||||
|
||||
ksort($vlan_ports);
|
||||
|
||||
$i = 0;
|
||||
foreach ($vlan_ports as $vlan => $ports) {
|
||||
$bg_colour = \LibreNMS\Config::get('list_colour.odd');
|
||||
if (! is_integer($i / 2)) {
|
||||
$bg_colour = \LibreNMS\Config::get('list_colour.even');
|
||||
}
|
||||
|
||||
echo "<tr bgcolor='$bg_colour'>";
|
||||
echo '<td width=100 class=list-large> Vlan ' . $vlan . '</td>';
|
||||
echo '<td width=200 class=box-desc>' . $vlans_data[$vlan]['vlan_name'] . '</td>';
|
||||
echo '<td class=list-bold>';
|
||||
|
||||
foreach ($ports as $port_id => $port) {
|
||||
$port = cleanPort($port, $device);
|
||||
if ($vars['view'] == 'graphs') {
|
||||
echo "<div style='display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: " . \LibreNMS\Config::get('list_colour.odd_alt2') . ";'>
|
||||
<div style='font-weight: bold;'>" . makeshortif($port['ifDescr']) . "</div>
|
||||
<a href='device/device=" . $device['device_id'] . '/tab=port/port=' . $port['port_id'] . "/' onmouseover=\"return overlib('\
|
||||
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\'>" . $device['hostname'] . ' - ' . $port['ifDescr'] . '</div>\
|
||||
' . display($port['ifAlias']) . " \
|
||||
<img src=\'graph.php?type=$graph_type&id=" . $port['port_id'] . '&from=' . \LibreNMS\Config::get('time.twoday') . '&to=' . \LibreNMS\Config::get('time.now') . "&width=450&height=150\'>\
|
||||
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >" . "<img src='graph.php?type=$graph_type&id=" . $port['port_id'] . '&from=' . \LibreNMS\Config::get('time.twoday') . '&to=' . \LibreNMS\Config::get('time.now') . "&width=132&height=40&legend=no'>
|
||||
</a>
|
||||
<div style='font-size: 9px;'>" . substr(short_port_descr($port['ifAlias']), 0, 22) . '</div>
|
||||
</div>';
|
||||
} else {
|
||||
echo $vlans_data[$vlan]['port_sep'] . generate_port_link($port, makeshortif($port['label']));
|
||||
$vlans_data[$vlan]['port_sep'] = ', ';
|
||||
if ($port['untagged']) {
|
||||
echo '(U)';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '</td></tr>';
|
||||
$i++;
|
||||
}
|
46
resources/views/device/tabs/vlans.blade.php
Normal file
46
resources/views/device/tabs/vlans.blade.php
Normal file
@ -0,0 +1,46 @@
|
||||
@extends('device.submenu')
|
||||
|
||||
@section('tabcontent')
|
||||
<table class="table table-hover table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 150px;">@lang('VLAN Number')</th>
|
||||
<th style="width: 250px;">@lang('VLAN Name')</th>
|
||||
<th>@lang('Ports')</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@foreach($data['vlans'] as $vlan_number => $vlans)
|
||||
<tr>
|
||||
<td>{{ $vlan_number }}</td>
|
||||
<td>{{ $vlans->first()->vlan_name }}</td>
|
||||
<td>
|
||||
@foreach($vlans as $port)
|
||||
@if(!$vars)
|
||||
@portLink($port->port, $port->port->getShortLabel())
|
||||
@if($port->untagged)
|
||||
(U)@endif
|
||||
@if(!$loop->last),
|
||||
@endif
|
||||
|
||||
@else
|
||||
<div style="display: block; padding: 2px; margin: 2px; min-width: 139px; max-width:139px; min-height:85px; max-height:85px; text-align: center; float: left; background-color: {{ \LibreNMS\Config::get('list_colour.odd_alt2') }}">
|
||||
|
||||
<div style="font-weight: bold;">{{ $port->port->ifDescr }}</div>
|
||||
<a href="{{ route('device', ['device' => $device->device_id, 'tab' => 'port', 'vars' => 'port='.$port->port->port_id]) }}" onmouseover="return overlib('<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\'>{{ $device->hostname }}-{{ $port->port->ifDescr }}</div>{{ $port->port->ifAlias }}<img src=\'{{ url('graph.php') }}?type=port_{{ $vars }}&id={{ $port->port->port_id }}&from={{ \LibreNMS\Config::get('time.twoday') }}&to={{ \LibreNMS\Config::get('time.now') }}&width=450&height=150\'>', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);" onmouseout="return nd();">
|
||||
<img src="{{ url('graph.php') }}?type=port_{{ $vars }}&id={{ $port->port->port_id }}&from={{ \LibreNMS\Config::get('time.twoday') }}&to={{ \LibreNMS\Config::get('time.now') }}&width=132&height=40&legend=no">
|
||||
</a>
|
||||
<div style="font-size: 9px;">{{ $port->port->ifAlias }}</div>
|
||||
</div>
|
||||
@endif
|
||||
@endforeach
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endsection
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user