diff --git a/app/Http/Controllers/Device/Tabs/VlansController.php b/app/Http/Controllers/Device/Tabs/VlansController.php index 2a3071f16b..fd84da46a6 100644 --- a/app/Http/Controllers/Device/Tabs/VlansController.php +++ b/app/Http/Controllers/Device/Tabs/VlansController.php @@ -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; } } diff --git a/app/Models/PortVlan.php b/app/Models/PortVlan.php index 8b59a61362..316388e47e 100644 --- a/app/Models/PortVlan.php +++ b/app/Models/PortVlan.php @@ -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; + } } diff --git a/includes/html/pages/device/vlans.inc.php b/includes/html/pages/device/vlans.inc.php deleted file mode 100644 index b9e44bfb97..0000000000 --- a/includes/html/pages/device/vlans.inc.php +++ /dev/null @@ -1,82 +0,0 @@ - 'device', - 'device' => $device['device_id'], - 'tab' => 'vlans', -]; - -print_optionbar_start(); - -echo "VLANs » "; - -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 " '; - } - - $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 " '; - } - - /* - echo(' ('); - if ($vars['graph'] == $type && $vars['type'] == "minigraphs") { echo(" "); } - echo(')'); - */ - $type_sep = ' | '; -} - -print_optionbar_end(); - -echo '
@lang('VLAN Number') | +@lang('VLAN Name') | +@lang('Ports') | +
---|---|---|
{{ $vlan_number }} | +{{ $vlans->first()->vlan_name }} | ++ @foreach($vlans as $port) + @if(!$vars) +@portLink($port->port, $port->port->getShortLabel()) +@if($port->untagged) +(U)@endif +@if(!$loop->last), +@endif + + @else + + @endif + @endforeach + | +