librenms-librenms/html/includes/forms/component.inc.php
Tony Murray 32a7c50189 Use Laravel authentication (#8702)
* Use Laravel for authentication
Support legacy auth methods
Always create DB entry for users (segregate by auth method)

Port api auth to Laravel

restrict poller errors to devices the user has access to

Run checks on every page load.  But set a 5 minute (configurable) timer.
Only run some checks if the user is an admin

Move toastr down a few pixels so it isn't as annoying.

Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user.
Add two missing menu entries in the laravel menu

Rewrite 2FA code
Simplify some and verify code before applying

Get http-auth working
Handle legacy $_SESSION differently.  Allows Auth::once(), etc to work.

* Fix tests and mysqli extension check

* remove duplicate Toastr messages

* Fix new items

* Rename 266.sql to 267.sql
2018-09-11 07:51:35 -05:00

85 lines
2.2 KiB
PHP

<?php
use LibreNMS\Authentication\LegacyAuth;
header('Content-type: application/json');
if (!LegacyAuth::user()->hasGlobalAdmin()) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error with config';
// enable/disable components on devices.
$device_id = intval($_POST['device']);
$OBJCOMP = new LibreNMS\Component();
// 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 = array();
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;
}
} else {
// 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;
}
} else {
// 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.
$STATUS = $OBJCOMP->setComponentPrefs($device_id, $COMPONENTS);
$message = count($UPDATE).' Device records updated.';
$status = 'ok';
} else {
$message = 'Record unchanged. No update necessary.';
$status = 'ok';
}
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);