1 | <?php |
||
2 | |||
3 | /* |
||
4 | * LibreNMS |
||
5 | * |
||
6 | * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify it |
||
9 | * under the terms of the GNU General Public License as published by the |
||
10 | * Free Software Foundation, either version 3 of the License, or (at your |
||
11 | * option) any later version. Please see LICENSE.txt at the top level of |
||
12 | * the source code distribution for details. |
||
13 | */ |
||
14 | |||
15 | if (! Auth::user()->hasGlobalAdmin()) { |
||
16 | $response = [ |
||
17 | 'status' => 'error', |
||
18 | 'message' => 'Need to be admin', |
||
19 | ]; |
||
20 | echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||
21 | exit; |
||
22 | } |
||
23 | |||
24 | if (isset($_POST['device_id'])) { |
||
25 | if (! is_numeric($_POST['device_id'])) { |
||
26 | $status = 'error'; |
||
27 | $message = 'Invalid device id ' . $_POST['device_id']; |
||
28 | } else { |
||
29 | $result = device_discovery_trigger($_POST['device_id']); |
||
30 | if (! empty($result['status']) || $result['status'] == '0') { |
||
31 | $status = 'ok'; |
||
32 | } else { |
||
33 | $status = 'error'; |
||
34 | } |
||
35 | $message = $result['message']; |
||
36 | } |
||
37 | } elseif (isset($_POST['device_group_id'])) { |
||
38 | if (! is_numeric($_POST['device_group_id'])) { |
||
39 | $status = 'error'; |
||
40 | $message = 'Invalid device group id ' . $_POST['device_group_id']; |
||
41 | } else { |
||
42 | $device_ids = dbFetchColumn('SELECT `device_id` FROM `device_group_device` WHERE `device_group_id` = ?', [$_POST['device_group_id']]); |
||
43 | $update = 0; |
||
44 | foreach ($device_ids as $device_id) { |
||
45 | $result = device_discovery_trigger($device_id); |
||
46 | $update += $result['status']; |
||
47 | } |
||
48 | |||
49 | if (! empty($update) || $update == '0') { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
50 | $status = 'ok'; |
||
51 | $message = 'Devices of group ' . $_POST['device_group_id'] . ' will be rediscovered'; |
||
52 | } else { |
||
53 | $status = 'error'; |
||
54 | $message = 'Error rediscovering devices of group ' . $_POST['device_group_id']; |
||
55 | } |
||
56 | } |
||
57 | } else { |
||
58 | $status = 'Error'; |
||
59 | $message = 'Undefined POST keys received'; |
||
60 | } |
||
61 | |||
62 | $output = [ |
||
63 | 'status' => $status, |
||
64 | 'message' => $message, |
||
65 | ]; |
||
66 | |||
67 | header('Content-type: application/json'); |
||
68 | echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
||
69 |