mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
updating to f0os function
This commit is contained in:
@ -13,82 +13,35 @@ if (!$database_link)
|
|||||||
}
|
}
|
||||||
$database_db = mysql_select_db($config['db_name'], $database_link);
|
$database_db = mysql_select_db($config['db_name'], $database_link);
|
||||||
|
|
||||||
function create_array(&$arr,$string,$data,$type)
|
function mergecnf($obj) {
|
||||||
{
|
global $config;
|
||||||
// The original source of this code is from Stackoverflow (www.stackoverflow.com).
|
$val = $obj['config_value'];
|
||||||
// http://stackoverflow.com/questions/9145902/create-variable-length-array-from-string
|
$obj = $obj['config_name'];
|
||||||
// Answer provided by stewe (http://stackoverflow.com/users/511300/stewe)
|
$obj = explode('.',$obj);
|
||||||
// This code is slightly adapted from the original posting.
|
$str = "";
|
||||||
|
foreach ($obj as $sub) {
|
||||||
$a=explode(',',$string);
|
if (!empty($sub)) {
|
||||||
$last=count($a)-1;
|
$str .= "['".addslashes($sub)."']";
|
||||||
$p=&$arr;
|
} else {
|
||||||
|
$str .= "[]";
|
||||||
foreach($a as $k=>$key)
|
|
||||||
{
|
|
||||||
if ($k==$last)
|
|
||||||
{
|
|
||||||
if($type == 'multi')
|
|
||||||
{
|
|
||||||
if (!isset($p[$key])) {
|
|
||||||
$p[$key]=explode(',',$data);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
elseif($type == 'single')
|
|
||||||
{
|
|
||||||
if (!isset($p[$key])) {
|
|
||||||
$p[$key]=$data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (is_array($p))
|
$str = '$config'.$str.' = ';
|
||||||
{
|
if (filter_var($val,FILTER_VALIDATE_INT)) {
|
||||||
// $p[$key]=array();
|
$str .= "(int) '$val';";
|
||||||
|
} elseif (filter_var($val,FILTER_VALIDATE_FLOAT)) {
|
||||||
|
$str .= "(float) '$val';";
|
||||||
|
} elseif (filter_var($val,FILTER_VALIDATE_BOOLEAN)) {
|
||||||
|
$str .= "(boolean) '$val';";
|
||||||
|
} else {
|
||||||
|
$str .= "'$val';";
|
||||||
}
|
}
|
||||||
$p=&$p[$key];
|
eval('return array('.$str.')');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should be able to get config values from the DB now.
|
foreach( dbFetchRows('select config_name,config_value from config') as $obj ) {
|
||||||
// Single field config values
|
$config = array_merge_recursive($config,mergecnf($obj));
|
||||||
$config_vars = get_defined_vars();
|
|
||||||
$single_config = dbFetchRows("SELECT `config_name`, `config_value` FROM `config` WHERE `config_type` = 'single' AND `config_disabled` = '0'");
|
|
||||||
foreach ($single_config as $config_data)
|
|
||||||
{
|
|
||||||
$tmp_name = $config_data['config_name'];
|
|
||||||
if(!isset($config[$tmp_name]))
|
|
||||||
{
|
|
||||||
$config[$tmp_name] = stripslashes($config_data['config_value']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Array config values
|
|
||||||
$config_vars = get_defined_vars();
|
|
||||||
$array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'array' AND `config_disabled` = '0' GROUP BY config_name");
|
|
||||||
foreach ($array_config as $config_data)
|
|
||||||
{
|
|
||||||
$tmp_name = $config_data['config_name'];
|
|
||||||
if(!isset($config[$tmp_name]))
|
|
||||||
{
|
|
||||||
$config[$tmp_name] = explode(',',stripslashes($config_data['config_value']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multi-array config values
|
|
||||||
$config_vars = get_defined_vars();
|
|
||||||
$multi_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'multi-array' AND `config_disabled` = '0' GROUP BY config_name");
|
|
||||||
foreach ($multi_array_config as $config_data)
|
|
||||||
{
|
|
||||||
create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'multi');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single-array config values
|
|
||||||
$config_vars = get_defined_vars();
|
|
||||||
$single_array_config = dbFetchRows("SELECT `config_name`, GROUP_CONCAT( `config_value` ) AS `config_value` FROM `config` WHERE `config_type` = 'single-array' AND `config_disabled` = '0' GROUP BY config_name");
|
|
||||||
foreach ($single_array_config as $config_data)
|
|
||||||
{
|
|
||||||
create_array($config,$config_data['config_name'],stripslashes($config_data['config_value']),'single');
|
|
||||||
}
|
|
||||||
unset($config_vars);
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
# NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE #
|
# NO CHANGES TO THIS FILE, IT IS NOT USER-EDITABLE #
|
||||||
|
@ -28,6 +28,7 @@ include_once($config['install_dir'] . "/includes/syslog.php");
|
|||||||
include_once($config['install_dir'] . "/includes/rewrites.php");
|
include_once($config['install_dir'] . "/includes/rewrites.php");
|
||||||
include_once($config['install_dir'] . "/includes/snmp.inc.php");
|
include_once($config['install_dir'] . "/includes/snmp.inc.php");
|
||||||
include_once($config['install_dir'] . "/includes/services.inc.php");
|
include_once($config['install_dir'] . "/includes/services.inc.php");
|
||||||
|
echo $config['install_dir'] . "/includes/console_colour.php";
|
||||||
include_once($config['install_dir'] . "/includes/console_colour.php");
|
include_once($config['install_dir'] . "/includes/console_colour.php");
|
||||||
|
|
||||||
$console_color = new Console_Color2();
|
$console_color = new Console_Color2();
|
||||||
|
Reference in New Issue
Block a user