2014-09-01 16:16:56 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-09-01 16:16:56 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Icinga\Forms\Config\General;
|
2014-09-01 16:16:56 +02:00
|
|
|
|
2014-10-31 10:27:17 +01:00
|
|
|
use Icinga\Application\Logger;
|
2016-10-24 10:55:15 +02:00
|
|
|
use Icinga\Application\Logger\Writer\SyslogWriter;
|
2016-10-21 17:09:22 +02:00
|
|
|
use Icinga\Application\Platform;
|
2014-09-01 16:16:56 +02:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
2015-11-26 15:39:34 +01:00
|
|
|
/**
|
|
|
|
* Configuration form for logging options
|
|
|
|
*
|
|
|
|
* This form is not used directly but as subform for the {@link GeneralConfigForm}.
|
|
|
|
*/
|
2014-09-01 16:16:56 +02:00
|
|
|
class LoggingConfigForm extends Form
|
|
|
|
{
|
|
|
|
/**
|
2015-11-26 15:39:34 +01:00
|
|
|
* {@inheritdoc}
|
2014-09-01 16:16:56 +02:00
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('form_config_general_logging');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-26 15:39:34 +01:00
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @return $this
|
2014-09-01 16:16:56 +02:00
|
|
|
*/
|
|
|
|
public function createElements(array $formData)
|
|
|
|
{
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
2014-09-01 16:16:56 +02:00
|
|
|
'select',
|
2014-10-16 16:13:00 +02:00
|
|
|
'logging_log',
|
2014-09-01 16:16:56 +02:00
|
|
|
array(
|
|
|
|
'required' => true,
|
2014-09-17 09:43:10 +02:00
|
|
|
'autosubmit' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Logging Type'),
|
|
|
|
'description' => $this->translate('The type of logging to utilize.'),
|
2014-09-01 16:16:56 +02:00
|
|
|
'multiOptions' => array(
|
2016-10-19 15:34:57 +02:00
|
|
|
'php' => $this->translate('Webserver Log', 'app.config.logging.type'),
|
2014-09-01 16:16:56 +02:00
|
|
|
'syslog' => 'Syslog',
|
2015-01-19 11:26:23 +01:00
|
|
|
'file' => $this->translate('File', 'app.config.logging.type'),
|
|
|
|
'none' => $this->translate('None', 'app.config.logging.type')
|
2014-09-01 16:16:56 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2014-10-16 16:13:00 +02:00
|
|
|
if (! isset($formData['logging_log']) || $formData['logging_log'] !== 'none') {
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'logging_level',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Logging Level'),
|
|
|
|
'description' => $this->translate('The maximum logging level to emit.'),
|
2014-10-16 16:13:00 +02:00
|
|
|
'multiOptions' => array(
|
2015-01-19 11:26:23 +01:00
|
|
|
Logger::$levels[Logger::ERROR] => $this->translate('Error', 'app.config.logging.level'),
|
|
|
|
Logger::$levels[Logger::WARNING] => $this->translate('Warning', 'app.config.logging.level'),
|
|
|
|
Logger::$levels[Logger::INFO] => $this->translate('Information', 'app.config.logging.level'),
|
|
|
|
Logger::$levels[Logger::DEBUG] => $this->translate('Debug', 'app.config.logging.level')
|
2014-10-16 16:13:00 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-27 16:42:48 +01:00
|
|
|
if (! isset($formData['logging_log']) || in_array($formData['logging_log'], array('syslog', 'php'))) {
|
2014-10-16 16:13:00 +02:00
|
|
|
$this->addElement(
|
2014-09-01 16:16:56 +02:00
|
|
|
'text',
|
|
|
|
'logging_application',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('Application Prefix'),
|
|
|
|
'description' => $this->translate(
|
2016-10-19 15:34:57 +02:00
|
|
|
'The name of the application by which to prefix log messages.'
|
2015-01-19 11:26:23 +01:00
|
|
|
),
|
2015-03-06 09:49:15 +01:00
|
|
|
'requirement' => $this->translate('The application prefix must not contain whitespace.'),
|
2014-12-29 16:01:07 +01:00
|
|
|
'value' => 'icingaweb2',
|
2014-09-01 16:16:56 +02:00
|
|
|
'validators' => array(
|
|
|
|
array(
|
|
|
|
'Regex',
|
|
|
|
false,
|
|
|
|
array(
|
2015-12-09 17:56:22 +01:00
|
|
|
'pattern' => '/^\S+$/',
|
2014-09-01 16:16:56 +02:00
|
|
|
'messages' => array(
|
2015-02-12 08:54:56 +01:00
|
|
|
'regexNotMatch' => $this->translate(
|
|
|
|
'The application prefix must not contain whitespace.'
|
|
|
|
)
|
2014-09-01 16:16:56 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-10-21 17:09:22 +02:00
|
|
|
|
2017-11-27 16:42:48 +01:00
|
|
|
if (isset($formData['logging_log']) && $formData['logging_log'] === 'syslog') {
|
2016-11-04 17:19:35 +01:00
|
|
|
if (Platform::isWindows()) {
|
|
|
|
/* @see https://secure.php.net/manual/en/function.openlog.php */
|
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
|
|
|
'logging_facility',
|
|
|
|
array(
|
|
|
|
'value' => 'user',
|
|
|
|
'disabled' => true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$facilities = array_keys(SyslogWriter::$facilities);
|
|
|
|
$this->addElement(
|
|
|
|
'select',
|
|
|
|
'logging_facility',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => $this->translate('Facility'),
|
|
|
|
'description' => $this->translate('The syslog facility to utilize.'),
|
|
|
|
'value' => 'user',
|
|
|
|
'multiOptions' => array_combine($facilities, $facilities)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-10-21 17:09:22 +02:00
|
|
|
}
|
2014-10-16 16:13:00 +02:00
|
|
|
} elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') {
|
2014-09-03 12:21:31 +02:00
|
|
|
$this->addElement(
|
2014-09-01 16:16:56 +02:00
|
|
|
'text',
|
2014-10-16 16:13:00 +02:00
|
|
|
'logging_file',
|
2014-09-01 16:16:56 +02:00
|
|
|
array(
|
|
|
|
'required' => true,
|
2015-01-19 11:26:23 +01:00
|
|
|
'label' => $this->translate('File path'),
|
|
|
|
'description' => $this->translate('The full path to the log file to write messages to.'),
|
2014-12-29 16:02:40 +01:00
|
|
|
'value' => '/var/log/icingaweb2/icingaweb2.log',
|
2015-02-11 09:51:28 +01:00
|
|
|
'validators' => array('WritablePathValidator')
|
2014-09-01 16:16:56 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-09-03 12:21:31 +02:00
|
|
|
return $this;
|
2014-09-01 16:16:56 +02:00
|
|
|
}
|
|
|
|
}
|