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:
38
config.ini
38
config.ini
@@ -5,6 +5,15 @@ default_language = English_United_States
|
||||
log_type = SYSLOG ; SYSLOG|STDERR|STDOUT|NULL|FILE
|
||||
log_level = LOG_INFO ; LOG_EMERG|LOG_ALERT|LOG_CRIT|LOG_ERR|LOG_WARNING|LOG_NOTICE|LOG_INFO|LOG_DEBUG
|
||||
;log_filename = provision.log ; only in case of log_type = FILE
|
||||
auto_generate_settings = FALSE
|
||||
auto_sign = FALSE
|
||||
auto_encrypt = FALSE
|
||||
|
||||
[security]
|
||||
cert_ca =
|
||||
cert_priv =
|
||||
cert_pub =
|
||||
hash =
|
||||
|
||||
[subdirs]
|
||||
tftproot = tftpboot
|
||||
@@ -15,3 +24,32 @@ ringtones = ringtones
|
||||
locales = locales
|
||||
countries = countries
|
||||
languages = languages
|
||||
|
||||
[settings]
|
||||
sshUserId = cisco
|
||||
sshPassword = cisco
|
||||
ipAddress = ipv4|ipv6 ; ipv4 | ipv4 | ipv4|ipv6 | ipv6|ipv4
|
||||
datetime.template=M/D/YA
|
||||
datetime.timezone=W. Europe Standard/Daylight Time
|
||||
datetime.ipaddress=10.x.x.x
|
||||
datetime.mode=Unicast
|
||||
members.myhost.hostname = myhost.domain.com
|
||||
members.myhost.ipv4 = 10.x.x.x
|
||||
members.myhost.ipv6 = 2001:470::x:x
|
||||
members.myhost.port = 2000
|
||||
;srts.
|
||||
;common.
|
||||
;vendor.
|
||||
locale.country=United_States
|
||||
locale.language=English_United_States
|
||||
locale.langcode=en_US
|
||||
locale.charset=utf-8
|
||||
urls.secury = FALSE
|
||||
urls.information=
|
||||
urls.authentication=
|
||||
urls.services=
|
||||
urls.direcory=
|
||||
urls.messages=
|
||||
urls.proxyserver=
|
||||
;vpn.
|
||||
;phoneservices.
|
||||
|
@@ -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