mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix wireless sensor edit messages and collection alert rule (#9624)
* Fix wireless sensor edit messages and collection alert rule * fix alert rule quotes * json type
This commit is contained in:
@@ -15,20 +15,35 @@
|
||||
|
||||
use LibreNMS\Authentication\LegacyAuth;
|
||||
|
||||
header('Content-type: text/plain');
|
||||
header('Content-type: application/json');
|
||||
|
||||
// FUA
|
||||
|
||||
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
||||
die('ERROR: You need to be admin');
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'You need to be admin'
|
||||
]));
|
||||
}
|
||||
|
||||
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
|
||||
dbUpdate(array('sensor_custom' => 'No'), 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']));
|
||||
if (isset($_POST['sub_type']) && $_POST['sub_type'] == 'remove-custom') {
|
||||
if (dbUpdate(['sensor_custom' => 'No'], 'wireless_sensors', '`sensor_id` = ?', array($_POST['sensor_id']))) {
|
||||
die(json_encode([
|
||||
'status' => 'ok',
|
||||
'message' => 'Custom limit removed'
|
||||
]));
|
||||
}
|
||||
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Could not remove custom. Check librenms.log'
|
||||
]));
|
||||
} else {
|
||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
|
||||
echo 'error with data';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid values given'
|
||||
]));
|
||||
} else {
|
||||
if ($_POST['state'] == 'true') {
|
||||
$state = 1;
|
||||
@@ -39,17 +54,21 @@ if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
|
||||
}
|
||||
|
||||
$update = dbUpdate(
|
||||
array('sensor_alert' => $state),
|
||||
['sensor_alert' => $state],
|
||||
'wireless_sensors',
|
||||
'`sensor_id` = ? AND `device_id` = ?',
|
||||
array($_POST['sensor_id'], $_POST['device_id'])
|
||||
[$_POST['sensor_id'], $_POST['device_id']]
|
||||
);
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'ok',
|
||||
'message' => 'Updated sensor value'
|
||||
]));
|
||||
} else {
|
||||
echo 'error';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to update sensor value'
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,29 +15,38 @@
|
||||
|
||||
use LibreNMS\Authentication\LegacyAuth;
|
||||
|
||||
header('Content-type: text/plain');
|
||||
header('Content-type: application/json');
|
||||
|
||||
// FUA
|
||||
|
||||
if (!LegacyAuth::user()->hasGlobalAdmin()) {
|
||||
die('ERROR: You need to be admin');
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'You need to be admin'
|
||||
]));
|
||||
}
|
||||
|
||||
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
|
||||
echo 'error with data';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid values given'
|
||||
]));
|
||||
} else {
|
||||
$update = dbUpdate(
|
||||
array($_POST['value_type'] => set_null($_POST['data'], array('NULL')), 'sensor_custom' => 'Yes'),
|
||||
[$_POST['value_type'] => set_null($_POST['data'], ['NULL']), 'sensor_custom' => 'Yes'],
|
||||
'wireless_sensors',
|
||||
'`sensor_id` = ? AND `device_id` = ?',
|
||||
array($_POST['sensor_id'], $_POST['device_id'])
|
||||
[$_POST['sensor_id'], $_POST['device_id']]
|
||||
);
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'ok',
|
||||
'message' => 'Updated sensor value'
|
||||
]));
|
||||
} else {
|
||||
echo 'error';
|
||||
exit;
|
||||
die(json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Failed to update sensor value'
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
@@ -131,7 +131,7 @@ $('#newThread').on('click', function(e){
|
||||
}
|
||||
|
||||
},
|
||||
error:function(){
|
||||
error:function(data){
|
||||
toastr.error(data.message);
|
||||
}
|
||||
});
|
||||
@@ -169,7 +169,7 @@ $( ".sensor" ).bind('blur keyup',function(e) {
|
||||
}
|
||||
|
||||
},
|
||||
error:function(){
|
||||
error:function(data){
|
||||
toastr.error(data.message);
|
||||
}
|
||||
});
|
||||
@@ -198,7 +198,7 @@ $('input[name="alert-status"]').on('switchChange.bootstrapSwitch', function(eve
|
||||
toastr.error(data.message);
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
error:function(data){
|
||||
toastr.error(data.message);
|
||||
}
|
||||
});
|
||||
@@ -216,7 +216,7 @@ $("[name='remove-custom']").on('click', function(event) {
|
||||
toastr.success(data.message);
|
||||
$this.addClass('disabled');
|
||||
},
|
||||
error:function(){
|
||||
error:function(data){
|
||||
toastr.error(data.message);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user