Completed
Push — master ( 86d33c...02b092 )
by Blizzz
46:16 queued 28:50
created
lib/private/AppFramework/DependencyInjection/DIContainer.php 2 patches
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -67,408 +67,408 @@
 block discarded – undo
67 67
 
68 68
 class DIContainer extends SimpleContainer implements IAppContainer {
69 69
 
70
-	/**
71
-	 * @var array
72
-	 */
73
-	private $middleWares = array();
74
-
75
-	/** @var ServerContainer */
76
-	private $server;
77
-
78
-	/**
79
-	 * Put your class dependencies in here
80
-	 * @param string $appName the name of the app
81
-	 * @param array $urlParams
82
-	 * @param ServerContainer|null $server
83
-	 */
84
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
85
-		parent::__construct();
86
-		$this['AppName'] = $appName;
87
-		$this['urlParams'] = $urlParams;
88
-
89
-		/** @var \OC\ServerContainer $server */
90
-		if ($server === null) {
91
-			$server = \OC::$server;
92
-		}
93
-		$this->server = $server;
94
-		$this->server->registerAppContainer($appName, $this);
95
-
96
-		// aliases
97
-		$this->registerAlias('appName', 'AppName');
98
-		$this->registerAlias('webRoot', 'WebRoot');
99
-		$this->registerAlias('userId', 'UserId');
100
-
101
-		/**
102
-		 * Core services
103
-		 */
104
-		$this->registerService(IOutput::class, function($c){
105
-			return new Output($this->getServer()->getWebRoot());
106
-		});
107
-
108
-		$this->registerService(Folder::class, function() {
109
-			return $this->getServer()->getUserFolder();
110
-		});
111
-
112
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
113
-			return $this->getServer()->getAppDataDir($c->query('AppName'));
114
-		});
115
-
116
-		$this->registerService(IL10N::class, function($c) {
117
-			return $this->getServer()->getL10N($c->query('AppName'));
118
-		});
119
-
120
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
121
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
122
-
123
-		$this->registerService(IRequest::class, function() {
124
-			return $this->getServer()->query(IRequest::class);
125
-		});
126
-		$this->registerAlias('Request', IRequest::class);
127
-
128
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
129
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
130
-
131
-		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
132
-
133
-		$this->registerService(IServerContainer::class, function ($c) {
134
-			return $this->getServer();
135
-		});
136
-		$this->registerAlias('ServerContainer', IServerContainer::class);
137
-
138
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
139
-			return $c->query('OCA\WorkflowEngine\Manager');
140
-		});
141
-
142
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
143
-			return $c;
144
-		});
145
-
146
-		// commonly used attributes
147
-		$this->registerService('UserId', function ($c) {
148
-			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
149
-		});
150
-
151
-		$this->registerService('WebRoot', function ($c) {
152
-			return $c->query('ServerContainer')->getWebRoot();
153
-		});
154
-
155
-		$this->registerService('fromMailAddress', function() {
156
-			return Util::getDefaultEmailAddress('no-reply');
157
-		});
158
-
159
-		$this->registerService('OC_Defaults', function ($c) {
160
-			return $c->getServer()->getThemingDefaults();
161
-		});
162
-
163
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
164
-			return $this->getServer()->getEncryptionManager();
165
-		});
166
-
167
-		$this->registerService(IConfig::class, function ($c) {
168
-			return $c->query(OC\GlobalScale\Config::class);
169
-		});
170
-
171
-		$this->registerService(IValidator::class, function($c) {
172
-			return $c->query(Validator::class);
173
-		});
174
-
175
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
176
-			return new \OC\Security\IdentityProof\Manager(
177
-				$this->getServer()->query(\OC\Files\AppData\Factory::class),
178
-				$this->getServer()->getCrypto(),
179
-				$this->getServer()->getConfig()
180
-			);
181
-		});
182
-
183
-		/**
184
-		 * App Framework APIs
185
-		 */
186
-		$this->registerService('API', function($c){
187
-			$c->query('OCP\\ILogger')->debug(
188
-				'Accessing the API class is deprecated! Use the appropriate ' .
189
-				'services instead!'
190
-			);
191
-			return new API($c['AppName']);
192
-		});
193
-
194
-		$this->registerService('Protocol', function($c){
195
-			/** @var \OC\Server $server */
196
-			$server = $c->query('ServerContainer');
197
-			$protocol = $server->getRequest()->getHttpProtocol();
198
-			return new Http($_SERVER, $protocol);
199
-		});
200
-
201
-		$this->registerService('Dispatcher', function($c) {
202
-			return new Dispatcher(
203
-				$c['Protocol'],
204
-				$c['MiddlewareDispatcher'],
205
-				$c['ControllerMethodReflector'],
206
-				$c['Request']
207
-			);
208
-		});
209
-
210
-		/**
211
-		 * App Framework default arguments
212
-		 */
213
-		$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
214
-		$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
215
-		$this->registerParameter('corsMaxAge', 1728000);
216
-
217
-		/**
218
-		 * Middleware
219
-		 */
220
-		$app = $this;
221
-		$this->registerService('SecurityMiddleware', function($c) use ($app){
222
-			/** @var \OC\Server $server */
223
-			$server = $app->getServer();
224
-
225
-			return new SecurityMiddleware(
226
-				$c['Request'],
227
-				$c['ControllerMethodReflector'],
228
-				$server->getNavigationManager(),
229
-				$server->getURLGenerator(),
230
-				$server->getLogger(),
231
-				$c['AppName'],
232
-				$app->isLoggedIn(),
233
-				$app->isAdminUser(),
234
-				$server->getContentSecurityPolicyManager(),
235
-				$server->getCsrfTokenManager(),
236
-				$server->getContentSecurityPolicyNonceManager(),
237
-				$server->getAppManager()
238
-			);
239
-		});
240
-
241
-		$this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) {
242
-			/** @var \OC\Server $server */
243
-			$server = $app->getServer();
244
-
245
-			return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
246
-				$c['ControllerMethodReflector'],
247
-				$server->getSession(),
248
-				$server->getUserSession(),
249
-				$server->query(ITimeFactory::class)
250
-			);
251
-		});
252
-
253
-		$this->registerService('BruteForceMiddleware', function($c) use ($app) {
254
-			/** @var \OC\Server $server */
255
-			$server = $app->getServer();
256
-
257
-			return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
258
-				$c['ControllerMethodReflector'],
259
-				$server->getBruteForceThrottler(),
260
-				$server->getRequest()
261
-			);
262
-		});
263
-
264
-		$this->registerService('RateLimitingMiddleware', function($c) use ($app) {
265
-			/** @var \OC\Server $server */
266
-			$server = $app->getServer();
267
-
268
-			return new RateLimitingMiddleware(
269
-				$server->getRequest(),
270
-				$server->getUserSession(),
271
-				$c['ControllerMethodReflector'],
272
-				$c->query(OC\Security\RateLimiting\Limiter::class)
273
-			);
274
-		});
275
-
276
-		$this->registerService('CORSMiddleware', function($c) {
277
-			return new CORSMiddleware(
278
-				$c['Request'],
279
-				$c['ControllerMethodReflector'],
280
-				$c->query(IUserSession::class),
281
-				$c->getServer()->getBruteForceThrottler()
282
-			);
283
-		});
284
-
285
-		$this->registerService('SessionMiddleware', function($c) use ($app) {
286
-			return new SessionMiddleware(
287
-				$c['Request'],
288
-				$c['ControllerMethodReflector'],
289
-				$app->getServer()->getSession()
290
-			);
291
-		});
292
-
293
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
294
-			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
295
-			$userSession = $app->getServer()->getUserSession();
296
-			$session = $app->getServer()->getSession();
297
-			$urlGenerator = $app->getServer()->getURLGenerator();
298
-			$reflector = $c['ControllerMethodReflector'];
299
-			$request = $app->getServer()->getRequest();
300
-			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
301
-		});
302
-
303
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
304
-			return new OCSMiddleware(
305
-				$c['Request']
306
-			);
307
-		});
308
-
309
-		$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
310
-			return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
311
-				$c['Request'],
312
-				$c['ControllerMethodReflector']
313
-			);
314
-		});
315
-
316
-		$middleWares = &$this->middleWares;
317
-		$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
318
-			$dispatcher = new MiddlewareDispatcher();
319
-			$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
320
-			$dispatcher->registerMiddleware($c['CORSMiddleware']);
321
-			$dispatcher->registerMiddleware($c['OCSMiddleware']);
322
-			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
323
-			$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class]);
324
-			$dispatcher->registerMiddleware($c['TwoFactorMiddleware']);
325
-			$dispatcher->registerMiddleware($c['BruteForceMiddleware']);
326
-			$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
327
-
328
-			foreach($middleWares as $middleWare) {
329
-				$dispatcher->registerMiddleware($c[$middleWare]);
330
-			}
331
-
332
-			$dispatcher->registerMiddleware($c['SessionMiddleware']);
333
-			return $dispatcher;
334
-		});
335
-
336
-	}
337
-
338
-
339
-	/**
340
-	 * @deprecated implements only deprecated methods
341
-	 * @return IApi
342
-	 */
343
-	public function getCoreApi()
344
-	{
345
-		return $this->query('API');
346
-	}
347
-
348
-	/**
349
-	 * @return \OCP\IServerContainer
350
-	 */
351
-	public function getServer()
352
-	{
353
-		return $this->server;
354
-	}
355
-
356
-	/**
357
-	 * @param string $middleWare
358
-	 * @return boolean|null
359
-	 */
360
-	public function registerMiddleWare($middleWare) {
361
-		array_push($this->middleWares, $middleWare);
362
-	}
363
-
364
-	/**
365
-	 * used to return the appname of the set application
366
-	 * @return string the name of your application
367
-	 */
368
-	public function getAppName() {
369
-		return $this->query('AppName');
370
-	}
371
-
372
-	/**
373
-	 * @deprecated use IUserSession->isLoggedIn()
374
-	 * @return boolean
375
-	 */
376
-	public function isLoggedIn() {
377
-		return \OC::$server->getUserSession()->isLoggedIn();
378
-	}
379
-
380
-	/**
381
-	 * @deprecated use IGroupManager->isAdmin($userId)
382
-	 * @return boolean
383
-	 */
384
-	public function isAdminUser() {
385
-		$uid = $this->getUserId();
386
-		return \OC_User::isAdminUser($uid);
387
-	}
388
-
389
-	private function getUserId() {
390
-		return $this->getServer()->getSession()->get('user_id');
391
-	}
392
-
393
-	/**
394
-	 * @deprecated use the ILogger instead
395
-	 * @param string $message
396
-	 * @param string $level
397
-	 * @return mixed
398
-	 */
399
-	public function log($message, $level) {
400
-		switch($level){
401
-			case 'debug':
402
-				$level = \OCP\Util::DEBUG;
403
-				break;
404
-			case 'info':
405
-				$level = \OCP\Util::INFO;
406
-				break;
407
-			case 'warn':
408
-				$level = \OCP\Util::WARN;
409
-				break;
410
-			case 'fatal':
411
-				$level = \OCP\Util::FATAL;
412
-				break;
413
-			default:
414
-				$level = \OCP\Util::ERROR;
415
-				break;
416
-		}
417
-		\OCP\Util::writeLog($this->getAppName(), $message, $level);
418
-	}
419
-
420
-	/**
421
-	 * Register a capability
422
-	 *
423
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
424
-	 */
425
-	public function registerCapability($serviceName) {
426
-		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
427
-			return $this->query($serviceName);
428
-		});
429
-	}
430
-
431
-	/**
432
-	 * @param string $name
433
-	 * @return mixed
434
-	 * @throws QueryException if the query could not be resolved
435
-	 */
436
-	public function query($name) {
437
-		try {
438
-			return $this->queryNoFallback($name);
439
-		} catch (QueryException $firstException) {
440
-			try {
441
-				return $this->getServer()->query($name);
442
-			} catch (QueryException $secondException) {
443
-				if ($firstException->getCode() === 1) {
444
-					throw $secondException;
445
-				}
446
-				throw $firstException;
447
-			}
448
-		}
449
-	}
450
-
451
-	/**
452
-	 * @param string $name
453
-	 * @return mixed
454
-	 * @throws QueryException if the query could not be resolved
455
-	 */
456
-	public function queryNoFallback($name) {
457
-		$name = $this->sanitizeName($name);
458
-
459
-		if ($this->offsetExists($name)) {
460
-			return parent::query($name);
461
-		} else {
462
-			if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
463
-				return parent::query($name);
464
-			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
465
-				return parent::query($name);
466
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
467
-				return parent::query($name);
468
-			}
469
-		}
470
-
471
-		throw new QueryException('Could not resolve ' . $name . '!' .
472
-			' Class can not be instantiated', 1);
473
-	}
70
+    /**
71
+     * @var array
72
+     */
73
+    private $middleWares = array();
74
+
75
+    /** @var ServerContainer */
76
+    private $server;
77
+
78
+    /**
79
+     * Put your class dependencies in here
80
+     * @param string $appName the name of the app
81
+     * @param array $urlParams
82
+     * @param ServerContainer|null $server
83
+     */
84
+    public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
85
+        parent::__construct();
86
+        $this['AppName'] = $appName;
87
+        $this['urlParams'] = $urlParams;
88
+
89
+        /** @var \OC\ServerContainer $server */
90
+        if ($server === null) {
91
+            $server = \OC::$server;
92
+        }
93
+        $this->server = $server;
94
+        $this->server->registerAppContainer($appName, $this);
95
+
96
+        // aliases
97
+        $this->registerAlias('appName', 'AppName');
98
+        $this->registerAlias('webRoot', 'WebRoot');
99
+        $this->registerAlias('userId', 'UserId');
100
+
101
+        /**
102
+         * Core services
103
+         */
104
+        $this->registerService(IOutput::class, function($c){
105
+            return new Output($this->getServer()->getWebRoot());
106
+        });
107
+
108
+        $this->registerService(Folder::class, function() {
109
+            return $this->getServer()->getUserFolder();
110
+        });
111
+
112
+        $this->registerService(IAppData::class, function (SimpleContainer $c) {
113
+            return $this->getServer()->getAppDataDir($c->query('AppName'));
114
+        });
115
+
116
+        $this->registerService(IL10N::class, function($c) {
117
+            return $this->getServer()->getL10N($c->query('AppName'));
118
+        });
119
+
120
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
121
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
122
+
123
+        $this->registerService(IRequest::class, function() {
124
+            return $this->getServer()->query(IRequest::class);
125
+        });
126
+        $this->registerAlias('Request', IRequest::class);
127
+
128
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
129
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
130
+
131
+        $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
132
+
133
+        $this->registerService(IServerContainer::class, function ($c) {
134
+            return $this->getServer();
135
+        });
136
+        $this->registerAlias('ServerContainer', IServerContainer::class);
137
+
138
+        $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
139
+            return $c->query('OCA\WorkflowEngine\Manager');
140
+        });
141
+
142
+        $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
143
+            return $c;
144
+        });
145
+
146
+        // commonly used attributes
147
+        $this->registerService('UserId', function ($c) {
148
+            return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
149
+        });
150
+
151
+        $this->registerService('WebRoot', function ($c) {
152
+            return $c->query('ServerContainer')->getWebRoot();
153
+        });
154
+
155
+        $this->registerService('fromMailAddress', function() {
156
+            return Util::getDefaultEmailAddress('no-reply');
157
+        });
158
+
159
+        $this->registerService('OC_Defaults', function ($c) {
160
+            return $c->getServer()->getThemingDefaults();
161
+        });
162
+
163
+        $this->registerService('OCP\Encryption\IManager', function ($c) {
164
+            return $this->getServer()->getEncryptionManager();
165
+        });
166
+
167
+        $this->registerService(IConfig::class, function ($c) {
168
+            return $c->query(OC\GlobalScale\Config::class);
169
+        });
170
+
171
+        $this->registerService(IValidator::class, function($c) {
172
+            return $c->query(Validator::class);
173
+        });
174
+
175
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
176
+            return new \OC\Security\IdentityProof\Manager(
177
+                $this->getServer()->query(\OC\Files\AppData\Factory::class),
178
+                $this->getServer()->getCrypto(),
179
+                $this->getServer()->getConfig()
180
+            );
181
+        });
182
+
183
+        /**
184
+         * App Framework APIs
185
+         */
186
+        $this->registerService('API', function($c){
187
+            $c->query('OCP\\ILogger')->debug(
188
+                'Accessing the API class is deprecated! Use the appropriate ' .
189
+                'services instead!'
190
+            );
191
+            return new API($c['AppName']);
192
+        });
193
+
194
+        $this->registerService('Protocol', function($c){
195
+            /** @var \OC\Server $server */
196
+            $server = $c->query('ServerContainer');
197
+            $protocol = $server->getRequest()->getHttpProtocol();
198
+            return new Http($_SERVER, $protocol);
199
+        });
200
+
201
+        $this->registerService('Dispatcher', function($c) {
202
+            return new Dispatcher(
203
+                $c['Protocol'],
204
+                $c['MiddlewareDispatcher'],
205
+                $c['ControllerMethodReflector'],
206
+                $c['Request']
207
+            );
208
+        });
209
+
210
+        /**
211
+         * App Framework default arguments
212
+         */
213
+        $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
214
+        $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
215
+        $this->registerParameter('corsMaxAge', 1728000);
216
+
217
+        /**
218
+         * Middleware
219
+         */
220
+        $app = $this;
221
+        $this->registerService('SecurityMiddleware', function($c) use ($app){
222
+            /** @var \OC\Server $server */
223
+            $server = $app->getServer();
224
+
225
+            return new SecurityMiddleware(
226
+                $c['Request'],
227
+                $c['ControllerMethodReflector'],
228
+                $server->getNavigationManager(),
229
+                $server->getURLGenerator(),
230
+                $server->getLogger(),
231
+                $c['AppName'],
232
+                $app->isLoggedIn(),
233
+                $app->isAdminUser(),
234
+                $server->getContentSecurityPolicyManager(),
235
+                $server->getCsrfTokenManager(),
236
+                $server->getContentSecurityPolicyNonceManager(),
237
+                $server->getAppManager()
238
+            );
239
+        });
240
+
241
+        $this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) {
242
+            /** @var \OC\Server $server */
243
+            $server = $app->getServer();
244
+
245
+            return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
246
+                $c['ControllerMethodReflector'],
247
+                $server->getSession(),
248
+                $server->getUserSession(),
249
+                $server->query(ITimeFactory::class)
250
+            );
251
+        });
252
+
253
+        $this->registerService('BruteForceMiddleware', function($c) use ($app) {
254
+            /** @var \OC\Server $server */
255
+            $server = $app->getServer();
256
+
257
+            return new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
258
+                $c['ControllerMethodReflector'],
259
+                $server->getBruteForceThrottler(),
260
+                $server->getRequest()
261
+            );
262
+        });
263
+
264
+        $this->registerService('RateLimitingMiddleware', function($c) use ($app) {
265
+            /** @var \OC\Server $server */
266
+            $server = $app->getServer();
267
+
268
+            return new RateLimitingMiddleware(
269
+                $server->getRequest(),
270
+                $server->getUserSession(),
271
+                $c['ControllerMethodReflector'],
272
+                $c->query(OC\Security\RateLimiting\Limiter::class)
273
+            );
274
+        });
275
+
276
+        $this->registerService('CORSMiddleware', function($c) {
277
+            return new CORSMiddleware(
278
+                $c['Request'],
279
+                $c['ControllerMethodReflector'],
280
+                $c->query(IUserSession::class),
281
+                $c->getServer()->getBruteForceThrottler()
282
+            );
283
+        });
284
+
285
+        $this->registerService('SessionMiddleware', function($c) use ($app) {
286
+            return new SessionMiddleware(
287
+                $c['Request'],
288
+                $c['ControllerMethodReflector'],
289
+                $app->getServer()->getSession()
290
+            );
291
+        });
292
+
293
+        $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
294
+            $twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
295
+            $userSession = $app->getServer()->getUserSession();
296
+            $session = $app->getServer()->getSession();
297
+            $urlGenerator = $app->getServer()->getURLGenerator();
298
+            $reflector = $c['ControllerMethodReflector'];
299
+            $request = $app->getServer()->getRequest();
300
+            return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
301
+        });
302
+
303
+        $this->registerService('OCSMiddleware', function (SimpleContainer $c) {
304
+            return new OCSMiddleware(
305
+                $c['Request']
306
+            );
307
+        });
308
+
309
+        $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
310
+            return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
311
+                $c['Request'],
312
+                $c['ControllerMethodReflector']
313
+            );
314
+        });
315
+
316
+        $middleWares = &$this->middleWares;
317
+        $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
318
+            $dispatcher = new MiddlewareDispatcher();
319
+            $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
320
+            $dispatcher->registerMiddleware($c['CORSMiddleware']);
321
+            $dispatcher->registerMiddleware($c['OCSMiddleware']);
322
+            $dispatcher->registerMiddleware($c['SecurityMiddleware']);
323
+            $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class]);
324
+            $dispatcher->registerMiddleware($c['TwoFactorMiddleware']);
325
+            $dispatcher->registerMiddleware($c['BruteForceMiddleware']);
326
+            $dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
327
+
328
+            foreach($middleWares as $middleWare) {
329
+                $dispatcher->registerMiddleware($c[$middleWare]);
330
+            }
331
+
332
+            $dispatcher->registerMiddleware($c['SessionMiddleware']);
333
+            return $dispatcher;
334
+        });
335
+
336
+    }
337
+
338
+
339
+    /**
340
+     * @deprecated implements only deprecated methods
341
+     * @return IApi
342
+     */
343
+    public function getCoreApi()
344
+    {
345
+        return $this->query('API');
346
+    }
347
+
348
+    /**
349
+     * @return \OCP\IServerContainer
350
+     */
351
+    public function getServer()
352
+    {
353
+        return $this->server;
354
+    }
355
+
356
+    /**
357
+     * @param string $middleWare
358
+     * @return boolean|null
359
+     */
360
+    public function registerMiddleWare($middleWare) {
361
+        array_push($this->middleWares, $middleWare);
362
+    }
363
+
364
+    /**
365
+     * used to return the appname of the set application
366
+     * @return string the name of your application
367
+     */
368
+    public function getAppName() {
369
+        return $this->query('AppName');
370
+    }
371
+
372
+    /**
373
+     * @deprecated use IUserSession->isLoggedIn()
374
+     * @return boolean
375
+     */
376
+    public function isLoggedIn() {
377
+        return \OC::$server->getUserSession()->isLoggedIn();
378
+    }
379
+
380
+    /**
381
+     * @deprecated use IGroupManager->isAdmin($userId)
382
+     * @return boolean
383
+     */
384
+    public function isAdminUser() {
385
+        $uid = $this->getUserId();
386
+        return \OC_User::isAdminUser($uid);
387
+    }
388
+
389
+    private function getUserId() {
390
+        return $this->getServer()->getSession()->get('user_id');
391
+    }
392
+
393
+    /**
394
+     * @deprecated use the ILogger instead
395
+     * @param string $message
396
+     * @param string $level
397
+     * @return mixed
398
+     */
399
+    public function log($message, $level) {
400
+        switch($level){
401
+            case 'debug':
402
+                $level = \OCP\Util::DEBUG;
403
+                break;
404
+            case 'info':
405
+                $level = \OCP\Util::INFO;
406
+                break;
407
+            case 'warn':
408
+                $level = \OCP\Util::WARN;
409
+                break;
410
+            case 'fatal':
411
+                $level = \OCP\Util::FATAL;
412
+                break;
413
+            default:
414
+                $level = \OCP\Util::ERROR;
415
+                break;
416
+        }
417
+        \OCP\Util::writeLog($this->getAppName(), $message, $level);
418
+    }
419
+
420
+    /**
421
+     * Register a capability
422
+     *
423
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
424
+     */
425
+    public function registerCapability($serviceName) {
426
+        $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
427
+            return $this->query($serviceName);
428
+        });
429
+    }
430
+
431
+    /**
432
+     * @param string $name
433
+     * @return mixed
434
+     * @throws QueryException if the query could not be resolved
435
+     */
436
+    public function query($name) {
437
+        try {
438
+            return $this->queryNoFallback($name);
439
+        } catch (QueryException $firstException) {
440
+            try {
441
+                return $this->getServer()->query($name);
442
+            } catch (QueryException $secondException) {
443
+                if ($firstException->getCode() === 1) {
444
+                    throw $secondException;
445
+                }
446
+                throw $firstException;
447
+            }
448
+        }
449
+    }
450
+
451
+    /**
452
+     * @param string $name
453
+     * @return mixed
454
+     * @throws QueryException if the query could not be resolved
455
+     */
456
+    public function queryNoFallback($name) {
457
+        $name = $this->sanitizeName($name);
458
+
459
+        if ($this->offsetExists($name)) {
460
+            return parent::query($name);
461
+        } else {
462
+            if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
463
+                return parent::query($name);
464
+            } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
465
+                return parent::query($name);
466
+            } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
467
+                return parent::query($name);
468
+            }
469
+        }
470
+
471
+        throw new QueryException('Could not resolve ' . $name . '!' .
472
+            ' Class can not be instantiated', 1);
473
+    }
474 474
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @param array $urlParams
82 82
 	 * @param ServerContainer|null $server
83 83
 	 */
84
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
84
+	public function __construct($appName, $urlParams = array(), ServerContainer $server = null) {
85 85
 		parent::__construct();
86 86
 		$this['AppName'] = $appName;
87 87
 		$this['urlParams'] = $urlParams;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		/**
102 102
 		 * Core services
103 103
 		 */
104
-		$this->registerService(IOutput::class, function($c){
104
+		$this->registerService(IOutput::class, function($c) {
105 105
 			return new Output($this->getServer()->getWebRoot());
106 106
 		});
107 107
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			return $this->getServer()->getUserFolder();
110 110
 		});
111 111
 
112
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
112
+		$this->registerService(IAppData::class, function(SimpleContainer $c) {
113 113
 			return $this->getServer()->getAppDataDir($c->query('AppName'));
114 114
 		});
115 115
 
@@ -130,25 +130,25 @@  discard block
 block discarded – undo
130 130
 
131 131
 		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
132 132
 
133
-		$this->registerService(IServerContainer::class, function ($c) {
133
+		$this->registerService(IServerContainer::class, function($c) {
134 134
 			return $this->getServer();
135 135
 		});
136 136
 		$this->registerAlias('ServerContainer', IServerContainer::class);
137 137
 
138
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
138
+		$this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) {
139 139
 			return $c->query('OCA\WorkflowEngine\Manager');
140 140
 		});
141 141
 
142
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
142
+		$this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) {
143 143
 			return $c;
144 144
 		});
145 145
 
146 146
 		// commonly used attributes
147
-		$this->registerService('UserId', function ($c) {
147
+		$this->registerService('UserId', function($c) {
148 148
 			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
149 149
 		});
150 150
 
151
-		$this->registerService('WebRoot', function ($c) {
151
+		$this->registerService('WebRoot', function($c) {
152 152
 			return $c->query('ServerContainer')->getWebRoot();
153 153
 		});
154 154
 
@@ -156,15 +156,15 @@  discard block
 block discarded – undo
156 156
 			return Util::getDefaultEmailAddress('no-reply');
157 157
 		});
158 158
 
159
-		$this->registerService('OC_Defaults', function ($c) {
159
+		$this->registerService('OC_Defaults', function($c) {
160 160
 			return $c->getServer()->getThemingDefaults();
161 161
 		});
162 162
 
163
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
163
+		$this->registerService('OCP\Encryption\IManager', function($c) {
164 164
 			return $this->getServer()->getEncryptionManager();
165 165
 		});
166 166
 
167
-		$this->registerService(IConfig::class, function ($c) {
167
+		$this->registerService(IConfig::class, function($c) {
168 168
 			return $c->query(OC\GlobalScale\Config::class);
169 169
 		});
170 170
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			return $c->query(Validator::class);
173 173
 		});
174 174
 
175
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
175
+		$this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) {
176 176
 			return new \OC\Security\IdentityProof\Manager(
177 177
 				$this->getServer()->query(\OC\Files\AppData\Factory::class),
178 178
 				$this->getServer()->getCrypto(),
@@ -183,15 +183,15 @@  discard block
 block discarded – undo
183 183
 		/**
184 184
 		 * App Framework APIs
185 185
 		 */
186
-		$this->registerService('API', function($c){
186
+		$this->registerService('API', function($c) {
187 187
 			$c->query('OCP\\ILogger')->debug(
188
-				'Accessing the API class is deprecated! Use the appropriate ' .
188
+				'Accessing the API class is deprecated! Use the appropriate '.
189 189
 				'services instead!'
190 190
 			);
191 191
 			return new API($c['AppName']);
192 192
 		});
193 193
 
194
-		$this->registerService('Protocol', function($c){
194
+		$this->registerService('Protocol', function($c) {
195 195
 			/** @var \OC\Server $server */
196 196
 			$server = $c->query('ServerContainer');
197 197
 			$protocol = $server->getRequest()->getHttpProtocol();
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 			);
239 239
 		});
240 240
 
241
-		$this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) {
241
+		$this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function($c) use ($app) {
242 242
 			/** @var \OC\Server $server */
243 243
 			$server = $app->getServer();
244 244
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 			);
291 291
 		});
292 292
 
293
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
293
+		$this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) {
294 294
 			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
295 295
 			$userSession = $app->getServer()->getUserSession();
296 296
 			$session = $app->getServer()->getSession();
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
 			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
301 301
 		});
302 302
 
303
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
303
+		$this->registerService('OCSMiddleware', function(SimpleContainer $c) {
304 304
 			return new OCSMiddleware(
305 305
 				$c['Request']
306 306
 			);
307 307
 		});
308 308
 
309
-		$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) {
309
+		$this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function(SimpleContainer $c) {
310 310
 			return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
311 311
 				$c['Request'],
312 312
 				$c['ControllerMethodReflector']
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			$dispatcher->registerMiddleware($c['BruteForceMiddleware']);
326 326
 			$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
327 327
 
328
-			foreach($middleWares as $middleWare) {
328
+			foreach ($middleWares as $middleWare) {
329 329
 				$dispatcher->registerMiddleware($c[$middleWare]);
330 330
 			}
331 331
 
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 	 * @return mixed
398 398
 	 */
399 399
 	public function log($message, $level) {
400
-		switch($level){
400
+		switch ($level) {
401 401
 			case 'debug':
402 402
 				$level = \OCP\Util::DEBUG;
403 403
 				break;
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
 				return parent::query($name);
464 464
 			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
465 465
 				return parent::query($name);
466
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
466
+			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) {
467 467
 				return parent::query($name);
468 468
 			}
469 469
 		}
470 470
 
471
-		throw new QueryException('Could not resolve ' . $name . '!' .
471
+		throw new QueryException('Could not resolve '.$name.'!'.
472 472
 			' Class can not be instantiated', 1);
473 473
 	}
474 474
 }
Please login to merge, or discard this patch.
private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -31,51 +31,51 @@
 block discarded – undo
31 31
 use OCP\IUserSession;
32 32
 
33 33
 class PasswordConfirmationMiddleware extends Middleware {
34
-	/** @var ControllerMethodReflector */
35
-	private $reflector;
36
-	/** @var ISession */
37
-	private $session;
38
-	/** @var IUserSession */
39
-	private $userSession;
40
-	/** @var ITimeFactory */
41
-	private $timeFactory;
34
+    /** @var ControllerMethodReflector */
35
+    private $reflector;
36
+    /** @var ISession */
37
+    private $session;
38
+    /** @var IUserSession */
39
+    private $userSession;
40
+    /** @var ITimeFactory */
41
+    private $timeFactory;
42 42
 
43
-	/**
44
-	 * PasswordConfirmationMiddleware constructor.
45
-	 *
46
-	 * @param ControllerMethodReflector $reflector
47
-	 * @param ISession $session
48
-	 * @param IUserSession $userSession
49
-	 * @param ITimeFactory $timeFactory
50
-	 */
51
-	public function __construct(ControllerMethodReflector $reflector,
52
-								ISession $session,
53
-								IUserSession $userSession,
54
-								ITimeFactory $timeFactory) {
55
-		$this->reflector = $reflector;
56
-		$this->session = $session;
57
-		$this->userSession = $userSession;
58
-		$this->timeFactory = $timeFactory;
59
-	}
43
+    /**
44
+     * PasswordConfirmationMiddleware constructor.
45
+     *
46
+     * @param ControllerMethodReflector $reflector
47
+     * @param ISession $session
48
+     * @param IUserSession $userSession
49
+     * @param ITimeFactory $timeFactory
50
+     */
51
+    public function __construct(ControllerMethodReflector $reflector,
52
+                                ISession $session,
53
+                                IUserSession $userSession,
54
+                                ITimeFactory $timeFactory) {
55
+        $this->reflector = $reflector;
56
+        $this->session = $session;
57
+        $this->userSession = $userSession;
58
+        $this->timeFactory = $timeFactory;
59
+    }
60 60
 
61
-	/**
62
-	 * @param Controller $controller
63
-	 * @param string $methodName
64
-	 * @throws NotConfirmedException
65
-	 */
66
-	public function beforeController($controller, $methodName) {
67
-		if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
68
-			$user = $this->userSession->getUser();
69
-			$backendClassName = '';
70
-			if ($user !== null) {
71
-				$backendClassName = $user->getBackendClassName();
72
-			}
61
+    /**
62
+     * @param Controller $controller
63
+     * @param string $methodName
64
+     * @throws NotConfirmedException
65
+     */
66
+    public function beforeController($controller, $methodName) {
67
+        if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
68
+            $user = $this->userSession->getUser();
69
+            $backendClassName = '';
70
+            if ($user !== null) {
71
+                $backendClassName = $user->getBackendClassName();
72
+            }
73 73
 
74
-			$lastConfirm = (int) $this->session->get('last-password-confirm');
75
-			// we can't check the password against a SAML backend, so skip password confirmation in this case
76
-			if ($backendClassName !== 'user_saml' && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay
77
-				throw new NotConfirmedException();
78
-			}
79
-		}
80
-	}
74
+            $lastConfirm = (int) $this->session->get('last-password-confirm');
75
+            // we can't check the password against a SAML backend, so skip password confirmation in this case
76
+            if ($backendClassName !== 'user_saml' && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay
77
+                throw new NotConfirmedException();
78
+            }
79
+        }
80
+    }
81 81
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -63,200 +63,200 @@
 block discarded – undo
63 63
  * check fails
64 64
  */
65 65
 class SecurityMiddleware extends Middleware {
66
-	/** @var INavigationManager */
67
-	private $navigationManager;
68
-	/** @var IRequest */
69
-	private $request;
70
-	/** @var ControllerMethodReflector */
71
-	private $reflector;
72
-	/** @var string */
73
-	private $appName;
74
-	/** @var IURLGenerator */
75
-	private $urlGenerator;
76
-	/** @var ILogger */
77
-	private $logger;
78
-	/** @var bool */
79
-	private $isLoggedIn;
80
-	/** @var bool */
81
-	private $isAdminUser;
82
-	/** @var ContentSecurityPolicyManager */
83
-	private $contentSecurityPolicyManager;
84
-	/** @var CsrfTokenManager */
85
-	private $csrfTokenManager;
86
-	/** @var ContentSecurityPolicyNonceManager */
87
-	private $cspNonceManager;
88
-	/** @var IAppManager */
89
-	private $appManager;
66
+    /** @var INavigationManager */
67
+    private $navigationManager;
68
+    /** @var IRequest */
69
+    private $request;
70
+    /** @var ControllerMethodReflector */
71
+    private $reflector;
72
+    /** @var string */
73
+    private $appName;
74
+    /** @var IURLGenerator */
75
+    private $urlGenerator;
76
+    /** @var ILogger */
77
+    private $logger;
78
+    /** @var bool */
79
+    private $isLoggedIn;
80
+    /** @var bool */
81
+    private $isAdminUser;
82
+    /** @var ContentSecurityPolicyManager */
83
+    private $contentSecurityPolicyManager;
84
+    /** @var CsrfTokenManager */
85
+    private $csrfTokenManager;
86
+    /** @var ContentSecurityPolicyNonceManager */
87
+    private $cspNonceManager;
88
+    /** @var IAppManager */
89
+    private $appManager;
90 90
 
91
-	/**
92
-	 * @param IRequest $request
93
-	 * @param ControllerMethodReflector $reflector
94
-	 * @param INavigationManager $navigationManager
95
-	 * @param IURLGenerator $urlGenerator
96
-	 * @param ILogger $logger
97
-	 * @param string $appName
98
-	 * @param bool $isLoggedIn
99
-	 * @param bool $isAdminUser
100
-	 * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
101
-	 * @param CSRFTokenManager $csrfTokenManager
102
-	 * @param ContentSecurityPolicyNonceManager $cspNonceManager
103
-	 * @param IAppManager $appManager
104
-	 */
105
-	public function __construct(IRequest $request,
106
-								ControllerMethodReflector $reflector,
107
-								INavigationManager $navigationManager,
108
-								IURLGenerator $urlGenerator,
109
-								ILogger $logger,
110
-								$appName,
111
-								$isLoggedIn,
112
-								$isAdminUser,
113
-								ContentSecurityPolicyManager $contentSecurityPolicyManager,
114
-								CsrfTokenManager $csrfTokenManager,
115
-								ContentSecurityPolicyNonceManager $cspNonceManager,
116
-								IAppManager $appManager
117
-	) {
118
-		$this->navigationManager = $navigationManager;
119
-		$this->request = $request;
120
-		$this->reflector = $reflector;
121
-		$this->appName = $appName;
122
-		$this->urlGenerator = $urlGenerator;
123
-		$this->logger = $logger;
124
-		$this->isLoggedIn = $isLoggedIn;
125
-		$this->isAdminUser = $isAdminUser;
126
-		$this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
127
-		$this->csrfTokenManager = $csrfTokenManager;
128
-		$this->cspNonceManager = $cspNonceManager;
129
-		$this->appManager = $appManager;
130
-	}
91
+    /**
92
+     * @param IRequest $request
93
+     * @param ControllerMethodReflector $reflector
94
+     * @param INavigationManager $navigationManager
95
+     * @param IURLGenerator $urlGenerator
96
+     * @param ILogger $logger
97
+     * @param string $appName
98
+     * @param bool $isLoggedIn
99
+     * @param bool $isAdminUser
100
+     * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
101
+     * @param CSRFTokenManager $csrfTokenManager
102
+     * @param ContentSecurityPolicyNonceManager $cspNonceManager
103
+     * @param IAppManager $appManager
104
+     */
105
+    public function __construct(IRequest $request,
106
+                                ControllerMethodReflector $reflector,
107
+                                INavigationManager $navigationManager,
108
+                                IURLGenerator $urlGenerator,
109
+                                ILogger $logger,
110
+                                $appName,
111
+                                $isLoggedIn,
112
+                                $isAdminUser,
113
+                                ContentSecurityPolicyManager $contentSecurityPolicyManager,
114
+                                CsrfTokenManager $csrfTokenManager,
115
+                                ContentSecurityPolicyNonceManager $cspNonceManager,
116
+                                IAppManager $appManager
117
+    ) {
118
+        $this->navigationManager = $navigationManager;
119
+        $this->request = $request;
120
+        $this->reflector = $reflector;
121
+        $this->appName = $appName;
122
+        $this->urlGenerator = $urlGenerator;
123
+        $this->logger = $logger;
124
+        $this->isLoggedIn = $isLoggedIn;
125
+        $this->isAdminUser = $isAdminUser;
126
+        $this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
127
+        $this->csrfTokenManager = $csrfTokenManager;
128
+        $this->cspNonceManager = $cspNonceManager;
129
+        $this->appManager = $appManager;
130
+    }
131 131
 
132
-	/**
133
-	 * This runs all the security checks before a method call. The
134
-	 * security checks are determined by inspecting the controller method
135
-	 * annotations
136
-	 * @param Controller $controller the controller
137
-	 * @param string $methodName the name of the method
138
-	 * @throws SecurityException when a security check fails
139
-	 */
140
-	public function beforeController($controller, $methodName) {
132
+    /**
133
+     * This runs all the security checks before a method call. The
134
+     * security checks are determined by inspecting the controller method
135
+     * annotations
136
+     * @param Controller $controller the controller
137
+     * @param string $methodName the name of the method
138
+     * @throws SecurityException when a security check fails
139
+     */
140
+    public function beforeController($controller, $methodName) {
141 141
 
142
-		// this will set the current navigation entry of the app, use this only
143
-		// for normal HTML requests and not for AJAX requests
144
-		$this->navigationManager->setActiveEntry($this->appName);
142
+        // this will set the current navigation entry of the app, use this only
143
+        // for normal HTML requests and not for AJAX requests
144
+        $this->navigationManager->setActiveEntry($this->appName);
145 145
 
146
-		// security checks
147
-		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
148
-		if(!$isPublicPage) {
149
-			if(!$this->isLoggedIn) {
150
-				throw new NotLoggedInException();
151
-			}
146
+        // security checks
147
+        $isPublicPage = $this->reflector->hasAnnotation('PublicPage');
148
+        if(!$isPublicPage) {
149
+            if(!$this->isLoggedIn) {
150
+                throw new NotLoggedInException();
151
+            }
152 152
 
153
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
154
-				if(!$this->isAdminUser) {
155
-					throw new NotAdminException();
156
-				}
157
-			}
158
-		}
153
+            if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
154
+                if(!$this->isAdminUser) {
155
+                    throw new NotAdminException();
156
+                }
157
+            }
158
+        }
159 159
 
160
-		// Check for strict cookie requirement
161
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
162
-			if(!$this->request->passesStrictCookieCheck()) {
163
-				throw new StrictCookieMissingException();
164
-			}
165
-		}
166
-		// CSRF check - also registers the CSRF token since the session may be closed later
167
-		Util::callRegister();
168
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
169
-			/*
160
+        // Check for strict cookie requirement
161
+        if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
162
+            if(!$this->request->passesStrictCookieCheck()) {
163
+                throw new StrictCookieMissingException();
164
+            }
165
+        }
166
+        // CSRF check - also registers the CSRF token since the session may be closed later
167
+        Util::callRegister();
168
+        if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
169
+            /*
170 170
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
171 171
 			 * hacks around that we have no full token auth in place yet and we
172 172
 			 * do want to offer CSRF checks for web requests.
173 173
 			 */
174
-			if(!$this->request->passesCSRFCheck() && !(
175
-					$controller instanceof OCSController &&
176
-					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
177
-				throw new CrossSiteRequestForgeryException();
178
-			}
179
-		}
174
+            if(!$this->request->passesCSRFCheck() && !(
175
+                    $controller instanceof OCSController &&
176
+                    $this->request->getHeader('OCS-APIREQUEST') === 'true')) {
177
+                throw new CrossSiteRequestForgeryException();
178
+            }
179
+        }
180 180
 
181
-		/**
182
-		 * FIXME: Use DI once available
183
-		 * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
184
-		 * The getAppPath() check is here since components such as settings also use the AppFramework and
185
-		 * therefore won't pass this check.
186
-		 */
187
-		if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
188
-			throw new AppNotEnabledException();
189
-		}
181
+        /**
182
+         * FIXME: Use DI once available
183
+         * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
184
+         * The getAppPath() check is here since components such as settings also use the AppFramework and
185
+         * therefore won't pass this check.
186
+         */
187
+        if(\OC_App::getAppPath($this->appName) !== false && !$this->appManager->isEnabledForUser($this->appName)) {
188
+            throw new AppNotEnabledException();
189
+        }
190 190
 
191
-	}
191
+    }
192 192
 
193
-	/**
194
-	 * Performs the default CSP modifications that may be injected by other
195
-	 * applications
196
-	 *
197
-	 * @param Controller $controller
198
-	 * @param string $methodName
199
-	 * @param Response $response
200
-	 * @return Response
201
-	 */
202
-	public function afterController($controller, $methodName, Response $response) {
203
-		$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
193
+    /**
194
+     * Performs the default CSP modifications that may be injected by other
195
+     * applications
196
+     *
197
+     * @param Controller $controller
198
+     * @param string $methodName
199
+     * @param Response $response
200
+     * @return Response
201
+     */
202
+    public function afterController($controller, $methodName, Response $response) {
203
+        $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
204 204
 
205
-		if (get_class($policy) === EmptyContentSecurityPolicy::class) {
206
-			return $response;
207
-		}
205
+        if (get_class($policy) === EmptyContentSecurityPolicy::class) {
206
+            return $response;
207
+        }
208 208
 
209
-		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
210
-		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
209
+        $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
210
+        $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
211 211
 
212
-		if($this->cspNonceManager->browserSupportsCspV3()) {
213
-			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
214
-		}
212
+        if($this->cspNonceManager->browserSupportsCspV3()) {
213
+            $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
214
+        }
215 215
 
216
-		$response->setContentSecurityPolicy($defaultPolicy);
216
+        $response->setContentSecurityPolicy($defaultPolicy);
217 217
 
218
-		return $response;
219
-	}
218
+        return $response;
219
+    }
220 220
 
221
-	/**
222
-	 * If an SecurityException is being caught, ajax requests return a JSON error
223
-	 * response and non ajax requests redirect to the index
224
-	 * @param Controller $controller the controller that is being called
225
-	 * @param string $methodName the name of the method that will be called on
226
-	 *                           the controller
227
-	 * @param \Exception $exception the thrown exception
228
-	 * @throws \Exception the passed in exception if it can't handle it
229
-	 * @return Response a Response object or null in case that the exception could not be handled
230
-	 */
231
-	public function afterException($controller, $methodName, \Exception $exception) {
232
-		if($exception instanceof SecurityException) {
233
-			if($exception instanceof StrictCookieMissingException) {
234
-				return new RedirectResponse(\OC::$WEBROOT);
235
- 			}
236
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
237
-				$response = new JSONResponse(
238
-					array('message' => $exception->getMessage()),
239
-					$exception->getCode()
240
-				);
241
-			} else {
242
-				if($exception instanceof NotLoggedInException) {
243
-					$params = [];
244
-					if (isset($this->request->server['REQUEST_URI'])) {
245
-						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
246
-					}
247
-					$url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
248
-					$response = new RedirectResponse($url);
249
-				} else {
250
-					$response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
251
-					$response->setStatus($exception->getCode());
252
-				}
253
-			}
221
+    /**
222
+     * If an SecurityException is being caught, ajax requests return a JSON error
223
+     * response and non ajax requests redirect to the index
224
+     * @param Controller $controller the controller that is being called
225
+     * @param string $methodName the name of the method that will be called on
226
+     *                           the controller
227
+     * @param \Exception $exception the thrown exception
228
+     * @throws \Exception the passed in exception if it can't handle it
229
+     * @return Response a Response object or null in case that the exception could not be handled
230
+     */
231
+    public function afterException($controller, $methodName, \Exception $exception) {
232
+        if($exception instanceof SecurityException) {
233
+            if($exception instanceof StrictCookieMissingException) {
234
+                return new RedirectResponse(\OC::$WEBROOT);
235
+                }
236
+            if (stripos($this->request->getHeader('Accept'),'html') === false) {
237
+                $response = new JSONResponse(
238
+                    array('message' => $exception->getMessage()),
239
+                    $exception->getCode()
240
+                );
241
+            } else {
242
+                if($exception instanceof NotLoggedInException) {
243
+                    $params = [];
244
+                    if (isset($this->request->server['REQUEST_URI'])) {
245
+                        $params['redirect_url'] = $this->request->server['REQUEST_URI'];
246
+                    }
247
+                    $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
248
+                    $response = new RedirectResponse($url);
249
+                } else {
250
+                    $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
251
+                    $response->setStatus($exception->getCode());
252
+                }
253
+            }
254 254
 
255
-			$this->logger->debug($exception->getMessage());
256
-			return $response;
257
-		}
255
+            $this->logger->debug($exception->getMessage());
256
+            return $response;
257
+        }
258 258
 
259
-		throw $exception;
260
-	}
259
+        throw $exception;
260
+    }
261 261
 
262 262
 }
Please login to merge, or discard this patch.
lib/private/Template/JSConfigHelper.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -39,239 +39,239 @@
 block discarded – undo
39 39
 
40 40
 class JSConfigHelper {
41 41
 
42
-	/** @var IL10N */
43
-	private $l;
42
+    /** @var IL10N */
43
+    private $l;
44 44
 
45
-	/** @var Defaults */
46
-	private $defaults;
45
+    /** @var Defaults */
46
+    private $defaults;
47 47
 
48
-	/** @var IAppManager */
49
-	private $appManager;
48
+    /** @var IAppManager */
49
+    private $appManager;
50 50
 
51
-	/** @var ISession */
52
-	private $session;
51
+    /** @var ISession */
52
+    private $session;
53 53
 
54
-	/** @var IUser|null */
55
-	private $currentUser;
54
+    /** @var IUser|null */
55
+    private $currentUser;
56 56
 
57
-	/** @var IConfig */
58
-	private $config;
57
+    /** @var IConfig */
58
+    private $config;
59 59
 
60
-	/** @var IGroupManager */
61
-	private $groupManager;
60
+    /** @var IGroupManager */
61
+    private $groupManager;
62 62
 
63
-	/** @var IniGetWrapper */
64
-	private $iniWrapper;
63
+    /** @var IniGetWrapper */
64
+    private $iniWrapper;
65 65
 
66
-	/** @var IURLGenerator */
67
-	private $urlGenerator;
66
+    /** @var IURLGenerator */
67
+    private $urlGenerator;
68 68
 
69
-	/**
70
-	 * @param IL10N $l
71
-	 * @param Defaults $defaults
72
-	 * @param IAppManager $appManager
73
-	 * @param ISession $session
74
-	 * @param IUser|null $currentUser
75
-	 * @param IConfig $config
76
-	 * @param IGroupManager $groupManager
77
-	 * @param IniGetWrapper $iniWrapper
78
-	 * @param IURLGenerator $urlGenerator
79
-	 */
80
-	public function __construct(IL10N $l,
81
-								Defaults $defaults,
82
-								IAppManager $appManager,
83
-								ISession $session,
84
-								$currentUser,
85
-								IConfig $config,
86
-								IGroupManager $groupManager,
87
-								IniGetWrapper $iniWrapper,
88
-								IURLGenerator $urlGenerator) {
89
-		$this->l = $l;
90
-		$this->defaults = $defaults;
91
-		$this->appManager = $appManager;
92
-		$this->session = $session;
93
-		$this->currentUser = $currentUser;
94
-		$this->config = $config;
95
-		$this->groupManager = $groupManager;
96
-		$this->iniWrapper = $iniWrapper;
97
-		$this->urlGenerator = $urlGenerator;
98
-	}
69
+    /**
70
+     * @param IL10N $l
71
+     * @param Defaults $defaults
72
+     * @param IAppManager $appManager
73
+     * @param ISession $session
74
+     * @param IUser|null $currentUser
75
+     * @param IConfig $config
76
+     * @param IGroupManager $groupManager
77
+     * @param IniGetWrapper $iniWrapper
78
+     * @param IURLGenerator $urlGenerator
79
+     */
80
+    public function __construct(IL10N $l,
81
+                                Defaults $defaults,
82
+                                IAppManager $appManager,
83
+                                ISession $session,
84
+                                $currentUser,
85
+                                IConfig $config,
86
+                                IGroupManager $groupManager,
87
+                                IniGetWrapper $iniWrapper,
88
+                                IURLGenerator $urlGenerator) {
89
+        $this->l = $l;
90
+        $this->defaults = $defaults;
91
+        $this->appManager = $appManager;
92
+        $this->session = $session;
93
+        $this->currentUser = $currentUser;
94
+        $this->config = $config;
95
+        $this->groupManager = $groupManager;
96
+        $this->iniWrapper = $iniWrapper;
97
+        $this->urlGenerator = $urlGenerator;
98
+    }
99 99
 
100
-	public function getConfig() {
100
+    public function getConfig() {
101 101
 
102
-		if ($this->currentUser !== null) {
103
-			$uid = $this->currentUser->getUID();
104
-			$userBackend = $this->currentUser->getBackendClassName();
105
-		} else {
106
-			$uid = null;
107
-			$userBackend = '';
108
-		}
102
+        if ($this->currentUser !== null) {
103
+            $uid = $this->currentUser->getUID();
104
+            $userBackend = $this->currentUser->getBackendClassName();
105
+        } else {
106
+            $uid = null;
107
+            $userBackend = '';
108
+        }
109 109
 
110
-		// Get the config
111
-		$apps_paths = [];
110
+        // Get the config
111
+        $apps_paths = [];
112 112
 
113
-		if ($this->currentUser === null) {
114
-			$apps = $this->appManager->getInstalledApps();
115
-		} else {
116
-			$apps = $this->appManager->getEnabledAppsForUser($this->currentUser);
117
-		}
113
+        if ($this->currentUser === null) {
114
+            $apps = $this->appManager->getInstalledApps();
115
+        } else {
116
+            $apps = $this->appManager->getEnabledAppsForUser($this->currentUser);
117
+        }
118 118
 
119
-		foreach($apps as $app) {
120
-			$apps_paths[$app] = \OC_App::getAppWebPath($app);
121
-		}
119
+        foreach($apps as $app) {
120
+            $apps_paths[$app] = \OC_App::getAppWebPath($app);
121
+        }
122 122
 
123 123
 
124
-		$enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no');
125
-		$enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false;
126
-		$defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
127
-		$defaultExpireDate = $enforceDefaultExpireDate = null;
128
-		if ($defaultExpireDateEnabled) {
129
-			$defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
130
-			$enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
131
-		}
132
-		$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
124
+        $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no');
125
+        $enableLinkPasswordByDefault = ($enableLinkPasswordByDefault === 'yes') ? true : false;
126
+        $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes';
127
+        $defaultExpireDate = $enforceDefaultExpireDate = null;
128
+        if ($defaultExpireDateEnabled) {
129
+            $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7');
130
+            $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes';
131
+        }
132
+        $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
133 133
 
134
-		$countOfDataLocation = 0;
135
-		$dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
136
-		if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
137
-			$dataLocation = false;
138
-		}
134
+        $countOfDataLocation = 0;
135
+        $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
136
+        if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
137
+            $dataLocation = false;
138
+        }
139 139
 
140
-		if ($this->currentUser instanceof IUser) {
141
-			$lastConfirmTimestamp = $this->session->get('last-password-confirm');
142
-			if (!is_int($lastConfirmTimestamp)) {
143
-				$lastConfirmTimestamp = 0;
144
-			}
145
-		} else {
146
-			$lastConfirmTimestamp = 0;
147
-		}
140
+        if ($this->currentUser instanceof IUser) {
141
+            $lastConfirmTimestamp = $this->session->get('last-password-confirm');
142
+            if (!is_int($lastConfirmTimestamp)) {
143
+                $lastConfirmTimestamp = 0;
144
+            }
145
+        } else {
146
+            $lastConfirmTimestamp = 0;
147
+        }
148 148
 
149
-		$array = [
150
-			"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
151
-			"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
152
-			"backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true',
153
-			"oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false',
154
-			"oc_webroot" => "\"".\OC::$WEBROOT."\"",
155
-			"oc_appswebroots" =>  str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
156
-			"datepickerFormatDate" => json_encode($this->l->l('jsdate', null)),
157
-			'nc_lastLogin' => $lastConfirmTimestamp,
158
-			"dayNames" =>  json_encode([
159
-				(string)$this->l->t('Sunday'),
160
-				(string)$this->l->t('Monday'),
161
-				(string)$this->l->t('Tuesday'),
162
-				(string)$this->l->t('Wednesday'),
163
-				(string)$this->l->t('Thursday'),
164
-				(string)$this->l->t('Friday'),
165
-				(string)$this->l->t('Saturday')
166
-			]),
167
-			"dayNamesShort" =>  json_encode([
168
-				(string)$this->l->t('Sun.'),
169
-				(string)$this->l->t('Mon.'),
170
-				(string)$this->l->t('Tue.'),
171
-				(string)$this->l->t('Wed.'),
172
-				(string)$this->l->t('Thu.'),
173
-				(string)$this->l->t('Fri.'),
174
-				(string)$this->l->t('Sat.')
175
-			]),
176
-			"dayNamesMin" =>  json_encode([
177
-				(string)$this->l->t('Su'),
178
-				(string)$this->l->t('Mo'),
179
-				(string)$this->l->t('Tu'),
180
-				(string)$this->l->t('We'),
181
-				(string)$this->l->t('Th'),
182
-				(string)$this->l->t('Fr'),
183
-				(string)$this->l->t('Sa')
184
-			]),
185
-			"monthNames" => json_encode([
186
-				(string)$this->l->t('January'),
187
-				(string)$this->l->t('February'),
188
-				(string)$this->l->t('March'),
189
-				(string)$this->l->t('April'),
190
-				(string)$this->l->t('May'),
191
-				(string)$this->l->t('June'),
192
-				(string)$this->l->t('July'),
193
-				(string)$this->l->t('August'),
194
-				(string)$this->l->t('September'),
195
-				(string)$this->l->t('October'),
196
-				(string)$this->l->t('November'),
197
-				(string)$this->l->t('December')
198
-			]),
199
-			"monthNamesShort" => json_encode([
200
-				(string)$this->l->t('Jan.'),
201
-				(string)$this->l->t('Feb.'),
202
-				(string)$this->l->t('Mar.'),
203
-				(string)$this->l->t('Apr.'),
204
-				(string)$this->l->t('May.'),
205
-				(string)$this->l->t('Jun.'),
206
-				(string)$this->l->t('Jul.'),
207
-				(string)$this->l->t('Aug.'),
208
-				(string)$this->l->t('Sep.'),
209
-				(string)$this->l->t('Oct.'),
210
-				(string)$this->l->t('Nov.'),
211
-				(string)$this->l->t('Dec.')
212
-			]),
213
-			"firstDay" => json_encode($this->l->l('firstday', null)) ,
214
-			"oc_config" => json_encode([
215
-				'session_lifetime'	=> min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
216
-				'session_keepalive'	=> $this->config->getSystemValue('session_keepalive', true),
217
-				'version'			=> implode('.', \OCP\Util::getVersion()),
218
-				'versionstring'		=> \OC_Util::getVersionString(),
219
-				'enable_avatars'	=> true, // here for legacy reasons - to not crash existing code that relies on this value
220
-				'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null),
221
-				'modRewriteWorking'	=> ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'),
222
-				'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)),
223
-				'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)),
224
-				'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
225
-			]),
226
-			"oc_appconfig" => json_encode([
227
-				'core' => [
228
-					'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
229
-					'defaultExpireDate' => $defaultExpireDate,
230
-					'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
231
-					'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(),
232
-					'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault,
233
-					'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(),
234
-					'resharingAllowed' => \OC\Share\Share::isResharingAllowed(),
235
-					'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
236
-					'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
237
-					'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing()
238
-				]
239
-			]),
240
-			"oc_defaults" => json_encode([
241
-				'entity' => $this->defaults->getEntity(),
242
-				'name' => $this->defaults->getName(),
243
-				'title' => $this->defaults->getTitle(),
244
-				'baseUrl' => $this->defaults->getBaseUrl(),
245
-				'syncClientUrl' => $this->defaults->getSyncClientUrl(),
246
-				'docBaseUrl' => $this->defaults->getDocBaseUrl(),
247
-				'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'),
248
-				'slogan' => $this->defaults->getSlogan(),
249
-				'logoClaim' => '',
250
-				'shortFooter' => $this->defaults->getShortFooter(),
251
-				'longFooter' => $this->defaults->getLongFooter(),
252
-				'folder' => \OC_Util::getTheme(),
253
-			]),
254
-		];
149
+        $array = [
150
+            "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
151
+            "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
152
+            "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true',
153
+            "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false',
154
+            "oc_webroot" => "\"".\OC::$WEBROOT."\"",
155
+            "oc_appswebroots" =>  str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
156
+            "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)),
157
+            'nc_lastLogin' => $lastConfirmTimestamp,
158
+            "dayNames" =>  json_encode([
159
+                (string)$this->l->t('Sunday'),
160
+                (string)$this->l->t('Monday'),
161
+                (string)$this->l->t('Tuesday'),
162
+                (string)$this->l->t('Wednesday'),
163
+                (string)$this->l->t('Thursday'),
164
+                (string)$this->l->t('Friday'),
165
+                (string)$this->l->t('Saturday')
166
+            ]),
167
+            "dayNamesShort" =>  json_encode([
168
+                (string)$this->l->t('Sun.'),
169
+                (string)$this->l->t('Mon.'),
170
+                (string)$this->l->t('Tue.'),
171
+                (string)$this->l->t('Wed.'),
172
+                (string)$this->l->t('Thu.'),
173
+                (string)$this->l->t('Fri.'),
174
+                (string)$this->l->t('Sat.')
175
+            ]),
176
+            "dayNamesMin" =>  json_encode([
177
+                (string)$this->l->t('Su'),
178
+                (string)$this->l->t('Mo'),
179
+                (string)$this->l->t('Tu'),
180
+                (string)$this->l->t('We'),
181
+                (string)$this->l->t('Th'),
182
+                (string)$this->l->t('Fr'),
183
+                (string)$this->l->t('Sa')
184
+            ]),
185
+            "monthNames" => json_encode([
186
+                (string)$this->l->t('January'),
187
+                (string)$this->l->t('February'),
188
+                (string)$this->l->t('March'),
189
+                (string)$this->l->t('April'),
190
+                (string)$this->l->t('May'),
191
+                (string)$this->l->t('June'),
192
+                (string)$this->l->t('July'),
193
+                (string)$this->l->t('August'),
194
+                (string)$this->l->t('September'),
195
+                (string)$this->l->t('October'),
196
+                (string)$this->l->t('November'),
197
+                (string)$this->l->t('December')
198
+            ]),
199
+            "monthNamesShort" => json_encode([
200
+                (string)$this->l->t('Jan.'),
201
+                (string)$this->l->t('Feb.'),
202
+                (string)$this->l->t('Mar.'),
203
+                (string)$this->l->t('Apr.'),
204
+                (string)$this->l->t('May.'),
205
+                (string)$this->l->t('Jun.'),
206
+                (string)$this->l->t('Jul.'),
207
+                (string)$this->l->t('Aug.'),
208
+                (string)$this->l->t('Sep.'),
209
+                (string)$this->l->t('Oct.'),
210
+                (string)$this->l->t('Nov.'),
211
+                (string)$this->l->t('Dec.')
212
+            ]),
213
+            "firstDay" => json_encode($this->l->l('firstday', null)) ,
214
+            "oc_config" => json_encode([
215
+                'session_lifetime'	=> min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
216
+                'session_keepalive'	=> $this->config->getSystemValue('session_keepalive', true),
217
+                'version'			=> implode('.', \OCP\Util::getVersion()),
218
+                'versionstring'		=> \OC_Util::getVersionString(),
219
+                'enable_avatars'	=> true, // here for legacy reasons - to not crash existing code that relies on this value
220
+                'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null),
221
+                'modRewriteWorking'	=> ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'),
222
+                'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)),
223
+                'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)),
224
+                'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
225
+            ]),
226
+            "oc_appconfig" => json_encode([
227
+                'core' => [
228
+                    'defaultExpireDateEnabled' => $defaultExpireDateEnabled,
229
+                    'defaultExpireDate' => $defaultExpireDate,
230
+                    'defaultExpireDateEnforced' => $enforceDefaultExpireDate,
231
+                    'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(),
232
+                    'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault,
233
+                    'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(),
234
+                    'resharingAllowed' => \OC\Share\Share::isResharingAllowed(),
235
+                    'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
236
+                    'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
237
+                    'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing()
238
+                ]
239
+            ]),
240
+            "oc_defaults" => json_encode([
241
+                'entity' => $this->defaults->getEntity(),
242
+                'name' => $this->defaults->getName(),
243
+                'title' => $this->defaults->getTitle(),
244
+                'baseUrl' => $this->defaults->getBaseUrl(),
245
+                'syncClientUrl' => $this->defaults->getSyncClientUrl(),
246
+                'docBaseUrl' => $this->defaults->getDocBaseUrl(),
247
+                'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'),
248
+                'slogan' => $this->defaults->getSlogan(),
249
+                'logoClaim' => '',
250
+                'shortFooter' => $this->defaults->getShortFooter(),
251
+                'longFooter' => $this->defaults->getLongFooter(),
252
+                'folder' => \OC_Util::getTheme(),
253
+            ]),
254
+        ];
255 255
 
256
-		if ($this->currentUser !== null) {
257
-			$array['oc_userconfig'] = json_encode([
258
-				'avatar' => [
259
-					'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0),
260
-					'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true',
261
-				]
262
-			]);
263
-		}
256
+        if ($this->currentUser !== null) {
257
+            $array['oc_userconfig'] = json_encode([
258
+                'avatar' => [
259
+                    'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0),
260
+                    'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true',
261
+                ]
262
+            ]);
263
+        }
264 264
 
265
-		// Allow hooks to modify the output values
266
-		\OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array));
265
+        // Allow hooks to modify the output values
266
+        \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array));
267 267
 
268
-		$result = '';
268
+        $result = '';
269 269
 
270
-		// Echo it
271
-		foreach ($array as  $setting => $value) {
272
-			$result .= 'var '. $setting . '='. $value . ';' . PHP_EOL;
273
-		}
270
+        // Echo it
271
+        foreach ($array as  $setting => $value) {
272
+            $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL;
273
+        }
274 274
 
275
-		return $result;
276
-	}
275
+        return $result;
276
+    }
277 277
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 			$apps = $this->appManager->getEnabledAppsForUser($this->currentUser);
117 117
 		}
118 118
 
119
-		foreach($apps as $app) {
119
+		foreach ($apps as $app) {
120 120
 			$apps_paths[$app] = \OC_App::getAppWebPath($app);
121 121
 		}
122 122
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 		$outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes';
133 133
 
134 134
 		$countOfDataLocation = 0;
135
-		$dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
136
-		if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
135
+		$dataLocation = str_replace(\OC::$SERVERROOT.'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
136
+		if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) {
137 137
 			$dataLocation = false;
138 138
 		}
139 139
 
@@ -149,68 +149,68 @@  discard block
 block discarded – undo
149 149
 		$array = [
150 150
 			"oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false',
151 151
 			"oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false',
152
-			"backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true',
152
+			"backendAllowsPasswordConfirmation" => $userBackend === 'user_saml' ? 'false' : 'true',
153 153
 			"oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false',
154 154
 			"oc_webroot" => "\"".\OC::$WEBROOT."\"",
155 155
 			"oc_appswebroots" =>  str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution
156 156
 			"datepickerFormatDate" => json_encode($this->l->l('jsdate', null)),
157 157
 			'nc_lastLogin' => $lastConfirmTimestamp,
158 158
 			"dayNames" =>  json_encode([
159
-				(string)$this->l->t('Sunday'),
160
-				(string)$this->l->t('Monday'),
161
-				(string)$this->l->t('Tuesday'),
162
-				(string)$this->l->t('Wednesday'),
163
-				(string)$this->l->t('Thursday'),
164
-				(string)$this->l->t('Friday'),
165
-				(string)$this->l->t('Saturday')
159
+				(string) $this->l->t('Sunday'),
160
+				(string) $this->l->t('Monday'),
161
+				(string) $this->l->t('Tuesday'),
162
+				(string) $this->l->t('Wednesday'),
163
+				(string) $this->l->t('Thursday'),
164
+				(string) $this->l->t('Friday'),
165
+				(string) $this->l->t('Saturday')
166 166
 			]),
167 167
 			"dayNamesShort" =>  json_encode([
168
-				(string)$this->l->t('Sun.'),
169
-				(string)$this->l->t('Mon.'),
170
-				(string)$this->l->t('Tue.'),
171
-				(string)$this->l->t('Wed.'),
172
-				(string)$this->l->t('Thu.'),
173
-				(string)$this->l->t('Fri.'),
174
-				(string)$this->l->t('Sat.')
168
+				(string) $this->l->t('Sun.'),
169
+				(string) $this->l->t('Mon.'),
170
+				(string) $this->l->t('Tue.'),
171
+				(string) $this->l->t('Wed.'),
172
+				(string) $this->l->t('Thu.'),
173
+				(string) $this->l->t('Fri.'),
174
+				(string) $this->l->t('Sat.')
175 175
 			]),
176 176
 			"dayNamesMin" =>  json_encode([
177
-				(string)$this->l->t('Su'),
178
-				(string)$this->l->t('Mo'),
179
-				(string)$this->l->t('Tu'),
180
-				(string)$this->l->t('We'),
181
-				(string)$this->l->t('Th'),
182
-				(string)$this->l->t('Fr'),
183
-				(string)$this->l->t('Sa')
177
+				(string) $this->l->t('Su'),
178
+				(string) $this->l->t('Mo'),
179
+				(string) $this->l->t('Tu'),
180
+				(string) $this->l->t('We'),
181
+				(string) $this->l->t('Th'),
182
+				(string) $this->l->t('Fr'),
183
+				(string) $this->l->t('Sa')
184 184
 			]),
185 185
 			"monthNames" => json_encode([
186
-				(string)$this->l->t('January'),
187
-				(string)$this->l->t('February'),
188
-				(string)$this->l->t('March'),
189
-				(string)$this->l->t('April'),
190
-				(string)$this->l->t('May'),
191
-				(string)$this->l->t('June'),
192
-				(string)$this->l->t('July'),
193
-				(string)$this->l->t('August'),
194
-				(string)$this->l->t('September'),
195
-				(string)$this->l->t('October'),
196
-				(string)$this->l->t('November'),
197
-				(string)$this->l->t('December')
186
+				(string) $this->l->t('January'),
187
+				(string) $this->l->t('February'),
188
+				(string) $this->l->t('March'),
189
+				(string) $this->l->t('April'),
190
+				(string) $this->l->t('May'),
191
+				(string) $this->l->t('June'),
192
+				(string) $this->l->t('July'),
193
+				(string) $this->l->t('August'),
194
+				(string) $this->l->t('September'),
195
+				(string) $this->l->t('October'),
196
+				(string) $this->l->t('November'),
197
+				(string) $this->l->t('December')
198 198
 			]),
199 199
 			"monthNamesShort" => json_encode([
200
-				(string)$this->l->t('Jan.'),
201
-				(string)$this->l->t('Feb.'),
202
-				(string)$this->l->t('Mar.'),
203
-				(string)$this->l->t('Apr.'),
204
-				(string)$this->l->t('May.'),
205
-				(string)$this->l->t('Jun.'),
206
-				(string)$this->l->t('Jul.'),
207
-				(string)$this->l->t('Aug.'),
208
-				(string)$this->l->t('Sep.'),
209
-				(string)$this->l->t('Oct.'),
210
-				(string)$this->l->t('Nov.'),
211
-				(string)$this->l->t('Dec.')
200
+				(string) $this->l->t('Jan.'),
201
+				(string) $this->l->t('Feb.'),
202
+				(string) $this->l->t('Mar.'),
203
+				(string) $this->l->t('Apr.'),
204
+				(string) $this->l->t('May.'),
205
+				(string) $this->l->t('Jun.'),
206
+				(string) $this->l->t('Jul.'),
207
+				(string) $this->l->t('Aug.'),
208
+				(string) $this->l->t('Sep.'),
209
+				(string) $this->l->t('Oct.'),
210
+				(string) $this->l->t('Nov.'),
211
+				(string) $this->l->t('Dec.')
212 212
 			]),
213
-			"firstDay" => json_encode($this->l->l('firstday', null)) ,
213
+			"firstDay" => json_encode($this->l->l('firstday', null)),
214 214
 			"oc_config" => json_encode([
215 215
 				'session_lifetime'	=> min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
216 216
 				'session_keepalive'	=> $this->config->getSystemValue('session_keepalive', true),
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		if ($this->currentUser !== null) {
257 257
 			$array['oc_userconfig'] = json_encode([
258 258
 				'avatar' => [
259
-					'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0),
259
+					'version' => (int) $this->config->getUserValue($uid, 'avatar', 'version', 0),
260 260
 					'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true',
261 261
 				]
262 262
 			]);
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 		// Echo it
271 271
 		foreach ($array as  $setting => $value) {
272
-			$result .= 'var '. $setting . '='. $value . ';' . PHP_EOL;
272
+			$result .= 'var '.$setting.'='.$value.';'.PHP_EOL;
273 273
 		}
274 274
 
275 275
 		return $result;
Please login to merge, or discard this patch.