Files
librenms-librenms/app/Http/Controllers/Table/PortNacController.php
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* PortNacController.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Http\Controllers\Table;
use App\Models\PortsNac;
use LibreNMS\Util\Mac;
use LibreNMS\Util\Url;
class PortNacController extends TableController
{
public function rules()
{
return [
'device_id' => 'int',
];
}
public function searchFields($request)
{
return ['username', 'ip_address', 'mac_address'];
}
2020-06-15 09:50:21 -05:00
protected function sortFields($request)
{
return [
'device_id',
2020-06-15 09:50:21 -05:00
'port_id',
'mac_address',
'mac_oui',
2020-06-15 09:50:21 -05:00
'ip_address',
'vlan',
'domain',
'host_mode',
'username',
'authz_by',
'timeout',
'time_elapsed',
'time_left',
'authc_status',
'authz_status',
'method',
];
}
/**
* Defines the base query for this resource
*
2021-09-08 23:35:56 +02:00
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
*/
public function baseQuery($request)
{
return PortsNac::select('device_id', 'port_id', 'mac_address', 'ip_address', 'vlan', 'domain', 'host_mode', 'username', 'authz_by', 'timeout', 'time_elapsed', 'time_left', 'authc_status', 'authz_status', 'method')
->when($request->device_id, fn ($q, $id) => $q->where('device_id', $id))
->hasAccess($request->user())
->with('port')
->with('device');
}
2021-03-30 11:16:44 +02:00
/**
2021-09-08 23:35:56 +02:00
* @param PortsNac $nac
2021-03-30 11:16:44 +02:00
*/
public function formatItem($nac)
{
$item = $nac->toArray();
$mac = Mac::parse($item['mac_address']);
$item['port_id'] = Url::portLink($nac->port, $nac->port->getShortLabel());
$item['mac_oui'] = $mac->vendor();
$item['mac_address'] = $mac->readable();
$item['port'] = null; //free some unused data to be sent to the browser
$item['device_id'] = Url::deviceLink($nac->device);
return $item;
}
}