From 18972ae0fad10afb206b6edb4a5434dea2b5bf4a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 19 Aug 2021 10:18:08 +0200 Subject: [PATCH 1/4] luckily the PHP ini parser doesn't interpret this as an empty block, replacing the one defined above --- cfg/conf.sample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/conf.sample.php b/cfg/conf.sample.php index d362f3f2..7194ee57 100644 --- a/cfg/conf.sample.php +++ b/cfg/conf.sample.php @@ -161,7 +161,7 @@ class = Filesystem [model_options] dir = PATH "data" -[model] +;[model] ; example of a Google Cloud Storage configuration ;class = GoogleCloudStorage ;[model_options] From eb10d4d35e7c19ee660e43238623403c8d6576e0 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 19 Aug 2021 10:21:21 +0200 Subject: [PATCH 2/4] be more flexible with configuration paths 1. only consider CONFIG_PATH environment variable, if non-empty 2. fall back to search in PATH (defined in index.php), if CONFIG_PATH doesn't contain a readable configuration file --- lib/Configuration.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index 7c4eb106..81138004 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -101,15 +101,20 @@ class Configuration */ public function __construct() { - $config = array(); - $basePath = (getenv('CONFIG_PATH') !== false ? getenv('CONFIG_PATH') : PATH . 'cfg') . DIRECTORY_SEPARATOR; - $configFile = $basePath . 'conf.php'; - - if (is_readable($configFile)) { - $config = parse_ini_file($configFile, true); - foreach (array('main', 'model', 'model_options') as $section) { - if (!array_key_exists($section, $config)) { - throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 2); + $config = $basePaths = array(); + $configPath = getenv('CONFIG_PATH'); + if ($configPath !== false && !empty($configPath)) { + $basePaths[] = $configPath; + } + $basePaths[] = PATH . 'cfg'; + foreach ($basePaths as $basePath) { + $configFile = $basePath . DIRECTORY_SEPARATOR . 'conf.php'; + if (is_readable($configFile)) { + $config = parse_ini_file($configFile, true); + foreach (array('main', 'model', 'model_options') as $section) { + if (!array_key_exists($section, $config)) { + throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 2); + } } } } From ff3b6689581ff61cd68c752f161279183aa63150 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 19 Aug 2021 11:04:31 +0200 Subject: [PATCH 3/4] apply StyleCI recommendation --- lib/Configuration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index 81138004..19c2a3b0 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -101,7 +101,7 @@ class Configuration */ public function __construct() { - $config = $basePaths = array(); + $config = $basePaths = array(); $configPath = getenv('CONFIG_PATH'); if ($configPath !== false && !empty($configPath)) { $basePaths[] = $configPath; @@ -116,6 +116,7 @@ class Configuration throw new Exception(I18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 2); } } + break; } } From df2f5931cd2e5a57819121c54777469b31b55d7f Mon Sep 17 00:00:00 2001 From: El RIDO Date: Thu, 19 Aug 2021 19:28:52 +0200 Subject: [PATCH 4/4] improve readability, kudos @rugk --- lib/Configuration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Configuration.php b/lib/Configuration.php index 19c2a3b0..d8ef346b 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -101,7 +101,8 @@ class Configuration */ public function __construct() { - $config = $basePaths = array(); + $basePaths = array(); + $config = array(); $configPath = getenv('CONFIG_PATH'); if ($configPath !== false && !empty($configPath)) { $basePaths[] = $configPath;