Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -0,0 +1,38 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) Adam Armstrong
*
*/
// Currently edit allowed only for Admins
if (!$limitwrite) {
print_json_status('failed', 'Action not allowed.');
exit();
}
if ($alert_test = dbFetchRow("SELECT * FROM `alert_tests` WHERE `alert_test_id` = ?", [ $vars['alert_test_id'] ])) {
if ($alert_test['alert_assoc'] !== $vars['alert_assoc']) {
if (dbUpdate([ 'alert_assoc' => $vars['alert_assoc'] ], 'alert_tests', '`alert_test_id` = ?', [ $vars['alert_test_id'] ])) {
update_alert_table($vars['alert_test_id']);
print_json_status('ok', 'Associations updated.',
[ 'id' => $vars['alert_test_id'],
'redirect' => generate_url([ 'page' => 'alert_check', 'alert_test_id' => $vars['alert_test_id'] ]) ]);
} else {
print_json_status('failed', 'Database was not updated.');
}
} else {
print_json_status('warning', 'Associations not changed.');
}
} else {
print_json_status('failed', 'Alert Checker does not exist: [' . $vars['alert_test_id'] . ']');
}
// EOF

View File

@ -5,64 +5,72 @@
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
// Currently allowed only for Admins
if (!$readwrite) {
print_json_status('failed', 'Action not allowed.');
return;
// Currently allowed only for Admins and Limit Write
if (!$limitwrite) {
print_json_status('failed', 'Action not allowed.');
return;
}
$ok = TRUE;
foreach (array('entity_type', 'alert_name', 'alert_severity', 'alert_conditions') as $var) {
if (!isset($vars[$var]) || strlen($vars[$var]) == '0') {
$ok = FALSE;
$failed[] = $var;
}
foreach ([ 'entity_type', 'alert_name', 'alert_severity', 'alert_conditions' ] as $var) {
if (safe_empty($vars[$var])) {
$ok = FALSE;
$failed[] = $var;
}
}
if ($ok) {
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [ $vars['entity_type'], $vars['alert_name'] ])) {
print_json_status('failed', "Alert Checker '{$vars['alert_name']}' already exist.");
return;
}
if (dbExist('alert_tests', '`entity_type` = ? AND `alert_name` = ?', [ $vars['entity_type'], $vars['alert_name'] ])) {
print_json_status('failed', "Alert Checker '{$vars['alert_name']}' already exist.");
return;
}
$check_array = array();
$check_array = [];
$conditions = array();
foreach (explode("\n", trim($vars['alert_conditions'])) as $cond) {
$condition = array();
list($condition['metric'], $condition['condition'], $condition['value']) = explode(" ", trim($cond), 3);
$conditions[] = $condition;
}
$check_array['conditions'] = safe_json_encode($conditions);
$check_array['alert_assoc'] = $vars['alert_assoc'];
$check_array['entity_type'] = $vars['entity_type'];
$check_array['alert_name'] = $vars['alert_name'];
$check_array['alert_message'] = $vars['alert_message'];
$check_array['severity'] = $vars['alert_severity'];
$check_array['suppress_recovery'] = get_var_true($vars['alert_send_recovery']) ? 0 : 1;
$check_array['alerter'] = NULL;
$check_array['and'] = $vars['alert_and'];
$check_array['delay'] = $vars['alert_delay'];
$check_array['enable'] = '1';
$conditions = [];
foreach (explode("\n", trim($vars['alert_conditions'])) as $cond) {
if (preg_match(OBS_PATTERN_XSS, $cond)) {
print_json_status('failed', "Prevent XSS payload.");
return;
}
$condition = [];
[ $condition['metric'], $condition['condition'], $condition['value'] ] = explode(" ", trim($cond), 3);
if (!is_alpha($condition['metric'])) {
print_json_status('failed', "Incorrect condition metric '" . escape_html($condition['metric']) . "'");
return;
}
$conditions[] = $condition;
}
$check_array['conditions'] = safe_json_encode($conditions);
$check_array['alert_assoc'] = $vars['alert_assoc'];
$check_array['entity_type'] = $vars['entity_type'];
$check_array['alert_name'] = $vars['alert_name'];
$check_array['alert_message'] = $vars['alert_message'];
$check_array['severity'] = $vars['alert_severity'];
$check_array['suppress_recovery'] = get_var_true($vars['alert_send_recovery']) ? 0 : 1;
$check_array['alerter'] = NULL;
$check_array['and'] = $vars['alert_and'];
$check_array['delay'] = $vars['alert_delay'];
$check_array['enable'] = '1';
$check_id = dbInsert('alert_tests', $check_array);
$check_id = dbInsert('alert_tests', $check_array);
if (is_numeric($check_id)) {
update_alert_table($check_id);
if (is_numeric($check_id)) {
update_alert_table($check_id);
print_json_status('ok', '', [ 'id' => $check_id, 'redirect' => generate_url([ 'page' => 'alert_check', 'alert_test_id' => $check_id ]) ]);
} else {
print_json_status('ok', '', ['id' => $check_id, 'redirect' => generate_url(['page' => 'alert_check', 'alert_test_id' => $check_id])]);
} else {
print_json_status('failed', 'Alert creation failed. Please note that the alert name <b>must</b> be unique.');
}
print_json_status('failed', 'Alert creation failed. Please note that the alert name <b>must</b> be unique.');
}
} else {
print_json_status('failed', 'Missing required data. (' . implode(", ", $failed) . ')');
print_json_status('failed', 'Missing required data. (' . implode(", ", $failed) . ')');
}
// EOF

View File

@ -0,0 +1,37 @@
<?php
if ($_SESSION['userlevel'] >= 8) {
if (is_intnum($vars['value'])) {
$alert_entry = get_alert_entry_by_id($vars['value']);
if(!count($alert_entry)) {
print_json_status('failed', 'Alert entry not found. No update performed.');
die;
}
$update_array = [];
if ($alert_entry['ignore_until_ok'] != 1) {
$update_array['ignore_until_ok'] = '1';
}
if ($alert_entry['alert_status'] == 0) {
$update_array['alert_status'] = '3';
}
if (count($update_array)) {
//r($alert_entry);
dbUpdate($update_array, 'alert_table', 'alert_table_id = ?', [$alert_entry['alert_table_id']]);
$alert_device = device_by_id_cache($alert_entry['device_id']);
//print_message("Alert entry [{$vars['form_alert_table_id']}] for device '{$alert_device['hostname']}' suppressed.");
print_json_status('ok', 'alert '.$vars['form_alert_table_id'].' ignored until ok. status updated.', ['update_array' => $update_array]);
}
unset($update_array);
// FIXME - eventlog? audit log?
}
} else {
print_json_status('failed', 'Action not permitted. Not performed.');
}

View File

@ -6,21 +6,23 @@
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @copyright (C) Adam Armstrong
*
*/
if ($readonly) { return; } // Currently edit allowed only for 7+
if ($readonly) {
return;
} // Currently edit allowed only for 7+
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [ $vars['widget_id'] ]);
$widget = dbFetchRow("SELECT * FROM `dash_widgets` WHERE `widget_id` = ?", [$vars['widget_id']]);
$widget['widget_config'] = safe_json_decode($widget['widget_config']);
switch ($widget['widget_type']) {
case "graph":
case "graph":
if (safe_count($widget['widget_config'])) {
if (safe_count($widget['widget_config'])) {
// echo '
// <form onsubmit="return false">
@ -28,121 +30,120 @@ switch ($widget['widget_type']) {
// </form>
// ';
//r($widget['widget_config']);
//r($widget['widget_config']);
//r(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no');
//r(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no');
$modal_args = [
'id' => 'modal-edit_widget_' . $widget['widget_id'],
'title' => 'Configure Widget',
//'hide' => TRUE,
//'fade' => TRUE,
//'role' => 'dialog',
//'class' => 'modal-md',
];
$modal_args = [
'id' => 'modal-edit_widget_' . $widget['widget_id'],
'title' => 'Configure Widget',
//'hide' => TRUE,
//'fade' => TRUE,
//'role' => 'dialog',
//'class' => 'modal-md',
];
$form = [
'form_only' => TRUE, // Do not add modal open/close divs (it's generated outside)
'type' => 'horizontal',
'id' => 'edit_widget_' . $widget['widget_id'],
'userlevel' => 7, // Minimum user level for display form
'modal_args' => $modal_args, // !!! This generate modal specific form
//'help' => 'This will completely delete the rule and all associations and history.',
'class' => '', // Clean default box class!
//'url' => generate_url([ 'page' => 'syslog_rules' ]),
'onsubmit' => "return false",
];
$form['fieldset']['body'] = [ 'class' => 'modal-body' ]; // Required this class for modal body!
$form['fieldset']['footer'] = [ 'class' => 'modal-footer' ]; // Required this class for modal footer!
$form = [
'form_only' => TRUE, // Do not add modal open/close divs (it's generated outside)
'type' => 'horizontal',
'id' => 'edit_widget_' . $widget['widget_id'],
'userlevel' => 7, // Minimum user level for display form
'modal_args' => $modal_args, // !!! This generate modal specific form
//'help' => 'This will completely delete the rule and all associations and history.',
'class' => '', // Clean default box class!
//'url' => generate_url([ 'page' => 'syslog_rules' ]),
'onsubmit' => "return false",
];
$form['fieldset']['body'] = ['class' => 'modal-body']; // Required this class for modal body!
$form['fieldset']['footer'] = ['class' => 'modal-footer']; // Required this class for modal footer!
$form['row'][1]['widget-config-title'] = [
'type' => 'text',
'fieldset' => 'body',
'name' => 'Title',
'placeholder' => 'Graph Title',
'class' => 'input-xlarge',
'attribs' => [
'data-id' => $widget['widget_id'],
'data-field' => 'title',
'data-type' => 'text'
],
'value' => $widget['widget_config']['title']
];
$form['row'][2]['widget-config-legend'] = [
'type' => 'checkbox',
'fieldset' => 'body',
'name' => 'Show Legend',
//'placeholder' => 'Yes, please delete this rule.',
//'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');",
'attribs' => [
'data-id' => $widget['widget_id'],
'data-field' => 'legend',
'data-type' => 'checkbox'
],
'value' => safe_empty($widget['widget_config']['legend']) ? 'yes' : $widget['widget_config']['legend'] //'legend'
];
$form['row'][1]['widget-config-title'] = [
'type' => 'text',
'fieldset' => 'body',
'name' => 'Title',
'placeholder' => 'Graph Title',
'class' => 'input-xlarge',
'attribs' => [
'data-id' => $widget['widget_id'],
'data-field' => 'title',
'data-type' => 'text'
],
'value' => $widget['widget_config']['title']
];
$form['row'][2]['widget-config-legend'] = [
'type' => 'checkbox',
'fieldset' => 'body',
'name' => 'Show Legend',
//'placeholder' => 'Yes, please delete this rule.',
//'onchange' => "javascript: toggleAttrib('disabled', 'delete_button_".$la['la_id']."'); showDiv(!this.checked, 'warning_".$la['la_id']."_div');",
'attribs' => [
'data-id' => $widget['widget_id'],
'data-field' => 'legend',
'data-type' => 'checkbox'
],
'value' => safe_empty($widget['widget_config']['legend']) ? 'yes' : $widget['widget_config']['legend'] //'legend'
];
$form['row'][8]['close'] = [
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Close',
'icon' => '',
'attribs' => [
'data-dismiss' => 'modal',
'aria-hidden' => 'true'
]
];
$form['row'][8]['close'] = [
'type' => 'submit',
'fieldset' => 'footer',
'div_class' => '', // Clean default form-action class!
'name' => 'Close',
'icon' => '',
'attribs' => [
'data-dismiss' => 'modal',
'aria-hidden' => 'true'
]
];
echo generate_form_modal($form);
unset($form);
echo generate_form_modal($form);
unset($form);
/*
echo '
<form onsubmit="return false" class="form form-horizontal" style="margin-bottom: 0px;">
<fieldset>
<div id="purpose_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-1 -->
<label class="control-label" for="purpose">Title</label>
<div id="purpose_div" class="controls">
<input type="text" placeholder="Graph Title" name="widget-config-title" class="input" data-field="title" style="width: 100%;" value="'.$widget['widget_config']['title'].'" data-id="'.$widget['widget_id'].'">
</div>
</div>
/*
echo '
<form onsubmit="return false" class="form form-horizontal" style="margin-bottom: 0px;">
<fieldset>
<div id="purpose_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-1 -->
<label class="control-label" for="purpose">Title</label>
<div id="purpose_div" class="controls">
<input type="text" placeholder="Graph Title" name="widget-config-title" class="input" data-field="title" style="width: 100%;" value="'.$widget['widget_config']['title'].'" data-id="'.$widget['widget_id'].'">
</div>
</div>
<div id="ignore_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-6 -->
<label class="control-label" for="ignore">Show Legend</label>
<div id="ignore_div" class="controls">
<input type="checkbox" name="widget-config-legend" data-field="legend" data-type="checkbox" value="legend" '.(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no' ? '' : 'checked').' data-id="'.$widget['widget_id'].'">
</div>
</div>
</fieldset> <!-- END fieldset-body -->
<div id="ignore_div" class="control-group" style="margin-bottom: 10px;"> <!-- START row-6 -->
<label class="control-label" for="ignore">Show Legend</label>
<div id="ignore_div" class="controls">
<input type="checkbox" name="widget-config-legend" data-field="legend" data-type="checkbox" value="legend" '.(isset($widget['widget_config']['legend']) && $widget['widget_config']['legend'] === 'no' ? '' : 'checked').' data-id="'.$widget['widget_id'].'">
</div>
</div>
</fieldset> <!-- END fieldset-body -->
<div class="modal-footer">
<fieldset>
<button id="close" name="close" type="submit" class="btn btn-default text-nowrap" value="" data-dismiss="modal" aria-hidden="true">Close</button>
<!-- <button id="action" name="action" type="submit" class="btn btn-primary text-nowrap" value="add_contact"><i style="margin-right: 0px;" class="icon-ok icon-white"></i>&nbsp;&nbsp;Add Contact</button> -->
</fieldset>
</div>
<div class="modal-footer">
<fieldset>
<button id="close" name="close" type="submit" class="btn btn-default text-nowrap" value="" data-dismiss="modal" aria-hidden="true">Close</button>
<!-- <button id="action" name="action" type="submit" class="btn btn-primary text-nowrap" value="add_contact"><i style="margin-right: 0px;" class="icon-ok icon-white"></i>&nbsp;&nbsp;Add Contact</button> -->
</fieldset>
</div>
</form>';
*/
</form>';
*/
} else {
} else {
print_message('To add a graph to this widget, navigate to the required graph and use the "Add To Dashboard" function on the graph page.');
print_message('To add a graph to this widget, navigate to the required graph and use the "Add To Dashboard" function on the graph page.');
echo '<h3>Step 1. Locate Graph and click for Graph Browser.</h3>';
echo '<img class="img img-thumbnail" src="images/doc/add_graph_1">';
echo '<h3>Step 1. Locate Graph and click for Graph Browser.</h3>';
echo '<img class="img img-thumbnail" src="images/doc/add_graph_1">';
echo '<h3>Step 2. Select Add to Dashboard in Graph Browser.</h3>';
echo '<img class="img" src="images/doc/add_graph_2">';
}
break;
default:
print_vars($widget);
echo '<h3>Step 2. Select Add to Dashboard in Graph Browser.</h3>';
echo '<img class="img" src="images/doc/add_graph_2">';
}
break;
default:
r($widget['widget_config']);
}
// EOF

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage ajax
* @copyright (C) Adam Armstrong
*
*/
@ -15,15 +15,14 @@ $update_ports = [];
//r($vars);
//$ports_attribs = get_device_entities_attribs($device_id, 'port'); // Get all attribs
foreach($vars['port'] as $port_id => $port_data)
{
foreach ($vars['port'] as $port_id => $port_data) {
if (is_entity_write_permitted('port', $port_id)) {
$port = get_port_by_id_cache($port_id);
$port = get_port_by_id_cache($port_id);
$device = device_by_id_cache($port['device_id']);
$updated = FALSE;
$update_array = array();
$updated = FALSE;
$update_array = [];
$port_attribs = get_entity_attribs('port', $port['port_id']);
@ -32,7 +31,7 @@ foreach($vars['port'] as $port_id => $port_data)
}
// Check ignored and disabled port
foreach (array('ignore', 'disabled') as $param) {
foreach (['ignore', 'disabled'] as $param) {
$old_param = $port[$param] ? 1 : 0;
$new_param = (isset($port_data[$param]) && $port_data[$param]) ? 1 : 0;
if ($old_param != $new_param) {
@ -41,7 +40,7 @@ foreach($vars['port'] as $port_id => $port_data)
}
if (count($update_array)) {
dbUpdate($update_array, 'ports', '`port_id` = ?', array($port_id));
dbUpdate($update_array, 'ports', '`port_id` = ?', [$port_id]);
$updated = TRUE;
}
@ -50,7 +49,7 @@ foreach($vars['port'] as $port_id => $port_data)
$old_ifSpeed_bool = isset($port['ifSpeed_custom']);
$new_ifSpeed_bool = isset($port_data['ifSpeed_custom_bool']) && $port_data['ifSpeed_custom_bool'];
if ($new_ifSpeed_bool) {
$port_data['ifSpeed_custom'] = (int) unit_string_to_numeric($port_data['ifSpeed_custom'], 1000);
$port_data['ifSpeed_custom'] = (int)unit_string_to_numeric($port_data['ifSpeed_custom'], 1000);
if ($port_data['ifSpeed_custom'] <= 0) {
// Wrong ifSpeed, skip
//print_warning("Passed incorrect value for port speed: ".unit_string_to_numeric($port_data['ifSpeed_custom'], 1000));
@ -65,7 +64,7 @@ foreach($vars['port'] as $port_id => $port_data)
//r($vars['ifSpeed_custom_' . $port_id]); r($port['ifSpeed_custom']);
set_entity_attrib('port', $port_id, 'ifSpeed_custom', $port_data['ifSpeed_custom'], $device['device_id']);
$update_array['ifSpeed_custom'] = $port_data['ifSpeed_custom'];
$updated = TRUE;
$updated = TRUE;
}
} elseif ($old_ifSpeed_bool !== $new_ifSpeed_bool) {
// Added or removed
@ -88,9 +87,9 @@ foreach($vars['port'] as $port_id => $port_data)
}
// Query updated sensors array
if ($rows_updated) {
print_json_status('ok', $rows_updated.' port(s) updated.', [ 'update_array' => $update_ports ]);
print_json_status('ok', $rows_updated . ' port(s) updated.', ['update_array' => $update_ports]);
} else {
print_json_status('failed', 'No update performed.');
print_json_status('failed', 'No update performed.');
}
unset($ports_attribs);

View File

@ -0,0 +1,35 @@
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
// Currently, allowed only for Admins
if (!$readwrite) {
print_json_status('failed', 'Insufficient permissions to delete role.');
return;
}
$role_id = (int)$vars['role_id'];
if ($role_id > 0) {
$rows_deleted = dbDelete('roles', '`role_id` = ?', [$role_id]);
//$rows_deleted = 0;
if ($rows_deleted > 0) {
dbDelete('roles_entity_permissions', '`role_id` = ?', [$role_id]);
dbDelete('roles_permissions', '`role_id` = ?', [$role_id]);
dbDelete('roles_users', '`role_id` = ?', [$role_id]);
print_json_status('ok', 'Role deleted successfully.', ['reload' => TRUE]);
} else {
print_json_status('failed', 'Failed to delete role.');
}
} else {
print_json_status('failed', 'Invalid role ID.');
}
// EOF

View File

@ -4,96 +4,96 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage ajax
* @copyright (C) Adam Armstrong
*
*/
$rows_updated = 0;
$rows_updated = 0;
$update_entities = [];
//r($vars);
foreach ($vars['sensors'] as $sensor_id => $sensor_update) {
$update_array = [];
if (is_entity_write_permitted('sensor', $sensor_id)) {
$update_array = [];
if (is_entity_write_permitted('sensor', $sensor_id)) {
$sensor = get_sensor_by_id($sensor_id);
$sensor = get_sensor_by_id($sensor_id);
$device_id = $sensor['device_id'];
$device_id = $sensor['device_id'];
if (!$sensor['sensor_state']) {
// Normal sensors
$fields_switch = [ 'sensor_ignore', 'sensor_custom_limit' ];
$fields_limit = [ 'sensor_limit', 'sensor_limit_warn', 'sensor_limit_low_warn', 'sensor_limit_low' ];
if (!$sensor['sensor_state']) {
// Normal sensors
$fields_switch = ['sensor_ignore', 'sensor_custom_limit'];
$fields_limit = ['sensor_limit', 'sensor_limit_warn', 'sensor_limit_low_warn', 'sensor_limit_low'];
} else {
// State sensors not allow edit limits
$fields_switch = array('sensor_ignore');
$fields_limit = array();
}
// Switch selectors
foreach ($fields_switch as $field) {
$sensor_update[$field] = get_var_true($sensor_update[$field]) ? '1' : '0';
if ($sensor_update[$field] != $sensor[$field]) {
$update_array[$field] = $sensor_update[$field];
}
}
// Limits
if ($sensor_update['sensor_reset_limit']) {
// Reset limits
if ($sensor['sensor_custom_limit']) {
$update_array['sensor_custom_limit'] = '0';
}
$update_array['sensor_limit_low'] = [ 'NULL' ];
$update_array['sensor_limit_low_warn'] = [ 'NULL' ];
$update_array['sensor_limit_warn'] = [ 'NULL' ];
$update_array['sensor_limit'] = [ 'NULL' ];
} elseif ($sensor_update['sensor_custom_limit']) {
foreach ($fields_limit as $field) {
$sensor_update[$field] = !is_numeric($sensor_update[$field]) ? [ 'NULL' ] : (float)$sensor_update[$field];
$sensor[$field] = !is_numeric($sensor[$field]) ? [ 'NULL' ] : (float)$sensor[$field];
if ($sensor_update[$field] !== $sensor[$field]) {
$update_array[$field] = $sensor_update[$field];
} else {
// State sensors not allow edit limits
$fields_switch = ['sensor_ignore'];
$fields_limit = [];
}
}
}
if (count($update_array)) {
dbUpdate($update_array, 'sensors', '`sensor_id` = ?', array($sensor['sensor_id']));
$msg = 'Sensor updated (custom): ' . $sensor['sensor_class'] . ' ' . $sensor['sensor_type'] . ' ' . $sensor['sensor_id'] . ' ' . escape_html($sensor['sensor_descr']) . ' ';
if ($update_array['sensor_limit_low']) {
$msg .= '[L: ' . $update_array['sensor_limit_low'] . ']';
}
if ($update_array['sensor_limit_low_warn']) {
$msg .= '[Lw: ' . $update_array['sensor_limit_low_warn'] . ']';
}
if ($update_array['sensor_limit_warn']) {
$msg .= '[Hw: ' . $update_array['sensor_limit_warn'] . ']';
}
if ($update_array['sensor_limit']) {
$msg .= '[H: ' . $update_array['sensor_limit'] . ']';
}
log_event($msg, $device_id, 'sensor', $sensor['sensor_id']);
$rows_updated++;
// Switch selectors
foreach ($fields_switch as $field) {
$sensor_update[$field] = get_var_true($sensor_update[$field]) ? '1' : '0';
if ($sensor_update[$field] != $sensor[$field]) {
$update_array[$field] = $sensor_update[$field];
}
}
$update_entities[$sensor_id] = $update_array;
}
// Limits
if ($sensor_update['sensor_reset_limit']) {
// Reset limits
if ($sensor['sensor_custom_limit']) {
$update_array['sensor_custom_limit'] = '0';
}
$update_array['sensor_limit_low'] = ['NULL'];
$update_array['sensor_limit_low_warn'] = ['NULL'];
$update_array['sensor_limit_warn'] = ['NULL'];
$update_array['sensor_limit'] = ['NULL'];
} elseif ($sensor_update['sensor_custom_limit']) {
foreach ($fields_limit as $field) {
$sensor_update[$field] = !is_numeric($sensor_update[$field]) ? ['NULL'] : (float)$sensor_update[$field];
$sensor[$field] = !is_numeric($sensor[$field]) ? ['NULL'] : (float)$sensor[$field];
if ($sensor_update[$field] !== $sensor[$field]) {
$update_array[$field] = $sensor_update[$field];
}
}
}
unset($update_array);
if (count($update_array)) {
dbUpdate($update_array, 'sensors', '`sensor_id` = ?', [$sensor['sensor_id']]);
$msg = 'Sensor updated (custom): ' . $sensor['sensor_class'] . ' ' . $sensor['sensor_type'] . ' ' . $sensor['sensor_id'] . ' ' . escape_html($sensor['sensor_descr']) . ' ';
if ($update_array['sensor_limit_low']) {
$msg .= '[L: ' . $update_array['sensor_limit_low'] . ']';
}
if ($update_array['sensor_limit_low_warn']) {
$msg .= '[Lw: ' . $update_array['sensor_limit_low_warn'] . ']';
}
if ($update_array['sensor_limit_warn']) {
$msg .= '[Hw: ' . $update_array['sensor_limit_warn'] . ']';
}
if ($update_array['sensor_limit']) {
$msg .= '[H: ' . $update_array['sensor_limit'] . ']';
}
log_event($msg, $device_id, 'sensor', $sensor['sensor_id']);
$rows_updated++;
} // End write permission check
$update_entities[$sensor_id] = $update_array;
}
unset($update_array);
} // End write permission check
} // end sensors loop
// Query updated sensors array
if ($rows_updated) {
print_json_status('ok', $rows_updated.' sensor(s) updated.', [ 'update_array' => $update_entities ]);
print_json_status('ok', $rows_updated . ' sensor(s) updated.', ['update_array' => $update_entities]);
} else {
print_json_status('failed', 'No update performed.');
print_json_status('failed', 'No update performed.');
}
// EOF

View File

@ -4,9 +4,9 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
@ -14,46 +14,46 @@
// Allowed only for authenticated
if (!$_SESSION['authenticated'] || $_SESSION['user_id'] != $vars['user_id']) {
print_json_status('failed', "Unauthenticated");
//print_json_status('failed', var_export($vars, TRUE));
return;
print_json_status('failed', "Unauthenticated");
//print_json_status('failed', var_export($vars, TRUE));
return;
}
$user_id = $_SESSION['user_id'];
foreach (process_sql_vars($vars) as $param => $entry) {
// This sets:
// $deletes = array();
// $sets = array();
// $errors = array();
// $set_attribs = array(); // set obs_attribs
$$param = $entry;
// This sets:
// $deletes = array();
// $sets = array();
// $errors = array();
// $set_attribs = array(); // set obs_attribs
$$param = $entry;
}
$updates = 0;
// Set fields that were submitted with custom value
if (safe_count($sets)) {
$query = 'SELECT * FROM `users_prefs` WHERE `user_id` = ?' . generate_query_values_and(array_keys($sets), 'pref');
// Fetch current rows in config file so we know which one to UPDATE and which one to INSERT
$in_db = [];
foreach (dbFetchRows($query, [ $user_id ]) as $row) {
$in_db[$row['pref']] = $row['value'];
}
foreach ($sets as $key => $value) {
$serialize = serialize($value);
if (!isset($in_db[$key]) || $serialize !== $in_db[$key]) {
set_user_pref($user_id, $key, $serialize);
$updates++;
$query = 'SELECT * FROM `users_prefs` WHERE `user_id` = ?' . generate_query_values_and(array_keys($sets), 'pref');
// Fetch current rows in config file so we know which one to UPDATE and which one to INSERT
$in_db = [];
foreach (dbFetchRows($query, [$user_id]) as $row) {
$in_db[$row['pref']] = $row['value'];
}
foreach ($sets as $key => $value) {
$serialize = serialize($value);
if (!isset($in_db[$key]) || $serialize !== $in_db[$key]) {
set_user_pref($user_id, $key, $serialize);
$updates++;
}
}
}
}
// Delete fields that were reset to default
if (safe_count($deletes)) {
dbDelete('users_prefs', '`user_id` = ? ' . generate_query_values_and($deletes, 'pref'), [ $user_id ]);
$updates++;
dbDelete('users_prefs', '`user_id` = ? ' . generate_query_values_and($deletes, 'pref'), [$user_id]);
$updates++;
}
/*
@ -64,19 +64,19 @@ foreach ($set_attribs as $attrib => $value) {
}
*/
if ($updates) {
$status = 'ok';
$message = "Settings updated. Please note Web UI setting takes effect only after reload the page.";
$status = 'ok';
$message = "Settings updated. Please note Web UI setting takes effect only after reload the page.";
if (safe_count($errors)) {
$status = 'warning';
$message .= ' Errors: ' . implode('; ', $errors) . '.';
}
print_json_status($status, $message, [ 'reload' => TRUE ]);
if (safe_count($errors)) {
$status = 'warning';
$message .= ' Errors: ' . implode('; ', $errors) . '.';
}
print_json_status($status, $message, ['reload' => TRUE]);
} elseif (safe_count($errors)) {
$status = 'failed';
$message = 'Errors: ' . implode('; ', $errors) . '.';
print_json_status($status, $message);
$status = 'failed';
$message = 'Errors: ' . implode('; ', $errors) . '.';
print_json_status($status, $message);
}
//process_sql_vars($vars);

View File

@ -4,63 +4,63 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage web
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
* @package observium
* @subpackage web
* @copyright (C) Adam Armstrong
*
*/
switch (str_replace('->', '|', $vars['setting'])) {
case "theme":
case "web_theme_default":
$pref = 'web_theme_default';
if ($vars['value'] === 'reset') {
session_unset_var("theme");
if ($config['web_theme_default'] === 'system') {
// Override default
session_unset_var("theme_default");
}
case "theme":
case "web_theme_default":
$pref = 'web_theme_default';
if ($vars['value'] === 'reset') {
session_unset_var("theme");
if ($config['web_theme_default'] === 'system') {
// Override default
session_unset_var("theme_default");
}
if (del_user_pref($_SESSION['user_id'], $pref)) {
print_json_status('ok', 'Theme reset.');
}
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
print_json_status('ok', 'Theme set.');
}
} else {
print_json_status('failed', 'Invalid theme.');
}
break;
if (del_user_pref($_SESSION['user_id'], $pref)) {
print_json_status('ok', 'Theme reset.');
}
} elseif (isset($config['themes'][$vars['value']]) || $vars['value'] === 'system') {
if (set_user_pref($_SESSION['user_id'], $pref, serialize($vars['value']))) {
print_json_status('ok', 'Theme set.');
}
} else {
print_json_status('failed', 'Invalid theme.');
}
break;
case "big_graphs":
$pref = 'graphs|size';
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
print_json_status('ok', 'Big graphs set.');
session_unset_var("big_graphs"); // clear old
}
//session_set_var("big_graphs", TRUE);
//print_json_status('ok', 'Big graphs set.');
break;
case "big_graphs":
$pref = 'graphs|size';
if (set_user_pref($_SESSION['user_id'], $pref, serialize('big'))) {
print_json_status('ok', 'Big graphs set.');
session_unset_var("big_graphs"); // clear old
}
//session_set_var("big_graphs", TRUE);
//print_json_status('ok', 'Big graphs set.');
break;
case "normal_graphs":
$pref = 'graphs|size';
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
print_json_status('ok', 'Normal graphs set.');
session_unset_var("big_graphs"); // clear old
}
//session_unset_var("big_graphs");
//print_json_status('ok', 'Small graphs set.');
break;
case "normal_graphs":
$pref = 'graphs|size';
if (set_user_pref($_SESSION['user_id'], $pref, serialize('normal'))) {
print_json_status('ok', 'Normal graphs set.');
session_unset_var("big_graphs"); // clear old
}
//session_unset_var("big_graphs");
//print_json_status('ok', 'Small graphs set.');
break;
case "sensors|web_measured_compact":
// BOOL values
$pref = $vars['setting'];
if (set_user_pref($_SESSION['user_id'], $pref, serialize(get_var_true($vars['value'])))) {
print_json_status('ok', 'Setting was set.', [ 'reload' => TRUE ]);
}
break;
case "sensors|web_measured_compact":
// BOOL values
$pref = $vars['setting'];
if (set_user_pref($_SESSION['user_id'], $pref, serialize(get_var_true($vars['value'])))) {
print_json_status('ok', 'Setting was set.', ['reload' => TRUE]);
}
break;
}
// EOF

View File

@ -4,55 +4,55 @@
*
* This file is part of Observium.
*
* @package observium
* @subpackage ajax
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2021 Observium Limited
* @package observium
* @subpackage ajax
* @copyright (C) Adam Armstrong
*
*/
$rows_updated = 0;
$rows_updated = 0;
$update_entities = [];
//r($vars);
foreach ($vars['status'] as $status_id => $status_update) {
$update_array = [];
if(is_entity_write_permitted('status', $status_id)) {
$status = get_status_by_id($status_id);
$update_array = [];
if (is_entity_write_permitted('status', $status_id)) {
$status = get_status_by_id($status_id);
$device_id = $status['device_id'];
$device_id = $status['device_id'];
$fields_switch = array('status_ignore');
$fields_limit = array();
$fields_switch = ['status_ignore'];
$fields_limit = [];
// Switch selectors
foreach ($fields_switch as $field) {
$status_update[$field] = get_var_true($status_update[$field]) ? '1' : '0';
if ($status_update[$field] != $status[$field]) {
$update_array[$field] = $status_update[$field];
}
}
// Switch selectors
foreach ($fields_switch as $field) {
$status_update[$field] = get_var_true($status_update[$field]) ? '1' : '0';
if ($status_update[$field] != $status[$field]) {
$update_array[$field] = $status_update[$field];
}
}
if (count($update_array)) {
dbUpdate($update_array, 'status', '`status_id` = ?', array($status['status_id']));
$msg = 'Status updated (custom): ' . $status['status_type'] . ' ' . $status['status_id'] . ' ' . escape_html($status['status_descr']) . ' ';
log_event($msg, $device_id, 'status', $status['status_id']);
$rows_updated++;
if (count($update_array)) {
dbUpdate($update_array, 'status', '`status_id` = ?', [$status['status_id']]);
$msg = 'Status updated (custom): ' . $status['status_type'] . ' ' . $status['status_id'] . ' ' . escape_html($status['status_descr']) . ' ';
log_event($msg, $device_id, 'status', $status['status_id']);
$rows_updated++;
$update_entities[$status_id] = $update_array;
}
$update_entities[$status_id] = $update_array;
}
unset($update_array);
unset($update_array);
} // End write permission check
} // End write permission check
} // end entity loop
// Query updated array
if ($rows_updated) {
print_json_status('ok', $rows_updated.' status(es) updated.', [ 'update_array' => $update_entities ]);
print_json_status('ok', $rows_updated . ' status(es) updated.', ['update_array' => $update_entities]);
} else {
print_json_status('failed', 'No update performed.');
print_json_status('failed', 'No update performed.');
}
// EOF