parent
d1b1bc368f
commit
bc05d2ee64
|
@ -58,20 +58,15 @@ class ConfigController extends BaseConfigController
|
||||||
|
|
||||||
$form = new GeneralForm();
|
$form = new GeneralForm();
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$currentConfig = IcingaConfig::app();
|
|
||||||
if ($request->isPost()) {
|
if ($request->isPost()) {
|
||||||
if ($form->isValid($request->getPost())) {
|
if ($form->isValid($request->getPost())) {
|
||||||
$formConfig = $form->getConfiguration();
|
if ($this->writeConfigFile($form->getConfiguration(), 'config')) {
|
||||||
$newConfig = new Zend_Config($currentConfig->toArray(), true);
|
|
||||||
$newConfig->global = $formConfig->global;
|
|
||||||
$newConfig->preferences = $formConfig->preferences;
|
|
||||||
if ($this->writeConfigFile($newConfig, 'config')) {
|
|
||||||
Notification::success($this->translate('New configuration has successfully been stored'));
|
Notification::success($this->translate('New configuration has successfully been stored'));
|
||||||
$this->redirectNow('config');
|
$this->redirectNow('config');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$form->setConfiguration($currentConfig);
|
$form->setConfiguration(IcingaConfig::app());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
|
|
|
@ -8,7 +8,9 @@ use DateTimeZone;
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Util\Translator;
|
use Icinga\Util\Translator;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
|
use Icinga\Web\Form\Validator\WritablePathValidator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration form for general, application-wide settings
|
* Configuration form for general, application-wide settings
|
||||||
|
@ -34,7 +36,11 @@ class GeneralForm extends Form
|
||||||
$this->getModulePathInput($formData)
|
$this->getModulePathInput($formData)
|
||||||
);
|
);
|
||||||
|
|
||||||
return array_merge($elements, $this->getPreferencesElements($formData));
|
return array_merge(
|
||||||
|
$elements,
|
||||||
|
$this->getPreferencesElements($formData),
|
||||||
|
$this->getLoggingElements($formData)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,13 +69,14 @@ class GeneralForm extends Form
|
||||||
*/
|
*/
|
||||||
public function setConfiguration(Zend_Config $config)
|
public function setConfiguration(Zend_Config $config)
|
||||||
{
|
{
|
||||||
$defaults = $config->get('global', new Zend_Config(array()))->toArray();
|
$defaults = array();
|
||||||
if ($config->get('preferences', new Zend_Config(array()))->type !== null) {
|
foreach ($config as $section => $properties) {
|
||||||
$defaults['preferences_type'] = $config->get('preferences')->type;
|
foreach ($properties as $name => $value) {
|
||||||
$defaults['preferences_resource'] = $config->get('preferences')->resource;
|
$defaults[$section . '_' . $name] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setDefaults($defaults);
|
$this->populate($defaults);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,19 +87,14 @@ class GeneralForm extends Form
|
||||||
*/
|
*/
|
||||||
public function getConfiguration()
|
public function getConfiguration()
|
||||||
{
|
{
|
||||||
|
$config = array();
|
||||||
$values = $this->getValues();
|
$values = $this->getValues();
|
||||||
$globalData = array(
|
foreach ($values as $sectionAndPropertyName => $value) {
|
||||||
'language' => $values['language'],
|
list($section, $property) = explode('_', $sectionAndPropertyName);
|
||||||
'timezone' => $values['timezone'],
|
$config[$section][$property] = $value;
|
||||||
'modulePath' => $values['modulePath']
|
|
||||||
);
|
|
||||||
|
|
||||||
$preferencesData = array('type' => $values['preferences_type']);
|
|
||||||
if ($values['preferences_type'] === 'db') {
|
|
||||||
$preferencesData['resource'] = $values['preferences_resource'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Zend_Config(array('global' => $globalData, 'preferences' => $preferencesData));
|
return new Zend_Config($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +115,7 @@ class GeneralForm extends Form
|
||||||
|
|
||||||
return $this->createElement(
|
return $this->createElement(
|
||||||
'select',
|
'select',
|
||||||
'language',
|
'global_language',
|
||||||
array(
|
array(
|
||||||
'label' => t('Default Language'),
|
'label' => t('Default Language'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -144,7 +146,7 @@ class GeneralForm extends Form
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'timezone',
|
'global_timezone',
|
||||||
array(
|
array(
|
||||||
'label' => t('Default Application Timezone'),
|
'label' => t('Default Application Timezone'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -167,7 +169,7 @@ class GeneralForm extends Form
|
||||||
{
|
{
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'text',
|
'text',
|
||||||
'modulePath',
|
'global_modulePath',
|
||||||
array(
|
array(
|
||||||
'label' => t('Module Path'),
|
'label' => t('Module Path'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -232,4 +234,108 @@ class GeneralForm extends Form
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return form elements to setup the application's logging
|
||||||
|
*
|
||||||
|
* @param array $formData The data sent by the user
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getLoggingElements(array $formData)
|
||||||
|
{
|
||||||
|
$elements = array();
|
||||||
|
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'select',
|
||||||
|
'logging_level',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Logging Level'),
|
||||||
|
'helptext' => t('The maximum loglevel to emit.'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
0 => t('None'),
|
||||||
|
1 => t('Error'),
|
||||||
|
2 => t('Warning'),
|
||||||
|
3 => t('Information'),
|
||||||
|
4 => t('Debug')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'select',
|
||||||
|
'logging_type',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'class' => 'autosubmit',
|
||||||
|
'label' => t('Logging Type'),
|
||||||
|
'helptext' => t('The type of logging to utilize.'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'syslog' => 'Syslog',
|
||||||
|
'file' => t('File')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (false === isset($formData['logging_type']) || $formData['logging_type'] === 'syslog') {
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'text',
|
||||||
|
'logging_application',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Application Prefix'),
|
||||||
|
'helptext' => t('The name of the application by which to prefix syslog messages.'),
|
||||||
|
'value' => 'icingaweb',
|
||||||
|
'validators' => array(
|
||||||
|
array(
|
||||||
|
'Regex',
|
||||||
|
false,
|
||||||
|
array(
|
||||||
|
'pattern' => '/^[^\W]+$/',
|
||||||
|
'messages' => array(
|
||||||
|
'regexNotMatch' => 'The application prefix cannot contain any whitespaces.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'select',
|
||||||
|
'logging_facility',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Facility'),
|
||||||
|
'helptext' => t('The Syslog facility to utilize.'),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'LOG_USER' => 'LOG_USER'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} elseif ($formData['logging_type'] === 'file') {
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'text',
|
||||||
|
'logging_target',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Filepath'),
|
||||||
|
'helptext' => t('The logfile to write messages to.'),
|
||||||
|
'value' => $this->getDefaultLogDir(),
|
||||||
|
'validators' => array(new WritablePathValidator())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the default logging directory for type "file"
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getDefaultLogDir()
|
||||||
|
{
|
||||||
|
return realpath(Icinga::app()->getApplicationDir('../var/log/icingaweb.log'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,154 +0,0 @@
|
||||||
<?php
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
namespace Icinga\Form\Config;
|
|
||||||
|
|
||||||
use Icinga\Web\Form;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Web\Form\Validator\WritablePathValidator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form class for setting the application wide logging configuration
|
|
||||||
*/
|
|
||||||
class LoggingForm extends Form
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Initialize this logging configuration form
|
|
||||||
*
|
|
||||||
* Sets actually only the name.
|
|
||||||
*/
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
$this->setName('form_config_logging');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Form::createElements()
|
|
||||||
*/
|
|
||||||
public function createElements(array $formData)
|
|
||||||
{
|
|
||||||
$elements = array();
|
|
||||||
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'checkbox',
|
|
||||||
'enable',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Logging Enabled'),
|
|
||||||
'helptext' => t('Check this to enable logging.'),
|
|
||||||
'value' => isset($formData['enable']) ? $formData['enable'] : 0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'select',
|
|
||||||
'level',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Logging Level'),
|
|
||||||
'helptext' => t('The maximum loglevel to emit.'),
|
|
||||||
'value' => isset($formData['level']) ? $formData['level'] : 0,
|
|
||||||
'multiOptions' => array(
|
|
||||||
0 => t('Error'),
|
|
||||||
1 => t('Warning'),
|
|
||||||
2 => t('Information'),
|
|
||||||
3 => t('Debug')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'select',
|
|
||||||
'type',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'class' => 'autosubmit',
|
|
||||||
'label' => t('Logging Type'),
|
|
||||||
'helptext' => t('The type of logging to utilize.'),
|
|
||||||
'value' => isset($formData['type']) ? $formData['type'] : 'syslog',
|
|
||||||
'multiOptions' => array(
|
|
||||||
'file' => t('File'),
|
|
||||||
'syslog' => 'Syslog'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (false === isset($formData['type']) || $formData['type'] === 'syslog') {
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'text',
|
|
||||||
'application',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Application Prefix'),
|
|
||||||
'helptext' => t('The name of the application by which to prefix syslog messages.'),
|
|
||||||
'value' => isset($formData['application']) ? $formData['application'] : 'icingaweb',
|
|
||||||
'validators' => array(
|
|
||||||
array(
|
|
||||||
'Regex',
|
|
||||||
false,
|
|
||||||
array(
|
|
||||||
'pattern' => '/^[^\W]+$/',
|
|
||||||
'messages' => array(
|
|
||||||
'regexNotMatch' => 'The application prefix cannot contain any whitespaces.'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'select',
|
|
||||||
'facility',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Facility'),
|
|
||||||
'helptext' => t('The Syslog facility to utilize.'),
|
|
||||||
'value' => isset($formData['facility']) ? $formData['facility'] : 'LOG_USER',
|
|
||||||
'multiOptions' => array(
|
|
||||||
'LOG_USER' => 'LOG_USER'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} elseif ($formData['type'] === 'file') {
|
|
||||||
$elements[] = $this->createElement(
|
|
||||||
'text',
|
|
||||||
'target',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'label' => t('Filepath'),
|
|
||||||
'helptext' => t('The logfile to write messages to.'),
|
|
||||||
'value' => isset($formData['target']) ? $formData['target'] : $this->getDefaultLogDir(),
|
|
||||||
'validators' => array(new WritablePathValidator())
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Form::addSubmitButton()
|
|
||||||
*/
|
|
||||||
public function addSubmitButton()
|
|
||||||
{
|
|
||||||
$this->addElement(
|
|
||||||
'submit',
|
|
||||||
'btn_submit',
|
|
||||||
array(
|
|
||||||
'ignore' => true,
|
|
||||||
'label' => t('Save')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the default logging directory for type "file"
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getDefaultLogDir()
|
|
||||||
{
|
|
||||||
return realpath(Icinga::app()->getApplicationDir() . '/../var/log/icingaweb.log');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,6 +6,7 @@ namespace Icinga\Logger;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
|
use LogicException;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,10 +38,11 @@ class Logger
|
||||||
/**
|
/**
|
||||||
* The supported severities
|
* The supported severities
|
||||||
*/
|
*/
|
||||||
public static $ERROR = 0;
|
public static $NONE = 0;
|
||||||
public static $WARNING = 1;
|
public static $ERROR = 1;
|
||||||
public static $INFO = 2;
|
public static $WARNING = 2;
|
||||||
public static $DEBUG = 3;
|
public static $INFO = 3;
|
||||||
|
public static $DEBUG = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new logger object
|
* Create a new logger object
|
||||||
|
@ -90,9 +92,15 @@ class Logger
|
||||||
*
|
*
|
||||||
* @param string $message The message to write
|
* @param string $message The message to write
|
||||||
* @param int $severity The severity to use
|
* @param int $severity The severity to use
|
||||||
|
*
|
||||||
|
* @throws LogicException In case $severity equals self::$NONE
|
||||||
*/
|
*/
|
||||||
public function log($message, $severity)
|
public function log($message, $severity)
|
||||||
{
|
{
|
||||||
|
if ($severity === static::$NONE) {
|
||||||
|
throw new LogicException("`None' (0) is not a valid severity to log messages");
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->writer !== null && $this->verbosity >= $severity) {
|
if ($this->writer !== null && $this->verbosity >= $severity) {
|
||||||
$this->writer->log($severity, $message);
|
$this->writer->log($severity, $message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue