@@ -69,354 +69,354 @@ |
||
| 69 | 69 | |
| 70 | 70 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @var array |
|
| 74 | - */ |
|
| 75 | - private $middleWares = []; |
|
| 76 | - |
|
| 77 | - /** @var ServerContainer */ |
|
| 78 | - private $server; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Put your class dependencies in here |
|
| 82 | - * @param string $appName the name of the app |
|
| 83 | - * @param array $urlParams |
|
| 84 | - * @param ServerContainer|null $server |
|
| 85 | - */ |
|
| 86 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 87 | - parent::__construct(); |
|
| 88 | - $this['AppName'] = $appName; |
|
| 89 | - $this['urlParams'] = $urlParams; |
|
| 90 | - |
|
| 91 | - $this->registerAlias('Request', IRequest::class); |
|
| 92 | - |
|
| 93 | - /** @var \OC\ServerContainer $server */ |
|
| 94 | - if ($server === null) { |
|
| 95 | - $server = \OC::$server; |
|
| 96 | - } |
|
| 97 | - $this->server = $server; |
|
| 98 | - $this->server->registerAppContainer($appName, $this); |
|
| 99 | - |
|
| 100 | - // aliases |
|
| 101 | - $this->registerAlias('appName', 'AppName'); |
|
| 102 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 103 | - $this->registerAlias('userId', 'UserId'); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Core services |
|
| 107 | - */ |
|
| 108 | - $this->registerService(IOutput::class, function(){ |
|
| 109 | - return new Output($this->getServer()->getWebRoot()); |
|
| 110 | - }); |
|
| 111 | - |
|
| 112 | - $this->registerService(Folder::class, function() { |
|
| 113 | - return $this->getServer()->getUserFolder(); |
|
| 114 | - }); |
|
| 115 | - |
|
| 116 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 117 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 118 | - }); |
|
| 119 | - |
|
| 120 | - $this->registerService(IL10N::class, function($c) { |
|
| 121 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 122 | - }); |
|
| 123 | - |
|
| 124 | - // Log wrapper |
|
| 125 | - $this->registerService(ILogger::class, function ($c) { |
|
| 126 | - return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName')); |
|
| 127 | - }); |
|
| 128 | - |
|
| 129 | - $this->registerService(IServerContainer::class, function () { |
|
| 130 | - return $this->getServer(); |
|
| 131 | - }); |
|
| 132 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 133 | - |
|
| 134 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 135 | - return $c->query(Manager::class); |
|
| 136 | - }); |
|
| 137 | - |
|
| 138 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 139 | - return $c; |
|
| 140 | - }); |
|
| 141 | - |
|
| 142 | - // commonly used attributes |
|
| 143 | - $this->registerService('UserId', function ($c) { |
|
| 144 | - return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 145 | - }); |
|
| 146 | - |
|
| 147 | - $this->registerService('WebRoot', function ($c) { |
|
| 148 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 149 | - }); |
|
| 150 | - |
|
| 151 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 152 | - return $c->getServer()->getThemingDefaults(); |
|
| 153 | - }); |
|
| 154 | - |
|
| 155 | - $this->registerService(IConfig::class, function ($c) { |
|
| 156 | - return $c->query(OC\GlobalScale\Config::class); |
|
| 157 | - }); |
|
| 158 | - |
|
| 159 | - $this->registerService('Protocol', function($c){ |
|
| 160 | - /** @var \OC\Server $server */ |
|
| 161 | - $server = $c->query('ServerContainer'); |
|
| 162 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 163 | - return new Http($_SERVER, $protocol); |
|
| 164 | - }); |
|
| 165 | - |
|
| 166 | - $this->registerService('Dispatcher', function($c) { |
|
| 167 | - return new Dispatcher( |
|
| 168 | - $c['Protocol'], |
|
| 169 | - $c['MiddlewareDispatcher'], |
|
| 170 | - $c->query(IControllerMethodReflector::class), |
|
| 171 | - $c['Request'] |
|
| 172 | - ); |
|
| 173 | - }); |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * App Framework default arguments |
|
| 177 | - */ |
|
| 178 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 179 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 180 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Middleware |
|
| 184 | - */ |
|
| 185 | - $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) { |
|
| 186 | - $server = $this->getServer(); |
|
| 187 | - |
|
| 188 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 189 | - $dispatcher->registerMiddleware( |
|
| 190 | - $c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - $dispatcher->registerMiddleware( |
|
| 194 | - new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 195 | - $c->query(IRequest::class), |
|
| 196 | - $c->query(IControllerMethodReflector::class) |
|
| 197 | - ) |
|
| 198 | - ); |
|
| 199 | - $dispatcher->registerMiddleware( |
|
| 200 | - new CORSMiddleware( |
|
| 201 | - $c->query(IRequest::class), |
|
| 202 | - $c->query(IControllerMethodReflector::class), |
|
| 203 | - $c->query(IUserSession::class), |
|
| 204 | - $c->query(OC\Security\Bruteforce\Throttler::class) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - $dispatcher->registerMiddleware( |
|
| 208 | - new OCSMiddleware( |
|
| 209 | - $c->query(IRequest::class) |
|
| 210 | - ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - $securityMiddleware = new SecurityMiddleware( |
|
| 214 | - $c->query(IRequest::class), |
|
| 215 | - $c->query(IControllerMethodReflector::class), |
|
| 216 | - $c->query(INavigationManager::class), |
|
| 217 | - $c->query(IURLGenerator::class), |
|
| 218 | - $server->getLogger(), |
|
| 219 | - $c['AppName'], |
|
| 220 | - $server->getUserSession()->isLoggedIn(), |
|
| 221 | - $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 222 | - $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
| 223 | - $server->getAppManager(), |
|
| 224 | - $server->getL10N('lib') |
|
| 225 | - ); |
|
| 226 | - $dispatcher->registerMiddleware($securityMiddleware); |
|
| 227 | - $dispatcher->registerMiddleware( |
|
| 228 | - new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
| 229 | - $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
| 230 | - $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
| 231 | - $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
| 232 | - ) |
|
| 233 | - ); |
|
| 234 | - $dispatcher->registerMiddleware( |
|
| 235 | - $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
| 236 | - ); |
|
| 237 | - $dispatcher->registerMiddleware( |
|
| 238 | - new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 239 | - $c->query(IControllerMethodReflector::class), |
|
| 240 | - $c->query(ISession::class), |
|
| 241 | - $c->query(IUserSession::class), |
|
| 242 | - $c->query(ITimeFactory::class) |
|
| 243 | - ) |
|
| 244 | - ); |
|
| 245 | - $dispatcher->registerMiddleware( |
|
| 246 | - new TwoFactorMiddleware( |
|
| 247 | - $c->query(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 248 | - $c->query(IUserSession::class), |
|
| 249 | - $c->query(ISession::class), |
|
| 250 | - $c->query(IURLGenerator::class), |
|
| 251 | - $c->query(IControllerMethodReflector::class), |
|
| 252 | - $c->query(IRequest::class) |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - $dispatcher->registerMiddleware( |
|
| 256 | - new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 257 | - $c->query(IControllerMethodReflector::class), |
|
| 258 | - $c->query(OC\Security\Bruteforce\Throttler::class), |
|
| 259 | - $c->query(IRequest::class) |
|
| 260 | - ) |
|
| 261 | - ); |
|
| 262 | - $dispatcher->registerMiddleware( |
|
| 263 | - new RateLimitingMiddleware( |
|
| 264 | - $c->query(IRequest::class), |
|
| 265 | - $c->query(IUserSession::class), |
|
| 266 | - $c->query(IControllerMethodReflector::class), |
|
| 267 | - $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 268 | - ) |
|
| 269 | - ); |
|
| 270 | - $dispatcher->registerMiddleware( |
|
| 271 | - new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 272 | - $c->query(IRequest::class), |
|
| 273 | - $c->query(ISession::class), |
|
| 274 | - $c->query(\OCP\IConfig::class) |
|
| 275 | - ) |
|
| 276 | - ); |
|
| 277 | - $dispatcher->registerMiddleware( |
|
| 278 | - $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 279 | - ); |
|
| 280 | - |
|
| 281 | - foreach($this->middleWares as $middleWare) { |
|
| 282 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $dispatcher->registerMiddleware( |
|
| 286 | - new SessionMiddleware( |
|
| 287 | - $c->query(IRequest::class), |
|
| 288 | - $c->query(IControllerMethodReflector::class), |
|
| 289 | - $c->query(ISession::class) |
|
| 290 | - ) |
|
| 291 | - ); |
|
| 292 | - return $dispatcher; |
|
| 293 | - }); |
|
| 294 | - |
|
| 295 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, OC\Collaboration\Resources\Manager::class); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return \OCP\IServerContainer |
|
| 300 | - */ |
|
| 301 | - public function getServer() |
|
| 302 | - { |
|
| 303 | - return $this->server; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @param string $middleWare |
|
| 308 | - * @return boolean|null |
|
| 309 | - */ |
|
| 310 | - public function registerMiddleWare($middleWare) { |
|
| 311 | - if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 312 | - return false; |
|
| 313 | - } |
|
| 314 | - $this->middleWares[] = $middleWare; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * used to return the appname of the set application |
|
| 319 | - * @return string the name of your application |
|
| 320 | - */ |
|
| 321 | - public function getAppName() { |
|
| 322 | - return $this->query('AppName'); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 327 | - * @return boolean |
|
| 328 | - */ |
|
| 329 | - public function isLoggedIn() { |
|
| 330 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 335 | - * @return boolean |
|
| 336 | - */ |
|
| 337 | - public function isAdminUser() { |
|
| 338 | - $uid = $this->getUserId(); |
|
| 339 | - return \OC_User::isAdminUser($uid); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - private function getUserId() { |
|
| 343 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @deprecated use the ILogger instead |
|
| 348 | - * @param string $message |
|
| 349 | - * @param string $level |
|
| 350 | - * @return mixed |
|
| 351 | - */ |
|
| 352 | - public function log($message, $level) { |
|
| 353 | - switch($level){ |
|
| 354 | - case 'debug': |
|
| 355 | - $level = ILogger::DEBUG; |
|
| 356 | - break; |
|
| 357 | - case 'info': |
|
| 358 | - $level = ILogger::INFO; |
|
| 359 | - break; |
|
| 360 | - case 'warn': |
|
| 361 | - $level = ILogger::WARN; |
|
| 362 | - break; |
|
| 363 | - case 'fatal': |
|
| 364 | - $level = ILogger::FATAL; |
|
| 365 | - break; |
|
| 366 | - default: |
|
| 367 | - $level = ILogger::ERROR; |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Register a capability |
|
| 375 | - * |
|
| 376 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 377 | - */ |
|
| 378 | - public function registerCapability($serviceName) { |
|
| 379 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 380 | - return $this->query($serviceName); |
|
| 381 | - }); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - public function query(string $name, bool $autoload = true) { |
|
| 385 | - try { |
|
| 386 | - return $this->queryNoFallback($name); |
|
| 387 | - } catch (QueryException $firstException) { |
|
| 388 | - try { |
|
| 389 | - return $this->getServer()->query($name, $autoload); |
|
| 390 | - } catch (QueryException $secondException) { |
|
| 391 | - if ($firstException->getCode() === 1) { |
|
| 392 | - throw $secondException; |
|
| 393 | - } |
|
| 394 | - throw $firstException; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * @param string $name |
|
| 401 | - * @return mixed |
|
| 402 | - * @throws QueryException if the query could not be resolved |
|
| 403 | - */ |
|
| 404 | - public function queryNoFallback($name) { |
|
| 405 | - $name = $this->sanitizeName($name); |
|
| 406 | - |
|
| 407 | - if ($this->offsetExists($name)) { |
|
| 408 | - return parent::query($name); |
|
| 409 | - } else { |
|
| 410 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 411 | - return parent::query($name); |
|
| 412 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 413 | - return parent::query($name); |
|
| 414 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 415 | - return parent::query($name); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 420 | - ' Class can not be instantiated', 1); |
|
| 421 | - } |
|
| 72 | + /** |
|
| 73 | + * @var array |
|
| 74 | + */ |
|
| 75 | + private $middleWares = []; |
|
| 76 | + |
|
| 77 | + /** @var ServerContainer */ |
|
| 78 | + private $server; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Put your class dependencies in here |
|
| 82 | + * @param string $appName the name of the app |
|
| 83 | + * @param array $urlParams |
|
| 84 | + * @param ServerContainer|null $server |
|
| 85 | + */ |
|
| 86 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 87 | + parent::__construct(); |
|
| 88 | + $this['AppName'] = $appName; |
|
| 89 | + $this['urlParams'] = $urlParams; |
|
| 90 | + |
|
| 91 | + $this->registerAlias('Request', IRequest::class); |
|
| 92 | + |
|
| 93 | + /** @var \OC\ServerContainer $server */ |
|
| 94 | + if ($server === null) { |
|
| 95 | + $server = \OC::$server; |
|
| 96 | + } |
|
| 97 | + $this->server = $server; |
|
| 98 | + $this->server->registerAppContainer($appName, $this); |
|
| 99 | + |
|
| 100 | + // aliases |
|
| 101 | + $this->registerAlias('appName', 'AppName'); |
|
| 102 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 103 | + $this->registerAlias('userId', 'UserId'); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Core services |
|
| 107 | + */ |
|
| 108 | + $this->registerService(IOutput::class, function(){ |
|
| 109 | + return new Output($this->getServer()->getWebRoot()); |
|
| 110 | + }); |
|
| 111 | + |
|
| 112 | + $this->registerService(Folder::class, function() { |
|
| 113 | + return $this->getServer()->getUserFolder(); |
|
| 114 | + }); |
|
| 115 | + |
|
| 116 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 117 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 118 | + }); |
|
| 119 | + |
|
| 120 | + $this->registerService(IL10N::class, function($c) { |
|
| 121 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 122 | + }); |
|
| 123 | + |
|
| 124 | + // Log wrapper |
|
| 125 | + $this->registerService(ILogger::class, function ($c) { |
|
| 126 | + return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName')); |
|
| 127 | + }); |
|
| 128 | + |
|
| 129 | + $this->registerService(IServerContainer::class, function () { |
|
| 130 | + return $this->getServer(); |
|
| 131 | + }); |
|
| 132 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 133 | + |
|
| 134 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 135 | + return $c->query(Manager::class); |
|
| 136 | + }); |
|
| 137 | + |
|
| 138 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 139 | + return $c; |
|
| 140 | + }); |
|
| 141 | + |
|
| 142 | + // commonly used attributes |
|
| 143 | + $this->registerService('UserId', function ($c) { |
|
| 144 | + return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 145 | + }); |
|
| 146 | + |
|
| 147 | + $this->registerService('WebRoot', function ($c) { |
|
| 148 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 149 | + }); |
|
| 150 | + |
|
| 151 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 152 | + return $c->getServer()->getThemingDefaults(); |
|
| 153 | + }); |
|
| 154 | + |
|
| 155 | + $this->registerService(IConfig::class, function ($c) { |
|
| 156 | + return $c->query(OC\GlobalScale\Config::class); |
|
| 157 | + }); |
|
| 158 | + |
|
| 159 | + $this->registerService('Protocol', function($c){ |
|
| 160 | + /** @var \OC\Server $server */ |
|
| 161 | + $server = $c->query('ServerContainer'); |
|
| 162 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 163 | + return new Http($_SERVER, $protocol); |
|
| 164 | + }); |
|
| 165 | + |
|
| 166 | + $this->registerService('Dispatcher', function($c) { |
|
| 167 | + return new Dispatcher( |
|
| 168 | + $c['Protocol'], |
|
| 169 | + $c['MiddlewareDispatcher'], |
|
| 170 | + $c->query(IControllerMethodReflector::class), |
|
| 171 | + $c['Request'] |
|
| 172 | + ); |
|
| 173 | + }); |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * App Framework default arguments |
|
| 177 | + */ |
|
| 178 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 179 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 180 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Middleware |
|
| 184 | + */ |
|
| 185 | + $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) { |
|
| 186 | + $server = $this->getServer(); |
|
| 187 | + |
|
| 188 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 189 | + $dispatcher->registerMiddleware( |
|
| 190 | + $c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + $dispatcher->registerMiddleware( |
|
| 194 | + new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 195 | + $c->query(IRequest::class), |
|
| 196 | + $c->query(IControllerMethodReflector::class) |
|
| 197 | + ) |
|
| 198 | + ); |
|
| 199 | + $dispatcher->registerMiddleware( |
|
| 200 | + new CORSMiddleware( |
|
| 201 | + $c->query(IRequest::class), |
|
| 202 | + $c->query(IControllerMethodReflector::class), |
|
| 203 | + $c->query(IUserSession::class), |
|
| 204 | + $c->query(OC\Security\Bruteforce\Throttler::class) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + $dispatcher->registerMiddleware( |
|
| 208 | + new OCSMiddleware( |
|
| 209 | + $c->query(IRequest::class) |
|
| 210 | + ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + $securityMiddleware = new SecurityMiddleware( |
|
| 214 | + $c->query(IRequest::class), |
|
| 215 | + $c->query(IControllerMethodReflector::class), |
|
| 216 | + $c->query(INavigationManager::class), |
|
| 217 | + $c->query(IURLGenerator::class), |
|
| 218 | + $server->getLogger(), |
|
| 219 | + $c['AppName'], |
|
| 220 | + $server->getUserSession()->isLoggedIn(), |
|
| 221 | + $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 222 | + $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
| 223 | + $server->getAppManager(), |
|
| 224 | + $server->getL10N('lib') |
|
| 225 | + ); |
|
| 226 | + $dispatcher->registerMiddleware($securityMiddleware); |
|
| 227 | + $dispatcher->registerMiddleware( |
|
| 228 | + new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
| 229 | + $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
| 230 | + $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
| 231 | + $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
| 232 | + ) |
|
| 233 | + ); |
|
| 234 | + $dispatcher->registerMiddleware( |
|
| 235 | + $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
| 236 | + ); |
|
| 237 | + $dispatcher->registerMiddleware( |
|
| 238 | + new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 239 | + $c->query(IControllerMethodReflector::class), |
|
| 240 | + $c->query(ISession::class), |
|
| 241 | + $c->query(IUserSession::class), |
|
| 242 | + $c->query(ITimeFactory::class) |
|
| 243 | + ) |
|
| 244 | + ); |
|
| 245 | + $dispatcher->registerMiddleware( |
|
| 246 | + new TwoFactorMiddleware( |
|
| 247 | + $c->query(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 248 | + $c->query(IUserSession::class), |
|
| 249 | + $c->query(ISession::class), |
|
| 250 | + $c->query(IURLGenerator::class), |
|
| 251 | + $c->query(IControllerMethodReflector::class), |
|
| 252 | + $c->query(IRequest::class) |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + $dispatcher->registerMiddleware( |
|
| 256 | + new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 257 | + $c->query(IControllerMethodReflector::class), |
|
| 258 | + $c->query(OC\Security\Bruteforce\Throttler::class), |
|
| 259 | + $c->query(IRequest::class) |
|
| 260 | + ) |
|
| 261 | + ); |
|
| 262 | + $dispatcher->registerMiddleware( |
|
| 263 | + new RateLimitingMiddleware( |
|
| 264 | + $c->query(IRequest::class), |
|
| 265 | + $c->query(IUserSession::class), |
|
| 266 | + $c->query(IControllerMethodReflector::class), |
|
| 267 | + $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 268 | + ) |
|
| 269 | + ); |
|
| 270 | + $dispatcher->registerMiddleware( |
|
| 271 | + new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 272 | + $c->query(IRequest::class), |
|
| 273 | + $c->query(ISession::class), |
|
| 274 | + $c->query(\OCP\IConfig::class) |
|
| 275 | + ) |
|
| 276 | + ); |
|
| 277 | + $dispatcher->registerMiddleware( |
|
| 278 | + $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 279 | + ); |
|
| 280 | + |
|
| 281 | + foreach($this->middleWares as $middleWare) { |
|
| 282 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $dispatcher->registerMiddleware( |
|
| 286 | + new SessionMiddleware( |
|
| 287 | + $c->query(IRequest::class), |
|
| 288 | + $c->query(IControllerMethodReflector::class), |
|
| 289 | + $c->query(ISession::class) |
|
| 290 | + ) |
|
| 291 | + ); |
|
| 292 | + return $dispatcher; |
|
| 293 | + }); |
|
| 294 | + |
|
| 295 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, OC\Collaboration\Resources\Manager::class); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return \OCP\IServerContainer |
|
| 300 | + */ |
|
| 301 | + public function getServer() |
|
| 302 | + { |
|
| 303 | + return $this->server; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @param string $middleWare |
|
| 308 | + * @return boolean|null |
|
| 309 | + */ |
|
| 310 | + public function registerMiddleWare($middleWare) { |
|
| 311 | + if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
| 312 | + return false; |
|
| 313 | + } |
|
| 314 | + $this->middleWares[] = $middleWare; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * used to return the appname of the set application |
|
| 319 | + * @return string the name of your application |
|
| 320 | + */ |
|
| 321 | + public function getAppName() { |
|
| 322 | + return $this->query('AppName'); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 327 | + * @return boolean |
|
| 328 | + */ |
|
| 329 | + public function isLoggedIn() { |
|
| 330 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 335 | + * @return boolean |
|
| 336 | + */ |
|
| 337 | + public function isAdminUser() { |
|
| 338 | + $uid = $this->getUserId(); |
|
| 339 | + return \OC_User::isAdminUser($uid); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + private function getUserId() { |
|
| 343 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @deprecated use the ILogger instead |
|
| 348 | + * @param string $message |
|
| 349 | + * @param string $level |
|
| 350 | + * @return mixed |
|
| 351 | + */ |
|
| 352 | + public function log($message, $level) { |
|
| 353 | + switch($level){ |
|
| 354 | + case 'debug': |
|
| 355 | + $level = ILogger::DEBUG; |
|
| 356 | + break; |
|
| 357 | + case 'info': |
|
| 358 | + $level = ILogger::INFO; |
|
| 359 | + break; |
|
| 360 | + case 'warn': |
|
| 361 | + $level = ILogger::WARN; |
|
| 362 | + break; |
|
| 363 | + case 'fatal': |
|
| 364 | + $level = ILogger::FATAL; |
|
| 365 | + break; |
|
| 366 | + default: |
|
| 367 | + $level = ILogger::ERROR; |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Register a capability |
|
| 375 | + * |
|
| 376 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 377 | + */ |
|
| 378 | + public function registerCapability($serviceName) { |
|
| 379 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 380 | + return $this->query($serviceName); |
|
| 381 | + }); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + public function query(string $name, bool $autoload = true) { |
|
| 385 | + try { |
|
| 386 | + return $this->queryNoFallback($name); |
|
| 387 | + } catch (QueryException $firstException) { |
|
| 388 | + try { |
|
| 389 | + return $this->getServer()->query($name, $autoload); |
|
| 390 | + } catch (QueryException $secondException) { |
|
| 391 | + if ($firstException->getCode() === 1) { |
|
| 392 | + throw $secondException; |
|
| 393 | + } |
|
| 394 | + throw $firstException; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * @param string $name |
|
| 401 | + * @return mixed |
|
| 402 | + * @throws QueryException if the query could not be resolved |
|
| 403 | + */ |
|
| 404 | + public function queryNoFallback($name) { |
|
| 405 | + $name = $this->sanitizeName($name); |
|
| 406 | + |
|
| 407 | + if ($this->offsetExists($name)) { |
|
| 408 | + return parent::query($name); |
|
| 409 | + } else { |
|
| 410 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 411 | + return parent::query($name); |
|
| 412 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 413 | + return parent::query($name); |
|
| 414 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 415 | + return parent::query($name); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 420 | + ' Class can not be instantiated', 1); |
|
| 421 | + } |
|
| 422 | 422 | } |
@@ -38,33 +38,33 @@ |
||
| 38 | 38 | |
| 39 | 39 | class FeaturePolicyMiddleware extends Middleware { |
| 40 | 40 | |
| 41 | - /** @var FeaturePolicyManager */ |
|
| 42 | - private $policyManager; |
|
| 41 | + /** @var FeaturePolicyManager */ |
|
| 42 | + private $policyManager; |
|
| 43 | 43 | |
| 44 | - public function __construct(FeaturePolicyManager $policyManager) { |
|
| 45 | - $this->policyManager = $policyManager; |
|
| 46 | - } |
|
| 44 | + public function __construct(FeaturePolicyManager $policyManager) { |
|
| 45 | + $this->policyManager = $policyManager; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Performs the default FeaturePolicy modifications that may be injected by other |
|
| 50 | - * applications |
|
| 51 | - * |
|
| 52 | - * @param Controller $controller |
|
| 53 | - * @param string $methodName |
|
| 54 | - * @param Response $response |
|
| 55 | - * @return Response |
|
| 56 | - */ |
|
| 57 | - public function afterController($controller, $methodName, Response $response): Response { |
|
| 58 | - $policy = !is_null($response->getFeaturePolicy()) ? $response->getFeaturePolicy() : new FeaturePolicy(); |
|
| 48 | + /** |
|
| 49 | + * Performs the default FeaturePolicy modifications that may be injected by other |
|
| 50 | + * applications |
|
| 51 | + * |
|
| 52 | + * @param Controller $controller |
|
| 53 | + * @param string $methodName |
|
| 54 | + * @param Response $response |
|
| 55 | + * @return Response |
|
| 56 | + */ |
|
| 57 | + public function afterController($controller, $methodName, Response $response): Response { |
|
| 58 | + $policy = !is_null($response->getFeaturePolicy()) ? $response->getFeaturePolicy() : new FeaturePolicy(); |
|
| 59 | 59 | |
| 60 | - if (get_class($policy) === EmptyFeaturePolicy::class) { |
|
| 61 | - return $response; |
|
| 62 | - } |
|
| 60 | + if (get_class($policy) === EmptyFeaturePolicy::class) { |
|
| 61 | + return $response; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $defaultPolicy = $this->policyManager->getDefaultPolicy(); |
|
| 65 | - $defaultPolicy = $this->policyManager->mergePolicies($defaultPolicy, $policy); |
|
| 66 | - $response->setFeaturePolicy($defaultPolicy); |
|
| 64 | + $defaultPolicy = $this->policyManager->getDefaultPolicy(); |
|
| 65 | + $defaultPolicy = $this->policyManager->mergePolicies($defaultPolicy, $policy); |
|
| 66 | + $response->setFeaturePolicy($defaultPolicy); |
|
| 67 | 67 | |
| 68 | - return $response; |
|
| 69 | - } |
|
| 68 | + return $response; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -28,122 +28,122 @@ |
||
| 28 | 28 | use OCP\AppFramework\Http\Response; |
| 29 | 29 | |
| 30 | 30 | abstract class BaseResponse extends Response { |
| 31 | - /** @var array */ |
|
| 32 | - protected $data; |
|
| 33 | - |
|
| 34 | - /** @var string */ |
|
| 35 | - protected $format; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - protected $statusMessage; |
|
| 39 | - |
|
| 40 | - /** @var int */ |
|
| 41 | - protected $itemsCount; |
|
| 42 | - |
|
| 43 | - /** @var int */ |
|
| 44 | - protected $itemsPerPage; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * BaseResponse constructor. |
|
| 48 | - * |
|
| 49 | - * @param DataResponse|null $dataResponse |
|
| 50 | - * @param string $format |
|
| 51 | - * @param string|null $statusMessage |
|
| 52 | - * @param int|null $itemsCount |
|
| 53 | - * @param int|null $itemsPerPage |
|
| 54 | - */ |
|
| 55 | - public function __construct(DataResponse $dataResponse, |
|
| 56 | - $format = 'xml', |
|
| 57 | - $statusMessage = null, |
|
| 58 | - $itemsCount = null, |
|
| 59 | - $itemsPerPage = null) { |
|
| 60 | - parent::__construct(); |
|
| 61 | - |
|
| 62 | - $this->format = $format; |
|
| 63 | - $this->statusMessage = $statusMessage; |
|
| 64 | - $this->itemsCount = $itemsCount; |
|
| 65 | - $this->itemsPerPage = $itemsPerPage; |
|
| 66 | - |
|
| 67 | - $this->data = $dataResponse->getData(); |
|
| 68 | - |
|
| 69 | - $this->setHeaders($dataResponse->getHeaders()); |
|
| 70 | - $this->setStatus($dataResponse->getStatus()); |
|
| 71 | - $this->setETag($dataResponse->getETag()); |
|
| 72 | - $this->setLastModified($dataResponse->getLastModified()); |
|
| 73 | - $this->setCookies($dataResponse->getCookies()); |
|
| 74 | - |
|
| 75 | - if ($format === 'json') { |
|
| 76 | - $this->addHeader( |
|
| 77 | - 'Content-Type', 'application/json; charset=utf-8' |
|
| 78 | - ); |
|
| 79 | - } else { |
|
| 80 | - $this->addHeader( |
|
| 81 | - 'Content-Type', 'application/xml; charset=utf-8' |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param string[] $meta |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - protected function renderResult(array $meta): string { |
|
| 91 | - $status = $this->getStatus(); |
|
| 92 | - if ($status === Http::STATUS_NO_CONTENT || |
|
| 93 | - $status === Http::STATUS_NOT_MODIFIED || |
|
| 94 | - ($status >= 100 && $status <= 199)) { |
|
| 95 | - // Those status codes are not supposed to have a body: |
|
| 96 | - // https://stackoverflow.com/q/8628725 |
|
| 97 | - return ''; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $response = [ |
|
| 101 | - 'ocs' => [ |
|
| 102 | - 'meta' => $meta, |
|
| 103 | - 'data' => $this->data, |
|
| 104 | - ], |
|
| 105 | - ]; |
|
| 106 | - |
|
| 107 | - if ($this->format === 'json') { |
|
| 108 | - return json_encode($response, JSON_HEX_TAG); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $writer = new \XMLWriter(); |
|
| 112 | - $writer->openMemory(); |
|
| 113 | - $writer->setIndent(true); |
|
| 114 | - $writer->startDocument(); |
|
| 115 | - $this->toXML($response, $writer); |
|
| 116 | - $writer->endDocument(); |
|
| 117 | - return $writer->outputMemory(true); |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param array $array |
|
| 123 | - * @param \XMLWriter $writer |
|
| 124 | - */ |
|
| 125 | - protected function toXML(array $array, \XMLWriter $writer) { |
|
| 126 | - foreach ($array as $k => $v) { |
|
| 127 | - if ($k[0] === '@') { |
|
| 128 | - $writer->writeAttribute(substr($k, 1), $v); |
|
| 129 | - continue; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if (\is_numeric($k)) { |
|
| 133 | - $k = 'element'; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (\is_array($v)) { |
|
| 137 | - $writer->startElement($k); |
|
| 138 | - $this->toXML($v, $writer); |
|
| 139 | - $writer->endElement(); |
|
| 140 | - } else { |
|
| 141 | - $writer->writeElement($k, $v); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function getOCSStatus() { |
|
| 147 | - return parent::getStatus(); |
|
| 148 | - } |
|
| 31 | + /** @var array */ |
|
| 32 | + protected $data; |
|
| 33 | + |
|
| 34 | + /** @var string */ |
|
| 35 | + protected $format; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $statusMessage; |
|
| 39 | + |
|
| 40 | + /** @var int */ |
|
| 41 | + protected $itemsCount; |
|
| 42 | + |
|
| 43 | + /** @var int */ |
|
| 44 | + protected $itemsPerPage; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * BaseResponse constructor. |
|
| 48 | + * |
|
| 49 | + * @param DataResponse|null $dataResponse |
|
| 50 | + * @param string $format |
|
| 51 | + * @param string|null $statusMessage |
|
| 52 | + * @param int|null $itemsCount |
|
| 53 | + * @param int|null $itemsPerPage |
|
| 54 | + */ |
|
| 55 | + public function __construct(DataResponse $dataResponse, |
|
| 56 | + $format = 'xml', |
|
| 57 | + $statusMessage = null, |
|
| 58 | + $itemsCount = null, |
|
| 59 | + $itemsPerPage = null) { |
|
| 60 | + parent::__construct(); |
|
| 61 | + |
|
| 62 | + $this->format = $format; |
|
| 63 | + $this->statusMessage = $statusMessage; |
|
| 64 | + $this->itemsCount = $itemsCount; |
|
| 65 | + $this->itemsPerPage = $itemsPerPage; |
|
| 66 | + |
|
| 67 | + $this->data = $dataResponse->getData(); |
|
| 68 | + |
|
| 69 | + $this->setHeaders($dataResponse->getHeaders()); |
|
| 70 | + $this->setStatus($dataResponse->getStatus()); |
|
| 71 | + $this->setETag($dataResponse->getETag()); |
|
| 72 | + $this->setLastModified($dataResponse->getLastModified()); |
|
| 73 | + $this->setCookies($dataResponse->getCookies()); |
|
| 74 | + |
|
| 75 | + if ($format === 'json') { |
|
| 76 | + $this->addHeader( |
|
| 77 | + 'Content-Type', 'application/json; charset=utf-8' |
|
| 78 | + ); |
|
| 79 | + } else { |
|
| 80 | + $this->addHeader( |
|
| 81 | + 'Content-Type', 'application/xml; charset=utf-8' |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param string[] $meta |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + protected function renderResult(array $meta): string { |
|
| 91 | + $status = $this->getStatus(); |
|
| 92 | + if ($status === Http::STATUS_NO_CONTENT || |
|
| 93 | + $status === Http::STATUS_NOT_MODIFIED || |
|
| 94 | + ($status >= 100 && $status <= 199)) { |
|
| 95 | + // Those status codes are not supposed to have a body: |
|
| 96 | + // https://stackoverflow.com/q/8628725 |
|
| 97 | + return ''; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $response = [ |
|
| 101 | + 'ocs' => [ |
|
| 102 | + 'meta' => $meta, |
|
| 103 | + 'data' => $this->data, |
|
| 104 | + ], |
|
| 105 | + ]; |
|
| 106 | + |
|
| 107 | + if ($this->format === 'json') { |
|
| 108 | + return json_encode($response, JSON_HEX_TAG); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $writer = new \XMLWriter(); |
|
| 112 | + $writer->openMemory(); |
|
| 113 | + $writer->setIndent(true); |
|
| 114 | + $writer->startDocument(); |
|
| 115 | + $this->toXML($response, $writer); |
|
| 116 | + $writer->endDocument(); |
|
| 117 | + return $writer->outputMemory(true); |
|
| 118 | + |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param array $array |
|
| 123 | + * @param \XMLWriter $writer |
|
| 124 | + */ |
|
| 125 | + protected function toXML(array $array, \XMLWriter $writer) { |
|
| 126 | + foreach ($array as $k => $v) { |
|
| 127 | + if ($k[0] === '@') { |
|
| 128 | + $writer->writeAttribute(substr($k, 1), $v); |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if (\is_numeric($k)) { |
|
| 133 | + $k = 'element'; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (\is_array($v)) { |
|
| 137 | + $writer->startElement($k); |
|
| 138 | + $this->toXML($v, $writer); |
|
| 139 | + $writer->endElement(); |
|
| 140 | + } else { |
|
| 141 | + $writer->writeElement($k, $v); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function getOCSStatus() { |
|
| 147 | + return parent::getStatus(); |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -29,48 +29,48 @@ |
||
| 29 | 29 | use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent; |
| 30 | 30 | |
| 31 | 31 | class FeaturePolicyManager { |
| 32 | - /** @var EmptyFeaturePolicy[] */ |
|
| 33 | - private $policies = []; |
|
| 32 | + /** @var EmptyFeaturePolicy[] */ |
|
| 33 | + private $policies = []; |
|
| 34 | 34 | |
| 35 | - /** @var IEventDispatcher */ |
|
| 36 | - private $dispatcher; |
|
| 35 | + /** @var IEventDispatcher */ |
|
| 36 | + private $dispatcher; |
|
| 37 | 37 | |
| 38 | - public function __construct(IEventDispatcher $dispatcher) { |
|
| 39 | - $this->dispatcher = $dispatcher; |
|
| 40 | - } |
|
| 38 | + public function __construct(IEventDispatcher $dispatcher) { |
|
| 39 | + $this->dispatcher = $dispatcher; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
| 43 | - $this->policies[] = $policy; |
|
| 44 | - } |
|
| 42 | + public function addDefaultPolicy(EmptyFeaturePolicy $policy): void { |
|
| 43 | + $this->policies[] = $policy; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getDefaultPolicy(): FeaturePolicy { |
|
| 47 | - $event = new AddFeaturePolicyEvent($this); |
|
| 48 | - $this->dispatcher->dispatch(AddFeaturePolicyEvent::class, $event); |
|
| 46 | + public function getDefaultPolicy(): FeaturePolicy { |
|
| 47 | + $event = new AddFeaturePolicyEvent($this); |
|
| 48 | + $this->dispatcher->dispatch(AddFeaturePolicyEvent::class, $event); |
|
| 49 | 49 | |
| 50 | - $defaultPolicy = new FeaturePolicy(); |
|
| 51 | - foreach ($this->policies as $policy) { |
|
| 52 | - $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 53 | - } |
|
| 54 | - return $defaultPolicy; |
|
| 55 | - } |
|
| 50 | + $defaultPolicy = new FeaturePolicy(); |
|
| 51 | + foreach ($this->policies as $policy) { |
|
| 52 | + $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); |
|
| 53 | + } |
|
| 54 | + return $defaultPolicy; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Merges the first given policy with the second one |
|
| 59 | - * |
|
| 60 | - */ |
|
| 61 | - public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
| 62 | - EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
| 63 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 64 | - $setter = 'set' . ucfirst($name); |
|
| 65 | - if (\is_array($value)) { |
|
| 66 | - $getter = 'get' . ucfirst($name); |
|
| 67 | - $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 68 | - $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
| 69 | - } elseif (\is_bool($value)) { |
|
| 70 | - $defaultPolicy->$setter($value); |
|
| 71 | - } |
|
| 72 | - } |
|
| 57 | + /** |
|
| 58 | + * Merges the first given policy with the second one |
|
| 59 | + * |
|
| 60 | + */ |
|
| 61 | + public function mergePolicies(FeaturePolicy $defaultPolicy, |
|
| 62 | + EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
|
| 63 | + foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 64 | + $setter = 'set' . ucfirst($name); |
|
| 65 | + if (\is_array($value)) { |
|
| 66 | + $getter = 'get' . ucfirst($name); |
|
| 67 | + $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
|
| 68 | + $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
|
| 69 | + } elseif (\is_bool($value)) { |
|
| 70 | + $defaultPolicy->$setter($value); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $defaultPolicy; |
|
| 75 | - } |
|
| 74 | + return $defaultPolicy; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -60,10 +60,10 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function mergePolicies(FeaturePolicy $defaultPolicy, |
| 62 | 62 | EmptyFeaturePolicy $originalPolicy): FeaturePolicy { |
| 63 | - foreach ((object)(array)$originalPolicy as $name => $value) { |
|
| 64 | - $setter = 'set' . ucfirst($name); |
|
| 63 | + foreach ((object) (array) $originalPolicy as $name => $value) { |
|
| 64 | + $setter = 'set'.ucfirst($name); |
|
| 65 | 65 | if (\is_array($value)) { |
| 66 | - $getter = 'get' . ucfirst($name); |
|
| 66 | + $getter = 'get'.ucfirst($name); |
|
| 67 | 67 | $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; |
| 68 | 68 | $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); |
| 69 | 69 | } elseif (\is_bool($value)) { |
@@ -26,51 +26,51 @@ |
||
| 26 | 26 | |
| 27 | 27 | class FeaturePolicy extends \OCP\AppFramework\Http\FeaturePolicy { |
| 28 | 28 | |
| 29 | - public function getAutoplayDomains(): array { |
|
| 30 | - return $this->autoplayDomains; |
|
| 31 | - } |
|
| 29 | + public function getAutoplayDomains(): array { |
|
| 30 | + return $this->autoplayDomains; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function setAutoplayDomains(array $autoplayDomains): void { |
|
| 34 | - $this->autoplayDomains = $autoplayDomains; |
|
| 35 | - } |
|
| 33 | + public function setAutoplayDomains(array $autoplayDomains): void { |
|
| 34 | + $this->autoplayDomains = $autoplayDomains; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function getCameraDomains(): array { |
|
| 38 | - return $this->cameraDomains; |
|
| 39 | - } |
|
| 37 | + public function getCameraDomains(): array { |
|
| 38 | + return $this->cameraDomains; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function setCameraDomains(array $cameraDomains): void { |
|
| 42 | - $this->cameraDomains = $cameraDomains; |
|
| 43 | - } |
|
| 41 | + public function setCameraDomains(array $cameraDomains): void { |
|
| 42 | + $this->cameraDomains = $cameraDomains; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function getFullscreenDomains(): array { |
|
| 46 | - return $this->fullscreenDomains; |
|
| 47 | - } |
|
| 45 | + public function getFullscreenDomains(): array { |
|
| 46 | + return $this->fullscreenDomains; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public function setFullscreenDomains(array $fullscreenDomains): void { |
|
| 50 | - $this->fullscreenDomains = $fullscreenDomains; |
|
| 51 | - } |
|
| 49 | + public function setFullscreenDomains(array $fullscreenDomains): void { |
|
| 50 | + $this->fullscreenDomains = $fullscreenDomains; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function getGeolocationDomains(): array { |
|
| 54 | - return $this->geolocationDomains; |
|
| 55 | - } |
|
| 53 | + public function getGeolocationDomains(): array { |
|
| 54 | + return $this->geolocationDomains; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function setGeolocationDomains(array $geolocationDomains): void { |
|
| 58 | - $this->geolocationDomains = $geolocationDomains; |
|
| 59 | - } |
|
| 57 | + public function setGeolocationDomains(array $geolocationDomains): void { |
|
| 58 | + $this->geolocationDomains = $geolocationDomains; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function getMicrophoneDomains(): array { |
|
| 62 | - return $this->microphoneDomains; |
|
| 63 | - } |
|
| 61 | + public function getMicrophoneDomains(): array { |
|
| 62 | + return $this->microphoneDomains; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function setMicrophoneDomains(array $microphoneDomains): void { |
|
| 66 | - $this->microphoneDomains = $microphoneDomains; |
|
| 67 | - } |
|
| 65 | + public function setMicrophoneDomains(array $microphoneDomains): void { |
|
| 66 | + $this->microphoneDomains = $microphoneDomains; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function getPaymentDomains(): array { |
|
| 70 | - return $this->paymentDomains; |
|
| 71 | - } |
|
| 69 | + public function getPaymentDomains(): array { |
|
| 70 | + return $this->paymentDomains; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function setPaymentDomains(array $paymentDomains): void { |
|
| 74 | - $this->paymentDomains = $paymentDomains; |
|
| 75 | - } |
|
| 73 | + public function setPaymentDomains(array $paymentDomains): void { |
|
| 74 | + $this->paymentDomains = $paymentDomains; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -37,132 +37,132 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class TemplateResponse extends Response { |
| 39 | 39 | |
| 40 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
| 41 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * name of the template |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $templateName; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * parameters |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - protected $params; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * rendering type (admin, user, blank) |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $renderAs; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * app name |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - protected $appName; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * constructor of TemplateResponse |
|
| 69 | - * @param string $appName the name of the app to load the template from |
|
| 70 | - * @param string $templateName the name of the template |
|
| 71 | - * @param array $params an array of parameters which should be passed to the |
|
| 72 | - * template |
|
| 73 | - * @param string $renderAs how the page should be rendered, defaults to user |
|
| 74 | - * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 75 | - */ |
|
| 76 | - public function __construct($appName, $templateName, array $params=array(), |
|
| 77 | - $renderAs='user') { |
|
| 78 | - parent::__construct(); |
|
| 79 | - |
|
| 80 | - $this->templateName = $templateName; |
|
| 81 | - $this->appName = $appName; |
|
| 82 | - $this->params = $params; |
|
| 83 | - $this->renderAs = $renderAs; |
|
| 84 | - |
|
| 85 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 86 | - $this->setFeaturePolicy(new FeaturePolicy()); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Sets template parameters |
|
| 92 | - * @param array $params an array with key => value structure which sets template |
|
| 93 | - * variables |
|
| 94 | - * @return TemplateResponse Reference to this object |
|
| 95 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 96 | - */ |
|
| 97 | - public function setParams(array $params){ |
|
| 98 | - $this->params = $params; |
|
| 99 | - |
|
| 100 | - return $this; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Used for accessing the set parameters |
|
| 106 | - * @return array the params |
|
| 107 | - * @since 6.0.0 |
|
| 108 | - */ |
|
| 109 | - public function getParams(){ |
|
| 110 | - return $this->params; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Used for accessing the name of the set template |
|
| 116 | - * @return string the name of the used template |
|
| 117 | - * @since 6.0.0 |
|
| 118 | - */ |
|
| 119 | - public function getTemplateName(){ |
|
| 120 | - return $this->templateName; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Sets the template page |
|
| 126 | - * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 127 | - * settings header and footer, user renders the normal |
|
| 128 | - * normal page including footer and header and blank |
|
| 129 | - * just renders the plain template |
|
| 130 | - * @return TemplateResponse Reference to this object |
|
| 131 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 132 | - */ |
|
| 133 | - public function renderAs($renderAs){ |
|
| 134 | - $this->renderAs = $renderAs; |
|
| 135 | - |
|
| 136 | - return $this; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns the set renderAs |
|
| 142 | - * @return string the renderAs value |
|
| 143 | - * @since 6.0.0 |
|
| 144 | - */ |
|
| 145 | - public function getRenderAs(){ |
|
| 146 | - return $this->renderAs; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Returns the rendered html |
|
| 152 | - * @return string the rendered html |
|
| 153 | - * @since 6.0.0 |
|
| 154 | - */ |
|
| 155 | - public function render(){ |
|
| 156 | - // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 157 | - $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
| 158 | - |
|
| 159 | - $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
| 160 | - |
|
| 161 | - foreach($this->params as $key => $value){ |
|
| 162 | - $template->assign($key, $value); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $template->fetchPage($this->params); |
|
| 166 | - } |
|
| 40 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
| 41 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * name of the template |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $templateName; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * parameters |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + protected $params; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * rendering type (admin, user, blank) |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $renderAs; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * app name |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + protected $appName; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * constructor of TemplateResponse |
|
| 69 | + * @param string $appName the name of the app to load the template from |
|
| 70 | + * @param string $templateName the name of the template |
|
| 71 | + * @param array $params an array of parameters which should be passed to the |
|
| 72 | + * template |
|
| 73 | + * @param string $renderAs how the page should be rendered, defaults to user |
|
| 74 | + * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 75 | + */ |
|
| 76 | + public function __construct($appName, $templateName, array $params=array(), |
|
| 77 | + $renderAs='user') { |
|
| 78 | + parent::__construct(); |
|
| 79 | + |
|
| 80 | + $this->templateName = $templateName; |
|
| 81 | + $this->appName = $appName; |
|
| 82 | + $this->params = $params; |
|
| 83 | + $this->renderAs = $renderAs; |
|
| 84 | + |
|
| 85 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 86 | + $this->setFeaturePolicy(new FeaturePolicy()); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Sets template parameters |
|
| 92 | + * @param array $params an array with key => value structure which sets template |
|
| 93 | + * variables |
|
| 94 | + * @return TemplateResponse Reference to this object |
|
| 95 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 96 | + */ |
|
| 97 | + public function setParams(array $params){ |
|
| 98 | + $this->params = $params; |
|
| 99 | + |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Used for accessing the set parameters |
|
| 106 | + * @return array the params |
|
| 107 | + * @since 6.0.0 |
|
| 108 | + */ |
|
| 109 | + public function getParams(){ |
|
| 110 | + return $this->params; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Used for accessing the name of the set template |
|
| 116 | + * @return string the name of the used template |
|
| 117 | + * @since 6.0.0 |
|
| 118 | + */ |
|
| 119 | + public function getTemplateName(){ |
|
| 120 | + return $this->templateName; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Sets the template page |
|
| 126 | + * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 127 | + * settings header and footer, user renders the normal |
|
| 128 | + * normal page including footer and header and blank |
|
| 129 | + * just renders the plain template |
|
| 130 | + * @return TemplateResponse Reference to this object |
|
| 131 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 132 | + */ |
|
| 133 | + public function renderAs($renderAs){ |
|
| 134 | + $this->renderAs = $renderAs; |
|
| 135 | + |
|
| 136 | + return $this; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns the set renderAs |
|
| 142 | + * @return string the renderAs value |
|
| 143 | + * @since 6.0.0 |
|
| 144 | + */ |
|
| 145 | + public function getRenderAs(){ |
|
| 146 | + return $this->renderAs; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Returns the rendered html |
|
| 152 | + * @return string the rendered html |
|
| 153 | + * @since 6.0.0 |
|
| 154 | + */ |
|
| 155 | + public function render(){ |
|
| 156 | + // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 157 | + $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
| 158 | + |
|
| 159 | + $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
| 160 | + |
|
| 161 | + foreach($this->params as $key => $value){ |
|
| 162 | + $template->assign($key, $value); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $template->fetchPage($this->params); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | } |
@@ -37,147 +37,147 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class EmptyFeaturePolicy { |
| 39 | 39 | |
| 40 | - /** @var string[] of allowed domains to autoplay media */ |
|
| 41 | - protected $autoplayDomains = null; |
|
| 42 | - |
|
| 43 | - /** @var string[] of allowed domains that can access the camera */ |
|
| 44 | - protected $cameraDomains = null; |
|
| 45 | - |
|
| 46 | - /** @var string[] of allowed domains that can use fullscreen */ |
|
| 47 | - protected $fullscreenDomains = null; |
|
| 48 | - |
|
| 49 | - /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
| 50 | - protected $geolocationDomains = null; |
|
| 51 | - |
|
| 52 | - /** @var string[] of allowed domains that can use the microphone */ |
|
| 53 | - protected $microphoneDomains = null; |
|
| 54 | - |
|
| 55 | - /** @var string[] of allowed domains that can use the payment API */ |
|
| 56 | - protected $paymentDomains = null; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Allows to use autoplay from a specific domain. Use * to allow from all domains. |
|
| 60 | - * |
|
| 61 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 62 | - * @return $this |
|
| 63 | - * @since 17.0.0 |
|
| 64 | - */ |
|
| 65 | - public function addAllowedAutoplayDomain(string $domain): self { |
|
| 66 | - $this->autoplayDomains[] = $domain; |
|
| 67 | - return $this; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Allows to use the camera on a specific domain. Use * to allow from all domains |
|
| 72 | - * |
|
| 73 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 74 | - * @return $this |
|
| 75 | - * @since 17.0.0 |
|
| 76 | - */ |
|
| 77 | - public function addAllowedCameraDomain(string $domain): self { |
|
| 78 | - $this->cameraDomains[] = $domain; |
|
| 79 | - return $this; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Allows the full screen functionality to be used on a specific domain. Use * to allow from all domains |
|
| 84 | - * |
|
| 85 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 86 | - * @return $this |
|
| 87 | - * @since 17.0.0 |
|
| 88 | - */ |
|
| 89 | - public function addAllowedFullScreenDomain(string $domain): self { |
|
| 90 | - $this->fullscreenDomains[] = $domain; |
|
| 91 | - return $this; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Allows to use the geolocation on a specific domain. Use * to allow from all domains |
|
| 96 | - * |
|
| 97 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 98 | - * @return $this |
|
| 99 | - * @since 17.0.0 |
|
| 100 | - */ |
|
| 101 | - public function addAllowedGeoLocationDomain(string $domain): self { |
|
| 102 | - $this->geolocationDomains[] = $domain; |
|
| 103 | - return $this; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Allows to use the microphone on a specific domain. Use * to allow from all domains |
|
| 108 | - * |
|
| 109 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 110 | - * @return $this |
|
| 111 | - * @since 17.0.0 |
|
| 112 | - */ |
|
| 113 | - public function addAllowedMicrophoneDomain(string $domain): self { |
|
| 114 | - $this->microphoneDomains[] = $domain; |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Allows to use the payment API on a specific domain. Use * to allow from all domains |
|
| 120 | - * |
|
| 121 | - * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 122 | - * @return $this |
|
| 123 | - * @since 17.0.0 |
|
| 124 | - */ |
|
| 125 | - public function addAllowedPaymentDomain(string $domain): self { |
|
| 126 | - $this->paymentDomains[] = $domain; |
|
| 127 | - return $this; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Get the generated Feature-Policy as a string |
|
| 132 | - * |
|
| 133 | - * @return string |
|
| 134 | - * @since 17.0.0 |
|
| 135 | - */ |
|
| 136 | - public function buildPolicy(): string { |
|
| 137 | - $policy = ''; |
|
| 138 | - |
|
| 139 | - if (empty($this->autoplayDomains)) { |
|
| 140 | - $policy .= "autoplay 'none';"; |
|
| 141 | - } else { |
|
| 142 | - $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
| 143 | - $policy .= ';'; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if (empty($this->cameraDomains)) { |
|
| 147 | - $policy .= "camera 'none';"; |
|
| 148 | - } else { |
|
| 149 | - $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
| 150 | - $policy .= ';'; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if (empty($this->fullscreenDomains)) { |
|
| 154 | - $policy .= "fullscreen 'none';"; |
|
| 155 | - } else { |
|
| 156 | - $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
| 157 | - $policy .= ';'; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (empty($this->geolocationDomains)) { |
|
| 161 | - $policy .= "geolocation 'none';"; |
|
| 162 | - } else { |
|
| 163 | - $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
| 164 | - $policy .= ';'; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if (empty($this->microphoneDomains)) { |
|
| 168 | - $policy .= "microphone 'none';"; |
|
| 169 | - } else { |
|
| 170 | - $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
| 171 | - $policy .= ';'; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if (empty($this->paymentDomains)) { |
|
| 175 | - $policy .= "payment 'none';"; |
|
| 176 | - } else { |
|
| 177 | - $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
| 178 | - $policy .= ';'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return rtrim($policy, ';'); |
|
| 182 | - } |
|
| 40 | + /** @var string[] of allowed domains to autoplay media */ |
|
| 41 | + protected $autoplayDomains = null; |
|
| 42 | + |
|
| 43 | + /** @var string[] of allowed domains that can access the camera */ |
|
| 44 | + protected $cameraDomains = null; |
|
| 45 | + |
|
| 46 | + /** @var string[] of allowed domains that can use fullscreen */ |
|
| 47 | + protected $fullscreenDomains = null; |
|
| 48 | + |
|
| 49 | + /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
| 50 | + protected $geolocationDomains = null; |
|
| 51 | + |
|
| 52 | + /** @var string[] of allowed domains that can use the microphone */ |
|
| 53 | + protected $microphoneDomains = null; |
|
| 54 | + |
|
| 55 | + /** @var string[] of allowed domains that can use the payment API */ |
|
| 56 | + protected $paymentDomains = null; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Allows to use autoplay from a specific domain. Use * to allow from all domains. |
|
| 60 | + * |
|
| 61 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 62 | + * @return $this |
|
| 63 | + * @since 17.0.0 |
|
| 64 | + */ |
|
| 65 | + public function addAllowedAutoplayDomain(string $domain): self { |
|
| 66 | + $this->autoplayDomains[] = $domain; |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Allows to use the camera on a specific domain. Use * to allow from all domains |
|
| 72 | + * |
|
| 73 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 74 | + * @return $this |
|
| 75 | + * @since 17.0.0 |
|
| 76 | + */ |
|
| 77 | + public function addAllowedCameraDomain(string $domain): self { |
|
| 78 | + $this->cameraDomains[] = $domain; |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Allows the full screen functionality to be used on a specific domain. Use * to allow from all domains |
|
| 84 | + * |
|
| 85 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 86 | + * @return $this |
|
| 87 | + * @since 17.0.0 |
|
| 88 | + */ |
|
| 89 | + public function addAllowedFullScreenDomain(string $domain): self { |
|
| 90 | + $this->fullscreenDomains[] = $domain; |
|
| 91 | + return $this; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Allows to use the geolocation on a specific domain. Use * to allow from all domains |
|
| 96 | + * |
|
| 97 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 98 | + * @return $this |
|
| 99 | + * @since 17.0.0 |
|
| 100 | + */ |
|
| 101 | + public function addAllowedGeoLocationDomain(string $domain): self { |
|
| 102 | + $this->geolocationDomains[] = $domain; |
|
| 103 | + return $this; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Allows to use the microphone on a specific domain. Use * to allow from all domains |
|
| 108 | + * |
|
| 109 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 110 | + * @return $this |
|
| 111 | + * @since 17.0.0 |
|
| 112 | + */ |
|
| 113 | + public function addAllowedMicrophoneDomain(string $domain): self { |
|
| 114 | + $this->microphoneDomains[] = $domain; |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Allows to use the payment API on a specific domain. Use * to allow from all domains |
|
| 120 | + * |
|
| 121 | + * @param string $domain Domain to whitelist. Any passed value needs to be properly sanitized. |
|
| 122 | + * @return $this |
|
| 123 | + * @since 17.0.0 |
|
| 124 | + */ |
|
| 125 | + public function addAllowedPaymentDomain(string $domain): self { |
|
| 126 | + $this->paymentDomains[] = $domain; |
|
| 127 | + return $this; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Get the generated Feature-Policy as a string |
|
| 132 | + * |
|
| 133 | + * @return string |
|
| 134 | + * @since 17.0.0 |
|
| 135 | + */ |
|
| 136 | + public function buildPolicy(): string { |
|
| 137 | + $policy = ''; |
|
| 138 | + |
|
| 139 | + if (empty($this->autoplayDomains)) { |
|
| 140 | + $policy .= "autoplay 'none';"; |
|
| 141 | + } else { |
|
| 142 | + $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
| 143 | + $policy .= ';'; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if (empty($this->cameraDomains)) { |
|
| 147 | + $policy .= "camera 'none';"; |
|
| 148 | + } else { |
|
| 149 | + $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
| 150 | + $policy .= ';'; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (empty($this->fullscreenDomains)) { |
|
| 154 | + $policy .= "fullscreen 'none';"; |
|
| 155 | + } else { |
|
| 156 | + $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
| 157 | + $policy .= ';'; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (empty($this->geolocationDomains)) { |
|
| 161 | + $policy .= "geolocation 'none';"; |
|
| 162 | + } else { |
|
| 163 | + $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
| 164 | + $policy .= ';'; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if (empty($this->microphoneDomains)) { |
|
| 168 | + $policy .= "microphone 'none';"; |
|
| 169 | + } else { |
|
| 170 | + $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
| 171 | + $policy .= ';'; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if (empty($this->paymentDomains)) { |
|
| 175 | + $policy .= "payment 'none';"; |
|
| 176 | + } else { |
|
| 177 | + $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
| 178 | + $policy .= ';'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return rtrim($policy, ';'); |
|
| 182 | + } |
|
| 183 | 183 | } |
@@ -139,42 +139,42 @@ |
||
| 139 | 139 | if (empty($this->autoplayDomains)) { |
| 140 | 140 | $policy .= "autoplay 'none';"; |
| 141 | 141 | } else { |
| 142 | - $policy .= 'autoplay ' . implode(' ', $this->autoplayDomains); |
|
| 142 | + $policy .= 'autoplay '.implode(' ', $this->autoplayDomains); |
|
| 143 | 143 | $policy .= ';'; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if (empty($this->cameraDomains)) { |
| 147 | 147 | $policy .= "camera 'none';"; |
| 148 | 148 | } else { |
| 149 | - $policy .= 'camera ' . implode(' ', $this->cameraDomains); |
|
| 149 | + $policy .= 'camera '.implode(' ', $this->cameraDomains); |
|
| 150 | 150 | $policy .= ';'; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | if (empty($this->fullscreenDomains)) { |
| 154 | 154 | $policy .= "fullscreen 'none';"; |
| 155 | 155 | } else { |
| 156 | - $policy .= 'fullscreen ' . implode(' ', $this->fullscreenDomains); |
|
| 156 | + $policy .= 'fullscreen '.implode(' ', $this->fullscreenDomains); |
|
| 157 | 157 | $policy .= ';'; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | if (empty($this->geolocationDomains)) { |
| 161 | 161 | $policy .= "geolocation 'none';"; |
| 162 | 162 | } else { |
| 163 | - $policy .= 'geolocation ' . implode(' ', $this->geolocationDomains); |
|
| 163 | + $policy .= 'geolocation '.implode(' ', $this->geolocationDomains); |
|
| 164 | 164 | $policy .= ';'; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | if (empty($this->microphoneDomains)) { |
| 168 | 168 | $policy .= "microphone 'none';"; |
| 169 | 169 | } else { |
| 170 | - $policy .= 'microphone ' . implode(' ', $this->microphoneDomains); |
|
| 170 | + $policy .= 'microphone '.implode(' ', $this->microphoneDomains); |
|
| 171 | 171 | $policy .= ';'; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | if (empty($this->paymentDomains)) { |
| 175 | 175 | $policy .= "payment 'none';"; |
| 176 | 176 | } else { |
| 177 | - $policy .= 'payment ' . implode(' ', $this->paymentDomains); |
|
| 177 | + $policy .= 'payment '.implode(' ', $this->paymentDomains); |
|
| 178 | 178 | $policy .= ';'; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -45,361 +45,361 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | class Response { |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - private $headers = array( |
|
| 53 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Cookies that will be need to be constructed as header |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - private $cookies = array(); |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * HTTP status code - defaults to STATUS OK |
|
| 66 | - * @var int |
|
| 67 | - */ |
|
| 68 | - private $status = Http::STATUS_OK; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Last modified date |
|
| 73 | - * @var \DateTime |
|
| 74 | - */ |
|
| 75 | - private $lastModified; |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * ETag |
|
| 80 | - * @var string |
|
| 81 | - */ |
|
| 82 | - private $ETag; |
|
| 83 | - |
|
| 84 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
| 85 | - private $contentSecurityPolicy = null; |
|
| 86 | - |
|
| 87 | - /** @var FeaturePolicy */ |
|
| 88 | - private $featurePolicy; |
|
| 89 | - |
|
| 90 | - /** @var bool */ |
|
| 91 | - private $throttled = false; |
|
| 92 | - /** @var array */ |
|
| 93 | - private $throttleMetadata = []; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Response constructor. |
|
| 97 | - * |
|
| 98 | - * @since 17.0.0 |
|
| 99 | - */ |
|
| 100 | - public function __construct() { |
|
| 101 | - $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 102 | - $this->setFeaturePolicy(new EmptyFeaturePolicy()); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Caches the response |
|
| 107 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
| 108 | - * if 0 then caching will be disabled |
|
| 109 | - * @return $this |
|
| 110 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 111 | - */ |
|
| 112 | - public function cacheFor(int $cacheSeconds) { |
|
| 113 | - if($cacheSeconds > 0) { |
|
| 114 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 115 | - |
|
| 116 | - // Old scool prama caching |
|
| 117 | - $this->addHeader('Pragma', 'public'); |
|
| 118 | - |
|
| 119 | - // Set expires header |
|
| 120 | - $expires = new \DateTime(); |
|
| 121 | - /** @var ITimeFactory $time */ |
|
| 122 | - $time = \OC::$server->query(ITimeFactory::class); |
|
| 123 | - $expires->setTimestamp($time->getTime()); |
|
| 124 | - $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
| 125 | - $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 126 | - } else { |
|
| 127 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
| 128 | - unset($this->headers['Expires'], $this->headers['Pragma']); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $this; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Adds a new cookie to the response |
|
| 136 | - * @param string $name The name of the cookie |
|
| 137 | - * @param string $value The value of the cookie |
|
| 138 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
| 139 | - * to null cookie will be considered as session |
|
| 140 | - * cookie. |
|
| 141 | - * @return $this |
|
| 142 | - * @since 8.0.0 |
|
| 143 | - */ |
|
| 144 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
| 145 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set the specified cookies |
|
| 152 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
| 153 | - * @return $this |
|
| 154 | - * @since 8.0.0 |
|
| 155 | - */ |
|
| 156 | - public function setCookies(array $cookies) { |
|
| 157 | - $this->cookies = $cookies; |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Invalidates the specified cookie |
|
| 164 | - * @param string $name |
|
| 165 | - * @return $this |
|
| 166 | - * @since 8.0.0 |
|
| 167 | - */ |
|
| 168 | - public function invalidateCookie($name) { |
|
| 169 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Invalidates the specified cookies |
|
| 175 | - * @param array $cookieNames array('foo', 'bar') |
|
| 176 | - * @return $this |
|
| 177 | - * @since 8.0.0 |
|
| 178 | - */ |
|
| 179 | - public function invalidateCookies(array $cookieNames) { |
|
| 180 | - foreach($cookieNames as $cookieName) { |
|
| 181 | - $this->invalidateCookie($cookieName); |
|
| 182 | - } |
|
| 183 | - return $this; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns the cookies |
|
| 188 | - * @return array |
|
| 189 | - * @since 8.0.0 |
|
| 190 | - */ |
|
| 191 | - public function getCookies() { |
|
| 192 | - return $this->cookies; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Adds a new header to the response that will be called before the render |
|
| 197 | - * function |
|
| 198 | - * @param string $name The name of the HTTP header |
|
| 199 | - * @param string $value The value, null will delete it |
|
| 200 | - * @return $this |
|
| 201 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 202 | - */ |
|
| 203 | - public function addHeader($name, $value) { |
|
| 204 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 205 | - // to be able to reliably check for security |
|
| 206 | - // headers |
|
| 207 | - |
|
| 208 | - if(is_null($value)) { |
|
| 209 | - unset($this->headers[$name]); |
|
| 210 | - } else { |
|
| 211 | - $this->headers[$name] = $value; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $this; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Set the headers |
|
| 220 | - * @param array $headers value header pairs |
|
| 221 | - * @return $this |
|
| 222 | - * @since 8.0.0 |
|
| 223 | - */ |
|
| 224 | - public function setHeaders(array $headers) { |
|
| 225 | - $this->headers = $headers; |
|
| 226 | - |
|
| 227 | - return $this; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Returns the set headers |
|
| 233 | - * @return array the headers |
|
| 234 | - * @since 6.0.0 |
|
| 235 | - */ |
|
| 236 | - public function getHeaders() { |
|
| 237 | - $mergeWith = []; |
|
| 238 | - |
|
| 239 | - if($this->lastModified) { |
|
| 240 | - $mergeWith['Last-Modified'] = |
|
| 241 | - $this->lastModified->format(\DateTime::RFC2822); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Build Content-Security-Policy and use default if none has been specified |
|
| 245 | - if(is_null($this->contentSecurityPolicy)) { |
|
| 246 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 247 | - } |
|
| 248 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
| 249 | - $this->headers['Feature-Policy'] = $this->featurePolicy->buildPolicy(); |
|
| 250 | - |
|
| 251 | - if($this->ETag) { |
|
| 252 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return array_merge($mergeWith, $this->headers); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * By default renders no output |
|
| 261 | - * @return string |
|
| 262 | - * @since 6.0.0 |
|
| 263 | - */ |
|
| 264 | - public function render() { |
|
| 265 | - return ''; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Set response status |
|
| 271 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
| 272 | - * @return Response Reference to this object |
|
| 273 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 274 | - */ |
|
| 275 | - public function setStatus($status) { |
|
| 276 | - $this->status = $status; |
|
| 277 | - |
|
| 278 | - return $this; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Set a Content-Security-Policy |
|
| 283 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
| 284 | - * @return $this |
|
| 285 | - * @since 8.1.0 |
|
| 286 | - */ |
|
| 287 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
| 288 | - $this->contentSecurityPolicy = $csp; |
|
| 289 | - return $this; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Get the currently used Content-Security-Policy |
|
| 294 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
| 295 | - * none specified. |
|
| 296 | - * @since 8.1.0 |
|
| 297 | - */ |
|
| 298 | - public function getContentSecurityPolicy() { |
|
| 299 | - return $this->contentSecurityPolicy; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * @since 17.0.0 |
|
| 305 | - */ |
|
| 306 | - public function getFeaturePolicy(): EmptyFeaturePolicy { |
|
| 307 | - return $this->featurePolicy; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * @since 17.0.0 |
|
| 312 | - */ |
|
| 313 | - public function setFeaturePolicy(EmptyFeaturePolicy $featurePolicy): self { |
|
| 314 | - $this->featurePolicy = $featurePolicy; |
|
| 315 | - |
|
| 316 | - return $this; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get response status |
|
| 323 | - * @since 6.0.0 |
|
| 324 | - */ |
|
| 325 | - public function getStatus() { |
|
| 326 | - return $this->status; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the ETag |
|
| 332 | - * @return string the etag |
|
| 333 | - * @since 6.0.0 |
|
| 334 | - */ |
|
| 335 | - public function getETag() { |
|
| 336 | - return $this->ETag; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Get "last modified" date |
|
| 342 | - * @return \DateTime RFC2822 formatted last modified date |
|
| 343 | - * @since 6.0.0 |
|
| 344 | - */ |
|
| 345 | - public function getLastModified() { |
|
| 346 | - return $this->lastModified; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Set the ETag |
|
| 352 | - * @param string $ETag |
|
| 353 | - * @return Response Reference to this object |
|
| 354 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 355 | - */ |
|
| 356 | - public function setETag($ETag) { |
|
| 357 | - $this->ETag = $ETag; |
|
| 358 | - |
|
| 359 | - return $this; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Set "last modified" date |
|
| 365 | - * @param \DateTime $lastModified |
|
| 366 | - * @return Response Reference to this object |
|
| 367 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 368 | - */ |
|
| 369 | - public function setLastModified($lastModified) { |
|
| 370 | - $this->lastModified = $lastModified; |
|
| 371 | - |
|
| 372 | - return $this; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Marks the response as to throttle. Will be throttled when the |
|
| 377 | - * @BruteForceProtection annotation is added. |
|
| 378 | - * |
|
| 379 | - * @param array $metadata |
|
| 380 | - * @since 12.0.0 |
|
| 381 | - */ |
|
| 382 | - public function throttle(array $metadata = []) { |
|
| 383 | - $this->throttled = true; |
|
| 384 | - $this->throttleMetadata = $metadata; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Returns the throttle metadata, defaults to empty array |
|
| 389 | - * |
|
| 390 | - * @return array |
|
| 391 | - * @since 13.0.0 |
|
| 392 | - */ |
|
| 393 | - public function getThrottleMetadata() { |
|
| 394 | - return $this->throttleMetadata; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Whether the current response is throttled. |
|
| 399 | - * |
|
| 400 | - * @since 12.0.0 |
|
| 401 | - */ |
|
| 402 | - public function isThrottled() { |
|
| 403 | - return $this->throttled; |
|
| 404 | - } |
|
| 48 | + /** |
|
| 49 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + private $headers = array( |
|
| 53 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Cookies that will be need to be constructed as header |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + private $cookies = array(); |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * HTTP status code - defaults to STATUS OK |
|
| 66 | + * @var int |
|
| 67 | + */ |
|
| 68 | + private $status = Http::STATUS_OK; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Last modified date |
|
| 73 | + * @var \DateTime |
|
| 74 | + */ |
|
| 75 | + private $lastModified; |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * ETag |
|
| 80 | + * @var string |
|
| 81 | + */ |
|
| 82 | + private $ETag; |
|
| 83 | + |
|
| 84 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
| 85 | + private $contentSecurityPolicy = null; |
|
| 86 | + |
|
| 87 | + /** @var FeaturePolicy */ |
|
| 88 | + private $featurePolicy; |
|
| 89 | + |
|
| 90 | + /** @var bool */ |
|
| 91 | + private $throttled = false; |
|
| 92 | + /** @var array */ |
|
| 93 | + private $throttleMetadata = []; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Response constructor. |
|
| 97 | + * |
|
| 98 | + * @since 17.0.0 |
|
| 99 | + */ |
|
| 100 | + public function __construct() { |
|
| 101 | + $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 102 | + $this->setFeaturePolicy(new EmptyFeaturePolicy()); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Caches the response |
|
| 107 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
| 108 | + * if 0 then caching will be disabled |
|
| 109 | + * @return $this |
|
| 110 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 111 | + */ |
|
| 112 | + public function cacheFor(int $cacheSeconds) { |
|
| 113 | + if($cacheSeconds > 0) { |
|
| 114 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 115 | + |
|
| 116 | + // Old scool prama caching |
|
| 117 | + $this->addHeader('Pragma', 'public'); |
|
| 118 | + |
|
| 119 | + // Set expires header |
|
| 120 | + $expires = new \DateTime(); |
|
| 121 | + /** @var ITimeFactory $time */ |
|
| 122 | + $time = \OC::$server->query(ITimeFactory::class); |
|
| 123 | + $expires->setTimestamp($time->getTime()); |
|
| 124 | + $expires->add(new \DateInterval('PT'.$cacheSeconds.'S')); |
|
| 125 | + $this->addHeader('Expires', $expires->format(\DateTime::RFC2822)); |
|
| 126 | + } else { |
|
| 127 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
| 128 | + unset($this->headers['Expires'], $this->headers['Pragma']); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $this; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Adds a new cookie to the response |
|
| 136 | + * @param string $name The name of the cookie |
|
| 137 | + * @param string $value The value of the cookie |
|
| 138 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
| 139 | + * to null cookie will be considered as session |
|
| 140 | + * cookie. |
|
| 141 | + * @return $this |
|
| 142 | + * @since 8.0.0 |
|
| 143 | + */ |
|
| 144 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
| 145 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set the specified cookies |
|
| 152 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
| 153 | + * @return $this |
|
| 154 | + * @since 8.0.0 |
|
| 155 | + */ |
|
| 156 | + public function setCookies(array $cookies) { |
|
| 157 | + $this->cookies = $cookies; |
|
| 158 | + return $this; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Invalidates the specified cookie |
|
| 164 | + * @param string $name |
|
| 165 | + * @return $this |
|
| 166 | + * @since 8.0.0 |
|
| 167 | + */ |
|
| 168 | + public function invalidateCookie($name) { |
|
| 169 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Invalidates the specified cookies |
|
| 175 | + * @param array $cookieNames array('foo', 'bar') |
|
| 176 | + * @return $this |
|
| 177 | + * @since 8.0.0 |
|
| 178 | + */ |
|
| 179 | + public function invalidateCookies(array $cookieNames) { |
|
| 180 | + foreach($cookieNames as $cookieName) { |
|
| 181 | + $this->invalidateCookie($cookieName); |
|
| 182 | + } |
|
| 183 | + return $this; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns the cookies |
|
| 188 | + * @return array |
|
| 189 | + * @since 8.0.0 |
|
| 190 | + */ |
|
| 191 | + public function getCookies() { |
|
| 192 | + return $this->cookies; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Adds a new header to the response that will be called before the render |
|
| 197 | + * function |
|
| 198 | + * @param string $name The name of the HTTP header |
|
| 199 | + * @param string $value The value, null will delete it |
|
| 200 | + * @return $this |
|
| 201 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 202 | + */ |
|
| 203 | + public function addHeader($name, $value) { |
|
| 204 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 205 | + // to be able to reliably check for security |
|
| 206 | + // headers |
|
| 207 | + |
|
| 208 | + if(is_null($value)) { |
|
| 209 | + unset($this->headers[$name]); |
|
| 210 | + } else { |
|
| 211 | + $this->headers[$name] = $value; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $this; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Set the headers |
|
| 220 | + * @param array $headers value header pairs |
|
| 221 | + * @return $this |
|
| 222 | + * @since 8.0.0 |
|
| 223 | + */ |
|
| 224 | + public function setHeaders(array $headers) { |
|
| 225 | + $this->headers = $headers; |
|
| 226 | + |
|
| 227 | + return $this; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Returns the set headers |
|
| 233 | + * @return array the headers |
|
| 234 | + * @since 6.0.0 |
|
| 235 | + */ |
|
| 236 | + public function getHeaders() { |
|
| 237 | + $mergeWith = []; |
|
| 238 | + |
|
| 239 | + if($this->lastModified) { |
|
| 240 | + $mergeWith['Last-Modified'] = |
|
| 241 | + $this->lastModified->format(\DateTime::RFC2822); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Build Content-Security-Policy and use default if none has been specified |
|
| 245 | + if(is_null($this->contentSecurityPolicy)) { |
|
| 246 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 247 | + } |
|
| 248 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
| 249 | + $this->headers['Feature-Policy'] = $this->featurePolicy->buildPolicy(); |
|
| 250 | + |
|
| 251 | + if($this->ETag) { |
|
| 252 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return array_merge($mergeWith, $this->headers); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * By default renders no output |
|
| 261 | + * @return string |
|
| 262 | + * @since 6.0.0 |
|
| 263 | + */ |
|
| 264 | + public function render() { |
|
| 265 | + return ''; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Set response status |
|
| 271 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
| 272 | + * @return Response Reference to this object |
|
| 273 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 274 | + */ |
|
| 275 | + public function setStatus($status) { |
|
| 276 | + $this->status = $status; |
|
| 277 | + |
|
| 278 | + return $this; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Set a Content-Security-Policy |
|
| 283 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
| 284 | + * @return $this |
|
| 285 | + * @since 8.1.0 |
|
| 286 | + */ |
|
| 287 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
| 288 | + $this->contentSecurityPolicy = $csp; |
|
| 289 | + return $this; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Get the currently used Content-Security-Policy |
|
| 294 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
| 295 | + * none specified. |
|
| 296 | + * @since 8.1.0 |
|
| 297 | + */ |
|
| 298 | + public function getContentSecurityPolicy() { |
|
| 299 | + return $this->contentSecurityPolicy; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * @since 17.0.0 |
|
| 305 | + */ |
|
| 306 | + public function getFeaturePolicy(): EmptyFeaturePolicy { |
|
| 307 | + return $this->featurePolicy; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * @since 17.0.0 |
|
| 312 | + */ |
|
| 313 | + public function setFeaturePolicy(EmptyFeaturePolicy $featurePolicy): self { |
|
| 314 | + $this->featurePolicy = $featurePolicy; |
|
| 315 | + |
|
| 316 | + return $this; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get response status |
|
| 323 | + * @since 6.0.0 |
|
| 324 | + */ |
|
| 325 | + public function getStatus() { |
|
| 326 | + return $this->status; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the ETag |
|
| 332 | + * @return string the etag |
|
| 333 | + * @since 6.0.0 |
|
| 334 | + */ |
|
| 335 | + public function getETag() { |
|
| 336 | + return $this->ETag; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Get "last modified" date |
|
| 342 | + * @return \DateTime RFC2822 formatted last modified date |
|
| 343 | + * @since 6.0.0 |
|
| 344 | + */ |
|
| 345 | + public function getLastModified() { |
|
| 346 | + return $this->lastModified; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Set the ETag |
|
| 352 | + * @param string $ETag |
|
| 353 | + * @return Response Reference to this object |
|
| 354 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 355 | + */ |
|
| 356 | + public function setETag($ETag) { |
|
| 357 | + $this->ETag = $ETag; |
|
| 358 | + |
|
| 359 | + return $this; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Set "last modified" date |
|
| 365 | + * @param \DateTime $lastModified |
|
| 366 | + * @return Response Reference to this object |
|
| 367 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 368 | + */ |
|
| 369 | + public function setLastModified($lastModified) { |
|
| 370 | + $this->lastModified = $lastModified; |
|
| 371 | + |
|
| 372 | + return $this; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Marks the response as to throttle. Will be throttled when the |
|
| 377 | + * @BruteForceProtection annotation is added. |
|
| 378 | + * |
|
| 379 | + * @param array $metadata |
|
| 380 | + * @since 12.0.0 |
|
| 381 | + */ |
|
| 382 | + public function throttle(array $metadata = []) { |
|
| 383 | + $this->throttled = true; |
|
| 384 | + $this->throttleMetadata = $metadata; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Returns the throttle metadata, defaults to empty array |
|
| 389 | + * |
|
| 390 | + * @return array |
|
| 391 | + * @since 13.0.0 |
|
| 392 | + */ |
|
| 393 | + public function getThrottleMetadata() { |
|
| 394 | + return $this->throttleMetadata; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Whether the current response is throttled. |
|
| 399 | + * |
|
| 400 | + * @since 12.0.0 |
|
| 401 | + */ |
|
| 402 | + public function isThrottled() { |
|
| 403 | + return $this->throttled; |
|
| 404 | + } |
|
| 405 | 405 | } |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | * @since 6.0.0 - return value was added in 7.0.0 |
| 111 | 111 | */ |
| 112 | 112 | public function cacheFor(int $cacheSeconds) { |
| 113 | - if($cacheSeconds > 0) { |
|
| 114 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
| 113 | + if ($cacheSeconds > 0) { |
|
| 114 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
| 115 | 115 | |
| 116 | 116 | // Old scool prama caching |
| 117 | 117 | $this->addHeader('Pragma', 'public'); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @since 8.0.0 |
| 178 | 178 | */ |
| 179 | 179 | public function invalidateCookies(array $cookieNames) { |
| 180 | - foreach($cookieNames as $cookieName) { |
|
| 180 | + foreach ($cookieNames as $cookieName) { |
|
| 181 | 181 | $this->invalidateCookie($cookieName); |
| 182 | 182 | } |
| 183 | 183 | return $this; |
@@ -201,11 +201,11 @@ discard block |
||
| 201 | 201 | * @since 6.0.0 - return value was added in 7.0.0 |
| 202 | 202 | */ |
| 203 | 203 | public function addHeader($name, $value) { |
| 204 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 204 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 205 | 205 | // to be able to reliably check for security |
| 206 | 206 | // headers |
| 207 | 207 | |
| 208 | - if(is_null($value)) { |
|
| 208 | + if (is_null($value)) { |
|
| 209 | 209 | unset($this->headers[$name]); |
| 210 | 210 | } else { |
| 211 | 211 | $this->headers[$name] = $value; |
@@ -236,20 +236,20 @@ discard block |
||
| 236 | 236 | public function getHeaders() { |
| 237 | 237 | $mergeWith = []; |
| 238 | 238 | |
| 239 | - if($this->lastModified) { |
|
| 239 | + if ($this->lastModified) { |
|
| 240 | 240 | $mergeWith['Last-Modified'] = |
| 241 | 241 | $this->lastModified->format(\DateTime::RFC2822); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // Build Content-Security-Policy and use default if none has been specified |
| 245 | - if(is_null($this->contentSecurityPolicy)) { |
|
| 245 | + if (is_null($this->contentSecurityPolicy)) { |
|
| 246 | 246 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
| 247 | 247 | } |
| 248 | 248 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
| 249 | 249 | $this->headers['Feature-Policy'] = $this->featurePolicy->buildPolicy(); |
| 250 | 250 | |
| 251 | - if($this->ETag) { |
|
| 252 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
| 251 | + if ($this->ETag) { |
|
| 252 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | return array_merge($mergeWith, $this->headers); |
@@ -37,23 +37,23 @@ |
||
| 37 | 37 | * @since 17.0.0 |
| 38 | 38 | */ |
| 39 | 39 | class FeaturePolicy extends EmptyFeaturePolicy { |
| 40 | - protected $autoplayDomains = [ |
|
| 41 | - '\'self\'', |
|
| 42 | - ]; |
|
| 40 | + protected $autoplayDomains = [ |
|
| 41 | + '\'self\'', |
|
| 42 | + ]; |
|
| 43 | 43 | |
| 44 | - /** @var string[] of allowed domains that can access the camera */ |
|
| 45 | - protected $cameraDomains = []; |
|
| 44 | + /** @var string[] of allowed domains that can access the camera */ |
|
| 45 | + protected $cameraDomains = []; |
|
| 46 | 46 | |
| 47 | - protected $fullscreenDomains = [ |
|
| 48 | - '\'self\'', |
|
| 49 | - ]; |
|
| 47 | + protected $fullscreenDomains = [ |
|
| 48 | + '\'self\'', |
|
| 49 | + ]; |
|
| 50 | 50 | |
| 51 | - /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
| 52 | - protected $geolocationDomains = []; |
|
| 51 | + /** @var string[] of allowed domains that can use the geolocation of the device */ |
|
| 52 | + protected $geolocationDomains = []; |
|
| 53 | 53 | |
| 54 | - /** @var string[] of allowed domains that can use the microphone */ |
|
| 55 | - protected $microphoneDomains = []; |
|
| 54 | + /** @var string[] of allowed domains that can use the microphone */ |
|
| 55 | + protected $microphoneDomains = []; |
|
| 56 | 56 | |
| 57 | - /** @var string[] of allowed domains that can use the payment API */ |
|
| 58 | - protected $paymentDomains = []; |
|
| 57 | + /** @var string[] of allowed domains that can use the payment API */ |
|
| 58 | + protected $paymentDomains = []; |
|
| 59 | 59 | } |