Apply fixes from StyleCI (#12120)

This commit is contained in:
Jellyfrog
2020-09-21 15:40:17 +02:00
committed by GitHub
parent 77c531527c
commit 82f43cb98d
1733 changed files with 18337 additions and 18540 deletions
+10 -10
View File
@@ -27,26 +27,26 @@ use LibreNMS\Config;
header('Content-type: application/json');
$alert_id = $vars['alert_id'];
$state = $vars['state'];
$ack_msg = $vars['ack_msg'];
$alert_id = $vars['alert_id'];
$state = $vars['state'];
$ack_msg = $vars['ack_msg'];
$until_clear = $vars['ack_until_clear'];
$status = 'error';
if (!is_numeric($alert_id)) {
if (! is_numeric($alert_id)) {
$message = 'No alert selected';
} elseif (!is_numeric($state)) {
} elseif (! is_numeric($state)) {
$message = 'No state passed';
} else {
if ($state == 2) {
$state = 1;
$state_descr = 'UnAck';
$open = 1;
$open = 1;
} elseif ($state >= 1) {
$state = 2;
$state_descr = 'Ack';
$open = 1;
$open = 1;
}
if ($until_clear === 'true') {
@@ -67,7 +67,7 @@ if (!is_numeric($alert_id)) {
];
$note = dbFetchCell('SELECT note FROM alerts WHERE id=?', [$alert_id]);
if (!empty($note)) {
if (! empty($note)) {
$note .= PHP_EOL;
}
$data['note'] = $note . date(Config::get('dateformat.long')) . " - $state_descr ($username) $ack_msg";
@@ -78,13 +78,13 @@ if (!is_numeric($alert_id)) {
log_event("$username acknowledged alert {$alert_info['name']} note: $ack_msg", $alert_info['device_id'], 'alert', 2, $alert_id);
}
$message = 'Alert acknowledged status changed.';
$status = 'ok';
$status = 'ok';
} else {
$message = 'Alert has not been acknowledged.';
}
}//end if
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message,
]));
+11 -12
View File
@@ -21,35 +21,34 @@
* @package LibreNMS
* @subpackage Dashboards
*/
header('Content-type: application/json');
if (!Auth::check()) {
$response = array(
if (! Auth::check()) {
$response = [
'status' => 'error',
'message' => 'Unauthenticated',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'unknown error';
$status = 'error';
$message = 'unknown error';
$dashboard_name = trim($_REQUEST['dashboard_name']);
if (!empty($dashboard_name) && ($dash_id = dbInsert(['dashboard_name' => $dashboard_name, 'user_id' => Auth::id()], 'dashboards'))) {
$status = 'ok';
if (! empty($dashboard_name) && ($dash_id = dbInsert(['dashboard_name' => $dashboard_name, 'user_id' => Auth::id()], 'dashboards'))) {
$status = 'ok';
$message = 'Dashboard ' . $dashboard_name . ' created';
} else {
$status = 'error';
$status = 'error';
$message = 'ERROR: Could not create';
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'dashboard_id' => $dash_id
);
'dashboard_id' => $dash_id,
];
echo _json_encode($response);
+6 -7
View File
@@ -22,22 +22,21 @@
* @copyright 2018 Neil Lathwood
* @author Neil Lathwood <[email protected]>
*/
header('Content-type: application/json');
$alert_id = $vars['alert_id'];
$sub_type = $vars['sub_type'];
$note = $vars['note'] ?: '';
$status = 'error';
$note = $vars['note'] ?: '';
$status = 'error';
if (is_numeric($alert_id)) {
if ($sub_type === 'get_note') {
$note = dbFetchCell("SELECT `note` FROM `alerts` WHERE `id` = ?", [$alert_id]);
$note = dbFetchCell("SELECT `note` FROM `alerts` WHERE `id` = ?", [$alert_id]);
$message = 'Alert note retrieved';
$status = 'ok';
$status = 'ok';
} else {
if (dbUpdate(['note' => $note], 'alerts', '`id` = ?', [$alert_id])) {
$status = 'ok';
$status = 'ok';
$message = 'Note updated';
} else {
$message = 'Could not update note';
@@ -46,7 +45,7 @@ if (is_numeric($alert_id)) {
} else {
$message = 'Invalid alert id';
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message,
'note' => $note,
+48 -49
View File
@@ -28,8 +28,8 @@ use LibreNMS\Alerting\QueryBuilderParser;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: You need to be admin',
]));
@@ -38,7 +38,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
$status = 'ok';
$message = '';
$builder_json = $vars['builder_json'];
$builder_json = $vars['builder_json'];
$override_query = $vars['override_query'];
$options = [
@@ -50,23 +50,23 @@ if ($override_query === 'on') {
} else {
$query = QueryBuilderParser::fromJson($builder_json)->toSql();
}
$rule_id = $_POST['rule_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$interval = mres($_POST['interval']);
$mute = mres(isset($_POST['mute']) ? $_POST['mute'] : null);
$invert = mres(isset($_POST['invert']) ? $_POST['invert'] : null);
$name = mres($_POST['name']);
$proc = mres($_POST['proc']);
$recovery = ($vars['recovery']);
$invert_map = mres(isset($_POST['invert_map']) ? $_POST['invert_map'] : null);
$severity = mres($_POST['severity']);
$rule_id = $_POST['rule_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$interval = mres($_POST['interval']);
$mute = mres(isset($_POST['mute']) ? $_POST['mute'] : null);
$invert = mres(isset($_POST['invert']) ? $_POST['invert'] : null);
$name = mres($_POST['name']);
$proc = mres($_POST['proc']);
$recovery = ($vars['recovery']);
$invert_map = mres(isset($_POST['invert_map']) ? $_POST['invert_map'] : null);
$severity = mres($_POST['severity']);
if (!is_numeric($count)) {
if (! is_numeric($count)) {
$count = '-1';
}
$delay_sec = convert_delay($delay);
$delay_sec = convert_delay($delay);
$interval_sec = convert_delay($interval);
if ($mute == 'on') {
@@ -89,7 +89,7 @@ if ($invert_map == 'on') {
$invert_map = false;
}
$extra = array(
$extra = [
'mute' => $mute,
'count' => $count,
'delay' => $delay_sec,
@@ -97,47 +97,46 @@ $extra = array(
'interval' => $interval_sec,
'recovery' => $recovery,
'options' => $options,
);
];
$extra_json = json_encode($extra);
if (!is_array($vars['maps']) && $invert_map) {
die(json_encode([
if (! is_array($vars['maps']) && $invert_map) {
exit(json_encode([
'status' => 'error',
'message' => 'Invert map is on but no selection in devices, groups and locations match list<br />'
'message' => 'Invert map is on but no selection in devices, groups and locations match list<br />',
]));
}
if (is_numeric($rule_id) && $rule_id > 0) {
if (dbUpdate(
array(
[
'severity' => $severity,
'extra' => $extra_json,
'name' => $name,
'proc' => $proc,
'query' => $query,
'builder' => $builder_json,
'invert_map' => $invert_map
),
'invert_map' => $invert_map,
],
'alert_rules',
'id=?',
array($rule_id)
[$rule_id]
) >= 0) {
$message = "Edited Rule: <i>$name</i>";
} else {
$message = "Failed to edit Rule <i>$name</i>";
$status = 'error';
$status = 'error';
}
} else {
if (empty($name)) {
$status = 'error';
$message = 'No rule name provided';
} elseif (empty($builder_json) || empty($query)) {
$status = 'error';
$status = 'error';
$message = 'No rules provided';
} else {
$rule_id = dbInsert(array(
$rule_id = dbInsert([
'rule' => '',
'severity' => $severity,
'extra' => $extra_json,
@@ -146,8 +145,8 @@ if (is_numeric($rule_id) && $rule_id > 0) {
'proc' => $proc,
'query' => $query,
'builder' => $builder_json,
'invert_map' => $invert_map
), 'alert_rules');
'invert_map' => $invert_map,
], 'alert_rules');
if ($rule_id) {
$message = "Added Rule: <i>$name</i>";
@@ -167,13 +166,13 @@ if (is_numeric($rule_id) && $rule_id > 0) {
$devices = [];
$groups = [];
$locations = [];
foreach ((array)$vars['maps'] as $item) {
foreach ((array) $vars['maps'] as $item) {
if (Str::startsWith($item, 'l')) {
$locations[] = (int)substr($item, 1);
$locations[] = (int) substr($item, 1);
} elseif (Str::startsWith($item, 'g')) {
$groups[] = (int)substr($item, 1);
$groups[] = (int) substr($item, 1);
} else {
$devices[] = (int)$item;
$devices[] = (int) $item;
}
}
@@ -184,11 +183,11 @@ if (is_numeric($rule_id) && $rule_id > 0) {
//Update transport groups and transports - can't use dbSyncRelationship
$transports = [];
$groups = [];
foreach ((array)$vars['transports'] as $item) {
foreach ((array) $vars['transports'] as $item) {
if (Str::startsWith($item, 'g')) {
$groups[] = (int)substr($item, 1);
$groups[] = (int) substr($item, 1);
} else {
$transports[] = (int)$item;
$transports[] = (int) $item;
}
}
@@ -207,34 +206,34 @@ if (is_numeric($rule_id) && $rule_id > 0) {
// Insert any new mappings
$insert = [];
foreach ($t_add as $transport_id) {
$insert[] = array (
$insert[] = [
'transport_or_group_id' => $transport_id,
'target_type' => 'single',
'rule_id' => $rule_id
);
'rule_id' => $rule_id,
];
}
foreach ($g_add as $group_id) {
$insert[] = array(
$insert[] = [
'transport_or_group_id' => $group_id,
'target_type' => 'group',
'rule_id' => $rule_id
);
'rule_id' => $rule_id,
];
}
if (!empty($insert)) {
if (! empty($insert)) {
$res = dbBulkInsert($insert, 'alert_transport_map');
}
// Remove old mappings
if (!empty($t_del)) {
if (! empty($t_del)) {
$db_t_values = array_merge([$rule_id], $t_del);
dbDelete('alert_transport_map', 'target_type="single" AND rule_id=? AND transport_or_group_id IN ' . dbGenPlaceholders(count($t_del)), $db_t_values);
}
if (!empty($g_del)) {
if (! empty($g_del)) {
$db_g_values = array_merge([$rule_id], $g_del);
dbDelete('alert_transport_map', 'target_type="group" AND rule_id=? AND transport_or_group_id IN ' . dbGenPlaceholders(count($g_del)), $db_g_values);
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message
'message' => $message,
]));
+9 -10
View File
@@ -21,13 +21,12 @@
* @package LibreNMS
* @subpackage Alerts
*/
$status = 'error';
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-Type: application/json');
$response = array('status' => $status, 'message' => 'You need to be admin');
die(json_encode($response));
$response = ['status' => $status, 'message' => 'You need to be admin'];
exit(json_encode($response));
}
$template_id = 0;
@@ -37,12 +36,12 @@ $create = true;
$name = mres($vars['name']);
if (isset($vars['template']) && empty(view(['template' => $vars['template']], [])->__toString())) {
$message = 'Template failed to be parsed, please check the syntax';
} elseif (!empty($name)) {
} elseif (! empty($name)) {
if ($vars['template'] && is_numeric($vars['template_id'])) {
// Update template
$create = false;
$template_id = $vars['template_id'];
if (!dbUpdate(array('template' => $vars['template'], 'name' => $name, 'title' => $vars['title'], 'title_rec' => $vars['title_rec']), "alert_templates", "id = ?", array($template_id)) >= 0) {
if (! dbUpdate(['template' => $vars['template'], 'name' => $name, 'title' => $vars['title'], 'title_rec' => $vars['title_rec']], "alert_templates", "id = ?", [$template_id]) >= 0) {
$status = 'ok';
} else {
$message = "Failed to update the template";
@@ -50,7 +49,7 @@ if (isset($vars['template']) && empty(view(['template' => $vars['template']], []
} elseif ($vars['template']) {
// Create template
if ($name != 'Default Alert Template') {
$template_newid = dbInsert(array('template' => $vars['template'], 'name' => $name, 'title' => $vars['title'], 'title_rec' => $vars['title_rec']), "alert_templates");
$template_newid = dbInsert(['template' => $vars['template'], 'name' => $name, 'title' => $vars['title'], 'title_rec' => $vars['title_rec']], "alert_templates");
if ($template_newid != false) {
$template_id = $template_newid;
$status = 'ok';
@@ -65,11 +64,11 @@ if (isset($vars['template']) && empty(view(['template' => $vars['template']], []
}
if ($status == 'ok') {
$alertRulesOk = true;
dbDelete('alert_template_map', 'alert_templates_id = ?', array($template_id));
dbDelete('alert_template_map', 'alert_templates_id = ?', [$template_id]);
$rules = explode(',', $vars['rules']);
if ($rules !== false) {
foreach ($rules as $rule_id) {
if (!dbInsert(array('alert_rule_id' => $rule_id, 'alert_templates_id' => $template_id), 'alert_template_map')) {
if (! dbInsert(['alert_rule_id' => $rule_id, 'alert_templates_id' => $template_id], 'alert_template_map')) {
$alertRulesOk = false;
}
}
@@ -86,6 +85,6 @@ if (isset($vars['template']) && empty(view(['template' => $vars['template']], []
$message = "You haven't given name to your template";
}
$response = array('status' => $status, 'message' => $message, 'newid' => $template_newid);
$response = ['status' => $status, 'message' => $message, 'newid' => $template_newid];
echo _json_encode($response);
+20 -20
View File
@@ -31,20 +31,20 @@ use Illuminate\Validation\Factory;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
$status = 'ok';
$message = '';
$transport_id = $vars['transport_id'];
$name = $vars['name'];
$is_default = (int)(isset($vars['is_default']) && $vars['is_default'] == 'on');
$transport_type = $vars['transport-type'];
$transport_id = $vars['transport_id'];
$name = $vars['name'];
$is_default = (int) (isset($vars['is_default']) && $vars['is_default'] == 'on');
$transport_type = $vars['transport-type'];
if (empty($name)) {
$status = 'error';
@@ -53,10 +53,10 @@ if (empty($name)) {
$status = 'error';
$message = 'Missing transport information';
} else {
$details = array(
$details = [
'transport_name' => $name,
'is_default' => $is_default
);
'is_default' => $is_default,
];
if (is_numeric($transport_id) && $transport_id > 0) {
// Update the fields -- json config field will be updated later
@@ -68,17 +68,17 @@ if (empty($name)) {
}
if ($transport_id) {
$class = 'LibreNMS\\Alert\\Transport\\'.ucfirst($transport_type);
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport_type);
if (!method_exists($class, 'configTemplate')) {
die(json_encode([
if (! method_exists($class, 'configTemplate')) {
exit(json_encode([
'status' => 'error',
'message' => 'This transport type is not yet supported'
'message' => 'This transport type is not yet supported',
]));
}
// Build config values
$result = call_user_func_array($class.'::configTemplate', []);
$result = call_user_func_array($class . '::configTemplate', []);
$loader = new FileLoader(new Filesystem, "$install_dir/resources/lang");
$translator = new Translator($loader, 'en');
$validation = new Factory($translator, new Container);
@@ -90,7 +90,7 @@ if (empty($name)) {
}
$status = 'error';
} else {
$transport_config = (array)json_decode(dbFetchCell('SELECT transport_config FROM alert_transports WHERE transport_id=?', [$transport_id]), true);
$transport_config = (array) json_decode(dbFetchCell('SELECT transport_config FROM alert_transports WHERE transport_id=?', [$transport_id]), true);
foreach ($result['config'] as $tmp_config) {
if (isset($tmp_config['name']) && $tmp_config['type'] !== 'hidden') {
$transport_config[$tmp_config['name']] = $vars[$tmp_config['name']];
@@ -99,7 +99,7 @@ if (empty($name)) {
//Update the json config field
$detail = [
'transport_type' => $transport_type,
'transport_config' => json_encode($transport_config)
'transport_config' => json_encode($transport_config),
];
$where = 'transport_id=?';
@@ -119,7 +119,7 @@ if (empty($name)) {
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message
'message' => $message,
]));
+11 -12
View File
@@ -22,32 +22,31 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <[email protected]>
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' => 1, 'message' => 'You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' => 1, 'message' => 'You need to be admin'];
} else {
$device_id = $_POST['device_id'];
$app = $_POST['application'];
if (!isset($app) && validate_device_id($device_id) === false) {
$status = array('status' => 1, 'message' => 'Error with data');
if (! isset($app) && validate_device_id($device_id) === false) {
$status = ['status' => 1, 'message' => 'Error with data'];
} else {
$status = array('status' => 1, 'message' => 'Database update failed');
$status = ['status' => 1, 'message' => 'Database update failed'];
if ($_POST['state'] == 'true') {
$update = array(
$update = [
'device_id' => $device_id,
'app_type' => $app,
'app_status' => '',
'app_instance' => ''
);
'app_instance' => '',
];
if (dbInsert($update, 'applications')) {
log_event("Application enabled by user: $app", $device_id, 'application', 1);
$status = array('status' => 0, 'message' => 'Application enabled');
$status = ['status' => 0, 'message' => 'Application enabled'];
}
} else {
if (dbDelete('applications', '`device_id`=? AND `app_type`=?', array($device_id, $app))) {
if (dbDelete('applications', '`device_id`=? AND `app_type`=?', [$device_id, $app])) {
log_event("Application disabled by user: $app", $device_id, 'application', 3);
$status = array('status' => 0, 'message' => 'Application disabled');
$status = ['status' => 0, 'message' => 'Application disabled'];
}
}
}
+2 -2
View File
@@ -14,8 +14,8 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
\App\Models\Callback::set('enabled', '2');
@@ -14,8 +14,8 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
\App\Models\Callback::set('enabled', (int)($_POST['state'] == 'true'));
\App\Models\Callback::set('enabled', (int) ($_POST['state'] == 'true'));
+15 -15
View File
@@ -2,20 +2,20 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error with config';
$status = 'error';
$message = 'Error with config';
// enable/disable components on devices.
$device_id = intval($_POST['device']);
$device_id = intval($_POST['device']);
$OBJCOMP = new LibreNMS\Component();
@@ -26,11 +26,11 @@ $COMPONENTS = $OBJCOMP->getComponents($device_id);
$COMPONENTS = $COMPONENTS[$device_id];
// Track how many updates we are making.
$UPDATE = array();
$UPDATE = [];
foreach ($COMPONENTS as $ID => $AVP) {
// Is the component disabled?
if (isset($_POST['dis_'.$ID])) {
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..
@@ -47,7 +47,7 @@ foreach ($COMPONENTS as $ID => $AVP) {
}
// Is the component ignored?
if (isset($_POST['ign_'.$ID])) {
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..
@@ -68,15 +68,15 @@ if (count($UPDATE) > 0) {
// Update our edited components.
$STATUS = $OBJCOMP->setComponentPrefs($device_id, $COMPONENTS);
$message = count($UPDATE).' Device records updated.';
$status = 'ok';
$message = count($UPDATE) . ' Device records updated.';
$status = 'ok';
} else {
$message = 'Record unchanged. No update necessary.';
$status = 'ok';
$message = 'Record unchanged. No update necessary.';
$status = 'ok';
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
);
];
echo _json_encode($response);
+18 -16
View File
@@ -1,4 +1,5 @@
<?php
//FIXME remove Deprecated template
/**
@@ -30,15 +31,15 @@ use Illuminate\Support\Str;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin',
]));
}
if (empty($vars['template'])) {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'No template to convert',
]));
@@ -55,8 +56,8 @@ function convert_template($line)
if (Str::contains($line, '{calc')) {
return preg_replace(
[
'/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/',// Replaces {calc (something*100)}
'/%([\w\d]+)\.([\w\d]+)/',// Replaces %something.anything
'/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/', // Replaces {calc (something*100)}
'/%([\w\d]+)\.([\w\d]+)/', // Replaces %something.anything
],
[
"@php\necho \\1;\n@endphp ",
@@ -68,16 +69,16 @@ function convert_template($line)
$old1 = $line;
$find = [
'/{if %([\w=\s]+)}/',// Replaces {if %something == else}
'/{else}/',// Replaces {else}
'/{\/if}/',// Replaces {/if}
'/{foreach %faults}/',// Replaces {foreach %faults}
'/{foreach %contacts}/',// Replaces {foreach %contacts}
'/{\/foreach}/',// Replaces {/foreach}
'/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/',// Replaces {calc (something*100)}
'/%value.string/',// Replaces %value.string
'/%([\w\d]+)\.([\w\d]+)/',// Replaces %something.anything
'/%([\w\d]+)/',// Replaces %anything
'/{if %([\w=\s]+)}/', // Replaces {if %something == else}
'/{else}/', // Replaces {else}
'/{\/if}/', // Replaces {/if}
'/{foreach %faults}/', // Replaces {foreach %faults}
'/{foreach %contacts}/', // Replaces {foreach %contacts}
'/{\/foreach}/', // Replaces {/foreach}
'/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/', // Replaces {calc (something*100)}
'/%value.string/', // Replaces %value.string
'/%([\w\d]+)\.([\w\d]+)/', // Replaces %something.anything
'/%([\w\d]+)/', // Replaces %anything
];
$replace = [
' @if ($alert->\1) ',
@@ -102,10 +103,11 @@ function convert_template($line)
'$key',
'$value',
];
return preg_replace($find, $replace, $old1);
}
die(json_encode([
exit(json_encode([
'status' => 'ok',
'message' => 'Template converted, review and save to update',
'template' => $new_body,
+20 -20
View File
@@ -14,20 +14,20 @@
use LibreNMS\Alert\AlertDB;
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$rule = implode(' ', $_POST['rules']);
$rule = rtrim($rule, '&|');
$query = AlertDB::genSQL($rule);
$rule = implode(' ', $_POST['rules']);
$rule = rtrim($rule, '&|');
$query = AlertDB::genSQL($rule);
$alert_id = $_POST['alert_id'];
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$count = mres($_POST['count']);
$delay = mres($_POST['delay']);
$interval = mres($_POST['interval']);
$mute = mres($_POST['mute']);
$invert = mres($_POST['invert']);
$name = mres($_POST['name']);
$mute = mres($_POST['mute']);
$invert = mres($_POST['invert']);
$name = mres($_POST['name']);
if ($_POST['proc'] != "") {
$proc = $_POST['proc'];
} else {
@@ -38,11 +38,11 @@ if (empty($rule)) {
$update_message = 'ERROR: No rule was generated - did you forget to click and / or?';
} elseif (validate_device_id($_POST['device_id']) || $_POST['device_id'] == '-1' || $_POST['device_id'][0] == ':') {
$device_id = $_POST['device_id'];
if (!is_numeric($count)) {
if (! is_numeric($count)) {
$count = '-1';
}
$delay_sec = convert_delay($delay);
$delay_sec = convert_delay($delay);
$interval_sec = convert_delay($interval);
if ($mute == 'on') {
$mute = true;
@@ -56,29 +56,29 @@ if (empty($rule)) {
$invert = false;
}
$extra = array(
$extra = [
'mute' => $mute,
'count' => $count,
'delay' => $delay_sec,
'invert' => $invert,
'interval' => $interval_sec,
);
];
$extra_json = json_encode($extra);
if (is_numeric($alert_id) && $alert_id > 0) {
if (dbUpdate(array('rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name, 'proc' => $proc, 'query' => $query), 'alert_rules', 'id=?', array($alert_id)) >= 0) {
if (dbUpdate(['rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'name' => $name, 'proc' => $proc, 'query' => $query], 'alert_rules', 'id=?', [$alert_id]) >= 0) {
$update_message = "Edited Rule: <i>$name: $rule</i>";
} else {
$update_message = 'ERROR: Failed to edit Rule: <i>'.$rule.'</i>';
$update_message = 'ERROR: Failed to edit Rule: <i>' . $rule . '</i>';
}
} else {
if (is_array($_POST['maps'])) {
$device_id = ':'.$device_id;
$device_id = ':' . $device_id;
}
if (dbInsert(array('device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name, 'proc' => $proc, 'query' => $query), 'alert_rules')) {
if (dbInsert(['device_id' => $device_id, 'rule' => $rule, 'severity' => mres($_POST['severity']), 'extra' => $extra_json, 'disabled' => 0, 'name' => $name, 'proc' => $proc, 'query' => $query], 'alert_rules')) {
$update_message = "Added Rule: <i>$name: $rule</i>";
if (is_array($_POST['maps'])) {
foreach ($_POST['maps'] as $target) {
$_POST['rule'] = $name;
$_POST['rule'] = $name;
$_POST['target'] = $target;
$_POST['map_id'] = '';
include 'create-map-item.inc.php';
@@ -86,7 +86,7 @@ if (empty($rule)) {
}
}
} else {
$update_message = 'ERROR: Failed to add Rule: <i>'.$rule.'</i>';
$update_message = 'ERROR: Failed to add Rule: <i>' . $rule . '</i>';
}
}//end if
} else {
+7 -7
View File
@@ -12,8 +12,8 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$service_id = $vars['service_id'];
@@ -27,19 +27,19 @@ $device_id = $vars['device_id'];
if (is_numeric($service_id) && $service_id > 0) {
// Need to edit.
$update = array('service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param, 'service_ignore' => $ignore, 'service_disabled' => $disabled);
$update = ['service_desc' => $desc, 'service_ip' => $ip, 'service_param' => $param, 'service_ignore' => $ignore, 'service_disabled' => $disabled];
if (is_numeric(edit_service($update, $service_id))) {
$status = array('status' =>0, 'message' => 'Modified Service: <i>'.$service_id.': '.$type.'</i>');
$status = ['status' =>0, 'message' => 'Modified Service: <i>' . $service_id . ': ' . $type . '</i>'];
} else {
$status = array('status' =>1, 'message' => 'ERROR: Failed to modify service: <i>'.$service_id.'</i>');
$status = ['status' =>1, 'message' => 'ERROR: Failed to modify service: <i>' . $service_id . '</i>'];
}
} else {
// Need to add.
$service_id = add_service($device_id, $type, $desc, $ip, $param, $ignore, $disabled);
if ($service_id == false) {
$status = array('status' =>1, 'message' => 'ERROR: Failed to add Service: <i>'.$type.'</i>');
$status = ['status' =>1, 'message' => 'ERROR: Failed to add Service: <i>' . $type . '</i>'];
} else {
$status = array('status' =>0, 'message' => 'Added Service: <i>'.$service_id.': '.$type.'</i>');
$status = ['status' =>0, 'message' => 'Added Service: <i>' . $service_id . ': ' . $type . '</i>'];
}
}
header('Content-Type: application/json');
+46 -46
View File
@@ -2,11 +2,11 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
@@ -14,36 +14,36 @@ if (!Auth::user()->hasGlobalAdmin()) {
$status = 'ok';
$message = '';
$device_id = $_POST['device_id'];
$id = $_POST['ccustomoid_id'];
$action = mres($_POST['action']);
$name = mres($_POST['name']);
$oid = mres($_POST['oid']);
$datatype = mres($_POST['datatype']);
$device_id = $_POST['device_id'];
$id = $_POST['ccustomoid_id'];
$action = mres($_POST['action']);
$name = mres($_POST['name']);
$oid = mres($_POST['oid']);
$datatype = mres($_POST['datatype']);
if (empty(mres($_POST['unit']))) {
$unit = array('NULL');
$unit = ['NULL'];
} else {
$unit = mres($_POST['unit']);
$unit = mres($_POST['unit']);
}
if (!empty(mres($_POST['limit'])) && is_numeric(mres($_POST['limit']))) {
$limit = mres($_POST['limit']);
if (! empty(mres($_POST['limit'])) && is_numeric(mres($_POST['limit']))) {
$limit = mres($_POST['limit']);
} else {
$limit = array('NULL');
$limit = ['NULL'];
}
if (!empty(mres($_POST['limit_warn'])) && is_numeric(mres($_POST['limit_warn']))) {
$limit_warn = mres($_POST['limit_warn']);
if (! empty(mres($_POST['limit_warn'])) && is_numeric(mres($_POST['limit_warn']))) {
$limit_warn = mres($_POST['limit_warn']);
} else {
$limit_warn = array('NULL');
$limit_warn = ['NULL'];
}
if (!empty(mres($_POST['limit_low'])) && is_numeric(mres($_POST['limit_low']))) {
$limit_low = mres($_POST['limit_low']);
if (! empty(mres($_POST['limit_low'])) && is_numeric(mres($_POST['limit_low']))) {
$limit_low = mres($_POST['limit_low']);
} else {
$limit_low = array('NULL');
$limit_low = ['NULL'];
}
if (!empty(mres($_POST['limit_low_warn'])) && is_numeric(mres($_POST['limit_low_warn']))) {
if (! empty(mres($_POST['limit_low_warn'])) && is_numeric(mres($_POST['limit_low_warn']))) {
$limit_low_warn = mres($_POST['limit_low_warn']);
} else {
$limit_low_warn = array('NULL');
$limit_low_warn = ['NULL'];
}
if (mres($_POST['alerts']) == 'on') {
$alerts = 1;
@@ -55,20 +55,20 @@ if (mres($_POST['passed']) == 'on') {
} else {
$passed = 0;
}
if (!empty(mres($_POST['divisor'])) && is_numeric(mres($_POST['divisor']))) {
$divisor = mres($_POST['divisor']);
if (! empty(mres($_POST['divisor'])) && is_numeric(mres($_POST['divisor']))) {
$divisor = mres($_POST['divisor']);
} else {
$divisor = 1;
$divisor = 1;
}
if (!empty(mres($_POST['multiplier'])) && is_numeric(mres($_POST['multiplier']))) {
$multiplier = mres($_POST['multiplier']);
if (! empty(mres($_POST['multiplier'])) && is_numeric(mres($_POST['multiplier']))) {
$multiplier = mres($_POST['multiplier']);
} else {
$multiplier = 1;
$multiplier = 1;
}
if (!empty(mres($_POST['user_func']))) {
if (! empty(mres($_POST['user_func']))) {
$user_func = mres($_POST['user_func']);
} else {
$user_func = array('NULL');
$user_func = ['NULL'];
}
if ($action == "test") {
@@ -79,26 +79,26 @@ if ($action == "test") {
if (is_numeric($rawdata)) {
if (dbUpdate(
array(
[
'customoid_passed' => 1,
),
],
'customoids',
'customoid_id=?',
array($id)
[$id]
) >= 0) {
$message = "Test successful for <i>$name</i>, value $rawdata received";
} else {
$status = 'error';
$status = 'error';
$message = "Failed to set pass on OID <i>$name</i>";
}
} else {
$status = 'error';
$status = 'error';
$message = "Invalid data in SNMP reply, value $rawdata received";
}
} else {
if (is_numeric($id) && $id > 0) {
if (dbUpdate(
array(
[
'customoid_descr' => $name,
'customoid_oid' => $oid,
'customoid_datatype' => $datatype,
@@ -111,28 +111,28 @@ if ($action == "test") {
'customoid_limit_low_warn' => $limit_low_warn,
'customoid_alert' => $alerts,
'customoid_passed' => $passed,
'user_func' => $user_func
),
'user_func' => $user_func,
],
'customoids',
"`customoid_id` = ?",
array($id)
[$id]
) >= 0) { //end if condition
$message = "Edited OID: <i>$name</i>";
} else {
$status = 'error';
$status = 'error';
$message = "Failed to edit OID <i>$name</i>";
}
} else {
if (empty($name)) {
$status = 'error';
$status = 'error';
$message = 'No OID name provided';
} else {
if (dbFetchCell('SELECT 1 FROM `customoids` WHERE `customoid_descr` = ? AND `device_id`=?', array($name, $device_id))) {
if (dbFetchCell('SELECT 1 FROM `customoids` WHERE `customoid_descr` = ? AND `device_id`=?', [$name, $device_id])) {
$status = 'error';
$message = "OID named <i>$name</i> on this device already exists";
} else {
$id = dbInsert(
array(
[
'device_id' => $device_id,
'customoid_descr' => $name,
'customoid_oid' => $oid,
@@ -146,8 +146,8 @@ if ($action == "test") {
'customoid_limit_low_warn' => $limit_low_warn,
'customoid_alert' => $alerts,
'customoid_passed' => $passed,
'user_func' => $user_func
),
'user_func' => $user_func,
],
'customoids'
);
if ($id) {
@@ -161,7 +161,7 @@ if ($action == "test") {
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message,
]));
@@ -14,11 +14,11 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($vars['alert_id'])) {
if (! is_numeric($vars['alert_id'])) {
echo 'ERROR: No alert selected';
exit;
} else {
@@ -27,10 +27,10 @@ if (!is_numeric($vars['alert_id'])) {
if ($alert_name) {
$alert_msg_prefix .= ' ' . $alert_name;
}
if (!$alert_name) {
if (! $alert_name) {
$alert_msg_prefix .= ' id ' . $vars['alert_id'];
}
if (dbDelete('alert_rules', '`id` = ?', array($vars['alert_id']))) {
if (dbDelete('alert_rules', '`id` = ?', [$vars['alert_id']])) {
dbDelete('alert_device_map', 'rule_id=?', [$vars['alert_id']]);
dbDelete('alert_group_map', 'rule_id=?', [$vars['alert_id']]);
dbDelete('alert_location_map', 'rule_id=?', [$vars['alert_id']]);
@@ -14,16 +14,16 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($_POST['template_id'])) {
if (! is_numeric($_POST['template_id'])) {
echo 'ERROR: No template selected';
exit;
} else {
if (dbDelete('alert_templates', '`id` = ?', array($_POST['template_id']))) {
dbDelete('alert_template_map', 'alert_templates_id = ?', array($_POST['template_id']));
if (dbDelete('alert_templates', '`id` = ?', [$_POST['template_id']])) {
dbDelete('alert_template_map', 'alert_templates_id = ?', [$_POST['template_id']]);
echo 'Alert template has been deleted.';
exit;
} else {
@@ -12,17 +12,17 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin.'
'message' => 'You need to be admin.',
]));
}
$status = 'ok';
$message = '';
if (!is_numeric($vars['transport_id'])) {
if (! is_numeric($vars['transport_id'])) {
$status = 'error';
$message = 'No transport selected';
} else {
@@ -36,7 +36,7 @@ if (!is_numeric($vars['transport_id'])) {
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message'=> $message
'message'=> $message,
]));
@@ -22,19 +22,18 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <[email protected]>
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' =>1, 'message' => 'ERROR: You need to be admin to delete poller entries');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' =>1, 'message' => 'ERROR: You need to be admin to delete poller entries'];
} else {
$id = $vars['id'];
if (!is_numeric($id)) {
$status = array('status' =>1, 'message' => 'No poller has been selected');
if (! is_numeric($id)) {
$status = ['status' =>1, 'message' => 'No poller has been selected'];
} else {
$poller_name = dbFetchCell('SELECT `poller_name` FROM `pollers` WHERE `id`=?', array($id));
if (dbDelete('poller_cluster', 'id=?', array($id)) && dbDelete('poller_cluster_stats', 'parent_poller=?', array($id))) {
$status = array('status' => 0, 'message' => "Poller: <i>$poller_name ($id), has been deleted.</i>");
$poller_name = dbFetchCell('SELECT `poller_name` FROM `pollers` WHERE `id`=?', [$id]);
if (dbDelete('poller_cluster', 'id=?', [$id]) && dbDelete('poller_cluster_stats', 'parent_poller=?', [$id])) {
$status = ['status' => 0, 'message' => "Poller: <i>$poller_name ($id), has been deleted.</i>"];
} else {
$status = array('status' => 1, 'message' => "Poller: <i>$poller_name ($id), has NOT been deleted.</i>");
$status = ['status' => 1, 'message' => "Poller: <i>$poller_name ($id), has NOT been deleted.</i>"];
}
}
}
+5 -5
View File
@@ -2,20 +2,20 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
if (!is_numeric($_POST['customoid_id'])) {
if (! is_numeric($_POST['customoid_id'])) {
echo 'ERROR: No alert selected';
exit;
} else {
if (dbDelete('customoids', '`customoid_id` = ?', array($_POST['customoid_id']))) {
if (dbDelete('customoids', '`customoid_id` = ?', [$_POST['customoid_id']])) {
echo 'Custom OID has been deleted.';
exit;
} else {
+11 -12
View File
@@ -21,38 +21,37 @@
* @package LibreNMS
* @subpackage Dashboards
*/
header('Content-type: application/json');
if (!Auth::check()) {
$response = array(
if (! Auth::check()) {
$response = [
'status' => 'error',
'message' => 'Unauthenticated',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'unknown error';
$status = 'error';
$message = 'unknown error';
$dashboard_id = (int)$_REQUEST['dashboard_id'];
$dashboard_id = (int) $_REQUEST['dashboard_id'];
if ($dashboard_id) {
dbDelete('users_widgets', 'user_id = ? && dashboard_id = ?', [Auth::id(), $dashboard_id]);
if (dbDelete('dashboards', 'user_id = ? && dashboard_id = ?', [Auth::id(), $dashboard_id])) {
$status = 'ok';
$status = 'ok';
$message = 'Dashboard deleted';
} else {
$message = 'ERROR: Could not delete dashboard '. $dashboard_id;
$message = 'ERROR: Could not delete dashboard ' . $dashboard_id;
}
} else {
$message = 'ERROR: Not enough params';
}
$response = array(
$response = [
'status' => $status,
'message' => $message
);
'message' => $message,
];
echo _json_encode($response);
@@ -12,11 +12,11 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' => 1, 'message' => 'You need to be admin'];
} else {
if ($_POST['device_id']) {
if (!is_numeric($_POST['device_id'])) {
if (! is_numeric($_POST['device_id'])) {
$status = ['status' => 1, 'message' => 'Wrong device id!'];
} else {
$device = \App\Models\Device::find($_POST['device_id']);
@@ -31,7 +31,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
foreach ($_POST['parent_ids'] as $parent) {
if (is_numeric($parent) && $parent != 0) {
$device = \App\Models\Device::find($_POST['device_id']);
if (!$device->children()->detach()) {
if (! $device->children()->detach()) {
$status = ['status' => 1, 'message' => 'Device dependency cannot be deleted.'];
}
} elseif ($parent == 0) {
+8 -9
View File
@@ -22,19 +22,18 @@
* @copyright 2017 Tony Murray
* @author Tony Murray <[email protected]>
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' =>1, 'message' => 'ERROR: You need to be admin to delete poller entries');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' =>1, 'message' => 'ERROR: You need to be admin to delete poller entries'];
} else {
$id = $vars['id'];
if (!is_numeric($id)) {
$status = array('status' =>1, 'message' => 'No poller has been selected');
if (! is_numeric($id)) {
$status = ['status' =>1, 'message' => 'No poller has been selected'];
} else {
$poller_name = dbFetchCell('SELECT `poller_name` FROM `pollers` WHERE `id`=?', array($id));
if (dbDelete('pollers', 'id=?', array($id))) {
$status = array('status' => 0, 'message' => "Poller: <i>$poller_name ($id), has been deleted.</i>");
$poller_name = dbFetchCell('SELECT `poller_name` FROM `pollers` WHERE `id`=?', [$id]);
if (dbDelete('pollers', 'id=?', [$id])) {
$status = ['status' => 0, 'message' => "Poller: <i>$poller_name ($id), has been deleted.</i>"];
} else {
$status = array('status' => 1, 'message' => "Poller: <i>$poller_name ($id), has NOT been deleted.</i>");
$status = ['status' => 1, 'message' => "Poller: <i>$poller_name ($id), has NOT been deleted.</i>"];
}
}
}
+6 -6
View File
@@ -11,16 +11,16 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' =>1, 'message' => 'ERROR: You need to be admin to delete services');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' =>1, 'message' => 'ERROR: You need to be admin to delete services'];
} else {
if (!is_numeric($vars['service_id'])) {
$status = array('status' =>1, 'message' => 'No Service has been selected');
if (! is_numeric($vars['service_id'])) {
$status = ['status' =>1, 'message' => 'No Service has been selected'];
} else {
if (delete_service($vars['service_id'])) {
$status = array('status' =>0, 'message' => 'Service: <i>'.$vars['service_id'].', has been deleted.</i>');
$status = ['status' =>0, 'message' => 'Service: <i>' . $vars['service_id'] . ', has been deleted.</i>'];
} else {
$status = array('status' =>1, 'message' => 'Service: <i>'.$vars['service_id'].', has NOT been deleted.</i>');
$status = ['status' =>1, 'message' => 'Service: <i>' . $vars['service_id'] . ', has NOT been deleted.</i>'];
}
}
}
@@ -14,17 +14,17 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: You need to be admin.'
'message' => 'ERROR: You need to be admin.',
]));
}
$status = 'ok';
$message = '';
if (!is_numeric($vars['group_id'])) {
if (! is_numeric($vars['group_id'])) {
$status = 'error';
$message = 'ERROR: No transport group selected';
} else {
@@ -37,7 +37,7 @@ if (!is_numeric($vars['group_id'])) {
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message'=> $message
'message'=> $message,
]));
@@ -4,14 +4,14 @@ header('Content-type: text/plain');
// FUA
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$device['device_id'] = $_POST['device_id'];
$module = 'discover_'.$_POST['discovery_module'];
$module = 'discover_' . $_POST['discovery_module'];
if (!isset($module) && validate_device_id($device['device_id']) === false) {
if (! isset($module) && validate_device_id($device['device_id']) === false) {
echo 'error with data';
exit;
} else {
+9 -10
View File
@@ -21,30 +21,29 @@
* @package LibreNMS
* @subpackage Dashboards
*/
header('Content-type: application/json');
$status = 'error';
$message = 'unknown error';
$status = 'error';
$message = 'unknown error';
$dashboard_id = (int)$_REQUEST['dashboard_id'];
$dashboard_id = (int) $_REQUEST['dashboard_id'];
$dashboard_name = display($_REQUEST['dashboard_name']);
$access = $_REQUEST['access'];
if (isset($dashboard_id) && isset($dashboard_name) && isset($access)) {
if (dbUpdate(['dashboard_name'=> $dashboard_name,'access'=> $access], 'dashboards', '(user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dashboard_id]) >= 0) {
$status = 'ok';
if (dbUpdate(['dashboard_name'=> $dashboard_name, 'access'=> $access], 'dashboards', '(user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dashboard_id]) >= 0) {
$status = 'ok';
$message = 'Dashboard ' . $dashboard_name . ' updated';
} else {
$message = 'ERROR: Could not update dashboard '. $dashboard_name;
$message = 'ERROR: Could not update dashboard ' . $dashboard_name;
}
} else {
$message = 'ERROR: Not enough params';
}
$response = array(
$response = [
'status' => $status,
'message' => $message
);
'message' => $message,
];
echo _json_encode($response);
@@ -12,14 +12,14 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
$status = array('status' => 1, 'message' => 'You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' => 1, 'message' => 'You need to be admin'];
} else {
if (isset($_POST['viewtype'])) {
if ($_POST['viewtype'] == 'fulllist') {
$deps_query = "SELECT a.device_id as id, a.hostname as hostname, a.sysName as sysName, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id = a1.parent_device_id GROUP BY a.device_id, a.hostname, a.sysName";
if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) {
if (isset($_POST['searchPhrase']) && ! empty($_POST['searchPhrase'])) {
$deps_query .= " HAVING parent LIKE ? OR hostname LIKE ? OR sysName LIKE ? ";
$count_query = "SELECT COUNT(*) FROM (" . $deps_query . ") AS rowcount";
} else {
@@ -42,17 +42,15 @@ if (!Auth::user()->hasGlobalAdmin()) {
if (is_numeric($_POST['rowCount']) && is_numeric($_POST['current'])) {
$rows = $_POST['rowCount'];
$current = $_POST['current'];
$deps_query .= " LIMIT ".$rows * ($current - 1).", ".$rows;
$deps_query .= " LIMIT " . $rows * ($current - 1) . ", " . $rows;
}
} else {
$deps_query .= " ORDER BY a.hostname";
}
if (isset($_POST['format']) && !empty($_POST['searchPhrase'])) {
$searchphrase = '%'.mres($_POST['searchPhrase']).'%';
$search_arr = array($searchphrase, $searchphrase, $searchphrase);
if (isset($_POST['format']) && ! empty($_POST['searchPhrase'])) {
$searchphrase = '%' . mres($_POST['searchPhrase']) . '%';
$search_arr = [$searchphrase, $searchphrase, $searchphrase];
$device_deps = dbFetchRows($deps_query, $search_arr);
$rec_count = dbFetchCell($count_query, $search_arr);
} else {
@@ -60,9 +58,8 @@ if (!Auth::user()->hasGlobalAdmin()) {
$rec_count = dbFetchCell($count_query);
}
if (isset($_POST['format'])) {
$res_arr = array();
$res_arr = [];
foreach ($device_deps as $myrow) {
if ($myrow['parent'] == null || $myrow['parent'] == '') {
$parent = 'None';
@@ -74,9 +71,9 @@ if (!Auth::user()->hasGlobalAdmin()) {
$sysname = ($hostname == $myrow['sysName']) ? $myrow['hostname'] : $myrow['sysName'];
array_push($res_arr, ["deviceid" => $myrow['id'], "hostname" => $hostname, "sysname" => $sysname, "parent" => $parent, "parentid" => $myrow['parentid']]);
}
$status = array('current' => $_POST['current'], 'rowCount' => $_POST['rowCount'], 'rows' => $res_arr, 'total' => $rec_count);
$status = ['current' => $_POST['current'], 'rowCount' => $_POST['rowCount'], 'rows' => $res_arr, 'total' => $rec_count];
} else {
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
} else {
// Get childs from parent id(s)
@@ -85,25 +82,25 @@ if (!Auth::user()->hasGlobalAdmin()) {
$device_deps = dbFetchRows('SELECT `device_id`,`hostname` from `devices` as a LEFT JOIN `device_relationships` as b ON b.`child_device_id` = a.`device_id` WHERE b.`child_device_id` is null ORDER BY `hostname`');
} else {
$parents = implode(',', $_POST['parent_ids']);
$device_deps = dbFetchRows("SELECT a.device_id as device_id, a.hostname as hostname, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname HAVING parentid = ?", array($parents));
$device_deps = dbFetchRows("SELECT a.device_id as device_id, a.hostname as hostname, GROUP_CONCAT(b.hostname) as parent, GROUP_CONCAT(b.device_id) as parentid FROM devices as a LEFT JOIN device_relationships a1 ON a.device_id=a1.child_device_id LEFT JOIN devices b ON b.device_id=a1.parent_device_id GROUP BY a.device_id, a.hostname HAVING parentid = ?", [$parents]);
}
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
}
} else {
// Find devices by child.
if (!is_numeric($_POST['device_id'])) {
$status = array('status' => 1, 'message' => 'Wrong device id!');
if (! is_numeric($_POST['device_id'])) {
$status = ['status' => 1, 'message' => 'Wrong device id!'];
} else {
$deps_query = 'SELECT `device_id`, `hostname` FROM `devices` AS a INNER JOIN `device_relationships` AS b ON a.`device_id` = b.`parent_device_id` WHERE ';
// device_id == 0 is the case where we have no parents.
if ($_POST['device_id'] == 0) {
$device_deps = dbFetchRows($deps_query. ' b.`parent_device_id` is null OR b.`parent_device_id` = 0 ');
$device_deps = dbFetchRows($deps_query . ' b.`parent_device_id` is null OR b.`parent_device_id` = 0 ');
} else {
$device_deps = dbFetchRows($deps_query. ' b.`child_device_id` = ?', array($_POST['device_id']));
$device_deps = dbFetchRows($deps_query . ' b.`child_device_id` = ?', [$_POST['device_id']]);
}
$status = array('status' => 0, 'deps' => $device_deps);
$status = ['status' => 0, 'deps' => $device_deps];
}
}
}
+4 -5
View File
@@ -19,7 +19,7 @@
$vm_query = "SELECT v.vmwVmDisplayName AS vmname, v.vmwVmState AS powerstat, v.device_id AS deviceid, d.hostname AS physicalsrv, d.sysname AS sysname, v.vmwVmGuestOS AS os, v.vmwVmMemSize AS memory, v.vmwVmCpus AS cpu FROM vminfo AS v LEFT JOIN devices AS d ON v.device_id = d.device_id";
$param = [];
if (!Auth::user()->hasGlobalRead()) {
if (! Auth::user()->hasGlobalRead()) {
$vm_query .= ' LEFT JOIN devices_perms AS DP ON d.device_id = DP.device_id';
$uidwhere = ' AND DP.user_id = ?';
$uid = [Auth::id()];
@@ -28,7 +28,7 @@ if (!Auth::user()->hasGlobalRead()) {
$uid = [];
}
if (isset($vars['searchPhrase']) && !empty($vars['searchPhrase'])) {
if (isset($vars['searchPhrase']) && ! empty($vars['searchPhrase'])) {
$vm_query .= " WHERE v.vmwVmDisplayName LIKE ? OR d.hostname LIKE ? OR v.vmwVmGuestOS LIKE ? OR d.sysname LIKE ?" . $uidwhere;
$count_query = "SELECT COUNT(v.vmwVmDisplayName) FROM vminfo AS v LEFT JOIN devices AS d ON v.device_id = d.device_id WHERE v.vmwVmDisplayName LIKE ? OR d.hostname LIKE ? OR v.vmwVmGuestOS LIKE ? OR d.sysname LIKE ?" . $uidwhere;
$searchphrase = '%' . $vars['searchPhrase'] . '%';
@@ -51,11 +51,10 @@ $vm_query .= " ORDER BY " . $order_by;
if (is_numeric($vars['rowCount']) && is_numeric($vars['current'])) {
$rowcount = $vars['rowCount'];
$current = $vars['current'];
$vm_query .= " LIMIT ".$rowcount * ($current - 1).", ".$rowcount;
$vm_query .= " LIMIT " . $rowcount * ($current - 1) . ", " . $rowcount;
}
if (isset($vars['searchPhrase']) && !empty($vars['searchPhrase'])) {
if (isset($vars['searchPhrase']) && ! empty($vars['searchPhrase'])) {
$vm_arr = dbFetchRows($vm_query, $param);
$rec_count = dbFetchCell($count_query, $param);
} else {
+10 -10
View File
@@ -14,30 +14,30 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error updating mempool information';
$device_id = mres($_POST['device_id']);
$mempool_id = mres($_POST['mempool_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
if (! is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($mempool_id)) {
} elseif (! is_numeric($mempool_id)) {
$message = 'Missing mempool id';
} elseif (!is_numeric($data)) {
} elseif (! is_numeric($data)) {
$message = 'Missing value';
} else {
if (dbUpdate(array('mempool_perc_warn'=>$data), 'mempools', '`mempool_id`=? AND `device_id`=?', array($mempool_id,$device_id)) >= 0) {
if (dbUpdate(['mempool_perc_warn'=>$data], 'mempools', '`mempool_id`=? AND `device_id`=?', [$mempool_id, $device_id]) >= 0) {
$message = 'Memory information updated';
$status = 'ok';
} else {
@@ -45,9 +45,9 @@ if (!is_numeric($device_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
);
];
echo _json_encode($response);
+18 -20
View File
@@ -21,27 +21,25 @@
* @package LibreNMS
* @subpackage Notifications
*/
header('Content-type: application/json');
if (!isset($_REQUEST['action'])) {
die(json_encode([
if (! isset($_REQUEST['action'])) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: Missing Params',
]));
}
if (in_array($_REQUEST['action'], ['stick', 'unstick', 'create']) && !Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (in_array($_REQUEST['action'], ['stick', 'unstick', 'create']) && ! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: Need to be GlobalAdmin or DemoUser',
]));
}
if ($_REQUEST['action'] == 'read' && isset($_REQUEST['notification_id'])) {
if (dbInsert(['notifications_id'=>$_REQUEST['notification_id'],'user_id'=>Auth::id(),'key'=>'read','value'=>1], 'notifications_attribs')) {
die(json_encode([
if (dbInsert(['notifications_id'=>$_REQUEST['notification_id'], 'user_id'=>Auth::id(), 'key'=>'read', 'value'=>1], 'notifications_attribs')) {
exit(json_encode([
'status' => 'ok',
'message' => 'Set as Read',
]));
@@ -54,44 +52,44 @@ if ($_REQUEST['action'] == 'read' && isset($_REQUEST['notification_id'])) {
'notifications_id' => $notification_id,
'user_id' => Auth::id(),
'key' => 'read',
'value' => 1
'value' => 1,
],
'notifications_attribs'
);
}
die(json_encode([
exit(json_encode([
'status' => 'ok',
'message' => 'All notifications set as read',
]));
} elseif ($_REQUEST['action'] == 'stick' && isset($_REQUEST['notification_id'])) {
if (dbInsert(['notifications_id'=>$_REQUEST['notification_id'],'user_id'=>Auth::id(),'key'=>'sticky','value'=>1], 'notifications_attribs')) {
die(json_encode([
if (dbInsert(['notifications_id'=>$_REQUEST['notification_id'], 'user_id'=>Auth::id(), 'key'=>'sticky', 'value'=>1], 'notifications_attribs')) {
exit(json_encode([
'status' => 'ok',
'message' => 'Set as Sticky',
]));
}
} elseif ($_REQUEST['action'] == 'unstick' && isset($_REQUEST['notification_id'])) {
if (dbDelete('notifications_attribs', "notifications_id = ? && user_id = ? AND `key`='sticky'", [$_REQUEST['notification_id'],Auth::id()])) {
die(json_encode([
if (dbDelete('notifications_attribs', "notifications_id = ? && user_id = ? AND `key`='sticky'", [$_REQUEST['notification_id'], Auth::id()])) {
exit(json_encode([
'status' => 'ok',
'message' => 'Removed Sticky',
]));
}
} elseif ($_REQUEST['action'] == 'create' && (!empty($_REQUEST['title']) && !empty($_REQUEST['body']))) {
if (dbInsert(['title'=>$_REQUEST['title'],'body'=>$_REQUEST['body'],'checksum'=>hash('sha512', Auth::id().'.LOCAL.'.$_REQUEST['title']),'source'=>Auth::id()], 'notifications')) {
die(json_encode([
} elseif ($_REQUEST['action'] == 'create' && (! empty($_REQUEST['title']) && ! empty($_REQUEST['body']))) {
if (dbInsert(['title'=>$_REQUEST['title'], 'body'=>$_REQUEST['body'], 'checksum'=>hash('sha512', Auth::id() . '.LOCAL.' . $_REQUEST['title']), 'source'=>Auth::id()], 'notifications')) {
exit(json_encode([
'status' => 'ok',
'message' => 'Created',
]));
}
} else {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: Missing Params',
]));
}
die(json_encode(array(
exit(json_encode([
'status' => 'error',
'message' => 'unknown error',
)));
]));
+5 -5
View File
@@ -14,11 +14,11 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
@@ -41,8 +41,8 @@ if (empty($device['device_id'])) {
$message = 'Config has been updated';
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
);
];
echo _json_encode($response);
+5 -5
View File
@@ -14,9 +14,9 @@
use LibreNMS\Alerting\QueryBuilderParser;
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
exit('ERROR: You need to be admin');
}
$alert_id = $vars['alert_id'];
$template_id = $vars['template_id'];
@@ -46,15 +46,15 @@ if (is_numeric($alert_id) && $alert_id > 0) {
foreach ($members as $member) {
$transports[] = [
'id' => $member['transport_or_group_id'],
'text' => ucfirst($member['transport_type']).": ".$member['transport_name']
'text' => ucfirst($member['transport_type']) . ": " . $member['transport_name'],
];
}
$t_groups = dbFetchRows('SELECT `transport_or_group_id`, `transport_group_name` FROM `alert_transport_map` LEFT JOIN `alert_transport_groups` ON `transport_or_group_id`=`transport_group_id` WHERE `target_type`="group" AND `rule_id`=?', [$alert_id]);
foreach ($t_groups as $group) {
$transports[] = [
'id' => 'g'.$group['transport_or_group_id'],
'text' => 'Group: '.$group['transport_group_name']
'id' => 'g' . $group['transport_or_group_id'],
'text' => 'Group: ' . $group['transport_group_name'],
];
}
} elseif (is_numeric($template_id) && $template_id >= 0) {
@@ -12,23 +12,23 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
exit('ERROR: You need to be admin');
}
$template_id = $vars['template_id'];
$template_edit = is_numeric($template_id) && $template_id > 0;
$rules = [];
$output = array(
$output = [
'template' => '',
'name' => '',
'title' => '',
'title_rec' => '',
'type' => '',
'rules' => $rules,
);
];
if ($template_edit) {
$template = dbFetchRow('SELECT * FROM `alert_templates` WHERE `id` = ? LIMIT 1', [$template_id]);
@@ -37,7 +37,7 @@ if ($template_edit) {
'name' => $template['name'],
'title' => $template['title'],
'title_rec' => $template['title_rec'],
'type' => $template['type']
'type' => $template['type'],
];
}
+5 -5
View File
@@ -1,10 +1,10 @@
<?php
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
@@ -20,10 +20,10 @@ if (is_numeric($customoid_id) && $customoid_id > 0) {
}
if ($oid['customoid_passed'] == 1) {
$cpassed = true;
$passed = 'on';
$passed = 'on';
} else {
$cpassed = false;
$passed = '';
$passed = '';
}
header('Content-type: application/json');
@@ -12,19 +12,19 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
exit('ERROR: You need to be admin');
}
$group_id = ($_POST['group_id']);
if (is_numeric($group_id) && $group_id > 0) {
$group = dbFetchRow('SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1', array($group_id));
$output = array(
$group = dbFetchRow('SELECT * FROM `poller_groups` WHERE `id` = ? LIMIT 1', [$group_id]);
$output = [
'group_name' => $group['group_name'],
'descr' => $group['descr'],
);
];
header('Content-type: application/json');
echo _json_encode($output);
}
+5 -5
View File
@@ -12,8 +12,8 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$service_id = $vars['service_id'];
@@ -21,14 +21,14 @@ $service_id = $vars['service_id'];
if (is_numeric($service_id) && $service_id > 0) {
$service = service_get(null, $service_id);
$output = array(
$output = [
'stype' => $service[0]['service_type'],
'ip' => $service[0]['service_ip'],
'desc' => $service[0]['service_desc'],
'param' => $service[0]['service_param'],
'ignore' => $service[0]['service_ignore'],
'disabled' => $service[0]['service_disabled']
);
'disabled' => $service[0]['service_disabled'],
];
header('Content-Type: application/json');
echo _json_encode($output);
+12 -12
View File
@@ -14,24 +14,24 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$ok = '';
$error = '';
$group_id = $_POST['group_id'];
$ok = '';
$error = '';
$group_id = $_POST['group_id'];
$group_name = mres($_POST['group_name']);
$descr = mres($_POST['descr']);
if (!empty($group_name)) {
$descr = mres($_POST['descr']);
if (! empty($group_name)) {
if (is_numeric($group_id)) {
if (dbUpdate(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups', 'id = ?', array($group_id)) >= 0) {
if (dbUpdate(['group_name' => $group_name, 'descr' => $descr], 'poller_groups', 'id = ?', [$group_id]) >= 0) {
$ok = 'Updated poller group';
} else {
$error = 'Failed to update the poller group';
}
} else {
if (dbInsert(array('group_name' => $group_name, 'descr' => $descr), 'poller_groups') >= 0) {
if (dbInsert(['group_name' => $group_name, 'descr' => $descr], 'poller_groups') >= 0) {
$ok = 'Added new poller group';
} else {
$error = 'Failed to create new poller group';
@@ -41,8 +41,8 @@ if (!empty($group_name)) {
$error = "You haven't given your poller group a name, it feels sad :( - $group_name";
}
if (!empty($ok)) {
die("$ok");
if (! empty($ok)) {
exit("$ok");
} else {
die("ERROR: $error");
exit("ERROR: $error");
}
@@ -2,15 +2,15 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
// FUA
$device['device_id'] = $_POST['device_id'];
$module = 'poll_'.$_POST['poller_module'];
$module = 'poll_' . $_POST['poller_module'];
if (!isset($module) && validate_device_id($device['device_id']) === false) {
if (! isset($module) && validate_device_id($device['device_id']) === false) {
echo 'error with data';
exit;
} else {
+10 -10
View File
@@ -14,30 +14,30 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error updating processor information';
$device_id = mres($_POST['device_id']);
$processor_id = mres($_POST['processor_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
if (! is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($processor_id)) {
} elseif (! is_numeric($processor_id)) {
$message = 'Missing processor id';
} elseif (!is_numeric($data)) {
} elseif (! is_numeric($data)) {
$message = 'Missing value';
} else {
if (dbUpdate(array('processor_perc_warn'=>$data), 'processors', '`processor_id`=? AND `device_id`=?', array($processor_id,$device_id)) >= 0) {
if (dbUpdate(['processor_perc_warn'=>$data], 'processors', '`processor_id`=? AND `device_id`=?', [$processor_id, $device_id]) >= 0) {
$message = 'Processor information updated';
$status = 'ok';
} else {
@@ -45,9 +45,9 @@ if (!is_numeric($device_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
);
];
echo _json_encode($response);
+14 -14
View File
@@ -12,22 +12,22 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
if (isset($_POST['device_id'])) {
if (!is_numeric($_POST['device_id'])) {
$status = 'error';
if (! is_numeric($_POST['device_id'])) {
$status = 'error';
$message = 'Invalid device id ' . $_POST['device_id'];
} else {
$result = device_discovery_trigger($_POST['device_id']);
if (!empty($result['status']) || $result['status'] == '0') {
if (! empty($result['status']) || $result['status'] == '0') {
$status = 'ok';
} else {
$status = 'error';
@@ -35,8 +35,8 @@ if (isset($_POST['device_id'])) {
$message = $result['message'];
}
} elseif (isset($_POST['device_group_id'])) {
if (!is_numeric($_POST['device_group_id'])) {
$status = 'error';
if (! is_numeric($_POST['device_group_id'])) {
$status = 'error';
$message = 'Invalid device group id ' . $_POST['device_group_id'];
} else {
$device_ids = dbFetchColumn("SELECT `device_id` FROM `device_group_device` WHERE `device_group_id`=" . $_POST['device_group_id']);
@@ -46,23 +46,23 @@ if (isset($_POST['device_id'])) {
$update += $result['status'];
}
if (!empty($update) || $update == '0') {
$status = 'ok';
if (! empty($update) || $update == '0') {
$status = 'ok';
$message = 'Devices of group ' . $_POST['device_group_id'] . ' will be rediscovered';
} else {
$status = 'error';
$status = 'error';
$message = 'Error rediscovering devices of group ' . $_POST['device_group_id'];
}
}
} else {
$status = 'Error';
$status = 'Error';
$message = 'Undefined POST keys received';
}
$output = array(
$output = [
'status' => $status,
'message' => $message,
);
];
header('Content-type: application/json');
echo _json_encode($output);
@@ -15,21 +15,21 @@ header('Content-type: application/json');
$device_hostname = clean($_POST['device_hostname']);
if (Auth::user()->hasGlobalAdmin() && isset($device_hostname)) {
if (oxidized_node_update($device_hostname, "LibreNMS GUI refresh", Auth::user()->username)) {
$status = 'ok';
$status = 'ok';
$message = 'Queued refresh in oxidized for device ' . $device_hostname;
} else {
$status = 'error';
$status = 'error';
$message = 'ERROR: Could not queue refresh of oxidized device' . $device_hostname;
};
}
} else {
$status = 'error';
$status = 'error';
$message = 'ERROR: Could not queue refresh oxidized device';
}
$output = array(
$output = [
'status' => $status,
'message' => $message,
);
];
header('Content-type: application/json');
echo _json_encode($output);
@@ -10,7 +10,7 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
$status = 'error';
$message = 'ERROR: You need to be admin to reload Oxidized node list';
} else {
@@ -18,9 +18,9 @@ if (!Auth::user()->hasGlobalAdmin()) {
$status = 'ok';
$message = 'Oxidized node list was reloaded';
}
$output = array(
$output = [
'status' => $status,
'message' => $message,
);
];
header('Content-type: application/json');
echo _json_encode($output);
+9 -9
View File
@@ -14,28 +14,28 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error updating routing information';
$device_id = $_POST['device_id'];
$routing_id = $_POST['routing_id'];
$data = $_POST['data'];
if (!is_numeric($device_id)) {
if (! is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($routing_id)) {
} elseif (! is_numeric($routing_id)) {
$message = 'Missing routing id';
} else {
if (dbUpdate(array('bgpPeerDescr'=>$data), 'bgpPeers', '`bgpPeer_id`=? AND `device_id`=?', array($routing_id,$device_id)) >= 0) {
if (dbUpdate(['bgpPeerDescr'=>$data], 'bgpPeers', '`bgpPeer_id`=? AND `device_id`=?', [$routing_id, $device_id]) >= 0) {
$message = 'Routing information updated';
$status = 'ok';
} else {
@@ -43,9 +43,9 @@ if (!is_numeric($device_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
);
];
echo _json_encode($response);
@@ -12,14 +12,14 @@
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
$status = ['status' => 1, 'message' => 'You need to be admin'];
} else {
$parent_ids = (array)$_POST['parent_ids'];
$device_ids = (array)$_POST['device_ids'];
$parent_ids = (array) $_POST['parent_ids'];
$device_ids = (array) $_POST['device_ids'];
foreach ($parent_ids as $parent) {
if (!is_numeric($parent)) {
if (! is_numeric($parent)) {
$status = ['status' => 1, 'message' => 'Parent ID must be an integer!'];
break;
}
@@ -30,7 +30,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
}
foreach ($device_ids as $device_id) {
if (!is_numeric($device_id)) {
if (! is_numeric($device_id)) {
$status = ['status' => 1, 'message' => 'Device ID must be an integer!'];
break;
} elseif (in_array($device_id, $parent_ids)) {
@@ -40,7 +40,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
\App\Models\Device::find($device_id)->parents()->sync($parent_ids);
$status = array('status' => 0, 'message' => 'Device dependencies have been saved');
$status = ['status' => 0, 'message' => 'Device dependencies have been saved'];
}
}
header('Content-Type: application/json');
@@ -15,9 +15,9 @@ use Illuminate\Support\Str;
* the source code distribution for details.
*/
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
exit('ERROR: You need to be admin');
}
$sub_type = $_POST['sub_type'];
@@ -41,20 +41,20 @@ if ($sub_type == 'new-maintenance') {
$start_recurring_hr = mres($_POST['start_recurring_hr']);
$end_recurring_hr = mres($_POST['end_recurring_hr']);
$recurring_day = mres($_POST['recurring_day']);
$start = mres($_POST['start']);
$start = mres($_POST['start']);
[$duration_hour, $duration_min] = explode(':', mres($_POST['duration']));
$end = mres($_POST['end']);
$maps = mres($_POST['maps']);
$end = mres($_POST['end']);
$maps = mres($_POST['maps']);
if (isset($duration_hour) && isset($duration_min)) {
$end = date('Y-m-d H:i:00', strtotime('+'.intval($duration_hour).' hour '.intval($duration_min).' minute', strtotime($start)));
$end = date('Y-m-d H:i:00', strtotime('+' . intval($duration_hour) . ' hour ' . intval($duration_min) . ' minute', strtotime($start)));
}
if (empty($title)) {
$message = 'Missing title<br />';
}
if (!in_array($recurring, array(0,1))) {
if (! in_array($recurring, [0, 1])) {
$message .= 'Missing recurring choice<br />';
}
@@ -66,14 +66,14 @@ if ($sub_type == 'new-maintenance') {
} else {
// check if date is correct
[$ysrd, $msrd, $dsrd] = explode('-', $start_recurring_dt);
if (!checkdate($msrd, $dsrd, $ysrd)) {
if (! checkdate($msrd, $dsrd, $ysrd)) {
$message .= 'Please check start recurring date<br />';
}
}
// end recurring dt not mandatory.. but if set, check if correct
if (!empty($end_recurring_dt) && $end_recurring_dt != '0000-00-00' && $end_recurring_dt != '') {
if (! empty($end_recurring_dt) && $end_recurring_dt != '0000-00-00' && $end_recurring_dt != '') {
[$yerd, $merd, $derd] = explode('-', $end_recurring_dt);
if (!checkdate($merd, $derd, $yerd)) {
if (! checkdate($merd, $derd, $yerd)) {
$message .= 'Please check end recurring date<br />';
}
} else {
@@ -88,7 +88,7 @@ if ($sub_type == 'new-maintenance') {
$message .= 'Missing end recurring hour<br />';
}
if (isset($_POST['recurring_day']) && is_array($_POST['recurring_day']) && !empty($_POST['recurring_day'])) {
if (isset($_POST['recurring_day']) && is_array($_POST['recurring_day']) && ! empty($_POST['recurring_day'])) {
$recurring_day = $_POST['recurring_day'];
}
@@ -111,7 +111,7 @@ if ($sub_type == 'new-maintenance') {
$end_recurring_hr = '00:00:00';
}
if (!is_array($_POST['maps'])) {
if (! is_array($_POST['maps'])) {
$message .= 'Not mapped to any groups or devices<br />';
}
@@ -133,8 +133,8 @@ if ($sub_type == 'new-maintenance') {
$alert_schedule->save();
if ($alert_schedule->schedule_id > 0) {
$items = array();
$fail = 0;
$items = [];
$fail = 0;
if ($update == 1) {
dbDelete('alert_schedulables', '`schedule_id`=?', [$alert_schedule->schedule_id]);
@@ -153,7 +153,7 @@ if ($sub_type == 'new-maintenance') {
$item = dbInsert(['schedule_id' => $alert_schedule->schedule_id, 'alert_schedulable_type' => $type, 'alert_schedulable_id' => $target], 'alert_schedulables');
if ($notes && $type = 'device' && UserPref::getPref(Auth::user(), 'add_schedule_note_to_device')) {
$device_notes = dbFetchCell('SELECT `notes` FROM `devices` WHERE `device_id` = ?;', [$target]);
$device_notes.= ((empty($device_notes)) ? '' : PHP_EOL) . date("Y-m-d H:i") . ' Alerts delayed: ' . $notes;
$device_notes .= ((empty($device_notes)) ? '' : PHP_EOL) . date("Y-m-d H:i") . ' Alerts delayed: ' . $notes;
dbUpdate(['notes' => $device_notes], 'devices', '`device_id` = ?', [$target]);
}
if ($item > 0) {
@@ -165,13 +165,13 @@ if ($sub_type == 'new-maintenance') {
if ($fail == 1 && $update == 0) {
foreach ($items as $item) {
dbDelete('alert_schedulables', '`item_id`=?', array($item));
dbDelete('alert_schedulables', '`item_id`=?', [$item]);
}
dbDelete('alert_schedule', '`schedule_id`=?', [$alert_schedule->schedule_id]);
$message = 'Issue scheduling maintenance';
} else {
$status = 'ok';
$status = 'ok';
$message = 'Scheduling maintenance ok';
}
} else {
@@ -179,10 +179,10 @@ if ($sub_type == 'new-maintenance') {
}//end if
}//end if
$response = array(
$response = [
'status' => $status,
'message' => $message,
);
];
} elseif ($sub_type == 'parse-maintenance') {
$alert_schedule = \App\Models\AlertSchedule::findOrFail($_POST['schedule_id']);
$items = [];
@@ -209,14 +209,14 @@ if ($sub_type == 'new-maintenance') {
$response['targets'] = $items;
} elseif ($sub_type == 'del-maintenance') {
$schedule_id = mres($_POST['del_schedule_id']);
dbDelete('alert_schedule', '`schedule_id`=?', array($schedule_id));
dbDelete('alert_schedulables', '`schedule_id`=?', array($schedule_id));
$status = 'ok';
$message = 'Maintenance schedule has been removed';
$response = array(
dbDelete('alert_schedule', '`schedule_id`=?', [$schedule_id]);
dbDelete('alert_schedulables', '`schedule_id`=?', [$schedule_id]);
$status = 'ok';
$message = 'Maintenance schedule has been removed';
$response = [
'status' => $status,
'message' => $message,
);
];
}//end if
header('Content-type: application/json');
echo _json_encode($response);
@@ -11,20 +11,20 @@
*/
header('Content-type: application/json');
$status = 'error';
$message = 'unknown error';
$status = 'error';
$message = 'unknown error';
$parameters = clean($_POST['search_in_conf_textbox']);
if (isset($parameters)) {
$message = 'Queried';
if ($output = search_oxidized_config($parameters)) {
$status = 'ok';
$status = 'ok';
}
} else {
$message = 'ERROR: Could not query';
}
echo display(_json_encode(array(
'status' => $status,
'message' => $message,
'search_in_conf_textbox' => $parameters,
'output' => $output
)));
echo display(_json_encode([
'status' => $status,
'message' => $message,
'search_in_conf_textbox' => $parameters,
'output' => $output,
]));
@@ -15,16 +15,16 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error resetting values';
$sensor_limit = $_POST['sensor_limit'];
$sensor_limit_warn = $_POST['sensor_limit_warn'];
@@ -36,7 +36,7 @@ $sensor_count = count($sensor_id);
if (is_array($sensor_id)) {
for ($x = 0; $x < $sensor_count; $x++) {
if (dbUpdate(array('sensor_limit' => set_null($sensor_limit[$x], array('NULL')), 'sensor_limit_warn' => set_null($sensor_limit_warn[$x], array('NULL')), 'sensor_limit_low_warn' => set_null($sensor_limit_low_warn[$x], array('NULL')), 'sensor_limit_low' => set_null($sensor_limit_low[$x], array('NULL'))), 'sensors', '`sensor_id` = ?', array($sensor_id[$x])) >= 0) {
if (dbUpdate(['sensor_limit' => set_null($sensor_limit[$x], ['NULL']), 'sensor_limit_warn' => set_null($sensor_limit_warn[$x], ['NULL']), 'sensor_limit_low_warn' => set_null($sensor_limit_low_warn[$x], ['NULL']), 'sensor_limit_low' => set_null($sensor_limit_low[$x], ['NULL'])], 'sensors', '`sensor_id` = ?', [$sensor_id[$x]]) >= 0) {
$message = 'Sensor values resetted';
$status = 'ok';
} else {
@@ -44,11 +44,11 @@ if (is_array($sensor_id)) {
}
}
} else {
$status = 'error';
$status = 'error';
$message = 'Invalid sensor id';
}
$response = array(
$response = [
'status' => $status,
'message' => $message
);
'message' => $message,
];
echo _json_encode($response);
+13 -13
View File
@@ -15,26 +15,26 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
$status = 'error';
if (isset($_POST['sub_type']) && ! empty($_POST['sub_type'])) {
$status = 'error';
$message = 'Error removing custom';
if (dbUpdate(array('sensor_custom' => 'No'), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'])) >= 0) {
$status = 'ok';
if (dbUpdate(['sensor_custom' => 'No'], 'sensors', '`sensor_id` = ?', [$_POST['sensor_id']]) >= 0) {
$status = 'ok';
$message = 'Custom limit removed. New one will be set up in rediscovery';
} else {
$message = 'Couldn\'t not remove custom. Enable debug and check logfile';
}
} else {
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id'])) {
$message = "Invalid device or sensor id";
} else {
if ($_POST['state'] == 'true') {
@@ -47,8 +47,8 @@ if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
$state = 0;
$state_string = "disabled";
}
if (dbUpdate(array('sensor_alert' => $state), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'], $_POST['device_id'])) >= 0) {
$status = ($state == 0) ? 'info' : 'ok';
if (dbUpdate(['sensor_alert' => $state], 'sensors', '`sensor_id` = ? AND `device_id` = ?', [$_POST['sensor_id'], $_POST['device_id']]) >= 0) {
$status = ($state == 0) ? 'info' : 'ok';
$message = 'Alerts ' . $state_string . ' for sensor ' . $_POST['sensor_desc'];
} else {
$status = 'error';
@@ -56,8 +56,8 @@ if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) {
}
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message
);
'message' => $message,
];
echo _json_encode($response);
+10 -10
View File
@@ -15,30 +15,30 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$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)) {
if (! is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($sensor_id)) {
} elseif (! is_numeric($sensor_id)) {
$message = 'Missing sensor id';
} elseif (!isset($data)) {
} elseif (! isset($data)) {
$message = 'Missing data';
} else {
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) {
if (dbUpdate([$value_type => set_null($data, ['NULL']), 'sensor_custom' => 'Yes'], 'sensors', '`sensor_id` = ? AND `device_id` = ?', [$sensor_id, $device_id]) >= 0) {
$message = 'Sensor value updated';
$status = 'ok';
} else {
@@ -46,8 +46,8 @@ if (!is_numeric($device_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
);
];
echo _json_encode($response);
@@ -12,10 +12,10 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
@@ -34,21 +34,21 @@ if (is_numeric($transport_id) && $transport_id > 0) {
foreach (json_decode($transport['transport_config'], true) as $key => $value) {
$details[] = [
'name' => $key,
'value' => $value
'value' => $value,
];
}
}
if (is_array($transport)) {
die(json_encode([
exit(json_encode([
'name' => $transport['transport_name'],
'type' => $transport['transport_type'],
'is_default' => $is_default,
'details' => $details
'details' => $details,
]));
} else {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'No alert transport found'
'message' => 'No alert transport found',
]));
}
@@ -12,10 +12,10 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
@@ -23,26 +23,26 @@ $group_id = $vars['group_id'];
// Retrieve alert transport
if (is_numeric($group_id) && $group_id > 0) {
$name = dbFetchCell('SELECT `transport_group_name` FROM `alert_transport_groups` WHERE `transport_group_id`=? LIMIT 1', [$group_id]);
$query = "SELECT `a`.`transport_id`, `transport_type`, `transport_name` FROM `transport_group_transport` AS `a` LEFT JOIN `alert_transports` AS `b` ON `a`.`transport_id`=`b`.`transport_id` WHERE `transport_group_id`=?";
$members = [];
foreach (dbFetchRows($query, [$group_id]) as $member) {
$members[] = [
$members[] = [
'id' => $member['transport_id'],
'text' => ucfirst($member['transport_type']).": ".$member['transport_name']
'text' => ucfirst($member['transport_type']) . ": " . $member['transport_name'],
];
}
}
if (is_array($members)) {
die(json_encode([
exit(json_encode([
'name' => $name,
'members' => $members
'members' => $members,
]));
} else {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'No transport group found'
'message' => 'No transport group found',
]));
}
@@ -28,8 +28,8 @@ use LibreNMS\Config;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: You need to be admin',
]));
@@ -52,15 +52,15 @@ if (is_numeric($template_id)) {
'status' => 'ok',
'name' => $rule['name'],
'builder' => $rule['builder'] ?: QueryBuilderParser::fromOld($rule['rule'])->toArray(),
'extra' => array_replace($default_extra, (array)$rule['extra']),
'extra' => array_replace($default_extra, (array) $rule['extra']),
'severity' => $rule['severity'] ?: Config::get('alert_rule.severity'),
'invert_map' => Config::get('alert_rule.invert_map')
'invert_map' => Config::get('alert_rule.invert_map'),
];
} else {
$output = [
'status' => 'error',
'message' => 'Invalid template'
'message' => 'Invalid template',
];
}
die(json_encode($output));
exit(json_encode($output));
@@ -28,8 +28,8 @@ use LibreNMS\Config;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'ERROR: You need to be admin',
]));
@@ -38,7 +38,7 @@ if (!Auth::user()->hasGlobalAdmin()) {
$rule_id = $vars['rule_id'];
if (is_numeric($rule_id)) {
$rule = dbFetchRow('SELECT * FROM alert_rules where id=?', array($rule_id));
$rule = dbFetchRow('SELECT * FROM alert_rules where id=?', [$rule_id]);
$default_extra = [
'mute' => Config::get('alert_rule.mute_alerts'),
@@ -52,15 +52,15 @@ if (is_numeric($rule_id)) {
'status' => 'ok',
'name' => $rule['name'] . ' - Copy',
'builder' => QueryBuilderParser::fromJson($rule['builder']),
'extra' => array_replace($default_extra, (array)json_decode($rule['extra'])),
'extra' => array_replace($default_extra, (array) json_decode($rule['extra'])),
'severity' => $rule['severity'] ?: Config::get('alert_rule.severity'),
'invert_map' => $rule['invert_map'],
];
} else {
$output = [
'status' => 'error',
'message' => 'Invalid template'
'message' => 'Invalid template',
];
}
die(json_encode($output));
exit(json_encode($output));
+10 -10
View File
@@ -14,30 +14,30 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error updating storage information';
$device_id = mres($_POST['device_id']);
$storage_id = mres($_POST['storage_id']);
$data = mres($_POST['data']);
if (!is_numeric($device_id)) {
if (! is_numeric($device_id)) {
$message = 'Missing device id';
} elseif (!is_numeric($storage_id)) {
} elseif (! is_numeric($storage_id)) {
$message = 'Missing storage id';
} elseif (!is_numeric($data)) {
} elseif (! is_numeric($data)) {
$message = 'Missing value';
} else {
if (dbUpdate(array('storage_perc_warn'=>$data), 'storage', '`storage_id`=? AND `device_id`=?', array($storage_id,$device_id)) >= 0) {
if (dbUpdate(['storage_perc_warn'=>$data], 'storage', '`storage_id`=? AND `device_id`=?', [$storage_id, $device_id]) >= 0) {
$message = 'Storage information updated';
$status = 'ok';
} else {
@@ -45,9 +45,9 @@ if (!is_numeric($device_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
);
];
echo _json_encode($response);
+6 -6
View File
@@ -15,17 +15,17 @@
use LibreNMS\Alert\AlertUtil;
use LibreNMS\Config;
if (!Auth::user()->hasGlobalAdmin()) {
if (! Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
exit('ERROR: You need to be admin');
}
$transport = $vars['transport'] ?: null;
$transport_id = $vars['transport_id'] ?: null;
$tmp = array(dbFetchRow('select device_id,hostname,sysDescr,version,hardware,location_id from devices order by device_id asc limit 1'));
$tmp = [dbFetchRow('select device_id,hostname,sysDescr,version,hardware,location_id from devices order by device_id asc limit 1')];
$tmp['contacts'] = AlertUtil::getContacts($tmp);
$obj = array(
$obj = [
"hostname" => $tmp[0]['hostname'],
"device_id" => $tmp[0]['device_id'],
"sysDescr" => $tmp[0]['sysDescr'],
@@ -45,14 +45,14 @@ $obj = array(
"contacts" => $tmp['contacts'],
"state" => "1",
"msg" => "This is a test alert",
);
];
$response = ['status' => 'error'];
if ($transport_id) {
$transport = dbFetchCell("SELECT `transport_type` FROM `alert_transports` WHERE `transport_id` = ?", [$transport_id]);
}
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport);
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport);
if (class_exists($class)) {
$opts = Config::get("alert.transports.$transport");
$instance = new $class($transport_id);
@@ -14,11 +14,11 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($_POST['user_id']) || !isset($_POST['token'])) {
if (! is_numeric($_POST['user_id']) || ! isset($_POST['token'])) {
echo 'ERROR: error with data, please ensure a valid user and token have been specified.';
exit;
} elseif (strlen($_POST['token']) > 32) {
@@ -28,7 +28,7 @@ if (!is_numeric($_POST['user_id']) || !isset($_POST['token'])) {
echo 'ERROR: The token is less than 16 characters';
exit;
} else {
$create = dbInsert(array('user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']), 'api_tokens');
$create = dbInsert(['user_id' => $_POST['user_id'], 'token_hash' => $_POST['token'], 'description' => $_POST['description']], 'api_tokens');
if ($create > '0') {
echo 'API token has been created';
Session::put('api_token', true);
@@ -14,11 +14,11 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($_POST['token_id'])) {
if (! is_numeric($_POST['token_id'])) {
echo 'error with data';
exit;
} else {
@@ -30,8 +30,8 @@ if (!is_numeric($_POST['token_id'])) {
$state = 0;
}
$update = dbUpdate(array('disabled' => $state), 'api_tokens', '`id` = ?', array($_POST['token_id']));
if (!empty($update) || $update == '0') {
$update = dbUpdate(['disabled' => $state], 'api_tokens', '`id` = ?', [$_POST['token_id']]);
if (! empty($update) || $update == '0') {
echo 'success';
exit;
} else {
@@ -14,16 +14,16 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($_POST['token_id'])) {
if (! is_numeric($_POST['token_id'])) {
echo 'error with data';
exit;
} else {
if ($_POST['confirm'] == 'yes') {
$delete = dbDelete('api_tokens', '`id` = ?', array($_POST['token_id']));
$delete = dbDelete('api_tokens', '`id` = ?', [$_POST['token_id']]);
if ($delete > '0') {
echo 'API token has been removed';
exit;
+21 -22
View File
@@ -22,25 +22,24 @@
* @copyright 2018 Vivia Nguyen-Tran
* @author Vivia Nguyen-Tran <[email protected]>
*/
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
$status = 'ok';
$message = '';
$group_id = $vars['group_id'];
$name = $vars['name'];
$group_id = $vars['group_id'];
$name = $vars['name'];
$target_members = [];
foreach ((array)$vars['members'] as $target) {
$target_members[] = (int)$target;
foreach ((array) $vars['members'] as $target) {
$target_members[] = (int) $target;
}
if (empty($name)) {
@@ -52,16 +51,16 @@ if (empty($name)) {
$message = 'Not enough group members';
} else {
if (is_numeric($group_id) && $group_id > 0) {
dbUpdate(array(
'transport_group_name' => $name
), 'alert_transport_groups', "`transport_group_id`=?", [$group_id]);
dbUpdate([
'transport_group_name' => $name,
], 'alert_transport_groups', "`transport_group_id`=?", [$group_id]);
} else {
// Insert into db
$group_id = dbInsert(array(
'transport_group_name' => $name
), 'alert_transport_groups');
$group_id = dbInsert([
'transport_group_name' => $name,
], 'alert_transport_groups');
}
if (is_numeric($group_id) && $group_id > 0) {
$sql = "SELECT `transport_id` FROM `transport_group_transport` WHERE `transport_group_id`=?";
$db_members = dbFetchColumn($sql, [$group_id]);
@@ -73,17 +72,17 @@ if (empty($name)) {
// Insert new transport group members
$insert = [];
foreach ($add as $transport_id) {
$insert[] = array(
$insert[] = [
'transport_id' => $transport_id,
'transport_group_id' => $group_id
);
'transport_group_id' => $group_id,
];
}
if (!empty($insert)) {
if (! empty($insert)) {
dbBulkInsert($insert, 'transport_group_transport');
}
// Remove old transport group members
if (!empty($remove)) {
if (! empty($remove)) {
dbDelete('transport_group_transport', 'transport_group_id=? AND `transport_id` IN ' . dbGenPlaceholders(count($remove)), array_merge([$group_id], $remove));
}
$message = 'Updated alert transport group';
@@ -93,7 +92,7 @@ if (empty($name)) {
}
}
die(json_encode([
exit(json_encode([
'status' => $status,
'message' => $message
'message' => $message,
]));
@@ -14,11 +14,11 @@
header('Content-type: text/plain');
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
if (!is_numeric($_POST['alert_id'])) {
if (! is_numeric($_POST['alert_id'])) {
echo 'ERROR: No alert selected';
exit;
} else {
@@ -30,8 +30,8 @@ if (!is_numeric($_POST['alert_id'])) {
$state = 1;
}
$update = dbUpdate(array('disabled' => $state), 'alert_rules', '`id`=?', array($_POST['alert_id']));
if (!empty($update) || $update == '0') {
$update = dbUpdate(['disabled' => $state], 'alert_rules', '`id`=?', [$_POST['alert_id']]);
if (! empty($update) || $update == '0') {
echo 'Alert rule has been updated.';
exit;
} else {
@@ -2,16 +2,16 @@
header('Content-type: application/json');
if (!Auth::check()) {
$response = array(
if (! Auth::check()) {
$response = [
'status' => 'error',
'message' => 'Unauthenticated',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$status = 'error';
$message = 'Error updating user dashboard config';
$data = json_decode($vars['data'], true);
@@ -20,8 +20,8 @@ $widget_id = $vars['widget_id'];
$dasboard_id = $vars['dashboard_id'];
if ($sub_type == 'remove' && is_numeric($widget_id)) {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', array(Auth::id(),$dasboard_id)) == 1) {
if ($widget_id == 0 || dbDelete('users_widgets', '`user_widget_id`=? AND `dashboard_id`=?', array($widget_id,$dasboard_id))) {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dasboard_id]) == 1) {
if ($widget_id == 0 || dbDelete('users_widgets', '`user_widget_id`=? AND `dashboard_id`=?', [$widget_id, $dasboard_id])) {
$status = 'ok';
$message = 'Widget ' . $widget_id . ' removed';
}
@@ -30,8 +30,8 @@ if ($sub_type == 'remove' && is_numeric($widget_id)) {
$message = 'ERROR: You don\'t have write access.';
}
} elseif ($sub_type == 'remove-all') {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', array(Auth::id(),$dasboard_id)) == 1) {
if (dbDelete('users_widgets', '`dashboard_id`=?', array($dasboard_id))) {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dasboard_id]) == 1) {
if (dbDelete('users_widgets', '`dashboard_id`=?', [$dasboard_id])) {
$status = 'ok';
$message = 'All widgets removed';
}
@@ -40,13 +40,13 @@ if ($sub_type == 'remove' && is_numeric($widget_id)) {
$message = 'ERROR: You don\'t have write access.';
}
} elseif ($sub_type == 'add' && is_numeric($widget_id)) {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', array(Auth::id(),$dasboard_id)) == 1) {
$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', array($widget_id));
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dasboard_id]) == 1) {
$widget = dbFetchRow('SELECT * FROM `widgets` WHERE `widget_id`=?', [$widget_id]);
if (is_array($widget)) {
list($x,$y) = explode(',', $widget['base_dimensions']);
$item_id = dbInsert(array('user_id'=>Auth::id(),'widget_id'=>$widget_id, 'col'=>1,'row'=>1,'refresh'=>60,'title'=>$widget['widget_title'],'size_x'=>$x,'size_y'=>$y,'settings'=>'','dashboard_id'=>$dasboard_id), 'users_widgets');
[$x,$y] = explode(',', $widget['base_dimensions']);
$item_id = dbInsert(['user_id'=>Auth::id(), 'widget_id'=>$widget_id, 'col'=>1, 'row'=>1, 'refresh'=>60, 'title'=>$widget['widget_title'], 'size_x'=>$x, 'size_y'=>$y, 'settings'=>'', 'dashboard_id'=>$dasboard_id], 'users_widgets');
if (is_numeric($item_id)) {
$extra = array('user_widget_id'=>$item_id,'widget_id'=>$item_id,'title'=>$widget['widget_title'],'widget'=>$widget['widget'],'refresh'=>60,'size_x'=>$x,'size_y'=>$y);
$extra = ['user_widget_id'=>$item_id, 'widget_id'=>$item_id, 'title'=>$widget['widget_title'], 'widget'=>$widget['widget'], 'refresh'=>60, 'size_x'=>$x, 'size_y'=>$y];
$status = 'ok';
$message = 'Widget ' . $widget['widget_title'] . ' added';
}
@@ -56,13 +56,13 @@ if ($sub_type == 'remove' && is_numeric($widget_id)) {
$message = 'ERROR: You don\'t have write access.';
}
} else {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', array(Auth::id(),$dasboard_id)) == 1) {
if (dbFetchCell('select 1 from dashboards where (user_id = ? || access = 2) && dashboard_id = ?', [Auth::id(), $dasboard_id]) == 1) {
$status = 'ok';
$message = 'Widgets updated';
foreach ($data as $line) {
if (is_array($line)) {
$update = array('col'=>$line['col'],'row'=>$line['row'],'size_x'=>$line['size_x'],'size_y'=>$line['size_y']);
dbUpdate($update, 'users_widgets', '`user_widget_id`=? AND `dashboard_id`=?', array($line['id'],$dasboard_id));
$update = ['col'=>$line['col'], 'row'=>$line['row'], 'size_x'=>$line['size_x'], 'size_y'=>$line['size_y']];
dbUpdate($update, 'users_widgets', '`user_widget_id`=? AND `dashboard_id`=?', [$line['id'], $dasboard_id]);
}
}
} else {
@@ -71,9 +71,9 @@ if ($sub_type == 'remove' && is_numeric($widget_id)) {
}
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
'extra' => $extra,
);
];
echo _json_encode($response);
+7 -7
View File
@@ -13,26 +13,26 @@
*/
header('Content-type: application/json');
$status = 'error';
$status = 'error';
$descr = mres($_POST['descr']);
$device_id = mres($_POST['device_id']);
$ifName = mres($_POST['ifName']);
$port_id = mres($_POST['port_id']);
if (!empty($ifName) && is_numeric($port_id)) {
if (! empty($ifName) && is_numeric($port_id)) {
// We have ifName and port id so update ifAlias
if (empty($descr)) {
$descr = 'repoll';
// Set to repoll so we avoid using ifDescr on port poll
}
if (dbUpdate(array('ifAlias'=>$descr), 'ports', '`port_id`=?', array($port_id)) > 0) {
if (dbUpdate(['ifAlias'=>$descr], 'ports', '`port_id`=?', [$port_id]) > 0) {
$device = device_by_id_cache($device_id);
if ($descr === 'repoll') {
del_dev_attrib($device, 'ifName:'.$ifName);
del_dev_attrib($device, 'ifName:' . $ifName);
log_event("$ifName Port ifAlias cleared manually", $device, 'interface', 3, $port_id);
} else {
set_dev_attrib($device, 'ifName:'.$ifName, 1);
set_dev_attrib($device, 'ifName:' . $ifName, 1);
log_event("$ifName Port ifAlias set manually: $descr", $device, 'interface', 3, $port_id);
}
$status = 'ok';
@@ -41,7 +41,7 @@ if (!empty($ifName) && is_numeric($port_id)) {
}
}
$response = array(
$response = [
'status' => $status,
);
];
echo _json_encode($response);
+11 -11
View File
@@ -12,31 +12,31 @@
*/
header('Content-type: application/json');
$status = 'error';
$status = 'error';
$speed = mres($_POST['speed']);
$device_id = mres($_POST['device_id']);
$ifName = mres($_POST['ifName']);
$port_id = mres($_POST['port_id']);
if (!empty($ifName) && is_numeric($port_id) && is_numeric($port_id)) {
if (! empty($ifName) && is_numeric($port_id) && is_numeric($port_id)) {
// We have ifName and port id so update ifAlias
if (empty($speed)) {
$speed = array('NULL');
$high_speed = array('NULL');
// Set to 999999 so we avoid using ifDescr on port poll
$speed = ['NULL'];
$high_speed = ['NULL'];
// Set to 999999 so we avoid using ifDescr on port poll
} else {
$high_speed = $speed / 1000000;
}
if (dbUpdate(array('ifSpeed'=>$speed, 'ifHighSpeed'=>$high_speed), 'ports', '`port_id`=?', array($port_id)) > 0) {
if (dbUpdate(['ifSpeed'=>$speed, 'ifHighSpeed'=>$high_speed], 'ports', '`port_id`=?', [$port_id]) > 0) {
$device = device_by_id_cache($device_id);
if (is_array($speed)) {
del_dev_attrib($device, 'ifSpeed:'.$ifName);
del_dev_attrib($device, 'ifSpeed:' . $ifName);
log_event("$ifName Port speed cleared manually", $device, 'interface', 3, $port_id);
} else {
set_dev_attrib($device, 'ifSpeed:'.$ifName, 1);
set_dev_attrib($device, 'ifSpeed:' . $ifName, 1);
log_event("$ifName Port speed set manually: $speed", $device, 'interface', 3, $port_id);
$port_tune = get_dev_attrib($device, 'ifName_tune:'.$ifName);
$port_tune = get_dev_attrib($device, 'ifName_tune:' . $ifName);
$device_tune = get_dev_attrib($device, 'override_rrdtool_tune');
if ($port_tune == "true" ||
($device_tune == "true" && $port_tune != 'false') ||
@@ -51,7 +51,7 @@ if (!empty($ifName) && is_numeric($port_id) && is_numeric($port_id)) {
}
}
$response = array(
$response = [
'status' => $status,
);
];
echo _json_encode($response);
@@ -11,25 +11,25 @@
*/
header('Content-type: application/json');
$status = 'error';
$message = 'unknown error';
$status = 'error';
$message = 'unknown error';
$device_id = mres($_POST['device_id']);
$port_id_notes = mres($_POST['port_id_notes']);
$attrib_value = $_POST['notes'];
if (isset($attrib_value) && set_dev_attrib(array('device_id' => $device_id), $port_id_notes, $attrib_value)) {
$status = 'ok';
if (isset($attrib_value) && set_dev_attrib(['device_id' => $device_id], $port_id_notes, $attrib_value)) {
$status = 'ok';
$message = 'Updated';
} else {
$status = 'error';
$status = 'error';
$message = 'ERROR: Could not update';
}
die(json_encode(array(
exit(json_encode([
'status' => $status,
'message' => $message,
'attrib_type' => $port_id_notes,
'attrib_value' => $attrib_value,
'device_id' => $device_id
'device_id' => $device_id,
)));
]));
+15 -15
View File
@@ -2,20 +2,20 @@
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
$response = array(
if (! Auth::user()->hasGlobalAdmin()) {
$response = [
'status' => 'error',
'message' => 'Need to be admin',
);
];
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error with config';
$status = 'error';
$message = 'Error with config';
// enable/disable ports/interfaces on devices.
$device_id = intval($_POST['device']);
$device_id = intval($_POST['device']);
$rows_updated = 0;
foreach ($_POST as $key => $val) {
@@ -24,7 +24,7 @@ foreach ($_POST as $key => $val) {
$port_id = intval(substr($key, 7));
$oldign = intval($val) ? 1 : 0;
$newign = $_POST['ignore_'.$port_id] ? 1 : 0;
$newign = $_POST['ignore_' . $port_id] ? 1 : 0;
// As checkboxes are not posted when unset - we effectively need to do a diff to work
// out a set->unset case.
@@ -32,7 +32,7 @@ foreach ($_POST as $key => $val) {
continue;
}
$n = dbUpdate(array('ignore' => $newign), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
$n = dbUpdate(['ignore' => $newign], 'ports', '`device_id` = ? AND `port_id` = ?', [$device_id, $port_id]);
if ($n < 0) {
$rows_updated = -1;
@@ -45,7 +45,7 @@ foreach ($_POST as $key => $val) {
$port_id = intval(substr($key, 7));
$olddis = intval($val) ? 1 : 0;
$newdis = $_POST['disabled_'.$port_id] ? 1 : 0;
$newdis = $_POST['disabled_' . $port_id] ? 1 : 0;
// As checkboxes are not posted when unset - we effectively need to do a diff to work
// out a set->unset case.
@@ -53,7 +53,7 @@ foreach ($_POST as $key => $val) {
continue;
}
$n = dbUpdate(array('disabled' => $newdis), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id));
$n = dbUpdate(['disabled' => $newdis], 'ports', '`device_id` = ? AND `port_id` = ?', [$device_id, $port_id]);
if ($n < 0) {
$rows_updated = -1;
@@ -65,17 +65,17 @@ foreach ($_POST as $key => $val) {
}//end foreach
if ($rows_updated > 0) {
$message = $rows_updated.' Device record updated.';
$status = 'ok';
$message = $rows_updated . ' Device record updated.';
$status = 'ok';
} elseif ($rows_updated = '-1') {
$message = 'Device record unchanged. No update necessary.';
$status = 'ok';
$status = 'ok';
} else {
$message = 'Device record update error.';
}
$response = array(
$response = [
'status' => $status,
'message' => $message,
);
];
echo _json_encode($response);
@@ -17,19 +17,19 @@ header('Content-type: text/plain');
// FUA
if (!Auth::user()->hasGlobalAdmin()) {
die('ERROR: You need to be admin');
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
for ($x = 0; $x < count($_POST['sensor_id']); $x++) {
dbUpdate(
array(
'sensor_limit' => set_null($_POST['sensor_limit'][$x], array('NULL')),
'sensor_limit_low' => set_null($_POST['sensor_limit_low'][$x], array('NULL')),
'sensor_alert' => set_null($_POST['sensor_alert'][$x], array('NULL'))
),
[
'sensor_limit' => set_null($_POST['sensor_limit'][$x], ['NULL']),
'sensor_limit_low' => set_null($_POST['sensor_limit_low'][$x], ['NULL']),
'sensor_alert' => set_null($_POST['sensor_alert'][$x], ['NULL']),
],
'wireless_sensors',
'`sensor_id` = ?',
array($_POST['sensor_id'][$x])
[$_POST['sensor_id'][$x]]
);
}
@@ -17,30 +17,30 @@ header('Content-type: application/json');
// FUA
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
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([
if (dbUpdate(['sensor_custom' => 'No'], 'wireless_sensors', '`sensor_id` = ?', [$_POST['sensor_id']])) {
exit(json_encode([
'status' => 'ok',
'message' => 'Custom limit removed'
'message' => 'Custom limit removed',
]));
}
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'Could not remove custom. Check librenms.log'
'message' => 'Could not remove custom. Check librenms.log',
]));
} else {
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id'])) {
die(json_encode([
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id'])) {
exit(json_encode([
'status' => 'error',
'message' => 'Invalid values given'
'message' => 'Invalid values given',
]));
} else {
if ($_POST['state'] == 'true') {
@@ -57,15 +57,15 @@ if (isset($_POST['sub_type']) && $_POST['sub_type'] == 'remove-custom') {
'`sensor_id` = ? AND `device_id` = ?',
[$_POST['sensor_id'], $_POST['device_id']]
);
if (!empty($update) || $update == '0') {
die(json_encode([
if (! empty($update) || $update == '0') {
exit(json_encode([
'status' => 'ok',
'message' => 'Updated sensor value'
'message' => 'Updated sensor value',
]));
} else {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'Failed to update sensor value'
'message' => 'Failed to update sensor value',
]));
}
}
@@ -17,17 +17,17 @@ header('Content-type: application/json');
// FUA
if (!Auth::user()->hasGlobalAdmin()) {
die(json_encode([
if (! Auth::user()->hasGlobalAdmin()) {
exit(json_encode([
'status' => 'error',
'message' => 'You need to be admin'
'message' => 'You need to be admin',
]));
}
if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !isset($_POST['data'])) {
die(json_encode([
if (! is_numeric($_POST['device_id']) || ! is_numeric($_POST['sensor_id']) || ! isset($_POST['data'])) {
exit(json_encode([
'status' => 'error',
'message' => 'Invalid values given'
'message' => 'Invalid values given',
]));
} else {
$update = dbUpdate(
@@ -36,15 +36,15 @@ if (!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || !iss
'`sensor_id` = ? AND `device_id` = ?',
[$_POST['sensor_id'], $_POST['device_id']]
);
if (!empty($update) || $update == '0') {
die(json_encode([
if (! empty($update) || $update == '0') {
exit(json_encode([
'status' => 'ok',
'message' => 'Updated sensor value'
'message' => 'Updated sensor value',
]));
} else {
die(json_encode([
exit(json_encode([
'status' => 'error',
'message' => 'Failed to update sensor value'
'message' => 'Failed to update sensor value',
]));
}
}