diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index e15ca2c8c..d0af62e1b 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -205,9 +205,9 @@ class ConfigController extends Controller $this->createApplicationTabs()->activate('tls'); $rootCaCollections = array(); - foreach (new LocalFileStorage(Icinga::app()->getStorageDir('framework/tls/rootcacollections')) as $ca) { + foreach (LocalFileStorage::common('tls/rootcacollections') as $rootCaCollection) { $matches = array(); - if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $ca, $matches)) { + if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $rootCaCollection, $matches)) { $rootCaCollections[hex2bin($matches[1])] = null; } } @@ -216,9 +216,9 @@ class ConfigController extends Controller $this->view->rootCaCollections = array_keys($rootCaCollections); $clientIdentities = array(); - foreach (new LocalFileStorage(Icinga::app()->getStorageDir('framework/tls/clientidentities')) as $client) { + foreach (LocalFileStorage::common('tls/clientidentities') as $clientIdentity) { $matches = array(); - if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $client, $matches)) { + if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $clientIdentity, $matches)) { $clientIdentities[hex2bin($matches[1])] = null; } } diff --git a/library/Icinga/File/Storage/LocalFileStorage.php b/library/Icinga/File/Storage/LocalFileStorage.php index 4885f324e..eadd5898f 100644 --- a/library/Icinga/File/Storage/LocalFileStorage.php +++ b/library/Icinga/File/Storage/LocalFileStorage.php @@ -4,6 +4,7 @@ namespace Icinga\File\Storage; use ErrorException; +use Icinga\Application\Icinga; use Icinga\Exception\AlreadyExistsException; use Icinga\Exception\NotFoundError; use Icinga\Exception\NotReadableError; @@ -25,6 +26,21 @@ class LocalFileStorage implements StorageInterface */ protected $baseDir; + /** + * Factory for the common storage directory with optional subdirectory + * + * @param string $subDir + * + * @return static + */ + public static function common($subDir = null) + { + $baseDir = Icinga::app()->getStorageDir($subDir); + static::ensureDir($baseDir); + + return new static($baseDir); + } + /** * Constructor * @@ -135,10 +151,10 @@ class LocalFileStorage implements StorageInterface * * @throws NotWritableError */ - protected function ensureDir($dir) + protected static function ensureDir($dir) { if (! is_dir($dir)) { - $this->ensureDir(dirname($dir)); + static::ensureDir(dirname($dir)); try { mkdir($dir, 02770);