From 0108f43cab65ca8fb48d2cf2d07102071aafb52c Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Fri, 21 Nov 2014 21:39:34 +0000 Subject: [PATCH] Add function for making vars in zm.conf global in api This loops throgh zm.conf and sets each variable in it as global in CakePHP via Configure::write. The vars can then later be read withing CakePHP via Configure::read --- web/api/app/Config/bootstrap.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/web/api/app/Config/bootstrap.php b/web/api/app/Config/bootstrap.php index a65404ad2..56b28260f 100644 --- a/web/api/app/Config/bootstrap.php +++ b/web/api/app/Config/bootstrap.php @@ -109,3 +109,31 @@ CakeLog::config('error', array( Configure::write('ZM_CONFIG', '@ZM_CONFIG@'); Configure::write('ZM_VERSION', '@VERSION@'); + +loadConfigFile(); + +function loadConfigFile() { + $configFile = Configure::read('ZM_CONFIG'); + $localConfigFile = basename($configFile); + if ( file_exists( $localConfigFile ) && filesize( $localConfigFile ) > 0 ) + { + if ( php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']) ) + print( "Warning, overriding installed $localConfigFile file with local copy\n" ); + else + error_log( "Warning, overriding installed $localConfigFile file with local copy" ); + $configFile = $localConfigFile; + } + + $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]"); + } + fclose( $cfg ); +}