fix conf.d loading in api

This commit is contained in:
Isaac Connor 2017-07-14 11:46:36 -04:00
parent b3984ea2da
commit 9824049c0c
1 changed files with 45 additions and 28 deletions

View File

@ -101,49 +101,66 @@ CakeLog::config('debug', array(
'engine' => 'File', 'engine' => 'File',
'types' => array('notice', 'info', 'debug'), 'types' => array('notice', 'info', 'debug'),
'file' => 'cake_debug', 'file' => 'cake_debug',
'path' => '@ZM_LOGDIR@/'
)); ));
CakeLog::config('error', array( CakeLog::config('error', array(
'engine' => 'File', 'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'cake_error', 'file' => 'cake_error',
'path' => '@ZM_LOGDIR@/'
)); ));
CakeLog::config('custom_path', array( CakeLog::config('custom_path', array(
'engine' => 'File', 'engine' => 'File',
'path' => '@ZM_LOGDIR@' 'path' => '@ZM_LOGDIR@/'
)); ));
Configure::write('ZM_CONFIG', '@ZM_CONFIG@'); Configure::write('ZM_CONFIG', '@ZM_CONFIG@');
Configure::write('ZM_CONFIG_SUBDIR', '@ZM_CONFIG_SUBDIR@');
Configure::write('ZM_VERSION', '@VERSION@'); Configure::write('ZM_VERSION', '@VERSION@');
Configure::write('ZM_API_VERSION', '@API_VERSION@'); Configure::write('ZM_API_VERSION', '@API_VERSION@');
loadConfigFile(); # Process name, value pairs from the main config file first
$configvals = process_configfile(Configure::read('ZM_CONFIG'));
function loadConfigFile() { # Search for user created config files. If one or more are found then
$configFile = Configure::read('ZM_CONFIG'); # update our config value array with those values
$localConfigFile = basename($configFile); $configSubFolder = Configure::read('ZM_CONFIG_SUBDIR');
if ( file_exists( $localConfigFile ) && filesize( $localConfigFile ) > 0 ) if ( is_dir($configSubFolder) ) {
{ if ( is_readable($configSubFolder) ) {
if ( php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) ) foreach ( glob("$configSubFolder/*.conf") as $filename ) {
print( "Warning, overriding installed $localConfigFile file with local copy\n" ); $configvals = array_replace($configvals, process_configfile($filename) );
else }
error_log( "Warning, overriding installed $localConfigFile file with local copy" ); } else {
$configFile = $localConfigFile; error_log( "WARNING: ZoneMinder configuration subfolder found but is not readable. Check folder permissions on $configSubFolder." );
} }
$cfg = fopen( $configFile, "r") or die("Could not open config file.");
while ( !feof($cfg) )
{
$str = fgets( $cfg, 256 );
if ( preg_match( '/^\s*$/', $str ))
continue;
elseif ( preg_match( '/^\s*#/', $str ))
continue;
elseif ( preg_match( '/^\s*([^=\s]+)\s*=\s*(.*?)\s*$/', $str, $matches )) {
Configure::write( $matches[1], $matches[2] );
define( $matches[1], $matches[2] );
}
}
fclose( $cfg );
} }
# Now that our array our finalized, define each key => value
# pair in the array as a constant
foreach( $configvals as $key => $value) {
define( $key, $value );
Configure::write( $matches[1], $matches[2] );
}
function process_configfile($configFile) {
if ( is_readable( $configFile ) ) {
$configvals = array();
$cfg = fopen( $configFile, "r") or die("Could not open config file.");
while ( !feof($cfg) ) {
$str = fgets( $cfg, 256 );
if ( preg_match( '/^\s*$/', $str ))
continue;
elseif ( preg_match( '/^\s*#/', $str ))
continue;
elseif ( preg_match( '/^\s*([^=\s]+)\s*=\s*(.*?)\s*$/', $str, $matches ))
$configvals[$matches[1]] = $matches[2];
}
fclose( $cfg );
return( $configvals );
} else {
error_log( "WARNING: ZoneMinder configuration file found but is not readable. Check file permissions on $configFile." );
return( false );
}
}