2014-06-14 23:05:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2014-06-17 00:51:02 +01:00
|
|
|
* LibreNMS
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk>
|
2018-09-16 19:23:12 +02:00
|
|
|
* Copyright (c) 2018 TheGreatDoc <https://github.com/TheGreatDoc>
|
2014-06-17 00:51:02 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-04-07 15:55:28 -05:00
|
|
|
|
2018-09-16 19:23:12 +02:00
|
|
|
header('Content-type: application/json');
|
2015-08-10 15:13:27 +00:00
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
if (! Auth::user()->hasGlobalAdmin()) {
|
|
|
|
$response = [
|
2018-09-16 19:23:12 +02:00
|
|
|
'status' => 'error',
|
|
|
|
'message' => 'Need to be admin',
|
2020-09-21 15:40:17 +02:00
|
|
|
];
|
2018-09-16 19:23:12 +02:00
|
|
|
echo _json_encode($response);
|
|
|
|
exit;
|
2015-08-10 15:13:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 15:40:17 +02:00
|
|
|
if (isset($_POST['sub_type']) && ! empty($_POST['sub_type'])) {
|
|
|
|
$status = 'error';
|
2018-09-16 19:23:12 +02:00
|
|
|
$message = 'Error removing custom';
|
2020-09-21 15:40:17 +02:00
|
|
|
if (dbUpdate(['sensor_custom' => 'No'], 'sensors', '`sensor_id` = ?', [$_POST['sensor_id']]) >= 0) {
|
|
|
|
$status = 'ok';
|
2018-09-16 19:23:12 +02:00
|
|
|
$message = 'Custom limit removed. New one will be set up in rediscovery';
|
|
|
|
} else {
|
|
|
|
$message = 'Couldn\'t not remove custom. Enable debug and check logfile';
|
|
|
|
}
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2020-09-21 15:40:17 +02:00
|
|
|
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id'])) {
|
2018-09-16 19:23:12 +02:00
|
|
|
$message = "Invalid device or sensor id";
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-07-13 20:10:26 +02:00
|
|
|
if ($_POST['state'] == 'true') {
|
|
|
|
$state = 1;
|
2018-09-16 19:23:12 +02:00
|
|
|
$state_string = "enabled";
|
2016-08-18 20:28:22 -05:00
|
|
|
} elseif ($_POST['state'] == 'false') {
|
2015-07-13 20:10:26 +02:00
|
|
|
$state = 0;
|
2018-09-16 19:23:12 +02:00
|
|
|
$state_string = "disabled";
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2015-07-13 20:10:26 +02:00
|
|
|
$state = 0;
|
2018-09-16 19:23:12 +02:00
|
|
|
$state_string = "disabled";
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2020-09-21 15:40:17 +02:00
|
|
|
if (dbUpdate(['sensor_alert' => $state], 'sensors', '`sensor_id` = ? AND `device_id` = ?', [$_POST['sensor_id'], $_POST['device_id']]) >= 0) {
|
|
|
|
$status = ($state == 0) ? 'info' : 'ok';
|
2018-09-16 19:23:12 +02:00
|
|
|
$message = 'Alerts ' . $state_string . ' for sensor ' . $_POST['sensor_desc'];
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2018-09-16 19:23:12 +02:00
|
|
|
$status = 'error';
|
|
|
|
$message = 'Couldn\'t ' . substr($state_string, 0, -1) . ' alerts for sensor ' . $_POST['sensor_desc'] . '. Enable debug and check librenms.log';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 15:40:17 +02:00
|
|
|
$response = [
|
2018-09-16 19:23:12 +02:00
|
|
|
'status' => $status,
|
2020-09-21 15:40:17 +02:00
|
|
|
'message' => $message,
|
|
|
|
];
|
2018-09-16 19:23:12 +02:00
|
|
|
echo _json_encode($response);
|