@@ -71,221 +71,221 @@ |
||
| 71 | 71 | |
| 72 | 72 | class Application extends App implements IBootstrap { |
| 73 | 73 | |
| 74 | - /** @var LoggerInterface */ |
|
| 75 | - protected $logger; |
|
| 74 | + /** @var LoggerInterface */ |
|
| 75 | + protected $logger; |
|
| 76 | 76 | |
| 77 | - public function __construct() { |
|
| 78 | - parent::__construct('admin_audit'); |
|
| 79 | - } |
|
| 77 | + public function __construct() { |
|
| 78 | + parent::__construct('admin_audit'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function register(IRegistrationContext $context): void { |
|
| 82 | - $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
| 83 | - } |
|
| 81 | + public function register(IRegistrationContext $context): void { |
|
| 82 | + $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function boot(IBootContext $context): void { |
|
| 86 | - /** @var LoggerInterface $logger */ |
|
| 87 | - $logger = $context->injectFn( |
|
| 88 | - Closure::fromCallable([$this, 'getLogger']) |
|
| 89 | - ); |
|
| 85 | + public function boot(IBootContext $context): void { |
|
| 86 | + /** @var LoggerInterface $logger */ |
|
| 87 | + $logger = $context->injectFn( |
|
| 88 | + Closure::fromCallable([$this, 'getLogger']) |
|
| 89 | + ); |
|
| 90 | 90 | |
| 91 | - /* |
|
| 91 | + /* |
|
| 92 | 92 | * TODO: once the hooks are migrated to lazy events, this should be done |
| 93 | 93 | * in \OCA\AdminAudit\AppInfo\Application::register |
| 94 | 94 | */ |
| 95 | - $this->registerHooks($logger, $context->getServerContainer()); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - private function getLogger(IConfig $config, |
|
| 99 | - ILogFactory $logFactory): LoggerInterface { |
|
| 100 | - $auditType = $config->getSystemValueString('log_type_audit', 'file'); |
|
| 101 | - $defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud'); |
|
| 102 | - $auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag); |
|
| 103 | - $logFile = $config->getSystemValueString('logfile_audit', ''); |
|
| 104 | - |
|
| 105 | - if ($auditType === 'file' && !$logFile) { |
|
| 106 | - $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
| 107 | - // Legacy way was appconfig, now it's paralleled with the normal log config |
|
| 108 | - $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Register hooks in order to log them |
|
| 116 | - */ |
|
| 117 | - private function registerHooks(LoggerInterface $logger, |
|
| 118 | - IServerContainer $serverContainer): void { |
|
| 119 | - $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); |
|
| 120 | - $this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); |
|
| 121 | - $this->authHooks($logger); |
|
| 122 | - |
|
| 123 | - /** @var EventDispatcherInterface $eventDispatcher */ |
|
| 124 | - $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class); |
|
| 125 | - $this->consoleHooks($logger, $eventDispatcher); |
|
| 126 | - $this->appHooks($logger, $eventDispatcher); |
|
| 127 | - |
|
| 128 | - $this->sharingHooks($logger); |
|
| 129 | - |
|
| 130 | - $this->fileHooks($logger, $eventDispatcher); |
|
| 131 | - $this->trashbinHooks($logger); |
|
| 132 | - $this->versionsHooks($logger); |
|
| 133 | - |
|
| 134 | - $this->securityHooks($logger, $eventDispatcher); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - private function userManagementHooks(LoggerInterface $logger, |
|
| 138 | - IUserSession $userSession): void { |
|
| 139 | - $userActions = new UserManagement($logger); |
|
| 140 | - |
|
| 141 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 142 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 143 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 144 | - |
|
| 145 | - assert($userSession instanceof UserSession); |
|
| 146 | - $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 147 | - $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
| 148 | - $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - private function groupHooks(LoggerInterface $logger, |
|
| 152 | - IGroupManager $groupManager): void { |
|
| 153 | - $groupActions = new GroupManagement($logger); |
|
| 154 | - |
|
| 155 | - assert($groupManager instanceof GroupManager); |
|
| 156 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 157 | - $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 158 | - $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 159 | - $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - private function sharingHooks(LoggerInterface $logger): void { |
|
| 163 | - $shareActions = new Sharing($logger); |
|
| 164 | - |
|
| 165 | - Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
| 166 | - Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
| 167 | - Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
| 168 | - Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 169 | - Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 170 | - Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 171 | - Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - private function authHooks(LoggerInterface $logger): void { |
|
| 175 | - $authActions = new Auth($logger); |
|
| 176 | - |
|
| 177 | - Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 178 | - Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 179 | - Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - private function appHooks(LoggerInterface $logger, |
|
| 183 | - EventDispatcherInterface $eventDispatcher): void { |
|
| 184 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
| 185 | - $appActions = new AppManagement($logger); |
|
| 186 | - $appActions->enableApp($event->getAppID()); |
|
| 187 | - }); |
|
| 188 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
| 189 | - $appActions = new AppManagement($logger); |
|
| 190 | - $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
| 191 | - }); |
|
| 192 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
| 193 | - $appActions = new AppManagement($logger); |
|
| 194 | - $appActions->disableApp($event->getAppID()); |
|
| 195 | - }); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - private function consoleHooks(LoggerInterface $logger, |
|
| 199 | - EventDispatcherInterface $eventDispatcher): void { |
|
| 200 | - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
| 201 | - $appActions = new Console($logger); |
|
| 202 | - $appActions->runCommand($event->getArguments()); |
|
| 203 | - }); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - private function fileHooks(LoggerInterface $logger, |
|
| 207 | - EventDispatcherInterface $eventDispatcher): void { |
|
| 208 | - $fileActions = new Files($logger); |
|
| 209 | - $eventDispatcher->addListener( |
|
| 210 | - IPreview::EVENT, |
|
| 211 | - function (GenericEvent $event) use ($fileActions) { |
|
| 212 | - /** @var File $file */ |
|
| 213 | - $file = $event->getSubject(); |
|
| 214 | - $fileActions->preview([ |
|
| 215 | - 'path' => mb_substr($file->getInternalPath(), 5), |
|
| 216 | - 'width' => $event->getArguments()['width'], |
|
| 217 | - 'height' => $event->getArguments()['height'], |
|
| 218 | - 'crop' => $event->getArguments()['crop'], |
|
| 219 | - 'mode' => $event->getArguments()['mode'] |
|
| 220 | - ]); |
|
| 221 | - } |
|
| 222 | - ); |
|
| 223 | - |
|
| 224 | - Util::connectHook( |
|
| 225 | - Filesystem::CLASSNAME, |
|
| 226 | - Filesystem::signal_post_rename, |
|
| 227 | - $fileActions, |
|
| 228 | - 'rename' |
|
| 229 | - ); |
|
| 230 | - Util::connectHook( |
|
| 231 | - Filesystem::CLASSNAME, |
|
| 232 | - Filesystem::signal_post_create, |
|
| 233 | - $fileActions, |
|
| 234 | - 'create' |
|
| 235 | - ); |
|
| 236 | - Util::connectHook( |
|
| 237 | - Filesystem::CLASSNAME, |
|
| 238 | - Filesystem::signal_post_copy, |
|
| 239 | - $fileActions, |
|
| 240 | - 'copy' |
|
| 241 | - ); |
|
| 242 | - Util::connectHook( |
|
| 243 | - Filesystem::CLASSNAME, |
|
| 244 | - Filesystem::signal_post_write, |
|
| 245 | - $fileActions, |
|
| 246 | - 'write' |
|
| 247 | - ); |
|
| 248 | - Util::connectHook( |
|
| 249 | - Filesystem::CLASSNAME, |
|
| 250 | - Filesystem::signal_post_update, |
|
| 251 | - $fileActions, |
|
| 252 | - 'update' |
|
| 253 | - ); |
|
| 254 | - Util::connectHook( |
|
| 255 | - Filesystem::CLASSNAME, |
|
| 256 | - Filesystem::signal_read, |
|
| 257 | - $fileActions, |
|
| 258 | - 'read' |
|
| 259 | - ); |
|
| 260 | - Util::connectHook( |
|
| 261 | - Filesystem::CLASSNAME, |
|
| 262 | - Filesystem::signal_delete, |
|
| 263 | - $fileActions, |
|
| 264 | - 'delete' |
|
| 265 | - ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - private function versionsHooks(LoggerInterface $logger): void { |
|
| 269 | - $versionsActions = new Versions($logger); |
|
| 270 | - Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 271 | - Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - private function trashbinHooks(LoggerInterface $logger): void { |
|
| 275 | - $trashActions = new Trashbin($logger); |
|
| 276 | - Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 277 | - Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - private function securityHooks(LoggerInterface $logger, |
|
| 281 | - EventDispatcherInterface $eventDispatcher): void { |
|
| 282 | - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
| 283 | - $security = new Security($logger); |
|
| 284 | - $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
| 285 | - }); |
|
| 286 | - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
| 287 | - $security = new Security($logger); |
|
| 288 | - $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
| 289 | - }); |
|
| 290 | - } |
|
| 95 | + $this->registerHooks($logger, $context->getServerContainer()); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + private function getLogger(IConfig $config, |
|
| 99 | + ILogFactory $logFactory): LoggerInterface { |
|
| 100 | + $auditType = $config->getSystemValueString('log_type_audit', 'file'); |
|
| 101 | + $defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud'); |
|
| 102 | + $auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag); |
|
| 103 | + $logFile = $config->getSystemValueString('logfile_audit', ''); |
|
| 104 | + |
|
| 105 | + if ($auditType === 'file' && !$logFile) { |
|
| 106 | + $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
| 107 | + // Legacy way was appconfig, now it's paralleled with the normal log config |
|
| 108 | + $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Register hooks in order to log them |
|
| 116 | + */ |
|
| 117 | + private function registerHooks(LoggerInterface $logger, |
|
| 118 | + IServerContainer $serverContainer): void { |
|
| 119 | + $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); |
|
| 120 | + $this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); |
|
| 121 | + $this->authHooks($logger); |
|
| 122 | + |
|
| 123 | + /** @var EventDispatcherInterface $eventDispatcher */ |
|
| 124 | + $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class); |
|
| 125 | + $this->consoleHooks($logger, $eventDispatcher); |
|
| 126 | + $this->appHooks($logger, $eventDispatcher); |
|
| 127 | + |
|
| 128 | + $this->sharingHooks($logger); |
|
| 129 | + |
|
| 130 | + $this->fileHooks($logger, $eventDispatcher); |
|
| 131 | + $this->trashbinHooks($logger); |
|
| 132 | + $this->versionsHooks($logger); |
|
| 133 | + |
|
| 134 | + $this->securityHooks($logger, $eventDispatcher); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + private function userManagementHooks(LoggerInterface $logger, |
|
| 138 | + IUserSession $userSession): void { |
|
| 139 | + $userActions = new UserManagement($logger); |
|
| 140 | + |
|
| 141 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
| 142 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
| 143 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
| 144 | + |
|
| 145 | + assert($userSession instanceof UserSession); |
|
| 146 | + $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
| 147 | + $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
| 148 | + $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + private function groupHooks(LoggerInterface $logger, |
|
| 152 | + IGroupManager $groupManager): void { |
|
| 153 | + $groupActions = new GroupManagement($logger); |
|
| 154 | + |
|
| 155 | + assert($groupManager instanceof GroupManager); |
|
| 156 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
| 157 | + $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
| 158 | + $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
| 159 | + $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + private function sharingHooks(LoggerInterface $logger): void { |
|
| 163 | + $shareActions = new Sharing($logger); |
|
| 164 | + |
|
| 165 | + Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
| 166 | + Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
| 167 | + Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
| 168 | + Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
| 169 | + Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
| 170 | + Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
| 171 | + Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + private function authHooks(LoggerInterface $logger): void { |
|
| 175 | + $authActions = new Auth($logger); |
|
| 176 | + |
|
| 177 | + Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
| 178 | + Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
| 179 | + Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + private function appHooks(LoggerInterface $logger, |
|
| 183 | + EventDispatcherInterface $eventDispatcher): void { |
|
| 184 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
| 185 | + $appActions = new AppManagement($logger); |
|
| 186 | + $appActions->enableApp($event->getAppID()); |
|
| 187 | + }); |
|
| 188 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
| 189 | + $appActions = new AppManagement($logger); |
|
| 190 | + $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
| 191 | + }); |
|
| 192 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
| 193 | + $appActions = new AppManagement($logger); |
|
| 194 | + $appActions->disableApp($event->getAppID()); |
|
| 195 | + }); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + private function consoleHooks(LoggerInterface $logger, |
|
| 199 | + EventDispatcherInterface $eventDispatcher): void { |
|
| 200 | + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
| 201 | + $appActions = new Console($logger); |
|
| 202 | + $appActions->runCommand($event->getArguments()); |
|
| 203 | + }); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + private function fileHooks(LoggerInterface $logger, |
|
| 207 | + EventDispatcherInterface $eventDispatcher): void { |
|
| 208 | + $fileActions = new Files($logger); |
|
| 209 | + $eventDispatcher->addListener( |
|
| 210 | + IPreview::EVENT, |
|
| 211 | + function (GenericEvent $event) use ($fileActions) { |
|
| 212 | + /** @var File $file */ |
|
| 213 | + $file = $event->getSubject(); |
|
| 214 | + $fileActions->preview([ |
|
| 215 | + 'path' => mb_substr($file->getInternalPath(), 5), |
|
| 216 | + 'width' => $event->getArguments()['width'], |
|
| 217 | + 'height' => $event->getArguments()['height'], |
|
| 218 | + 'crop' => $event->getArguments()['crop'], |
|
| 219 | + 'mode' => $event->getArguments()['mode'] |
|
| 220 | + ]); |
|
| 221 | + } |
|
| 222 | + ); |
|
| 223 | + |
|
| 224 | + Util::connectHook( |
|
| 225 | + Filesystem::CLASSNAME, |
|
| 226 | + Filesystem::signal_post_rename, |
|
| 227 | + $fileActions, |
|
| 228 | + 'rename' |
|
| 229 | + ); |
|
| 230 | + Util::connectHook( |
|
| 231 | + Filesystem::CLASSNAME, |
|
| 232 | + Filesystem::signal_post_create, |
|
| 233 | + $fileActions, |
|
| 234 | + 'create' |
|
| 235 | + ); |
|
| 236 | + Util::connectHook( |
|
| 237 | + Filesystem::CLASSNAME, |
|
| 238 | + Filesystem::signal_post_copy, |
|
| 239 | + $fileActions, |
|
| 240 | + 'copy' |
|
| 241 | + ); |
|
| 242 | + Util::connectHook( |
|
| 243 | + Filesystem::CLASSNAME, |
|
| 244 | + Filesystem::signal_post_write, |
|
| 245 | + $fileActions, |
|
| 246 | + 'write' |
|
| 247 | + ); |
|
| 248 | + Util::connectHook( |
|
| 249 | + Filesystem::CLASSNAME, |
|
| 250 | + Filesystem::signal_post_update, |
|
| 251 | + $fileActions, |
|
| 252 | + 'update' |
|
| 253 | + ); |
|
| 254 | + Util::connectHook( |
|
| 255 | + Filesystem::CLASSNAME, |
|
| 256 | + Filesystem::signal_read, |
|
| 257 | + $fileActions, |
|
| 258 | + 'read' |
|
| 259 | + ); |
|
| 260 | + Util::connectHook( |
|
| 261 | + Filesystem::CLASSNAME, |
|
| 262 | + Filesystem::signal_delete, |
|
| 263 | + $fileActions, |
|
| 264 | + 'delete' |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + private function versionsHooks(LoggerInterface $logger): void { |
|
| 269 | + $versionsActions = new Versions($logger); |
|
| 270 | + Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
| 271 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + private function trashbinHooks(LoggerInterface $logger): void { |
|
| 275 | + $trashActions = new Trashbin($logger); |
|
| 276 | + Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
| 277 | + Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + private function securityHooks(LoggerInterface $logger, |
|
| 281 | + EventDispatcherInterface $eventDispatcher): void { |
|
| 282 | + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
| 283 | + $security = new Security($logger); |
|
| 284 | + $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
| 285 | + }); |
|
| 286 | + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
| 287 | + $security = new Security($logger); |
|
| 288 | + $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
| 289 | + }); |
|
| 290 | + } |
|
| 291 | 291 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $logFile = $config->getSystemValueString('logfile_audit', ''); |
| 104 | 104 | |
| 105 | 105 | if ($auditType === 'file' && !$logFile) { |
| 106 | - $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
| 106 | + $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/audit.log'; |
|
| 107 | 107 | // Legacy way was appconfig, now it's paralleled with the normal log config |
| 108 | 108 | $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
| 109 | 109 | } |
@@ -181,15 +181,15 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | private function appHooks(LoggerInterface $logger, |
| 183 | 183 | EventDispatcherInterface $eventDispatcher): void { |
| 184 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
| 184 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) use ($logger) { |
|
| 185 | 185 | $appActions = new AppManagement($logger); |
| 186 | 186 | $appActions->enableApp($event->getAppID()); |
| 187 | 187 | }); |
| 188 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
| 188 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) use ($logger) { |
|
| 189 | 189 | $appActions = new AppManagement($logger); |
| 190 | 190 | $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
| 191 | 191 | }); |
| 192 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
| 192 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) use ($logger) { |
|
| 193 | 193 | $appActions = new AppManagement($logger); |
| 194 | 194 | $appActions->disableApp($event->getAppID()); |
| 195 | 195 | }); |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | private function consoleHooks(LoggerInterface $logger, |
| 199 | 199 | EventDispatcherInterface $eventDispatcher): void { |
| 200 | - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
| 200 | + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) use ($logger) { |
|
| 201 | 201 | $appActions = new Console($logger); |
| 202 | 202 | $appActions->runCommand($event->getArguments()); |
| 203 | 203 | }); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $fileActions = new Files($logger); |
| 209 | 209 | $eventDispatcher->addListener( |
| 210 | 210 | IPreview::EVENT, |
| 211 | - function (GenericEvent $event) use ($fileActions) { |
|
| 211 | + function(GenericEvent $event) use ($fileActions) { |
|
| 212 | 212 | /** @var File $file */ |
| 213 | 213 | $file = $event->getSubject(); |
| 214 | 214 | $fileActions->preview([ |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | private function securityHooks(LoggerInterface $logger, |
| 281 | 281 | EventDispatcherInterface $eventDispatcher): void { |
| 282 | - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
| 282 | + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) use ($logger) { |
|
| 283 | 283 | $security = new Security($logger); |
| 284 | 284 | $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
| 285 | 285 | }); |
| 286 | - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
| 286 | + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) use ($logger) { |
|
| 287 | 287 | $security = new Security($logger); |
| 288 | 288 | $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
| 289 | 289 | }); |
@@ -29,20 +29,20 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Errorlog implements IWriter { |
| 31 | 31 | |
| 32 | - /** @var string */ |
|
| 33 | - protected $tag; |
|
| 32 | + /** @var string */ |
|
| 33 | + protected $tag; |
|
| 34 | 34 | |
| 35 | - public function __construct(string $tag = 'owncloud') { |
|
| 36 | - $this->tag = $tag; |
|
| 37 | - } |
|
| 35 | + public function __construct(string $tag = 'owncloud') { |
|
| 36 | + $this->tag = $tag; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * write a message in the log |
|
| 41 | - * @param string $app |
|
| 42 | - * @param string $message |
|
| 43 | - * @param int $level |
|
| 44 | - */ |
|
| 45 | - public function write(string $app, $message, int $level) { |
|
| 46 | - error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$message); |
|
| 47 | - } |
|
| 39 | + /** |
|
| 40 | + * write a message in the log |
|
| 41 | + * @param string $app |
|
| 42 | + * @param string $message |
|
| 43 | + * @param int $level |
|
| 44 | + */ |
|
| 45 | + public function write(string $app, $message, int $level) { |
|
| 46 | + error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$message); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -43,6 +43,6 @@ |
||
| 43 | 43 | * @param int $level |
| 44 | 44 | */ |
| 45 | 45 | public function write(string $app, $message, int $level) { |
| 46 | - error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$message); |
|
| 46 | + error_log('['.$this->tag.']['.$app.']['.$level.'] '.$message); |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -46,39 +46,39 @@ |
||
| 46 | 46 | // Syslog compatibility fields |
| 47 | 47 | |
| 48 | 48 | class Systemdlog extends LogDetails implements IWriter { |
| 49 | - protected $levels = [ |
|
| 50 | - ILogger::DEBUG => 7, |
|
| 51 | - ILogger::INFO => 6, |
|
| 52 | - ILogger::WARN => 4, |
|
| 53 | - ILogger::ERROR => 3, |
|
| 54 | - ILogger::FATAL => 2, |
|
| 55 | - ]; |
|
| 49 | + protected $levels = [ |
|
| 50 | + ILogger::DEBUG => 7, |
|
| 51 | + ILogger::INFO => 6, |
|
| 52 | + ILogger::WARN => 4, |
|
| 53 | + ILogger::ERROR => 3, |
|
| 54 | + ILogger::FATAL => 2, |
|
| 55 | + ]; |
|
| 56 | 56 | |
| 57 | - protected $syslogId; |
|
| 57 | + protected $syslogId; |
|
| 58 | 58 | |
| 59 | - public function __construct(SystemConfig $config, ?string $tag = null) { |
|
| 60 | - parent::__construct($config); |
|
| 61 | - if (!function_exists('sd_journal_send')) { |
|
| 62 | - throw new HintException( |
|
| 63 | - 'PHP extension php-systemd is not available.', |
|
| 64 | - 'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.'); |
|
| 65 | - } |
|
| 66 | - if ($tag === null) { |
|
| 67 | - $tag = $config->getValue('syslog_tag', 'Nextcloud'); |
|
| 68 | - } |
|
| 69 | - $this->syslogId = $tag; |
|
| 70 | - } |
|
| 59 | + public function __construct(SystemConfig $config, ?string $tag = null) { |
|
| 60 | + parent::__construct($config); |
|
| 61 | + if (!function_exists('sd_journal_send')) { |
|
| 62 | + throw new HintException( |
|
| 63 | + 'PHP extension php-systemd is not available.', |
|
| 64 | + 'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.'); |
|
| 65 | + } |
|
| 66 | + if ($tag === null) { |
|
| 67 | + $tag = $config->getValue('syslog_tag', 'Nextcloud'); |
|
| 68 | + } |
|
| 69 | + $this->syslogId = $tag; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Write a message to the log. |
|
| 74 | - * @param string $app |
|
| 75 | - * @param string $message |
|
| 76 | - * @param int $level |
|
| 77 | - */ |
|
| 78 | - public function write(string $app, $message, int $level) { |
|
| 79 | - $journal_level = $this->levels[$level]; |
|
| 80 | - sd_journal_send('PRIORITY='.$journal_level, |
|
| 81 | - 'SYSLOG_IDENTIFIER='.$this->syslogId, |
|
| 82 | - 'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level)); |
|
| 83 | - } |
|
| 72 | + /** |
|
| 73 | + * Write a message to the log. |
|
| 74 | + * @param string $app |
|
| 75 | + * @param string $message |
|
| 76 | + * @param int $level |
|
| 77 | + */ |
|
| 78 | + public function write(string $app, $message, int $level) { |
|
| 79 | + $journal_level = $this->levels[$level]; |
|
| 80 | + sd_journal_send('PRIORITY='.$journal_level, |
|
| 81 | + 'SYSLOG_IDENTIFIER='.$this->syslogId, |
|
| 82 | + 'MESSAGE=' . $this->logDetailsAsJSON($app, $message, $level)); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -33,73 +33,73 @@ |
||
| 33 | 33 | use Psr\Log\LoggerInterface; |
| 34 | 34 | |
| 35 | 35 | class LogFactory implements ILogFactory { |
| 36 | - /** @var IServerContainer */ |
|
| 37 | - private $c; |
|
| 38 | - /** @var SystemConfig */ |
|
| 39 | - private $systemConfig; |
|
| 36 | + /** @var IServerContainer */ |
|
| 37 | + private $c; |
|
| 38 | + /** @var SystemConfig */ |
|
| 39 | + private $systemConfig; |
|
| 40 | 40 | |
| 41 | - public function __construct(IServerContainer $c, SystemConfig $systemConfig) { |
|
| 42 | - $this->c = $c; |
|
| 43 | - $this->systemConfig = $systemConfig; |
|
| 44 | - } |
|
| 41 | + public function __construct(IServerContainer $c, SystemConfig $systemConfig) { |
|
| 42 | + $this->c = $c; |
|
| 43 | + $this->systemConfig = $systemConfig; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @throws \OCP\AppFramework\QueryException |
|
| 48 | - */ |
|
| 49 | - public function get(string $type):IWriter { |
|
| 50 | - switch (strtolower($type)) { |
|
| 51 | - case 'errorlog': |
|
| 52 | - return new Errorlog(); |
|
| 53 | - case 'syslog': |
|
| 54 | - return $this->c->resolve(Syslog::class); |
|
| 55 | - case 'systemd': |
|
| 56 | - return $this->c->resolve(Systemdlog::class); |
|
| 57 | - case 'file': |
|
| 58 | - return $this->buildLogFile(); |
|
| 46 | + /** |
|
| 47 | + * @throws \OCP\AppFramework\QueryException |
|
| 48 | + */ |
|
| 49 | + public function get(string $type):IWriter { |
|
| 50 | + switch (strtolower($type)) { |
|
| 51 | + case 'errorlog': |
|
| 52 | + return new Errorlog(); |
|
| 53 | + case 'syslog': |
|
| 54 | + return $this->c->resolve(Syslog::class); |
|
| 55 | + case 'systemd': |
|
| 56 | + return $this->c->resolve(Systemdlog::class); |
|
| 57 | + case 'file': |
|
| 58 | + return $this->buildLogFile(); |
|
| 59 | 59 | |
| 60 | - // Backwards compatibility for old and fallback for unknown log types |
|
| 61 | - case 'owncloud': |
|
| 62 | - case 'nextcloud': |
|
| 63 | - default: |
|
| 64 | - return $this->buildLogFile(); |
|
| 65 | - } |
|
| 66 | - } |
|
| 60 | + // Backwards compatibility for old and fallback for unknown log types |
|
| 61 | + case 'owncloud': |
|
| 62 | + case 'nextcloud': |
|
| 63 | + default: |
|
| 64 | + return $this->buildLogFile(); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function getCustomLogger(string $path):ILogger { |
|
| 69 | - $log = $this->buildLogFile($path); |
|
| 70 | - return new Log($log, $this->systemConfig); |
|
| 71 | - } |
|
| 68 | + public function getCustomLogger(string $path):ILogger { |
|
| 69 | + $log = $this->buildLogFile($path); |
|
| 70 | + return new Log($log, $this->systemConfig); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - protected function createNewLogger(string $type, string $tag, string $path): IWriter { |
|
| 74 | - switch (strtolower($type)) { |
|
| 75 | - case 'errorlog': |
|
| 76 | - return new Errorlog($tag); |
|
| 77 | - case 'syslog': |
|
| 78 | - return new Syslog($this->systemConfig, $tag); |
|
| 79 | - case 'systemd': |
|
| 80 | - return new Systemdlog($this->systemConfig, $tag); |
|
| 81 | - case 'file': |
|
| 82 | - case 'owncloud': |
|
| 83 | - case 'nextcloud': |
|
| 84 | - default: |
|
| 85 | - return $this->buildLogFile($path); |
|
| 86 | - } |
|
| 87 | - } |
|
| 73 | + protected function createNewLogger(string $type, string $tag, string $path): IWriter { |
|
| 74 | + switch (strtolower($type)) { |
|
| 75 | + case 'errorlog': |
|
| 76 | + return new Errorlog($tag); |
|
| 77 | + case 'syslog': |
|
| 78 | + return new Syslog($this->systemConfig, $tag); |
|
| 79 | + case 'systemd': |
|
| 80 | + return new Systemdlog($this->systemConfig, $tag); |
|
| 81 | + case 'file': |
|
| 82 | + case 'owncloud': |
|
| 83 | + case 'nextcloud': |
|
| 84 | + default: |
|
| 85 | + return $this->buildLogFile($path); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface { |
|
| 90 | - $log = $this->createNewLogger($type, $tag, $path); |
|
| 91 | - return new PsrLoggerAdapter( |
|
| 92 | - new Log($log, $this->systemConfig) |
|
| 93 | - ); |
|
| 94 | - } |
|
| 89 | + public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface { |
|
| 90 | + $log = $this->createNewLogger($type, $tag, $path); |
|
| 91 | + return new PsrLoggerAdapter( |
|
| 92 | + new Log($log, $this->systemConfig) |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - protected function buildLogFile(string $logFile = ''):File { |
|
| 97 | - $defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log'; |
|
| 98 | - if ($logFile === '') { |
|
| 99 | - $logFile = $this->systemConfig->getValue('logfile', $defaultLogFile); |
|
| 100 | - } |
|
| 101 | - $fallback = $defaultLogFile !== $logFile ? $defaultLogFile : ''; |
|
| 96 | + protected function buildLogFile(string $logFile = ''):File { |
|
| 97 | + $defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log'; |
|
| 98 | + if ($logFile === '') { |
|
| 99 | + $logFile = $this->systemConfig->getValue('logfile', $defaultLogFile); |
|
| 100 | + } |
|
| 101 | + $fallback = $defaultLogFile !== $logFile ? $defaultLogFile : ''; |
|
| 102 | 102 | |
| 103 | - return new File($logFile, $fallback, $this->systemConfig); |
|
| 104 | - } |
|
| 103 | + return new File($logFile, $fallback, $this->systemConfig); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -30,34 +30,34 @@ |
||
| 30 | 30 | use OCP\Log\IWriter; |
| 31 | 31 | |
| 32 | 32 | class Syslog extends LogDetails implements IWriter { |
| 33 | - protected $levels = [ |
|
| 34 | - ILogger::DEBUG => LOG_DEBUG, |
|
| 35 | - ILogger::INFO => LOG_INFO, |
|
| 36 | - ILogger::WARN => LOG_WARNING, |
|
| 37 | - ILogger::ERROR => LOG_ERR, |
|
| 38 | - ILogger::FATAL => LOG_CRIT, |
|
| 39 | - ]; |
|
| 33 | + protected $levels = [ |
|
| 34 | + ILogger::DEBUG => LOG_DEBUG, |
|
| 35 | + ILogger::INFO => LOG_INFO, |
|
| 36 | + ILogger::WARN => LOG_WARNING, |
|
| 37 | + ILogger::ERROR => LOG_ERR, |
|
| 38 | + ILogger::FATAL => LOG_CRIT, |
|
| 39 | + ]; |
|
| 40 | 40 | |
| 41 | - public function __construct(SystemConfig $config, ?string $tag = null) { |
|
| 42 | - parent::__construct($config); |
|
| 43 | - if ($tag === null) { |
|
| 44 | - $tag = $config->getValue('syslog_tag', 'Nextcloud'); |
|
| 45 | - } |
|
| 46 | - openlog($tag, LOG_PID | LOG_CONS, LOG_USER); |
|
| 47 | - } |
|
| 41 | + public function __construct(SystemConfig $config, ?string $tag = null) { |
|
| 42 | + parent::__construct($config); |
|
| 43 | + if ($tag === null) { |
|
| 44 | + $tag = $config->getValue('syslog_tag', 'Nextcloud'); |
|
| 45 | + } |
|
| 46 | + openlog($tag, LOG_PID | LOG_CONS, LOG_USER); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function __destruct() { |
|
| 50 | - closelog(); |
|
| 51 | - } |
|
| 49 | + public function __destruct() { |
|
| 50 | + closelog(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * write a message in the log |
|
| 55 | - * @param string $app |
|
| 56 | - * @param string $message |
|
| 57 | - * @param int $level |
|
| 58 | - */ |
|
| 59 | - public function write(string $app, $message, int $level) { |
|
| 60 | - $syslog_level = $this->levels[$level]; |
|
| 61 | - syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level)); |
|
| 62 | - } |
|
| 53 | + /** |
|
| 54 | + * write a message in the log |
|
| 55 | + * @param string $app |
|
| 56 | + * @param string $message |
|
| 57 | + * @param int $level |
|
| 58 | + */ |
|
| 59 | + public function write(string $app, $message, int $level) { |
|
| 60 | + $syslog_level = $this->levels[$level]; |
|
| 61 | + syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level)); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -33,28 +33,28 @@ |
||
| 33 | 33 | * @since 14.0.0 |
| 34 | 34 | */ |
| 35 | 35 | interface ILogFactory { |
| 36 | - /** |
|
| 37 | - * @param string $type - one of: file, errorlog, syslog, systemd |
|
| 38 | - * @return IWriter |
|
| 39 | - * @since 14.0.0 |
|
| 40 | - */ |
|
| 41 | - public function get(string $type): IWriter; |
|
| 36 | + /** |
|
| 37 | + * @param string $type - one of: file, errorlog, syslog, systemd |
|
| 38 | + * @return IWriter |
|
| 39 | + * @since 14.0.0 |
|
| 40 | + */ |
|
| 41 | + public function get(string $type): IWriter; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $path |
|
| 45 | - * @return ILogger |
|
| 46 | - * @since 14.0.0 |
|
| 47 | - * @deprecated use \OCP\Log\ILogFactory::getCustomPsrLogger |
|
| 48 | - * @see \OCP\Log\ILogFactory::getCustomPsrLogger |
|
| 49 | - */ |
|
| 50 | - public function getCustomLogger(string $path): ILogger; |
|
| 43 | + /** |
|
| 44 | + * @param string $path |
|
| 45 | + * @return ILogger |
|
| 46 | + * @since 14.0.0 |
|
| 47 | + * @deprecated use \OCP\Log\ILogFactory::getCustomPsrLogger |
|
| 48 | + * @see \OCP\Log\ILogFactory::getCustomPsrLogger |
|
| 49 | + */ |
|
| 50 | + public function getCustomLogger(string $path): ILogger; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $path |
|
| 54 | - * @param string $type |
|
| 55 | - * @param string $tag |
|
| 56 | - * @return LoggerInterface |
|
| 57 | - * @since 22.0.0 - Parameters $type and $tag were added in 24.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface; |
|
| 52 | + /** |
|
| 53 | + * @param string $path |
|
| 54 | + * @param string $type |
|
| 55 | + * @param string $tag |
|
| 56 | + * @return LoggerInterface |
|
| 57 | + * @since 22.0.0 - Parameters $type and $tag were added in 24.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface; |
|
| 60 | 60 | } |