mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Store config data serialized (#10651)
* Store config data serialized This way we can store null, booleans, and more reliably. * Use model to get the mutated output. * fix whitespace and unused function * use json_encode/decode and casts migration to transfer * json_encode JSON_UNESCAPED_SLASHES * Use JSON_UNESCAPED_SLASHES. That is only relevant if you are printing into an HTML page. * pre-encode the seed... * filter other fields besides config_value
This commit is contained in:
@@ -25,7 +25,7 @@ if (!is_numeric($_POST['config_id']) || empty($_POST['data'])) {
|
||||
exit;
|
||||
} else {
|
||||
$data = mres($_POST['data']);
|
||||
$update = dbUpdate(array('config_value' => "$data"), 'config', '`config_id` = ?', array($_POST['config_id']));
|
||||
$update = dbUpdate(array('config_value' => json_encode($data, JSON_UNESCAPED_SLASHES)), 'config', '`config_id` = ?', array($_POST['config_id']));
|
||||
if (!empty($update) || $update == '0') {
|
||||
echo 'success';
|
||||
exit;
|
||||
|
@@ -83,8 +83,16 @@ if (!is_numeric($config_id)) {
|
||||
$message = 'Config item has been updated:';
|
||||
$status = 'ok';
|
||||
} else {
|
||||
$state = mres($_POST['config_value']);
|
||||
$update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($config_id));
|
||||
$state = $_POST['config_value'];
|
||||
if (filter_var($value, FILTER_VALIDATE_INT)) {
|
||||
$state = (int)$value;
|
||||
} elseif (filter_var($value, FILTER_VALIDATE_FLOAT)) {
|
||||
$state = (float)$value;
|
||||
} elseif (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) {
|
||||
$state = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
$update = dbUpdate(['config_value' => json_encode($state, JSON_UNESCAPED_SLASHES)], 'config', '`config_id`=?', array($config_id));
|
||||
if (!empty($update) || $update == '0') {
|
||||
$message = 'Alert rule has been updated.';
|
||||
$status = 'ok';
|
||||
|
@@ -917,52 +917,15 @@ function clean_bootgrid($string)
|
||||
|
||||
function get_config_by_group($group)
|
||||
{
|
||||
$items = array();
|
||||
foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_group` = ?", array($group)) as $config_item) {
|
||||
$val = $config_item['config_value'];
|
||||
if (filter_var($val, FILTER_VALIDATE_INT)) {
|
||||
$val = (int)$val;
|
||||
} elseif (filter_var($val, FILTER_VALIDATE_FLOAT)) {
|
||||
$val = (float)$val;
|
||||
} elseif (filter_var($val, FILTER_VALIDATE_BOOLEAN)) {
|
||||
$val = (boolean)$val;
|
||||
return \App\Models\Config::query()->where('config_group', $group)->get()->map(function ($config_item) {
|
||||
if ($config_item['config_value'] === true) {
|
||||
$config_item['config_checked'] = 'checked';
|
||||
}
|
||||
|
||||
if ($val === true) {
|
||||
$config_item += array('config_checked' => 'checked');
|
||||
}
|
||||
|
||||
$items[$config_item['config_name']] = $config_item;
|
||||
}
|
||||
|
||||
return $items;
|
||||
return $config_item;
|
||||
})->keyBy('config_name')->toArray();
|
||||
}//end get_config_by_group()
|
||||
|
||||
|
||||
function get_config_like_name($name)
|
||||
{
|
||||
$items = array();
|
||||
foreach (dbFetchRows("SELECT * FROM `config` WHERE `config_name` LIKE ?", array("%$name%")) as $config_item) {
|
||||
$items[$config_item['config_id']] = $config_item;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}//end get_config_like_name()
|
||||
|
||||
|
||||
function get_config_by_name($name)
|
||||
{
|
||||
$config_item = dbFetchRow('SELECT * FROM `config` WHERE `config_name` = ?', array($name));
|
||||
return $config_item;
|
||||
}//end get_config_by_name()
|
||||
|
||||
|
||||
function set_config_name($name, $config_value)
|
||||
{
|
||||
return dbUpdate(array('config_value' => $config_value), 'config', '`config_name`=?', array($name));
|
||||
}//end set_config_name()
|
||||
|
||||
|
||||
function get_url()
|
||||
{
|
||||
// http://stackoverflow.com/questions/2820723/how-to-get-base-url-with-php
|
||||
|
Reference in New Issue
Block a user