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
|
|
|
|
2019-08-05 14:16:05 -05:00
|
|
|
if (!Auth::user()->hasGlobalAdmin()) {
|
2018-09-16 19:23:12 +02:00
|
|
|
$response = array(
|
|
|
|
'status' => 'error',
|
|
|
|
'message' => 'Need to be admin',
|
|
|
|
);
|
|
|
|
echo _json_encode($response);
|
|
|
|
exit;
|
2015-08-10 15:13:27 +00:00
|
|
|
}
|
|
|
|
|
2018-09-16 19:23:12 +02:00
|
|
|
$status = 'error';
|
|
|
|
$message = 'Error updating sensor limit';
|
|
|
|
$device_id = $_POST['device_id'];
|
|
|
|
$sensor_id = $_POST['sensor_id'];
|
|
|
|
$value_type = $_POST['value_type'];
|
|
|
|
$data = $_POST['data'];
|
|
|
|
|
|
|
|
if (!is_numeric($device_id)) {
|
|
|
|
$message = 'Missing device id';
|
|
|
|
} elseif (!is_numeric($sensor_id)) {
|
|
|
|
$message = 'Missing sensor id';
|
|
|
|
} elseif (!isset($data)) {
|
|
|
|
$message = 'Missing data';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2018-09-16 19:23:12 +02:00
|
|
|
if (dbUpdate(array($value_type => set_null($data, array('NULL')), 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($sensor_id, $device_id)) >= 0) {
|
|
|
|
$message = 'Sensor value updated';
|
|
|
|
$status = 'ok';
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2018-09-16 19:23:12 +02:00
|
|
|
$message = 'Could not update sensor value';
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
2018-09-16 19:23:12 +02:00
|
|
|
|
|
|
|
$response = array(
|
|
|
|
'status' => $status,
|
|
|
|
'message' => $message,
|
|
|
|
);
|
|
|
|
echo _json_encode($response);
|