@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param string $stream |
| 129 | 129 | * @see http://www.php.net/manual/en/reserved.variables.php |
| 130 | 130 | */ |
| 131 | - public function __construct(array $vars=array(), |
|
| 131 | + public function __construct(array $vars = array(), |
|
| 132 | 132 | ISecureRandom $secureRandom = null, |
| 133 | 133 | IConfig $config, |
| 134 | 134 | CsrfTokenManager $csrfTokenManager = null, |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | $this->config = $config; |
| 140 | 140 | $this->csrfTokenManager = $csrfTokenManager; |
| 141 | 141 | |
| 142 | - if(!array_key_exists('method', $vars)) { |
|
| 142 | + if (!array_key_exists('method', $vars)) { |
|
| 143 | 143 | $vars['method'] = 'GET'; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - foreach($this->allowedKeys as $name) { |
|
| 146 | + foreach ($this->allowedKeys as $name) { |
|
| 147 | 147 | $this->items[$name] = isset($vars[$name]) |
| 148 | 148 | ? $vars[$name] |
| 149 | 149 | : array(); |
@@ -248,12 +248,12 @@ discard block |
||
| 248 | 248 | * @return mixed|null |
| 249 | 249 | */ |
| 250 | 250 | public function __get($name) { |
| 251 | - switch($name) { |
|
| 251 | + switch ($name) { |
|
| 252 | 252 | case 'put': |
| 253 | 253 | case 'patch': |
| 254 | 254 | case 'get': |
| 255 | 255 | case 'post': |
| 256 | - if($this->method !== strtoupper($name)) { |
|
| 256 | + if ($this->method !== strtoupper($name)) { |
|
| 257 | 257 | throw new \LogicException(sprintf('%s cannot be accessed in a %s request.', $name, $this->method)); |
| 258 | 258 | } |
| 259 | 259 | return $this->getContent(); |
@@ -304,14 +304,14 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | public function getHeader($name) { |
| 306 | 306 | |
| 307 | - $name = strtoupper(str_replace(array('-'),array('_'),$name)); |
|
| 308 | - if (isset($this->server['HTTP_' . $name])) { |
|
| 309 | - return $this->server['HTTP_' . $name]; |
|
| 307 | + $name = strtoupper(str_replace(array('-'), array('_'), $name)); |
|
| 308 | + if (isset($this->server['HTTP_'.$name])) { |
|
| 309 | + return $this->server['HTTP_'.$name]; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // There's a few headers that seem to end up in the top-level |
| 313 | 313 | // server array. |
| 314 | - switch($name) { |
|
| 314 | + switch ($name) { |
|
| 315 | 315 | case 'CONTENT_TYPE' : |
| 316 | 316 | case 'CONTENT_LENGTH' : |
| 317 | 317 | if (isset($this->server[$name])) { |
@@ -430,21 +430,21 @@ discard block |
||
| 430 | 430 | // 'application/json' must be decoded manually. |
| 431 | 431 | if (strpos($this->getHeader('Content-Type'), 'application/json') !== false) { |
| 432 | 432 | $params = json_decode(file_get_contents($this->inputStream), true); |
| 433 | - if(count($params) > 0) { |
|
| 433 | + if (count($params) > 0) { |
|
| 434 | 434 | $this->items['params'] = $params; |
| 435 | - if($this->method === 'POST') { |
|
| 435 | + if ($this->method === 'POST') { |
|
| 436 | 436 | $this->items['post'] = $params; |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // Handle application/x-www-form-urlencoded for methods other than GET |
| 441 | 441 | // or post correctly |
| 442 | - } elseif($this->method !== 'GET' |
|
| 442 | + } elseif ($this->method !== 'GET' |
|
| 443 | 443 | && $this->method !== 'POST' |
| 444 | 444 | && strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false) { |
| 445 | 445 | |
| 446 | 446 | parse_str(file_get_contents($this->inputStream), $params); |
| 447 | - if(is_array($params)) { |
|
| 447 | + if (is_array($params)) { |
|
| 448 | 448 | $this->items['params'] = $params; |
| 449 | 449 | } |
| 450 | 450 | } |
@@ -461,11 +461,11 @@ discard block |
||
| 461 | 461 | * @return bool true if CSRF check passed |
| 462 | 462 | */ |
| 463 | 463 | public function passesCSRFCheck() { |
| 464 | - if($this->csrfTokenManager === null) { |
|
| 464 | + if ($this->csrfTokenManager === null) { |
|
| 465 | 465 | return false; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if(!$this->passesStrictCookieCheck()) { |
|
| 468 | + if (!$this->passesStrictCookieCheck()) { |
|
| 469 | 469 | return false; |
| 470 | 470 | } |
| 471 | 471 | |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | if ($this->getHeader('OCS-APIREQUEST')) { |
| 494 | 494 | return false; |
| 495 | 495 | } |
| 496 | - if($this->getCookie(session_name()) === null && $this->getCookie('nc_token') === null) { |
|
| 496 | + if ($this->getCookie(session_name()) === null && $this->getCookie('nc_token') === null) { |
|
| 497 | 497 | return false; |
| 498 | 498 | } |
| 499 | 499 | |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | protected function getProtectedCookieName($name) { |
| 519 | 519 | $cookieParams = $this->getCookieParams(); |
| 520 | 520 | $prefix = ''; |
| 521 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 521 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 522 | 522 | $prefix = '__Host-'; |
| 523 | 523 | } |
| 524 | 524 | |
@@ -533,12 +533,12 @@ discard block |
||
| 533 | 533 | * @since 9.1.0 |
| 534 | 534 | */ |
| 535 | 535 | public function passesStrictCookieCheck() { |
| 536 | - if(!$this->cookieCheckRequired()) { |
|
| 536 | + if (!$this->cookieCheckRequired()) { |
|
| 537 | 537 | return true; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | $cookieName = $this->getProtectedCookieName('nc_sameSiteCookiestrict'); |
| 541 | - if($this->getCookie($cookieName) === 'true' |
|
| 541 | + if ($this->getCookie($cookieName) === 'true' |
|
| 542 | 542 | && $this->passesLaxCookieCheck()) { |
| 543 | 543 | return true; |
| 544 | 544 | } |
@@ -553,12 +553,12 @@ discard block |
||
| 553 | 553 | * @since 9.1.0 |
| 554 | 554 | */ |
| 555 | 555 | public function passesLaxCookieCheck() { |
| 556 | - if(!$this->cookieCheckRequired()) { |
|
| 556 | + if (!$this->cookieCheckRequired()) { |
|
| 557 | 557 | return true; |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | $cookieName = $this->getProtectedCookieName('nc_sameSiteCookielax'); |
| 561 | - if($this->getCookie($cookieName) === 'true') { |
|
| 561 | + if ($this->getCookie($cookieName) === 'true') { |
|
| 562 | 562 | return true; |
| 563 | 563 | } |
| 564 | 564 | return false; |
@@ -571,11 +571,11 @@ discard block |
||
| 571 | 571 | * @return string |
| 572 | 572 | */ |
| 573 | 573 | public function getId() { |
| 574 | - if(isset($this->server['UNIQUE_ID'])) { |
|
| 574 | + if (isset($this->server['UNIQUE_ID'])) { |
|
| 575 | 575 | return $this->server['UNIQUE_ID']; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - if(empty($this->requestId)) { |
|
| 578 | + if (empty($this->requestId)) { |
|
| 579 | 579 | $this->requestId = $this->secureRandom->generate(20); |
| 580 | 580 | } |
| 581 | 581 | |
@@ -593,15 +593,15 @@ discard block |
||
| 593 | 593 | $remoteAddress = isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''; |
| 594 | 594 | $trustedProxies = $this->config->getSystemValue('trusted_proxies', []); |
| 595 | 595 | |
| 596 | - if(is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) { |
|
| 596 | + if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) { |
|
| 597 | 597 | $forwardedForHeaders = $this->config->getSystemValue('forwarded_for_headers', [ |
| 598 | 598 | 'HTTP_X_FORWARDED_FOR' |
| 599 | 599 | // only have one default, so we cannot ship an insecure product out of the box |
| 600 | 600 | ]); |
| 601 | 601 | |
| 602 | - foreach($forwardedForHeaders as $header) { |
|
| 603 | - if(isset($this->server[$header])) { |
|
| 604 | - foreach(explode(',', $this->server[$header]) as $IP) { |
|
| 602 | + foreach ($forwardedForHeaders as $header) { |
|
| 603 | + if (isset($this->server[$header])) { |
|
| 604 | + foreach (explode(',', $this->server[$header]) as $IP) { |
|
| 605 | 605 | $IP = trim($IP); |
| 606 | 606 | if (filter_var($IP, FILTER_VALIDATE_IP) !== false) { |
| 607 | 607 | return $IP; |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | * @return bool |
| 621 | 621 | */ |
| 622 | 622 | private function isOverwriteCondition($type = '') { |
| 623 | - $regex = '/' . $this->config->getSystemValue('overwritecondaddr', '') . '/'; |
|
| 623 | + $regex = '/'.$this->config->getSystemValue('overwritecondaddr', '').'/'; |
|
| 624 | 624 | $remoteAddr = isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : ''; |
| 625 | 625 | return $regex === '//' || preg_match($regex, $remoteAddr) === 1 |
| 626 | 626 | || $type !== 'protocol'; |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | * @return string Server protocol (http or https) |
| 633 | 633 | */ |
| 634 | 634 | public function getServerProtocol() { |
| 635 | - if($this->config->getSystemValue('overwriteprotocol') !== '' |
|
| 635 | + if ($this->config->getSystemValue('overwriteprotocol') !== '' |
|
| 636 | 636 | && $this->isOverwriteCondition('protocol')) { |
| 637 | 637 | return $this->config->getSystemValue('overwriteprotocol'); |
| 638 | 638 | } |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | 'HTTP/2', |
| 675 | 675 | ]; |
| 676 | 676 | |
| 677 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 677 | + if (in_array($claimedProtocol, $validProtocols, true)) { |
|
| 678 | 678 | return $claimedProtocol; |
| 679 | 679 | } |
| 680 | 680 | |
@@ -688,8 +688,8 @@ discard block |
||
| 688 | 688 | */ |
| 689 | 689 | public function getRequestUri() { |
| 690 | 690 | $uri = isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : ''; |
| 691 | - if($this->config->getSystemValue('overwritewebroot') !== '' && $this->isOverwriteCondition()) { |
|
| 692 | - $uri = $this->getScriptName() . substr($uri, strlen($this->server['SCRIPT_NAME'])); |
|
| 691 | + if ($this->config->getSystemValue('overwritewebroot') !== '' && $this->isOverwriteCondition()) { |
|
| 692 | + $uri = $this->getScriptName().substr($uri, strlen($this->server['SCRIPT_NAME'])); |
|
| 693 | 693 | } |
| 694 | 694 | return $uri; |
| 695 | 695 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $requestUri = isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : ''; |
| 704 | 704 | // remove too many leading slashes - can be caused by reverse proxy configuration |
| 705 | 705 | if (strpos($requestUri, '/') === 0) { |
| 706 | - $requestUri = '/' . ltrim($requestUri, '/'); |
|
| 706 | + $requestUri = '/'.ltrim($requestUri, '/'); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | $requestUri = preg_replace('%/{2,}%', '/', $requestUri); |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | // FIXME: Sabre does not really belong here |
| 721 | 721 | list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($scriptName); |
| 722 | 722 | if (!empty($path)) { |
| 723 | - if($path === $pathInfo || strpos($pathInfo, $path.'/') === 0) { |
|
| 723 | + if ($path === $pathInfo || strpos($pathInfo, $path.'/') === 0) { |
|
| 724 | 724 | $pathInfo = substr($pathInfo, strlen($path)); |
| 725 | 725 | } else { |
| 726 | 726 | throw new \Exception("The requested uri($requestUri) cannot be processed by the script '$scriptName')"); |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | if (strpos($pathInfo, $name) === 0) { |
| 733 | 733 | $pathInfo = substr($pathInfo, strlen($name)); |
| 734 | 734 | } |
| 735 | - if($pathInfo === false || $pathInfo === '/'){ |
|
| 735 | + if ($pathInfo === false || $pathInfo === '/') { |
|
| 736 | 736 | return ''; |
| 737 | 737 | } else { |
| 738 | 738 | return $pathInfo; |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | $pathInfo = rawurldecode($pathInfo); |
| 751 | 751 | $encoding = mb_detect_encoding($pathInfo, ['UTF-8', 'ISO-8859-1']); |
| 752 | 752 | |
| 753 | - switch($encoding) { |
|
| 753 | + switch ($encoding) { |
|
| 754 | 754 | case 'ISO-8859-1' : |
| 755 | 755 | $pathInfo = utf8_encode($pathInfo); |
| 756 | 756 | } |
@@ -766,12 +766,12 @@ discard block |
||
| 766 | 766 | */ |
| 767 | 767 | public function getScriptName() { |
| 768 | 768 | $name = $this->server['SCRIPT_NAME']; |
| 769 | - $overwriteWebRoot = $this->config->getSystemValue('overwritewebroot'); |
|
| 769 | + $overwriteWebRoot = $this->config->getSystemValue('overwritewebroot'); |
|
| 770 | 770 | if ($overwriteWebRoot !== '' && $this->isOverwriteCondition()) { |
| 771 | 771 | // FIXME: This code is untestable due to __DIR__, also that hardcoded path is really dangerous |
| 772 | 772 | $serverRoot = str_replace('\\', '/', substr(__DIR__, 0, -strlen('lib/private/appframework/http/'))); |
| 773 | 773 | $suburi = str_replace('\\', '/', substr(realpath($this->server['SCRIPT_FILENAME']), strlen($serverRoot))); |
| 774 | - $name = '/' . ltrim($overwriteWebRoot . $suburi, '/'); |
|
| 774 | + $name = '/'.ltrim($overwriteWebRoot.$suburi, '/'); |
|
| 775 | 775 | } |
| 776 | 776 | return $name; |
| 777 | 777 | } |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | return $host; |
| 842 | 842 | } else { |
| 843 | 843 | $trustedList = $this->config->getSystemValue('trusted_domains', []); |
| 844 | - if(!empty($trustedList)) { |
|
| 844 | + if (!empty($trustedList)) { |
|
| 845 | 845 | return $trustedList[0]; |
| 846 | 846 | } else { |
| 847 | 847 | return ''; |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | * isn't met |
| 857 | 857 | */ |
| 858 | 858 | private function getOverwriteHost() { |
| 859 | - if($this->config->getSystemValue('overwritehost') !== '' && $this->isOverwriteCondition()) { |
|
| 859 | + if ($this->config->getSystemValue('overwritehost') !== '' && $this->isOverwriteCondition()) { |
|
| 860 | 860 | return $this->config->getSystemValue('overwritehost'); |
| 861 | 861 | } |
| 862 | 862 | return null; |