@@ -74,207 +74,207 @@ |
||
74 | 74 | |
75 | 75 | class Application extends App implements IBootstrap { |
76 | 76 | |
77 | - /** @var LoggerInterface */ |
|
78 | - protected $logger; |
|
77 | + /** @var LoggerInterface */ |
|
78 | + protected $logger; |
|
79 | 79 | |
80 | - public function __construct() { |
|
81 | - parent::__construct('admin_audit'); |
|
82 | - } |
|
80 | + public function __construct() { |
|
81 | + parent::__construct('admin_audit'); |
|
82 | + } |
|
83 | 83 | |
84 | - public function register(IRegistrationContext $context): void { |
|
85 | - $context->registerService(IAuditLogger::class, function (ContainerInterface $c) { |
|
86 | - return new AuditLogger($c->get(ILogFactory::class), $c->get(Iconfig::class)); |
|
87 | - }); |
|
84 | + public function register(IRegistrationContext $context): void { |
|
85 | + $context->registerService(IAuditLogger::class, function (ContainerInterface $c) { |
|
86 | + return new AuditLogger($c->get(ILogFactory::class), $c->get(Iconfig::class)); |
|
87 | + }); |
|
88 | 88 | |
89 | - $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
90 | - } |
|
89 | + $context->registerEventListener(CriticalActionPerformedEvent::class, CriticalActionPerformedEventListener::class); |
|
90 | + } |
|
91 | 91 | |
92 | - public function boot(IBootContext $context): void { |
|
93 | - /** @var IAuditLogger $logger */ |
|
94 | - $logger = $context->getAppContainer()->get(IAuditLogger::class); |
|
92 | + public function boot(IBootContext $context): void { |
|
93 | + /** @var IAuditLogger $logger */ |
|
94 | + $logger = $context->getAppContainer()->get(IAuditLogger::class); |
|
95 | 95 | |
96 | - /* |
|
96 | + /* |
|
97 | 97 | * TODO: once the hooks are migrated to lazy events, this should be done |
98 | 98 | * in \OCA\AdminAudit\AppInfo\Application::register |
99 | 99 | */ |
100 | - $this->registerHooks($logger, $context->getServerContainer()); |
|
101 | - } |
|
100 | + $this->registerHooks($logger, $context->getServerContainer()); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Register hooks in order to log them |
|
105 | - */ |
|
106 | - private function registerHooks(IAuditLogger $logger, |
|
107 | - IServerContainer $serverContainer): void { |
|
108 | - $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); |
|
109 | - $this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); |
|
110 | - $this->authHooks($logger); |
|
103 | + /** |
|
104 | + * Register hooks in order to log them |
|
105 | + */ |
|
106 | + private function registerHooks(IAuditLogger $logger, |
|
107 | + IServerContainer $serverContainer): void { |
|
108 | + $this->userManagementHooks($logger, $serverContainer->get(IUserSession::class)); |
|
109 | + $this->groupHooks($logger, $serverContainer->get(IGroupManager::class)); |
|
110 | + $this->authHooks($logger); |
|
111 | 111 | |
112 | - /** @var EventDispatcherInterface $eventDispatcher */ |
|
113 | - $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class); |
|
114 | - $this->consoleHooks($logger, $eventDispatcher); |
|
115 | - $this->appHooks($logger, $eventDispatcher); |
|
112 | + /** @var EventDispatcherInterface $eventDispatcher */ |
|
113 | + $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class); |
|
114 | + $this->consoleHooks($logger, $eventDispatcher); |
|
115 | + $this->appHooks($logger, $eventDispatcher); |
|
116 | 116 | |
117 | - $this->sharingHooks($logger); |
|
117 | + $this->sharingHooks($logger); |
|
118 | 118 | |
119 | - $this->fileHooks($logger, $eventDispatcher); |
|
120 | - $this->trashbinHooks($logger); |
|
121 | - $this->versionsHooks($logger); |
|
119 | + $this->fileHooks($logger, $eventDispatcher); |
|
120 | + $this->trashbinHooks($logger); |
|
121 | + $this->versionsHooks($logger); |
|
122 | 122 | |
123 | - $this->securityHooks($logger, $eventDispatcher); |
|
124 | - } |
|
123 | + $this->securityHooks($logger, $eventDispatcher); |
|
124 | + } |
|
125 | 125 | |
126 | - private function userManagementHooks(IAuditLogger $logger, |
|
127 | - IUserSession $userSession): void { |
|
128 | - $userActions = new UserManagement($logger); |
|
126 | + private function userManagementHooks(IAuditLogger $logger, |
|
127 | + IUserSession $userSession): void { |
|
128 | + $userActions = new UserManagement($logger); |
|
129 | 129 | |
130 | - Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
131 | - Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
132 | - Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
130 | + Util::connectHook('OC_User', 'post_createUser', $userActions, 'create'); |
|
131 | + Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete'); |
|
132 | + Util::connectHook('OC_User', 'changeUser', $userActions, 'change'); |
|
133 | 133 | |
134 | - assert($userSession instanceof UserSession); |
|
135 | - $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
136 | - $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
137 | - $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
138 | - } |
|
134 | + assert($userSession instanceof UserSession); |
|
135 | + $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']); |
|
136 | + $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']); |
|
137 | + $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']); |
|
138 | + } |
|
139 | 139 | |
140 | - private function groupHooks(IAuditLogger $logger, |
|
141 | - IGroupManager $groupManager): void { |
|
142 | - $groupActions = new GroupManagement($logger); |
|
140 | + private function groupHooks(IAuditLogger $logger, |
|
141 | + IGroupManager $groupManager): void { |
|
142 | + $groupActions = new GroupManagement($logger); |
|
143 | 143 | |
144 | - assert($groupManager instanceof GroupManager); |
|
145 | - $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
146 | - $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
147 | - $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
148 | - $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
149 | - } |
|
144 | + assert($groupManager instanceof GroupManager); |
|
145 | + $groupManager->listen('\OC\Group', 'postRemoveUser', [$groupActions, 'removeUser']); |
|
146 | + $groupManager->listen('\OC\Group', 'postAddUser', [$groupActions, 'addUser']); |
|
147 | + $groupManager->listen('\OC\Group', 'postDelete', [$groupActions, 'deleteGroup']); |
|
148 | + $groupManager->listen('\OC\Group', 'postCreate', [$groupActions, 'createGroup']); |
|
149 | + } |
|
150 | 150 | |
151 | - private function sharingHooks(IAuditLogger $logger): void { |
|
152 | - $shareActions = new Sharing($logger); |
|
151 | + private function sharingHooks(IAuditLogger $logger): void { |
|
152 | + $shareActions = new Sharing($logger); |
|
153 | 153 | |
154 | - Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
155 | - Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
156 | - Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
157 | - Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
158 | - Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
159 | - Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
160 | - Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
161 | - } |
|
154 | + Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared'); |
|
155 | + Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare'); |
|
156 | + Util::connectHook(Share::class, 'post_unshareFromSelf', $shareActions, 'unshare'); |
|
157 | + Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions'); |
|
158 | + Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword'); |
|
159 | + Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate'); |
|
160 | + Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed'); |
|
161 | + } |
|
162 | 162 | |
163 | - private function authHooks(IAuditLogger $logger): void { |
|
164 | - $authActions = new Auth($logger); |
|
163 | + private function authHooks(IAuditLogger $logger): void { |
|
164 | + $authActions = new Auth($logger); |
|
165 | 165 | |
166 | - Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
167 | - Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
168 | - Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
169 | - } |
|
166 | + Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt'); |
|
167 | + Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful'); |
|
168 | + Util::connectHook('OC_User', 'logout', $authActions, 'logout'); |
|
169 | + } |
|
170 | 170 | |
171 | - private function appHooks(IAuditLogger $logger, |
|
172 | - EventDispatcherInterface $eventDispatcher): void { |
|
173 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
174 | - $appActions = new AppManagement($logger); |
|
175 | - $appActions->enableApp($event->getAppID()); |
|
176 | - }); |
|
177 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
178 | - $appActions = new AppManagement($logger); |
|
179 | - $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
180 | - }); |
|
181 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
182 | - $appActions = new AppManagement($logger); |
|
183 | - $appActions->disableApp($event->getAppID()); |
|
184 | - }); |
|
185 | - } |
|
171 | + private function appHooks(IAuditLogger $logger, |
|
172 | + EventDispatcherInterface $eventDispatcher): void { |
|
173 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
174 | + $appActions = new AppManagement($logger); |
|
175 | + $appActions->enableApp($event->getAppID()); |
|
176 | + }); |
|
177 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
178 | + $appActions = new AppManagement($logger); |
|
179 | + $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
|
180 | + }); |
|
181 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
182 | + $appActions = new AppManagement($logger); |
|
183 | + $appActions->disableApp($event->getAppID()); |
|
184 | + }); |
|
185 | + } |
|
186 | 186 | |
187 | - private function consoleHooks(IAuditLogger $logger, |
|
188 | - EventDispatcherInterface $eventDispatcher): void { |
|
189 | - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
190 | - $appActions = new Console($logger); |
|
191 | - $appActions->runCommand($event->getArguments()); |
|
192 | - }); |
|
193 | - } |
|
187 | + private function consoleHooks(IAuditLogger $logger, |
|
188 | + EventDispatcherInterface $eventDispatcher): void { |
|
189 | + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
190 | + $appActions = new Console($logger); |
|
191 | + $appActions->runCommand($event->getArguments()); |
|
192 | + }); |
|
193 | + } |
|
194 | 194 | |
195 | - private function fileHooks(IAuditLogger $logger, |
|
196 | - EventDispatcherInterface $eventDispatcher): void { |
|
197 | - $fileActions = new Files($logger); |
|
198 | - $eventDispatcher->addListener( |
|
199 | - IPreview::EVENT, |
|
200 | - function (GenericEvent $event) use ($fileActions) { |
|
201 | - /** @var File $file */ |
|
202 | - $file = $event->getSubject(); |
|
203 | - $fileActions->preview([ |
|
204 | - 'path' => mb_substr($file->getInternalPath(), 5), |
|
205 | - 'width' => $event->getArguments()['width'], |
|
206 | - 'height' => $event->getArguments()['height'], |
|
207 | - 'crop' => $event->getArguments()['crop'], |
|
208 | - 'mode' => $event->getArguments()['mode'] |
|
209 | - ]); |
|
210 | - } |
|
211 | - ); |
|
195 | + private function fileHooks(IAuditLogger $logger, |
|
196 | + EventDispatcherInterface $eventDispatcher): void { |
|
197 | + $fileActions = new Files($logger); |
|
198 | + $eventDispatcher->addListener( |
|
199 | + IPreview::EVENT, |
|
200 | + function (GenericEvent $event) use ($fileActions) { |
|
201 | + /** @var File $file */ |
|
202 | + $file = $event->getSubject(); |
|
203 | + $fileActions->preview([ |
|
204 | + 'path' => mb_substr($file->getInternalPath(), 5), |
|
205 | + 'width' => $event->getArguments()['width'], |
|
206 | + 'height' => $event->getArguments()['height'], |
|
207 | + 'crop' => $event->getArguments()['crop'], |
|
208 | + 'mode' => $event->getArguments()['mode'] |
|
209 | + ]); |
|
210 | + } |
|
211 | + ); |
|
212 | 212 | |
213 | - Util::connectHook( |
|
214 | - Filesystem::CLASSNAME, |
|
215 | - Filesystem::signal_post_rename, |
|
216 | - $fileActions, |
|
217 | - 'rename' |
|
218 | - ); |
|
219 | - Util::connectHook( |
|
220 | - Filesystem::CLASSNAME, |
|
221 | - Filesystem::signal_post_create, |
|
222 | - $fileActions, |
|
223 | - 'create' |
|
224 | - ); |
|
225 | - Util::connectHook( |
|
226 | - Filesystem::CLASSNAME, |
|
227 | - Filesystem::signal_post_copy, |
|
228 | - $fileActions, |
|
229 | - 'copy' |
|
230 | - ); |
|
231 | - Util::connectHook( |
|
232 | - Filesystem::CLASSNAME, |
|
233 | - Filesystem::signal_post_write, |
|
234 | - $fileActions, |
|
235 | - 'write' |
|
236 | - ); |
|
237 | - Util::connectHook( |
|
238 | - Filesystem::CLASSNAME, |
|
239 | - Filesystem::signal_post_update, |
|
240 | - $fileActions, |
|
241 | - 'update' |
|
242 | - ); |
|
243 | - Util::connectHook( |
|
244 | - Filesystem::CLASSNAME, |
|
245 | - Filesystem::signal_read, |
|
246 | - $fileActions, |
|
247 | - 'read' |
|
248 | - ); |
|
249 | - Util::connectHook( |
|
250 | - Filesystem::CLASSNAME, |
|
251 | - Filesystem::signal_delete, |
|
252 | - $fileActions, |
|
253 | - 'delete' |
|
254 | - ); |
|
255 | - } |
|
213 | + Util::connectHook( |
|
214 | + Filesystem::CLASSNAME, |
|
215 | + Filesystem::signal_post_rename, |
|
216 | + $fileActions, |
|
217 | + 'rename' |
|
218 | + ); |
|
219 | + Util::connectHook( |
|
220 | + Filesystem::CLASSNAME, |
|
221 | + Filesystem::signal_post_create, |
|
222 | + $fileActions, |
|
223 | + 'create' |
|
224 | + ); |
|
225 | + Util::connectHook( |
|
226 | + Filesystem::CLASSNAME, |
|
227 | + Filesystem::signal_post_copy, |
|
228 | + $fileActions, |
|
229 | + 'copy' |
|
230 | + ); |
|
231 | + Util::connectHook( |
|
232 | + Filesystem::CLASSNAME, |
|
233 | + Filesystem::signal_post_write, |
|
234 | + $fileActions, |
|
235 | + 'write' |
|
236 | + ); |
|
237 | + Util::connectHook( |
|
238 | + Filesystem::CLASSNAME, |
|
239 | + Filesystem::signal_post_update, |
|
240 | + $fileActions, |
|
241 | + 'update' |
|
242 | + ); |
|
243 | + Util::connectHook( |
|
244 | + Filesystem::CLASSNAME, |
|
245 | + Filesystem::signal_read, |
|
246 | + $fileActions, |
|
247 | + 'read' |
|
248 | + ); |
|
249 | + Util::connectHook( |
|
250 | + Filesystem::CLASSNAME, |
|
251 | + Filesystem::signal_delete, |
|
252 | + $fileActions, |
|
253 | + 'delete' |
|
254 | + ); |
|
255 | + } |
|
256 | 256 | |
257 | - private function versionsHooks(IAuditLogger $logger): void { |
|
258 | - $versionsActions = new Versions($logger); |
|
259 | - Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
260 | - Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
261 | - } |
|
257 | + private function versionsHooks(IAuditLogger $logger): void { |
|
258 | + $versionsActions = new Versions($logger); |
|
259 | + Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback'); |
|
260 | + Util::connectHook('\OCP\Versions', 'delete', $versionsActions, 'delete'); |
|
261 | + } |
|
262 | 262 | |
263 | - private function trashbinHooks(IAuditLogger $logger): void { |
|
264 | - $trashActions = new Trashbin($logger); |
|
265 | - Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
266 | - Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
267 | - } |
|
263 | + private function trashbinHooks(IAuditLogger $logger): void { |
|
264 | + $trashActions = new Trashbin($logger); |
|
265 | + Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete'); |
|
266 | + Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore'); |
|
267 | + } |
|
268 | 268 | |
269 | - private function securityHooks(IAuditLogger $logger, |
|
270 | - EventDispatcherInterface $eventDispatcher): void { |
|
271 | - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
272 | - $security = new Security($logger); |
|
273 | - $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
274 | - }); |
|
275 | - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
276 | - $security = new Security($logger); |
|
277 | - $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
278 | - }); |
|
279 | - } |
|
269 | + private function securityHooks(IAuditLogger $logger, |
|
270 | + EventDispatcherInterface $eventDispatcher): void { |
|
271 | + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
272 | + $security = new Security($logger); |
|
273 | + $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
|
274 | + }); |
|
275 | + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
276 | + $security = new Security($logger); |
|
277 | + $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
|
278 | + }); |
|
279 | + } |
|
280 | 280 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | public function register(IRegistrationContext $context): void { |
85 | - $context->registerService(IAuditLogger::class, function (ContainerInterface $c) { |
|
85 | + $context->registerService(IAuditLogger::class, function(ContainerInterface $c) { |
|
86 | 86 | return new AuditLogger($c->get(ILogFactory::class), $c->get(Iconfig::class)); |
87 | 87 | }); |
88 | 88 | |
@@ -170,15 +170,15 @@ discard block |
||
170 | 170 | |
171 | 171 | private function appHooks(IAuditLogger $logger, |
172 | 172 | EventDispatcherInterface $eventDispatcher): void { |
173 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) { |
|
173 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) use ($logger) { |
|
174 | 174 | $appActions = new AppManagement($logger); |
175 | 175 | $appActions->enableApp($event->getAppID()); |
176 | 176 | }); |
177 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function (ManagerEvent $event) use ($logger) { |
|
177 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) use ($logger) { |
|
178 | 178 | $appActions = new AppManagement($logger); |
179 | 179 | $appActions->enableAppForGroups($event->getAppID(), $event->getGroups()); |
180 | 180 | }); |
181 | - $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function (ManagerEvent $event) use ($logger) { |
|
181 | + $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) use ($logger) { |
|
182 | 182 | $appActions = new AppManagement($logger); |
183 | 183 | $appActions->disableApp($event->getAppID()); |
184 | 184 | }); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | private function consoleHooks(IAuditLogger $logger, |
188 | 188 | EventDispatcherInterface $eventDispatcher): void { |
189 | - $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) { |
|
189 | + $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) use ($logger) { |
|
190 | 190 | $appActions = new Console($logger); |
191 | 191 | $appActions->runCommand($event->getArguments()); |
192 | 192 | }); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $fileActions = new Files($logger); |
198 | 198 | $eventDispatcher->addListener( |
199 | 199 | IPreview::EVENT, |
200 | - function (GenericEvent $event) use ($fileActions) { |
|
200 | + function(GenericEvent $event) use ($fileActions) { |
|
201 | 201 | /** @var File $file */ |
202 | 202 | $file = $event->getSubject(); |
203 | 203 | $fileActions->preview([ |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | |
269 | 269 | private function securityHooks(IAuditLogger $logger, |
270 | 270 | EventDispatcherInterface $eventDispatcher): void { |
271 | - $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) { |
|
271 | + $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) use ($logger) { |
|
272 | 272 | $security = new Security($logger); |
273 | 273 | $security->twofactorSuccess($event->getSubject(), $event->getArguments()); |
274 | 274 | }); |
275 | - $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) { |
|
275 | + $eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) use ($logger) { |
|
276 | 276 | $security = new Security($logger); |
277 | 277 | $security->twofactorFailed($event->getSubject(), $event->getArguments()); |
278 | 278 | }); |
@@ -31,61 +31,61 @@ |
||
31 | 31 | use OCA\AdminAudit\IAuditLogger; |
32 | 32 | |
33 | 33 | class Action { |
34 | - /** @var IAuditLogger */ |
|
35 | - private $logger; |
|
34 | + /** @var IAuditLogger */ |
|
35 | + private $logger; |
|
36 | 36 | |
37 | - public function __construct(IAuditLogger $logger) { |
|
38 | - $this->logger = $logger; |
|
39 | - } |
|
37 | + public function __construct(IAuditLogger $logger) { |
|
38 | + $this->logger = $logger; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Log a single action with a log level of info |
|
43 | - * |
|
44 | - * @param string $text |
|
45 | - * @param array $params |
|
46 | - * @param array $elements |
|
47 | - * @param bool $obfuscateParameters |
|
48 | - */ |
|
49 | - public function log(string $text, |
|
50 | - array $params, |
|
51 | - array $elements, |
|
52 | - bool $obfuscateParameters = false): void { |
|
53 | - foreach ($elements as $element) { |
|
54 | - if (!isset($params[$element])) { |
|
55 | - if ($obfuscateParameters) { |
|
56 | - $this->logger->critical( |
|
57 | - '$params["'.$element.'"] was missing.', |
|
58 | - ['app' => 'admin_audit'] |
|
59 | - ); |
|
60 | - } else { |
|
61 | - $this->logger->critical( |
|
62 | - sprintf( |
|
63 | - '$params["'.$element.'"] was missing. Transferred value: %s', |
|
64 | - print_r($params, true) |
|
65 | - ), |
|
66 | - ['app' => 'admin_audit'] |
|
67 | - ); |
|
68 | - } |
|
69 | - return; |
|
70 | - } |
|
71 | - } |
|
41 | + /** |
|
42 | + * Log a single action with a log level of info |
|
43 | + * |
|
44 | + * @param string $text |
|
45 | + * @param array $params |
|
46 | + * @param array $elements |
|
47 | + * @param bool $obfuscateParameters |
|
48 | + */ |
|
49 | + public function log(string $text, |
|
50 | + array $params, |
|
51 | + array $elements, |
|
52 | + bool $obfuscateParameters = false): void { |
|
53 | + foreach ($elements as $element) { |
|
54 | + if (!isset($params[$element])) { |
|
55 | + if ($obfuscateParameters) { |
|
56 | + $this->logger->critical( |
|
57 | + '$params["'.$element.'"] was missing.', |
|
58 | + ['app' => 'admin_audit'] |
|
59 | + ); |
|
60 | + } else { |
|
61 | + $this->logger->critical( |
|
62 | + sprintf( |
|
63 | + '$params["'.$element.'"] was missing. Transferred value: %s', |
|
64 | + print_r($params, true) |
|
65 | + ), |
|
66 | + ['app' => 'admin_audit'] |
|
67 | + ); |
|
68 | + } |
|
69 | + return; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - $replaceArray = []; |
|
74 | - foreach ($elements as $element) { |
|
75 | - if ($params[$element] instanceof \DateTime) { |
|
76 | - $params[$element] = $params[$element]->format('Y-m-d H:i:s'); |
|
77 | - } |
|
78 | - $replaceArray[] = $params[$element]; |
|
79 | - } |
|
73 | + $replaceArray = []; |
|
74 | + foreach ($elements as $element) { |
|
75 | + if ($params[$element] instanceof \DateTime) { |
|
76 | + $params[$element] = $params[$element]->format('Y-m-d H:i:s'); |
|
77 | + } |
|
78 | + $replaceArray[] = $params[$element]; |
|
79 | + } |
|
80 | 80 | |
81 | - $this->logger->info( |
|
82 | - vsprintf( |
|
83 | - $text, |
|
84 | - $replaceArray |
|
85 | - ), |
|
86 | - [ |
|
87 | - 'app' => 'admin_audit' |
|
88 | - ] |
|
89 | - ); |
|
90 | - } |
|
81 | + $this->logger->info( |
|
82 | + vsprintf( |
|
83 | + $text, |
|
84 | + $replaceArray |
|
85 | + ), |
|
86 | + [ |
|
87 | + 'app' => 'admin_audit' |
|
88 | + ] |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -32,57 +32,57 @@ |
||
32 | 32 | */ |
33 | 33 | class AuditLogger implements IAuditLogger { |
34 | 34 | |
35 | - /** @var LoggerInterface */ |
|
36 | - private $parentLogger; |
|
37 | - |
|
38 | - public function __construct(ILogFactory $logFactory, IConfig $config) { |
|
39 | - $auditType = $config->getSystemValueString('log_type_audit', 'file'); |
|
40 | - $defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud'); |
|
41 | - $auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag); |
|
42 | - $logFile = $config->getSystemValueString('logfile_audit', ''); |
|
43 | - |
|
44 | - if ($auditType === 'file' && !$logFile) { |
|
45 | - $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
46 | - // Legacy way was appconfig, now it's paralleled with the normal log config |
|
47 | - $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
48 | - } |
|
49 | - |
|
50 | - $this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); |
|
51 | - } |
|
52 | - |
|
53 | - public function emergency($message, array $context = array()) { |
|
54 | - $this->parentLogger->emergency($message, $context); |
|
55 | - } |
|
56 | - |
|
57 | - public function alert($message, array $context = array()) { |
|
58 | - $this->parentLogger->alert($message, $context); |
|
59 | - } |
|
60 | - |
|
61 | - public function critical($message, array $context = array()) { |
|
62 | - $this->parentLogger->critical($message, $context); |
|
63 | - } |
|
64 | - |
|
65 | - public function error($message, array $context = array()) { |
|
66 | - $this->parentLogger->error($message, $context); |
|
67 | - } |
|
68 | - |
|
69 | - public function warning($message, array $context = array()) { |
|
70 | - $this->parentLogger->warning($message, $context); |
|
71 | - } |
|
72 | - |
|
73 | - public function notice($message, array $context = array()) { |
|
74 | - $this->parentLogger->notice($message, $context); |
|
75 | - } |
|
76 | - |
|
77 | - public function info($message, array $context = array()) { |
|
78 | - $this->parentLogger->info($message, $context); |
|
79 | - } |
|
80 | - |
|
81 | - public function debug($message, array $context = array()) { |
|
82 | - $this->parentLogger->debug($message, $context); |
|
83 | - } |
|
84 | - |
|
85 | - public function log($level, $message, array $context = array()) { |
|
86 | - $this->parentLogger->log($level, $message, $context); |
|
87 | - } |
|
35 | + /** @var LoggerInterface */ |
|
36 | + private $parentLogger; |
|
37 | + |
|
38 | + public function __construct(ILogFactory $logFactory, IConfig $config) { |
|
39 | + $auditType = $config->getSystemValueString('log_type_audit', 'file'); |
|
40 | + $defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud'); |
|
41 | + $auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag); |
|
42 | + $logFile = $config->getSystemValueString('logfile_audit', ''); |
|
43 | + |
|
44 | + if ($auditType === 'file' && !$logFile) { |
|
45 | + $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
46 | + // Legacy way was appconfig, now it's paralleled with the normal log config |
|
47 | + $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
48 | + } |
|
49 | + |
|
50 | + $this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); |
|
51 | + } |
|
52 | + |
|
53 | + public function emergency($message, array $context = array()) { |
|
54 | + $this->parentLogger->emergency($message, $context); |
|
55 | + } |
|
56 | + |
|
57 | + public function alert($message, array $context = array()) { |
|
58 | + $this->parentLogger->alert($message, $context); |
|
59 | + } |
|
60 | + |
|
61 | + public function critical($message, array $context = array()) { |
|
62 | + $this->parentLogger->critical($message, $context); |
|
63 | + } |
|
64 | + |
|
65 | + public function error($message, array $context = array()) { |
|
66 | + $this->parentLogger->error($message, $context); |
|
67 | + } |
|
68 | + |
|
69 | + public function warning($message, array $context = array()) { |
|
70 | + $this->parentLogger->warning($message, $context); |
|
71 | + } |
|
72 | + |
|
73 | + public function notice($message, array $context = array()) { |
|
74 | + $this->parentLogger->notice($message, $context); |
|
75 | + } |
|
76 | + |
|
77 | + public function info($message, array $context = array()) { |
|
78 | + $this->parentLogger->info($message, $context); |
|
79 | + } |
|
80 | + |
|
81 | + public function debug($message, array $context = array()) { |
|
82 | + $this->parentLogger->debug($message, $context); |
|
83 | + } |
|
84 | + |
|
85 | + public function log($level, $message, array $context = array()) { |
|
86 | + $this->parentLogger->log($level, $message, $context); |
|
87 | + } |
|
88 | 88 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | $logFile = $config->getSystemValueString('logfile_audit', ''); |
43 | 43 | |
44 | 44 | if ($auditType === 'file' && !$logFile) { |
45 | - $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
45 | + $default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/audit.log'; |
|
46 | 46 | // Legacy way was appconfig, now it's paralleled with the normal log config |
47 | 47 | $logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
48 | 48 | } |
@@ -6,21 +6,21 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | - 'OCA\\AdminAudit\\Actions\\Action' => $baseDir . '/../lib/Actions/Action.php', |
|
11 | - 'OCA\\AdminAudit\\Actions\\AppManagement' => $baseDir . '/../lib/Actions/AppManagement.php', |
|
12 | - 'OCA\\AdminAudit\\Actions\\Auth' => $baseDir . '/../lib/Actions/Auth.php', |
|
13 | - 'OCA\\AdminAudit\\Actions\\Console' => $baseDir . '/../lib/Actions/Console.php', |
|
14 | - 'OCA\\AdminAudit\\Actions\\Files' => $baseDir . '/../lib/Actions/Files.php', |
|
15 | - 'OCA\\AdminAudit\\Actions\\GroupManagement' => $baseDir . '/../lib/Actions/GroupManagement.php', |
|
16 | - 'OCA\\AdminAudit\\Actions\\Security' => $baseDir . '/../lib/Actions/Security.php', |
|
17 | - 'OCA\\AdminAudit\\Actions\\Sharing' => $baseDir . '/../lib/Actions/Sharing.php', |
|
18 | - 'OCA\\AdminAudit\\Actions\\Trashbin' => $baseDir . '/../lib/Actions/Trashbin.php', |
|
19 | - 'OCA\\AdminAudit\\Actions\\UserManagement' => $baseDir . '/../lib/Actions/UserManagement.php', |
|
20 | - 'OCA\\AdminAudit\\Actions\\Versions' => $baseDir . '/../lib/Actions/Versions.php', |
|
21 | - 'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
22 | - 'OCA\\AdminAudit\\AuditLogger' => $baseDir . '/../lib/AuditLogger.php', |
|
23 | - 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => $baseDir . '/../lib/BackgroundJobs/Rotate.php', |
|
24 | - 'OCA\\AdminAudit\\IAuditLogger' => $baseDir . '/../lib/IAuditLogger.php', |
|
25 | - 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => $baseDir . '/../lib/Listener/CriticalActionPerformedEventListener.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
10 | + 'OCA\\AdminAudit\\Actions\\Action' => $baseDir.'/../lib/Actions/Action.php', |
|
11 | + 'OCA\\AdminAudit\\Actions\\AppManagement' => $baseDir.'/../lib/Actions/AppManagement.php', |
|
12 | + 'OCA\\AdminAudit\\Actions\\Auth' => $baseDir.'/../lib/Actions/Auth.php', |
|
13 | + 'OCA\\AdminAudit\\Actions\\Console' => $baseDir.'/../lib/Actions/Console.php', |
|
14 | + 'OCA\\AdminAudit\\Actions\\Files' => $baseDir.'/../lib/Actions/Files.php', |
|
15 | + 'OCA\\AdminAudit\\Actions\\GroupManagement' => $baseDir.'/../lib/Actions/GroupManagement.php', |
|
16 | + 'OCA\\AdminAudit\\Actions\\Security' => $baseDir.'/../lib/Actions/Security.php', |
|
17 | + 'OCA\\AdminAudit\\Actions\\Sharing' => $baseDir.'/../lib/Actions/Sharing.php', |
|
18 | + 'OCA\\AdminAudit\\Actions\\Trashbin' => $baseDir.'/../lib/Actions/Trashbin.php', |
|
19 | + 'OCA\\AdminAudit\\Actions\\UserManagement' => $baseDir.'/../lib/Actions/UserManagement.php', |
|
20 | + 'OCA\\AdminAudit\\Actions\\Versions' => $baseDir.'/../lib/Actions/Versions.php', |
|
21 | + 'OCA\\AdminAudit\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
22 | + 'OCA\\AdminAudit\\AuditLogger' => $baseDir.'/../lib/AuditLogger.php', |
|
23 | + 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => $baseDir.'/../lib/BackgroundJobs/Rotate.php', |
|
24 | + 'OCA\\AdminAudit\\IAuditLogger' => $baseDir.'/../lib/IAuditLogger.php', |
|
25 | + 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => $baseDir.'/../lib/Listener/CriticalActionPerformedEventListener.php', |
|
26 | 26 | ); |
@@ -6,43 +6,43 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitAdminAudit |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\AdminAudit\\' => 15, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\AdminAudit\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
25 | - 'OCA\\AdminAudit\\Actions\\Action' => __DIR__ . '/..' . '/../lib/Actions/Action.php', |
|
26 | - 'OCA\\AdminAudit\\Actions\\AppManagement' => __DIR__ . '/..' . '/../lib/Actions/AppManagement.php', |
|
27 | - 'OCA\\AdminAudit\\Actions\\Auth' => __DIR__ . '/..' . '/../lib/Actions/Auth.php', |
|
28 | - 'OCA\\AdminAudit\\Actions\\Console' => __DIR__ . '/..' . '/../lib/Actions/Console.php', |
|
29 | - 'OCA\\AdminAudit\\Actions\\Files' => __DIR__ . '/..' . '/../lib/Actions/Files.php', |
|
30 | - 'OCA\\AdminAudit\\Actions\\GroupManagement' => __DIR__ . '/..' . '/../lib/Actions/GroupManagement.php', |
|
31 | - 'OCA\\AdminAudit\\Actions\\Security' => __DIR__ . '/..' . '/../lib/Actions/Security.php', |
|
32 | - 'OCA\\AdminAudit\\Actions\\Sharing' => __DIR__ . '/..' . '/../lib/Actions/Sharing.php', |
|
33 | - 'OCA\\AdminAudit\\Actions\\Trashbin' => __DIR__ . '/..' . '/../lib/Actions/Trashbin.php', |
|
34 | - 'OCA\\AdminAudit\\Actions\\UserManagement' => __DIR__ . '/..' . '/../lib/Actions/UserManagement.php', |
|
35 | - 'OCA\\AdminAudit\\Actions\\Versions' => __DIR__ . '/..' . '/../lib/Actions/Versions.php', |
|
36 | - 'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
37 | - 'OCA\\AdminAudit\\AuditLogger' => __DIR__ . '/..' . '/../lib/AuditLogger.php', |
|
38 | - 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => __DIR__ . '/..' . '/../lib/BackgroundJobs/Rotate.php', |
|
39 | - 'OCA\\AdminAudit\\IAuditLogger' => __DIR__ . '/..' . '/../lib/IAuditLogger.php', |
|
40 | - 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => __DIR__ . '/..' . '/../lib/Listener/CriticalActionPerformedEventListener.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
25 | + 'OCA\\AdminAudit\\Actions\\Action' => __DIR__.'/..'.'/../lib/Actions/Action.php', |
|
26 | + 'OCA\\AdminAudit\\Actions\\AppManagement' => __DIR__.'/..'.'/../lib/Actions/AppManagement.php', |
|
27 | + 'OCA\\AdminAudit\\Actions\\Auth' => __DIR__.'/..'.'/../lib/Actions/Auth.php', |
|
28 | + 'OCA\\AdminAudit\\Actions\\Console' => __DIR__.'/..'.'/../lib/Actions/Console.php', |
|
29 | + 'OCA\\AdminAudit\\Actions\\Files' => __DIR__.'/..'.'/../lib/Actions/Files.php', |
|
30 | + 'OCA\\AdminAudit\\Actions\\GroupManagement' => __DIR__.'/..'.'/../lib/Actions/GroupManagement.php', |
|
31 | + 'OCA\\AdminAudit\\Actions\\Security' => __DIR__.'/..'.'/../lib/Actions/Security.php', |
|
32 | + 'OCA\\AdminAudit\\Actions\\Sharing' => __DIR__.'/..'.'/../lib/Actions/Sharing.php', |
|
33 | + 'OCA\\AdminAudit\\Actions\\Trashbin' => __DIR__.'/..'.'/../lib/Actions/Trashbin.php', |
|
34 | + 'OCA\\AdminAudit\\Actions\\UserManagement' => __DIR__.'/..'.'/../lib/Actions/UserManagement.php', |
|
35 | + 'OCA\\AdminAudit\\Actions\\Versions' => __DIR__.'/..'.'/../lib/Actions/Versions.php', |
|
36 | + 'OCA\\AdminAudit\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
37 | + 'OCA\\AdminAudit\\AuditLogger' => __DIR__.'/..'.'/../lib/AuditLogger.php', |
|
38 | + 'OCA\\AdminAudit\\BackgroundJobs\\Rotate' => __DIR__.'/..'.'/../lib/BackgroundJobs/Rotate.php', |
|
39 | + 'OCA\\AdminAudit\\IAuditLogger' => __DIR__.'/..'.'/../lib/IAuditLogger.php', |
|
40 | + 'OCA\\AdminAudit\\Listener\\CriticalActionPerformedEventListener' => __DIR__.'/..'.'/../lib/Listener/CriticalActionPerformedEventListener.php', |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | public static function getInitializer(ClassLoader $loader) |
44 | 44 | { |
45 | - return \Closure::bind(function () use ($loader) { |
|
45 | + return \Closure::bind(function() use ($loader) { |
|
46 | 46 | $loader->prefixLengthsPsr4 = ComposerStaticInitAdminAudit::$prefixLengthsPsr4; |
47 | 47 | $loader->prefixDirsPsr4 = ComposerStaticInitAdminAudit::$prefixDirsPsr4; |
48 | 48 | $loader->classMap = ComposerStaticInitAdminAudit::$classMap; |