summaryrefslogtreecommitdiffstats
path: root/application/controllers/LogController.php
blob: fc5e17cabec9bd33d4d469f95b0c5959c6b9bdf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
    }
}