From 968a206dff4631e1ecc8a489f7884d08648113aa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:13:17 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- application/controllers/ConfigController.php | 23 ++++++ application/controllers/LogController.php | 51 ++++++++++++++ application/forms/Config/AuditLogConfigForm.php | 93 +++++++++++++++++++++++++ application/views/scripts/config/index.phtml | 6 ++ application/views/scripts/log/index.phtml | 33 +++++++++ application/views/scripts/log/log-empty.phtml | 8 +++ 6 files changed, 214 insertions(+) create mode 100644 application/controllers/ConfigController.php create mode 100644 application/controllers/LogController.php create mode 100644 application/forms/Config/AuditLogConfigForm.php create mode 100644 application/views/scripts/config/index.phtml create mode 100644 application/views/scripts/log/index.phtml create mode 100644 application/views/scripts/log/log-empty.phtml (limited to 'application') diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php new file mode 100644 index 0000000..5e6a31a --- /dev/null +++ b/application/controllers/ConfigController.php @@ -0,0 +1,23 @@ +setIniConfig($this->Config()); + $form->setSubmitLabel($this->translate('Save Configuration')); + + $form->handleRequest(); + + $this->view->form = $form; + $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); + } +} diff --git a/application/controllers/LogController.php b/application/controllers/LogController.php new file mode 100644 index 0000000..fc5e17c --- /dev/null +++ b/application/controllers/LogController.php @@ -0,0 +1,51 @@ +assertPermission('audit/log'); + + if ($this->Config()->get('log', 'type') !== 'file') { + $this->httpNotFound('Page not found'); + } + + $this->getTabs()->add('audit/log', [ + 'active' => true, + 'label' => $this->translate('Audit Log'), + 'url' => 'audit/log', + ]); + + $file = $this->Config()->get('log', 'path', '/var/log/icingaweb2/audit.log'); + + if (! @file_exists($file)) { + $this->render('log-empty'); + + return; + } + + $resource = new FileReader(new ConfigObject([ + 'filename' => $file, + 'fields' => '/(?[0-9]{4}(?:-[0-9]{2}){2}' // date + . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time + . ' - (?.+)' // identity + . ' - (?.+)' // type + . ' - (?.+)' // message + . '(?!.)/msSU' // $ can't handle multilines, don't ... + ])); + + $this->view->logData = $resource->select()->order('DESC'); + + $this->setupLimitControl(); + $this->setupPaginationControl($this->view->logData); + } +} diff --git a/application/forms/Config/AuditLogConfigForm.php b/application/forms/Config/AuditLogConfigForm.php new file mode 100644 index 0000000..6e93b5a --- /dev/null +++ b/application/forms/Config/AuditLogConfigForm.php @@ -0,0 +1,93 @@ +addElement( + 'select', + 'log_type', + [ + 'autosubmit' => true, + 'label' => $this->translate('Standard Log'), + 'description' => $this->translate('Human-readable message log'), + 'multiOptions' => [ + 'none' => $this->translate('None', 'log.type'), + 'file' => $this->translate('File'), + 'syslog' => 'Syslog' + ] + ] + ); + if (isset($formData['log_type']) && $formData['log_type'] === 'file') { + $this->addElement( + 'text', + 'log_path', + [ + 'label' => $this->translate('Standard Log Path'), + 'description' => $this->translate('The full path to the standard log'), + 'placeholder' => '/var/log/icingaweb2/audit.log' + ] + ); + } elseif (isset($formData['log_type']) && $formData['log_type'] === 'syslog') { + $this->addElement( + 'text', + 'log_ident', + [ + 'label' => $this->translate('Ident'), + 'description' => $this->translate('The identifier to use for syslog messages'), + 'placeholder' => 'icingaweb2-audit' + ] + ); + $this->addElement( + 'select', + 'log_facility', + [ + 'label' => $this->translate('Facility'), + 'description' => $this->translate('The facility to send syslog messages to'), + 'multiOptions' => [ + '' => 'auth', // The default + 'authpriv' => 'authpriv', + 'user' => 'user', + 'local0' => 'local0', + 'local1' => 'local1', + 'local2' => 'local2', + 'local3' => 'local3', + 'local4' => 'local4', + 'local5' => 'local5', + 'local6' => 'local6', + 'local7' => 'local7' + ] + ] + ); + } + + $this->addElement( + 'checkbox', + 'stream_format', + [ + 'autosubmit' => true, + 'label' => $this->translate('JSON Log'), + 'description' => $this->translate('Machine-parsable JSON objects'), + 'checkedValue' => 'json', + 'uncheckedValue' => 'none' + ] + ); + if (isset($formData['stream_format']) && $formData['stream_format'] === 'json') { + $this->addElement( + 'text', + 'stream_path', + [ + 'label' => $this->translate('JSON Log Path'), + 'description' => $this->translate('The full path to the JSON log'), + 'placeholder' => '/var/log/icingaweb2/audit.json' + ] + ); + } + } +} diff --git a/application/views/scripts/config/index.phtml b/application/views/scripts/config/index.phtml new file mode 100644 index 0000000..71f2a34 --- /dev/null +++ b/application/views/scripts/config/index.phtml @@ -0,0 +1,6 @@ +
+ tabs ?> +
+
+ form ?> +
diff --git a/application/views/scripts/log/index.phtml b/application/views/scripts/log/index.phtml new file mode 100644 index 0000000..79b9239 --- /dev/null +++ b/application/views/scripts/log/index.phtml @@ -0,0 +1,33 @@ +compact): ?> +
+ tabs ?> + paginator ?> +
+ limiter ?> +
+
+ +
+logData !== null): ?> + + + logData as $value): ?> + datetime) ?> + + + + + + + +
+ escape($datetime->format('d.m. H:i')) ?> +
+ escape($value->type) ?> +
+ escape($value->identity) ?> + + escape($value->message), false) ?> +
+ +
diff --git a/application/views/scripts/log/log-empty.phtml b/application/views/scripts/log/log-empty.phtml new file mode 100644 index 0000000..901e6c4 --- /dev/null +++ b/application/views/scripts/log/log-empty.phtml @@ -0,0 +1,8 @@ +compact): ?> +
+ tabs ?> +
+ +
+

escape($this->translate('No activity has been recorded yet.')) ?>

+
-- cgit v1.2.3