mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 05:44:36 +02:00
Implement General configuration form
Missing: - Logical validation (check for writable paths) - DB Resource selection (see #4503) refs #3777
This commit is contained in:
parent
26a5018d16
commit
9ddc03d571
@ -86,9 +86,12 @@ class ConfigController extends BaseConfigController
|
|||||||
if ($form->isSubmittedAndValid()) {
|
if ($form->isSubmittedAndValid()) {
|
||||||
$cfg = IcingaConfig::app()->getConfigFile();
|
$cfg = IcingaConfig::app()->getConfigFile();
|
||||||
$writer = new PreservingIniWriter(
|
$writer = new PreservingIniWriter(
|
||||||
array('config' => $form->getConfig(),'filename' => $cfg)
|
array(
|
||||||
|
'config' => $form->getConfig(),
|
||||||
|
'filename' => $cfg
|
||||||
|
)
|
||||||
);
|
);
|
||||||
print_r($writer->render());die();
|
$writer->write();
|
||||||
}
|
}
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
@ -27,41 +27,17 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Icinga\Form\Config;
|
namespace Icinga\Form\Config;
|
||||||
/**
|
|
||||||
* [global]
|
|
||||||
environment = development
|
|
||||||
timezone = "Europe/Berlin"
|
|
||||||
indexModule = monitoring
|
|
||||||
indexController = dashboard
|
|
||||||
moduleFolder = "/etc/icinga2-web/enabledModules"
|
|
||||||
dateFormat = "d/m/Y"
|
|
||||||
timeFormat = "g:i A"
|
|
||||||
|
|
||||||
[logging]
|
|
||||||
; General log
|
|
||||||
enable = 1
|
|
||||||
type = stream
|
|
||||||
verbose = 1
|
|
||||||
target = /tmp/icinga2.log
|
|
||||||
|
|
||||||
; For development and debug purposes: Logs additional (non critical) events to a
|
|
||||||
; seperate log
|
|
||||||
debug.enable = 1
|
|
||||||
debug.type = stream
|
|
||||||
debug.target = /tmp/icinga2.debug.log
|
|
||||||
|
|
||||||
; Use ini store to store preferences on local disk
|
|
||||||
[preferences]
|
|
||||||
type=ini
|
|
||||||
|
|
||||||
*/
|
|
||||||
use \Icinga\Application\Config as IcingaConfig;
|
use \Icinga\Application\Config as IcingaConfig;
|
||||||
use Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
use \Zend_Form_Element_Radio;
|
use \Icinga\Web\Form\Decorator\ConditionalHidden;
|
||||||
|
use \Icinga\Web\Form\Element\Note;
|
||||||
|
|
||||||
use \DateTimeZone;
|
use \DateTimeZone;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use Icinga\Web\Form\Element\Note;
|
use \Zend_Form_Element_Text;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration form for general, application-wide settings
|
* Configuration form for general, application-wide settings
|
||||||
@ -231,6 +207,56 @@ class GeneralForm extends Form
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addUserPreferencesDialog(Zend_Config $cfg)
|
||||||
|
{
|
||||||
|
$backend = $cfg->get('type', 'ini');
|
||||||
|
if ($this->getRequest()->get('preferences_type', null) !== null) {
|
||||||
|
$backend = $this->getRequest()->get('preferences_type');
|
||||||
|
}
|
||||||
|
$this->addElement(
|
||||||
|
'select',
|
||||||
|
'preferences_type',
|
||||||
|
array(
|
||||||
|
'label' => 'User preference storage type',
|
||||||
|
'required' => true,
|
||||||
|
'value' => $backend,
|
||||||
|
'multiOptions' => array(
|
||||||
|
'ini' => 'File system (ini files)',
|
||||||
|
'db' => 'Database'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$txtPreferencesIniPath = new Zend_Form_Element_Text(
|
||||||
|
array(
|
||||||
|
'name' => 'preferences_ini_path',
|
||||||
|
'label' => 'Path to store user preference files',
|
||||||
|
'required' => $backend === 'ini',
|
||||||
|
'condition' => $backend === 'ini',
|
||||||
|
'value' => $cfg->get('configPath')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$txtPreferencesDbResource = new Zend_Form_Element_Text(
|
||||||
|
array(
|
||||||
|
'name' => 'preferences_db_resource',
|
||||||
|
'label' => 'Database connection (TODO: Make select field)',
|
||||||
|
'required' => $backend === 'db',
|
||||||
|
'condition' => $backend === 'db',
|
||||||
|
'value' => $cfg->get('resource')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->addElement($txtPreferencesIniPath);
|
||||||
|
$this->addElement($txtPreferencesDbResource);
|
||||||
|
|
||||||
|
$txtPreferencesIniPath->addDecorator(new ConditionalHidden());
|
||||||
|
$txtPreferencesDbResource->addDecorator(new ConditionalHidden());
|
||||||
|
$this->enableAutoSubmit(array(
|
||||||
|
'preferences_type'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the general form, using the provided configuration
|
* Create the general form, using the provided configuration
|
||||||
*
|
*
|
||||||
@ -245,11 +271,17 @@ class GeneralForm extends Form
|
|||||||
if ($global === null) {
|
if ($global === null) {
|
||||||
$global = new Zend_Config(array());
|
$global = new Zend_Config(array());
|
||||||
}
|
}
|
||||||
|
$preferences = $this->config->preferences;
|
||||||
|
if ($preferences === null) {
|
||||||
|
$preferences = new Zend_Config(array());
|
||||||
|
}
|
||||||
|
|
||||||
$this->addDevelopmentCheckbox($global);
|
$this->addDevelopmentCheckbox($global);
|
||||||
$this->addTimezoneSelection($global);
|
$this->addTimezoneSelection($global);
|
||||||
$this->addModuleSettings($global);
|
$this->addModuleSettings($global);
|
||||||
$this->addDateFormatSettings($global);
|
$this->addDateFormatSettings($global);
|
||||||
|
$this->addUserPreferencesDialog($preferences);
|
||||||
|
|
||||||
|
|
||||||
$this->setSubmitLabel('Save changes');
|
$this->setSubmitLabel('Save changes');
|
||||||
}
|
}
|
||||||
@ -259,10 +291,12 @@ class GeneralForm extends Form
|
|||||||
if ($this->config === null) {
|
if ($this->config === null) {
|
||||||
$this->config = new Zend_Config(array());
|
$this->config = new Zend_Config(array());
|
||||||
}
|
}
|
||||||
$global = $this->config->global;
|
if ($this->config->global === null) {
|
||||||
if ($global === null) {
|
|
||||||
$this->config->global = new Zend_Config(array());
|
$this->config->global = new Zend_Config(array());
|
||||||
}
|
}
|
||||||
|
if ($this->config->preferences === null) {
|
||||||
|
$this->config->preferences = new Zend_Config(array());
|
||||||
|
}
|
||||||
|
|
||||||
$values = $this->getValues();
|
$values = $this->getValues();
|
||||||
$cfg = clone $this->config;
|
$cfg = clone $this->config;
|
||||||
@ -272,6 +306,13 @@ class GeneralForm extends Form
|
|||||||
$cfg->global->dateFormat = $values['date_format'];
|
$cfg->global->dateFormat = $values['date_format'];
|
||||||
$cfg->global->timeFormat = $values['time_format'];
|
$cfg->global->timeFormat = $values['time_format'];
|
||||||
|
|
||||||
|
$cfg->preferences->type = $values['preferences_type'];
|
||||||
|
if ($cfg->preferences->type === 'ini') {
|
||||||
|
$cfg->preferences->configPath = $values['preferences_ini_path'];
|
||||||
|
} elseif ($cfg->preferences->type === 'db') {
|
||||||
|
$cfg->preferences->resource = $values['preferences_db_resource'];
|
||||||
|
}
|
||||||
|
|
||||||
return $cfg;
|
return $cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,6 @@ class LoggingForm extends Form
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->addDecorator(new ConditionalHidden());
|
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
@ -195,7 +194,7 @@ class LoggingForm extends Form
|
|||||||
'label' => 'Debug log path',
|
'label' => 'Debug log path',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'condition' => $this->shouldDisplayDebugLog($debug),
|
'condition' => $this->shouldDisplayDebugLog($debug),
|
||||||
'value' => $debug->get('target', '/var/log/icingaweb.debug.log')
|
'value' => $debug->get('target')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$loggingPathNote = new Note(
|
$loggingPathNote = new Note(
|
||||||
@ -205,10 +204,13 @@ class LoggingForm extends Form
|
|||||||
'condition' => $this->shouldDisplayDebugLog($debug)
|
'condition' => $this->shouldDisplayDebugLog($debug)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$decorator = new ConditionalHidden();
|
||||||
$this->addElement($textLoggingDebugPath);
|
$this->addElement($textLoggingDebugPath);
|
||||||
$this->addElement($loggingPathNote);
|
$this->addElement($loggingPathNote);
|
||||||
|
|
||||||
|
$textLoggingDebugPath->addDecorator($decorator);
|
||||||
|
$loggingPathNote->addDecorator($decorator);
|
||||||
|
|
||||||
$this->enableAutoSubmit(array('logging_use_debug', 'logging_enable'));
|
$this->enableAutoSubmit(array('logging_use_debug', 'logging_enable'));
|
||||||
|
|
||||||
$this->setSubmitLabel('Save changes');
|
$this->setSubmitLabel('Save changes');
|
||||||
|
@ -25,13 +25,14 @@
|
|||||||
|
|
||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
|
use \Icinga\Web\Form\Decorator\ConditionalHidden;
|
||||||
use \Zend_Controller_Request_Abstract;
|
use \Zend_Controller_Request_Abstract;
|
||||||
use \Zend_Form_Element_Submit;
|
use \Zend_Form_Element_Submit;
|
||||||
use \Zend_Form_Element_Reset;
|
use \Zend_Form_Element_Reset;
|
||||||
use \Zend_View_Interface;
|
use \Zend_View_Interface;
|
||||||
use \Zend_Form;
|
use \Zend_Form;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use \Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Web\Form\InvalidCSRFTokenException;
|
use \Icinga\Web\Form\InvalidCSRFTokenException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for forms providing CSRF protection, confirmation logic and auto submission
|
* Base class for forms providing CSRF protection, confirmation logic and auto submission
|
||||||
@ -179,6 +180,7 @@ abstract class Form extends Zend_Form
|
|||||||
*/
|
*/
|
||||||
public function buildForm()
|
public function buildForm()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->created === false) {
|
if ($this->created === false) {
|
||||||
$this->initCsrfToken();
|
$this->initCsrfToken();
|
||||||
$this->create();
|
$this->create();
|
||||||
|
@ -40,4 +40,9 @@ class Note extends Zend_Form_Element_Xhtml
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $helper = 'formNote';
|
public $helper = 'formNote';
|
||||||
|
|
||||||
|
public function isValid($value)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user