aboutsummaryrefslogtreecommitdiffstats
path: root/apps/admin_audit/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/admin_audit/lib')
-rw-r--r--apps/admin_audit/lib/Actions/Action.php34
-rw-r--r--apps/admin_audit/lib/Actions/AppManagement.php61
-rw-r--r--apps/admin_audit/lib/Actions/Auth.php65
-rw-r--r--apps/admin_audit/lib/Actions/Console.php48
-rw-r--r--apps/admin_audit/lib/Actions/Files.php212
-rw-r--r--apps/admin_audit/lib/Actions/GroupManagement.php109
-rw-r--r--apps/admin_audit/lib/Actions/Security.php79
-rw-r--r--apps/admin_audit/lib/Actions/Sharing.php294
-rw-r--r--apps/admin_audit/lib/Actions/TagManagement.php27
-rw-r--r--apps/admin_audit/lib/Actions/Trashbin.php24
-rw-r--r--apps/admin_audit/lib/Actions/UserManagement.php146
-rw-r--r--apps/admin_audit/lib/Actions/Versions.php34
-rw-r--r--apps/admin_audit/lib/AppInfo/Application.php299
-rw-r--r--apps/admin_audit/lib/AuditLogger.php24
-rwxr-xr-xapps/admin_audit/lib/BackgroundJobs/Rotate.php24
-rw-r--r--apps/admin_audit/lib/IAuditLogger.php23
-rw-r--r--apps/admin_audit/lib/Listener/AppManagementEventListener.php60
-rw-r--r--apps/admin_audit/lib/Listener/AuthEventListener.php83
-rw-r--r--apps/admin_audit/lib/Listener/ConsoleEventListener.php42
-rw-r--r--apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php22
-rw-r--r--apps/admin_audit/lib/Listener/FileEventListener.php74
-rw-r--r--apps/admin_audit/lib/Listener/GroupManagementEventListener.php81
-rw-r--r--apps/admin_audit/lib/Listener/SecurityEventListener.php61
-rw-r--r--apps/admin_audit/lib/Listener/SharingEventListener.php291
-rw-r--r--apps/admin_audit/lib/Listener/UserManagementEventListener.php126
25 files changed, 1102 insertions, 1241 deletions
diff --git a/apps/admin_audit/lib/Actions/Action.php b/apps/admin_audit/lib/Actions/Action.php
index 238ed10e4d9..acd415d82ea 100644
--- a/apps/admin_audit/lib/Actions/Action.php
+++ b/apps/admin_audit/lib/Actions/Action.php
@@ -1,30 +1,9 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
@@ -53,16 +32,13 @@ class Action {
if (!isset($params[$element])) {
if ($obfuscateParameters) {
$this->logger->critical(
- '$params["'.$element.'"] was missing.',
+ '$params["' . $element . '"] was missing.',
['app' => 'admin_audit']
);
} else {
$this->logger->critical(
- sprintf(
- '$params["'.$element.'"] was missing. Transferred value: %s',
- print_r($params, true)
- ),
- ['app' => 'admin_audit']
+ '$params["' . $element . '"] was missing. Transferred value: {params}',
+ ['app' => 'admin_audit', 'params' => $params]
);
}
return;
diff --git a/apps/admin_audit/lib/Actions/AppManagement.php b/apps/admin_audit/lib/Actions/AppManagement.php
deleted file mode 100644
index d6bc7d2c61f..00000000000
--- a/apps/admin_audit/lib/Actions/AppManagement.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-class AppManagement extends Action {
-
- /**
- * @param string $appName
- */
- public function enableApp(string $appName): void {
- $this->log('App "%s" enabled',
- ['app' => $appName],
- ['app']
- );
- }
-
- /**
- * @param string $appName
- * @param string[] $groups
- */
- public function enableAppForGroups(string $appName, array $groups): void {
- $this->log('App "%1$s" enabled for groups: %2$s',
- ['app' => $appName, 'groups' => implode(', ', $groups)],
- ['app', 'groups']
- );
- }
-
- /**
- * @param string $appName
- */
- public function disableApp(string $appName): void {
- $this->log('App "%s" disabled',
- ['app' => $appName],
- ['app']
- );
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Auth.php b/apps/admin_audit/lib/Actions/Auth.php
deleted file mode 100644
index 27722d4a41c..00000000000
--- a/apps/admin_audit/lib/Actions/Auth.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-/**
- * Class Auth logs all auth related actions
- *
- * @package OCA\AdminAudit\Actions
- */
-class Auth extends Action {
- public function loginAttempt(array $params): void {
- $this->log(
- 'Login attempt: "%s"',
- $params,
- [
- 'uid',
- ],
- true
- );
- }
-
- public function loginSuccessful(array $params): void {
- $this->log(
- 'Login successful: "%s"',
- $params,
- [
- 'uid',
- ],
- true
- );
- }
-
- public function logout(array $params): void {
- $this->log(
- 'Logout occurred',
- [],
- []
- );
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Console.php b/apps/admin_audit/lib/Actions/Console.php
deleted file mode 100644
index 4635fbecbf3..00000000000
--- a/apps/admin_audit/lib/Actions/Console.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-class Console extends Action {
- /**
- * @param array $arguments
- */
- public function runCommand(array $arguments): void {
- if (!isset($arguments[1]) || $arguments[1] === '_completion') {
- // Don't log autocompletion
- return;
- }
-
- // Remove `./occ`
- array_shift($arguments);
-
- $this->log('Console command executed: %s',
- ['arguments' => implode(' ', $arguments)],
- ['arguments']
- );
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Files.php b/apps/admin_audit/lib/Actions/Files.php
index b02f9a4f02b..7be4a7cd581 100644
--- a/apps/admin_audit/lib/Actions/Files.php
+++ b/apps/admin_audit/lib/Actions/Files.php
@@ -1,32 +1,24 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
+use OC\Files\Node\NonExistingFile;
+use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
+use OCP\Files\Events\Node\BeforeNodeReadEvent;
+use OCP\Files\Events\Node\NodeCopiedEvent;
+use OCP\Files\Events\Node\NodeCreatedEvent;
+use OCP\Files\Events\Node\NodeRenamedEvent;
+use OCP\Files\Events\Node\NodeWrittenEvent;
+use OCP\Files\InvalidPathException;
+use OCP\Files\NotFoundException;
+use OCP\Server;
+use Psr\Log\LoggerInterface;
+
/**
* Class Files logs the actions to files
*
@@ -35,135 +27,149 @@ namespace OCA\AdminAudit\Actions;
class Files extends Action {
/**
* Logs file read actions
- *
- * @param array $params
*/
- public function read(array $params): void {
+ public function read(BeforeNodeReadEvent $event): void {
+ try {
+ $node = $event->getNode();
+ $params = [
+ 'id' => $node instanceof NonExistingFile ? null : $node->getId(),
+ 'path' => $node->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file read: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
$this->log(
- 'File accessed: "%s"',
+ 'File with id "%s" accessed: "%s"',
$params,
- [
- 'path',
- ]
+ array_keys($params)
);
}
/**
* Logs rename actions of files
- *
- * @param array $params
*/
- public function rename(array $params): void {
+ public function afterRename(NodeRenamedEvent $event): void {
+ try {
+ $target = $event->getTarget();
+ $source = $event->getSource();
+ $params = [
+ 'newid' => $target->getId(),
+ 'oldpath' => $source->getPath(),
+ 'newpath' => $target->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file rename: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
+
$this->log(
- 'File renamed: "%s" to "%s"',
+ 'File renamed with id "%s" from "%s" to "%s"',
$params,
- [
- 'oldpath',
- 'newpath',
- ]
+ array_keys($params)
);
}
+
/**
* Logs creation of files
- *
- * @param array $params
*/
- public function create(array $params): void {
- if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) {
+ public function create(NodeCreatedEvent $event): void {
+ try {
+ $params = [
+ 'id' => $event->getNode()->getId(),
+ 'path' => $event->getNode()->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file create: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
+ if ($params['path'] === '/' || $params['path'] === '') {
return;
}
-
$this->log(
- 'File created: "%s"',
+ 'File with id "%s" created: "%s"',
$params,
- [
- 'path',
- ]
+ array_keys($params)
);
}
/**
* Logs copying of files
- *
- * @param array $params
*/
- public function copy(array $params): void {
+ public function copy(NodeCopiedEvent $event): void {
+ try {
+ $params = [
+ 'oldid' => $event->getSource()->getId(),
+ 'newid' => $event->getTarget()->getId(),
+ 'oldpath' => $event->getSource()->getPath(),
+ 'newpath' => $event->getTarget()->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file copy: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
$this->log(
- 'File copied: "%s" to "%s"',
+ 'File id copied from: "%s" to "%s", path from "%s" to "%s"',
$params,
- [
- 'oldpath',
- 'newpath',
- ]
+ array_keys($params)
);
}
/**
* Logs writing of files
- *
- * @param array $params
*/
- public function write(array $params): void {
- if ($params['path'] === '/' || $params['path'] === '' || $params['path'] === null) {
+ public function write(NodeWrittenEvent $event): void {
+ $node = $event->getNode();
+ try {
+ $params = [
+ 'id' => $node->getId(),
+ 'path' => $node->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file write: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
+ if ($params['path'] === '/' || $params['path'] === '') {
return;
}
$this->log(
- 'File written to: "%s"',
- $params,
- [
- 'path',
- ]
- );
- }
-
- /**
- * Logs update of files
- *
- * @param array $params
- */
- public function update(array $params): void {
- $this->log(
- 'File updated: "%s"',
+ 'File with id "%s" written to: "%s"',
$params,
- [
- 'path',
- ]
+ array_keys($params)
);
}
/**
* Logs deletions of files
- *
- * @param array $params
*/
- public function delete(array $params): void {
- $this->log(
- 'File deleted: "%s"',
- $params,
- [
- 'path',
- ]
- );
- }
-
- /**
- * Logs preview access to a file
- *
- * @param array $params
- */
- public function preview(array $params): void {
+ public function delete(BeforeNodeDeletedEvent $event): void {
+ try {
+ $params = [
+ 'id' => $event->getNode()->getId(),
+ 'path' => $event->getNode()->getPath(),
+ ];
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file delete: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
$this->log(
- 'Preview accessed: "%s" (width: "%s", height: "%s" crop: "%s", mode: "%s")',
+ 'File with id "%s" deleted: "%s"',
$params,
- [
- 'path',
- 'width',
- 'height',
- 'crop',
- 'mode'
- ]
+ array_keys($params)
);
}
}
diff --git a/apps/admin_audit/lib/Actions/GroupManagement.php b/apps/admin_audit/lib/Actions/GroupManagement.php
deleted file mode 100644
index e79b86bb88b..00000000000
--- a/apps/admin_audit/lib/Actions/GroupManagement.php
+++ /dev/null
@@ -1,109 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Roger Szabo <roger.szabo@web.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-use OCP\IGroup;
-use OCP\IUser;
-
-/**
- * Class GroupManagement logs all group manager related events
- *
- * @package OCA\AdminAudit\Actions
- */
-class GroupManagement extends Action {
-
- /**
- * log add user to group event
- *
- * @param IGroup $group
- * @param IUser $user
- */
- public function addUser(IGroup $group, IUser $user): void {
- $this->log('User "%s" added to group "%s"',
- [
- 'group' => $group->getGID(),
- 'user' => $user->getUID()
- ],
- [
- 'user', 'group'
- ]
- );
- }
-
- /**
- * log remove user from group event
- *
- * @param IGroup $group
- * @param IUser $user
- */
- public function removeUser(IGroup $group, IUser $user): void {
- $this->log('User "%s" removed from group "%s"',
- [
- 'group' => $group->getGID(),
- 'user' => $user->getUID()
- ],
- [
- 'user', 'group'
- ]
- );
- }
-
- /**
- * log create group to group event
- *
- * @param IGroup $group
- */
- public function createGroup(IGroup $group): void {
- $this->log('Group created: "%s"',
- [
- 'group' => $group->getGID()
- ],
- [
- 'group'
- ]
- );
- }
-
- /**
- * log delete group to group event
- *
- * @param IGroup $group
- */
- public function deleteGroup(IGroup $group): void {
- $this->log('Group deleted: "%s"',
- [
- 'group' => $group->getGID()
- ],
- [
- 'group'
- ]
- );
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Security.php b/apps/admin_audit/lib/Actions/Security.php
deleted file mode 100644
index 17cf0c3c2b9..00000000000
--- a/apps/admin_audit/lib/Actions/Security.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-use OCP\Authentication\TwoFactorAuth\IProvider;
-use OCP\IUser;
-
-/**
- * Class Sharing logs the sharing actions
- *
- * @package OCA\AdminAudit\Actions
- */
-class Security extends Action {
- /**
- * Logs failed twofactor challenge
- */
- public function twofactorFailed(IUser $user, IProvider $provider): void {
- $params = [
- 'displayName' => $user->getDisplayName(),
- 'uid' => $user->getUID(),
- 'provider' => $provider->getDisplayName(),
- ];
-
- $this->log(
- 'Failed two factor attempt by user %s (%s) with provider %s',
- $params,
- [
- 'displayName',
- 'uid',
- 'provider',
- ]
- );
- }
-
- /**
- * Logs successful twofactor challenge
- */
- public function twofactorSuccess(IUser $user, IProvider $provider): void {
- $params = [
- 'displayName' => $user->getDisplayName(),
- 'uid' => $user->getUID(),
- 'provider' => $provider->getDisplayName(),
- ];
-
- $this->log(
- 'Successful two factor attempt by user %s (%s) with provider %s',
- $params,
- [
- 'displayName',
- 'uid',
- 'provider',
- ]
- );
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Sharing.php b/apps/admin_audit/lib/Actions/Sharing.php
index 5cb3602deae..8f021d5f210 100644
--- a/apps/admin_audit/lib/Actions/Sharing.php
+++ b/apps/admin_audit/lib/Actions/Sharing.php
@@ -1,308 +1,18 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sascha Wiswedel <sascha.wiswedel@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
-use OCP\Share\IShare;
-
/**
* Class Sharing logs the sharing actions
*
* @package OCA\AdminAudit\Actions
*/
class Sharing extends Action {
- /**
- * Logs sharing of data
- *
- * @param array $params
- */
- public function shared(array $params): void {
- if ($params['shareType'] === IShare::TYPE_LINK) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_USER) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_DECK) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
- $this->log(
- 'The %s "%s" with ID "%s" has been shared to the ScienceMesh user "%s" with permissions "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'path',
- 'itemSource',
- 'shareWith',
- 'permissions',
- 'id',
- ]
- );
- }
- }
-
- /**
- * Logs unsharing of data
- *
- * @param array $params
- */
- public function unshare(array $params): void {
- if ($params['shareType'] === IShare::TYPE_LINK) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_USER) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_GROUP) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_ROOM) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_EMAIL) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_CIRCLE) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_REMOTE) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_REMOTE_GROUP) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_DECK) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- } elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
- $this->log(
- 'The %s "%s" with ID "%s" has been unshared from the ScienceMesh user "%s" (Share ID: %s)',
- $params,
- [
- 'itemType',
- 'fileTarget',
- 'itemSource',
- 'shareWith',
- 'id',
- ]
- );
- }
- }
/**
* Logs the updating of permission changes for shares
diff --git a/apps/admin_audit/lib/Actions/TagManagement.php b/apps/admin_audit/lib/Actions/TagManagement.php
new file mode 100644
index 00000000000..a167017aec3
--- /dev/null
+++ b/apps/admin_audit/lib/Actions/TagManagement.php
@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+/*!
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\AdminAudit\Actions;
+
+use OCP\SystemTag\ISystemTag;
+
+class TagManagement extends Action {
+ /**
+ * @param ISystemTag $tag newly created tag
+ */
+ public function createTag(ISystemTag $tag): void {
+ $this->log('System tag "%s" (%s, %s) created',
+ [
+ 'name' => $tag->getName(),
+ 'visbility' => $tag->isUserVisible() ? 'visible' : 'invisible',
+ 'assignable' => $tag->isUserAssignable() ? 'user assignable' : 'system only',
+ ],
+ ['name', 'visibility', 'assignable']
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Actions/Trashbin.php b/apps/admin_audit/lib/Actions/Trashbin.php
index ab2863399e5..c1e994da3a5 100644
--- a/apps/admin_audit/lib/Actions/Trashbin.php
+++ b/apps/admin_audit/lib/Actions/Trashbin.php
@@ -1,29 +1,9 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
diff --git a/apps/admin_audit/lib/Actions/UserManagement.php b/apps/admin_audit/lib/Actions/UserManagement.php
deleted file mode 100644
index c66793d8a5b..00000000000
--- a/apps/admin_audit/lib/Actions/UserManagement.php
+++ /dev/null
@@ -1,146 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\AdminAudit\Actions;
-
-use OCP\IUser;
-
-/**
- * Class UserManagement logs all user management related actions.
- *
- * @package OCA\AdminAudit\Actions
- */
-class UserManagement extends Action {
- /**
- * Log creation of users
- *
- * @param array $params
- */
- public function create(array $params): void {
- $this->log(
- 'User created: "%s"',
- $params,
- [
- 'uid',
- ]
- );
- }
-
- /**
- * Log assignments of users (typically user backends)
- *
- * @param string $uid
- */
- public function assign(string $uid): void {
- $this->log(
- 'UserID assigned: "%s"',
- [ 'uid' => $uid ],
- [ 'uid' ]
- );
- }
-
- /**
- * Log deletion of users
- *
- * @param array $params
- */
- public function delete(array $params): void {
- $this->log(
- 'User deleted: "%s"',
- $params,
- [
- 'uid',
- ]
- );
- }
-
- /**
- * Log unassignments of users (typically user backends, no data removed)
- *
- * @param string $uid
- */
- public function unassign(string $uid): void {
- $this->log(
- 'UserID unassigned: "%s"',
- [ 'uid' => $uid ],
- [ 'uid' ]
- );
- }
-
- /**
- * Log enabling of users
- *
- * @param array $params
- */
- public function change(array $params): void {
- switch ($params['feature']) {
- case 'enabled':
- $this->log(
- $params['value'] === true
- ? 'User enabled: "%s"'
- : 'User disabled: "%s"',
- ['user' => $params['user']->getUID()],
- [
- 'user',
- ]
- );
- break;
- case 'eMailAddress':
- $this->log(
- 'Email address changed for user %s',
- ['user' => $params['user']->getUID()],
- [
- 'user',
- ]
- );
- break;
- }
- }
-
- /**
- * Logs changing of the user scope
- *
- * @param IUser $user
- */
- public function setPassword(IUser $user): void {
- if ($user->getBackendClassName() === 'Database') {
- $this->log(
- 'Password of user "%s" has been changed',
- [
- 'user' => $user->getUID(),
- ],
- [
- 'user',
- ]
- );
- }
- }
-}
diff --git a/apps/admin_audit/lib/Actions/Versions.php b/apps/admin_audit/lib/Actions/Versions.php
index acd3b0e77e7..b3fdefd011d 100644
--- a/apps/admin_audit/lib/Actions/Versions.php
+++ b/apps/admin_audit/lib/Actions/Versions.php
@@ -1,43 +1,13 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Bjoern Schiessle <bjoern@schiessle.org>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Actions;
class Versions extends Action {
- public function rollback(array $params): void {
- $this->log('Version "%s" of "%s" was restored.',
- [
- 'version' => $params['revision'],
- 'path' => $params['path']
- ],
- ['version', 'path']
- );
- }
-
public function delete(array $params): void {
$this->log('Version "%s" was deleted.',
['path' => $params['path']],
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php
index 860b7b70ae6..63a1d065bc8 100644
--- a/apps/admin_audit/lib/AppInfo/Application.php
+++ b/apps/admin_audit/lib/AppInfo/Application.php
@@ -3,76 +3,75 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author GrayFix <grayfix@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Tiago Flores <tiago.flores@yahoo.com.br>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
+
namespace OCA\AdminAudit\AppInfo;
-use OC\Files\Filesystem;
-use OC\Group\Manager as GroupManager;
-use OC\User\Session as UserSession;
-use OCA\AdminAudit\Actions\AppManagement;
use OCA\AdminAudit\Actions\Auth;
use OCA\AdminAudit\Actions\Console;
use OCA\AdminAudit\Actions\Files;
-use OCA\AdminAudit\Actions\GroupManagement;
-use OCA\AdminAudit\Actions\Security;
use OCA\AdminAudit\Actions\Sharing;
+use OCA\AdminAudit\Actions\TagManagement;
use OCA\AdminAudit\Actions\Trashbin;
-use OCA\AdminAudit\Actions\UserManagement;
use OCA\AdminAudit\Actions\Versions;
use OCA\AdminAudit\AuditLogger;
use OCA\AdminAudit\IAuditLogger;
+use OCA\AdminAudit\Listener\AppManagementEventListener;
+use OCA\AdminAudit\Listener\AuthEventListener;
+use OCA\AdminAudit\Listener\ConsoleEventListener;
use OCA\AdminAudit\Listener\CriticalActionPerformedEventListener;
-use OCP\App\ManagerEvent;
+use OCA\AdminAudit\Listener\FileEventListener;
+use OCA\AdminAudit\Listener\GroupManagementEventListener;
+use OCA\AdminAudit\Listener\SecurityEventListener;
+use OCA\AdminAudit\Listener\SharingEventListener;
+use OCA\AdminAudit\Listener\UserManagementEventListener;
+use OCA\Files_Versions\Events\VersionRestoredEvent;
+use OCP\App\Events\AppDisableEvent;
+use OCP\App\Events\AppEnableEvent;
+use OCP\App\Events\AppUpdateEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\Authentication\Events\AnyLoginFailedEvent;
use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
use OCP\Console\ConsoleEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
+use OCP\Files\Events\Node\BeforeNodeReadEvent;
+use OCP\Files\Events\Node\NodeCopiedEvent;
+use OCP\Files\Events\Node\NodeCreatedEvent;
+use OCP\Files\Events\Node\NodeRenamedEvent;
+use OCP\Files\Events\Node\NodeWrittenEvent;
+use OCP\Group\Events\GroupCreatedEvent;
+use OCP\Group\Events\GroupDeletedEvent;
+use OCP\Group\Events\UserAddedEvent;
+use OCP\Group\Events\UserRemovedEvent;
use OCP\IConfig;
-use OCP\IGroupManager;
-use OCP\IUserSession;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use OCP\Log\ILogFactory;
use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Share;
+use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\Events\ShareDeletedEvent;
+use OCP\SystemTag\ManagerEvent;
+use OCP\User\Events\BeforeUserLoggedInEvent;
+use OCP\User\Events\BeforeUserLoggedOutEvent;
+use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\UserChangedEvent;
+use OCP\User\Events\UserCreatedEvent;
+use OCP\User\Events\UserDeletedEvent;
+use OCP\User\Events\UserIdAssignedEvent;
+use OCP\User\Events\UserIdUnassignedEvent;
+use OCP\User\Events\UserLoggedInEvent;
+use OCP\User\Events\UserLoggedInWithCookieEvent;
use OCP\Util;
use Psr\Container\ContainerInterface;
-use Psr\Log\LoggerInterface;
class Application extends App implements IBootstrap {
- /** @var LoggerInterface */
- protected $logger;
-
public function __construct() {
parent::__construct('admin_audit');
}
@@ -83,6 +82,47 @@ class Application extends App implements IBootstrap {
});
$context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class);
+
+ // User management events
+ $context->registerEventListener(UserCreatedEvent::class, UserManagementEventListener::class);
+ $context->registerEventListener(UserDeletedEvent::class, UserManagementEventListener::class);
+ $context->registerEventListener(UserChangedEvent::class, UserManagementEventListener::class);
+ $context->registerEventListener(PasswordUpdatedEvent::class, UserManagementEventListener::class);
+ $context->registerEventListener(UserIdAssignedEvent::class, UserManagementEventListener::class);
+ $context->registerEventListener(UserIdUnassignedEvent::class, UserManagementEventListener::class);
+
+ // Group management events
+ $context->registerEventListener(UserAddedEvent::class, GroupManagementEventListener::class);
+ $context->registerEventListener(UserRemovedEvent::class, GroupManagementEventListener::class);
+ $context->registerEventListener(GroupCreatedEvent::class, GroupManagementEventListener::class);
+ $context->registerEventListener(GroupDeletedEvent::class, GroupManagementEventListener::class);
+
+ // Sharing events
+ $context->registerEventListener(ShareCreatedEvent::class, SharingEventListener::class);
+ $context->registerEventListener(ShareDeletedEvent::class, SharingEventListener::class);
+
+ // Auth events
+ $context->registerEventListener(BeforeUserLoggedInEvent::class, AuthEventListener::class);
+ $context->registerEventListener(UserLoggedInWithCookieEvent::class, AuthEventListener::class);
+ $context->registerEventListener(UserLoggedInEvent::class, AuthEventListener::class);
+ $context->registerEventListener(BeforeUserLoggedOutEvent::class, AuthEventListener::class);
+ $context->registerEventListener(AnyLoginFailedEvent::class, AuthEventListener::class);
+
+ // File events
+ $context->registerEventListener(BeforePreviewFetchedEvent::class, FileEventListener::class);
+ $context->registerEventListener(VersionRestoredEvent::class, FileEventListener::class);
+
+ // Security events
+ $context->registerEventListener(TwoFactorProviderChallengePassed::class, SecurityEventListener::class);
+ $context->registerEventListener(TwoFactorProviderChallengeFailed::class, SecurityEventListener::class);
+
+ // App management events
+ $context->registerEventListener(AppEnableEvent::class, AppManagementEventListener::class);
+ $context->registerEventListener(AppDisableEvent::class, AppManagementEventListener::class);
+ $context->registerEventListener(AppUpdateEvent::class, AppManagementEventListener::class);
+
+ // Console events
+ $context->registerEventListener(ConsoleEvent::class, ConsoleEventListener::class);
}
public function boot(IBootContext $context): void {
@@ -93,166 +133,87 @@ class Application extends App implements IBootstrap {
* TODO: once the hooks are migrated to lazy events, this should be done
* in \OCA\AdminAudit\AppInfo\Application::register
*/
- $this->registerHooks($logger, $context->getServerContainer());
+ $this->registerLegacyHooks($logger, $context->getServerContainer());
}
/**
* Register hooks in order to log them
*/
- private function registerHooks(IAuditLogger $logger,
- ContainerInterface $serverContainer): void {
- $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class));
- $this->groupHooks($logger, $serverContainer->get(IGroupManager::class));
- $this->authHooks($logger);
-
-
+ private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $serverContainer): void {
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $serverContainer->get(IEventDispatcher::class);
- $this->consoleHooks($logger, $eventDispatcher);
- $this->appHooks($logger, $eventDispatcher);
-
- $this->sharingHooks($logger);
-
+ $this->sharingLegacyHooks($logger);
$this->fileHooks($logger, $eventDispatcher);
$this->trashbinHooks($logger);
$this->versionsHooks($logger);
-
- $this->securityHooks($logger, $eventDispatcher);
- }
-
- private function userManagementHooks(IAuditLogger $logger,
- IUserSession $userSession): void {
- $userActions = new UserManagement($logger);
-
- Util::connectHook('OC_User', 'post_createUser', $userActions, 'create');
- Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete');
- Util::connectHook('OC_User', 'changeUser', $userActions, 'change');
-
- assert($userSession instanceof UserSession);
- $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
- $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
- $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
+ $this->tagHooks($logger, $eventDispatcher);
}
- private function groupHooks(IAuditLogger $logger,
- IGroupManager $groupManager): void {
- $groupActions = new GroupManagement($logger);
-
- assert($groupManager instanceof GroupManager);
- $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']);
- $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']);
- $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']);
- $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']);
- }
-
- private function sharingHooks(IAuditLogger $logger): void {
+ private function sharingLegacyHooks(IAuditLogger $logger): void {
$shareActions = new Sharing($logger);
- Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared');
- Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare');
- Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare');
Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions');
Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword');
Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate');
Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
}
- private function authHooks(IAuditLogger $logger): void {
- $authActions = new Auth($logger);
-
- Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
- Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful');
- Util::connectHook('OC_User', 'logout', $authActions, 'logout');
- }
-
- private function appHooks(IAuditLogger $logger,
- IEventDispatcher $eventDispatcher): void {
- $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) {
- $appActions = new AppManagement($logger);
- $appActions->enableApp($event->getAppID());
- });
- $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) {
- $appActions = new AppManagement($logger);
- $appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
- });
- $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) {
- $appActions = new AppManagement($logger);
- $appActions->disableApp($event->getAppID());
- });
- }
-
- private function consoleHooks(IAuditLogger $logger,
+ private function tagHooks(IAuditLogger $logger,
IEventDispatcher $eventDispatcher): void {
- $eventDispatcher->addListener(ConsoleEvent::class, function (ConsoleEvent $event) use ($logger) {
- $appActions = new Console($logger);
- $appActions->runCommand($event->getArguments());
+ $eventDispatcher->addListener(ManagerEvent::EVENT_CREATE, function (ManagerEvent $event) use ($logger): void {
+ $tagActions = new TagManagement($logger);
+ $tagActions->createTag($event->getTag());
});
}
- private function fileHooks(IAuditLogger $logger,
- IEventDispatcher $eventDispatcher): void {
+ private function fileHooks(IAuditLogger $logger, IEventDispatcher $eventDispatcher): void {
$fileActions = new Files($logger);
+
$eventDispatcher->addListener(
- BeforePreviewFetchedEvent::class,
- function (BeforePreviewFetchedEvent $event) use ($fileActions) {
- $file = $event->getNode();
- $fileActions->preview([
- 'path' => mb_substr($file->getInternalPath(), 5),
- 'width' => $event->getWidth(),
- 'height' => $event->getHeight(),
- 'crop' => $event->isCrop(),
- 'mode' => $event->getMode()
- ]);
+ NodeRenamedEvent::class,
+ function (NodeRenamedEvent $event) use ($fileActions): void {
+ $fileActions->afterRename($event);
}
);
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_post_rename,
- $fileActions,
- 'rename'
- );
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_post_create,
- $fileActions,
- 'create'
- );
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_post_copy,
- $fileActions,
- 'copy'
+ $eventDispatcher->addListener(
+ NodeCreatedEvent::class,
+ function (NodeCreatedEvent $event) use ($fileActions): void {
+ $fileActions->create($event);
+ }
);
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_post_write,
- $fileActions,
- 'write'
+
+ $eventDispatcher->addListener(
+ NodeCopiedEvent::class,
+ function (NodeCopiedEvent $event) use ($fileActions): void {
+ $fileActions->copy($event);
+ }
);
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_post_update,
- $fileActions,
- 'update'
+
+ $eventDispatcher->addListener(
+ NodeWrittenEvent::class,
+ function (NodeWrittenEvent $event) use ($fileActions): void {
+ $fileActions->write($event);
+ }
);
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_read,
- $fileActions,
- 'read'
+
+ $eventDispatcher->addListener(
+ BeforeNodeReadEvent::class,
+ function (BeforeNodeReadEvent $event) use ($fileActions): void {
+ $fileActions->read($event);
+ }
);
- Util::connectHook(
- Filesystem::CLASSNAME,
- Filesystem::signal_delete,
- $fileActions,
- 'delete'
+
+ $eventDispatcher->addListener(
+ BeforeNodeDeletedEvent::class,
+ function (BeforeNodeDeletedEvent $event) use ($fileActions): void {
+ $fileActions->delete($event);
+ }
);
}
private function versionsHooks(IAuditLogger $logger): void {
$versionsActions = new Versions($logger);
- Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete');
}
@@ -261,16 +222,4 @@ class Application extends App implements IBootstrap {
Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
}
-
- private function securityHooks(IAuditLogger $logger,
- IEventDispatcher $eventDispatcher): void {
- $eventDispatcher->addListener(TwoFactorProviderChallengePassed::class, function (TwoFactorProviderChallengePassed $event) use ($logger) {
- $security = new Security($logger);
- $security->twofactorSuccess($event->getUser(), $event->getProvider());
- });
- $eventDispatcher->addListener(TwoFactorProviderChallengeFailed::class, function (TwoFactorProviderChallengeFailed $event) use ($logger) {
- $security = new Security($logger);
- $security->twofactorFailed($event->getUser(), $event->getProvider());
- });
- }
}
diff --git a/apps/admin_audit/lib/AuditLogger.php b/apps/admin_audit/lib/AuditLogger.php
index fa33e828bfd..a622794dc08 100644
--- a/apps/admin_audit/lib/AuditLogger.php
+++ b/apps/admin_audit/lib/AuditLogger.php
@@ -1,24 +1,10 @@
<?php
+
+declare(strict_types=1);
+
/**
- * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
- *
- * @author Carl Schwan <carl@carlschwan.eu>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit;
diff --git a/apps/admin_audit/lib/BackgroundJobs/Rotate.php b/apps/admin_audit/lib/BackgroundJobs/Rotate.php
index 4482a45df4e..deb0f4a922c 100755
--- a/apps/admin_audit/lib/BackgroundJobs/Rotate.php
+++ b/apps/admin_audit/lib/BackgroundJobs/Rotate.php
@@ -1,29 +1,9 @@
<?php
declare(strict_types=1);
-
/**
- * @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\BackgroundJobs;
diff --git a/apps/admin_audit/lib/IAuditLogger.php b/apps/admin_audit/lib/IAuditLogger.php
index b55d36b942d..f17afa6852e 100644
--- a/apps/admin_audit/lib/IAuditLogger.php
+++ b/apps/admin_audit/lib/IAuditLogger.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
- *
- * @author Carl Schwan <carl@carlschwan.eu>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OCA\AdminAudit;
use Psr\Log\LoggerInterface;
diff --git a/apps/admin_audit/lib/Listener/AppManagementEventListener.php b/apps/admin_audit/lib/Listener/AppManagementEventListener.php
new file mode 100644
index 00000000000..c20bdd481d6
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/AppManagementEventListener.php
@@ -0,0 +1,60 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\App\Events\AppDisableEvent;
+use OCP\App\Events\AppEnableEvent;
+use OCP\App\Events\AppUpdateEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/**
+ * @template-implements IEventListener<AppEnableEvent|AppDisableEvent|AppUpdateEvent>
+ */
+class AppManagementEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof AppEnableEvent) {
+ $this->appEnable($event);
+ } elseif ($event instanceof AppDisableEvent) {
+ $this->appDisable($event);
+ } elseif ($event instanceof AppUpdateEvent) {
+ $this->appUpdate($event);
+ }
+ }
+
+ private function appEnable(AppEnableEvent $event): void {
+ if (empty($event->getGroupIds())) {
+ $this->log('App "%s" enabled',
+ ['app' => $event->getAppId()],
+ ['app']
+ );
+ } else {
+ $this->log('App "%1$s" enabled for groups: %2$s',
+ ['app' => $event->getAppId(), 'groups' => implode(', ', $event->getGroupIds())],
+ ['app', 'groups']
+ );
+ }
+ }
+
+ private function appDisable(AppDisableEvent $event): void {
+ $this->log('App "%s" disabled',
+ ['app' => $event->getAppId()],
+ ['app']
+ );
+ }
+
+ private function appUpdate(AppUpdateEvent $event): void {
+ $this->log('App "%s" updated',
+ ['app' => $event->getAppId()],
+ ['app']
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/AuthEventListener.php b/apps/admin_audit/lib/Listener/AuthEventListener.php
new file mode 100644
index 00000000000..88be8555a4d
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/AuthEventListener.php
@@ -0,0 +1,83 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\Authentication\Events\AnyLoginFailedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\User\Events\BeforeUserLoggedInEvent;
+use OCP\User\Events\BeforeUserLoggedOutEvent;
+use OCP\User\Events\UserLoggedInEvent;
+use OCP\User\Events\UserLoggedInWithCookieEvent;
+
+/**
+ * @template-implements IEventListener<BeforeUserLoggedInEvent|UserLoggedInWithCookieEvent|UserLoggedInEvent|BeforeUserLoggedOutEvent|AnyLoginFailedEvent>
+ */
+class AuthEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof BeforeUserLoggedInEvent) {
+ $this->beforeUserLoggedIn($event);
+ } elseif ($event instanceof UserLoggedInWithCookieEvent || $event instanceof UserLoggedInEvent) {
+ $this->userLoggedIn($event);
+ } elseif ($event instanceof BeforeUserLoggedOutEvent) {
+ $this->beforeUserLogout($event);
+ } elseif ($event instanceof AnyLoginFailedEvent) {
+ $this->anyLoginFailed($event);
+ }
+ }
+
+ private function beforeUserLoggedIn(BeforeUserLoggedInEvent $event): void {
+ $this->log(
+ 'Login attempt: "%s"',
+ [
+ 'uid' => $event->getUsername()
+ ],
+ [
+ 'uid',
+ ],
+ true
+ );
+ }
+
+ private function userLoggedIn(UserLoggedInWithCookieEvent|UserLoggedInEvent $event): void {
+ $this->log(
+ 'Login successful: "%s"',
+ [
+ 'uid' => $event->getUser()->getUID()
+ ],
+ [
+ 'uid',
+ ],
+ true
+ );
+ }
+
+ private function beforeUserLogout(BeforeUserLoggedOutEvent $event): void {
+ $this->log(
+ 'Logout occurred',
+ [],
+ []
+ );
+ }
+
+ private function anyLoginFailed(AnyLoginFailedEvent $event): void {
+ $this->log(
+ 'Login failed: "%s"',
+ [
+ 'loginName' => $event->getLoginName()
+ ],
+ [
+ 'loginName',
+ ],
+ true
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/ConsoleEventListener.php b/apps/admin_audit/lib/Listener/ConsoleEventListener.php
new file mode 100644
index 00000000000..aa6029f2016
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/ConsoleEventListener.php
@@ -0,0 +1,42 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\Console\ConsoleEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/**
+ * @template-implements IEventListener<ConsoleEvent>
+ */
+class ConsoleEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof ConsoleEvent) {
+ $this->runCommand($event);
+ }
+ }
+
+ private function runCommand(ConsoleEvent $event): void {
+ $arguments = $event->getArguments();
+ if (!isset($arguments[1]) || $arguments[1] === '_completion') {
+ // Don't log autocompletion
+ return;
+ }
+
+ // Remove `./occ`
+ array_shift($arguments);
+
+ $this->log('Console command executed: %s',
+ ['arguments' => implode(' ', $arguments)],
+ ['arguments']
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php b/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php
index 737afeeaba2..bc3652a08bc 100644
--- a/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php
+++ b/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php
@@ -3,26 +3,10 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com>
- *
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
+
namespace OCA\AdminAudit\Listener;
use OCA\AdminAudit\Actions\Action;
diff --git a/apps/admin_audit/lib/Listener/FileEventListener.php b/apps/admin_audit/lib/Listener/FileEventListener.php
new file mode 100644
index 00000000000..46a4962123b
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/FileEventListener.php
@@ -0,0 +1,74 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCA\Files_Versions\Events\VersionRestoredEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Files\InvalidPathException;
+use OCP\Files\NotFoundException;
+use OCP\Preview\BeforePreviewFetchedEvent;
+use OCP\Server;
+use Psr\Log\LoggerInterface;
+
+/**
+ * @template-implements IEventListener<BeforePreviewFetchedEvent|VersionRestoredEvent>
+ */
+class FileEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof BeforePreviewFetchedEvent) {
+ $this->beforePreviewFetched($event);
+ } elseif ($event instanceof VersionRestoredEvent) {
+ $this->versionRestored($event);
+ }
+ }
+
+ /**
+ * Logs preview access to a file
+ */
+ private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void {
+ try {
+ $file = $event->getNode();
+ $params = [
+ 'id' => $file->getId(),
+ 'width' => $event->getWidth(),
+ 'height' => $event->getHeight(),
+ 'crop' => $event->isCrop(),
+ 'mode' => $event->getMode(),
+ 'path' => $file->getPath(),
+ ];
+ $this->log(
+ 'Preview accessed: (id: "%s", width: "%s", height: "%s" crop: "%s", mode: "%s", path: "%s")',
+ $params,
+ array_keys($params)
+ );
+ } catch (InvalidPathException|NotFoundException $e) {
+ Server::get(LoggerInterface::class)->error(
+ 'Exception thrown in file preview: ' . $e->getMessage(), ['app' => 'admin_audit', 'exception' => $e]
+ );
+ return;
+ }
+ }
+
+ /**
+ * Logs when a version is restored
+ */
+ private function versionRestored(VersionRestoredEvent $event): void {
+ $version = $event->getVersion();
+ $this->log('Version "%s" of "%s" was restored.',
+ [
+ 'version' => $version->getRevisionId(),
+ 'path' => $version->getVersionPath()
+ ],
+ ['version', 'path']
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/GroupManagementEventListener.php b/apps/admin_audit/lib/Listener/GroupManagementEventListener.php
new file mode 100644
index 00000000000..df937447e70
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/GroupManagementEventListener.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Group\Events\GroupCreatedEvent;
+use OCP\Group\Events\GroupDeletedEvent;
+use OCP\Group\Events\UserAddedEvent;
+use OCP\Group\Events\UserRemovedEvent;
+
+/**
+ * @template-implements IEventListener<UserAddedEvent|UserRemovedEvent|GroupCreatedEvent|GroupDeletedEvent>
+ */
+class GroupManagementEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof UserAddedEvent) {
+ $this->userAdded($event);
+ } elseif ($event instanceof UserRemovedEvent) {
+ $this->userRemoved($event);
+ } elseif ($event instanceof GroupCreatedEvent) {
+ $this->groupCreated($event);
+ } elseif ($event instanceof GroupDeletedEvent) {
+ $this->groupDeleted($event);
+ }
+ }
+
+ private function userAdded(UserAddedEvent $event): void {
+ $this->log('User "%s" added to group "%s"',
+ [
+ 'group' => $event->getGroup()->getGID(),
+ 'user' => $event->getUser()->getUID()
+ ],
+ [
+ 'user', 'group'
+ ]
+ );
+ }
+
+ private function userRemoved(UserRemovedEvent $event): void {
+ $this->log('User "%s" removed from group "%s"',
+ [
+ 'group' => $event->getGroup()->getGID(),
+ 'user' => $event->getUser()->getUID()
+ ],
+ [
+ 'user', 'group'
+ ]
+ );
+ }
+
+ private function groupCreated(GroupCreatedEvent $event): void {
+ $this->log('Group created: "%s"',
+ [
+ 'group' => $event->getGroup()->getGID()
+ ],
+ [
+ 'group'
+ ]
+ );
+ }
+
+ private function groupDeleted(GroupDeletedEvent $event): void {
+ $this->log('Group deleted: "%s"',
+ [
+ 'group' => $event->getGroup()->getGID()
+ ],
+ [
+ 'group'
+ ]
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/SecurityEventListener.php b/apps/admin_audit/lib/Listener/SecurityEventListener.php
new file mode 100644
index 00000000000..17253aa384c
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/SecurityEventListener.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+/**
+ * @template-implements IEventListener<TwoFactorProviderChallengePassed|TwoFactorProviderChallengeFailed>
+ */
+class SecurityEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof TwoFactorProviderChallengePassed) {
+ $this->twoFactorProviderChallengePassed($event);
+ } elseif ($event instanceof TwoFactorProviderChallengeFailed) {
+ $this->twoFactorProviderChallengeFailed($event);
+ }
+ }
+
+ private function twoFactorProviderChallengePassed(TwoFactorProviderChallengePassed $event): void {
+ $this->log(
+ 'Successful two factor attempt by user %s (%s) with provider %s',
+ [
+ 'uid' => $event->getUser()->getUID(),
+ 'displayName' => $event->getUser()->getDisplayName(),
+ 'provider' => $event->getProvider()->getDisplayName()
+ ],
+ [
+ 'displayName',
+ 'uid',
+ 'provider',
+ ]
+ );
+ }
+
+ private function twoFactorProviderChallengeFailed(TwoFactorProviderChallengeFailed $event): void {
+ $this->log(
+ 'Failed two factor attempt by user %s (%s) with provider %s',
+ [
+ 'uid' => $event->getUser()->getUID(),
+ 'displayName' => $event->getUser()->getDisplayName(),
+ 'provider' => $event->getProvider()->getDisplayName()
+ ],
+ [
+ 'displayName',
+ 'uid',
+ 'provider',
+ ]
+ );
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/SharingEventListener.php b/apps/admin_audit/lib/Listener/SharingEventListener.php
new file mode 100644
index 00000000000..1ba3c6f49d3
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/SharingEventListener.php
@@ -0,0 +1,291 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Share\Events\ShareCreatedEvent;
+use OCP\Share\Events\ShareDeletedEvent;
+use OCP\Share\IShare;
+
+/**
+ * @template-implements IEventListener<ShareCreatedEvent|ShareDeletedEvent>
+ */
+class SharingEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof ShareCreatedEvent) {
+ $this->shareCreated($event);
+ } elseif ($event instanceof ShareDeletedEvent) {
+ $this->shareDeleted($event);
+ }
+ }
+
+ private function shareCreated(ShareCreatedEvent $event): void {
+ $share = $event->getShare();
+
+ $params = [
+ 'itemType' => $share->getNodeType(),
+ 'path' => $share->getNode()->getPath(),
+ 'itemSource' => $share->getNodeId(),
+ 'shareWith' => $share->getSharedWith(),
+ 'permissions' => $share->getPermissions(),
+ 'id' => $share->getId()
+ ];
+
+ match ($share->getShareType()) {
+ IShare::TYPE_LINK => $this->log(
+ 'The %s "%s" with ID "%s" has been shared via link with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_USER => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the user "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_GROUP => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the group "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_ROOM => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_EMAIL => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the email recipient "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_CIRCLE => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the circle "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_REMOTE => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the remote user "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_REMOTE_GROUP => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the remote group "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_DECK => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the deck card "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_SCIENCEMESH => $this->log(
+ 'The %s "%s" with ID "%s" has been shared to the sciencemesh user "%s" with permissions "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'path',
+ 'itemSource',
+ 'shareWith',
+ 'permissions',
+ 'id',
+ ]
+ ),
+ default => null
+ };
+ }
+
+ private function shareDeleted(ShareDeletedEvent $event): void {
+ $share = $event->getShare();
+
+ $params = [
+ 'itemType' => $share->getNodeType(),
+ 'fileTarget' => $share->getTarget(),
+ 'itemSource' => $share->getNodeId(),
+ 'shareWith' => $share->getSharedWith(),
+ 'id' => $share->getId()
+ ];
+
+ match ($share->getShareType()) {
+ IShare::TYPE_LINK => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_USER => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the user "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_GROUP => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the group "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_ROOM => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_EMAIL => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the email recipient "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_CIRCLE => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the circle "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_REMOTE => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the remote user "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_REMOTE_GROUP => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the remote group "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_DECK => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the deck card "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ IShare::TYPE_SCIENCEMESH => $this->log(
+ 'The %s "%s" with ID "%s" has been unshared from the sciencemesh user "%s" (Share ID: %s)',
+ $params,
+ [
+ 'itemType',
+ 'fileTarget',
+ 'itemSource',
+ 'shareWith',
+ 'id',
+ ]
+ ),
+ default => null
+ };
+ }
+}
diff --git a/apps/admin_audit/lib/Listener/UserManagementEventListener.php b/apps/admin_audit/lib/Listener/UserManagementEventListener.php
new file mode 100644
index 00000000000..c22d04dce9a
--- /dev/null
+++ b/apps/admin_audit/lib/Listener/UserManagementEventListener.php
@@ -0,0 +1,126 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\AdminAudit\Listener;
+
+use OCA\AdminAudit\Actions\Action;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\UserChangedEvent;
+use OCP\User\Events\UserCreatedEvent;
+use OCP\User\Events\UserDeletedEvent;
+use OCP\User\Events\UserIdAssignedEvent;
+use OCP\User\Events\UserIdUnassignedEvent;
+
+/**
+ * @template-implements IEventListener<UserCreatedEvent|UserDeletedEvent|UserChangedEvent|PasswordUpdatedEvent|UserIdAssignedEvent|UserIdUnassignedEvent>
+ */
+class UserManagementEventListener extends Action implements IEventListener {
+ public function handle(Event $event): void {
+ if ($event instanceof UserCreatedEvent) {
+ $this->userCreated($event);
+ } elseif ($event instanceof UserDeletedEvent) {
+ $this->userDeleted($event);
+ } elseif ($event instanceof UserChangedEvent) {
+ $this->userChanged($event);
+ } elseif ($event instanceof PasswordUpdatedEvent) {
+ $this->passwordUpdated($event);
+ } elseif ($event instanceof UserIdAssignedEvent) {
+ $this->userIdAssigned($event);
+ } elseif ($event instanceof UserIdUnassignedEvent) {
+ $this->userIdUnassigned($event);
+ }
+ }
+
+ private function userCreated(UserCreatedEvent $event): void {
+ $this->log(
+ 'User created: "%s"',
+ [
+ 'uid' => $event->getUid()
+ ],
+ [
+ 'uid',
+ ]
+ );
+ }
+
+ private function userDeleted(UserDeletedEvent $event): void {
+ $this->log(
+ 'User deleted: "%s"',
+ [
+ 'uid' => $event->getUser()->getUID()
+ ],
+ [
+ 'uid',
+ ]
+ );
+ }
+
+ private function userChanged(UserChangedEvent $event): void {
+ switch ($event->getFeature()) {
+ case 'enabled':
+ $this->log(
+ $event->getValue() === true
+ ? 'User enabled: "%s"'
+ : 'User disabled: "%s"',
+ ['user' => $event->getUser()->getUID()],
+ [
+ 'user',
+ ]
+ );
+ break;
+ case 'eMailAddress':
+ $this->log(
+ 'Email address changed for user %s',
+ ['user' => $event->getUser()->getUID()],
+ [
+ 'user',
+ ]
+ );
+ break;
+ }
+ }
+
+ private function passwordUpdated(PasswordUpdatedEvent $event): void {
+ if ($event->getUser()->getBackendClassName() === 'Database') {
+ $this->log(
+ 'Password of user "%s" has been changed',
+ [
+ 'user' => $event->getUser()->getUID(),
+ ],
+ [
+ 'user',
+ ]
+ );
+ }
+ }
+
+ /**
+ * Log assignments of users (typically user backends)
+ */
+ private function userIdAssigned(UserIdAssignedEvent $event): void {
+ $this->log(
+ 'UserID assigned: "%s"',
+ [ 'uid' => $event->getUserId() ],
+ [ 'uid' ]
+ );
+ }
+
+ /**
+ * Log unassignments of users (typically user backends, no data removed)
+ */
+ private function userIdUnassigned(UserIdUnassignedEvent $event): void {
+ $this->log(
+ 'UserID unassigned: "%s"',
+ [ 'uid' => $event->getUserId() ],
+ [ 'uid' ]
+ );
+ }
+}