Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/admin_audit/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
'OCA\\AdminAudit\\Listener\\SharingEventListener' => $baseDir . '/../lib/Listener/SharingEventListener.php',
'OCA\\AdminAudit\\Listener\\TagEventListener' => $baseDir . '/../lib/Listener/TagEventListener.php',
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => $baseDir . '/../lib/Listener/UserManagementEventListener.php',
'OCA\\AdminAudit\\Operation' => $baseDir . '/../lib/Operation.php',
);
1 change: 1 addition & 0 deletions apps/admin_audit/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ComposerStaticInitAdminAudit
'OCA\\AdminAudit\\Listener\\SharingEventListener' => __DIR__ . '/..' . '/../lib/Listener/SharingEventListener.php',
'OCA\\AdminAudit\\Listener\\TagEventListener' => __DIR__ . '/..' . '/../lib/Listener/TagEventListener.php',
'OCA\\AdminAudit\\Listener\\UserManagementEventListener' => __DIR__ . '/..' . '/../lib/Listener/UserManagementEventListener.php',
'OCA\\AdminAudit\\Operation' => __DIR__ . '/..' . '/../lib/Operation.php',
);

public static function getInitializer(ClassLoader $loader)
Expand Down
12 changes: 10 additions & 2 deletions apps/admin_audit/lib/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\AdminAudit\Actions;

use OCA\AdminAudit\IAuditLogger;
use OCA\AdminAudit\Operation;

class Action {

Expand All @@ -20,21 +21,28 @@ public function __construct(
/**
* Log a single action with a log level of info
*
* @param Operation|string|null $operation Stable identifier of the action. A string in the form `app.entity.action` is only expected from other apps via CriticalActionPerformedEvent
* @param string $text
* @param array<string, scalar|null|\DateTimeInterface> $params
* @param list<string> $elements
* @param bool $obfuscateParameters
*/
public function log(
Operation|string|null $operation,
string $text,
array $params,
array $elements,
bool $obfuscateParameters = false,
): void {
$baseContext = ['app' => 'admin_audit'];
if ($operation !== null) {
$baseContext['operation'] = $operation instanceof Operation ? $operation->value : $operation;
}

foreach ($elements as $element) {
if (!array_key_exists($element, $params)) {
$message = '$params["' . $element . '"] was missing.';
$context = ['app' => 'admin_audit'];
$context = $baseContext;

if (!$obfuscateParameters) {
$message .= ' Transferred value: {params}';
Expand All @@ -47,7 +55,7 @@ public function log(
}

$replaceArray = [];
$context = ['app' => 'admin_audit'];
$context = $baseContext;
foreach ($elements as $element) {
$value = $params[$element];
if ($value instanceof \DateTimeInterface) {
Expand Down
7 changes: 7 additions & 0 deletions apps/admin_audit/lib/Actions/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\AdminAudit\Actions;

use OC\Files\Node\NonExistingFile;
use OCA\AdminAudit\Operation;
use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
use OCP\Files\Events\Node\BeforeNodeReadEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function read(BeforeNodeReadEvent $event): void {
return;
}
$this->log(
Operation::FileRead,
'File with id "%s" accessed: "%s"',
$params,
array_keys($params)
Expand All @@ -69,6 +71,7 @@ public function afterRename(NodeRenamedEvent $event): void {
}

$this->log(
Operation::FileRenamed,
'File renamed with id "%s" from "%s" to "%s"',
$params,
array_keys($params)
Expand All @@ -95,6 +98,7 @@ public function create(NodeCreatedEvent $event): void {
return;
}
$this->log(
Operation::FileCreated,
'File with id "%s" created: "%s"',
$params,
array_keys($params)
Expand All @@ -121,6 +125,7 @@ public function copy(NodeCopiedEvent $event): void {
return;
}
$this->log(
Operation::FileCopied,
'File id copied from: "%s" to "%s", path from "%s" to "%s"',
$params,
array_keys($params)
Expand Down Expand Up @@ -148,6 +153,7 @@ public function write(NodeWrittenEvent $event): void {
}

$this->log(
Operation::FileWritten,
'File with id "%s" written to: "%s"',
$params,
array_keys($params)
Expand All @@ -171,6 +177,7 @@ public function delete(BeforeNodeDeletedEvent $event): void {
return;
}
$this->log(
Operation::FileDeleted,
'File with id "%s" deleted: "%s"',
$params,
array_keys($params)
Expand Down
7 changes: 7 additions & 0 deletions apps/admin_audit/lib/Actions/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace OCA\AdminAudit\Actions;

use OCA\AdminAudit\Operation;

/**
* Class Sharing logs the sharing actions
*
Expand All @@ -22,6 +24,7 @@ class Sharing extends Action {
*/
public function updatePermissions(array $params): void {
$this->log(
Operation::SharePermissionsUpdated,
'The permissions of the shared %s "%s" with ID "%s" have been changed to "%s"',
$params,
[
Expand All @@ -40,6 +43,7 @@ public function updatePermissions(array $params): void {
*/
public function updatePassword(array $params): void {
$this->log(
Operation::SharePasswordUpdated,
'The password of the publicly shared %s "%s" with ID "%s" has been changed',
$params,
[
Expand All @@ -58,6 +62,7 @@ public function updatePassword(array $params): void {
public function updateExpirationDate(array $params): void {
if ($params['date'] === null) {
$this->log(
Operation::ShareExpirationRemoved,
'The expiration date of the publicly shared %s with ID "%s" has been removed',
$params,
[
Expand All @@ -67,6 +72,7 @@ public function updateExpirationDate(array $params): void {
);
} else {
$this->log(
Operation::ShareExpirationUpdated,
'The expiration date of the publicly shared %s with ID "%s" has been changed to "%s"',
$params,
[
Expand All @@ -85,6 +91,7 @@ public function updateExpirationDate(array $params): void {
*/
public function shareAccessed(array $params): void {
$this->log(
Operation::ShareLinkAccessed,
'The shared %s with the token "%s" by "%s" has been accessed.',
$params,
[
Expand Down
6 changes: 4 additions & 2 deletions apps/admin_audit/lib/Actions/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

namespace OCA\AdminAudit\Actions;

use OCA\AdminAudit\Operation;

class Trashbin extends Action {
public function delete(array $params): void {
$this->log('File "%s" deleted from trash bin.',
$this->log(Operation::TrashbinFileDeleted, 'File "%s" deleted from trash bin.',
['path' => $params['path']], ['path']
);
}

public function restore(array $params): void {
$this->log('File "%s" restored from trash bin.',
$this->log(Operation::TrashbinFileRestored, 'File "%s" restored from trash bin.',
['path' => $params['filePath']], ['path']
);
}
Expand Down
4 changes: 3 additions & 1 deletion apps/admin_audit/lib/Actions/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

namespace OCA\AdminAudit\Actions;

use OCA\AdminAudit\Operation;

class Versions extends Action {
public function delete(array $params): void {
$this->log('Version "%s" was deleted.',
$this->log(Operation::VersionDeleted, 'Version "%s" was deleted.',
['path' => $params['path']],
['path']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCP\App\Events\AppDisableEvent;
use OCP\App\Events\AppEnableEvent;
use OCP\App\Events\AppUpdateEvent;
Expand All @@ -33,27 +34,27 @@ public function handle(Event $event): void {

private function appEnable(AppEnableEvent $event): void {
if (empty($event->getGroupIds())) {
$this->log('App "%s" enabled',
$this->log(Operation::AppEnabled, 'App "%s" enabled',
['app' => $event->getAppId()],
['app']
);
} else {
$this->log('App "%1$s" enabled for groups: %2$s',
$this->log(Operation::AppEnabled, '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',
$this->log(Operation::AppDisabled, 'App "%s" disabled',
['app' => $event->getAppId()],
['app']
);
}

private function appUpdate(AppUpdateEvent $event): void {
$this->log('App "%s" updated',
$this->log(Operation::AppUpdated, 'App "%s" updated',
['app' => $event->getAppId()],
['app']
);
Expand Down
5 changes: 5 additions & 0 deletions apps/admin_audit/lib/Listener/AuthEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCP\Authentication\Events\AnyLoginFailedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function handle(Event $event): void {

private function beforeUserLoggedIn(BeforeUserLoggedInEvent $event): void {
$this->log(
Operation::LoginAttempted,
'Login attempt: "%s"',
[
'uid' => $event->getUsername()
Expand All @@ -50,6 +52,7 @@ private function beforeUserLoggedIn(BeforeUserLoggedInEvent $event): void {

private function userLoggedIn(UserLoggedInWithCookieEvent|UserLoggedInEvent $event): void {
$this->log(
Operation::LoginSucceeded,
'Login successful: "%s"',
[
'uid' => $event->getUser()->getUID()
Expand All @@ -63,6 +66,7 @@ private function userLoggedIn(UserLoggedInWithCookieEvent|UserLoggedInEvent $eve

private function beforeUserLogout(BeforeUserLoggedOutEvent $event): void {
$this->log(
Operation::LogoutPerformed,
'Logout occurred',
[],
[]
Expand All @@ -71,6 +75,7 @@ private function beforeUserLogout(BeforeUserLoggedOutEvent $event): void {

private function anyLoginFailed(AnyLoginFailedEvent $event): void {
$this->log(
Operation::LoginFailed,
'Login failed: "%s"',
[
'loginName' => $event->getLoginName()
Expand Down
5 changes: 3 additions & 2 deletions apps/admin_audit/lib/Listener/CacheEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Cache\CacheEntryInsertedEvent;
Expand All @@ -29,7 +30,7 @@ public function handle(Event $event): void {
}

private function entryInserted(CacheEntryInsertedEvent $event): void {
$this->log('Cache entry inserted for fileid "%1$d", path "%2$s" on storageid "%3$d"',
$this->log(Operation::CacheEntryInserted, 'Cache entry inserted for fileid "%1$d", path "%2$s" on storageid "%3$d"',
[
'fileid' => $event->getFileId(),
'path' => $event->getPath(),
Expand All @@ -40,7 +41,7 @@ private function entryInserted(CacheEntryInsertedEvent $event): void {
}

private function entryRemoved(CacheEntryRemovedEvent $event): void {
$this->log('Cache entry removed for fileid "%1$d", path "%2$s" on storageid "%3$d"',
$this->log(Operation::CacheEntryRemoved, 'Cache entry removed for fileid "%1$d", path "%2$s" on storageid "%3$d"',
[
'fileid' => $event->getFileId(),
'path' => $event->getPath(),
Expand Down
3 changes: 2 additions & 1 deletion apps/admin_audit/lib/Listener/ConsoleEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCP\Console\ConsoleEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -35,7 +36,7 @@ private function runCommand(ConsoleEvent $event): void {
// Remove `./occ`
array_shift($arguments);

$this->log('Console command executed: %s',
$this->log(Operation::ConsoleCommandExecuted, 'Console command executed: %s',
['arguments' => implode(' ', $arguments)],
['arguments']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function handle(Event $event): void {
}

$this->log(
$event->getOperation(),
$event->getLogMessage(),
$event->getParameters(),
array_keys($event->getParameters()),
Expand Down
4 changes: 3 additions & 1 deletion apps/admin_audit/lib/Listener/FileEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCA\Files_Versions\Events\VersionRestoredEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand Down Expand Up @@ -47,6 +48,7 @@ private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void {
'path' => $file->getPath(),
];
$this->log(
Operation::PreviewAccessed,
'Preview accessed: (id: "%s", width: "%s", height: "%s" crop: "%s", mode: "%s", path: "%s")',
$params,
array_keys($params)
Expand All @@ -64,7 +66,7 @@ private function beforePreviewFetched(BeforePreviewFetchedEvent $event): void {
*/
private function versionRestored(VersionRestoredEvent $event): void {
$version = $event->getVersion();
$this->log('Version "%s" of "%s" was restored.',
$this->log(Operation::VersionRestored, 'Version "%s" of "%s" was restored.',
[
'version' => $version->getRevisionId(),
'path' => $version->getVersionPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\AdminAudit\Listener;

use OCA\AdminAudit\Actions\Action;
use OCA\AdminAudit\Operation;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Group\Events\GroupCreatedEvent;
Expand All @@ -35,7 +36,7 @@ public function handle(Event $event): void {
}

private function userAdded(UserAddedEvent $event): void {
$this->log('User "%s" added to group "%s"',
$this->log(Operation::GroupMemberAdded, 'User "%s" added to group "%s"',
[
'group' => $event->getGroup()->getGID(),
'user' => $event->getUser()->getUID()
Expand All @@ -47,7 +48,7 @@ private function userAdded(UserAddedEvent $event): void {
}

private function userRemoved(UserRemovedEvent $event): void {
$this->log('User "%s" removed from group "%s"',
$this->log(Operation::GroupMemberRemoved, 'User "%s" removed from group "%s"',
[
'group' => $event->getGroup()->getGID(),
'user' => $event->getUser()->getUID()
Expand All @@ -59,7 +60,7 @@ private function userRemoved(UserRemovedEvent $event): void {
}

private function groupCreated(GroupCreatedEvent $event): void {
$this->log('Group created: "%s"',
$this->log(Operation::GroupCreated, 'Group created: "%s"',
[
'group' => $event->getGroup()->getGID()
],
Expand All @@ -70,7 +71,7 @@ private function groupCreated(GroupCreatedEvent $event): void {
}

private function groupDeleted(GroupDeletedEvent $event): void {
$this->log('Group deleted: "%s"',
$this->log(Operation::GroupDeleted, 'Group deleted: "%s"',
[
'group' => $event->getGroup()->getGID()
],
Expand Down
Loading
Loading