1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * reset-port-state.inc.php |
||||
5 | * |
||||
6 | * LibreNMS form for reseting port state |
||||
7 | * |
||||
8 | * This program is free software: you can redistribute it and/or modify |
||||
9 | * it under the terms of the GNU General Public License as published by |
||||
10 | * the Free Software Foundation, either version 3 of the License, or |
||||
11 | * (at your option) any later version. |
||||
12 | * |
||||
13 | * This program is distributed in the hope that it will be useful, |
||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||||
16 | * GNU General Public License for more details. |
||||
17 | * |
||||
18 | * You should have received a copy of the GNU General Public License |
||||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||||
20 | * |
||||
21 | * @link https://www.librenms.org |
||||
22 | * |
||||
23 | * @copyright 2021 Adam Bishop |
||||
24 | * @author Adam Bishop <[email protected]> |
||||
25 | */ |
||||
26 | |||||
27 | use App\Models\Device; |
||||
28 | |||||
29 | if (! Auth::user()->hasGlobalAdmin()) { |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
30 | $response = [ |
||||
31 | 'status' => 'error', |
||||
32 | 'message' => 'Need to be admin', |
||||
33 | ]; |
||||
34 | echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||||
35 | exit; |
||||
36 | } |
||||
37 | |||||
38 | if (isset($_POST['device_id'])) { |
||||
39 | if (! is_numeric($_POST['device_id'])) { |
||||
40 | $status = 'error'; |
||||
41 | $message = 'Invalid device id ' . $_POST['device_id']; |
||||
42 | } else { |
||||
43 | $device = Device::find($_POST['device_id']); |
||||
44 | |||||
45 | log_event('Port state history reset by ' . Auth::user()->username, $device); |
||||
0 ignored issues
–
show
It seems like
$device can also be of type App\Models\Device ; however, parameter $device of log_event() does only seem to accept array|integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
46 | |||||
47 | try { |
||||
48 | foreach ($device->ports()->get() as $port) { |
||||
49 | $port->ifSpeed_prev = null; |
||||
50 | $port->ifOperStatus_prev = null; |
||||
51 | $port->ifAdminStatus_prev = null; |
||||
52 | |||||
53 | $port->save(); |
||||
54 | } |
||||
55 | $status = 'ok'; |
||||
56 | $message = 'Port state cleared successfully'; |
||||
57 | } catch (Exception $e) { |
||||
58 | $status = 'error'; |
||||
59 | $message = 'Clearing port state failed: $e'; |
||||
60 | } |
||||
61 | } |
||||
62 | } else { |
||||
63 | $status = 'Error'; |
||||
64 | $message = 'Undefined POST keys received'; |
||||
65 | } |
||||
66 | |||||
67 | $output = [ |
||||
68 | 'status' => $status, |
||||
69 | 'message' => $message, |
||||
70 | ]; |
||||
71 | |||||
72 | header('Content-type: application/json'); |
||||
73 | echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||||
74 |