Files
provision_sccp/lib/utils.php
Diederik de Groot 7aa4524b19 - Copied github.com/tm1000/tftpserver/tftpserver.php over to lib/tftpserver.php
- Replaced logging functions with lib/logger.php
- 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
- Added simple test implementation of tftpserver
- Renamed lib/tftpserver.php to lib/tftp.php
- Fixed error output from lib/tftp.php
- Note: current simple tftpserver.php test implementation stores/read files
- from memory (not fs). So you need to put a file, before you can get that
  file back.
- Cleanup some small config details
- First simple implementation of tftp_provisioner.php
2020-03-17 12:16:26 +01:00

54 lines
1.5 KiB
PHP

<?php
//
// Helper functions
//
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;
}
?>