Files
provision_sccp/lib/config.php
Diederik de Groot a4ebaee776 Initial checkin of resolver.php
- use \\ instead of just \ in FileName
- Use file_put_contents instead of open/write
- Use file_exist instead of stat
- Added /lib directory
- Moved /tftpboot/index.cfg -> /config.ini
- Moved /tftpboot/resolver.php -> /lib/resolver.php
- Added /lib/config.php
  - include /lib/config.php in resolver.php and index.php
- Changed $config array
- Remove print_r($config['main']['base_path']) from config.php
- Add isValidRequest() function
- Use Boolean in tree_base data
- Simplify config['subdirs'] substitution
- Add lib/utils.php file
- Added simple shell/utf/html escape checking
- Added a collection of test cases (we need some more escape checking ones)
- Added lib/logger.php (copied from tftpserver.php, so that it can be reused for that).
- Clarify config.ini logformat
- Update logger implementation
- Replaced index.php with version that uses lib/resolver.php
- Replaced ../etc/nginx/sites-available/tftpboot Example file
2020-03-17 10:03:55 +01:00

81 lines
2.6 KiB
PHP

<?php
include_once("logger.php");
$base_path = !empty($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT'] . "/../"): realpath(getcwd()."/../");
$base_config = Array(
'main' => Array(
'debug' => 1,
'default_language' => 'English_United_States',
'log_type' => "NULL",
'log_level' => LOG_EMERG
),
'subdirs' => Array(
'tftproot' => 'tftpboot',
'firmware' => 'firmware',
'settings' => 'settings',
'wallpapers' => 'wallpapers',
'ringtones' => 'ringtones',
'locales' => 'locales',
'countries' => 'countries',
'languages' => 'languages',
)
);
$tree_base = Array(
'settings' => array('path' => 'tftproot', "strip" => TRUE),
'wallpapers' => array('path' => 'tftproot', "strip" => FALSE),
'ringtones' => array('path' => 'tftproot', "strip" => TRUE),
'locales' => array('path' => 'tftproot', "strip" => TRUE),
'firmware' => array('path' => 'tftproot', "strip" => TRUE),
'languages' => array('path' => 'locales', "strip" => FALSE),
'countries' => array('path' => 'locales', "strip" => FALSE),
'default_language' => array('path' => 'locales', "strip" => TRUE),
);
# Merge config
$ini_array = parse_ini_file('../config.ini', TRUE, INI_SCANNER_TYPED);
if (!empty($ini_array)) {
$config = array_merge($base_config, $ini_array);
}
# build new config['subdirs'] paths substituting bases from tree_base
foreach ($tree_base as $key => $value) {
$tmp = $config;
if (!empty($tmp['subdirs'][$key])) {
if (substr($tmp['subdirs'][$key], 0, 1) !== "/") {
if (is_array($tmp['subdirs'][$value['path']])) {
$path = $tmp['subdirs'][$value['path']]['path'].'/'.$tmp['subdirs'][$key];
} else {
$path = $tmp['subdirs'][$value['path']].'/'.$tmp['subdirs'][$key];
}
}
$config['subdirs'][$key] = array('path' => $path, 'strip' => $value['strip']);
}
}
$config['main']['base_path'] = $base_path;
$config['main']['tftproot'] = (!empty($config['main']['tftproot'])) ? $base_path . "tftpboot" : '/tftpboot';
switch($config['main']['log_type']) {
case 'SYSLOG':
$logger = new Logger_Syslog($config['main']['log_level']);
break;
case 'FILE':
if (!isempty($config['main']['log_file'])) {
$logger = new Logger_Filename($config['main']['log_level'], $config['main']['log_file']);
}
break;
case 'STDOUT':
$logger = new Logger_Stdout($config['main']['log_level']);
break;
case 'STDERR':
$logger = new Logger_Stderr($config['main']['log_level']);
break;
default:
$logger = new Logger_Null($config['main']['log_level']);
}
# Fixup debug
$print_debug = (!empty($config['main']['debug'])) ? $config['main']['debug'] : 'off';
$print_debug = ($print_debug == 1) ? 'on' : $print_debug;
?>