summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:41:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:41:27 +0000
commitadc6ca9ee76d4b765c0e892fd452bc7e7ff28f4c (patch)
tree48747500fe157b459d74fac87e7114e6c846d215 /application
parentInitial commit. (diff)
downloadicingaweb2-module-audit-adc6ca9ee76d4b765c0e892fd452bc7e7ff28f4c.tar.xz
icingaweb2-module-audit-adc6ca9ee76d4b765c0e892fd452bc7e7ff28f4c.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/ConfigController.php23
-rw-r--r--application/controllers/LogController.php51
-rw-r--r--application/forms/Config/AuditLogConfigForm.php93
-rw-r--r--application/views/scripts/config/index.phtml6
-rw-r--r--application/views/scripts/log/index.phtml33
-rw-r--r--application/views/scripts/log/log-empty.phtml8
6 files changed, 214 insertions, 0 deletions
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 @@
+<?php
+
+/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Audit\Controllers;
+
+use Icinga\Web\Controller;
+use Icinga\Module\Audit\Forms\Config\AuditLogConfigForm;
+
+class ConfigController extends Controller
+{
+ public function indexAction()
+ {
+ $form = new AuditLogConfigForm();
+ $form->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 @@
+<?php
+
+/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Audit\Controllers;
+
+use Icinga\Data\ConfigObject;
+use Icinga\Protocol\File\FileReader;
+use Icinga\Web\Controller;
+
+class LogController extends Controller
+{
+ public function indexAction()
+ {
+ $this->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' => '/(?<!.)' // ^ can't handle multilines, don't ask *me* why this works
+ . '(?<datetime>[0-9]{4}(?:-[0-9]{2}){2}' // date
+ . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\+\-][0-9]{2}:[0-9]{2})?)' // time
+ . ' - (?<identity>.+)' // identity
+ . ' - (?<type>.+)' // type
+ . ' - (?<message>.+)' // 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 @@
+<?php
+
+/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Audit\Forms\Config;
+
+use Icinga\Forms\ConfigForm;
+
+class AuditLogConfigForm extends ConfigForm
+{
+ public function createElements(array $formData)
+ {
+ $this->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 @@
+<div class="controls">
+ <?= $this->tabs ?>
+</div>
+<div class="content">
+ <?= $this->form ?>
+</div>
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 @@
+<?php if (! $this->compact): ?>
+<div class="controls separated">
+ <?= $this->tabs ?>
+ <?= $this->paginator ?>
+ <div class="sort-controls-container">
+ <?= $this->limiter ?>
+ </div>
+</div>
+<?php endif ?>
+<div class="content">
+<?php if ($this->logData !== null): ?>
+ <table class="action">
+ <tbody>
+ <?php foreach ($this->logData as $value): ?>
+ <?php $datetime = new Datetime($value->datetime) ?>
+ <tr class="state">
+ <td style="width: 6em; text-align: center">
+ <?= $this->escape($datetime->format('d.m. H:i')) ?>
+ <br>
+ <?= $this->escape($value->type) ?>
+ </td>
+ <td style="width: 12em; text-align: center">
+ <?= $this->escape($value->identity) ?>
+ </td>
+ <td>
+ <?= nl2br($this->escape($value->message), false) ?>
+ </td>
+ </tr>
+ <?php endforeach ?>
+ </tbody>
+ </table>
+<?php endif ?>
+</div>
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 @@
+<?php if (! $this->compact): ?>
+<div class="controls">
+ <?= $this->tabs ?>
+</div>
+<?php endif ?>
+<div class="content">
+ <p><?= $this->escape($this->translate('No activity has been recorded yet.')) ?></p>
+</div>