class_auditSecurity.inc 3.35 KB
Newer Older
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
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)

  Copyright (C) 2018-2019  FusionDirectory

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/

class auditSecurity extends simplePlugin
{
  static function plInfo (): array
  {
    return [
      'plShortName'   => _('Security'),
      'plDescription' => _('Security audit'),
      'plObjectType'  => ['user'],
      'plSelfModify'  => TRUE,

      'plProvidedAcls'  => parent::generatePlProvidedAcls(static::getAttributesInfo())
    ];
  }

  static function getAttributesInfo (): array
  {
    return [
      'main' => [
40
41
42
        'name'  => _('Security audit'),
        'class' => ['fullwidth'],
        'attrs' => [
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
          new AuditLogAttribute(
            '', _('Important events involving your account'),
            'fdAuditSecurityLog'
          ),
        ],
      ],
    ];
  }

  function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE)
  {
    parent::__construct($dn, $object, $parent, $mainTab);

    $this->attributesAccess['fdAuditSecurityLog']->setHeaders([
      _('Event'),
      _('Author'),
      _('Origin'),
      _('Time'),
      _('Result'),
    ]);
63
64
  }

65
  protected function loadEvents ()
66
  {
67
68
69
    $events = objects::ls(
      'auditEvent',
      [
70
        'fdAuditAction'     => 1,
71
72
73
74
75
76
77
78
79
        'fdAuditDateTime'   => 1,
        'fdAuditAuthorDN'   => 1,
        'fdAuditAuthorIP'   => 1,
        'fdAuditObjectType' => 1,
        'fdAuditObject'     => 1,
        'fdAuditAttributes' => '*',
        'fdAuditResult'     => 1
      ],
      NULL,
80
81
82
83
84
85
86
87
88
89
90
91
92
93
      '(|'.
        '(&'.
          '(fdAuditAction=security)'.
          '(|'.
            '(fdAuditObject='.ldap_escape_f($this->getUid()).')'.
            '(fdAuditObject='.ldap_escape_f($this->dn).')'.
            '(fdAuditAuthorDN='.ldap_escape_f($this->dn).')'.
          ')'.
        ')'.
        '(&'.
          '(fdAuditAttributes=userPassword)'.
          '(fdAuditObject='.ldap_escape_f($this->dn).')'.
        ')'.
      ')'
94
95
96
97
98
99
100
101
102
103
104
    );
    uasort(
      $events,
      function ($event1, $event2)
      {
        return $event2['fdAuditDateTime'] <=> $event1['fdAuditDateTime'];
      }
    );
    $this->fdAuditSecurityLog = $events;
  }

105
106
107
108
109
110
  public function execute (): string
  {
    $this->loadEvents();
    return parent::execute();
  }

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  protected function getUid (): string
  {
    if (isset($this->parent)) {
      $baseobject = $this->parent->getBaseObject();
      return $baseobject->uid;
    }
    if (isset($this->attrs['uid'][0])) {
      return $this->attrs['uid'][0];
    }
    return '';
  }

  function check (): array
  {
    return [];
  }

  function save (): array
  {
    return [];
  }

  function remove (bool $fulldelete = FALSE): array
  {
    return [];
  }
}