@@ -32,86 +32,86 @@ |
||
| 32 | 32 | use Sabre\DAV\ServerPlugin; |
| 33 | 33 | |
| 34 | 34 | class BrowserErrorPagePlugin extends ServerPlugin { |
| 35 | - /** @var Server */ |
|
| 36 | - private $server; |
|
| 35 | + /** @var Server */ |
|
| 36 | + private $server; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * This initializes the plugin. |
|
| 40 | - * |
|
| 41 | - * This function is called by Sabre\DAV\Server, after |
|
| 42 | - * addPlugin is called. |
|
| 43 | - * |
|
| 44 | - * This method should set up the required event subscriptions. |
|
| 45 | - * |
|
| 46 | - * @param Server $server |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function initialize(Server $server) { |
|
| 50 | - $this->server = $server; |
|
| 51 | - $server->on('exception', array($this, 'logException'), 1000); |
|
| 52 | - } |
|
| 38 | + /** |
|
| 39 | + * This initializes the plugin. |
|
| 40 | + * |
|
| 41 | + * This function is called by Sabre\DAV\Server, after |
|
| 42 | + * addPlugin is called. |
|
| 43 | + * |
|
| 44 | + * This method should set up the required event subscriptions. |
|
| 45 | + * |
|
| 46 | + * @param Server $server |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function initialize(Server $server) { |
|
| 50 | + $this->server = $server; |
|
| 51 | + $server->on('exception', array($this, 'logException'), 1000); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param IRequest $request |
|
| 56 | - * @return bool |
|
| 57 | - */ |
|
| 58 | - public static function isBrowserRequest(IRequest $request) { |
|
| 59 | - if ($request->getMethod() !== 'GET') { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - return $request->isUserAgent([ |
|
| 63 | - Request::USER_AGENT_IE, |
|
| 64 | - Request::USER_AGENT_MS_EDGE, |
|
| 65 | - Request::USER_AGENT_CHROME, |
|
| 66 | - Request::USER_AGENT_FIREFOX, |
|
| 67 | - Request::USER_AGENT_SAFARI, |
|
| 68 | - ]); |
|
| 69 | - } |
|
| 54 | + /** |
|
| 55 | + * @param IRequest $request |
|
| 56 | + * @return bool |
|
| 57 | + */ |
|
| 58 | + public static function isBrowserRequest(IRequest $request) { |
|
| 59 | + if ($request->getMethod() !== 'GET') { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + return $request->isUserAgent([ |
|
| 63 | + Request::USER_AGENT_IE, |
|
| 64 | + Request::USER_AGENT_MS_EDGE, |
|
| 65 | + Request::USER_AGENT_CHROME, |
|
| 66 | + Request::USER_AGENT_FIREFOX, |
|
| 67 | + Request::USER_AGENT_SAFARI, |
|
| 68 | + ]); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param \Exception $ex |
|
| 73 | - */ |
|
| 74 | - public function logException(\Exception $ex) { |
|
| 75 | - if ($ex instanceof Exception) { |
|
| 76 | - $httpCode = $ex->getHTTPCode(); |
|
| 77 | - $headers = $ex->getHTTPHeaders($this->server); |
|
| 78 | - } else { |
|
| 79 | - $httpCode = 500; |
|
| 80 | - $headers = []; |
|
| 81 | - } |
|
| 82 | - $this->server->httpResponse->addHeaders($headers); |
|
| 83 | - $this->server->httpResponse->setStatus($httpCode); |
|
| 84 | - $body = $this->generateBody($httpCode); |
|
| 85 | - $this->server->httpResponse->setBody($body); |
|
| 86 | - $csp = new ContentSecurityPolicy(); |
|
| 87 | - $this->server->httpResponse->addHeader('Content-Security-Policy', $csp->buildPolicy()); |
|
| 88 | - $this->sendResponse(); |
|
| 89 | - } |
|
| 71 | + /** |
|
| 72 | + * @param \Exception $ex |
|
| 73 | + */ |
|
| 74 | + public function logException(\Exception $ex) { |
|
| 75 | + if ($ex instanceof Exception) { |
|
| 76 | + $httpCode = $ex->getHTTPCode(); |
|
| 77 | + $headers = $ex->getHTTPHeaders($this->server); |
|
| 78 | + } else { |
|
| 79 | + $httpCode = 500; |
|
| 80 | + $headers = []; |
|
| 81 | + } |
|
| 82 | + $this->server->httpResponse->addHeaders($headers); |
|
| 83 | + $this->server->httpResponse->setStatus($httpCode); |
|
| 84 | + $body = $this->generateBody($httpCode); |
|
| 85 | + $this->server->httpResponse->setBody($body); |
|
| 86 | + $csp = new ContentSecurityPolicy(); |
|
| 87 | + $this->server->httpResponse->addHeader('Content-Security-Policy', $csp->buildPolicy()); |
|
| 88 | + $this->sendResponse(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @codeCoverageIgnore |
|
| 93 | - * @return bool|string |
|
| 94 | - */ |
|
| 95 | - public function generateBody(int $httpCode) { |
|
| 96 | - $request = \OC::$server->getRequest(); |
|
| 91 | + /** |
|
| 92 | + * @codeCoverageIgnore |
|
| 93 | + * @return bool|string |
|
| 94 | + */ |
|
| 95 | + public function generateBody(int $httpCode) { |
|
| 96 | + $request = \OC::$server->getRequest(); |
|
| 97 | 97 | |
| 98 | - $templateName = 'exception'; |
|
| 99 | - if($httpCode === 403 || $httpCode === 404) { |
|
| 100 | - $templateName = (string)$httpCode; |
|
| 101 | - } |
|
| 98 | + $templateName = 'exception'; |
|
| 99 | + if($httpCode === 403 || $httpCode === 404) { |
|
| 100 | + $templateName = (string)$httpCode; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $content = new OC_Template('core', $templateName, 'guest'); |
|
| 104 | - $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 105 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 106 | - $content->assign('requestID', $request->getId()); |
|
| 107 | - return $content->fetchPage(); |
|
| 108 | - } |
|
| 103 | + $content = new OC_Template('core', $templateName, 'guest'); |
|
| 104 | + $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 105 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 106 | + $content->assign('requestID', $request->getId()); |
|
| 107 | + return $content->fetchPage(); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @codeCoverageIgnore |
|
| 112 | - */ |
|
| 113 | - public function sendResponse() { |
|
| 114 | - $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 115 | - exit(); |
|
| 116 | - } |
|
| 110 | + /** |
|
| 111 | + * @codeCoverageIgnore |
|
| 112 | + */ |
|
| 113 | + public function sendResponse() { |
|
| 114 | + $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 115 | + exit(); |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -96,8 +96,8 @@ |
||
| 96 | 96 | $request = \OC::$server->getRequest(); |
| 97 | 97 | |
| 98 | 98 | $templateName = 'exception'; |
| 99 | - if($httpCode === 403 || $httpCode === 404) { |
|
| 100 | - $templateName = (string)$httpCode; |
|
| 99 | + if ($httpCode === 403 || $httpCode === 404) { |
|
| 100 | + $templateName = (string) $httpCode; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $content = new OC_Template('core', $templateName, 'guest'); |