...
 
Commits (6)
......@@ -35,7 +35,7 @@ class auditEvent extends simplePlugin
'ou' => get_ou('auditRDN'),
'mainAttr' => FALSE,
]],
'plSearchAttrs' => ['fdAuditAction','fdAuditAuthorDN','fdAuditObjectType',
'plSearchAttrs' => ['fdAuditAction','fdAuditAuthorDN','fdAuditAuthorIP','fdAuditObjectType',
'fdAuditObject','fdAuditAttributes','fdAuditResult'],
'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo())
......@@ -54,12 +54,13 @@ class auditEvent extends simplePlugin
_('Time'), _('Date and time this event happened'),
'fdAuditDateTime', TRUE
),
new DisplayLDAPAttribute(_('Action'), _('Action type'), 'fdAuditAction', TRUE),
new ObjectLinkAttribute(_('Author'), _('Action author'), 'fdAuditAuthorDN', TRUE, 'user'),
new DisplayLDAPAttribute(_('Object type'), _('Object type'), 'fdAuditObjectType', TRUE),
new DisplayLDAPAttribute(_('Object'), _('Target object'), 'fdAuditObject', TRUE),
new DisplayLDAPArrayAttribute(_('Attributes'), _('Target attributes'), 'fdAuditAttributes', FALSE),
new DisplayLDAPAttribute(_('Result'), _('Result or error'), 'fdAuditResult', FALSE),
new DisplayLDAPAttribute(_('Action'), _('Action type'), 'fdAuditAction', TRUE),
new ObjectLinkAttribute(_('Author'), _('Action author'), 'fdAuditAuthorDN', TRUE, 'user'),
new DisplayLDAPAttribute(_('Author IP'), _('Action author IP address'), 'fdAuditAuthorIP', FALSE),
new DisplayLDAPAttribute(_('Object type'), _('Object type'), 'fdAuditObjectType', TRUE),
new DisplayLDAPAttribute(_('Object'), _('Target object'), 'fdAuditObject', TRUE),
new DisplayLDAPArrayAttribute(_('Attributes'), _('Target attributes'), 'fdAuditAttributes', FALSE),
new DisplayLDAPAttribute(_('Result'), _('Result or error'), 'fdAuditResult', FALSE),
]
],
];
......@@ -68,7 +69,8 @@ class auditEvent extends simplePlugin
function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE, $attributesInfo = NULL)
{
parent::__construct($dn, $object, $parent, $mainTab, $attributesInfo);
$this->fdAuditId = random_int(0, PHP_INT_MAX);
$this->fdAuditId = random_int(0, PHP_INT_MAX);
$this->fdAuditAuthorIP = ($_SERVER['REMOTE_ADDR'] ?? '');
}
function compute_dn (): string
......
......@@ -29,6 +29,7 @@ class auditManagement extends management
['ObjectTypeColumn', []],
['LdapGeneralizedTimeColumn', ['attributes' => 'fdAuditDateTime', 'label' => 'Time']],
['LinkColumn', ['attributes' => 'fdAuditAuthorDN', 'label' => 'Author']],
['LinkColumn', ['attributes' => 'fdAuditAuthorIP', 'label' => 'IP']],
['LinkColumn', ['attributes' => 'fdAuditAction', 'label' => 'Action']],
['LinkColumn', ['attributes' => 'fdAuditObjectType', 'label' => 'Type']],
['LinkColumn', ['attributes' => 'fdAuditObject', 'label' => 'Target']],
......@@ -51,12 +52,22 @@ class auditManagement extends management
parent::__construct();
$this->filter->addElement(new DateFilterElement($this->filter, 'fdAuditDateTime', _('Date'), date('Y-m-d')));
$items = [];
foreach (logging::$validActions as $validAction) {
$items[$validAction] = [
'name' => $validAction,
'filter' => '(fdAuditAction='.$validAction.')',
];
}
$this->filter->addElement(new CheckBoxesFilterElement($this->filter, _('Action'), $items, '|'));
}
protected function setUpListing ()
{
/* Disable base mode and multi select */
$this->listing = new managementListing($this, FALSE, FALSE);
/* Newer events first */
$this->listing->setSortColumn(1, TRUE);
}
protected function configureActions ()
......
......@@ -57,9 +57,16 @@ attributetype ( 1.3.6.1.4.1.38414.60.1.8 NAME 'fdAuditId'
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27
SINGLE-VALUE)
attributetype ( 1.3.6.1.4.1.38414.60.1.9 NAME 'fdAuditAuthorIP'
DESC 'FusionDirectory - audit event author IP address'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
SINGLE-VALUE )
# Object Class
objectclass (1.3.6.1.4.1.38414.60.2.1 NAME 'fdAuditEvent'
DESC 'FusionDirectory - audit event'
MUST ( fdAuditDateTime $ fdAuditAction $ fdAuditAuthorDN $ fdAuditObject $ fdAuditObjectType )
MAY ( fdAuditAttributes $ fdAuditResult $ fdAuditId ) )
MAY ( fdAuditAttributes $ fdAuditResult $ fdAuditId $ fdAuditAuthorIP ) )
<?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 AuditLogAttribute extends OrderedArrayAttribute
{
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{
Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->edit_enabled = FALSE;
$this->attribute = FALSE;
$this->order = FALSE;
$this->setInLdap(FALSE);
}
protected function getAttributeArrayValue ($key, $event)
{
try {
$author = ['html' => objects::link($event['fdAuditAuthorDN'], 'user')];
} catch (FusionDirectoryException $e) {
$author = $event['fdAuditAuthorDN'];
}
try {
$time = static::formatDateDiff(LdapGeneralizedTime::fromString($event['fdAuditDateTime']));
} catch (Exception $e) {
$time = $event['fdAuditDateTime'];
}
return [
$event['fdAuditObjectType'],
$author,
$event['fdAuditAuthorIP'] ?? '',
$time,
$event['fdAuditResult'],
];
}
protected function genRowIcons ($key, $value)
{
return ['', 0];
}
public function htmlIds (): array
{
return [];
}
function renderButtons ()
{
return '';
}
public static function formatDateDiff ($date)
{
$now = new DateTime();
$interval = $now->diff($date);
if ($interval->y > 0) {
return sprintf(_('%s years(s) ago'), $interval->y);
}
if ($interval->m > 0) {
return sprintf(_('%s month(s) ago'), $interval->m);
}
if ($interval->d > 0) {
return sprintf(_('%s day(s) ago'), $interval->d);
}
if ($interval->h > 0) {
return sprintf(_('%s hour(s) ago'), $interval->h);
}
if ($interval->i > 0) {
return sprintf(_('%s minute(s) ago'), $interval->i);
}
if ($interval->s > 0) {
return sprintf(_('%s second(s) ago'), $interval->s);
}
return _('Now');
}
}
<?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' => [
'name' => _('Security audit'),
'class' => ['fullwidth'],
'attrs' => [
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'),
]);
$events = objects::ls(
'auditEvent',
[
'fdAuditDateTime' => 1,
'fdAuditAuthorDN' => 1,
'fdAuditAuthorIP' => 1,
'fdAuditObjectType' => 1,
'fdAuditObject' => 1,
'fdAuditAttributes' => '*',
'fdAuditResult' => 1
],
NULL,
'(&(|(fdAuditAction=security)(fdAuditAttributes=userPassword))(|(fdAuditObject='.$this->getUid().')(fdAuditObject='.$this->dn.')(fdAuditAuthorDN='.$this->dn.')))'
);
uasort(
$events,
function ($event1, $event2)
{
return $event2['fdAuditDateTime'] <=> $event1['fdAuditDateTime'];
}
);
$this->fdAuditSecurityLog = $events;
}
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 [];
}
}