diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-04-25 02:27:43 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-04-26 12:10:52 +0200 |
commit | cfc3ab0119d23a4c8ccccefb13d2271b0c0675ae (patch) | |
tree | dfab8e9dd20412ce46d21eeb42861854193ca56f /apps/admin_audit/lib | |
parent | 5fbf184134f34633bc150b2e0210c4a97ec285a9 (diff) | |
download | nextcloud-server-cfc3ab0119d23a4c8ccccefb13d2271b0c0675ae.tar.gz nextcloud-server-cfc3ab0119d23a4c8ccccefb13d2271b0c0675ae.zip |
offer API to create own File log. admin_audit makes use of it
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/admin_audit/lib')
-rw-r--r-- | apps/admin_audit/lib/AppInfo/Application.php | 96 |
1 files changed, 55 insertions, 41 deletions
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php index df39e3eb111..f0387e86057 100644 --- a/apps/admin_audit/lib/AppInfo/Application.php +++ b/apps/admin_audit/lib/AppInfo/Application.php @@ -53,8 +53,24 @@ use OCP\Share; class Application extends App { + /** @var ILogger */ + protected $logger; + public function __construct() { parent::__construct('admin_audit'); + $this->initLogger(); + } + + public function initLogger() { + $c = $this->getContainer()->getServer(); + + $logFile = $c->getConfig()->getAppValue('admin_audit', 'logfile', null); + if($logFile === null) { + $this->logger = $c->getLogger(); + return; + } + $this->logger = $c->getLogFactory()->getCustomLogger($logFile); + } public function register() { @@ -65,26 +81,24 @@ class Application extends App { * Register hooks in order to log them */ protected function registerHooks() { - $logger = $this->getContainer()->getServer()->getLogger(); - - $this->userManagementHooks($logger); - $this->groupHooks($logger); - $this->authHooks($logger); + $this->userManagementHooks(); + $this->groupHooks(); + $this->authHooks(); - $this->consoleHooks($logger); - $this->appHooks($logger); + $this->consoleHooks(); + $this->appHooks(); - $this->sharingHooks($logger); + $this->sharingHooks(); - $this->fileHooks($logger); - $this->trashbinHooks($logger); - $this->versionsHooks($logger); + $this->fileHooks(); + $this->trashbinHooks(); + $this->versionsHooks(); - $this->securityHooks($logger); + $this->securityHooks(); } - protected function userManagementHooks(ILogger $logger) { - $userActions = new UserManagement($logger); + protected function userManagementHooks() { + $userActions = new UserManagement($this->logger); Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); @@ -97,8 +111,8 @@ class Application extends App { $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); } - protected function groupHooks(ILogger $logger) { - $groupActions = new GroupManagement($logger); + protected function groupHooks() { + $groupActions = new GroupManagement($this->logger); /** @var IGroupManager|Manager $groupManager */ $groupManager = $this->getContainer()->getServer()->getGroupManager(); @@ -108,8 +122,8 @@ class Application extends App { $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); } - protected function sharingHooks(ILogger $logger) { - $shareActions = new Sharing($logger); + protected function sharingHooks() { + $shareActions = new Sharing($this->logger); Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); @@ -119,42 +133,42 @@ class Application extends App { Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); } - protected function authHooks(ILogger $logger) { - $authActions = new Auth($logger); + protected function authHooks() { + $authActions = new Auth($this->logger); Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); Util::connectHook('OC_User', 'logout', $authActions, 'logout'); } - protected function appHooks(ILogger $logger) { + protected function appHooks() { $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) use ($logger) { - $appActions = new AppManagement($logger); + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) { + $appActions = new AppManagement($this->logger); $appActions->enableApp($event->getAppID()); }); - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) use ($logger) { - $appActions = new AppManagement($logger); + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) { + $appActions = new AppManagement($this->logger); $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); }); - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) use ($logger) { - $appActions = new AppManagement($logger); + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) { + $appActions = new AppManagement($this->logger); $appActions->disableApp($event->getAppID()); }); } - protected function consoleHooks(ILogger $logger) { + protected function consoleHooks() { $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) use ($logger) { - $appActions = new Console($logger); + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) { + $appActions = new Console($this->logger); $appActions->runCommand($event->getArguments()); }); } - protected function fileHooks(ILogger $logger) { - $fileActions = new Files($logger); + protected function fileHooks() { + $fileActions = new Files($this->logger); $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); $eventDispatcher->addListener( IPreview::EVENT, @@ -215,26 +229,26 @@ class Application extends App { ); } - protected function versionsHooks(ILogger $logger) { - $versionsActions = new Versions($logger); + protected function versionsHooks() { + $versionsActions = new Versions($this->logger); Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete'); } - protected function trashbinHooks(ILogger $logger) { - $trashActions = new Trashbin($logger); + protected function trashbinHooks() { + $trashActions = new Trashbin($this->logger); Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); } - protected function securityHooks(ILogger $logger) { + protected function securityHooks() { $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) use ($logger) { - $security = new Security($logger); + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) { + $security = new Security($this->logger); $security->twofactorSuccess($event->getSubject(), $event->getArguments()); }); - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) use ($logger) { - $security = new Security($logger); + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) { + $security = new Security($this->logger); $security->twofactorFailed($event->getSubject(), $event->getArguments()); }); } |