forked from PipoCanaja/InterfaceAdminPlugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenable-port.inc.php
More file actions
95 lines (79 loc) · 2.09 KB
/
enable-port.inc.php
File metadata and controls
95 lines (79 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
* LibreNMS
*
* Copyright (c) 2018 PipoCanaja <https://github.com/PipoCanaja>
*
* 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. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
use LibreNMS\Authentication\LegacyAuth;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
/*
* Default answer for AJAX call
*
*/
$status = 'error';
$message = 'Error enabling port';
/*
* Retrieving device and port parameters
*
*/
$device_id = mres($_POST['device_id']);
$port_id = mres($_POST['port_id']);
/*
* Quick sanity checks
*
*/
if (!is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($port_id)) {
$message = 'Missing port id';
} else {
/*
* Get device/port objects
*
*/
$port = cleanPort(get_port_by_id($port_id));
$device = device_by_id_cache($device_id);
/*
* Let's do the SNMP Set to the device
*
*/
$res = snmp_set($device, ".1.3.6.1.2.1.2.2.1.7.$port[ifIndex]", 'i', 1);
/*
* Return the results of the call
*
*/
if ($res == false) {
$message = 'Could not enable '.$port['ifName'].' port';
} elseif ($res == 'community') {
$message = 'Community in LibreNMS is probably ReadOnly. No answer from device with current community';
$status = 'error';
} elseif ($res == 'multiple-oid') {
$message = 'Cannot send multiple OIDs to snmp_set, plugin internal error, please report';
$status = 'error';
} else {
$message = 'Port '.$port['ifName'].' enabled successfully. ';
$status = 'ok';
log_event('GUI : Enabled port', $device_id, 'interface', 3, $port_id);
}
}
$response = array(
'status' => $status,
'message' => $message,
'extra' => $res,
);
echo _json_encode($response);
?>