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>
|
2017-05-01 23:49:11 -05:00
|
|
|
* Copyright (c) 2017 Neil Lathwood <https://github.com/murrant>
|
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
|
|
|
|
2019-01-09 19:40:27 -06:00
|
|
|
header('Content-type: application/json');
|
2014-06-14 23:05:31 +01:00
|
|
|
|
|
|
|
|
// FUA
|
2015-08-10 15:13:27 +00:00
|
|
|
|
2019-08-05 14:16:05 -05:00
|
|
|
if (! Auth::user()->hasGlobalAdmin()) {
|
2019-01-09 19:40:27 -06:00
|
|
|
exit(json_encode([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'You need to be admin',
|
|
|
|
|
]));
|
2015-08-10 15:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-25 04:37:13 -06:00
|
|
|
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id']) || ! isset($_POST['data'])) {
|
2019-01-09 19:40:27 -06:00
|
|
|
exit(json_encode([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Invalid values given',
|
|
|
|
|
]));
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2017-05-01 23:49:11 -05:00
|
|
|
$update = dbUpdate(
|
2023-10-12 07:15:03 -07:00
|
|
|
[$_POST['value_type'] => set_null($_POST['data'], null), 'sensor_custom' => 'Yes'],
|
2017-05-01 23:49:11 -05:00
|
|
|
'wireless_sensors',
|
|
|
|
|
'`sensor_id` = ? AND `device_id` = ?',
|
2019-01-09 19:40:27 -06:00
|
|
|
[$_POST['sensor_id'], $_POST['device_id']]
|
2017-05-01 23:49:11 -05:00
|
|
|
);
|
2014-06-14 23:05:31 +01:00
|
|
|
if (! empty($update) || $update == '0') {
|
2019-01-09 19:40:27 -06:00
|
|
|
exit(json_encode([
|
|
|
|
|
'status' => 'ok',
|
|
|
|
|
'message' => 'Updated sensor value',
|
|
|
|
|
]));
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2019-01-09 19:40:27 -06:00
|
|
|
exit(json_encode([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Failed to update sensor value',
|
|
|
|
|
]));
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
|
|
|
|
}
|