Log access to preview images
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
parent
03a92eaf74
commit
abaf909ba2
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
||||||
*
|
*
|
||||||
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||||
|
@ -25,6 +26,12 @@
|
||||||
$logger = \OC::$server->getLogger();
|
$logger = \OC::$server->getLogger();
|
||||||
$userSession = \OC::$server->getUserSession();
|
$userSession = \OC::$server->getUserSession();
|
||||||
$groupManager = \OC::$server->getGroupManager();
|
$groupManager = \OC::$server->getGroupManager();
|
||||||
|
$eventDispatcher = \OC::$server->getEventDispatcher();
|
||||||
|
|
||||||
$auditLogger = new \OCA\Admin_Audit\AuditLogger($logger, $userSession, $groupManager);
|
$auditLogger = new \OCA\Admin_Audit\AuditLogger(
|
||||||
|
$logger,
|
||||||
|
$userSession,
|
||||||
|
$groupManager,
|
||||||
|
$eventDispatcher
|
||||||
|
);
|
||||||
$auditLogger->registerHooks();
|
$auditLogger->registerHooks();
|
||||||
|
|
|
@ -134,4 +134,23 @@ class Files extends Action {
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs preview access to a file
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*/
|
||||||
|
public function preview(array $params) {
|
||||||
|
$this->log(
|
||||||
|
'Preview accessed: "%s" (width: "%s", height: "%s" crop: "%s", mode: "%s")',
|
||||||
|
$params,
|
||||||
|
[
|
||||||
|
'path',
|
||||||
|
'width',
|
||||||
|
'height',
|
||||||
|
'crop',
|
||||||
|
'mode'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
|
||||||
*
|
*
|
||||||
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
||||||
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
|
@ -21,11 +23,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
namespace OCA\Admin_Audit;
|
namespace OCA\Admin_Audit;
|
||||||
|
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
|
use OC\Files\Node\File;
|
||||||
use OCA\Admin_Audit\Actions\Auth;
|
use OCA\Admin_Audit\Actions\Auth;
|
||||||
use OCA\Admin_Audit\Actions\Files;
|
use OCA\Admin_Audit\Actions\Files;
|
||||||
use OCA\Admin_Audit\Actions\GroupManagement;
|
use OCA\Admin_Audit\Actions\GroupManagement;
|
||||||
|
@ -35,17 +36,17 @@ use OCA\Admin_Audit\Actions\UserManagement;
|
||||||
use OCA\Admin_Audit\Actions\Versions;
|
use OCA\Admin_Audit\Actions\Versions;
|
||||||
use OCP\IGroupManager;
|
use OCP\IGroupManager;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\IPreview;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
class AuditLogger {
|
class AuditLogger {
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/** @var IUserSession */
|
/** @var IUserSession */
|
||||||
private $userSession;
|
private $userSession;
|
||||||
|
|
||||||
/** @var IGroupManager */
|
/** @var IGroupManager */
|
||||||
private $groupManager;
|
private $groupManager;
|
||||||
|
|
||||||
|
@ -55,17 +56,20 @@ class AuditLogger {
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param IUserSession $userSession
|
* @param IUserSession $userSession
|
||||||
* @param IGroupManager $groupManager
|
* @param IGroupManager $groupManager
|
||||||
|
* @param EventDispatcherInterface $eventDispatcher
|
||||||
*/
|
*/
|
||||||
public function __construct(ILogger $logger,
|
public function __construct(ILogger $logger,
|
||||||
IUserSession $userSession,
|
IUserSession $userSession,
|
||||||
IGroupManager $groupManager) {
|
IGroupManager $groupManager,
|
||||||
|
EventDispatcherInterface $eventDispatcher) {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register hooks in order to log them
|
* Register hooks in order to log them
|
||||||
*/
|
*/
|
||||||
public function registerHooks() {
|
public function registerHooks() {
|
||||||
$this->userManagementHooks();
|
$this->userManagementHooks();
|
||||||
|
@ -78,7 +82,7 @@ class AuditLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect to user management hooks
|
* Connect to user management hooks
|
||||||
*/
|
*/
|
||||||
private function userManagementHooks() {
|
private function userManagementHooks() {
|
||||||
$userActions = new UserManagement($this->logger);
|
$userActions = new UserManagement($this->logger);
|
||||||
|
@ -119,12 +123,25 @@ class AuditLogger {
|
||||||
Util::connectHook('OC_User', 'logout', $authActions, 'logout');
|
Util::connectHook('OC_User', 'logout', $authActions, 'logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect to file hooks
|
* Connect to file hooks
|
||||||
*/
|
*/
|
||||||
private function fileHooks() {
|
private function fileHooks() {
|
||||||
$fileActions = new Files($this->logger);
|
$fileActions = new Files($this->logger);
|
||||||
|
$this->eventDispatcher->addListener(
|
||||||
|
IPreview::EVENT,
|
||||||
|
function(GenericEvent $event) use ($fileActions) {
|
||||||
|
/** @var File $file */
|
||||||
|
$file = $event->getSubject();
|
||||||
|
$fileActions->preview([
|
||||||
|
'path' => substr($file->getInternalPath(), 5),
|
||||||
|
'width' => $event->getArguments()['width'],
|
||||||
|
'height' => $event->getArguments()['height'],
|
||||||
|
'crop' => $event->getArguments()['crop'],
|
||||||
|
'mode' => $event->getArguments()['mode']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Util::connectHook(
|
Util::connectHook(
|
||||||
Filesystem::CLASSNAME,
|
Filesystem::CLASSNAME,
|
||||||
|
@ -177,7 +194,7 @@ class AuditLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect to trash bin hooks
|
* Connect to trash bin hooks
|
||||||
*/
|
*/
|
||||||
private function trashbinHooks() {
|
private function trashbinHooks() {
|
||||||
$trashActions = new Trashbin($this->logger);
|
$trashActions = new Trashbin($this->logger);
|
||||||
|
|
Loading…
Reference in New Issue