First step for adding templated settings/file where placeholders can be filled out.
Add 'settings' structure to config.ini Add 'settings' multidimensional config parser to lib/utils.php Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
include_once("logger.php");
|
||||
include_once("utils.php");
|
||||
|
||||
$base_path = !empty($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT'] . "/../"): realpath(getcwd()."/../");
|
||||
$base_config = Array(
|
||||
@@ -18,6 +19,46 @@ $base_config = Array(
|
||||
'locales' => 'locales',
|
||||
'countries' => 'countries',
|
||||
'languages' => 'languages',
|
||||
),
|
||||
'security' => Array(
|
||||
'cert_ca' => null,
|
||||
'cert_priv' => null,
|
||||
'cert_pub' => null,
|
||||
'hash' => null,
|
||||
),
|
||||
'settings' => Array(
|
||||
'sshUserId' => 'cisco',
|
||||
'sshPassword' => 'cisco',
|
||||
'ipAddress' => '0',
|
||||
'datetime' => Array(
|
||||
'template' => 'M/D/YA',
|
||||
'timezone' => 'W. Europe Standard/Daylight Time',
|
||||
'ipaddress' => '10.x.x.x',
|
||||
'mode' => 'Unicast',
|
||||
),
|
||||
'members' => Array(
|
||||
'myhost' => Array(
|
||||
'hostname' => 'myhost.domain.com',
|
||||
'ipv4' => '10.x.x.x',
|
||||
'ipv6' => '2001:470::x:x',
|
||||
'port' => '2000',
|
||||
)
|
||||
),
|
||||
'locale' => Array(
|
||||
'country' => 'United_States',
|
||||
'language' => 'English_United_States',
|
||||
'langcode' => 'en_US',
|
||||
'charset' => 'utf-8',
|
||||
),
|
||||
'urls' => Array(
|
||||
'secury' => '',
|
||||
'information' => '',
|
||||
'authentication' => '',
|
||||
'services' => '',
|
||||
'direcory' => '',
|
||||
'messages' => '',
|
||||
'proxyserver' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
$tree_base = Array(
|
||||
@@ -32,7 +73,8 @@ $tree_base = Array(
|
||||
);
|
||||
|
||||
# Merge config
|
||||
$ini_array = parse_ini_file('../config.ini', TRUE, INI_SCANNER_TYPED);
|
||||
//$ini_array = parse_ini_file("$base_path/config.ini", TRUE, INI_SCANNER_TYPED);
|
||||
$ini_array = parse_ini_file_multi("$base_path/config.ini", TRUE, INI_SCANNER_TYPED);
|
||||
if (!empty($ini_array)) {
|
||||
$config = array_merge($base_config, $ini_array);
|
||||
}
|
||||
@@ -77,4 +119,10 @@ switch($config['main']['log_type']) {
|
||||
# Fixup debug
|
||||
$print_debug = (!empty($config['main']['debug'])) ? $config['main']['debug'] : 'off';
|
||||
$print_debug = ($print_debug == 1) ? 'on' : $print_debug;
|
||||
|
||||
if(defined('STDIN') ) {
|
||||
print_r($config);
|
||||
//var_dump($config);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -7,4 +7,47 @@ function utf8_urldecode($str) {
|
||||
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
|
||||
return html_entity_decode($str,null,'UTF-8');;
|
||||
}
|
||||
|
||||
function parse_ini_file_multi($file, $process_sections = false, $scanner_mode = INI_SCANNER_NORMAL) {
|
||||
$explode_str = '.';
|
||||
$escape_char = "'";
|
||||
// load ini file the normal way
|
||||
$data = parse_ini_file($file, $process_sections, $scanner_mode);
|
||||
if (!$process_sections) {
|
||||
$data = array($data);
|
||||
}
|
||||
foreach ($data as $section_key => $section) {
|
||||
// loop inside the section
|
||||
foreach ($section as $key => $value) {
|
||||
if (strpos($key, $explode_str)) {
|
||||
if (substr($key, 0, 1) !== $escape_char) {
|
||||
// key has a dot. Explode on it, then parse each subkeys
|
||||
// and set value at the right place thanks to references
|
||||
$sub_keys = explode($explode_str, $key);
|
||||
$subs =& $data[$section_key];
|
||||
foreach ($sub_keys as $sub_key) {
|
||||
if (!isset($subs[$sub_key])) {
|
||||
$subs[$sub_key] = [];
|
||||
}
|
||||
$subs =& $subs[$sub_key];
|
||||
}
|
||||
// set the value at the right place
|
||||
$subs = $value;
|
||||
// unset the dotted key, we don't need it anymore
|
||||
unset($data[$section_key][$key]);
|
||||
}
|
||||
// we have escaped the key, so we keep dots as they are
|
||||
else {
|
||||
$new_key = trim($key, $escape_char);
|
||||
$data[$section_key][$new_key] = $value;
|
||||
unset($data[$section_key][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$process_sections) {
|
||||
$data = $data[0];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user