registerService(IAuditLogger::class, function (ContainerInterface $c) { return new AuditLogger($c->get(ILogFactory::class), $c->get(IConfig::class)); }); $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); // File events $context->registerEventListener(BeforePreviewFetchedEvent::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 { /** @var IAuditLogger $logger */ $logger = $context->getAppContainer()->get(IAuditLogger::class); /* * TODO: once the hooks are migrated to lazy events, this should be done * in \OCA\AdminAudit\AppInfo\Application::register */ $this->registerLegacyHooks($logger, $context->getServerContainer()); } /** * Register hooks in order to log them */ private function registerLegacyHooks(IAuditLogger $logger, ContainerInterface $serverContainer): void { /** @var IEventDispatcher $eventDispatcher */ $eventDispatcher = $serverContainer->get(IEventDispatcher::class); $this->sharingLegacyHooks($logger); $this->fileHooks($logger, $eventDispatcher); $this->trashbinHooks($logger); $this->versionsHooks($logger); $this->tagHooks($logger, $eventDispatcher); } private function sharingLegacyHooks(IAuditLogger $logger): void { $shareActions = new Sharing($logger); 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 tagHooks(IAuditLogger $logger, IEventDispatcher $eventDispatcher): void { $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 { $fileActions = new Files($logger); $eventDispatcher->addListener( BeforeNodeRenamedEvent::class, function (BeforeNodeRenamedEvent $event) use ($fileActions): void { $fileActions->beforeRename($event); } ); $eventDispatcher->addListener( NodeRenamedEvent::class, function (NodeRenamedEvent $event) use ($fileActions): void { $fileActions->afterRename($event); } ); $eventDispatcher->addListener( NodeCreatedEvent::class, function (NodeCreatedEvent $event) use ($fileActions): void { $fileActions->create($event); } ); $eventDispatcher->addListener( NodeCopiedEvent::class, function (NodeCopiedEvent $event) use ($fileActions): void { $fileActions->copy($event); } ); $eventDispatcher->addListener( NodeWrittenEvent::class, function (NodeWrittenEvent $event) use ($fileActions): void { $fileActions->write($event); } ); $eventDispatcher->addListener( BeforeNodeReadEvent::class, function (BeforeNodeReadEvent $event) use ($fileActions): void { $fileActions->read($event); } ); $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'); } private function trashbinHooks(IAuditLogger $logger): void { $trashActions = new Trashbin($logger); Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); } }