1 | <?php |
||
2 | /** |
||
3 | * PortNacController.php |
||
4 | * |
||
5 | * -Description- |
||
6 | * |
||
7 | * This program is free software: you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation, either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
19 | * |
||
20 | * @link https://www.librenms.org |
||
21 | * |
||
22 | * @copyright 2018 Tony Murray |
||
23 | * @author Tony Murray <[email protected]> |
||
24 | */ |
||
25 | |||
26 | namespace App\Http\Controllers\Table; |
||
27 | |||
28 | use App\Models\PortsNac; |
||
29 | use LibreNMS\Util\Rewrite; |
||
30 | use LibreNMS\Util\Url; |
||
31 | |||
32 | class PortNacController extends TableController |
||
33 | { |
||
34 | public function rules() |
||
35 | { |
||
36 | return [ |
||
37 | 'device_id' => 'required|int', |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | public function searchFields($request) |
||
42 | { |
||
43 | return ['username', 'ip_address', 'mac_address']; |
||
44 | } |
||
45 | |||
46 | protected function sortFields($request) |
||
47 | { |
||
48 | return [ |
||
49 | 'port_id', |
||
50 | 'mac_address', |
||
51 | 'mac_oui', |
||
52 | 'ip_address', |
||
53 | 'vlan', |
||
54 | 'domain', |
||
55 | 'host_mode', |
||
56 | 'username', |
||
57 | 'authz_by', |
||
58 | 'timeout', |
||
59 | 'time_elapsed', |
||
60 | 'time_left', |
||
61 | 'authc_status', |
||
62 | 'authz_status', |
||
63 | 'method', |
||
64 | ]; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Defines the base query for this resource |
||
69 | * |
||
70 | * @param \Illuminate\Http\Request $request |
||
71 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder |
||
72 | */ |
||
73 | public function baseQuery($request) |
||
74 | { |
||
75 | return PortsNac::select('port_id', 'mac_address', 'ip_address', 'vlan', 'domain', 'host_mode', 'username', 'authz_by', 'timeout', 'time_elapsed', 'time_left', 'authc_status', 'authz_status', 'method') |
||
76 | ->where('device_id', $request->device_id) |
||
77 | ->hasAccess($request->user()) |
||
78 | ->with('port'); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param PortsNac $nac |
||
83 | */ |
||
84 | public function formatItem($nac) |
||
85 | { |
||
86 | $item = $nac->toArray(); |
||
87 | $item['port_id'] = Url::portLink($nac->port, $nac->port->getShortLabel()); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
88 | $item['mac_oui'] = Rewrite::readableOUI($item['mac_address']); |
||
89 | $item['mac_address'] = Rewrite::readableMac($item['mac_address']); |
||
90 | $item['port'] = null; //free some unused data to be sent to the browser |
||
91 | |||
92 | return $item; |
||
93 | } |
||
94 | } |
||
95 |