diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2021-04-13 08:52:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 08:52:08 +0200 |
commit | 421914b4d0ac3b13250d08292f98fdf44e7c60ba (patch) | |
tree | 7a4442c3f5b5a2b5ba103e4f08ae54394af02706 /apps/admin_audit | |
parent | bab06b9abb2a135dc9c3146e027c74c3c80c8593 (diff) | |
parent | 6d502041e07f93ad4a17db69dc5dd0befae0e930 (diff) | |
download | nextcloud-server-421914b4d0ac3b13250d08292f98fdf44e7c60ba.tar.gz nextcloud-server-421914b4d0ac3b13250d08292f98fdf44e7c60ba.zip |
Merge pull request #26467 from nextcloud/feature/noid/allow-apps-to-log-to-audit
Allow apps to log actions into the audit_log
Diffstat (limited to 'apps/admin_audit')
4 files changed, 49 insertions, 0 deletions
diff --git a/apps/admin_audit/composer/composer/autoload_classmap.php b/apps/admin_audit/composer/composer/autoload_classmap.php index a08bab93724..e52032ca3ea 100644 --- a/apps/admin_audit/composer/composer/autoload_classmap.php +++ b/apps/admin_audit/composer/composer/autoload_classmap.php @@ -20,4 +20,5 @@ return array( 'OCA\\AdminAudit\\Actions\\Versions' => $baseDir . '/../lib/Actions/Versions.php', 'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => $baseDir . '/../lib/BackgroundJobs/Rotate.php', + 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => $baseDir . '/../lib/Listener/CriticalActionPerformedEventListener.php', ); diff --git a/apps/admin_audit/composer/composer/autoload_static.php b/apps/admin_audit/composer/composer/autoload_static.php index cbced7b5625..829bc2ab049 100644 --- a/apps/admin_audit/composer/composer/autoload_static.php +++ b/apps/admin_audit/composer/composer/autoload_static.php @@ -35,6 +35,7 @@ class ComposerStaticInitAdminAudit 'OCA\\AdminAudit\\Actions\\Versions' => __DIR__ . '/..' . '/../lib/Actions/Versions.php', 'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => __DIR__ . '/..' . '/../lib/BackgroundJobs/Rotate.php', + 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => __DIR__ . '/..' . '/../lib/Listener/CriticalActionPerformedEventListener.php', ); public static function getInitializer(ClassLoader $loader) diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index d7afb96ea87..4ee49e7129b 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -49,6 +49,7 @@ use OCA\AdminAudit\Actions\Sharing; use OCA\AdminAudit\Actions\Trashbin; use OCA\AdminAudit\Actions\UserManagement; use OCA\AdminAudit\Actions\Versions; +use OCA\AdminAudit\Listener\CriticalActionPerformedEventListener; use OCP\App\ManagerEvent; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -61,6 +62,7 @@ use OCP\IGroupManager; use OCP\IPreview; use OCP\IServerContainer; use OCP\IUserSession; +use OCP\Log\Audit\CriticalActionPerformedEvent; use OCP\Log\ILogFactory; use OCP\Share; use OCP\Util; @@ -78,6 +80,7 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php b/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php new file mode 100644 index 00000000000..75f7d86d421 --- /dev/null +++ b/apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2021 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/>. + * + */ + +namespace OCA\AdminAudit\Listener; + +use OCA\AdminAudit\Actions\Action; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Log\Audit\CriticalActionPerformedEvent; + +class CriticalActionPerformedEventListener extends Action implements IEventListener { + public function handle(Event $event): void { + if (!($event instanceof CriticalActionPerformedEvent)) { + return; + } + + $this->log( + $event->getLogMessage(), + $event->getParameters(), + array_keys($event->getParameters()), + $event->getObfuscateParameters() + ); + } +} |