Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2015-08-15 16:01:43 +10:00
<?php
2016-04-26 15:06:29 -07:00
header('Content-type: application/json');
2015-08-15 16:01:43 +10:00
if (! Auth::user()->hasGlobalAdmin()) {
2015-08-15 16:01:43 +10:00
$response = [
2024-01-05 05:39:12 +01:00
'status' => 'error',
2015-08-15 16:01:43 +10:00
'message' => 'Need to be admin',
];
2021-03-04 07:55:41 -06:00
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
2015-08-15 16:01:43 +10:00
exit;
}
$status = 'error';
$message = 'Error with config';
// enable/disable components on devices.
$device_id = intval($_POST['device']);
2016-08-21 08:07:14 -05:00
$OBJCOMP = new LibreNMS\Component();
2015-08-15 16:01:43 +10:00
// Go get the component array.
$COMPONENTS = $OBJCOMP->getComponents($device_id);
// We only care about our device id.
$COMPONENTS = $COMPONENTS[$device_id];
// Track how many updates we are making.
$UPDATE = [];
foreach ($COMPONENTS as $ID => $AVP) {
// Is the component disabled?
if (isset($_POST['dis_' . $ID])) {
// Yes it is, was it disabled before?
if ($COMPONENTS[$ID]['disabled'] == 0) {
// No it wasn't, best we disable it then..
$COMPONENTS[$ID]['disabled'] = 1;
$UPDATE[$ID] = true;
}
2016-08-18 20:28:22 -05:00
} else {
2015-08-15 16:01:43 +10:00
// No its not, was it disabled before?
if ($COMPONENTS[$ID]['disabled'] == 1) {
// Yes it was, best we enable it then..
$COMPONENTS[$ID]['disabled'] = 0;
$UPDATE[$ID] = true;
}
}
// Is the component ignored?
if (isset($_POST['ign_' . $ID])) {
// Yes it is, was it ignored before?
if ($COMPONENTS[$ID]['ignore'] == 0) {
// No it wasn't, best we ignore it then..
$COMPONENTS[$ID]['ignore'] = 1;
$UPDATE[$ID] = true;
}
2016-08-18 20:28:22 -05:00
} else {
2015-08-15 16:01:43 +10:00
// No its not, was it ignored before?
if ($COMPONENTS[$ID]['ignore'] == 1) {
// Yes it was, best we un-ignore it then..
$COMPONENTS[$ID]['ignore'] = 0;
$UPDATE[$ID] = true;
}
}
}
if (count($UPDATE) > 0) {
// Update our edited components.
2016-08-18 20:28:22 -05:00
$STATUS = $OBJCOMP->setComponentPrefs($device_id, $COMPONENTS);
2015-08-15 16:01:43 +10:00
$message = count($UPDATE) . ' Device records updated.';
$status = 'ok';
2016-08-18 20:28:22 -05:00
} else {
2015-08-15 16:01:43 +10:00
$message = 'Record unchanged. No update necessary.';
$status = 'ok';
}
$response = [
2024-01-05 05:39:12 +01:00
'status' => $status,
'message' => $message,
2015-08-15 16:01:43 +10:00
];
2021-03-04 07:55:41 -06:00
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);