Merge branch 'feature/create-missing-directories-when-creating-inis-8219'

resolves #8219
This commit is contained in:
Johannes Meyer 2015-01-30 16:22:20 +01:00
commit ab33350439
17 changed files with 205 additions and 187 deletions

View File

@ -2,14 +2,13 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Logger; use \Exception;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Forms\Dashboard\DashletForm; use Icinga\Forms\Dashboard\DashletForm;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\Controller\ActionController; use Icinga\Web\Controller\ActionController;
use Icinga\Web\Request;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Widget\Tabextension\DashboardSettings; use Icinga\Web\Widget\Tabextension\DashboardSettings;
@ -56,11 +55,12 @@ class DashboardController extends ActionController
$dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane); $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
$dashlet->setUserWidget(); $dashlet->setUserWidget();
$pane->addDashlet($dashlet); $pane->addDashlet($dashlet);
$dashboardConfig = $dashboard->getConfig();
try { try {
$dashboard->write(); $dashboardConfig->saveIni();
} catch (\Zend_Config_Exception $e) { } catch (Exception $e) {
$action->view->error = $e; $action->view->error = $e;
$action->view->config = $dashboard->createWriter(); $action->view->config = $dashboardConfig;
$action->render('error'); $action->render('error');
return false; return false;
} }
@ -117,11 +117,12 @@ class DashboardController extends ActionController
$oldPane = $dashboard->getPane($form->getValue('org_pane')); $oldPane = $dashboard->getPane($form->getValue('org_pane'));
$oldPane->removeDashlet($dashlet->getTitle()); $oldPane->removeDashlet($dashlet->getTitle());
} }
$dashboardConfig = $dashboard->getConfig();
try { try {
$dashboard->write(); $dashboardConfig->saveIni();
} catch (\Zend_Config_Exception $e) { } catch (Exception $e) {
$action->view->error = $e; $action->view->error = $e;
$action->view->config = $dashboard->createWriter(); $action->view->config = $dashboardConfig;
$action->render('error'); $action->render('error');
return false; return false;
} }
@ -158,15 +159,16 @@ class DashboardController extends ActionController
$dashlet = $this->_request->getParam('dashlet'); $dashlet = $this->_request->getParam('dashlet');
$action = $this; $action = $this;
$form->setOnSuccess(function (Form $form) use ($dashboard, $dashlet, $pane, $action) { $form->setOnSuccess(function (Form $form) use ($dashboard, $dashlet, $pane, $action) {
$pane = $dashboard->getPane($pane);
$pane->removeDashlet($dashlet);
$dashboardConfig = $dashboard->getConfig();
try { try {
$pane = $dashboard->getPane($pane); $dashboardConfig->saveIni();
$pane->removeDashlet($dashlet);
$dashboard->write();
Notification::success(t('Dashlet has been removed from') . ' ' . $pane->getTitle()); Notification::success(t('Dashlet has been removed from') . ' ' . $pane->getTitle());
return true; return true;
} catch (\Zend_Config_Exception $e) { } catch (Exception $e) {
$action->view->error = $e; $action->view->error = $e;
$action->view->config = $dashboard->createWriter(); $action->view->config = $dashboardConfig;
$action->render('error'); $action->render('error');
return false; return false;
} catch (ProgrammingError $e) { } catch (ProgrammingError $e) {
@ -196,15 +198,16 @@ class DashboardController extends ActionController
$pane = $this->_request->getParam('pane'); $pane = $this->_request->getParam('pane');
$action = $this; $action = $this;
$form->setOnSuccess(function (Form $form) use ($dashboard, $pane, $action) { $form->setOnSuccess(function (Form $form) use ($dashboard, $pane, $action) {
$pane = $dashboard->getPane($pane);
$dashboard->removePane($pane->getTitle());
$dashboardConfig = $dashboard->getConfig();
try { try {
$pane = $dashboard->getPane($pane); $dashboardConfig->saveIni();
$dashboard->removePane($pane->getTitle());
$dashboard->write();
Notification::success(t('Dashboard has been removed') . ': ' . $pane->getTitle()); Notification::success(t('Dashboard has been removed') . ': ' . $pane->getTitle());
return true; return true;
} catch (\Zend_Config_Exception $e) { } catch (Exception $e) {
$action->view->error = $e; $action->view->error = $e;
$action->view->config = $dashboard->createWriter(); $action->view->config = $dashboardConfig;
$action->render('error'); $action->render('error');
return false; return false;
} catch (ProgrammingError $e) { } catch (ProgrammingError $e) {
@ -241,7 +244,7 @@ class DashboardController extends ActionController
$this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard'; $this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard';
if ($this->hasParam('remove')) { if ($this->hasParam('remove')) {
$this->dashboard->getActivePane()->removeDashlet($this->getParam('remove')); $this->dashboard->getActivePane()->removeDashlet($this->getParam('remove'));
$this->dashboard->write(); $this->dashboard->getConfig()->saveIni();
$this->redirectNow(URL::fromRequest()->remove('remove')); $this->redirectNow(URL::fromRequest()->remove('remove'));
} }
$this->view->tabs->add( $this->view->tabs->add(

View File

@ -8,7 +8,6 @@ use Exception;
use Zend_Form_Decorator_Abstract; use Zend_Form_Decorator_Abstract;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
/** /**
* Form base-class providing standard functionality for configuration forms * Form base-class providing standard functionality for configuration forms
@ -44,21 +43,14 @@ class ConfigForm extends Form
*/ */
public function save() public function save()
{ {
$writer = new IniWriter(
array(
'config' => $this->config,
'filename' => $this->config->getConfigFile()
)
);
try { try {
$writer->write(); $this->config->saveIni();
} catch (Exception $e) { } catch (Exception $e) {
$this->addDecorator('ViewScript', array( $this->addDecorator('ViewScript', array(
'viewModule' => 'default', 'viewModule' => 'default',
'viewScript' => 'showConfiguration.phtml', 'viewScript' => 'showConfiguration.phtml',
'errorMessage' => $e->getMessage(), 'errorMessage' => $e->getMessage(),
'configString' => $writer->render(), 'configString' => $this->config,
'filePath' => $this->config->getConfigFile(), 'filePath' => $this->config->getConfigFile(),
'placement' => Zend_Form_Decorator_Abstract::PREPEND 'placement' => Zend_Form_Decorator_Abstract::PREPEND
)); ));

View File

@ -1,13 +1,13 @@
<div class="content"> <div class="content">
<h1><?= t('Could not persist dashboard'); ?></h1> <h1><?= $this->translate('Could not persist dashboard'); ?></h1>
<p> <p>
<?= t('Please copy the following dashboard snippet to '); ?> <?= $this->translate('Please copy the following dashboard snippet to '); ?>
<strong><?= $this->config->getFilename(); ?>;</strong>. <strong><?= $this->config->getConfigFile(); ?>;</strong>.
<br> <br>
<?= t('Make sure that the webserver can write to this file.'); ?> <?= $this->translate('Make sure that the webserver can write to this file.'); ?>
</p> </p>
<pre><?= (string) $this->config->render(); ?></pre> <pre><?= $this->config; ?></pre>
<hr> <hr>
<h2><?= t('Error details') ?></h2> <h2><?= $this->translate('Error details'); ?></h2>
<p><?= $this->error->getMessage(); ?></p> <p><?= $this->error->getMessage(); ?></p>
</div> </div>

View File

@ -6,8 +6,11 @@ namespace Icinga\Application;
use Iterator; use Iterator;
use Countable; use Countable;
use LogicException;
use UnexpectedValueException; use UnexpectedValueException;
use Icinga\Util\File;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\File\Ini\IniWriter;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
/** /**
@ -299,6 +302,49 @@ class Config implements Countable, Iterator
return $emptyConfig; return $emptyConfig;
} }
/**
* Save configuration to the given INI file
*
* @param string|null $filePath The path to the INI file or null in case this config's path should be used
* @param int $fileMode The file mode to store the file with
*
* @throws LogicException In case this config has no path and none is passed in either
* @throws NotWritableError In case the INI file cannot be written
*
* @todo create basepath and throw NotWritableError in case its not possible
*/
public function saveIni($filePath = null, $fileMode = 0660)
{
if ($filePath === null && $this->configFile) {
$filePath = $this->configFile;
} elseif ($filePath === null) {
throw new LogicException('You need to pass $filePath or set a path using Config::setConfigFile()');
}
if (! file_exists($filePath)) {
File::create($filePath, $fileMode);
}
$this->getIniWriter($filePath, $fileMode)->write();
}
/**
* Return a IniWriter for this config
*
* @param string|null $filePath
* @param int $fileMode
*
* @return IniWriter
*/
protected function getIniWriter($filePath = null, $fileMode = null)
{
return new IniWriter(array(
'config' => $this,
'filename' => $filePath,
'filemode' => $fileMode
));
}
/** /**
* Prepend configuration base dir to the given relative path * Prepend configuration base dir to the given relative path
* *
@ -354,4 +400,14 @@ class Config implements Countable, Iterator
return $moduleConfigs[$configname]; return $moduleConfigs[$configname];
} }
/**
* Return this config rendered as a INI structured string
*
* @return string
*/
public function __toString()
{
return $this->getIniWriter()->render();
}
} }

View File

@ -103,25 +103,22 @@ class Manager
*/ */
private function detectEnabledModules() private function detectEnabledModules()
{ {
$canonical = $this->enableDir; if (! file_exists($this->enableDir)) {
if ($canonical === false || ! file_exists($canonical)) {
// TODO: I guess the check for false has something to do with a
// call to realpath no longer present
return; return;
} }
if (!is_dir($this->enableDir)) { if (! is_dir($this->enableDir)) {
throw new NotReadableError( throw new NotReadableError(
'Cannot read enabled modules. Module directory "%s" is not a directory', 'Cannot read enabled modules. Module directory "%s" is not a directory',
$this->enableDir $this->enableDir
); );
} }
if (!is_readable($this->enableDir)) { if (! is_readable($this->enableDir)) {
throw new NotReadableError( throw new NotReadableError(
'Cannot read enabled modules. Module directory "%s" is not readable', 'Cannot read enabled modules. Module directory "%s" is not readable',
$this->enableDir $this->enableDir
); );
} }
if (($dh = opendir($canonical)) !== false) { if (($dh = opendir($this->enableDir)) !== false) {
$this->enabledDirs = array(); $this->enabledDirs = array();
while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
@ -129,7 +126,7 @@ class Manager
continue; continue;
} }
$link = $this->enableDir . '/' . $file; $link = $this->enableDir . DIRECTORY_SEPARATOR . $file;
if (! is_link($link)) { if (! is_link($link)) {
Logger::warning( Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" is not a symlink', 'Found invalid module in enabledModule directory "%s": "%s" is not a symlink',
@ -140,7 +137,7 @@ class Manager
} }
$dir = realpath($link); $dir = realpath($link);
if (!file_exists($dir) || !is_dir($dir)) { if (! file_exists($dir) || !is_dir($dir)) {
Logger::warning( Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"', 'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
$this->enableDir, $this->enableDir,
@ -208,7 +205,7 @@ class Manager
*/ */
public function enableModule($name) public function enableModule($name)
{ {
if (!$this->hasInstalled($name)) { if (! $this->hasInstalled($name)) {
throw new ConfigurationError( throw new ConfigurationError(
'Cannot enable module "%s". Module is not installed.', 'Cannot enable module "%s". Module is not installed.',
$name $name
@ -217,11 +214,16 @@ class Manager
clearstatcache(true); clearstatcache(true);
$target = $this->installedBaseDirs[$name]; $target = $this->installedBaseDirs[$name];
$link = $this->enableDir . '/' . $name; $link = $this->enableDir . DIRECTORY_SEPARATOR . $name;
if (! is_dir($this->enableDir)) { if (! is_dir($this->enableDir) && !@mkdir($this->enableDir, 02770, true)) {
throw new NotFoundError('Cannot enable module "%s". Path "%s" not found.', $name, $this->enableDir); $error = error_get_last();
} elseif (!is_writable($this->enableDir)) { throw new SystemPermissionException(
'Failed to create enabledModule directory "%s" (%s)',
$this->enableDir,
$error['message']
);
} elseif (! is_writable($this->enableDir)) {
throw new SystemPermissionException( throw new SystemPermissionException(
'Cannot enable module "%s". Insufficient system permissions for enabling modules.', 'Cannot enable module "%s". Insufficient system permissions for enabling modules.',
$name $name
@ -232,7 +234,7 @@ class Manager
return $this; return $this;
} }
if (!@symlink($target, $link)) { if (! @symlink($target, $link)) {
$error = error_get_last(); $error = error_get_last();
if (strstr($error["message"], "File exists") === false) { if (strstr($error["message"], "File exists") === false) {
throw new SystemPermissionException( throw new SystemPermissionException(
@ -246,9 +248,7 @@ class Manager
} }
$this->enabledDirs[$name] = $link; $this->enabledDirs[$name] = $link;
$this->loadModule($name); $this->loadModule($name);
return $this; return $this;
} }
@ -264,22 +264,22 @@ class Manager
*/ */
public function disableModule($name) public function disableModule($name)
{ {
if (!$this->hasEnabled($name)) { if (! $this->hasEnabled($name)) {
return $this; return $this;
} }
if (!is_writable($this->enableDir)) { if (! is_writable($this->enableDir)) {
throw new SystemPermissionException( throw new SystemPermissionException(
'Could not disable module. Module path is not writable.' 'Could not disable module. Module path is not writable.'
); );
} }
$link = $this->enableDir . '/' . $name; $link = $this->enableDir . DIRECTORY_SEPARATOR . $name;
if (!file_exists($link)) { if (! file_exists($link)) {
throw new ConfigurationError( throw new ConfigurationError(
'Could not disable module. The module %s was not found.', 'Could not disable module. The module %s was not found.',
$name $name
); );
} }
if (!is_link($link)) { if (! is_link($link)) {
throw new ConfigurationError( throw new ConfigurationError(
'Could not disable module. The module "%s" is not a symlink. ' 'Could not disable module. The module "%s" is not a symlink. '
. 'It looks like you have installed this module manually and moved it to your module folder. ' . 'It looks like you have installed this module manually and moved it to your module folder. '
@ -290,7 +290,7 @@ class Manager
} }
if (file_exists($link) && is_link($link)) { if (file_exists($link) && is_link($link)) {
if (!@unlink($link)) { if (! @unlink($link)) {
$error = error_get_last(); $error = error_get_last();
throw new SystemPermissionException( throw new SystemPermissionException(
'Could not disable module "%s" due to file system errors. ' 'Could not disable module "%s" due to file system errors. '

View File

@ -7,10 +7,8 @@ namespace Icinga\User\Preferences\Store;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
use Icinga\Exception\NotWritableError; use Icinga\Exception\NotWritableError;
use Icinga\File\Ini\IniWriter;
use Icinga\User\Preferences; use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore; use Icinga\User\Preferences\PreferencesStore;
use Icinga\Util\File;
/** /**
* Load and save user preferences from and to INI files * Load and save user preferences from and to INI files
@ -31,13 +29,6 @@ class IniStore extends PreferencesStore
*/ */
protected $preferences = array(); protected $preferences = array();
/**
* Writer which stores the preferences
*
* @var IniWriter
*/
protected $writer;
/** /**
* Initialize the store * Initialize the store
*/ */
@ -98,35 +89,7 @@ class IniStore extends PreferencesStore
*/ */
public function write() public function write()
{ {
if ($this->writer === null) { Config::fromArray($this->preferences)->saveIni($this->preferencesFile);
if (! file_exists($this->preferencesFile)) {
if (! is_writable($this->getStoreConfig()->location)) {
throw new NotWritableError(
'Path to the preferences INI files %s is not writable',
$this->getStoreConfig()->location
);
}
File::create($this->preferencesFile, 0664);
}
if (! is_writable($this->preferencesFile)) {
throw new NotWritableError(
'Preferences INI file %s for user %s is not writable',
$this->preferencesFile,
$this->getUser()->getUsername()
);
}
$this->writer = new IniWriter(
array(
'config' => Config::fromArray($this->preferences),
'filename' => $this->preferencesFile
)
);
}
$this->writer->write();
} }
/** /**

View File

@ -23,6 +23,13 @@ class File extends SplFileObject
*/ */
protected $openMode; protected $openMode;
/**
* The access mode to use when creating directories
*
* @var int
*/
public static $dirMode = 1528; // 2770
/** /**
* @see SplFileObject::__construct() * @see SplFileObject::__construct()
*/ */
@ -37,21 +44,74 @@ class File extends SplFileObject
} }
/** /**
* Create a file with an access mode * Create a file using the given access mode and return a instance of File open for writing
* *
* @param string $path The path to the file * @param string $path The path to the file
* @param int $accessMode The access mode to set * @param int $accessMode The access mode to set
* @param bool $recursive Whether missing nested directories of the given path should be created
*
* @return File
* *
* @throws RuntimeException In case the file cannot be created or the access mode cannot be set * @throws RuntimeException In case the file cannot be created or the access mode cannot be set
* @throws NotWritableError In case the path's (existing) parent is not writable
*/ */
public static function create($path, $accessMode) public static function create($path, $accessMode, $recursive = true)
{ {
if (!@touch($path)) { $dirPath = dirname($path);
throw new RuntimeException('Cannot create file "' . $path . '" with acces mode "' . $accessMode . '"'); if ($recursive && !is_dir($dirPath)) {
static::createDirectories($dirPath);
} elseif (! is_writable($dirPath)) {
throw new NotWritableError(sprintf('Path "%s" is not writable', $dirPath));
} }
if (!@chmod($path, $accessMode)) { $file = new static($path, 'x');
throw new RuntimeException('Cannot set access mode "' . $accessMode . '" on file "' . $path . '"');
if (! @chmod($path, $accessMode)) {
$error = error_get_last();
throw new RuntimeException(sprintf(
'Cannot set access mode "%s" on file "%s" (%s)',
decoct($accessMode),
$path,
$error['message']
));
}
return $file;
}
/**
* Create missing directories
*
* @param string $path
*
* @throws RuntimeException In case a directory cannot be created or the access mode cannot be set
*/
protected static function createDirectories($path)
{
$part = strpos($path, DIRECTORY_SEPARATOR) === 0 ? DIRECTORY_SEPARATOR : '';
foreach (explode(DIRECTORY_SEPARATOR, ltrim($path, DIRECTORY_SEPARATOR)) as $dir) {
$part .= $dir . DIRECTORY_SEPARATOR;
if (! is_dir($part)) {
if (! @mkdir($part, static::$dirMode)) {
$error = error_get_last();
throw new RuntimeException(sprintf(
'Failed to create missing directory "%s" (%s)',
$part,
$error['message']
));
}
if (! @chmod($part, static::$dirMode)) {
$error = error_get_last();
throw new RuntimeException(sprintf(
'Failed to set access mode "%s" for directory "%s" (%s)',
decoct(static::$dirMode),
$part,
$error['message']
));
}
}
} }
} }

View File

@ -6,12 +6,10 @@ namespace Icinga\Web\Widget;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Data\ConfigObject;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotReadableError; use Icinga\Exception\NotReadableError;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Exception\SystemPermissionException; use Icinga\Exception\SystemPermissionException;
use Icinga\File\Ini\IniWriter;
use Icinga\User; use Icinga\User;
use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Web\Widget\Dashboard\Pane;
use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet; use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet;
@ -86,13 +84,12 @@ class Dashboard extends AbstractWidget
} }
/** /**
* Create a writer object * Create and return a Config object for this dashboard
* *
* @return IniWriter * @return Config
*/ */
public function createWriter() public function getConfig()
{ {
$configFile = $this->getConfigFile();
$output = array(); $output = array();
foreach ($this->panes as $pane) { foreach ($this->panes as $pane) {
if ($pane->isUserWidget() === true) { if ($pane->isUserWidget() === true) {
@ -105,17 +102,7 @@ class Dashboard extends AbstractWidget
} }
} }
$co = new ConfigObject($output); return Config::fromArray($output)->setConfigFile($this->getConfigFile());
$config = new Config($co);
return new IniWriter(array('config' => $config, 'filename' => $configFile));
}
/**
* Write user specific dashboards to disk
*/
public function write()
{
$this->createWriter()->write();
} }
/** /**

View File

@ -7,7 +7,6 @@ namespace Icinga\Module\Monitoring;
use Exception; use Exception;
use Icinga\Module\Setup\Step; use Icinga\Module\Setup\Step;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
class BackendStep extends Step class BackendStep extends Step
{ {
@ -38,11 +37,9 @@ class BackendStep extends Step
); );
try { try {
$writer = new IniWriter(array( Config::fromArray($config)
'config' => Config::fromArray($config), ->setConfigFile(Config::resolvePath('modules/monitoring/backends.ini'))
'filename' => Config::resolvePath('modules/monitoring/backends.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->backendIniError = $e; $this->backendIniError = $e;
return false; return false;
@ -61,13 +58,7 @@ class BackendStep extends Step
try { try {
$config = Config::app('resources', true); $config = Config::app('resources', true);
$config->setSection($resourceName, $resourceConfig); $config->setSection($resourceName, $resourceConfig);
$config->saveIni();
$writer = new IniWriter(array(
'config' => $config,
'filename' => Config::resolvePath('resources.ini'),
'filemode' => 0660
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->resourcesIniError = $e; $this->resourcesIniError = $e;
return false; return false;

View File

@ -7,7 +7,6 @@ namespace Icinga\Module\Monitoring;
use Exception; use Exception;
use Icinga\Module\Setup\Step; use Icinga\Module\Setup\Step;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
class InstanceStep extends Step class InstanceStep extends Step
{ {
@ -27,11 +26,9 @@ class InstanceStep extends Step
unset($instanceConfig['name']); unset($instanceConfig['name']);
try { try {
$writer = new IniWriter(array( Config::fromArray(array($instanceName => $instanceConfig))
'config' => Config::fromArray(array($instanceName => $instanceConfig)), ->setConfigFile(Config::resolvePath('modules/monitoring/instances.ini'))
'filename' => Config::resolvePath('modules/monitoring/instances.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->error = $e; $this->error = $e;
return false; return false;

View File

@ -4,7 +4,6 @@
namespace Icinga\Module\Monitoring; namespace Icinga\Module\Monitoring;
use Icinga\Application\Icinga;
use Icinga\Application\Platform; use Icinga\Application\Platform;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Wizard; use Icinga\Web\Wizard;
@ -12,7 +11,6 @@ use Icinga\Web\Request;
use Icinga\Module\Setup\Setup; use Icinga\Module\Setup\Setup;
use Icinga\Module\Setup\SetupWizard; use Icinga\Module\Setup\SetupWizard;
use Icinga\Module\Setup\Requirements; use Icinga\Module\Setup\Requirements;
use Icinga\Module\Setup\Utils\MakeDirStep;
use Icinga\Module\Setup\Forms\SummaryPage; use Icinga\Module\Setup\Forms\SummaryPage;
use Icinga\Module\Monitoring\Forms\Setup\WelcomePage; use Icinga\Module\Monitoring\Forms\Setup\WelcomePage;
use Icinga\Module\Monitoring\Forms\Setup\BackendPage; use Icinga\Module\Monitoring\Forms\Setup\BackendPage;
@ -109,8 +107,6 @@ class MonitoringWizard extends Wizard implements SetupWizard
$pageData = $this->getPageData(); $pageData = $this->getPageData();
$setup = new Setup(); $setup = new Setup();
$setup->addStep(new MakeDirStep(array(Icinga::app()->getConfigDir() . '/modules/monitoring'), 2770));
$setup->addStep( $setup->addStep(
new BackendStep(array( new BackendStep(array(
'backendConfig' => $pageData['setup_monitoring_backend'], 'backendConfig' => $pageData['setup_monitoring_backend'],

View File

@ -7,7 +7,6 @@ namespace Icinga\Module\Monitoring;
use Exception; use Exception;
use Icinga\Module\Setup\Step; use Icinga\Module\Setup\Step;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
class SecurityStep extends Step class SecurityStep extends Step
{ {
@ -26,11 +25,9 @@ class SecurityStep extends Step
$config['security'] = $this->data['securityConfig']; $config['security'] = $this->data['securityConfig'];
try { try {
$writer = new IniWriter(array( Config::fromArray($config)
'config' => Config::fromArray($config), ->setConfigFile(Config::resolvePath('modules/monitoring/config.ini'))
'filename' => Config::resolvePath('modules/monitoring/config.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->error = $e; $this->error = $e;
return false; return false;

View File

@ -6,7 +6,6 @@ namespace Icinga\Module\Setup\Steps;
use Exception; use Exception;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory; use Icinga\Data\ResourceFactory;
use Icinga\Authentication\Backend\DbUserBackend; use Icinga\Authentication\Backend\DbUserBackend;
@ -50,11 +49,9 @@ class AuthenticationStep extends Step
} }
try { try {
$writer = new IniWriter(array( Config::fromArray($config)
'config' => Config::fromArray($config), ->setConfigFile(Config::resolvePath('authentication.ini'))
'filename' => Config::resolvePath('authentication.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->authIniError = $e; $this->authIniError = $e;
return false; return false;
@ -73,11 +70,9 @@ class AuthenticationStep extends Step
); );
try { try {
$writer = new IniWriter(array( Config::fromArray($config)
'config' => Config::fromArray($config), ->setConfigFile(Config::resolvePath('permissions.ini'))
'filename' => Config::resolvePath('permissions.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->permIniError = $e; $this->permIniError = $e;
return false; return false;

View File

@ -7,7 +7,6 @@ namespace Icinga\Module\Setup\Steps;
use Exception; use Exception;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
use Icinga\Module\Setup\Step; use Icinga\Module\Setup\Step;
class GeneralConfigStep extends Step class GeneralConfigStep extends Step
@ -35,11 +34,9 @@ class GeneralConfigStep extends Step
} }
try { try {
$writer = new IniWriter(array( Config::fromArray($config)
'config' => Config::fromArray($config), ->setConfigFile(Config::resolvePath('config.ini'))
'filename' => Config::resolvePath('config.ini') ->saveIni();
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->error = $e; $this->error = $e;
return false; return false;

View File

@ -6,7 +6,6 @@ namespace Icinga\Module\Setup\Steps;
use Exception; use Exception;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\File\Ini\IniWriter;
use Icinga\Module\Setup\Step; use Icinga\Module\Setup\Step;
class ResourceStep extends Step class ResourceStep extends Step
@ -38,12 +37,9 @@ class ResourceStep extends Step
} }
try { try {
$writer = new IniWriter(array( Config::fromArray($resourceConfig)
'config' => Config::fromArray($resourceConfig), ->setConfigFile(Config::resolvePath('resources.ini'))
'filename' => Config::resolvePath('resources.ini'), ->saveIni();
'filemode' => 0660
));
$writer->write();
} catch (Exception $e) { } catch (Exception $e) {
$this->error = $e; $this->error = $e;
return false; return false;

View File

@ -16,12 +16,12 @@ class MakeDirStep extends Step
/** /**
* @param array $paths * @param array $paths
* @param int $dirmode Directory mode in octal notation * @param int $dirmode
*/ */
public function __construct($paths, $dirmode) public function __construct($paths, $dirmode)
{ {
$this->paths = $paths; $this->paths = $paths;
$this->dirmode = octdec((string) $dirmode); $this->dirmode = $dirmode;
$this->errors = array(); $this->errors = array();
} }

View File

@ -334,18 +334,6 @@ class WebWizard extends Wizard implements SetupWizard
); );
} }
$configDir = Icinga::app()->getConfigDir();
$setup->addStep(
new MakeDirStep(
array(
$configDir . DIRECTORY_SEPARATOR . 'modules',
$configDir . DIRECTORY_SEPARATOR . 'preferences',
$configDir . DIRECTORY_SEPARATOR . 'enabledModules'
),
2770
)
);
foreach ($this->getWizards() as $wizard) { foreach ($this->getWizards() as $wizard) {
if ($wizard->isComplete()) { if ($wizard->isComplete()) {
$setup->addSteps($wizard->getSetup()->getSteps()); $setup->addSteps($wizard->getSetup()->getSteps());