2018-12-20 01:18:30 -02:00
|
|
|
<?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/>.
|
2018-12-20 01:18:30 -02:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 20:09:53 +02:00
|
|
|
*
|
2018-12-20 01:18:30 -02:00
|
|
|
* @copyright 2018 Tony Murray
|
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Table;
|
|
|
|
|
|
|
|
|
|
use App\Models\PortsNac;
|
2023-10-06 07:34:14 -05:00
|
|
|
use LibreNMS\Util\Mac;
|
2018-12-20 01:18:30 -02:00
|
|
|
use LibreNMS\Util\Url;
|
|
|
|
|
|
|
|
|
|
class PortNacController extends TableController
|
|
|
|
|
{
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2023-09-01 03:25:24 +02:00
|
|
|
'device_id' => 'int',
|
2018-12-20 01:18:30 -02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function searchFields($request)
|
|
|
|
|
{
|
|
|
|
|
return ['username', 'ip_address', 'mac_address'];
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 09:50:21 -05:00
|
|
|
protected function sortFields($request)
|
|
|
|
|
{
|
|
|
|
|
return [
|
2023-09-01 03:25:24 +02:00
|
|
|
'device_id',
|
2020-06-15 09:50:21 -05:00
|
|
|
'port_id',
|
|
|
|
|
'mac_address',
|
2021-05-10 21:56:48 +02:00
|
|
|
'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',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 01:18:30 -02:00
|
|
|
/**
|
|
|
|
|
* Defines the base query for this resource
|
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2018-12-20 01:18:30 -02:00
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
|
|
|
|
|
*/
|
|
|
|
|
public function baseQuery($request)
|
|
|
|
|
{
|
2023-09-01 03:25:24 +02:00
|
|
|
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))
|
2021-05-10 21:56:48 +02:00
|
|
|
->hasAccess($request->user())
|
2023-09-01 03:25:24 +02:00
|
|
|
->with('port')
|
|
|
|
|
->with('device');
|
2018-12-20 01:18:30 -02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
*/
|
2018-12-20 01:18:30 -02:00
|
|
|
public function formatItem($nac)
|
|
|
|
|
{
|
|
|
|
|
$item = $nac->toArray();
|
2023-10-06 07:34:14 -05:00
|
|
|
$mac = Mac::parse($item['mac_address']);
|
2018-12-20 01:18:30 -02:00
|
|
|
$item['port_id'] = Url::portLink($nac->port, $nac->port->getShortLabel());
|
2023-10-06 07:34:14 -05:00
|
|
|
$item['mac_oui'] = $mac->vendor();
|
|
|
|
|
$item['mac_address'] = $mac->readable();
|
2021-05-10 21:56:48 +02:00
|
|
|
$item['port'] = null; //free some unused data to be sent to the browser
|
2023-09-01 03:25:24 +02:00
|
|
|
$item['device_id'] = Url::deviceLink($nac->device);
|
2018-12-20 01:18:30 -02:00
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
}
|
|
|
|
|
}
|