mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-05-29 19:10:12 +02:00
parent
e020dd3541
commit
364c7c0858
67
application/forms/ConfigForm.php
Normal file
67
application/forms/ConfigForm.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Form;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Config\PreservingIniWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form base-class providing standard functionality for configuration forms
|
||||||
|
*/
|
||||||
|
class ConfigForm extends Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The configuration to work with
|
||||||
|
*
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the configuration to use when populating the form or when saving the user's input
|
||||||
|
*
|
||||||
|
* @param Config $config The configuration to use
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setConfig(Config $config)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persist the current configuration to disk
|
||||||
|
*
|
||||||
|
* If an error occurs the user is shown a view describing the issue and displaying the raw INI configuration.
|
||||||
|
*
|
||||||
|
* @return bool Whether the configuration could be persisted
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$writer = new PreservingIniWriter(
|
||||||
|
array(
|
||||||
|
'config' => $this->config,
|
||||||
|
'filename' => $this->config->getConfigFile()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$writer->write();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->addDecorator('ViewScript', array(
|
||||||
|
'viewScript' => 'showConfiguration.phtml',
|
||||||
|
'errorMessage' => $e->getMessage(),
|
||||||
|
'configString' => $writer->render(),
|
||||||
|
'filePath' => $this->config->getConfigFile()
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
28
application/views/scripts/showConfiguration.phtml
Normal file
28
application/views/scripts/showConfiguration.phtml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<div>
|
||||||
|
<h4><?= $this->translate('Saving Configuration Failed'); ?></h4>
|
||||||
|
<br>
|
||||||
|
<p>
|
||||||
|
<?= sprintf(
|
||||||
|
$this->translate('The file %s couldn\'t be stored. (Error: "%s")'),
|
||||||
|
$this->escape($filePath),
|
||||||
|
$this->escape($errorMessage)
|
||||||
|
); ?>
|
||||||
|
<br>
|
||||||
|
<?= $this->translate('This could have one or more of the following reasons:'); ?>
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><?= $this->translate('You don\'t have file-system permissions to write to the file'); ?></li>
|
||||||
|
<li><?= $this->translate('Something went wrong while writing the file'); ?></li>
|
||||||
|
<li><?= $this->translate('There\'s an application error preventing you from persisting the configuration'); ?></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
<?= $this->translate('Details can be found in the application log. (If you don\'t have access to this log, call your administrator in this case)'); ?>
|
||||||
|
<br>
|
||||||
|
<?= $this->translate('In case you can access the file by yourself, you can open it and insert the config manually:'); ?>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<pre>
|
||||||
|
<code><?= $this->escape($configString); ?></code>
|
||||||
|
</pre>
|
||||||
|
</p>
|
Loading…
x
Reference in New Issue
Block a user