@@ -9,209 +9,209 @@ |
||
| 9 | 9 | require __DIR__ . '/../../vendor/autoload.php'; |
| 10 | 10 | |
| 11 | 11 | trait Avatar { |
| 12 | - /** @var string * */ |
|
| 13 | - private $lastAvatar; |
|
| 14 | - |
|
| 15 | - /** @AfterScenario **/ |
|
| 16 | - public function cleanupLastAvatar() { |
|
| 17 | - $this->lastAvatar = null; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - private function getLastAvatar() { |
|
| 21 | - $this->lastAvatar = ''; |
|
| 22 | - |
|
| 23 | - $body = $this->response->getBody(); |
|
| 24 | - while (!$body->eof()) { |
|
| 25 | - $this->lastAvatar .= $body->read(8192); |
|
| 26 | - } |
|
| 27 | - $body->close(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @When user :user gets avatar for user :userAvatar |
|
| 32 | - * |
|
| 33 | - * @param string $user |
|
| 34 | - * @param string $userAvatar |
|
| 35 | - */ |
|
| 36 | - public function userGetsAvatarForUser(string $user, string $userAvatar) { |
|
| 37 | - $this->userGetsAvatarForUserWithSize($user, $userAvatar, '128'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @When user :user gets avatar for user :userAvatar with size :size |
|
| 42 | - * |
|
| 43 | - * @param string $user |
|
| 44 | - * @param string $userAvatar |
|
| 45 | - * @param string $size |
|
| 46 | - */ |
|
| 47 | - public function userGetsAvatarForUserWithSize(string $user, string $userAvatar, string $size) { |
|
| 48 | - $this->asAn($user); |
|
| 49 | - $this->sendingToDirectUrl('GET', '/index.php/avatar/' . $userAvatar . '/' . $size); |
|
| 50 | - $this->theHTTPStatusCodeShouldBe('200'); |
|
| 51 | - |
|
| 52 | - $this->getLastAvatar(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @When user :user gets avatar for guest :guestAvatar |
|
| 57 | - * |
|
| 58 | - * @param string $user |
|
| 59 | - * @param string $guestAvatar |
|
| 60 | - */ |
|
| 61 | - public function userGetsAvatarForGuest(string $user, string $guestAvatar) { |
|
| 62 | - $this->asAn($user); |
|
| 63 | - $this->sendingToDirectUrl('GET', '/index.php/avatar/guest/' . $guestAvatar . '/128'); |
|
| 64 | - $this->theHTTPStatusCodeShouldBe('201'); |
|
| 65 | - |
|
| 66 | - $this->getLastAvatar(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @When logged in user posts avatar from file :source |
|
| 71 | - * |
|
| 72 | - * @param string $source |
|
| 73 | - */ |
|
| 74 | - public function loggedInUserPostsAvatarFromFile(string $source) { |
|
| 75 | - $file = \GuzzleHttp\Psr7\Utils::streamFor(fopen($source, 'r')); |
|
| 76 | - |
|
| 77 | - $this->sendingAToWithRequesttoken('POST', '/index.php/avatar', |
|
| 78 | - [ |
|
| 79 | - 'multipart' => [ |
|
| 80 | - [ |
|
| 81 | - 'name' => 'files[]', |
|
| 82 | - 'contents' => $file |
|
| 83 | - ] |
|
| 84 | - ] |
|
| 85 | - ]); |
|
| 86 | - $this->theHTTPStatusCodeShouldBe('200'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @When logged in user posts avatar from internal path :path |
|
| 91 | - * |
|
| 92 | - * @param string $path |
|
| 93 | - */ |
|
| 94 | - public function loggedInUserPostsAvatarFromInternalPath(string $path) { |
|
| 95 | - $this->sendingAToWithRequesttoken('POST', '/index.php/avatar?path=' . $path); |
|
| 96 | - $this->theHTTPStatusCodeShouldBe('200'); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @When logged in user deletes the user avatar |
|
| 101 | - */ |
|
| 102 | - public function loggedInUserDeletesTheUserAvatar() { |
|
| 103 | - $this->sendingAToWithRequesttoken('DELETE', '/index.php/avatar'); |
|
| 104 | - $this->theHTTPStatusCodeShouldBe('200'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @Then last avatar is a square of size :size |
|
| 109 | - * |
|
| 110 | - * @param string size |
|
| 111 | - */ |
|
| 112 | - public function lastAvatarIsASquareOfSize(string $size) { |
|
| 113 | - [$width, $height] = getimagesizefromstring($this->lastAvatar); |
|
| 114 | - |
|
| 115 | - Assert::assertEquals($width, $height, 'Expected avatar to be a square'); |
|
| 116 | - Assert::assertEquals($size, $width); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @Then last avatar is not a square |
|
| 121 | - */ |
|
| 122 | - public function lastAvatarIsNotASquare() { |
|
| 123 | - [$width, $height] = getimagesizefromstring($this->lastAvatar); |
|
| 124 | - |
|
| 125 | - Assert::assertNotEquals($width, $height, 'Expected avatar to not be a square'); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @Then last avatar is not a single color |
|
| 130 | - */ |
|
| 131 | - public function lastAvatarIsNotASingleColor() { |
|
| 132 | - Assert::assertEquals(null, $this->getColorFromLastAvatar()); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @Then last avatar is a single :color color |
|
| 137 | - * |
|
| 138 | - * @param string $color |
|
| 139 | - * @param string $size |
|
| 140 | - */ |
|
| 141 | - public function lastAvatarIsASingleColor(string $color) { |
|
| 142 | - $expectedColor = $this->hexStringToRgbColor($color); |
|
| 143 | - $colorFromLastAvatar = $this->getColorFromLastAvatar(); |
|
| 144 | - |
|
| 145 | - Assert::assertTrue($this->isSameColor($expectedColor, $colorFromLastAvatar), |
|
| 146 | - $this->rgbColorToHexString($colorFromLastAvatar) . ' does not match expected ' . $color); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - private function hexStringToRgbColor($hexString) { |
|
| 150 | - // Strip initial "#" |
|
| 151 | - $hexString = substr($hexString, 1); |
|
| 152 | - |
|
| 153 | - $rgbColorInt = hexdec($hexString); |
|
| 154 | - |
|
| 155 | - // RGBA hex strings are not supported; the given string is assumed to be |
|
| 156 | - // an RGB hex string. |
|
| 157 | - return [ |
|
| 158 | - 'red' => ($rgbColorInt >> 16) & 0xFF, |
|
| 159 | - 'green' => ($rgbColorInt >> 8) & 0xFF, |
|
| 160 | - 'blue' => $rgbColorInt & 0xFF, |
|
| 161 | - 'alpha' => 0 |
|
| 162 | - ]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - private function rgbColorToHexString($rgbColor) { |
|
| 166 | - $rgbColorInt = ($rgbColor['red'] << 16) + ($rgbColor['green'] << 8) + ($rgbColor['blue']); |
|
| 167 | - |
|
| 168 | - return '#' . str_pad(strtoupper(dechex($rgbColorInt)), 6, '0', STR_PAD_LEFT); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - private function getColorFromLastAvatar() { |
|
| 172 | - $image = imagecreatefromstring($this->lastAvatar); |
|
| 173 | - |
|
| 174 | - $firstPixelColorIndex = imagecolorat($image, 0, 0); |
|
| 175 | - $firstPixelColor = imagecolorsforindex($image, $firstPixelColorIndex); |
|
| 176 | - |
|
| 177 | - for ($i = 0; $i < imagesx($image); $i++) { |
|
| 178 | - for ($j = 0; $j < imagesx($image); $j++) { |
|
| 179 | - $currentPixelColorIndex = imagecolorat($image, $i, $j); |
|
| 180 | - $currentPixelColor = imagecolorsforindex($image, $currentPixelColorIndex); |
|
| 181 | - |
|
| 182 | - // The colors are compared with a small allowed delta, as even |
|
| 183 | - // on solid color images the resizing can cause some small |
|
| 184 | - // artifacts that slightly modify the color of certain pixels. |
|
| 185 | - if (!$this->isSameColor($firstPixelColor, $currentPixelColor)) { |
|
| 186 | - imagedestroy($image); |
|
| 187 | - |
|
| 188 | - return null; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - imagedestroy($image); |
|
| 194 | - |
|
| 195 | - return $firstPixelColor; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - private function isSameColor(array $firstColor, array $secondColor, int $allowedDelta = 1) { |
|
| 199 | - if ($this->isSameColorComponent($firstColor['red'], $secondColor['red'], $allowedDelta) |
|
| 200 | - && $this->isSameColorComponent($firstColor['green'], $secondColor['green'], $allowedDelta) |
|
| 201 | - && $this->isSameColorComponent($firstColor['blue'], $secondColor['blue'], $allowedDelta) |
|
| 202 | - && $this->isSameColorComponent($firstColor['alpha'], $secondColor['alpha'], $allowedDelta)) { |
|
| 203 | - return true; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - private function isSameColorComponent(int $firstColorComponent, int $secondColorComponent, int $allowedDelta) { |
|
| 210 | - if ($firstColorComponent >= ($secondColorComponent - $allowedDelta) |
|
| 211 | - && $firstColorComponent <= ($secondColorComponent + $allowedDelta)) { |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 12 | + /** @var string * */ |
|
| 13 | + private $lastAvatar; |
|
| 14 | + |
|
| 15 | + /** @AfterScenario **/ |
|
| 16 | + public function cleanupLastAvatar() { |
|
| 17 | + $this->lastAvatar = null; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + private function getLastAvatar() { |
|
| 21 | + $this->lastAvatar = ''; |
|
| 22 | + |
|
| 23 | + $body = $this->response->getBody(); |
|
| 24 | + while (!$body->eof()) { |
|
| 25 | + $this->lastAvatar .= $body->read(8192); |
|
| 26 | + } |
|
| 27 | + $body->close(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @When user :user gets avatar for user :userAvatar |
|
| 32 | + * |
|
| 33 | + * @param string $user |
|
| 34 | + * @param string $userAvatar |
|
| 35 | + */ |
|
| 36 | + public function userGetsAvatarForUser(string $user, string $userAvatar) { |
|
| 37 | + $this->userGetsAvatarForUserWithSize($user, $userAvatar, '128'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @When user :user gets avatar for user :userAvatar with size :size |
|
| 42 | + * |
|
| 43 | + * @param string $user |
|
| 44 | + * @param string $userAvatar |
|
| 45 | + * @param string $size |
|
| 46 | + */ |
|
| 47 | + public function userGetsAvatarForUserWithSize(string $user, string $userAvatar, string $size) { |
|
| 48 | + $this->asAn($user); |
|
| 49 | + $this->sendingToDirectUrl('GET', '/index.php/avatar/' . $userAvatar . '/' . $size); |
|
| 50 | + $this->theHTTPStatusCodeShouldBe('200'); |
|
| 51 | + |
|
| 52 | + $this->getLastAvatar(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @When user :user gets avatar for guest :guestAvatar |
|
| 57 | + * |
|
| 58 | + * @param string $user |
|
| 59 | + * @param string $guestAvatar |
|
| 60 | + */ |
|
| 61 | + public function userGetsAvatarForGuest(string $user, string $guestAvatar) { |
|
| 62 | + $this->asAn($user); |
|
| 63 | + $this->sendingToDirectUrl('GET', '/index.php/avatar/guest/' . $guestAvatar . '/128'); |
|
| 64 | + $this->theHTTPStatusCodeShouldBe('201'); |
|
| 65 | + |
|
| 66 | + $this->getLastAvatar(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @When logged in user posts avatar from file :source |
|
| 71 | + * |
|
| 72 | + * @param string $source |
|
| 73 | + */ |
|
| 74 | + public function loggedInUserPostsAvatarFromFile(string $source) { |
|
| 75 | + $file = \GuzzleHttp\Psr7\Utils::streamFor(fopen($source, 'r')); |
|
| 76 | + |
|
| 77 | + $this->sendingAToWithRequesttoken('POST', '/index.php/avatar', |
|
| 78 | + [ |
|
| 79 | + 'multipart' => [ |
|
| 80 | + [ |
|
| 81 | + 'name' => 'files[]', |
|
| 82 | + 'contents' => $file |
|
| 83 | + ] |
|
| 84 | + ] |
|
| 85 | + ]); |
|
| 86 | + $this->theHTTPStatusCodeShouldBe('200'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @When logged in user posts avatar from internal path :path |
|
| 91 | + * |
|
| 92 | + * @param string $path |
|
| 93 | + */ |
|
| 94 | + public function loggedInUserPostsAvatarFromInternalPath(string $path) { |
|
| 95 | + $this->sendingAToWithRequesttoken('POST', '/index.php/avatar?path=' . $path); |
|
| 96 | + $this->theHTTPStatusCodeShouldBe('200'); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @When logged in user deletes the user avatar |
|
| 101 | + */ |
|
| 102 | + public function loggedInUserDeletesTheUserAvatar() { |
|
| 103 | + $this->sendingAToWithRequesttoken('DELETE', '/index.php/avatar'); |
|
| 104 | + $this->theHTTPStatusCodeShouldBe('200'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @Then last avatar is a square of size :size |
|
| 109 | + * |
|
| 110 | + * @param string size |
|
| 111 | + */ |
|
| 112 | + public function lastAvatarIsASquareOfSize(string $size) { |
|
| 113 | + [$width, $height] = getimagesizefromstring($this->lastAvatar); |
|
| 114 | + |
|
| 115 | + Assert::assertEquals($width, $height, 'Expected avatar to be a square'); |
|
| 116 | + Assert::assertEquals($size, $width); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @Then last avatar is not a square |
|
| 121 | + */ |
|
| 122 | + public function lastAvatarIsNotASquare() { |
|
| 123 | + [$width, $height] = getimagesizefromstring($this->lastAvatar); |
|
| 124 | + |
|
| 125 | + Assert::assertNotEquals($width, $height, 'Expected avatar to not be a square'); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @Then last avatar is not a single color |
|
| 130 | + */ |
|
| 131 | + public function lastAvatarIsNotASingleColor() { |
|
| 132 | + Assert::assertEquals(null, $this->getColorFromLastAvatar()); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @Then last avatar is a single :color color |
|
| 137 | + * |
|
| 138 | + * @param string $color |
|
| 139 | + * @param string $size |
|
| 140 | + */ |
|
| 141 | + public function lastAvatarIsASingleColor(string $color) { |
|
| 142 | + $expectedColor = $this->hexStringToRgbColor($color); |
|
| 143 | + $colorFromLastAvatar = $this->getColorFromLastAvatar(); |
|
| 144 | + |
|
| 145 | + Assert::assertTrue($this->isSameColor($expectedColor, $colorFromLastAvatar), |
|
| 146 | + $this->rgbColorToHexString($colorFromLastAvatar) . ' does not match expected ' . $color); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + private function hexStringToRgbColor($hexString) { |
|
| 150 | + // Strip initial "#" |
|
| 151 | + $hexString = substr($hexString, 1); |
|
| 152 | + |
|
| 153 | + $rgbColorInt = hexdec($hexString); |
|
| 154 | + |
|
| 155 | + // RGBA hex strings are not supported; the given string is assumed to be |
|
| 156 | + // an RGB hex string. |
|
| 157 | + return [ |
|
| 158 | + 'red' => ($rgbColorInt >> 16) & 0xFF, |
|
| 159 | + 'green' => ($rgbColorInt >> 8) & 0xFF, |
|
| 160 | + 'blue' => $rgbColorInt & 0xFF, |
|
| 161 | + 'alpha' => 0 |
|
| 162 | + ]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + private function rgbColorToHexString($rgbColor) { |
|
| 166 | + $rgbColorInt = ($rgbColor['red'] << 16) + ($rgbColor['green'] << 8) + ($rgbColor['blue']); |
|
| 167 | + |
|
| 168 | + return '#' . str_pad(strtoupper(dechex($rgbColorInt)), 6, '0', STR_PAD_LEFT); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + private function getColorFromLastAvatar() { |
|
| 172 | + $image = imagecreatefromstring($this->lastAvatar); |
|
| 173 | + |
|
| 174 | + $firstPixelColorIndex = imagecolorat($image, 0, 0); |
|
| 175 | + $firstPixelColor = imagecolorsforindex($image, $firstPixelColorIndex); |
|
| 176 | + |
|
| 177 | + for ($i = 0; $i < imagesx($image); $i++) { |
|
| 178 | + for ($j = 0; $j < imagesx($image); $j++) { |
|
| 179 | + $currentPixelColorIndex = imagecolorat($image, $i, $j); |
|
| 180 | + $currentPixelColor = imagecolorsforindex($image, $currentPixelColorIndex); |
|
| 181 | + |
|
| 182 | + // The colors are compared with a small allowed delta, as even |
|
| 183 | + // on solid color images the resizing can cause some small |
|
| 184 | + // artifacts that slightly modify the color of certain pixels. |
|
| 185 | + if (!$this->isSameColor($firstPixelColor, $currentPixelColor)) { |
|
| 186 | + imagedestroy($image); |
|
| 187 | + |
|
| 188 | + return null; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + imagedestroy($image); |
|
| 194 | + |
|
| 195 | + return $firstPixelColor; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + private function isSameColor(array $firstColor, array $secondColor, int $allowedDelta = 1) { |
|
| 199 | + if ($this->isSameColorComponent($firstColor['red'], $secondColor['red'], $allowedDelta) |
|
| 200 | + && $this->isSameColorComponent($firstColor['green'], $secondColor['green'], $allowedDelta) |
|
| 201 | + && $this->isSameColorComponent($firstColor['blue'], $secondColor['blue'], $allowedDelta) |
|
| 202 | + && $this->isSameColorComponent($firstColor['alpha'], $secondColor['alpha'], $allowedDelta)) { |
|
| 203 | + return true; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + private function isSameColorComponent(int $firstColorComponent, int $secondColorComponent, int $allowedDelta) { |
|
| 210 | + if ($firstColorComponent >= ($secondColorComponent - $allowedDelta) |
|
| 211 | + && $firstColorComponent <= ($secondColorComponent + $allowedDelta)) { |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -249,1452 +249,1452 @@ |
||
| 249 | 249 | * TODO: hookup all manager classes |
| 250 | 250 | */ |
| 251 | 251 | class Server extends ServerContainer implements IServerContainer { |
| 252 | - /** @var string */ |
|
| 253 | - private $webRoot; |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param string $webRoot |
|
| 257 | - * @param \OC\Config $config |
|
| 258 | - */ |
|
| 259 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | - parent::__construct(); |
|
| 261 | - $this->webRoot = $webRoot; |
|
| 262 | - |
|
| 263 | - // To find out if we are running from CLI or not |
|
| 264 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | - |
|
| 267 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | - return $c; |
|
| 269 | - }); |
|
| 270 | - $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | - |
|
| 272 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | - |
|
| 274 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | - |
|
| 276 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | - |
|
| 278 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | - |
|
| 280 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 281 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 282 | - $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 283 | - |
|
| 284 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 285 | - |
|
| 286 | - $this->registerService(View::class, function (Server $c) { |
|
| 287 | - return new View(); |
|
| 288 | - }, false); |
|
| 289 | - |
|
| 290 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 291 | - return new PreviewManager( |
|
| 292 | - $c->get(\OCP\IConfig::class), |
|
| 293 | - $c->get(IRootFolder::class), |
|
| 294 | - new \OC\Preview\Storage\Root( |
|
| 295 | - $c->get(IRootFolder::class), |
|
| 296 | - $c->get(SystemConfig::class) |
|
| 297 | - ), |
|
| 298 | - $c->get(IEventDispatcher::class), |
|
| 299 | - $c->get(GeneratorHelper::class), |
|
| 300 | - $c->get(ISession::class)->get('user_id'), |
|
| 301 | - $c->get(Coordinator::class), |
|
| 302 | - $c->get(IServerContainer::class), |
|
| 303 | - $c->get(IBinaryFinder::class), |
|
| 304 | - $c->get(IMagickSupport::class) |
|
| 305 | - ); |
|
| 306 | - }); |
|
| 307 | - $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 308 | - |
|
| 309 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 310 | - return new \OC\Preview\Watcher( |
|
| 311 | - new \OC\Preview\Storage\Root( |
|
| 312 | - $c->get(IRootFolder::class), |
|
| 313 | - $c->get(SystemConfig::class) |
|
| 314 | - ) |
|
| 315 | - ); |
|
| 316 | - }); |
|
| 317 | - |
|
| 318 | - $this->registerService(IProfiler::class, function (Server $c) { |
|
| 319 | - return new Profiler($c->get(SystemConfig::class)); |
|
| 320 | - }); |
|
| 321 | - |
|
| 322 | - $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 323 | - $view = new View(); |
|
| 324 | - $util = new Encryption\Util( |
|
| 325 | - $view, |
|
| 326 | - $c->get(IUserManager::class), |
|
| 327 | - $c->get(IGroupManager::class), |
|
| 328 | - $c->get(\OCP\IConfig::class) |
|
| 329 | - ); |
|
| 330 | - return new Encryption\Manager( |
|
| 331 | - $c->get(\OCP\IConfig::class), |
|
| 332 | - $c->get(LoggerInterface::class), |
|
| 333 | - $c->getL10N('core'), |
|
| 334 | - new View(), |
|
| 335 | - $util, |
|
| 336 | - new ArrayCache() |
|
| 337 | - ); |
|
| 338 | - }); |
|
| 339 | - $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 340 | - |
|
| 341 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | - $util = new Encryption\Util( |
|
| 343 | - new View(), |
|
| 344 | - $c->get(IUserManager::class), |
|
| 345 | - $c->get(IGroupManager::class), |
|
| 346 | - $c->get(\OCP\IConfig::class) |
|
| 347 | - ); |
|
| 348 | - return new Encryption\File( |
|
| 349 | - $util, |
|
| 350 | - $c->get(IRootFolder::class), |
|
| 351 | - $c->get(\OCP\Share\IManager::class) |
|
| 352 | - ); |
|
| 353 | - }); |
|
| 354 | - |
|
| 355 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | - $view = new View(); |
|
| 357 | - $util = new Encryption\Util( |
|
| 358 | - $view, |
|
| 359 | - $c->get(IUserManager::class), |
|
| 360 | - $c->get(IGroupManager::class), |
|
| 361 | - $c->get(\OCP\IConfig::class) |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - return new Encryption\Keys\Storage( |
|
| 365 | - $view, |
|
| 366 | - $util, |
|
| 367 | - $c->get(ICrypto::class), |
|
| 368 | - $c->get(\OCP\IConfig::class) |
|
| 369 | - ); |
|
| 370 | - }); |
|
| 371 | - |
|
| 372 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | - |
|
| 374 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | - /** @var \OCP\IConfig $config */ |
|
| 376 | - $config = $c->get(\OCP\IConfig::class); |
|
| 377 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | - return new $factoryClass($this); |
|
| 379 | - }); |
|
| 380 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | - }); |
|
| 383 | - /** @deprecated 19.0.0 */ |
|
| 384 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | - |
|
| 386 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | - }); |
|
| 389 | - $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | - $view = new View(); |
|
| 393 | - /** @var IUserSession $userSession */ |
|
| 394 | - $userSession = $c->get(IUserSession::class); |
|
| 395 | - $root = new Root( |
|
| 396 | - $manager, |
|
| 397 | - $view, |
|
| 398 | - $userSession->getUser(), |
|
| 399 | - $c->get(IUserMountCache::class), |
|
| 400 | - $this->get(LoggerInterface::class), |
|
| 401 | - $this->get(IUserManager::class), |
|
| 402 | - $this->get(IEventDispatcher::class), |
|
| 403 | - $this->get(ICacheFactory::class), |
|
| 404 | - ); |
|
| 405 | - |
|
| 406 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | - $root, |
|
| 408 | - $c->get(SystemConfig::class), |
|
| 409 | - $this->get(IEventDispatcher::class) |
|
| 410 | - ); |
|
| 411 | - $previewConnector->connectWatcher(); |
|
| 412 | - |
|
| 413 | - return $root; |
|
| 414 | - }); |
|
| 415 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | - return new HookConnector( |
|
| 417 | - $c->get(IRootFolder::class), |
|
| 418 | - new View(), |
|
| 419 | - $c->get(IEventDispatcher::class), |
|
| 420 | - $c->get(LoggerInterface::class) |
|
| 421 | - ); |
|
| 422 | - }); |
|
| 423 | - |
|
| 424 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | - return new LazyRoot(function () use ($c) { |
|
| 426 | - return $c->get('RootFolder'); |
|
| 427 | - }); |
|
| 428 | - }); |
|
| 429 | - |
|
| 430 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | - |
|
| 432 | - $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | - return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | - }); |
|
| 435 | - |
|
| 436 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | - $groupManager = new \OC\Group\Manager( |
|
| 438 | - $this->get(IUserManager::class), |
|
| 439 | - $this->get(IEventDispatcher::class), |
|
| 440 | - $this->get(LoggerInterface::class), |
|
| 441 | - $this->get(ICacheFactory::class), |
|
| 442 | - $this->get(IRemoteAddress::class), |
|
| 443 | - ); |
|
| 444 | - return $groupManager; |
|
| 445 | - }); |
|
| 446 | - |
|
| 447 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | - $session = $c->get(ISession::class); |
|
| 449 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | - $tokenProvider = $c->get(IProvider::class); |
|
| 451 | - } else { |
|
| 452 | - $tokenProvider = null; |
|
| 453 | - } |
|
| 454 | - $logger = $c->get(LoggerInterface::class); |
|
| 455 | - $crypto = $c->get(ICrypto::class); |
|
| 456 | - return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | - }); |
|
| 458 | - $this->registerAlias(IStore::class, Store::class); |
|
| 459 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | - $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | - |
|
| 462 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | - $manager = $c->get(IUserManager::class); |
|
| 464 | - $session = new \OC\Session\Memory(); |
|
| 465 | - $timeFactory = new TimeFactory(); |
|
| 466 | - // Token providers might require a working database. This code |
|
| 467 | - // might however be called when Nextcloud is not yet setup. |
|
| 468 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | - $provider = $c->get(IProvider::class); |
|
| 470 | - } else { |
|
| 471 | - $provider = null; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $userSession = new \OC\User\Session( |
|
| 475 | - $manager, |
|
| 476 | - $session, |
|
| 477 | - $timeFactory, |
|
| 478 | - $provider, |
|
| 479 | - $c->get(\OCP\IConfig::class), |
|
| 480 | - $c->get(ISecureRandom::class), |
|
| 481 | - $c->get('LockdownManager'), |
|
| 482 | - $c->get(LoggerInterface::class), |
|
| 483 | - $c->get(IEventDispatcher::class), |
|
| 484 | - ); |
|
| 485 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | - }); |
|
| 489 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | - /** @var \OC\User\User $user */ |
|
| 492 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | - }); |
|
| 494 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | - /** @var \OC\User\User $user */ |
|
| 497 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | - }); |
|
| 499 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | - /** @var \OC\User\User $user */ |
|
| 502 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | - }); |
|
| 504 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | - /** @var \OC\User\User $user */ |
|
| 506 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | - }); |
|
| 508 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | - /** @var \OC\User\User $user */ |
|
| 510 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | - }); |
|
| 512 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | - |
|
| 515 | - /** @var IEventDispatcher $dispatcher */ |
|
| 516 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | - }); |
|
| 519 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | - /** @var \OC\User\User $user */ |
|
| 521 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | - |
|
| 523 | - /** @var IEventDispatcher $dispatcher */ |
|
| 524 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | - }); |
|
| 527 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | - /** @var IEventDispatcher $dispatcher */ |
|
| 529 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | - }); |
|
| 532 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | - /** @var \OC\User\User $user */ |
|
| 534 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | - |
|
| 536 | - /** @var IEventDispatcher $dispatcher */ |
|
| 537 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | - }); |
|
| 540 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | - |
|
| 543 | - /** @var IEventDispatcher $dispatcher */ |
|
| 544 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | - }); |
|
| 547 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | - /** @var IEventDispatcher $dispatcher */ |
|
| 549 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | - }); |
|
| 552 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | - /** @var \OC\User\User $user */ |
|
| 554 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | - }); |
|
| 556 | - return $userSession; |
|
| 557 | - }); |
|
| 558 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | - |
|
| 560 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | - |
|
| 562 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | - |
|
| 564 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | - |
|
| 566 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | - return new \OC\SystemConfig($config); |
|
| 568 | - }); |
|
| 569 | - |
|
| 570 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | - $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 573 | - |
|
| 574 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 575 | - return new \OC\L10N\Factory( |
|
| 576 | - $c->get(\OCP\IConfig::class), |
|
| 577 | - $c->getRequest(), |
|
| 578 | - $c->get(IUserSession::class), |
|
| 579 | - $c->get(ICacheFactory::class), |
|
| 580 | - \OC::$SERVERROOT, |
|
| 581 | - $c->get(IAppManager::class), |
|
| 582 | - ); |
|
| 583 | - }); |
|
| 584 | - |
|
| 585 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 586 | - |
|
| 587 | - $this->registerService(ICache::class, function ($c) { |
|
| 588 | - /** @var LoggerInterface $logger */ |
|
| 589 | - $logger = $c->get(LoggerInterface::class); |
|
| 590 | - $logger->debug('The requested service "' . ICache::class . '" is deprecated. Please use "' . ICacheFactory::class . '" instead to create a cache. This service will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 591 | - |
|
| 592 | - /** @var ICacheFactory $cacheFactory */ |
|
| 593 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 594 | - return $cacheFactory->createDistributed(); |
|
| 595 | - }); |
|
| 596 | - |
|
| 597 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 598 | - $profiler = $c->get(IProfiler::class); |
|
| 599 | - $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 600 | - $profiler, |
|
| 601 | - ArrayCache::class, |
|
| 602 | - ArrayCache::class, |
|
| 603 | - ArrayCache::class |
|
| 604 | - ); |
|
| 605 | - /** @var SystemConfig $config */ |
|
| 606 | - $config = $c->get(SystemConfig::class); |
|
| 607 | - /** @var ServerVersion $serverVersion */ |
|
| 608 | - $serverVersion = $c->get(ServerVersion::class); |
|
| 609 | - |
|
| 610 | - if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 611 | - $logQuery = $config->getValue('log_query'); |
|
| 612 | - $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 613 | - if (!$logQuery) { |
|
| 614 | - try { |
|
| 615 | - $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(true); |
|
| 616 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
| 617 | - // Database service probably unavailable |
|
| 618 | - // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 619 | - return null; |
|
| 620 | - } |
|
| 621 | - } else { |
|
| 622 | - // If the log_query is enabled, we can not get the app versions |
|
| 623 | - // as that does a query, which will be logged and the logging |
|
| 624 | - // depends on redis and here we are back again in the same function. |
|
| 625 | - $v = [ |
|
| 626 | - 'log_query' => 'enabled', |
|
| 627 | - ]; |
|
| 628 | - } |
|
| 629 | - $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 630 | - $version = implode(',', array_keys($v)) . implode(',', $v); |
|
| 631 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 632 | - $path = \OC::$SERVERROOT; |
|
| 633 | - return md5($instanceId . '-' . $version . '-' . $path); |
|
| 634 | - }; |
|
| 635 | - return new \OC\Memcache\Factory($prefixClosure, |
|
| 636 | - $c->get(LoggerInterface::class), |
|
| 637 | - $profiler, |
|
| 638 | - /** @psalm-taint-escape callable */ |
|
| 639 | - $config->getValue('memcache.local', null), |
|
| 640 | - /** @psalm-taint-escape callable */ |
|
| 641 | - $config->getValue('memcache.distributed', null), |
|
| 642 | - /** @psalm-taint-escape callable */ |
|
| 643 | - $config->getValue('memcache.locking', null), |
|
| 644 | - /** @psalm-taint-escape callable */ |
|
| 645 | - $config->getValue('redis_log_file') |
|
| 646 | - ); |
|
| 647 | - } |
|
| 648 | - return $arrayCacheFactory; |
|
| 649 | - }); |
|
| 650 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 651 | - |
|
| 652 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 653 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 654 | - return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 655 | - }); |
|
| 656 | - |
|
| 657 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 658 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 659 | - return new \OC\Activity\Manager( |
|
| 660 | - $c->getRequest(), |
|
| 661 | - $c->get(IUserSession::class), |
|
| 662 | - $c->get(\OCP\IConfig::class), |
|
| 663 | - $c->get(IValidator::class), |
|
| 664 | - $c->get(IRichTextFormatter::class), |
|
| 665 | - $l10n |
|
| 666 | - ); |
|
| 667 | - }); |
|
| 668 | - |
|
| 669 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 670 | - return new \OC\Activity\EventMerger( |
|
| 671 | - $c->getL10N('lib') |
|
| 672 | - ); |
|
| 673 | - }); |
|
| 674 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 675 | - |
|
| 676 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 677 | - return new AvatarManager( |
|
| 678 | - $c->get(IUserSession::class), |
|
| 679 | - $c->get(\OC\User\Manager::class), |
|
| 680 | - $c->getAppDataDir('avatar'), |
|
| 681 | - $c->getL10N('lib'), |
|
| 682 | - $c->get(LoggerInterface::class), |
|
| 683 | - $c->get(\OCP\IConfig::class), |
|
| 684 | - $c->get(IAccountManager::class), |
|
| 685 | - $c->get(KnownUserService::class) |
|
| 686 | - ); |
|
| 687 | - }); |
|
| 688 | - |
|
| 689 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 690 | - |
|
| 691 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 692 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 693 | - $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 694 | - |
|
| 695 | - /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 696 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 697 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 698 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 699 | - $logger = $factory->get($logType); |
|
| 700 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 701 | - |
|
| 702 | - return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 703 | - }); |
|
| 704 | - // PSR-3 logger |
|
| 705 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 706 | - |
|
| 707 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 708 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 709 | - }); |
|
| 710 | - |
|
| 711 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 712 | - |
|
| 713 | - $this->registerService(Router::class, function (Server $c) { |
|
| 714 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 715 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 716 | - $router = $c->resolve(CachingRouter::class); |
|
| 717 | - } else { |
|
| 718 | - $router = $c->resolve(Router::class); |
|
| 719 | - } |
|
| 720 | - return $router; |
|
| 721 | - }); |
|
| 722 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 723 | - |
|
| 724 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 725 | - $config = $c->get(\OCP\IConfig::class); |
|
| 726 | - if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 727 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 728 | - $c->get(AllConfig::class), |
|
| 729 | - $this->get(ICacheFactory::class), |
|
| 730 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 731 | - ); |
|
| 732 | - } else { |
|
| 733 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 734 | - $c->get(AllConfig::class), |
|
| 735 | - $c->get(IDBConnection::class), |
|
| 736 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 737 | - ); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - return $backend; |
|
| 741 | - }); |
|
| 742 | - |
|
| 743 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 744 | - $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 745 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 746 | - |
|
| 747 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 748 | - |
|
| 749 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 750 | - |
|
| 751 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 752 | - |
|
| 753 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 754 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 755 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 756 | - $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 757 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 758 | - if (!$factory->isValidType($type)) { |
|
| 759 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 760 | - } |
|
| 761 | - $connection = $factory->getConnection($type, []); |
|
| 762 | - return $connection; |
|
| 763 | - }); |
|
| 764 | - |
|
| 765 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 766 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 767 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 768 | - return new NegativeDnsCache( |
|
| 769 | - $c->get(ICacheFactory::class), |
|
| 770 | - ); |
|
| 771 | - }); |
|
| 772 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 773 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 774 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 775 | - }); |
|
| 776 | - |
|
| 777 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 778 | - $queryLogger = new QueryLogger(); |
|
| 779 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 780 | - // In debug mode, module is being activated by default |
|
| 781 | - $queryLogger->activate(); |
|
| 782 | - } |
|
| 783 | - return $queryLogger; |
|
| 784 | - }); |
|
| 785 | - |
|
| 786 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 787 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 788 | - |
|
| 789 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 790 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 791 | - |
|
| 792 | - return new DateTimeFormatter( |
|
| 793 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 794 | - $c->getL10N('lib', $language) |
|
| 795 | - ); |
|
| 796 | - }); |
|
| 797 | - |
|
| 798 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 799 | - $mountCache = $c->get(UserMountCache::class); |
|
| 800 | - $listener = new UserMountCacheListener($mountCache); |
|
| 801 | - $listener->listen($c->get(IUserManager::class)); |
|
| 802 | - return $mountCache; |
|
| 803 | - }); |
|
| 804 | - |
|
| 805 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 806 | - $loader = $c->get(IStorageFactory::class); |
|
| 807 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 808 | - $eventLogger = $c->get(IEventLogger::class); |
|
| 809 | - $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 810 | - |
|
| 811 | - // builtin providers |
|
| 812 | - |
|
| 813 | - $config = $c->get(\OCP\IConfig::class); |
|
| 814 | - $logger = $c->get(LoggerInterface::class); |
|
| 815 | - $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 816 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 817 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 818 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 819 | - $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 820 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 821 | - |
|
| 822 | - return $manager; |
|
| 823 | - }); |
|
| 824 | - |
|
| 825 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 826 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 827 | - if ($busClass) { |
|
| 828 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 829 | - if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 830 | - $c->get(IAppManager::class)->loadApp($app); |
|
| 831 | - return $c->get($class); |
|
| 832 | - } else { |
|
| 833 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 834 | - } |
|
| 835 | - } else { |
|
| 836 | - $jobList = $c->get(IJobList::class); |
|
| 837 | - return new CronBus($jobList); |
|
| 838 | - } |
|
| 839 | - }); |
|
| 840 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 841 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 842 | - $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 843 | - |
|
| 844 | - $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 845 | - $config = $c->get(\OCP\IConfig::class); |
|
| 846 | - if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 847 | - && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 848 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 849 | - } else { |
|
| 850 | - $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - return $backend; |
|
| 854 | - }); |
|
| 855 | - |
|
| 856 | - $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 857 | - $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 858 | - // IConfig requires a working database. This code |
|
| 859 | - // might however be called when Nextcloud is not yet setup. |
|
| 860 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 861 | - $config = $c->get(\OCP\IConfig::class); |
|
| 862 | - $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 863 | - } else { |
|
| 864 | - $config = null; |
|
| 865 | - $appConfig = null; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - return new Checker( |
|
| 869 | - $c->get(ServerVersion::class), |
|
| 870 | - $c->get(EnvironmentHelper::class), |
|
| 871 | - new FileAccessHelper(), |
|
| 872 | - new AppLocator(), |
|
| 873 | - $config, |
|
| 874 | - $appConfig, |
|
| 875 | - $c->get(ICacheFactory::class), |
|
| 876 | - $c->get(IAppManager::class), |
|
| 877 | - $c->get(IMimeTypeDetector::class) |
|
| 878 | - ); |
|
| 879 | - }); |
|
| 880 | - $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 881 | - if (isset($this['urlParams'])) { |
|
| 882 | - $urlParams = $this['urlParams']; |
|
| 883 | - } else { |
|
| 884 | - $urlParams = []; |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 888 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 889 | - ) { |
|
| 890 | - $stream = 'fakeinput://data'; |
|
| 891 | - } else { |
|
| 892 | - $stream = 'php://input'; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return new Request( |
|
| 896 | - [ |
|
| 897 | - 'get' => $_GET, |
|
| 898 | - 'post' => $_POST, |
|
| 899 | - 'files' => $_FILES, |
|
| 900 | - 'server' => $_SERVER, |
|
| 901 | - 'env' => $_ENV, |
|
| 902 | - 'cookies' => $_COOKIE, |
|
| 903 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 904 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 905 | - : '', |
|
| 906 | - 'urlParams' => $urlParams, |
|
| 907 | - ], |
|
| 908 | - $this->get(IRequestId::class), |
|
| 909 | - $this->get(\OCP\IConfig::class), |
|
| 910 | - $this->get(CsrfTokenManager::class), |
|
| 911 | - $stream |
|
| 912 | - ); |
|
| 913 | - }); |
|
| 914 | - $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 915 | - |
|
| 916 | - $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 917 | - return new RequestId( |
|
| 918 | - $_SERVER['UNIQUE_ID'] ?? '', |
|
| 919 | - $this->get(ISecureRandom::class) |
|
| 920 | - ); |
|
| 921 | - }); |
|
| 922 | - |
|
| 923 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 924 | - return new Mailer( |
|
| 925 | - $c->get(\OCP\IConfig::class), |
|
| 926 | - $c->get(LoggerInterface::class), |
|
| 927 | - $c->get(Defaults::class), |
|
| 928 | - $c->get(IURLGenerator::class), |
|
| 929 | - $c->getL10N('lib'), |
|
| 930 | - $c->get(IEventDispatcher::class), |
|
| 931 | - $c->get(IFactory::class) |
|
| 932 | - ); |
|
| 933 | - }); |
|
| 934 | - |
|
| 935 | - /** @since 30.0.0 */ |
|
| 936 | - $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 937 | - |
|
| 938 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 939 | - $config = $c->get(\OCP\IConfig::class); |
|
| 940 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 941 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 942 | - return new NullLDAPProviderFactory($this); |
|
| 943 | - } |
|
| 944 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 945 | - return new $factoryClass($this); |
|
| 946 | - }); |
|
| 947 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 948 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 949 | - return $factory->getLDAPProvider(); |
|
| 950 | - }); |
|
| 951 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 952 | - $ini = $c->get(IniGetWrapper::class); |
|
| 953 | - $config = $c->get(\OCP\IConfig::class); |
|
| 954 | - $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 955 | - if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 956 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 957 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 958 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 959 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 960 | - $timeFactory = $c->get(ITimeFactory::class); |
|
| 961 | - return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 962 | - } |
|
| 963 | - return new DBLockingProvider( |
|
| 964 | - $c->get(IDBConnection::class), |
|
| 965 | - new TimeFactory(), |
|
| 966 | - $ttl, |
|
| 967 | - !\OC::$CLI |
|
| 968 | - ); |
|
| 969 | - } |
|
| 970 | - return new NoopLockingProvider(); |
|
| 971 | - }); |
|
| 972 | - |
|
| 973 | - $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 974 | - return new LockManager(); |
|
| 975 | - }); |
|
| 976 | - |
|
| 977 | - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 978 | - $this->registerService(SetupManager::class, function ($c) { |
|
| 979 | - // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 980 | - return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 981 | - }); |
|
| 982 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 983 | - |
|
| 984 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 985 | - return new \OC\Files\Type\Detection( |
|
| 986 | - $c->get(IURLGenerator::class), |
|
| 987 | - $c->get(LoggerInterface::class), |
|
| 988 | - \OC::$configDir, |
|
| 989 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 990 | - ); |
|
| 991 | - }); |
|
| 992 | - |
|
| 993 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 994 | - $this->registerService(BundleFetcher::class, function () { |
|
| 995 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 996 | - }); |
|
| 997 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 998 | - |
|
| 999 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1000 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1001 | - $manager->registerCapability(function () use ($c) { |
|
| 1002 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1003 | - }); |
|
| 1004 | - $manager->registerCapability(function () use ($c) { |
|
| 1005 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1006 | - }); |
|
| 1007 | - return $manager; |
|
| 1008 | - }); |
|
| 1009 | - |
|
| 1010 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1011 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1012 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1013 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1014 | - $factory = new $factoryClass($this); |
|
| 1015 | - $manager = $factory->getManager(); |
|
| 1016 | - |
|
| 1017 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1018 | - $manager = $c->get(IUserManager::class); |
|
| 1019 | - $userDisplayName = $manager->getDisplayName($id); |
|
| 1020 | - if ($userDisplayName === null) { |
|
| 1021 | - $l = $c->get(IFactory::class)->get('core'); |
|
| 1022 | - return $l->t('Unknown account'); |
|
| 1023 | - } |
|
| 1024 | - return $userDisplayName; |
|
| 1025 | - }); |
|
| 1026 | - |
|
| 1027 | - return $manager; |
|
| 1028 | - }); |
|
| 1029 | - |
|
| 1030 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1031 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1032 | - try { |
|
| 1033 | - $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1034 | - } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1035 | - // App disabled or in maintenance mode |
|
| 1036 | - $classExists = false; |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1040 | - $backgroundService = new BackgroundService( |
|
| 1041 | - $c->get(IRootFolder::class), |
|
| 1042 | - $c->getAppDataDir('theming'), |
|
| 1043 | - $c->get(IAppConfig::class), |
|
| 1044 | - $c->get(\OCP\IConfig::class), |
|
| 1045 | - $c->get(ISession::class)->get('user_id'), |
|
| 1046 | - ); |
|
| 1047 | - $imageManager = new ImageManager( |
|
| 1048 | - $c->get(\OCP\IConfig::class), |
|
| 1049 | - $c->getAppDataDir('theming'), |
|
| 1050 | - $c->get(IURLGenerator::class), |
|
| 1051 | - $c->get(ICacheFactory::class), |
|
| 1052 | - $c->get(LoggerInterface::class), |
|
| 1053 | - $c->get(ITempManager::class), |
|
| 1054 | - $backgroundService, |
|
| 1055 | - ); |
|
| 1056 | - return new ThemingDefaults( |
|
| 1057 | - $c->get(\OCP\IConfig::class), |
|
| 1058 | - $c->get(\OCP\IAppConfig::class), |
|
| 1059 | - $c->getL10N('theming'), |
|
| 1060 | - $c->get(IUserSession::class), |
|
| 1061 | - $c->get(IURLGenerator::class), |
|
| 1062 | - $c->get(ICacheFactory::class), |
|
| 1063 | - new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1064 | - $imageManager, |
|
| 1065 | - $c->get(IAppManager::class), |
|
| 1066 | - $c->get(INavigationManager::class), |
|
| 1067 | - $backgroundService, |
|
| 1068 | - ); |
|
| 1069 | - } |
|
| 1070 | - return new \OC_Defaults(); |
|
| 1071 | - }); |
|
| 1072 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1073 | - return new JSCombiner( |
|
| 1074 | - $c->getAppDataDir('js'), |
|
| 1075 | - $c->get(IURLGenerator::class), |
|
| 1076 | - $this->get(ICacheFactory::class), |
|
| 1077 | - $c->get(SystemConfig::class), |
|
| 1078 | - $c->get(LoggerInterface::class) |
|
| 1079 | - ); |
|
| 1080 | - }); |
|
| 1081 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1082 | - |
|
| 1083 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1084 | - // FIXME: Instantiated here due to cyclic dependency |
|
| 1085 | - $request = new Request( |
|
| 1086 | - [ |
|
| 1087 | - 'get' => $_GET, |
|
| 1088 | - 'post' => $_POST, |
|
| 1089 | - 'files' => $_FILES, |
|
| 1090 | - 'server' => $_SERVER, |
|
| 1091 | - 'env' => $_ENV, |
|
| 1092 | - 'cookies' => $_COOKIE, |
|
| 1093 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1094 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1095 | - : null, |
|
| 1096 | - ], |
|
| 1097 | - $c->get(IRequestId::class), |
|
| 1098 | - $c->get(\OCP\IConfig::class) |
|
| 1099 | - ); |
|
| 1100 | - |
|
| 1101 | - return new CryptoWrapper( |
|
| 1102 | - $c->get(ICrypto::class), |
|
| 1103 | - $c->get(ISecureRandom::class), |
|
| 1104 | - $request |
|
| 1105 | - ); |
|
| 1106 | - }); |
|
| 1107 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1108 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1109 | - }); |
|
| 1110 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1111 | - |
|
| 1112 | - $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1113 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1114 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1115 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1116 | - return $c->get($factoryClass); |
|
| 1117 | - }); |
|
| 1118 | - |
|
| 1119 | - $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1120 | - |
|
| 1121 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1122 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1123 | - |
|
| 1124 | - // register default plugins |
|
| 1125 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1126 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1127 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1128 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1129 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1130 | - |
|
| 1131 | - return $instance; |
|
| 1132 | - }); |
|
| 1133 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1134 | - |
|
| 1135 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1136 | - |
|
| 1137 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1138 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1139 | - |
|
| 1140 | - $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1141 | - $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1142 | - |
|
| 1143 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1144 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1145 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1146 | - return new \OC\Files\AppData\Factory( |
|
| 1147 | - $c->get(IRootFolder::class), |
|
| 1148 | - $c->get(SystemConfig::class) |
|
| 1149 | - ); |
|
| 1150 | - }); |
|
| 1151 | - |
|
| 1152 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1153 | - return new LockdownManager(function () use ($c) { |
|
| 1154 | - return $c->get(ISession::class); |
|
| 1155 | - }); |
|
| 1156 | - }); |
|
| 1157 | - |
|
| 1158 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1159 | - return new DiscoveryService( |
|
| 1160 | - $c->get(ICacheFactory::class), |
|
| 1161 | - $c->get(IClientService::class) |
|
| 1162 | - ); |
|
| 1163 | - }); |
|
| 1164 | - $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1165 | - |
|
| 1166 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1167 | - return new CloudIdManager( |
|
| 1168 | - $c->get(\OCP\Contacts\IManager::class), |
|
| 1169 | - $c->get(IURLGenerator::class), |
|
| 1170 | - $c->get(IUserManager::class), |
|
| 1171 | - $c->get(ICacheFactory::class), |
|
| 1172 | - $c->get(IEventDispatcher::class), |
|
| 1173 | - ); |
|
| 1174 | - }); |
|
| 1175 | - |
|
| 1176 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1177 | - $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1178 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1179 | - return new CloudFederationFactory(); |
|
| 1180 | - }); |
|
| 252 | + /** @var string */ |
|
| 253 | + private $webRoot; |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param string $webRoot |
|
| 257 | + * @param \OC\Config $config |
|
| 258 | + */ |
|
| 259 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 260 | + parent::__construct(); |
|
| 261 | + $this->webRoot = $webRoot; |
|
| 262 | + |
|
| 263 | + // To find out if we are running from CLI or not |
|
| 264 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 265 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 266 | + |
|
| 267 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 268 | + return $c; |
|
| 269 | + }); |
|
| 270 | + $this->registerDeprecatedAlias(\OCP\IServerContainer::class, ContainerInterface::class); |
|
| 271 | + |
|
| 272 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 273 | + |
|
| 274 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 275 | + |
|
| 276 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 277 | + |
|
| 278 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 279 | + |
|
| 280 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 281 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 282 | + $this->registerAlias(\OCP\Template\ITemplateManager::class, \OC\Template\TemplateManager::class); |
|
| 283 | + |
|
| 284 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 285 | + |
|
| 286 | + $this->registerService(View::class, function (Server $c) { |
|
| 287 | + return new View(); |
|
| 288 | + }, false); |
|
| 289 | + |
|
| 290 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 291 | + return new PreviewManager( |
|
| 292 | + $c->get(\OCP\IConfig::class), |
|
| 293 | + $c->get(IRootFolder::class), |
|
| 294 | + new \OC\Preview\Storage\Root( |
|
| 295 | + $c->get(IRootFolder::class), |
|
| 296 | + $c->get(SystemConfig::class) |
|
| 297 | + ), |
|
| 298 | + $c->get(IEventDispatcher::class), |
|
| 299 | + $c->get(GeneratorHelper::class), |
|
| 300 | + $c->get(ISession::class)->get('user_id'), |
|
| 301 | + $c->get(Coordinator::class), |
|
| 302 | + $c->get(IServerContainer::class), |
|
| 303 | + $c->get(IBinaryFinder::class), |
|
| 304 | + $c->get(IMagickSupport::class) |
|
| 305 | + ); |
|
| 306 | + }); |
|
| 307 | + $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); |
|
| 308 | + |
|
| 309 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 310 | + return new \OC\Preview\Watcher( |
|
| 311 | + new \OC\Preview\Storage\Root( |
|
| 312 | + $c->get(IRootFolder::class), |
|
| 313 | + $c->get(SystemConfig::class) |
|
| 314 | + ) |
|
| 315 | + ); |
|
| 316 | + }); |
|
| 317 | + |
|
| 318 | + $this->registerService(IProfiler::class, function (Server $c) { |
|
| 319 | + return new Profiler($c->get(SystemConfig::class)); |
|
| 320 | + }); |
|
| 321 | + |
|
| 322 | + $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { |
|
| 323 | + $view = new View(); |
|
| 324 | + $util = new Encryption\Util( |
|
| 325 | + $view, |
|
| 326 | + $c->get(IUserManager::class), |
|
| 327 | + $c->get(IGroupManager::class), |
|
| 328 | + $c->get(\OCP\IConfig::class) |
|
| 329 | + ); |
|
| 330 | + return new Encryption\Manager( |
|
| 331 | + $c->get(\OCP\IConfig::class), |
|
| 332 | + $c->get(LoggerInterface::class), |
|
| 333 | + $c->getL10N('core'), |
|
| 334 | + new View(), |
|
| 335 | + $util, |
|
| 336 | + new ArrayCache() |
|
| 337 | + ); |
|
| 338 | + }); |
|
| 339 | + $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); |
|
| 340 | + |
|
| 341 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 342 | + $util = new Encryption\Util( |
|
| 343 | + new View(), |
|
| 344 | + $c->get(IUserManager::class), |
|
| 345 | + $c->get(IGroupManager::class), |
|
| 346 | + $c->get(\OCP\IConfig::class) |
|
| 347 | + ); |
|
| 348 | + return new Encryption\File( |
|
| 349 | + $util, |
|
| 350 | + $c->get(IRootFolder::class), |
|
| 351 | + $c->get(\OCP\Share\IManager::class) |
|
| 352 | + ); |
|
| 353 | + }); |
|
| 354 | + |
|
| 355 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 356 | + $view = new View(); |
|
| 357 | + $util = new Encryption\Util( |
|
| 358 | + $view, |
|
| 359 | + $c->get(IUserManager::class), |
|
| 360 | + $c->get(IGroupManager::class), |
|
| 361 | + $c->get(\OCP\IConfig::class) |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + return new Encryption\Keys\Storage( |
|
| 365 | + $view, |
|
| 366 | + $util, |
|
| 367 | + $c->get(ICrypto::class), |
|
| 368 | + $c->get(\OCP\IConfig::class) |
|
| 369 | + ); |
|
| 370 | + }); |
|
| 371 | + |
|
| 372 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 373 | + |
|
| 374 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 375 | + /** @var \OCP\IConfig $config */ |
|
| 376 | + $config = $c->get(\OCP\IConfig::class); |
|
| 377 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 378 | + return new $factoryClass($this); |
|
| 379 | + }); |
|
| 380 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 381 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 382 | + }); |
|
| 383 | + /** @deprecated 19.0.0 */ |
|
| 384 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 385 | + |
|
| 386 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 387 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 388 | + }); |
|
| 389 | + $this->registerAlias(IFileAccess::class, FileAccess::class); |
|
| 390 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 391 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
| 392 | + $view = new View(); |
|
| 393 | + /** @var IUserSession $userSession */ |
|
| 394 | + $userSession = $c->get(IUserSession::class); |
|
| 395 | + $root = new Root( |
|
| 396 | + $manager, |
|
| 397 | + $view, |
|
| 398 | + $userSession->getUser(), |
|
| 399 | + $c->get(IUserMountCache::class), |
|
| 400 | + $this->get(LoggerInterface::class), |
|
| 401 | + $this->get(IUserManager::class), |
|
| 402 | + $this->get(IEventDispatcher::class), |
|
| 403 | + $this->get(ICacheFactory::class), |
|
| 404 | + ); |
|
| 405 | + |
|
| 406 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 407 | + $root, |
|
| 408 | + $c->get(SystemConfig::class), |
|
| 409 | + $this->get(IEventDispatcher::class) |
|
| 410 | + ); |
|
| 411 | + $previewConnector->connectWatcher(); |
|
| 412 | + |
|
| 413 | + return $root; |
|
| 414 | + }); |
|
| 415 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 416 | + return new HookConnector( |
|
| 417 | + $c->get(IRootFolder::class), |
|
| 418 | + new View(), |
|
| 419 | + $c->get(IEventDispatcher::class), |
|
| 420 | + $c->get(LoggerInterface::class) |
|
| 421 | + ); |
|
| 422 | + }); |
|
| 423 | + |
|
| 424 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 425 | + return new LazyRoot(function () use ($c) { |
|
| 426 | + return $c->get('RootFolder'); |
|
| 427 | + }); |
|
| 428 | + }); |
|
| 429 | + |
|
| 430 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 431 | + |
|
| 432 | + $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) { |
|
| 433 | + return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); |
|
| 434 | + }); |
|
| 435 | + |
|
| 436 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 437 | + $groupManager = new \OC\Group\Manager( |
|
| 438 | + $this->get(IUserManager::class), |
|
| 439 | + $this->get(IEventDispatcher::class), |
|
| 440 | + $this->get(LoggerInterface::class), |
|
| 441 | + $this->get(ICacheFactory::class), |
|
| 442 | + $this->get(IRemoteAddress::class), |
|
| 443 | + ); |
|
| 444 | + return $groupManager; |
|
| 445 | + }); |
|
| 446 | + |
|
| 447 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 448 | + $session = $c->get(ISession::class); |
|
| 449 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 450 | + $tokenProvider = $c->get(IProvider::class); |
|
| 451 | + } else { |
|
| 452 | + $tokenProvider = null; |
|
| 453 | + } |
|
| 454 | + $logger = $c->get(LoggerInterface::class); |
|
| 455 | + $crypto = $c->get(ICrypto::class); |
|
| 456 | + return new Store($session, $logger, $crypto, $tokenProvider); |
|
| 457 | + }); |
|
| 458 | + $this->registerAlias(IStore::class, Store::class); |
|
| 459 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 460 | + $this->registerAlias(OCPIProvider::class, Authentication\Token\Manager::class); |
|
| 461 | + |
|
| 462 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 463 | + $manager = $c->get(IUserManager::class); |
|
| 464 | + $session = new \OC\Session\Memory(); |
|
| 465 | + $timeFactory = new TimeFactory(); |
|
| 466 | + // Token providers might require a working database. This code |
|
| 467 | + // might however be called when Nextcloud is not yet setup. |
|
| 468 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 469 | + $provider = $c->get(IProvider::class); |
|
| 470 | + } else { |
|
| 471 | + $provider = null; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $userSession = new \OC\User\Session( |
|
| 475 | + $manager, |
|
| 476 | + $session, |
|
| 477 | + $timeFactory, |
|
| 478 | + $provider, |
|
| 479 | + $c->get(\OCP\IConfig::class), |
|
| 480 | + $c->get(ISecureRandom::class), |
|
| 481 | + $c->get('LockdownManager'), |
|
| 482 | + $c->get(LoggerInterface::class), |
|
| 483 | + $c->get(IEventDispatcher::class), |
|
| 484 | + ); |
|
| 485 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 486 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 487 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 488 | + }); |
|
| 489 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 490 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 491 | + /** @var \OC\User\User $user */ |
|
| 492 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 493 | + }); |
|
| 494 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 495 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 496 | + /** @var \OC\User\User $user */ |
|
| 497 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 498 | + }); |
|
| 499 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 500 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 501 | + /** @var \OC\User\User $user */ |
|
| 502 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 503 | + }); |
|
| 504 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 505 | + /** @var \OC\User\User $user */ |
|
| 506 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 507 | + }); |
|
| 508 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 509 | + /** @var \OC\User\User $user */ |
|
| 510 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 511 | + }); |
|
| 512 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 513 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 514 | + |
|
| 515 | + /** @var IEventDispatcher $dispatcher */ |
|
| 516 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 517 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 518 | + }); |
|
| 519 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 520 | + /** @var \OC\User\User $user */ |
|
| 521 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 522 | + |
|
| 523 | + /** @var IEventDispatcher $dispatcher */ |
|
| 524 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 525 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 526 | + }); |
|
| 527 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 528 | + /** @var IEventDispatcher $dispatcher */ |
|
| 529 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 530 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 531 | + }); |
|
| 532 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 533 | + /** @var \OC\User\User $user */ |
|
| 534 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 535 | + |
|
| 536 | + /** @var IEventDispatcher $dispatcher */ |
|
| 537 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 538 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 539 | + }); |
|
| 540 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 541 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 542 | + |
|
| 543 | + /** @var IEventDispatcher $dispatcher */ |
|
| 544 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 545 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 546 | + }); |
|
| 547 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 548 | + /** @var IEventDispatcher $dispatcher */ |
|
| 549 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 550 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 551 | + }); |
|
| 552 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 553 | + /** @var \OC\User\User $user */ |
|
| 554 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 555 | + }); |
|
| 556 | + return $userSession; |
|
| 557 | + }); |
|
| 558 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 559 | + |
|
| 560 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 561 | + |
|
| 562 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 563 | + |
|
| 564 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 565 | + |
|
| 566 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 567 | + return new \OC\SystemConfig($config); |
|
| 568 | + }); |
|
| 569 | + |
|
| 570 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 571 | + $this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class); |
|
| 572 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 573 | + |
|
| 574 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 575 | + return new \OC\L10N\Factory( |
|
| 576 | + $c->get(\OCP\IConfig::class), |
|
| 577 | + $c->getRequest(), |
|
| 578 | + $c->get(IUserSession::class), |
|
| 579 | + $c->get(ICacheFactory::class), |
|
| 580 | + \OC::$SERVERROOT, |
|
| 581 | + $c->get(IAppManager::class), |
|
| 582 | + ); |
|
| 583 | + }); |
|
| 584 | + |
|
| 585 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 586 | + |
|
| 587 | + $this->registerService(ICache::class, function ($c) { |
|
| 588 | + /** @var LoggerInterface $logger */ |
|
| 589 | + $logger = $c->get(LoggerInterface::class); |
|
| 590 | + $logger->debug('The requested service "' . ICache::class . '" is deprecated. Please use "' . ICacheFactory::class . '" instead to create a cache. This service will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 591 | + |
|
| 592 | + /** @var ICacheFactory $cacheFactory */ |
|
| 593 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 594 | + return $cacheFactory->createDistributed(); |
|
| 595 | + }); |
|
| 596 | + |
|
| 597 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 598 | + $profiler = $c->get(IProfiler::class); |
|
| 599 | + $arrayCacheFactory = new \OC\Memcache\Factory(fn () => '', $c->get(LoggerInterface::class), |
|
| 600 | + $profiler, |
|
| 601 | + ArrayCache::class, |
|
| 602 | + ArrayCache::class, |
|
| 603 | + ArrayCache::class |
|
| 604 | + ); |
|
| 605 | + /** @var SystemConfig $config */ |
|
| 606 | + $config = $c->get(SystemConfig::class); |
|
| 607 | + /** @var ServerVersion $serverVersion */ |
|
| 608 | + $serverVersion = $c->get(ServerVersion::class); |
|
| 609 | + |
|
| 610 | + if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 611 | + $logQuery = $config->getValue('log_query'); |
|
| 612 | + $prefixClosure = function () use ($logQuery, $serverVersion): ?string { |
|
| 613 | + if (!$logQuery) { |
|
| 614 | + try { |
|
| 615 | + $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(true); |
|
| 616 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
| 617 | + // Database service probably unavailable |
|
| 618 | + // Probably related to https://github.com/nextcloud/server/issues/37424 |
|
| 619 | + return null; |
|
| 620 | + } |
|
| 621 | + } else { |
|
| 622 | + // If the log_query is enabled, we can not get the app versions |
|
| 623 | + // as that does a query, which will be logged and the logging |
|
| 624 | + // depends on redis and here we are back again in the same function. |
|
| 625 | + $v = [ |
|
| 626 | + 'log_query' => 'enabled', |
|
| 627 | + ]; |
|
| 628 | + } |
|
| 629 | + $v['core'] = implode(',', $serverVersion->getVersion()); |
|
| 630 | + $version = implode(',', array_keys($v)) . implode(',', $v); |
|
| 631 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 632 | + $path = \OC::$SERVERROOT; |
|
| 633 | + return md5($instanceId . '-' . $version . '-' . $path); |
|
| 634 | + }; |
|
| 635 | + return new \OC\Memcache\Factory($prefixClosure, |
|
| 636 | + $c->get(LoggerInterface::class), |
|
| 637 | + $profiler, |
|
| 638 | + /** @psalm-taint-escape callable */ |
|
| 639 | + $config->getValue('memcache.local', null), |
|
| 640 | + /** @psalm-taint-escape callable */ |
|
| 641 | + $config->getValue('memcache.distributed', null), |
|
| 642 | + /** @psalm-taint-escape callable */ |
|
| 643 | + $config->getValue('memcache.locking', null), |
|
| 644 | + /** @psalm-taint-escape callable */ |
|
| 645 | + $config->getValue('redis_log_file') |
|
| 646 | + ); |
|
| 647 | + } |
|
| 648 | + return $arrayCacheFactory; |
|
| 649 | + }); |
|
| 650 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 651 | + |
|
| 652 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 653 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 654 | + return new RedisFactory($systemConfig, $c->get(IEventLogger::class)); |
|
| 655 | + }); |
|
| 656 | + |
|
| 657 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 658 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 659 | + return new \OC\Activity\Manager( |
|
| 660 | + $c->getRequest(), |
|
| 661 | + $c->get(IUserSession::class), |
|
| 662 | + $c->get(\OCP\IConfig::class), |
|
| 663 | + $c->get(IValidator::class), |
|
| 664 | + $c->get(IRichTextFormatter::class), |
|
| 665 | + $l10n |
|
| 666 | + ); |
|
| 667 | + }); |
|
| 668 | + |
|
| 669 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 670 | + return new \OC\Activity\EventMerger( |
|
| 671 | + $c->getL10N('lib') |
|
| 672 | + ); |
|
| 673 | + }); |
|
| 674 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 675 | + |
|
| 676 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 677 | + return new AvatarManager( |
|
| 678 | + $c->get(IUserSession::class), |
|
| 679 | + $c->get(\OC\User\Manager::class), |
|
| 680 | + $c->getAppDataDir('avatar'), |
|
| 681 | + $c->getL10N('lib'), |
|
| 682 | + $c->get(LoggerInterface::class), |
|
| 683 | + $c->get(\OCP\IConfig::class), |
|
| 684 | + $c->get(IAccountManager::class), |
|
| 685 | + $c->get(KnownUserService::class) |
|
| 686 | + ); |
|
| 687 | + }); |
|
| 688 | + |
|
| 689 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 690 | + |
|
| 691 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 692 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 693 | + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); |
|
| 694 | + |
|
| 695 | + /** Only used by the PsrLoggerAdapter should not be used by apps */ |
|
| 696 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 697 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 698 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 699 | + $logger = $factory->get($logType); |
|
| 700 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 701 | + |
|
| 702 | + return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry); |
|
| 703 | + }); |
|
| 704 | + // PSR-3 logger |
|
| 705 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 706 | + |
|
| 707 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 708 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 709 | + }); |
|
| 710 | + |
|
| 711 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 712 | + |
|
| 713 | + $this->registerService(Router::class, function (Server $c) { |
|
| 714 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 715 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 716 | + $router = $c->resolve(CachingRouter::class); |
|
| 717 | + } else { |
|
| 718 | + $router = $c->resolve(Router::class); |
|
| 719 | + } |
|
| 720 | + return $router; |
|
| 721 | + }); |
|
| 722 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 723 | + |
|
| 724 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 725 | + $config = $c->get(\OCP\IConfig::class); |
|
| 726 | + if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 727 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 728 | + $c->get(AllConfig::class), |
|
| 729 | + $this->get(ICacheFactory::class), |
|
| 730 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 731 | + ); |
|
| 732 | + } else { |
|
| 733 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 734 | + $c->get(AllConfig::class), |
|
| 735 | + $c->get(IDBConnection::class), |
|
| 736 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 737 | + ); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + return $backend; |
|
| 741 | + }); |
|
| 742 | + |
|
| 743 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 744 | + $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class); |
|
| 745 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 746 | + |
|
| 747 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 748 | + |
|
| 749 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 750 | + |
|
| 751 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 752 | + |
|
| 753 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 754 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 755 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 756 | + $factory = new \OC\DB\ConnectionFactory($systemConfig, $c->get(ICacheFactory::class)); |
|
| 757 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 758 | + if (!$factory->isValidType($type)) { |
|
| 759 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 760 | + } |
|
| 761 | + $connection = $factory->getConnection($type, []); |
|
| 762 | + return $connection; |
|
| 763 | + }); |
|
| 764 | + |
|
| 765 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 766 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 767 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 768 | + return new NegativeDnsCache( |
|
| 769 | + $c->get(ICacheFactory::class), |
|
| 770 | + ); |
|
| 771 | + }); |
|
| 772 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 773 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 774 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 775 | + }); |
|
| 776 | + |
|
| 777 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 778 | + $queryLogger = new QueryLogger(); |
|
| 779 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 780 | + // In debug mode, module is being activated by default |
|
| 781 | + $queryLogger->activate(); |
|
| 782 | + } |
|
| 783 | + return $queryLogger; |
|
| 784 | + }); |
|
| 785 | + |
|
| 786 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 787 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 788 | + |
|
| 789 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 790 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 791 | + |
|
| 792 | + return new DateTimeFormatter( |
|
| 793 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 794 | + $c->getL10N('lib', $language) |
|
| 795 | + ); |
|
| 796 | + }); |
|
| 797 | + |
|
| 798 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 799 | + $mountCache = $c->get(UserMountCache::class); |
|
| 800 | + $listener = new UserMountCacheListener($mountCache); |
|
| 801 | + $listener->listen($c->get(IUserManager::class)); |
|
| 802 | + return $mountCache; |
|
| 803 | + }); |
|
| 804 | + |
|
| 805 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 806 | + $loader = $c->get(IStorageFactory::class); |
|
| 807 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 808 | + $eventLogger = $c->get(IEventLogger::class); |
|
| 809 | + $manager = new MountProviderCollection($loader, $mountCache, $eventLogger); |
|
| 810 | + |
|
| 811 | + // builtin providers |
|
| 812 | + |
|
| 813 | + $config = $c->get(\OCP\IConfig::class); |
|
| 814 | + $logger = $c->get(LoggerInterface::class); |
|
| 815 | + $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); |
|
| 816 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 817 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 818 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($objectStoreConfig)); |
|
| 819 | + $manager->registerRootProvider(new RootMountProvider($objectStoreConfig, $config)); |
|
| 820 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 821 | + |
|
| 822 | + return $manager; |
|
| 823 | + }); |
|
| 824 | + |
|
| 825 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 826 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValueString('commandbus'); |
|
| 827 | + if ($busClass) { |
|
| 828 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 829 | + if ($c->get(IAppManager::class)->isEnabledForUser($app)) { |
|
| 830 | + $c->get(IAppManager::class)->loadApp($app); |
|
| 831 | + return $c->get($class); |
|
| 832 | + } else { |
|
| 833 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 834 | + } |
|
| 835 | + } else { |
|
| 836 | + $jobList = $c->get(IJobList::class); |
|
| 837 | + return new CronBus($jobList); |
|
| 838 | + } |
|
| 839 | + }); |
|
| 840 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 841 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 842 | + $this->registerAlias(IThrottler::class, Throttler::class); |
|
| 843 | + |
|
| 844 | + $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) { |
|
| 845 | + $config = $c->get(\OCP\IConfig::class); |
|
| 846 | + if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false) |
|
| 847 | + && ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) { |
|
| 848 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\MemoryCacheBackend::class); |
|
| 849 | + } else { |
|
| 850 | + $backend = $c->get(\OC\Security\Bruteforce\Backend\DatabaseBackend::class); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + return $backend; |
|
| 854 | + }); |
|
| 855 | + |
|
| 856 | + $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); |
|
| 857 | + $this->registerService(Checker::class, function (ContainerInterface $c) { |
|
| 858 | + // IConfig requires a working database. This code |
|
| 859 | + // might however be called when Nextcloud is not yet setup. |
|
| 860 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 861 | + $config = $c->get(\OCP\IConfig::class); |
|
| 862 | + $appConfig = $c->get(\OCP\IAppConfig::class); |
|
| 863 | + } else { |
|
| 864 | + $config = null; |
|
| 865 | + $appConfig = null; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + return new Checker( |
|
| 869 | + $c->get(ServerVersion::class), |
|
| 870 | + $c->get(EnvironmentHelper::class), |
|
| 871 | + new FileAccessHelper(), |
|
| 872 | + new AppLocator(), |
|
| 873 | + $config, |
|
| 874 | + $appConfig, |
|
| 875 | + $c->get(ICacheFactory::class), |
|
| 876 | + $c->get(IAppManager::class), |
|
| 877 | + $c->get(IMimeTypeDetector::class) |
|
| 878 | + ); |
|
| 879 | + }); |
|
| 880 | + $this->registerService(Request::class, function (ContainerInterface $c) { |
|
| 881 | + if (isset($this['urlParams'])) { |
|
| 882 | + $urlParams = $this['urlParams']; |
|
| 883 | + } else { |
|
| 884 | + $urlParams = []; |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 888 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 889 | + ) { |
|
| 890 | + $stream = 'fakeinput://data'; |
|
| 891 | + } else { |
|
| 892 | + $stream = 'php://input'; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return new Request( |
|
| 896 | + [ |
|
| 897 | + 'get' => $_GET, |
|
| 898 | + 'post' => $_POST, |
|
| 899 | + 'files' => $_FILES, |
|
| 900 | + 'server' => $_SERVER, |
|
| 901 | + 'env' => $_ENV, |
|
| 902 | + 'cookies' => $_COOKIE, |
|
| 903 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 904 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 905 | + : '', |
|
| 906 | + 'urlParams' => $urlParams, |
|
| 907 | + ], |
|
| 908 | + $this->get(IRequestId::class), |
|
| 909 | + $this->get(\OCP\IConfig::class), |
|
| 910 | + $this->get(CsrfTokenManager::class), |
|
| 911 | + $stream |
|
| 912 | + ); |
|
| 913 | + }); |
|
| 914 | + $this->registerAlias(\OCP\IRequest::class, Request::class); |
|
| 915 | + |
|
| 916 | + $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId { |
|
| 917 | + return new RequestId( |
|
| 918 | + $_SERVER['UNIQUE_ID'] ?? '', |
|
| 919 | + $this->get(ISecureRandom::class) |
|
| 920 | + ); |
|
| 921 | + }); |
|
| 922 | + |
|
| 923 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 924 | + return new Mailer( |
|
| 925 | + $c->get(\OCP\IConfig::class), |
|
| 926 | + $c->get(LoggerInterface::class), |
|
| 927 | + $c->get(Defaults::class), |
|
| 928 | + $c->get(IURLGenerator::class), |
|
| 929 | + $c->getL10N('lib'), |
|
| 930 | + $c->get(IEventDispatcher::class), |
|
| 931 | + $c->get(IFactory::class) |
|
| 932 | + ); |
|
| 933 | + }); |
|
| 934 | + |
|
| 935 | + /** @since 30.0.0 */ |
|
| 936 | + $this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class); |
|
| 937 | + |
|
| 938 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 939 | + $config = $c->get(\OCP\IConfig::class); |
|
| 940 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 941 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 942 | + return new NullLDAPProviderFactory($this); |
|
| 943 | + } |
|
| 944 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 945 | + return new $factoryClass($this); |
|
| 946 | + }); |
|
| 947 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 948 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 949 | + return $factory->getLDAPProvider(); |
|
| 950 | + }); |
|
| 951 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 952 | + $ini = $c->get(IniGetWrapper::class); |
|
| 953 | + $config = $c->get(\OCP\IConfig::class); |
|
| 954 | + $ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 955 | + if ($config->getSystemValueBool('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 956 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 957 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 958 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 959 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 960 | + $timeFactory = $c->get(ITimeFactory::class); |
|
| 961 | + return new MemcacheLockingProvider($memcache, $timeFactory, $ttl); |
|
| 962 | + } |
|
| 963 | + return new DBLockingProvider( |
|
| 964 | + $c->get(IDBConnection::class), |
|
| 965 | + new TimeFactory(), |
|
| 966 | + $ttl, |
|
| 967 | + !\OC::$CLI |
|
| 968 | + ); |
|
| 969 | + } |
|
| 970 | + return new NoopLockingProvider(); |
|
| 971 | + }); |
|
| 972 | + |
|
| 973 | + $this->registerService(ILockManager::class, function (Server $c): LockManager { |
|
| 974 | + return new LockManager(); |
|
| 975 | + }); |
|
| 976 | + |
|
| 977 | + $this->registerAlias(ILockdownManager::class, 'LockdownManager'); |
|
| 978 | + $this->registerService(SetupManager::class, function ($c) { |
|
| 979 | + // create the setupmanager through the mount manager to resolve the cyclic dependency |
|
| 980 | + return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); |
|
| 981 | + }); |
|
| 982 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 983 | + |
|
| 984 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 985 | + return new \OC\Files\Type\Detection( |
|
| 986 | + $c->get(IURLGenerator::class), |
|
| 987 | + $c->get(LoggerInterface::class), |
|
| 988 | + \OC::$configDir, |
|
| 989 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 990 | + ); |
|
| 991 | + }); |
|
| 992 | + |
|
| 993 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 994 | + $this->registerService(BundleFetcher::class, function () { |
|
| 995 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 996 | + }); |
|
| 997 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 998 | + |
|
| 999 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1000 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1001 | + $manager->registerCapability(function () use ($c) { |
|
| 1002 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1003 | + }); |
|
| 1004 | + $manager->registerCapability(function () use ($c) { |
|
| 1005 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1006 | + }); |
|
| 1007 | + return $manager; |
|
| 1008 | + }); |
|
| 1009 | + |
|
| 1010 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1011 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1012 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1013 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1014 | + $factory = new $factoryClass($this); |
|
| 1015 | + $manager = $factory->getManager(); |
|
| 1016 | + |
|
| 1017 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1018 | + $manager = $c->get(IUserManager::class); |
|
| 1019 | + $userDisplayName = $manager->getDisplayName($id); |
|
| 1020 | + if ($userDisplayName === null) { |
|
| 1021 | + $l = $c->get(IFactory::class)->get('core'); |
|
| 1022 | + return $l->t('Unknown account'); |
|
| 1023 | + } |
|
| 1024 | + return $userDisplayName; |
|
| 1025 | + }); |
|
| 1026 | + |
|
| 1027 | + return $manager; |
|
| 1028 | + }); |
|
| 1029 | + |
|
| 1030 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1031 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1032 | + try { |
|
| 1033 | + $classExists = class_exists('OCA\Theming\ThemingDefaults'); |
|
| 1034 | + } catch (\OCP\AutoloadNotAllowedException $e) { |
|
| 1035 | + // App disabled or in maintenance mode |
|
| 1036 | + $classExists = false; |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValueBool('installed', false) && $c->get(IAppManager::class)->isEnabledForAnyone('theming') && $c->get(TrustedDomainHelper::class)->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1040 | + $backgroundService = new BackgroundService( |
|
| 1041 | + $c->get(IRootFolder::class), |
|
| 1042 | + $c->getAppDataDir('theming'), |
|
| 1043 | + $c->get(IAppConfig::class), |
|
| 1044 | + $c->get(\OCP\IConfig::class), |
|
| 1045 | + $c->get(ISession::class)->get('user_id'), |
|
| 1046 | + ); |
|
| 1047 | + $imageManager = new ImageManager( |
|
| 1048 | + $c->get(\OCP\IConfig::class), |
|
| 1049 | + $c->getAppDataDir('theming'), |
|
| 1050 | + $c->get(IURLGenerator::class), |
|
| 1051 | + $c->get(ICacheFactory::class), |
|
| 1052 | + $c->get(LoggerInterface::class), |
|
| 1053 | + $c->get(ITempManager::class), |
|
| 1054 | + $backgroundService, |
|
| 1055 | + ); |
|
| 1056 | + return new ThemingDefaults( |
|
| 1057 | + $c->get(\OCP\IConfig::class), |
|
| 1058 | + $c->get(\OCP\IAppConfig::class), |
|
| 1059 | + $c->getL10N('theming'), |
|
| 1060 | + $c->get(IUserSession::class), |
|
| 1061 | + $c->get(IURLGenerator::class), |
|
| 1062 | + $c->get(ICacheFactory::class), |
|
| 1063 | + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), |
|
| 1064 | + $imageManager, |
|
| 1065 | + $c->get(IAppManager::class), |
|
| 1066 | + $c->get(INavigationManager::class), |
|
| 1067 | + $backgroundService, |
|
| 1068 | + ); |
|
| 1069 | + } |
|
| 1070 | + return new \OC_Defaults(); |
|
| 1071 | + }); |
|
| 1072 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1073 | + return new JSCombiner( |
|
| 1074 | + $c->getAppDataDir('js'), |
|
| 1075 | + $c->get(IURLGenerator::class), |
|
| 1076 | + $this->get(ICacheFactory::class), |
|
| 1077 | + $c->get(SystemConfig::class), |
|
| 1078 | + $c->get(LoggerInterface::class) |
|
| 1079 | + ); |
|
| 1080 | + }); |
|
| 1081 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1082 | + |
|
| 1083 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1084 | + // FIXME: Instantiated here due to cyclic dependency |
|
| 1085 | + $request = new Request( |
|
| 1086 | + [ |
|
| 1087 | + 'get' => $_GET, |
|
| 1088 | + 'post' => $_POST, |
|
| 1089 | + 'files' => $_FILES, |
|
| 1090 | + 'server' => $_SERVER, |
|
| 1091 | + 'env' => $_ENV, |
|
| 1092 | + 'cookies' => $_COOKIE, |
|
| 1093 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1094 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1095 | + : null, |
|
| 1096 | + ], |
|
| 1097 | + $c->get(IRequestId::class), |
|
| 1098 | + $c->get(\OCP\IConfig::class) |
|
| 1099 | + ); |
|
| 1100 | + |
|
| 1101 | + return new CryptoWrapper( |
|
| 1102 | + $c->get(ICrypto::class), |
|
| 1103 | + $c->get(ISecureRandom::class), |
|
| 1104 | + $request |
|
| 1105 | + ); |
|
| 1106 | + }); |
|
| 1107 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1108 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1109 | + }); |
|
| 1110 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1111 | + |
|
| 1112 | + $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { |
|
| 1113 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1114 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1115 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1116 | + return $c->get($factoryClass); |
|
| 1117 | + }); |
|
| 1118 | + |
|
| 1119 | + $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); |
|
| 1120 | + |
|
| 1121 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1122 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1123 | + |
|
| 1124 | + // register default plugins |
|
| 1125 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1126 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1127 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1128 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1129 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1130 | + |
|
| 1131 | + return $instance; |
|
| 1132 | + }); |
|
| 1133 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1134 | + |
|
| 1135 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1136 | + |
|
| 1137 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1138 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1139 | + |
|
| 1140 | + $this->registerAlias(IReferenceManager::class, ReferenceManager::class); |
|
| 1141 | + $this->registerAlias(ITeamManager::class, TeamManager::class); |
|
| 1142 | + |
|
| 1143 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1144 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1145 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1146 | + return new \OC\Files\AppData\Factory( |
|
| 1147 | + $c->get(IRootFolder::class), |
|
| 1148 | + $c->get(SystemConfig::class) |
|
| 1149 | + ); |
|
| 1150 | + }); |
|
| 1151 | + |
|
| 1152 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1153 | + return new LockdownManager(function () use ($c) { |
|
| 1154 | + return $c->get(ISession::class); |
|
| 1155 | + }); |
|
| 1156 | + }); |
|
| 1157 | + |
|
| 1158 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1159 | + return new DiscoveryService( |
|
| 1160 | + $c->get(ICacheFactory::class), |
|
| 1161 | + $c->get(IClientService::class) |
|
| 1162 | + ); |
|
| 1163 | + }); |
|
| 1164 | + $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); |
|
| 1165 | + |
|
| 1166 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1167 | + return new CloudIdManager( |
|
| 1168 | + $c->get(\OCP\Contacts\IManager::class), |
|
| 1169 | + $c->get(IURLGenerator::class), |
|
| 1170 | + $c->get(IUserManager::class), |
|
| 1171 | + $c->get(ICacheFactory::class), |
|
| 1172 | + $c->get(IEventDispatcher::class), |
|
| 1173 | + ); |
|
| 1174 | + }); |
|
| 1175 | + |
|
| 1176 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1177 | + $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); |
|
| 1178 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1179 | + return new CloudFederationFactory(); |
|
| 1180 | + }); |
|
| 1181 | 1181 | |
| 1182 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1182 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1183 | 1183 | |
| 1184 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1185 | - $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1184 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1185 | + $this->registerAlias(\Psr\Clock\ClockInterface::class, \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1186 | 1186 | |
| 1187 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1188 | - return new Defaults( |
|
| 1189 | - $c->get('ThemingDefaults') |
|
| 1190 | - ); |
|
| 1191 | - }); |
|
| 1187 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1188 | + return new Defaults( |
|
| 1189 | + $c->get('ThemingDefaults') |
|
| 1190 | + ); |
|
| 1191 | + }); |
|
| 1192 | 1192 | |
| 1193 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1194 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1195 | - }, false); |
|
| 1193 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1194 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1195 | + }, false); |
|
| 1196 | 1196 | |
| 1197 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1198 | - return new ShareHelper( |
|
| 1199 | - $c->get(\OCP\Share\IManager::class) |
|
| 1200 | - ); |
|
| 1201 | - }); |
|
| 1197 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1198 | + return new ShareHelper( |
|
| 1199 | + $c->get(\OCP\Share\IManager::class) |
|
| 1200 | + ); |
|
| 1201 | + }); |
|
| 1202 | 1202 | |
| 1203 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1204 | - return new Installer( |
|
| 1205 | - $c->get(AppFetcher::class), |
|
| 1206 | - $c->get(IClientService::class), |
|
| 1207 | - $c->get(ITempManager::class), |
|
| 1208 | - $c->get(LoggerInterface::class), |
|
| 1209 | - $c->get(\OCP\IConfig::class), |
|
| 1210 | - \OC::$CLI |
|
| 1211 | - ); |
|
| 1212 | - }); |
|
| 1203 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1204 | + return new Installer( |
|
| 1205 | + $c->get(AppFetcher::class), |
|
| 1206 | + $c->get(IClientService::class), |
|
| 1207 | + $c->get(ITempManager::class), |
|
| 1208 | + $c->get(LoggerInterface::class), |
|
| 1209 | + $c->get(\OCP\IConfig::class), |
|
| 1210 | + \OC::$CLI |
|
| 1211 | + ); |
|
| 1212 | + }); |
|
| 1213 | 1213 | |
| 1214 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1215 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1216 | - }); |
|
| 1214 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1215 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1216 | + }); |
|
| 1217 | 1217 | |
| 1218 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1219 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1220 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1221 | - }); |
|
| 1218 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1219 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1220 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1221 | + }); |
|
| 1222 | 1222 | |
| 1223 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1224 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1223 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1224 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1225 | 1225 | |
| 1226 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1226 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1227 | 1227 | |
| 1228 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1228 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1229 | 1229 | |
| 1230 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1231 | - $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1230 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1231 | + $this->registerAlias(IFilesMetadataManager::class, FilesMetadataManager::class); |
|
| 1232 | 1232 | |
| 1233 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1233 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1234 | 1234 | |
| 1235 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1235 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1236 | 1236 | |
| 1237 | - $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1237 | + $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class); |
|
| 1238 | 1238 | |
| 1239 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1239 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1240 | 1240 | |
| 1241 | - $this->registerAlias(IBroker::class, Broker::class); |
|
| 1241 | + $this->registerAlias(IBroker::class, Broker::class); |
|
| 1242 | 1242 | |
| 1243 | - $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1243 | + $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class); |
|
| 1244 | 1244 | |
| 1245 | - $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1245 | + $this->registerAlias(\OCP\Files\IFilenameValidator::class, \OC\Files\FilenameValidator::class); |
|
| 1246 | 1246 | |
| 1247 | - $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1247 | + $this->registerAlias(IBinaryFinder::class, BinaryFinder::class); |
|
| 1248 | 1248 | |
| 1249 | - $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1249 | + $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class); |
|
| 1250 | 1250 | |
| 1251 | - $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1251 | + $this->registerAlias(ITranslationManager::class, TranslationManager::class); |
|
| 1252 | 1252 | |
| 1253 | - $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1253 | + $this->registerAlias(IConversionManager::class, ConversionManager::class); |
|
| 1254 | 1254 | |
| 1255 | - $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1255 | + $this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class); |
|
| 1256 | 1256 | |
| 1257 | - $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1257 | + $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class); |
|
| 1258 | 1258 | |
| 1259 | - $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1259 | + $this->registerAlias(\OCP\TextProcessing\IManager::class, \OC\TextProcessing\Manager::class); |
|
| 1260 | 1260 | |
| 1261 | - $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1261 | + $this->registerAlias(\OCP\TextToImage\IManager::class, \OC\TextToImage\Manager::class); |
|
| 1262 | 1262 | |
| 1263 | - $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1263 | + $this->registerAlias(ILimiter::class, Limiter::class); |
|
| 1264 | 1264 | |
| 1265 | - $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1265 | + $this->registerAlias(IPhoneNumberUtil::class, PhoneNumberUtil::class); |
|
| 1266 | 1266 | |
| 1267 | - $this->registerAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1268 | - $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1267 | + $this->registerAlias(ICapabilityAwareOCMProvider::class, OCMProvider::class); |
|
| 1268 | + $this->registerDeprecatedAlias(IOCMProvider::class, OCMProvider::class); |
|
| 1269 | 1269 | |
| 1270 | - $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1270 | + $this->registerAlias(ISetupCheckManager::class, SetupCheckManager::class); |
|
| 1271 | 1271 | |
| 1272 | - $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1272 | + $this->registerAlias(IProfileManager::class, ProfileManager::class); |
|
| 1273 | 1273 | |
| 1274 | - $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1274 | + $this->registerAlias(IAvailabilityCoordinator::class, AvailabilityCoordinator::class); |
|
| 1275 | 1275 | |
| 1276 | - $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1276 | + $this->registerAlias(IDeclarativeManager::class, DeclarativeManager::class); |
|
| 1277 | 1277 | |
| 1278 | - $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1278 | + $this->registerAlias(\OCP\TaskProcessing\IManager::class, \OC\TaskProcessing\Manager::class); |
|
| 1279 | 1279 | |
| 1280 | - $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1280 | + $this->registerAlias(IRemoteAddress::class, RemoteAddress::class); |
|
| 1281 | 1281 | |
| 1282 | - $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1283 | - |
|
| 1284 | - $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1285 | - |
|
| 1286 | - $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1287 | - |
|
| 1288 | - $this->connectDispatcher(); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - public function boot() { |
|
| 1292 | - /** @var HookConnector $hookConnector */ |
|
| 1293 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1294 | - $hookConnector->viewToNode(); |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - private function connectDispatcher(): void { |
|
| 1298 | - /** @var IEventDispatcher $eventDispatcher */ |
|
| 1299 | - $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1300 | - $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1301 | - $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1302 | - $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1303 | - $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1304 | - |
|
| 1305 | - FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1306 | - GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * @return \OCP\Contacts\IManager |
|
| 1311 | - * @deprecated 20.0.0 |
|
| 1312 | - */ |
|
| 1313 | - public function getContactsManager() { |
|
| 1314 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * @return \OC\Encryption\Manager |
|
| 1319 | - * @deprecated 20.0.0 |
|
| 1320 | - */ |
|
| 1321 | - public function getEncryptionManager() { |
|
| 1322 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * @return \OC\Encryption\File |
|
| 1327 | - * @deprecated 20.0.0 |
|
| 1328 | - */ |
|
| 1329 | - public function getEncryptionFilesHelper() { |
|
| 1330 | - return $this->get(IFile::class); |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - /** |
|
| 1334 | - * The current request object holding all information about the request |
|
| 1335 | - * currently being processed is returned from this method. |
|
| 1336 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1337 | - * |
|
| 1338 | - * @return \OCP\IRequest |
|
| 1339 | - * @deprecated 20.0.0 |
|
| 1340 | - */ |
|
| 1341 | - public function getRequest() { |
|
| 1342 | - return $this->get(IRequest::class); |
|
| 1343 | - } |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * Returns the root folder of ownCloud's data directory |
|
| 1347 | - * |
|
| 1348 | - * @return IRootFolder |
|
| 1349 | - * @deprecated 20.0.0 |
|
| 1350 | - */ |
|
| 1351 | - public function getRootFolder() { |
|
| 1352 | - return $this->get(IRootFolder::class); |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - /** |
|
| 1356 | - * Returns the root folder of ownCloud's data directory |
|
| 1357 | - * This is the lazy variant so this gets only initialized once it |
|
| 1358 | - * is actually used. |
|
| 1359 | - * |
|
| 1360 | - * @return IRootFolder |
|
| 1361 | - * @deprecated 20.0.0 |
|
| 1362 | - */ |
|
| 1363 | - public function getLazyRootFolder() { |
|
| 1364 | - return $this->get(IRootFolder::class); |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * Returns a view to ownCloud's files folder |
|
| 1369 | - * |
|
| 1370 | - * @param string $userId user ID |
|
| 1371 | - * @return \OCP\Files\Folder|null |
|
| 1372 | - * @deprecated 20.0.0 |
|
| 1373 | - */ |
|
| 1374 | - public function getUserFolder($userId = null) { |
|
| 1375 | - if ($userId === null) { |
|
| 1376 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1377 | - if (!$user) { |
|
| 1378 | - return null; |
|
| 1379 | - } |
|
| 1380 | - $userId = $user->getUID(); |
|
| 1381 | - } |
|
| 1382 | - $root = $this->get(IRootFolder::class); |
|
| 1383 | - return $root->getUserFolder($userId); |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - /** |
|
| 1387 | - * @return \OC\User\Manager |
|
| 1388 | - * @deprecated 20.0.0 |
|
| 1389 | - */ |
|
| 1390 | - public function getUserManager() { |
|
| 1391 | - return $this->get(IUserManager::class); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * @return \OC\Group\Manager |
|
| 1396 | - * @deprecated 20.0.0 |
|
| 1397 | - */ |
|
| 1398 | - public function getGroupManager() { |
|
| 1399 | - return $this->get(IGroupManager::class); |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * @return \OC\User\Session |
|
| 1404 | - * @deprecated 20.0.0 |
|
| 1405 | - */ |
|
| 1406 | - public function getUserSession() { |
|
| 1407 | - return $this->get(IUserSession::class); |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - /** |
|
| 1411 | - * @return \OCP\ISession |
|
| 1412 | - * @deprecated 20.0.0 |
|
| 1413 | - */ |
|
| 1414 | - public function getSession() { |
|
| 1415 | - return $this->get(Session::class)->getSession(); |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * @param \OCP\ISession $session |
|
| 1420 | - * @return void |
|
| 1421 | - */ |
|
| 1422 | - public function setSession(\OCP\ISession $session) { |
|
| 1423 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1424 | - $this->get(Session::class)->setSession($session); |
|
| 1425 | - $this->get(Store::class)->setSession($session); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * @return \OCP\IConfig |
|
| 1430 | - * @deprecated 20.0.0 |
|
| 1431 | - */ |
|
| 1432 | - public function getConfig() { |
|
| 1433 | - return $this->get(AllConfig::class); |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - /** |
|
| 1437 | - * @return \OC\SystemConfig |
|
| 1438 | - * @deprecated 20.0.0 |
|
| 1439 | - */ |
|
| 1440 | - public function getSystemConfig() { |
|
| 1441 | - return $this->get(SystemConfig::class); |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * @return IFactory |
|
| 1446 | - * @deprecated 20.0.0 |
|
| 1447 | - */ |
|
| 1448 | - public function getL10NFactory() { |
|
| 1449 | - return $this->get(IFactory::class); |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - /** |
|
| 1453 | - * get an L10N instance |
|
| 1454 | - * |
|
| 1455 | - * @param string $app appid |
|
| 1456 | - * @param string $lang |
|
| 1457 | - * @return IL10N |
|
| 1458 | - * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1459 | - */ |
|
| 1460 | - public function getL10N($app, $lang = null) { |
|
| 1461 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - /** |
|
| 1465 | - * @return IURLGenerator |
|
| 1466 | - * @deprecated 20.0.0 |
|
| 1467 | - */ |
|
| 1468 | - public function getURLGenerator() { |
|
| 1469 | - return $this->get(IURLGenerator::class); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - /** |
|
| 1473 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1474 | - * getMemCacheFactory() instead. |
|
| 1475 | - * |
|
| 1476 | - * @return ICache |
|
| 1477 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1478 | - */ |
|
| 1479 | - public function getCache() { |
|
| 1480 | - return $this->get(ICache::class); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Returns an \OCP\CacheFactory instance |
|
| 1485 | - * |
|
| 1486 | - * @return \OCP\ICacheFactory |
|
| 1487 | - * @deprecated 20.0.0 |
|
| 1488 | - */ |
|
| 1489 | - public function getMemCacheFactory() { |
|
| 1490 | - return $this->get(ICacheFactory::class); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Returns the current session |
|
| 1495 | - * |
|
| 1496 | - * @return \OCP\IDBConnection |
|
| 1497 | - * @deprecated 20.0.0 |
|
| 1498 | - */ |
|
| 1499 | - public function getDatabaseConnection() { |
|
| 1500 | - return $this->get(IDBConnection::class); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Returns the activity manager |
|
| 1505 | - * |
|
| 1506 | - * @return \OCP\Activity\IManager |
|
| 1507 | - * @deprecated 20.0.0 |
|
| 1508 | - */ |
|
| 1509 | - public function getActivityManager() { |
|
| 1510 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * Returns an job list for controlling background jobs |
|
| 1515 | - * |
|
| 1516 | - * @return IJobList |
|
| 1517 | - * @deprecated 20.0.0 |
|
| 1518 | - */ |
|
| 1519 | - public function getJobList() { |
|
| 1520 | - return $this->get(IJobList::class); |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * Returns a SecureRandom instance |
|
| 1525 | - * |
|
| 1526 | - * @return \OCP\Security\ISecureRandom |
|
| 1527 | - * @deprecated 20.0.0 |
|
| 1528 | - */ |
|
| 1529 | - public function getSecureRandom() { |
|
| 1530 | - return $this->get(ISecureRandom::class); |
|
| 1531 | - } |
|
| 1532 | - |
|
| 1533 | - /** |
|
| 1534 | - * Returns a Crypto instance |
|
| 1535 | - * |
|
| 1536 | - * @return ICrypto |
|
| 1537 | - * @deprecated 20.0.0 |
|
| 1538 | - */ |
|
| 1539 | - public function getCrypto() { |
|
| 1540 | - return $this->get(ICrypto::class); |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - /** |
|
| 1544 | - * Returns a Hasher instance |
|
| 1545 | - * |
|
| 1546 | - * @return IHasher |
|
| 1547 | - * @deprecated 20.0.0 |
|
| 1548 | - */ |
|
| 1549 | - public function getHasher() { |
|
| 1550 | - return $this->get(IHasher::class); |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - /** |
|
| 1554 | - * Get the certificate manager |
|
| 1555 | - * |
|
| 1556 | - * @return \OCP\ICertificateManager |
|
| 1557 | - */ |
|
| 1558 | - public function getCertificateManager() { |
|
| 1559 | - return $this->get(ICertificateManager::class); |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - /** |
|
| 1563 | - * Get the manager for temporary files and folders |
|
| 1564 | - * |
|
| 1565 | - * @return \OCP\ITempManager |
|
| 1566 | - * @deprecated 20.0.0 |
|
| 1567 | - */ |
|
| 1568 | - public function getTempManager() { |
|
| 1569 | - return $this->get(ITempManager::class); |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - /** |
|
| 1573 | - * Get the app manager |
|
| 1574 | - * |
|
| 1575 | - * @return \OCP\App\IAppManager |
|
| 1576 | - * @deprecated 20.0.0 |
|
| 1577 | - */ |
|
| 1578 | - public function getAppManager() { |
|
| 1579 | - return $this->get(IAppManager::class); |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - /** |
|
| 1583 | - * Creates a new mailer |
|
| 1584 | - * |
|
| 1585 | - * @return IMailer |
|
| 1586 | - * @deprecated 20.0.0 |
|
| 1587 | - */ |
|
| 1588 | - public function getMailer() { |
|
| 1589 | - return $this->get(IMailer::class); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * Get the webroot |
|
| 1594 | - * |
|
| 1595 | - * @return string |
|
| 1596 | - * @deprecated 20.0.0 |
|
| 1597 | - */ |
|
| 1598 | - public function getWebRoot() { |
|
| 1599 | - return $this->webRoot; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - /** |
|
| 1603 | - * Get the locking provider |
|
| 1604 | - * |
|
| 1605 | - * @return ILockingProvider |
|
| 1606 | - * @since 8.1.0 |
|
| 1607 | - * @deprecated 20.0.0 |
|
| 1608 | - */ |
|
| 1609 | - public function getLockingProvider() { |
|
| 1610 | - return $this->get(ILockingProvider::class); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - /** |
|
| 1614 | - * Get the MimeTypeDetector |
|
| 1615 | - * |
|
| 1616 | - * @return IMimeTypeDetector |
|
| 1617 | - * @deprecated 20.0.0 |
|
| 1618 | - */ |
|
| 1619 | - public function getMimeTypeDetector() { |
|
| 1620 | - return $this->get(IMimeTypeDetector::class); |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * Get the MimeTypeLoader |
|
| 1625 | - * |
|
| 1626 | - * @return IMimeTypeLoader |
|
| 1627 | - * @deprecated 20.0.0 |
|
| 1628 | - */ |
|
| 1629 | - public function getMimeTypeLoader() { |
|
| 1630 | - return $this->get(IMimeTypeLoader::class); |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - /** |
|
| 1634 | - * Get the Notification Manager |
|
| 1635 | - * |
|
| 1636 | - * @return \OCP\Notification\IManager |
|
| 1637 | - * @since 8.2.0 |
|
| 1638 | - * @deprecated 20.0.0 |
|
| 1639 | - */ |
|
| 1640 | - public function getNotificationManager() { |
|
| 1641 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 1642 | - } |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1646 | - * @deprecated 20.0.0 |
|
| 1647 | - */ |
|
| 1648 | - public function getThemingDefaults() { |
|
| 1649 | - return $this->get('ThemingDefaults'); |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - /** |
|
| 1653 | - * @return \OC\IntegrityCheck\Checker |
|
| 1654 | - * @deprecated 20.0.0 |
|
| 1655 | - */ |
|
| 1656 | - public function getIntegrityCodeChecker() { |
|
| 1657 | - return $this->get('IntegrityCodeChecker'); |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * @return CsrfTokenManager |
|
| 1662 | - * @deprecated 20.0.0 |
|
| 1663 | - */ |
|
| 1664 | - public function getCsrfTokenManager() { |
|
| 1665 | - return $this->get(CsrfTokenManager::class); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * @return ContentSecurityPolicyNonceManager |
|
| 1670 | - * @deprecated 20.0.0 |
|
| 1671 | - */ |
|
| 1672 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1673 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1674 | - } |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * @return \OCP\Settings\IManager |
|
| 1678 | - * @deprecated 20.0.0 |
|
| 1679 | - */ |
|
| 1680 | - public function getSettingsManager() { |
|
| 1681 | - return $this->get(\OC\Settings\Manager::class); |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * @return \OCP\Files\IAppData |
|
| 1686 | - * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1687 | - */ |
|
| 1688 | - public function getAppDataDir($app) { |
|
| 1689 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1690 | - return $factory->get($app); |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1695 | - * @deprecated 20.0.0 |
|
| 1696 | - */ |
|
| 1697 | - public function getCloudIdManager() { |
|
| 1698 | - return $this->get(ICloudIdManager::class); |
|
| 1699 | - } |
|
| 1282 | + $this->registerAlias(\OCP\Security\Ip\IFactory::class, \OC\Security\Ip\Factory::class); |
|
| 1283 | + |
|
| 1284 | + $this->registerAlias(IRichTextFormatter::class, \OC\RichObjectStrings\RichTextFormatter::class); |
|
| 1285 | + |
|
| 1286 | + $this->registerAlias(ISignatureManager::class, SignatureManager::class); |
|
| 1287 | + |
|
| 1288 | + $this->connectDispatcher(); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + public function boot() { |
|
| 1292 | + /** @var HookConnector $hookConnector */ |
|
| 1293 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1294 | + $hookConnector->viewToNode(); |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + private function connectDispatcher(): void { |
|
| 1298 | + /** @var IEventDispatcher $eventDispatcher */ |
|
| 1299 | + $eventDispatcher = $this->get(IEventDispatcher::class); |
|
| 1300 | + $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1301 | + $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1302 | + $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class); |
|
| 1303 | + $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class); |
|
| 1304 | + |
|
| 1305 | + FilesMetadataManager::loadListeners($eventDispatcher); |
|
| 1306 | + GenerateBlurhashMetadata::loadListeners($eventDispatcher); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * @return \OCP\Contacts\IManager |
|
| 1311 | + * @deprecated 20.0.0 |
|
| 1312 | + */ |
|
| 1313 | + public function getContactsManager() { |
|
| 1314 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * @return \OC\Encryption\Manager |
|
| 1319 | + * @deprecated 20.0.0 |
|
| 1320 | + */ |
|
| 1321 | + public function getEncryptionManager() { |
|
| 1322 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * @return \OC\Encryption\File |
|
| 1327 | + * @deprecated 20.0.0 |
|
| 1328 | + */ |
|
| 1329 | + public function getEncryptionFilesHelper() { |
|
| 1330 | + return $this->get(IFile::class); |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + /** |
|
| 1334 | + * The current request object holding all information about the request |
|
| 1335 | + * currently being processed is returned from this method. |
|
| 1336 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1337 | + * |
|
| 1338 | + * @return \OCP\IRequest |
|
| 1339 | + * @deprecated 20.0.0 |
|
| 1340 | + */ |
|
| 1341 | + public function getRequest() { |
|
| 1342 | + return $this->get(IRequest::class); |
|
| 1343 | + } |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * Returns the root folder of ownCloud's data directory |
|
| 1347 | + * |
|
| 1348 | + * @return IRootFolder |
|
| 1349 | + * @deprecated 20.0.0 |
|
| 1350 | + */ |
|
| 1351 | + public function getRootFolder() { |
|
| 1352 | + return $this->get(IRootFolder::class); |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + /** |
|
| 1356 | + * Returns the root folder of ownCloud's data directory |
|
| 1357 | + * This is the lazy variant so this gets only initialized once it |
|
| 1358 | + * is actually used. |
|
| 1359 | + * |
|
| 1360 | + * @return IRootFolder |
|
| 1361 | + * @deprecated 20.0.0 |
|
| 1362 | + */ |
|
| 1363 | + public function getLazyRootFolder() { |
|
| 1364 | + return $this->get(IRootFolder::class); |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * Returns a view to ownCloud's files folder |
|
| 1369 | + * |
|
| 1370 | + * @param string $userId user ID |
|
| 1371 | + * @return \OCP\Files\Folder|null |
|
| 1372 | + * @deprecated 20.0.0 |
|
| 1373 | + */ |
|
| 1374 | + public function getUserFolder($userId = null) { |
|
| 1375 | + if ($userId === null) { |
|
| 1376 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1377 | + if (!$user) { |
|
| 1378 | + return null; |
|
| 1379 | + } |
|
| 1380 | + $userId = $user->getUID(); |
|
| 1381 | + } |
|
| 1382 | + $root = $this->get(IRootFolder::class); |
|
| 1383 | + return $root->getUserFolder($userId); |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + /** |
|
| 1387 | + * @return \OC\User\Manager |
|
| 1388 | + * @deprecated 20.0.0 |
|
| 1389 | + */ |
|
| 1390 | + public function getUserManager() { |
|
| 1391 | + return $this->get(IUserManager::class); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * @return \OC\Group\Manager |
|
| 1396 | + * @deprecated 20.0.0 |
|
| 1397 | + */ |
|
| 1398 | + public function getGroupManager() { |
|
| 1399 | + return $this->get(IGroupManager::class); |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * @return \OC\User\Session |
|
| 1404 | + * @deprecated 20.0.0 |
|
| 1405 | + */ |
|
| 1406 | + public function getUserSession() { |
|
| 1407 | + return $this->get(IUserSession::class); |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + /** |
|
| 1411 | + * @return \OCP\ISession |
|
| 1412 | + * @deprecated 20.0.0 |
|
| 1413 | + */ |
|
| 1414 | + public function getSession() { |
|
| 1415 | + return $this->get(Session::class)->getSession(); |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * @param \OCP\ISession $session |
|
| 1420 | + * @return void |
|
| 1421 | + */ |
|
| 1422 | + public function setSession(\OCP\ISession $session) { |
|
| 1423 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1424 | + $this->get(Session::class)->setSession($session); |
|
| 1425 | + $this->get(Store::class)->setSession($session); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * @return \OCP\IConfig |
|
| 1430 | + * @deprecated 20.0.0 |
|
| 1431 | + */ |
|
| 1432 | + public function getConfig() { |
|
| 1433 | + return $this->get(AllConfig::class); |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + /** |
|
| 1437 | + * @return \OC\SystemConfig |
|
| 1438 | + * @deprecated 20.0.0 |
|
| 1439 | + */ |
|
| 1440 | + public function getSystemConfig() { |
|
| 1441 | + return $this->get(SystemConfig::class); |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * @return IFactory |
|
| 1446 | + * @deprecated 20.0.0 |
|
| 1447 | + */ |
|
| 1448 | + public function getL10NFactory() { |
|
| 1449 | + return $this->get(IFactory::class); |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + /** |
|
| 1453 | + * get an L10N instance |
|
| 1454 | + * |
|
| 1455 | + * @param string $app appid |
|
| 1456 | + * @param string $lang |
|
| 1457 | + * @return IL10N |
|
| 1458 | + * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort |
|
| 1459 | + */ |
|
| 1460 | + public function getL10N($app, $lang = null) { |
|
| 1461 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + /** |
|
| 1465 | + * @return IURLGenerator |
|
| 1466 | + * @deprecated 20.0.0 |
|
| 1467 | + */ |
|
| 1468 | + public function getURLGenerator() { |
|
| 1469 | + return $this->get(IURLGenerator::class); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + /** |
|
| 1473 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1474 | + * getMemCacheFactory() instead. |
|
| 1475 | + * |
|
| 1476 | + * @return ICache |
|
| 1477 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1478 | + */ |
|
| 1479 | + public function getCache() { |
|
| 1480 | + return $this->get(ICache::class); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Returns an \OCP\CacheFactory instance |
|
| 1485 | + * |
|
| 1486 | + * @return \OCP\ICacheFactory |
|
| 1487 | + * @deprecated 20.0.0 |
|
| 1488 | + */ |
|
| 1489 | + public function getMemCacheFactory() { |
|
| 1490 | + return $this->get(ICacheFactory::class); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Returns the current session |
|
| 1495 | + * |
|
| 1496 | + * @return \OCP\IDBConnection |
|
| 1497 | + * @deprecated 20.0.0 |
|
| 1498 | + */ |
|
| 1499 | + public function getDatabaseConnection() { |
|
| 1500 | + return $this->get(IDBConnection::class); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Returns the activity manager |
|
| 1505 | + * |
|
| 1506 | + * @return \OCP\Activity\IManager |
|
| 1507 | + * @deprecated 20.0.0 |
|
| 1508 | + */ |
|
| 1509 | + public function getActivityManager() { |
|
| 1510 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * Returns an job list for controlling background jobs |
|
| 1515 | + * |
|
| 1516 | + * @return IJobList |
|
| 1517 | + * @deprecated 20.0.0 |
|
| 1518 | + */ |
|
| 1519 | + public function getJobList() { |
|
| 1520 | + return $this->get(IJobList::class); |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * Returns a SecureRandom instance |
|
| 1525 | + * |
|
| 1526 | + * @return \OCP\Security\ISecureRandom |
|
| 1527 | + * @deprecated 20.0.0 |
|
| 1528 | + */ |
|
| 1529 | + public function getSecureRandom() { |
|
| 1530 | + return $this->get(ISecureRandom::class); |
|
| 1531 | + } |
|
| 1532 | + |
|
| 1533 | + /** |
|
| 1534 | + * Returns a Crypto instance |
|
| 1535 | + * |
|
| 1536 | + * @return ICrypto |
|
| 1537 | + * @deprecated 20.0.0 |
|
| 1538 | + */ |
|
| 1539 | + public function getCrypto() { |
|
| 1540 | + return $this->get(ICrypto::class); |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + /** |
|
| 1544 | + * Returns a Hasher instance |
|
| 1545 | + * |
|
| 1546 | + * @return IHasher |
|
| 1547 | + * @deprecated 20.0.0 |
|
| 1548 | + */ |
|
| 1549 | + public function getHasher() { |
|
| 1550 | + return $this->get(IHasher::class); |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + /** |
|
| 1554 | + * Get the certificate manager |
|
| 1555 | + * |
|
| 1556 | + * @return \OCP\ICertificateManager |
|
| 1557 | + */ |
|
| 1558 | + public function getCertificateManager() { |
|
| 1559 | + return $this->get(ICertificateManager::class); |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + /** |
|
| 1563 | + * Get the manager for temporary files and folders |
|
| 1564 | + * |
|
| 1565 | + * @return \OCP\ITempManager |
|
| 1566 | + * @deprecated 20.0.0 |
|
| 1567 | + */ |
|
| 1568 | + public function getTempManager() { |
|
| 1569 | + return $this->get(ITempManager::class); |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + /** |
|
| 1573 | + * Get the app manager |
|
| 1574 | + * |
|
| 1575 | + * @return \OCP\App\IAppManager |
|
| 1576 | + * @deprecated 20.0.0 |
|
| 1577 | + */ |
|
| 1578 | + public function getAppManager() { |
|
| 1579 | + return $this->get(IAppManager::class); |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + /** |
|
| 1583 | + * Creates a new mailer |
|
| 1584 | + * |
|
| 1585 | + * @return IMailer |
|
| 1586 | + * @deprecated 20.0.0 |
|
| 1587 | + */ |
|
| 1588 | + public function getMailer() { |
|
| 1589 | + return $this->get(IMailer::class); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * Get the webroot |
|
| 1594 | + * |
|
| 1595 | + * @return string |
|
| 1596 | + * @deprecated 20.0.0 |
|
| 1597 | + */ |
|
| 1598 | + public function getWebRoot() { |
|
| 1599 | + return $this->webRoot; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + /** |
|
| 1603 | + * Get the locking provider |
|
| 1604 | + * |
|
| 1605 | + * @return ILockingProvider |
|
| 1606 | + * @since 8.1.0 |
|
| 1607 | + * @deprecated 20.0.0 |
|
| 1608 | + */ |
|
| 1609 | + public function getLockingProvider() { |
|
| 1610 | + return $this->get(ILockingProvider::class); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + /** |
|
| 1614 | + * Get the MimeTypeDetector |
|
| 1615 | + * |
|
| 1616 | + * @return IMimeTypeDetector |
|
| 1617 | + * @deprecated 20.0.0 |
|
| 1618 | + */ |
|
| 1619 | + public function getMimeTypeDetector() { |
|
| 1620 | + return $this->get(IMimeTypeDetector::class); |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * Get the MimeTypeLoader |
|
| 1625 | + * |
|
| 1626 | + * @return IMimeTypeLoader |
|
| 1627 | + * @deprecated 20.0.0 |
|
| 1628 | + */ |
|
| 1629 | + public function getMimeTypeLoader() { |
|
| 1630 | + return $this->get(IMimeTypeLoader::class); |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + /** |
|
| 1634 | + * Get the Notification Manager |
|
| 1635 | + * |
|
| 1636 | + * @return \OCP\Notification\IManager |
|
| 1637 | + * @since 8.2.0 |
|
| 1638 | + * @deprecated 20.0.0 |
|
| 1639 | + */ |
|
| 1640 | + public function getNotificationManager() { |
|
| 1641 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 1642 | + } |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1646 | + * @deprecated 20.0.0 |
|
| 1647 | + */ |
|
| 1648 | + public function getThemingDefaults() { |
|
| 1649 | + return $this->get('ThemingDefaults'); |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + /** |
|
| 1653 | + * @return \OC\IntegrityCheck\Checker |
|
| 1654 | + * @deprecated 20.0.0 |
|
| 1655 | + */ |
|
| 1656 | + public function getIntegrityCodeChecker() { |
|
| 1657 | + return $this->get('IntegrityCodeChecker'); |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * @return CsrfTokenManager |
|
| 1662 | + * @deprecated 20.0.0 |
|
| 1663 | + */ |
|
| 1664 | + public function getCsrfTokenManager() { |
|
| 1665 | + return $this->get(CsrfTokenManager::class); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + /** |
|
| 1669 | + * @return ContentSecurityPolicyNonceManager |
|
| 1670 | + * @deprecated 20.0.0 |
|
| 1671 | + */ |
|
| 1672 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1673 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 1674 | + } |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * @return \OCP\Settings\IManager |
|
| 1678 | + * @deprecated 20.0.0 |
|
| 1679 | + */ |
|
| 1680 | + public function getSettingsManager() { |
|
| 1681 | + return $this->get(\OC\Settings\Manager::class); |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * @return \OCP\Files\IAppData |
|
| 1686 | + * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead |
|
| 1687 | + */ |
|
| 1688 | + public function getAppDataDir($app) { |
|
| 1689 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 1690 | + return $factory->get($app); |
|
| 1691 | + } |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1695 | + * @deprecated 20.0.0 |
|
| 1696 | + */ |
|
| 1697 | + public function getCloudIdManager() { |
|
| 1698 | + return $this->get(ICloudIdManager::class); |
|
| 1699 | + } |
|
| 1700 | 1700 | } |
@@ -40,1136 +40,1136 @@ |
||
| 40 | 40 | * OC_autoload! |
| 41 | 41 | */ |
| 42 | 42 | class OC { |
| 43 | - /** |
|
| 44 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 45 | - */ |
|
| 46 | - public static string $SERVERROOT = ''; |
|
| 47 | - /** |
|
| 48 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 49 | - */ |
|
| 50 | - private static string $SUBURI = ''; |
|
| 51 | - /** |
|
| 52 | - * the Nextcloud root path for http requests (e.g. /nextcloud) |
|
| 53 | - */ |
|
| 54 | - public static string $WEBROOT = ''; |
|
| 55 | - /** |
|
| 56 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 57 | - * web path in 'url' |
|
| 58 | - */ |
|
| 59 | - public static array $APPSROOTS = []; |
|
| 60 | - |
|
| 61 | - public static string $configDir; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * requested app |
|
| 65 | - */ |
|
| 66 | - public static string $REQUESTEDAPP = ''; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * check if Nextcloud runs in cli mode |
|
| 70 | - */ |
|
| 71 | - public static bool $CLI = false; |
|
| 72 | - |
|
| 73 | - public static \Composer\Autoload\ClassLoader $composerAutoloader; |
|
| 74 | - |
|
| 75 | - public static \OC\Server $server; |
|
| 76 | - |
|
| 77 | - private static \OC\Config $config; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 81 | - * the app path list is empty or contains an invalid path |
|
| 82 | - */ |
|
| 83 | - public static function initPaths(): void { |
|
| 84 | - if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 85 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 86 | - } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 87 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 88 | - } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 89 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 90 | - } else { |
|
| 91 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 92 | - } |
|
| 93 | - self::$config = new \OC\Config(self::$configDir); |
|
| 94 | - |
|
| 95 | - OC::$SUBURI = str_replace('\\', '/', substr(realpath($_SERVER['SCRIPT_FILENAME'] ?? ''), strlen(OC::$SERVERROOT))); |
|
| 96 | - /** |
|
| 97 | - * FIXME: The following lines are required because we can't yet instantiate |
|
| 98 | - * Server::get(\OCP\IRequest::class) since \OC::$server does not yet exist. |
|
| 99 | - */ |
|
| 100 | - $params = [ |
|
| 101 | - 'server' => [ |
|
| 102 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'] ?? null, |
|
| 103 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'] ?? null, |
|
| 104 | - ], |
|
| 105 | - ]; |
|
| 106 | - if (isset($_SERVER['REMOTE_ADDR'])) { |
|
| 107 | - $params['server']['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; |
|
| 108 | - } |
|
| 109 | - $fakeRequest = new \OC\AppFramework\Http\Request( |
|
| 110 | - $params, |
|
| 111 | - new \OC\AppFramework\Http\RequestId($_SERVER['UNIQUE_ID'] ?? '', new \OC\Security\SecureRandom()), |
|
| 112 | - new \OC\AllConfig(new \OC\SystemConfig(self::$config)) |
|
| 113 | - ); |
|
| 114 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 115 | - if (substr($scriptName, -1) == '/') { |
|
| 116 | - $scriptName .= 'index.php'; |
|
| 117 | - //make sure suburi follows the same rules as scriptName |
|
| 118 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 119 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 120 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 121 | - } |
|
| 122 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (OC::$CLI) { |
|
| 127 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 128 | - } else { |
|
| 129 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 130 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 131 | - |
|
| 132 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 133 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 134 | - } |
|
| 135 | - } else { |
|
| 136 | - // The scriptName is not ending with OC::$SUBURI |
|
| 137 | - // This most likely means that we are calling from CLI. |
|
| 138 | - // However some cron jobs still need to generate |
|
| 139 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 140 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 144 | - // slash which is required by URL generation. |
|
| 145 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT |
|
| 146 | - && substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 147 | - header('Location: ' . \OC::$WEBROOT . '/'); |
|
| 148 | - exit(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // search the apps folder |
|
| 153 | - $config_paths = self::$config->getValue('apps_paths', []); |
|
| 154 | - if (!empty($config_paths)) { |
|
| 155 | - foreach ($config_paths as $paths) { |
|
| 156 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 157 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 158 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 159 | - OC::$APPSROOTS[] = $paths; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 163 | - OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if (empty(OC::$APPSROOTS)) { |
|
| 167 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 168 | - . '. You can also configure the location in the config.php file.'); |
|
| 169 | - } |
|
| 170 | - $paths = []; |
|
| 171 | - foreach (OC::$APPSROOTS as $path) { |
|
| 172 | - $paths[] = $path['path']; |
|
| 173 | - if (!is_dir($path['path'])) { |
|
| 174 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 175 | - . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // set the right include path |
|
| 180 | - set_include_path( |
|
| 181 | - implode(PATH_SEPARATOR, $paths) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - public static function checkConfig(): void { |
|
| 186 | - // Create config if it does not already exist |
|
| 187 | - $configFilePath = self::$configDir . '/config.php'; |
|
| 188 | - if (!file_exists($configFilePath)) { |
|
| 189 | - @touch($configFilePath); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // Check if config is writable |
|
| 193 | - $configFileWritable = is_writable($configFilePath); |
|
| 194 | - $configReadOnly = Server::get(IConfig::class)->getSystemValueBool('config_is_read_only'); |
|
| 195 | - if (!$configFileWritable && !$configReadOnly |
|
| 196 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 197 | - $urlGenerator = Server::get(IURLGenerator::class); |
|
| 198 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 199 | - |
|
| 200 | - if (self::$CLI) { |
|
| 201 | - echo $l->t('Cannot write into "config" directory!') . "\n"; |
|
| 202 | - echo $l->t('This can usually be fixed by giving the web server write access to the config directory.') . "\n"; |
|
| 203 | - echo "\n"; |
|
| 204 | - echo $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . "\n"; |
|
| 205 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]) . "\n"; |
|
| 206 | - exit; |
|
| 207 | - } else { |
|
| 208 | - Server::get(ITemplateManager::class)->printErrorPage( |
|
| 209 | - $l->t('Cannot write into "config" directory!'), |
|
| 210 | - $l->t('This can usually be fixed by giving the web server write access to the config directory.') . ' ' |
|
| 211 | - . $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . ' ' |
|
| 212 | - . $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 213 | - 503 |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public static function checkInstalled(\OC\SystemConfig $systemConfig): void { |
|
| 220 | - if (defined('OC_CONSOLE')) { |
|
| 221 | - return; |
|
| 222 | - } |
|
| 223 | - // Redirect to installer if not installed |
|
| 224 | - if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 225 | - if (OC::$CLI) { |
|
| 226 | - throw new Exception('Not installed'); |
|
| 227 | - } else { |
|
| 228 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 229 | - header('Location: ' . $url); |
|
| 230 | - } |
|
| 231 | - exit(); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig): void { |
|
| 236 | - // Allow ajax update script to execute without being stopped |
|
| 237 | - if (((bool)$systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 238 | - // send http status 503 |
|
| 239 | - http_response_code(503); |
|
| 240 | - header('X-Nextcloud-Maintenance-Mode: 1'); |
|
| 241 | - header('Retry-After: 120'); |
|
| 242 | - |
|
| 243 | - // render error page |
|
| 244 | - $template = Server::get(ITemplateManager::class)->getTemplate('', 'update.user', 'guest'); |
|
| 245 | - \OCP\Util::addScript('core', 'maintenance'); |
|
| 246 | - \OCP\Util::addStyle('core', 'guest'); |
|
| 247 | - $template->printPage(); |
|
| 248 | - die(); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Prints the upgrade page |
|
| 254 | - */ |
|
| 255 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { |
|
| 256 | - $cliUpgradeLink = $systemConfig->getValue('upgrade.cli-upgrade-link', ''); |
|
| 257 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 258 | - $tooBig = false; |
|
| 259 | - if (!$disableWebUpdater) { |
|
| 260 | - $apps = Server::get(\OCP\App\IAppManager::class); |
|
| 261 | - if ($apps->isEnabledForAnyone('user_ldap')) { |
|
| 262 | - $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
| 263 | - |
|
| 264 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 265 | - ->from('ldap_user_mapping') |
|
| 266 | - ->executeQuery(); |
|
| 267 | - $row = $result->fetch(); |
|
| 268 | - $result->closeCursor(); |
|
| 269 | - |
|
| 270 | - $tooBig = ($row['user_count'] > 50); |
|
| 271 | - } |
|
| 272 | - if (!$tooBig && $apps->isEnabledForAnyone('user_saml')) { |
|
| 273 | - $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
| 274 | - |
|
| 275 | - $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 276 | - ->from('user_saml_users') |
|
| 277 | - ->executeQuery(); |
|
| 278 | - $row = $result->fetch(); |
|
| 279 | - $result->closeCursor(); |
|
| 280 | - |
|
| 281 | - $tooBig = ($row['user_count'] > 50); |
|
| 282 | - } |
|
| 283 | - if (!$tooBig) { |
|
| 284 | - // count users |
|
| 285 | - $totalUsers = Server::get(\OCP\IUserManager::class)->countUsersTotal(51); |
|
| 286 | - $tooBig = ($totalUsers > 50); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) |
|
| 290 | - && $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 291 | - |
|
| 292 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 293 | - // send http status 503 |
|
| 294 | - http_response_code(503); |
|
| 295 | - header('Retry-After: 120'); |
|
| 296 | - |
|
| 297 | - $serverVersion = \OCP\Server::get(\OCP\ServerVersion::class); |
|
| 298 | - |
|
| 299 | - // render error page |
|
| 300 | - $template = Server::get(ITemplateManager::class)->getTemplate('', 'update.use-cli', 'guest'); |
|
| 301 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 302 | - $template->assign('version', $serverVersion->getVersionString()); |
|
| 303 | - $template->assign('tooBig', $tooBig); |
|
| 304 | - $template->assign('cliUpgradeLink', $cliUpgradeLink); |
|
| 305 | - |
|
| 306 | - $template->printPage(); |
|
| 307 | - die(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // check whether this is a core update or apps update |
|
| 311 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 312 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 313 | - |
|
| 314 | - // if not a core upgrade, then it's apps upgrade |
|
| 315 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 316 | - |
|
| 317 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 318 | - $systemConfig->setValue('theme', ''); |
|
| 319 | - \OCP\Util::addScript('core', 'common'); |
|
| 320 | - \OCP\Util::addScript('core', 'main'); |
|
| 321 | - \OCP\Util::addTranslations('core'); |
|
| 322 | - \OCP\Util::addScript('core', 'update'); |
|
| 323 | - |
|
| 324 | - /** @var \OC\App\AppManager $appManager */ |
|
| 325 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 326 | - |
|
| 327 | - $tmpl = Server::get(ITemplateManager::class)->getTemplate('', 'update.admin', 'guest'); |
|
| 328 | - $tmpl->assign('version', \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString()); |
|
| 329 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 330 | - |
|
| 331 | - // get third party apps |
|
| 332 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 333 | - $ocVersion = implode('.', $ocVersion); |
|
| 334 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 335 | - $incompatibleOverwrites = $systemConfig->getValue('app_install_overwrite', []); |
|
| 336 | - $incompatibleShippedApps = []; |
|
| 337 | - $incompatibleDisabledApps = []; |
|
| 338 | - foreach ($incompatibleApps as $appInfo) { |
|
| 339 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 340 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 341 | - } |
|
| 342 | - if (!in_array($appInfo['id'], $incompatibleOverwrites)) { |
|
| 343 | - $incompatibleDisabledApps[] = $appInfo; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - if (!empty($incompatibleShippedApps)) { |
|
| 348 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('core'); |
|
| 349 | - $hint = $l->t('Application %1$s is not present or has a non-compatible version with this server. Please check the apps directory.', [implode(', ', $incompatibleShippedApps)]); |
|
| 350 | - throw new \OCP\HintException('Application ' . implode(', ', $incompatibleShippedApps) . ' is not present or has a non-compatible version with this server. Please check the apps directory.', $hint); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 354 | - $tmpl->assign('incompatibleAppsList', $incompatibleDisabledApps); |
|
| 355 | - try { |
|
| 356 | - $defaults = new \OC_Defaults(); |
|
| 357 | - $tmpl->assign('productName', $defaults->getName()); |
|
| 358 | - } catch (Throwable $error) { |
|
| 359 | - $tmpl->assign('productName', 'Nextcloud'); |
|
| 360 | - } |
|
| 361 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 362 | - $tmpl->printPage(); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - public static function initSession(): void { |
|
| 366 | - $request = Server::get(IRequest::class); |
|
| 367 | - |
|
| 368 | - // TODO: Temporary disabled again to solve issues with CalDAV/CardDAV clients like DAVx5 that use cookies |
|
| 369 | - // TODO: See https://github.com/nextcloud/server/issues/37277#issuecomment-1476366147 and the other comments |
|
| 370 | - // TODO: for further information. |
|
| 371 | - // $isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 || strpos($request->getRequestUri(), '/remote.php/webdav') === 0; |
|
| 372 | - // if ($request->getHeader('Authorization') !== '' && is_null($request->getCookie('cookie_test')) && $isDavRequest && !isset($_COOKIE['nc_session_id'])) { |
|
| 373 | - // setcookie('cookie_test', 'test', time() + 3600); |
|
| 374 | - // // Do not initialize the session if a request is authenticated directly |
|
| 375 | - // // unless there is a session cookie already sent along |
|
| 376 | - // return; |
|
| 377 | - // } |
|
| 378 | - |
|
| 379 | - if ($request->getServerProtocol() === 'https') { |
|
| 380 | - ini_set('session.cookie_secure', 'true'); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - // prevents javascript from accessing php session cookies |
|
| 384 | - ini_set('session.cookie_httponly', 'true'); |
|
| 385 | - |
|
| 386 | - // Do not initialize sessions for 'status.php' requests |
|
| 387 | - // Monitoring endpoints can quickly flood session handlers |
|
| 388 | - // and 'status.php' doesn't require sessions anyway |
|
| 389 | - if (str_ends_with($request->getScriptName(), '/status.php')) { |
|
| 390 | - return; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // set the cookie path to the Nextcloud directory |
|
| 394 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 395 | - ini_set('session.cookie_path', $cookie_path); |
|
| 396 | - |
|
| 397 | - // set the cookie domain to the Nextcloud domain |
|
| 398 | - $cookie_domain = self::$config->getValue('cookie_domain', ''); |
|
| 399 | - if ($cookie_domain) { |
|
| 400 | - ini_set('session.cookie_domain', $cookie_domain); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - // Let the session name be changed in the initSession Hook |
|
| 404 | - $sessionName = OC_Util::getInstanceId(); |
|
| 405 | - |
|
| 406 | - try { |
|
| 407 | - $logger = null; |
|
| 408 | - if (Server::get(\OC\SystemConfig::class)->getValue('installed', false)) { |
|
| 409 | - $logger = logger('core'); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // set the session name to the instance id - which is unique |
|
| 413 | - $session = new \OC\Session\Internal( |
|
| 414 | - $sessionName, |
|
| 415 | - $logger, |
|
| 416 | - ); |
|
| 417 | - |
|
| 418 | - $cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class); |
|
| 419 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 420 | - self::$server->setSession($session); |
|
| 421 | - |
|
| 422 | - // if session can't be started break with http 500 error |
|
| 423 | - } catch (Exception $e) { |
|
| 424 | - Server::get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'base','exception' => $e]); |
|
| 425 | - //show the user a detailed error page |
|
| 426 | - Server::get(ITemplateManager::class)->printExceptionErrorPage($e, 500); |
|
| 427 | - die(); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - //try to set the session lifetime |
|
| 431 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 432 | - |
|
| 433 | - // session timeout |
|
| 434 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 435 | - if (isset($_COOKIE[session_name()])) { |
|
| 436 | - setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 437 | - } |
|
| 438 | - Server::get(IUserSession::class)->logout(); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - if (!self::hasSessionRelaxedExpiry()) { |
|
| 442 | - $session->set('LAST_ACTIVITY', time()); |
|
| 443 | - } |
|
| 444 | - $session->close(); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - private static function getSessionLifeTime(): int { |
|
| 448 | - return Server::get(\OC\AllConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return bool true if the session expiry should only be done by gc instead of an explicit timeout |
|
| 453 | - */ |
|
| 454 | - public static function hasSessionRelaxedExpiry(): bool { |
|
| 455 | - return Server::get(\OC\AllConfig::class)->getSystemValueBool('session_relaxed_expiry', false); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Try to set some values to the required Nextcloud default |
|
| 460 | - */ |
|
| 461 | - public static function setRequiredIniValues(): void { |
|
| 462 | - // Don't display errors and log them |
|
| 463 | - @ini_set('display_errors', '0'); |
|
| 464 | - @ini_set('log_errors', '1'); |
|
| 465 | - |
|
| 466 | - // Try to configure php to enable big file uploads. |
|
| 467 | - // This doesn't work always depending on the webserver and php configuration. |
|
| 468 | - // Let's try to overwrite some defaults if they are smaller than 1 hour |
|
| 469 | - |
|
| 470 | - if (intval(@ini_get('max_execution_time') ?: 0) < 3600) { |
|
| 471 | - @ini_set('max_execution_time', strval(3600)); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - if (intval(@ini_get('max_input_time') ?: 0) < 3600) { |
|
| 475 | - @ini_set('max_input_time', strval(3600)); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - // Try to set the maximum execution time to the largest time limit we have |
|
| 479 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 480 | - @set_time_limit(max(intval(@ini_get('max_execution_time')), intval(@ini_get('max_input_time')))); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - @ini_set('default_charset', 'UTF-8'); |
|
| 484 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Send the same site cookies |
|
| 489 | - */ |
|
| 490 | - private static function sendSameSiteCookies(): void { |
|
| 491 | - $cookieParams = session_get_cookie_params(); |
|
| 492 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 493 | - $policies = [ |
|
| 494 | - 'lax', |
|
| 495 | - 'strict', |
|
| 496 | - ]; |
|
| 497 | - |
|
| 498 | - // Append __Host to the cookie if it meets the requirements |
|
| 499 | - $cookiePrefix = ''; |
|
| 500 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 501 | - $cookiePrefix = '__Host-'; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - foreach ($policies as $policy) { |
|
| 505 | - header( |
|
| 506 | - sprintf( |
|
| 507 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 508 | - $cookiePrefix, |
|
| 509 | - $policy, |
|
| 510 | - $cookieParams['path'], |
|
| 511 | - $policy |
|
| 512 | - ), |
|
| 513 | - false |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 520 | - * be set in every request if cookies are sent to add a second level of |
|
| 521 | - * defense against CSRF. |
|
| 522 | - * |
|
| 523 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 524 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 525 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 526 | - */ |
|
| 527 | - private static function performSameSiteCookieProtection(IConfig $config): void { |
|
| 528 | - $request = Server::get(IRequest::class); |
|
| 529 | - |
|
| 530 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 531 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 532 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 533 | - // here. |
|
| 534 | - $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
| 535 | - |
|
| 536 | - // Fallback, if csrf.optout is unset |
|
| 537 | - if (!is_array($incompatibleUserAgents)) { |
|
| 538 | - $incompatibleUserAgents = [ |
|
| 539 | - // OS X Finder |
|
| 540 | - '/^WebDAVFS/', |
|
| 541 | - // Windows webdav drive |
|
| 542 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
| 543 | - ]; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 547 | - return; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - if (count($_COOKIE) > 0) { |
|
| 551 | - $requestUri = $request->getScriptName(); |
|
| 552 | - $processingScript = explode('/', $requestUri); |
|
| 553 | - $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 554 | - |
|
| 555 | - if ($processingScript === 'index.php' // index.php routes are handled in the middleware |
|
| 556 | - || $processingScript === 'cron.php' // and cron.php does not need any authentication at all |
|
| 557 | - || $processingScript === 'public.php' // For public.php, auth for password protected shares is done in the PublicAuth plugin |
|
| 558 | - ) { |
|
| 559 | - return; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - // All other endpoints require the lax and the strict cookie |
|
| 563 | - if (!$request->passesStrictCookieCheck()) { |
|
| 564 | - logger('core')->warning('Request does not pass strict cookie check'); |
|
| 565 | - self::sendSameSiteCookies(); |
|
| 566 | - // Debug mode gets access to the resources without strict cookie |
|
| 567 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 568 | - if (!$config->getSystemValueBool('debug', false)) { |
|
| 569 | - http_response_code(\OCP\AppFramework\Http::STATUS_PRECONDITION_FAILED); |
|
| 570 | - header('Content-Type: application/json'); |
|
| 571 | - echo json_encode(['error' => 'Strict Cookie has not been found in request']); |
|
| 572 | - exit(); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 576 | - self::sendSameSiteCookies(); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - public static function init(): void { |
|
| 581 | - // First handle PHP configuration and copy auth headers to the expected |
|
| 582 | - // $_SERVER variable before doing anything Server object related |
|
| 583 | - self::setRequiredIniValues(); |
|
| 584 | - self::handleAuthHeaders(); |
|
| 585 | - |
|
| 586 | - // prevent any XML processing from loading external entities |
|
| 587 | - libxml_set_external_entity_loader(static function () { |
|
| 588 | - return null; |
|
| 589 | - }); |
|
| 590 | - |
|
| 591 | - // Set default timezone before the Server object is booted |
|
| 592 | - if (!date_default_timezone_set('UTC')) { |
|
| 593 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - // calculate the root directories |
|
| 597 | - OC::$SERVERROOT = str_replace('\\', '/', substr(__DIR__, 0, -4)); |
|
| 598 | - |
|
| 599 | - // register autoloader |
|
| 600 | - $loaderStart = microtime(true); |
|
| 601 | - |
|
| 602 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 603 | - |
|
| 604 | - // Add default composer PSR-4 autoloader, ensure apcu to be disabled |
|
| 605 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 606 | - self::$composerAutoloader->setApcuPrefix(null); |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - try { |
|
| 610 | - self::initPaths(); |
|
| 611 | - // setup 3rdparty autoloader |
|
| 612 | - $vendorAutoLoad = OC::$SERVERROOT . '/3rdparty/autoload.php'; |
|
| 613 | - if (!file_exists($vendorAutoLoad)) { |
|
| 614 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 615 | - } |
|
| 616 | - require_once $vendorAutoLoad; |
|
| 617 | - } catch (\RuntimeException $e) { |
|
| 618 | - if (!self::$CLI) { |
|
| 619 | - http_response_code(503); |
|
| 620 | - } |
|
| 621 | - // we can't use the template error page here, because this needs the |
|
| 622 | - // DI container which isn't available yet |
|
| 623 | - print($e->getMessage()); |
|
| 624 | - exit(); |
|
| 625 | - } |
|
| 626 | - $loaderEnd = microtime(true); |
|
| 627 | - |
|
| 628 | - // Enable lazy loading if activated |
|
| 629 | - \OC\AppFramework\Utility\SimpleContainer::$useLazyObjects = (bool)self::$config->getValue('enable_lazy_objects', true); |
|
| 630 | - |
|
| 631 | - // setup the basic server |
|
| 632 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 633 | - self::$server->boot(); |
|
| 634 | - |
|
| 635 | - try { |
|
| 636 | - $profiler = new BuiltInProfiler( |
|
| 637 | - Server::get(IConfig::class), |
|
| 638 | - Server::get(IRequest::class), |
|
| 639 | - ); |
|
| 640 | - $profiler->start(); |
|
| 641 | - } catch (\Throwable $e) { |
|
| 642 | - logger('core')->error('Failed to start profiler: ' . $e->getMessage(), ['app' => 'base']); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - if (self::$CLI && in_array('--' . \OCP\Console\ReservedOptions::DEBUG_LOG, $_SERVER['argv'])) { |
|
| 646 | - \OC\Core\Listener\BeforeMessageLoggedEventListener::setup(); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $eventLogger = Server::get(\OCP\Diagnostics\IEventLogger::class); |
|
| 650 | - $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 651 | - $eventLogger->start('boot', 'Initialize'); |
|
| 652 | - |
|
| 653 | - // Override php.ini and log everything if we're troubleshooting |
|
| 654 | - if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 655 | - error_reporting(E_ALL); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // initialize intl fallback if necessary |
|
| 659 | - OC_Util::isSetLocaleWorking(); |
|
| 660 | - |
|
| 661 | - $config = Server::get(IConfig::class); |
|
| 662 | - if (!defined('PHPUNIT_RUN')) { |
|
| 663 | - $errorHandler = new OC\Log\ErrorHandler( |
|
| 664 | - \OCP\Server::get(\Psr\Log\LoggerInterface::class), |
|
| 665 | - ); |
|
| 666 | - $exceptionHandler = [$errorHandler, 'onException']; |
|
| 667 | - if ($config->getSystemValueBool('debug', false)) { |
|
| 668 | - set_error_handler([$errorHandler, 'onAll'], E_ALL); |
|
| 669 | - if (\OC::$CLI) { |
|
| 670 | - $exceptionHandler = [Server::get(ITemplateManager::class), 'printExceptionErrorPage']; |
|
| 671 | - } |
|
| 672 | - } else { |
|
| 673 | - set_error_handler([$errorHandler, 'onError']); |
|
| 674 | - } |
|
| 675 | - register_shutdown_function([$errorHandler, 'onShutdown']); |
|
| 676 | - set_exception_handler($exceptionHandler); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 680 | - $bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 681 | - $bootstrapCoordinator->runInitialRegistration(); |
|
| 682 | - |
|
| 683 | - $eventLogger->start('init_session', 'Initialize session'); |
|
| 684 | - |
|
| 685 | - // Check for PHP SimpleXML extension earlier since we need it before our other checks and want to provide a useful hint for web users |
|
| 686 | - // see https://github.com/nextcloud/server/pull/2619 |
|
| 687 | - if (!function_exists('simplexml_load_file')) { |
|
| 688 | - throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.'); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $systemConfig = Server::get(\OC\SystemConfig::class); |
|
| 692 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 693 | - if ($systemConfig->getValue('installed', false)) { |
|
| 694 | - $appManager->loadApps(['session']); |
|
| 695 | - } |
|
| 696 | - if (!self::$CLI) { |
|
| 697 | - self::initSession(); |
|
| 698 | - } |
|
| 699 | - $eventLogger->end('init_session'); |
|
| 700 | - self::checkConfig(); |
|
| 701 | - self::checkInstalled($systemConfig); |
|
| 702 | - |
|
| 703 | - OC_Response::addSecurityHeaders(); |
|
| 704 | - |
|
| 705 | - self::performSameSiteCookieProtection($config); |
|
| 706 | - |
|
| 707 | - if (!defined('OC_CONSOLE')) { |
|
| 708 | - $eventLogger->start('check_server', 'Run a few configuration checks'); |
|
| 709 | - $errors = OC_Util::checkServer($systemConfig); |
|
| 710 | - if (count($errors) > 0) { |
|
| 711 | - if (!self::$CLI) { |
|
| 712 | - http_response_code(503); |
|
| 713 | - Util::addStyle('guest'); |
|
| 714 | - try { |
|
| 715 | - Server::get(ITemplateManager::class)->printGuestPage('', 'error', ['errors' => $errors]); |
|
| 716 | - exit; |
|
| 717 | - } catch (\Exception $e) { |
|
| 718 | - // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 719 | - // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // Convert l10n string into regular string for usage in database |
|
| 724 | - $staticErrors = []; |
|
| 725 | - foreach ($errors as $error) { |
|
| 726 | - echo $error['error'] . "\n"; |
|
| 727 | - echo $error['hint'] . "\n\n"; |
|
| 728 | - $staticErrors[] = [ |
|
| 729 | - 'error' => (string)$error['error'], |
|
| 730 | - 'hint' => (string)$error['hint'], |
|
| 731 | - ]; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - try { |
|
| 735 | - $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 736 | - } catch (\Exception $e) { |
|
| 737 | - echo('Writing to database failed'); |
|
| 738 | - } |
|
| 739 | - exit(1); |
|
| 740 | - } elseif (self::$CLI && $config->getSystemValueBool('installed', false)) { |
|
| 741 | - $config->deleteAppValue('core', 'cronErrors'); |
|
| 742 | - } |
|
| 743 | - $eventLogger->end('check_server'); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - // User and Groups |
|
| 747 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 748 | - self::$server->getSession()->set('user_id', ''); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - $eventLogger->start('setup_backends', 'Setup group and user backends'); |
|
| 752 | - Server::get(\OCP\IUserManager::class)->registerBackend(new \OC\User\Database()); |
|
| 753 | - Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database()); |
|
| 754 | - |
|
| 755 | - // Subscribe to the hook |
|
| 756 | - \OCP\Util::connectHook( |
|
| 757 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 758 | - 'preLoginNameUsedAsUserName', |
|
| 759 | - '\OC\User\Database', |
|
| 760 | - 'preLoginNameUsedAsUserName' |
|
| 761 | - ); |
|
| 762 | - |
|
| 763 | - //setup extra user backends |
|
| 764 | - if (!\OCP\Util::needUpgrade()) { |
|
| 765 | - OC_User::setupBackends(); |
|
| 766 | - } else { |
|
| 767 | - // Run upgrades in incognito mode |
|
| 768 | - OC_User::setIncognitoMode(true); |
|
| 769 | - } |
|
| 770 | - $eventLogger->end('setup_backends'); |
|
| 771 | - |
|
| 772 | - self::registerCleanupHooks($systemConfig); |
|
| 773 | - self::registerShareHooks($systemConfig); |
|
| 774 | - self::registerEncryptionWrapperAndHooks(); |
|
| 775 | - self::registerAccountHooks(); |
|
| 776 | - self::registerResourceCollectionHooks(); |
|
| 777 | - self::registerFileReferenceEventListener(); |
|
| 778 | - self::registerRenderReferenceEventListener(); |
|
| 779 | - self::registerAppRestrictionsHooks(); |
|
| 780 | - |
|
| 781 | - // Make sure that the application class is not loaded before the database is setup |
|
| 782 | - if ($systemConfig->getValue('installed', false)) { |
|
| 783 | - $appManager->loadApp('settings'); |
|
| 784 | - /* Run core application registration */ |
|
| 785 | - $bootstrapCoordinator->runLazyRegistration('core'); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - //make sure temporary files are cleaned up |
|
| 789 | - $tmpManager = Server::get(\OCP\ITempManager::class); |
|
| 790 | - register_shutdown_function([$tmpManager, 'clean']); |
|
| 791 | - $lockProvider = Server::get(\OCP\Lock\ILockingProvider::class); |
|
| 792 | - register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 793 | - |
|
| 794 | - // Check whether the sample configuration has been copied |
|
| 795 | - if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 796 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 797 | - Server::get(ITemplateManager::class)->printErrorPage( |
|
| 798 | - $l->t('Sample configuration detected'), |
|
| 799 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 800 | - 503 |
|
| 801 | - ); |
|
| 802 | - return; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - $request = Server::get(IRequest::class); |
|
| 806 | - $host = $request->getInsecureServerHost(); |
|
| 807 | - /** |
|
| 808 | - * if the host passed in headers isn't trusted |
|
| 809 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 810 | - */ |
|
| 811 | - if (!OC::$CLI |
|
| 812 | - && !Server::get(\OC\Security\TrustedDomainHelper::class)->isTrustedDomain($host) |
|
| 813 | - && $config->getSystemValueBool('installed', false) |
|
| 814 | - ) { |
|
| 815 | - // Allow access to CSS resources |
|
| 816 | - $isScssRequest = false; |
|
| 817 | - if (strpos($request->getPathInfo() ?: '', '/css/') === 0) { |
|
| 818 | - $isScssRequest = true; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 822 | - http_response_code(400); |
|
| 823 | - header('Content-Type: application/json'); |
|
| 824 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 825 | - exit(); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - if (!$isScssRequest) { |
|
| 829 | - http_response_code(400); |
|
| 830 | - Server::get(LoggerInterface::class)->info( |
|
| 831 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 832 | - [ |
|
| 833 | - 'app' => 'core', |
|
| 834 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 835 | - 'host' => $host, |
|
| 836 | - ] |
|
| 837 | - ); |
|
| 838 | - |
|
| 839 | - $tmpl = Server::get(ITemplateManager::class)->getTemplate('core', 'untrustedDomain', 'guest'); |
|
| 840 | - $tmpl->assign('docUrl', Server::get(IURLGenerator::class)->linkToDocs('admin-trusted-domains')); |
|
| 841 | - $tmpl->printPage(); |
|
| 842 | - |
|
| 843 | - exit(); |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - $eventLogger->end('boot'); |
|
| 847 | - $eventLogger->log('init', 'OC::init', $loaderStart, microtime(true)); |
|
| 848 | - $eventLogger->start('runtime', 'Runtime'); |
|
| 849 | - $eventLogger->start('request', 'Full request after boot'); |
|
| 850 | - register_shutdown_function(function () use ($eventLogger) { |
|
| 851 | - $eventLogger->end('request'); |
|
| 852 | - }); |
|
| 853 | - |
|
| 854 | - register_shutdown_function(function () { |
|
| 855 | - $memoryPeak = memory_get_peak_usage(); |
|
| 856 | - $logLevel = match (true) { |
|
| 857 | - $memoryPeak > 500_000_000 => ILogger::FATAL, |
|
| 858 | - $memoryPeak > 400_000_000 => ILogger::ERROR, |
|
| 859 | - $memoryPeak > 300_000_000 => ILogger::WARN, |
|
| 860 | - default => null, |
|
| 861 | - }; |
|
| 862 | - if ($logLevel !== null) { |
|
| 863 | - $message = 'Request used more than 300 MB of RAM: ' . Util::humanFileSize($memoryPeak); |
|
| 864 | - $logger = Server::get(LoggerInterface::class); |
|
| 865 | - $logger->log($logLevel, $message, ['app' => 'core']); |
|
| 866 | - } |
|
| 867 | - }); |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * register hooks for the cleanup of cache and bruteforce protection |
|
| 872 | - */ |
|
| 873 | - public static function registerCleanupHooks(\OC\SystemConfig $systemConfig): void { |
|
| 874 | - //don't try to do this before we are properly setup |
|
| 875 | - if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 876 | - // NOTE: This will be replaced to use OCP |
|
| 877 | - $userSession = Server::get(\OC\User\Session::class); |
|
| 878 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 879 | - if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 880 | - // reset brute force delay for this IP address and username |
|
| 881 | - $uid = $userSession->getUser()->getUID(); |
|
| 882 | - $request = Server::get(IRequest::class); |
|
| 883 | - $throttler = Server::get(IThrottler::class); |
|
| 884 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 885 | - } |
|
| 886 | - }); |
|
| 887 | - } |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - private static function registerEncryptionWrapperAndHooks(): void { |
|
| 891 | - /** @var \OC\Encryption\Manager */ |
|
| 892 | - $manager = Server::get(\OCP\Encryption\IManager::class); |
|
| 893 | - Server::get(IEventDispatcher::class)->addListener( |
|
| 894 | - BeforeFileSystemSetupEvent::class, |
|
| 895 | - $manager->setupStorage(...), |
|
| 896 | - ); |
|
| 897 | - |
|
| 898 | - $enabled = $manager->isEnabled(); |
|
| 899 | - if ($enabled) { |
|
| 900 | - \OC\Encryption\EncryptionEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - private static function registerAccountHooks(): void { |
|
| 905 | - /** @var IEventDispatcher $dispatcher */ |
|
| 906 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
| 907 | - $dispatcher->addServiceListener(UserChangedEvent::class, \OC\Accounts\Hooks::class); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - private static function registerAppRestrictionsHooks(): void { |
|
| 911 | - /** @var \OC\Group\Manager $groupManager */ |
|
| 912 | - $groupManager = Server::get(\OCP\IGroupManager::class); |
|
| 913 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 914 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 915 | - $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 916 | - foreach ($apps as $appId) { |
|
| 917 | - $restrictions = $appManager->getAppRestriction($appId); |
|
| 918 | - if (empty($restrictions)) { |
|
| 919 | - continue; |
|
| 920 | - } |
|
| 921 | - $key = array_search($group->getGID(), $restrictions); |
|
| 922 | - unset($restrictions[$key]); |
|
| 923 | - $restrictions = array_values($restrictions); |
|
| 924 | - if (empty($restrictions)) { |
|
| 925 | - $appManager->disableApp($appId); |
|
| 926 | - } else { |
|
| 927 | - $appManager->enableAppForGroups($appId, $restrictions); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - }); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - private static function registerResourceCollectionHooks(): void { |
|
| 934 | - \OC\Collaboration\Resources\Listener::register(Server::get(IEventDispatcher::class)); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - private static function registerFileReferenceEventListener(): void { |
|
| 938 | - \OC\Collaboration\Reference\File\FileReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - private static function registerRenderReferenceEventListener() { |
|
| 942 | - \OC\Collaboration\Reference\RenderReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * register hooks for sharing |
|
| 947 | - */ |
|
| 948 | - public static function registerShareHooks(\OC\SystemConfig $systemConfig): void { |
|
| 949 | - if ($systemConfig->getValue('installed')) { |
|
| 950 | - |
|
| 951 | - $dispatcher = Server::get(IEventDispatcher::class); |
|
| 952 | - $dispatcher->addServiceListener(UserRemovedEvent::class, UserRemovedListener::class); |
|
| 953 | - $dispatcher->addServiceListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
| 954 | - $dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - /** |
|
| 959 | - * Handle the request |
|
| 960 | - */ |
|
| 961 | - public static function handleRequest(): void { |
|
| 962 | - Server::get(\OCP\Diagnostics\IEventLogger::class)->start('handle_request', 'Handle request'); |
|
| 963 | - $systemConfig = Server::get(\OC\SystemConfig::class); |
|
| 964 | - |
|
| 965 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 966 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 967 | - \OC::$server->getSession()->clear(); |
|
| 968 | - $controller = Server::get(\OC\Core\Controller\SetupController::class); |
|
| 969 | - $controller->run($_POST); |
|
| 970 | - exit(); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - $request = Server::get(IRequest::class); |
|
| 974 | - $request->throwDecodingExceptionIfAny(); |
|
| 975 | - $requestPath = $request->getRawPathInfo(); |
|
| 976 | - if ($requestPath === '/heartbeat') { |
|
| 977 | - return; |
|
| 978 | - } |
|
| 979 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 980 | - self::checkMaintenanceMode($systemConfig); |
|
| 981 | - |
|
| 982 | - if (\OCP\Util::needUpgrade()) { |
|
| 983 | - if (function_exists('opcache_reset')) { |
|
| 984 | - opcache_reset(); |
|
| 985 | - } |
|
| 986 | - if (!((bool)$systemConfig->getValue('maintenance', false))) { |
|
| 987 | - self::printUpgradePage($systemConfig); |
|
| 988 | - exit(); |
|
| 989 | - } |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 994 | - |
|
| 995 | - // Always load authentication apps |
|
| 996 | - $appManager->loadApps(['authentication']); |
|
| 997 | - $appManager->loadApps(['extended_authentication']); |
|
| 998 | - |
|
| 999 | - // Load minimum set of apps |
|
| 1000 | - if (!\OCP\Util::needUpgrade() |
|
| 1001 | - && !((bool)$systemConfig->getValue('maintenance', false))) { |
|
| 1002 | - // For logged-in users: Load everything |
|
| 1003 | - if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
| 1004 | - $appManager->loadApps(); |
|
| 1005 | - } else { |
|
| 1006 | - // For guests: Load only filesystem and logging |
|
| 1007 | - $appManager->loadApps(['filesystem', 'logging']); |
|
| 1008 | - |
|
| 1009 | - // Don't try to login when a client is trying to get a OAuth token. |
|
| 1010 | - // OAuth needs to support basic auth too, so the login is not valid |
|
| 1011 | - // inside Nextcloud and the Login exception would ruin it. |
|
| 1012 | - if ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') { |
|
| 1013 | - try { |
|
| 1014 | - self::handleLogin($request); |
|
| 1015 | - } catch (DisabledUserException $e) { |
|
| 1016 | - // Disabled users would not be seen as logged in and |
|
| 1017 | - // trying to log them in would fail, so the login |
|
| 1018 | - // exception is ignored for the themed stylesheets and |
|
| 1019 | - // images. |
|
| 1020 | - if ($request->getRawPathInfo() !== '/apps/theming/theme/default.css' |
|
| 1021 | - && $request->getRawPathInfo() !== '/apps/theming/theme/light.css' |
|
| 1022 | - && $request->getRawPathInfo() !== '/apps/theming/theme/dark.css' |
|
| 1023 | - && $request->getRawPathInfo() !== '/apps/theming/theme/light-highcontrast.css' |
|
| 1024 | - && $request->getRawPathInfo() !== '/apps/theming/theme/dark-highcontrast.css' |
|
| 1025 | - && $request->getRawPathInfo() !== '/apps/theming/theme/opendyslexic.css' |
|
| 1026 | - && $request->getRawPathInfo() !== '/apps/theming/image/background' |
|
| 1027 | - && $request->getRawPathInfo() !== '/apps/theming/image/logo' |
|
| 1028 | - && $request->getRawPathInfo() !== '/apps/theming/image/logoheader' |
|
| 1029 | - && !str_starts_with($request->getRawPathInfo(), '/apps/theming/favicon') |
|
| 1030 | - && !str_starts_with($request->getRawPathInfo(), '/apps/theming/icon')) { |
|
| 1031 | - throw $e; |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - if (!self::$CLI) { |
|
| 1039 | - try { |
|
| 1040 | - if (!\OCP\Util::needUpgrade()) { |
|
| 1041 | - $appManager->loadApps(['filesystem', 'logging']); |
|
| 1042 | - $appManager->loadApps(); |
|
| 1043 | - } |
|
| 1044 | - Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
| 1045 | - return; |
|
| 1046 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1047 | - //header('HTTP/1.0 404 Not Found'); |
|
| 1048 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1049 | - http_response_code(405); |
|
| 1050 | - return; |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - // Handle WebDAV |
|
| 1055 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1056 | - // not allowed any more to prevent people |
|
| 1057 | - // mounting this root directly. |
|
| 1058 | - // Users need to mount remote.php/webdav instead. |
|
| 1059 | - http_response_code(405); |
|
| 1060 | - return; |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - // Handle requests for JSON or XML |
|
| 1064 | - $acceptHeader = $request->getHeader('Accept'); |
|
| 1065 | - if (in_array($acceptHeader, ['application/json', 'application/xml'], true)) { |
|
| 1066 | - http_response_code(404); |
|
| 1067 | - return; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - // Handle resources that can't be found |
|
| 1071 | - // This prevents browsers from redirecting to the default page and then |
|
| 1072 | - // attempting to parse HTML as CSS and similar. |
|
| 1073 | - $destinationHeader = $request->getHeader('Sec-Fetch-Dest'); |
|
| 1074 | - if (in_array($destinationHeader, ['font', 'script', 'style'])) { |
|
| 1075 | - http_response_code(404); |
|
| 1076 | - return; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - // Redirect to the default app or login only as an entry point |
|
| 1080 | - if ($requestPath === '') { |
|
| 1081 | - // Someone is logged in |
|
| 1082 | - if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
| 1083 | - header('Location: ' . Server::get(IURLGenerator::class)->linkToDefaultPageUrl()); |
|
| 1084 | - } else { |
|
| 1085 | - // Not handled and not logged in |
|
| 1086 | - header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1087 | - } |
|
| 1088 | - return; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - try { |
|
| 1092 | - Server::get(\OC\Route\Router::class)->match('/error/404'); |
|
| 1093 | - } catch (\Exception $e) { |
|
| 1094 | - if (!$e instanceof MethodNotAllowedException) { |
|
| 1095 | - logger('core')->emergency($e->getMessage(), ['exception' => $e]); |
|
| 1096 | - } |
|
| 1097 | - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 1098 | - Server::get(ITemplateManager::class)->printErrorPage( |
|
| 1099 | - '404', |
|
| 1100 | - $l->t('The page could not be found on the server.'), |
|
| 1101 | - 404 |
|
| 1102 | - ); |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - /** |
|
| 1107 | - * Check login: apache auth, auth token, basic auth |
|
| 1108 | - */ |
|
| 1109 | - public static function handleLogin(OCP\IRequest $request): bool { |
|
| 1110 | - if ($request->getHeader('X-Nextcloud-Federation')) { |
|
| 1111 | - return false; |
|
| 1112 | - } |
|
| 1113 | - $userSession = Server::get(\OC\User\Session::class); |
|
| 1114 | - if (OC_User::handleApacheAuth()) { |
|
| 1115 | - return true; |
|
| 1116 | - } |
|
| 1117 | - if (self::tryAppAPILogin($request)) { |
|
| 1118 | - return true; |
|
| 1119 | - } |
|
| 1120 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1121 | - return true; |
|
| 1122 | - } |
|
| 1123 | - if (isset($_COOKIE['nc_username']) |
|
| 1124 | - && isset($_COOKIE['nc_token']) |
|
| 1125 | - && isset($_COOKIE['nc_session_id']) |
|
| 1126 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1127 | - return true; |
|
| 1128 | - } |
|
| 1129 | - if ($userSession->tryBasicAuthLogin($request, Server::get(IThrottler::class))) { |
|
| 1130 | - return true; |
|
| 1131 | - } |
|
| 1132 | - return false; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - protected static function handleAuthHeaders(): void { |
|
| 1136 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1137 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1138 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1142 | - $vars = [ |
|
| 1143 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1144 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1145 | - ]; |
|
| 1146 | - foreach ($vars as $var) { |
|
| 1147 | - if (isset($_SERVER[$var]) && is_string($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1148 | - $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1149 | - if (count($credentials) === 2) { |
|
| 1150 | - $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1151 | - $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1152 | - break; |
|
| 1153 | - } |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - protected static function tryAppAPILogin(OCP\IRequest $request): bool { |
|
| 1159 | - if (!$request->getHeader('AUTHORIZATION-APP-API')) { |
|
| 1160 | - return false; |
|
| 1161 | - } |
|
| 1162 | - $appManager = Server::get(OCP\App\IAppManager::class); |
|
| 1163 | - if (!$appManager->isEnabledForAnyone('app_api')) { |
|
| 1164 | - return false; |
|
| 1165 | - } |
|
| 1166 | - try { |
|
| 1167 | - $appAPIService = Server::get(OCA\AppAPI\Service\AppAPIService::class); |
|
| 1168 | - return $appAPIService->validateExAppRequestToNC($request); |
|
| 1169 | - } catch (\Psr\Container\NotFoundExceptionInterface|\Psr\Container\ContainerExceptionInterface $e) { |
|
| 1170 | - return false; |
|
| 1171 | - } |
|
| 1172 | - } |
|
| 43 | + /** |
|
| 44 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 45 | + */ |
|
| 46 | + public static string $SERVERROOT = ''; |
|
| 47 | + /** |
|
| 48 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 49 | + */ |
|
| 50 | + private static string $SUBURI = ''; |
|
| 51 | + /** |
|
| 52 | + * the Nextcloud root path for http requests (e.g. /nextcloud) |
|
| 53 | + */ |
|
| 54 | + public static string $WEBROOT = ''; |
|
| 55 | + /** |
|
| 56 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 57 | + * web path in 'url' |
|
| 58 | + */ |
|
| 59 | + public static array $APPSROOTS = []; |
|
| 60 | + |
|
| 61 | + public static string $configDir; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * requested app |
|
| 65 | + */ |
|
| 66 | + public static string $REQUESTEDAPP = ''; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * check if Nextcloud runs in cli mode |
|
| 70 | + */ |
|
| 71 | + public static bool $CLI = false; |
|
| 72 | + |
|
| 73 | + public static \Composer\Autoload\ClassLoader $composerAutoloader; |
|
| 74 | + |
|
| 75 | + public static \OC\Server $server; |
|
| 76 | + |
|
| 77 | + private static \OC\Config $config; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 81 | + * the app path list is empty or contains an invalid path |
|
| 82 | + */ |
|
| 83 | + public static function initPaths(): void { |
|
| 84 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 85 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 86 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 87 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 88 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 89 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 90 | + } else { |
|
| 91 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 92 | + } |
|
| 93 | + self::$config = new \OC\Config(self::$configDir); |
|
| 94 | + |
|
| 95 | + OC::$SUBURI = str_replace('\\', '/', substr(realpath($_SERVER['SCRIPT_FILENAME'] ?? ''), strlen(OC::$SERVERROOT))); |
|
| 96 | + /** |
|
| 97 | + * FIXME: The following lines are required because we can't yet instantiate |
|
| 98 | + * Server::get(\OCP\IRequest::class) since \OC::$server does not yet exist. |
|
| 99 | + */ |
|
| 100 | + $params = [ |
|
| 101 | + 'server' => [ |
|
| 102 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'] ?? null, |
|
| 103 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'] ?? null, |
|
| 104 | + ], |
|
| 105 | + ]; |
|
| 106 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
| 107 | + $params['server']['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR']; |
|
| 108 | + } |
|
| 109 | + $fakeRequest = new \OC\AppFramework\Http\Request( |
|
| 110 | + $params, |
|
| 111 | + new \OC\AppFramework\Http\RequestId($_SERVER['UNIQUE_ID'] ?? '', new \OC\Security\SecureRandom()), |
|
| 112 | + new \OC\AllConfig(new \OC\SystemConfig(self::$config)) |
|
| 113 | + ); |
|
| 114 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 115 | + if (substr($scriptName, -1) == '/') { |
|
| 116 | + $scriptName .= 'index.php'; |
|
| 117 | + //make sure suburi follows the same rules as scriptName |
|
| 118 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 119 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 120 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 121 | + } |
|
| 122 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (OC::$CLI) { |
|
| 127 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 128 | + } else { |
|
| 129 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 130 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 131 | + |
|
| 132 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 133 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 134 | + } |
|
| 135 | + } else { |
|
| 136 | + // The scriptName is not ending with OC::$SUBURI |
|
| 137 | + // This most likely means that we are calling from CLI. |
|
| 138 | + // However some cron jobs still need to generate |
|
| 139 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 140 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 144 | + // slash which is required by URL generation. |
|
| 145 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT |
|
| 146 | + && substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 147 | + header('Location: ' . \OC::$WEBROOT . '/'); |
|
| 148 | + exit(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // search the apps folder |
|
| 153 | + $config_paths = self::$config->getValue('apps_paths', []); |
|
| 154 | + if (!empty($config_paths)) { |
|
| 155 | + foreach ($config_paths as $paths) { |
|
| 156 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 157 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 158 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 159 | + OC::$APPSROOTS[] = $paths; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 163 | + OC::$APPSROOTS[] = ['path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true]; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if (empty(OC::$APPSROOTS)) { |
|
| 167 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 168 | + . '. You can also configure the location in the config.php file.'); |
|
| 169 | + } |
|
| 170 | + $paths = []; |
|
| 171 | + foreach (OC::$APPSROOTS as $path) { |
|
| 172 | + $paths[] = $path['path']; |
|
| 173 | + if (!is_dir($path['path'])) { |
|
| 174 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 175 | + . ' Nextcloud folder. You can also configure the location in the config.php file.', $path['path'])); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // set the right include path |
|
| 180 | + set_include_path( |
|
| 181 | + implode(PATH_SEPARATOR, $paths) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + public static function checkConfig(): void { |
|
| 186 | + // Create config if it does not already exist |
|
| 187 | + $configFilePath = self::$configDir . '/config.php'; |
|
| 188 | + if (!file_exists($configFilePath)) { |
|
| 189 | + @touch($configFilePath); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // Check if config is writable |
|
| 193 | + $configFileWritable = is_writable($configFilePath); |
|
| 194 | + $configReadOnly = Server::get(IConfig::class)->getSystemValueBool('config_is_read_only'); |
|
| 195 | + if (!$configFileWritable && !$configReadOnly |
|
| 196 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 197 | + $urlGenerator = Server::get(IURLGenerator::class); |
|
| 198 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 199 | + |
|
| 200 | + if (self::$CLI) { |
|
| 201 | + echo $l->t('Cannot write into "config" directory!') . "\n"; |
|
| 202 | + echo $l->t('This can usually be fixed by giving the web server write access to the config directory.') . "\n"; |
|
| 203 | + echo "\n"; |
|
| 204 | + echo $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . "\n"; |
|
| 205 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]) . "\n"; |
|
| 206 | + exit; |
|
| 207 | + } else { |
|
| 208 | + Server::get(ITemplateManager::class)->printErrorPage( |
|
| 209 | + $l->t('Cannot write into "config" directory!'), |
|
| 210 | + $l->t('This can usually be fixed by giving the web server write access to the config directory.') . ' ' |
|
| 211 | + . $l->t('But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.') . ' ' |
|
| 212 | + . $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ]), |
|
| 213 | + 503 |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public static function checkInstalled(\OC\SystemConfig $systemConfig): void { |
|
| 220 | + if (defined('OC_CONSOLE')) { |
|
| 221 | + return; |
|
| 222 | + } |
|
| 223 | + // Redirect to installer if not installed |
|
| 224 | + if (!$systemConfig->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 225 | + if (OC::$CLI) { |
|
| 226 | + throw new Exception('Not installed'); |
|
| 227 | + } else { |
|
| 228 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 229 | + header('Location: ' . $url); |
|
| 230 | + } |
|
| 231 | + exit(); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + public static function checkMaintenanceMode(\OC\SystemConfig $systemConfig): void { |
|
| 236 | + // Allow ajax update script to execute without being stopped |
|
| 237 | + if (((bool)$systemConfig->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 238 | + // send http status 503 |
|
| 239 | + http_response_code(503); |
|
| 240 | + header('X-Nextcloud-Maintenance-Mode: 1'); |
|
| 241 | + header('Retry-After: 120'); |
|
| 242 | + |
|
| 243 | + // render error page |
|
| 244 | + $template = Server::get(ITemplateManager::class)->getTemplate('', 'update.user', 'guest'); |
|
| 245 | + \OCP\Util::addScript('core', 'maintenance'); |
|
| 246 | + \OCP\Util::addStyle('core', 'guest'); |
|
| 247 | + $template->printPage(); |
|
| 248 | + die(); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Prints the upgrade page |
|
| 254 | + */ |
|
| 255 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { |
|
| 256 | + $cliUpgradeLink = $systemConfig->getValue('upgrade.cli-upgrade-link', ''); |
|
| 257 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 258 | + $tooBig = false; |
|
| 259 | + if (!$disableWebUpdater) { |
|
| 260 | + $apps = Server::get(\OCP\App\IAppManager::class); |
|
| 261 | + if ($apps->isEnabledForAnyone('user_ldap')) { |
|
| 262 | + $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
| 263 | + |
|
| 264 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 265 | + ->from('ldap_user_mapping') |
|
| 266 | + ->executeQuery(); |
|
| 267 | + $row = $result->fetch(); |
|
| 268 | + $result->closeCursor(); |
|
| 269 | + |
|
| 270 | + $tooBig = ($row['user_count'] > 50); |
|
| 271 | + } |
|
| 272 | + if (!$tooBig && $apps->isEnabledForAnyone('user_saml')) { |
|
| 273 | + $qb = Server::get(\OCP\IDBConnection::class)->getQueryBuilder(); |
|
| 274 | + |
|
| 275 | + $result = $qb->select($qb->func()->count('*', 'user_count')) |
|
| 276 | + ->from('user_saml_users') |
|
| 277 | + ->executeQuery(); |
|
| 278 | + $row = $result->fetch(); |
|
| 279 | + $result->closeCursor(); |
|
| 280 | + |
|
| 281 | + $tooBig = ($row['user_count'] > 50); |
|
| 282 | + } |
|
| 283 | + if (!$tooBig) { |
|
| 284 | + // count users |
|
| 285 | + $totalUsers = Server::get(\OCP\IUserManager::class)->countUsersTotal(51); |
|
| 286 | + $tooBig = ($totalUsers > 50); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) |
|
| 290 | + && $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 291 | + |
|
| 292 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 293 | + // send http status 503 |
|
| 294 | + http_response_code(503); |
|
| 295 | + header('Retry-After: 120'); |
|
| 296 | + |
|
| 297 | + $serverVersion = \OCP\Server::get(\OCP\ServerVersion::class); |
|
| 298 | + |
|
| 299 | + // render error page |
|
| 300 | + $template = Server::get(ITemplateManager::class)->getTemplate('', 'update.use-cli', 'guest'); |
|
| 301 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 302 | + $template->assign('version', $serverVersion->getVersionString()); |
|
| 303 | + $template->assign('tooBig', $tooBig); |
|
| 304 | + $template->assign('cliUpgradeLink', $cliUpgradeLink); |
|
| 305 | + |
|
| 306 | + $template->printPage(); |
|
| 307 | + die(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // check whether this is a core update or apps update |
|
| 311 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 312 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 313 | + |
|
| 314 | + // if not a core upgrade, then it's apps upgrade |
|
| 315 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 316 | + |
|
| 317 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 318 | + $systemConfig->setValue('theme', ''); |
|
| 319 | + \OCP\Util::addScript('core', 'common'); |
|
| 320 | + \OCP\Util::addScript('core', 'main'); |
|
| 321 | + \OCP\Util::addTranslations('core'); |
|
| 322 | + \OCP\Util::addScript('core', 'update'); |
|
| 323 | + |
|
| 324 | + /** @var \OC\App\AppManager $appManager */ |
|
| 325 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 326 | + |
|
| 327 | + $tmpl = Server::get(ITemplateManager::class)->getTemplate('', 'update.admin', 'guest'); |
|
| 328 | + $tmpl->assign('version', \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString()); |
|
| 329 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 330 | + |
|
| 331 | + // get third party apps |
|
| 332 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 333 | + $ocVersion = implode('.', $ocVersion); |
|
| 334 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 335 | + $incompatibleOverwrites = $systemConfig->getValue('app_install_overwrite', []); |
|
| 336 | + $incompatibleShippedApps = []; |
|
| 337 | + $incompatibleDisabledApps = []; |
|
| 338 | + foreach ($incompatibleApps as $appInfo) { |
|
| 339 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 340 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 341 | + } |
|
| 342 | + if (!in_array($appInfo['id'], $incompatibleOverwrites)) { |
|
| 343 | + $incompatibleDisabledApps[] = $appInfo; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + if (!empty($incompatibleShippedApps)) { |
|
| 348 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('core'); |
|
| 349 | + $hint = $l->t('Application %1$s is not present or has a non-compatible version with this server. Please check the apps directory.', [implode(', ', $incompatibleShippedApps)]); |
|
| 350 | + throw new \OCP\HintException('Application ' . implode(', ', $incompatibleShippedApps) . ' is not present or has a non-compatible version with this server. Please check the apps directory.', $hint); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 354 | + $tmpl->assign('incompatibleAppsList', $incompatibleDisabledApps); |
|
| 355 | + try { |
|
| 356 | + $defaults = new \OC_Defaults(); |
|
| 357 | + $tmpl->assign('productName', $defaults->getName()); |
|
| 358 | + } catch (Throwable $error) { |
|
| 359 | + $tmpl->assign('productName', 'Nextcloud'); |
|
| 360 | + } |
|
| 361 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 362 | + $tmpl->printPage(); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + public static function initSession(): void { |
|
| 366 | + $request = Server::get(IRequest::class); |
|
| 367 | + |
|
| 368 | + // TODO: Temporary disabled again to solve issues with CalDAV/CardDAV clients like DAVx5 that use cookies |
|
| 369 | + // TODO: See https://github.com/nextcloud/server/issues/37277#issuecomment-1476366147 and the other comments |
|
| 370 | + // TODO: for further information. |
|
| 371 | + // $isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 || strpos($request->getRequestUri(), '/remote.php/webdav') === 0; |
|
| 372 | + // if ($request->getHeader('Authorization') !== '' && is_null($request->getCookie('cookie_test')) && $isDavRequest && !isset($_COOKIE['nc_session_id'])) { |
|
| 373 | + // setcookie('cookie_test', 'test', time() + 3600); |
|
| 374 | + // // Do not initialize the session if a request is authenticated directly |
|
| 375 | + // // unless there is a session cookie already sent along |
|
| 376 | + // return; |
|
| 377 | + // } |
|
| 378 | + |
|
| 379 | + if ($request->getServerProtocol() === 'https') { |
|
| 380 | + ini_set('session.cookie_secure', 'true'); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + // prevents javascript from accessing php session cookies |
|
| 384 | + ini_set('session.cookie_httponly', 'true'); |
|
| 385 | + |
|
| 386 | + // Do not initialize sessions for 'status.php' requests |
|
| 387 | + // Monitoring endpoints can quickly flood session handlers |
|
| 388 | + // and 'status.php' doesn't require sessions anyway |
|
| 389 | + if (str_ends_with($request->getScriptName(), '/status.php')) { |
|
| 390 | + return; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // set the cookie path to the Nextcloud directory |
|
| 394 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 395 | + ini_set('session.cookie_path', $cookie_path); |
|
| 396 | + |
|
| 397 | + // set the cookie domain to the Nextcloud domain |
|
| 398 | + $cookie_domain = self::$config->getValue('cookie_domain', ''); |
|
| 399 | + if ($cookie_domain) { |
|
| 400 | + ini_set('session.cookie_domain', $cookie_domain); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + // Let the session name be changed in the initSession Hook |
|
| 404 | + $sessionName = OC_Util::getInstanceId(); |
|
| 405 | + |
|
| 406 | + try { |
|
| 407 | + $logger = null; |
|
| 408 | + if (Server::get(\OC\SystemConfig::class)->getValue('installed', false)) { |
|
| 409 | + $logger = logger('core'); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // set the session name to the instance id - which is unique |
|
| 413 | + $session = new \OC\Session\Internal( |
|
| 414 | + $sessionName, |
|
| 415 | + $logger, |
|
| 416 | + ); |
|
| 417 | + |
|
| 418 | + $cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class); |
|
| 419 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 420 | + self::$server->setSession($session); |
|
| 421 | + |
|
| 422 | + // if session can't be started break with http 500 error |
|
| 423 | + } catch (Exception $e) { |
|
| 424 | + Server::get(LoggerInterface::class)->error($e->getMessage(), ['app' => 'base','exception' => $e]); |
|
| 425 | + //show the user a detailed error page |
|
| 426 | + Server::get(ITemplateManager::class)->printExceptionErrorPage($e, 500); |
|
| 427 | + die(); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + //try to set the session lifetime |
|
| 431 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 432 | + |
|
| 433 | + // session timeout |
|
| 434 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 435 | + if (isset($_COOKIE[session_name()])) { |
|
| 436 | + setcookie(session_name(), '', -1, self::$WEBROOT ? : '/'); |
|
| 437 | + } |
|
| 438 | + Server::get(IUserSession::class)->logout(); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + if (!self::hasSessionRelaxedExpiry()) { |
|
| 442 | + $session->set('LAST_ACTIVITY', time()); |
|
| 443 | + } |
|
| 444 | + $session->close(); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + private static function getSessionLifeTime(): int { |
|
| 448 | + return Server::get(\OC\AllConfig::class)->getSystemValueInt('session_lifetime', 60 * 60 * 24); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return bool true if the session expiry should only be done by gc instead of an explicit timeout |
|
| 453 | + */ |
|
| 454 | + public static function hasSessionRelaxedExpiry(): bool { |
|
| 455 | + return Server::get(\OC\AllConfig::class)->getSystemValueBool('session_relaxed_expiry', false); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Try to set some values to the required Nextcloud default |
|
| 460 | + */ |
|
| 461 | + public static function setRequiredIniValues(): void { |
|
| 462 | + // Don't display errors and log them |
|
| 463 | + @ini_set('display_errors', '0'); |
|
| 464 | + @ini_set('log_errors', '1'); |
|
| 465 | + |
|
| 466 | + // Try to configure php to enable big file uploads. |
|
| 467 | + // This doesn't work always depending on the webserver and php configuration. |
|
| 468 | + // Let's try to overwrite some defaults if they are smaller than 1 hour |
|
| 469 | + |
|
| 470 | + if (intval(@ini_get('max_execution_time') ?: 0) < 3600) { |
|
| 471 | + @ini_set('max_execution_time', strval(3600)); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + if (intval(@ini_get('max_input_time') ?: 0) < 3600) { |
|
| 475 | + @ini_set('max_input_time', strval(3600)); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + // Try to set the maximum execution time to the largest time limit we have |
|
| 479 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 480 | + @set_time_limit(max(intval(@ini_get('max_execution_time')), intval(@ini_get('max_input_time')))); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + @ini_set('default_charset', 'UTF-8'); |
|
| 484 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Send the same site cookies |
|
| 489 | + */ |
|
| 490 | + private static function sendSameSiteCookies(): void { |
|
| 491 | + $cookieParams = session_get_cookie_params(); |
|
| 492 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 493 | + $policies = [ |
|
| 494 | + 'lax', |
|
| 495 | + 'strict', |
|
| 496 | + ]; |
|
| 497 | + |
|
| 498 | + // Append __Host to the cookie if it meets the requirements |
|
| 499 | + $cookiePrefix = ''; |
|
| 500 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 501 | + $cookiePrefix = '__Host-'; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + foreach ($policies as $policy) { |
|
| 505 | + header( |
|
| 506 | + sprintf( |
|
| 507 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 508 | + $cookiePrefix, |
|
| 509 | + $policy, |
|
| 510 | + $cookieParams['path'], |
|
| 511 | + $policy |
|
| 512 | + ), |
|
| 513 | + false |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 520 | + * be set in every request if cookies are sent to add a second level of |
|
| 521 | + * defense against CSRF. |
|
| 522 | + * |
|
| 523 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 524 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 525 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 526 | + */ |
|
| 527 | + private static function performSameSiteCookieProtection(IConfig $config): void { |
|
| 528 | + $request = Server::get(IRequest::class); |
|
| 529 | + |
|
| 530 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 531 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 532 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 533 | + // here. |
|
| 534 | + $incompatibleUserAgents = $config->getSystemValue('csrf.optout'); |
|
| 535 | + |
|
| 536 | + // Fallback, if csrf.optout is unset |
|
| 537 | + if (!is_array($incompatibleUserAgents)) { |
|
| 538 | + $incompatibleUserAgents = [ |
|
| 539 | + // OS X Finder |
|
| 540 | + '/^WebDAVFS/', |
|
| 541 | + // Windows webdav drive |
|
| 542 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
| 543 | + ]; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 547 | + return; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + if (count($_COOKIE) > 0) { |
|
| 551 | + $requestUri = $request->getScriptName(); |
|
| 552 | + $processingScript = explode('/', $requestUri); |
|
| 553 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 554 | + |
|
| 555 | + if ($processingScript === 'index.php' // index.php routes are handled in the middleware |
|
| 556 | + || $processingScript === 'cron.php' // and cron.php does not need any authentication at all |
|
| 557 | + || $processingScript === 'public.php' // For public.php, auth for password protected shares is done in the PublicAuth plugin |
|
| 558 | + ) { |
|
| 559 | + return; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + // All other endpoints require the lax and the strict cookie |
|
| 563 | + if (!$request->passesStrictCookieCheck()) { |
|
| 564 | + logger('core')->warning('Request does not pass strict cookie check'); |
|
| 565 | + self::sendSameSiteCookies(); |
|
| 566 | + // Debug mode gets access to the resources without strict cookie |
|
| 567 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 568 | + if (!$config->getSystemValueBool('debug', false)) { |
|
| 569 | + http_response_code(\OCP\AppFramework\Http::STATUS_PRECONDITION_FAILED); |
|
| 570 | + header('Content-Type: application/json'); |
|
| 571 | + echo json_encode(['error' => 'Strict Cookie has not been found in request']); |
|
| 572 | + exit(); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 576 | + self::sendSameSiteCookies(); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + public static function init(): void { |
|
| 581 | + // First handle PHP configuration and copy auth headers to the expected |
|
| 582 | + // $_SERVER variable before doing anything Server object related |
|
| 583 | + self::setRequiredIniValues(); |
|
| 584 | + self::handleAuthHeaders(); |
|
| 585 | + |
|
| 586 | + // prevent any XML processing from loading external entities |
|
| 587 | + libxml_set_external_entity_loader(static function () { |
|
| 588 | + return null; |
|
| 589 | + }); |
|
| 590 | + |
|
| 591 | + // Set default timezone before the Server object is booted |
|
| 592 | + if (!date_default_timezone_set('UTC')) { |
|
| 593 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + // calculate the root directories |
|
| 597 | + OC::$SERVERROOT = str_replace('\\', '/', substr(__DIR__, 0, -4)); |
|
| 598 | + |
|
| 599 | + // register autoloader |
|
| 600 | + $loaderStart = microtime(true); |
|
| 601 | + |
|
| 602 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 603 | + |
|
| 604 | + // Add default composer PSR-4 autoloader, ensure apcu to be disabled |
|
| 605 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 606 | + self::$composerAutoloader->setApcuPrefix(null); |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + try { |
|
| 610 | + self::initPaths(); |
|
| 611 | + // setup 3rdparty autoloader |
|
| 612 | + $vendorAutoLoad = OC::$SERVERROOT . '/3rdparty/autoload.php'; |
|
| 613 | + if (!file_exists($vendorAutoLoad)) { |
|
| 614 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 615 | + } |
|
| 616 | + require_once $vendorAutoLoad; |
|
| 617 | + } catch (\RuntimeException $e) { |
|
| 618 | + if (!self::$CLI) { |
|
| 619 | + http_response_code(503); |
|
| 620 | + } |
|
| 621 | + // we can't use the template error page here, because this needs the |
|
| 622 | + // DI container which isn't available yet |
|
| 623 | + print($e->getMessage()); |
|
| 624 | + exit(); |
|
| 625 | + } |
|
| 626 | + $loaderEnd = microtime(true); |
|
| 627 | + |
|
| 628 | + // Enable lazy loading if activated |
|
| 629 | + \OC\AppFramework\Utility\SimpleContainer::$useLazyObjects = (bool)self::$config->getValue('enable_lazy_objects', true); |
|
| 630 | + |
|
| 631 | + // setup the basic server |
|
| 632 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 633 | + self::$server->boot(); |
|
| 634 | + |
|
| 635 | + try { |
|
| 636 | + $profiler = new BuiltInProfiler( |
|
| 637 | + Server::get(IConfig::class), |
|
| 638 | + Server::get(IRequest::class), |
|
| 639 | + ); |
|
| 640 | + $profiler->start(); |
|
| 641 | + } catch (\Throwable $e) { |
|
| 642 | + logger('core')->error('Failed to start profiler: ' . $e->getMessage(), ['app' => 'base']); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + if (self::$CLI && in_array('--' . \OCP\Console\ReservedOptions::DEBUG_LOG, $_SERVER['argv'])) { |
|
| 646 | + \OC\Core\Listener\BeforeMessageLoggedEventListener::setup(); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $eventLogger = Server::get(\OCP\Diagnostics\IEventLogger::class); |
|
| 650 | + $eventLogger->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 651 | + $eventLogger->start('boot', 'Initialize'); |
|
| 652 | + |
|
| 653 | + // Override php.ini and log everything if we're troubleshooting |
|
| 654 | + if (self::$config->getValue('loglevel') === ILogger::DEBUG) { |
|
| 655 | + error_reporting(E_ALL); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // initialize intl fallback if necessary |
|
| 659 | + OC_Util::isSetLocaleWorking(); |
|
| 660 | + |
|
| 661 | + $config = Server::get(IConfig::class); |
|
| 662 | + if (!defined('PHPUNIT_RUN')) { |
|
| 663 | + $errorHandler = new OC\Log\ErrorHandler( |
|
| 664 | + \OCP\Server::get(\Psr\Log\LoggerInterface::class), |
|
| 665 | + ); |
|
| 666 | + $exceptionHandler = [$errorHandler, 'onException']; |
|
| 667 | + if ($config->getSystemValueBool('debug', false)) { |
|
| 668 | + set_error_handler([$errorHandler, 'onAll'], E_ALL); |
|
| 669 | + if (\OC::$CLI) { |
|
| 670 | + $exceptionHandler = [Server::get(ITemplateManager::class), 'printExceptionErrorPage']; |
|
| 671 | + } |
|
| 672 | + } else { |
|
| 673 | + set_error_handler([$errorHandler, 'onError']); |
|
| 674 | + } |
|
| 675 | + register_shutdown_function([$errorHandler, 'onShutdown']); |
|
| 676 | + set_exception_handler($exceptionHandler); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** @var \OC\AppFramework\Bootstrap\Coordinator $bootstrapCoordinator */ |
|
| 680 | + $bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); |
|
| 681 | + $bootstrapCoordinator->runInitialRegistration(); |
|
| 682 | + |
|
| 683 | + $eventLogger->start('init_session', 'Initialize session'); |
|
| 684 | + |
|
| 685 | + // Check for PHP SimpleXML extension earlier since we need it before our other checks and want to provide a useful hint for web users |
|
| 686 | + // see https://github.com/nextcloud/server/pull/2619 |
|
| 687 | + if (!function_exists('simplexml_load_file')) { |
|
| 688 | + throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.'); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $systemConfig = Server::get(\OC\SystemConfig::class); |
|
| 692 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 693 | + if ($systemConfig->getValue('installed', false)) { |
|
| 694 | + $appManager->loadApps(['session']); |
|
| 695 | + } |
|
| 696 | + if (!self::$CLI) { |
|
| 697 | + self::initSession(); |
|
| 698 | + } |
|
| 699 | + $eventLogger->end('init_session'); |
|
| 700 | + self::checkConfig(); |
|
| 701 | + self::checkInstalled($systemConfig); |
|
| 702 | + |
|
| 703 | + OC_Response::addSecurityHeaders(); |
|
| 704 | + |
|
| 705 | + self::performSameSiteCookieProtection($config); |
|
| 706 | + |
|
| 707 | + if (!defined('OC_CONSOLE')) { |
|
| 708 | + $eventLogger->start('check_server', 'Run a few configuration checks'); |
|
| 709 | + $errors = OC_Util::checkServer($systemConfig); |
|
| 710 | + if (count($errors) > 0) { |
|
| 711 | + if (!self::$CLI) { |
|
| 712 | + http_response_code(503); |
|
| 713 | + Util::addStyle('guest'); |
|
| 714 | + try { |
|
| 715 | + Server::get(ITemplateManager::class)->printGuestPage('', 'error', ['errors' => $errors]); |
|
| 716 | + exit; |
|
| 717 | + } catch (\Exception $e) { |
|
| 718 | + // In case any error happens when showing the error page, we simply fall back to posting the text. |
|
| 719 | + // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // Convert l10n string into regular string for usage in database |
|
| 724 | + $staticErrors = []; |
|
| 725 | + foreach ($errors as $error) { |
|
| 726 | + echo $error['error'] . "\n"; |
|
| 727 | + echo $error['hint'] . "\n\n"; |
|
| 728 | + $staticErrors[] = [ |
|
| 729 | + 'error' => (string)$error['error'], |
|
| 730 | + 'hint' => (string)$error['hint'], |
|
| 731 | + ]; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + try { |
|
| 735 | + $config->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 736 | + } catch (\Exception $e) { |
|
| 737 | + echo('Writing to database failed'); |
|
| 738 | + } |
|
| 739 | + exit(1); |
|
| 740 | + } elseif (self::$CLI && $config->getSystemValueBool('installed', false)) { |
|
| 741 | + $config->deleteAppValue('core', 'cronErrors'); |
|
| 742 | + } |
|
| 743 | + $eventLogger->end('check_server'); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + // User and Groups |
|
| 747 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 748 | + self::$server->getSession()->set('user_id', ''); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + $eventLogger->start('setup_backends', 'Setup group and user backends'); |
|
| 752 | + Server::get(\OCP\IUserManager::class)->registerBackend(new \OC\User\Database()); |
|
| 753 | + Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database()); |
|
| 754 | + |
|
| 755 | + // Subscribe to the hook |
|
| 756 | + \OCP\Util::connectHook( |
|
| 757 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 758 | + 'preLoginNameUsedAsUserName', |
|
| 759 | + '\OC\User\Database', |
|
| 760 | + 'preLoginNameUsedAsUserName' |
|
| 761 | + ); |
|
| 762 | + |
|
| 763 | + //setup extra user backends |
|
| 764 | + if (!\OCP\Util::needUpgrade()) { |
|
| 765 | + OC_User::setupBackends(); |
|
| 766 | + } else { |
|
| 767 | + // Run upgrades in incognito mode |
|
| 768 | + OC_User::setIncognitoMode(true); |
|
| 769 | + } |
|
| 770 | + $eventLogger->end('setup_backends'); |
|
| 771 | + |
|
| 772 | + self::registerCleanupHooks($systemConfig); |
|
| 773 | + self::registerShareHooks($systemConfig); |
|
| 774 | + self::registerEncryptionWrapperAndHooks(); |
|
| 775 | + self::registerAccountHooks(); |
|
| 776 | + self::registerResourceCollectionHooks(); |
|
| 777 | + self::registerFileReferenceEventListener(); |
|
| 778 | + self::registerRenderReferenceEventListener(); |
|
| 779 | + self::registerAppRestrictionsHooks(); |
|
| 780 | + |
|
| 781 | + // Make sure that the application class is not loaded before the database is setup |
|
| 782 | + if ($systemConfig->getValue('installed', false)) { |
|
| 783 | + $appManager->loadApp('settings'); |
|
| 784 | + /* Run core application registration */ |
|
| 785 | + $bootstrapCoordinator->runLazyRegistration('core'); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + //make sure temporary files are cleaned up |
|
| 789 | + $tmpManager = Server::get(\OCP\ITempManager::class); |
|
| 790 | + register_shutdown_function([$tmpManager, 'clean']); |
|
| 791 | + $lockProvider = Server::get(\OCP\Lock\ILockingProvider::class); |
|
| 792 | + register_shutdown_function([$lockProvider, 'releaseAll']); |
|
| 793 | + |
|
| 794 | + // Check whether the sample configuration has been copied |
|
| 795 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 796 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 797 | + Server::get(ITemplateManager::class)->printErrorPage( |
|
| 798 | + $l->t('Sample configuration detected'), |
|
| 799 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), |
|
| 800 | + 503 |
|
| 801 | + ); |
|
| 802 | + return; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + $request = Server::get(IRequest::class); |
|
| 806 | + $host = $request->getInsecureServerHost(); |
|
| 807 | + /** |
|
| 808 | + * if the host passed in headers isn't trusted |
|
| 809 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 810 | + */ |
|
| 811 | + if (!OC::$CLI |
|
| 812 | + && !Server::get(\OC\Security\TrustedDomainHelper::class)->isTrustedDomain($host) |
|
| 813 | + && $config->getSystemValueBool('installed', false) |
|
| 814 | + ) { |
|
| 815 | + // Allow access to CSS resources |
|
| 816 | + $isScssRequest = false; |
|
| 817 | + if (strpos($request->getPathInfo() ?: '', '/css/') === 0) { |
|
| 818 | + $isScssRequest = true; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 822 | + http_response_code(400); |
|
| 823 | + header('Content-Type: application/json'); |
|
| 824 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 825 | + exit(); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + if (!$isScssRequest) { |
|
| 829 | + http_response_code(400); |
|
| 830 | + Server::get(LoggerInterface::class)->info( |
|
| 831 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 832 | + [ |
|
| 833 | + 'app' => 'core', |
|
| 834 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 835 | + 'host' => $host, |
|
| 836 | + ] |
|
| 837 | + ); |
|
| 838 | + |
|
| 839 | + $tmpl = Server::get(ITemplateManager::class)->getTemplate('core', 'untrustedDomain', 'guest'); |
|
| 840 | + $tmpl->assign('docUrl', Server::get(IURLGenerator::class)->linkToDocs('admin-trusted-domains')); |
|
| 841 | + $tmpl->printPage(); |
|
| 842 | + |
|
| 843 | + exit(); |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + $eventLogger->end('boot'); |
|
| 847 | + $eventLogger->log('init', 'OC::init', $loaderStart, microtime(true)); |
|
| 848 | + $eventLogger->start('runtime', 'Runtime'); |
|
| 849 | + $eventLogger->start('request', 'Full request after boot'); |
|
| 850 | + register_shutdown_function(function () use ($eventLogger) { |
|
| 851 | + $eventLogger->end('request'); |
|
| 852 | + }); |
|
| 853 | + |
|
| 854 | + register_shutdown_function(function () { |
|
| 855 | + $memoryPeak = memory_get_peak_usage(); |
|
| 856 | + $logLevel = match (true) { |
|
| 857 | + $memoryPeak > 500_000_000 => ILogger::FATAL, |
|
| 858 | + $memoryPeak > 400_000_000 => ILogger::ERROR, |
|
| 859 | + $memoryPeak > 300_000_000 => ILogger::WARN, |
|
| 860 | + default => null, |
|
| 861 | + }; |
|
| 862 | + if ($logLevel !== null) { |
|
| 863 | + $message = 'Request used more than 300 MB of RAM: ' . Util::humanFileSize($memoryPeak); |
|
| 864 | + $logger = Server::get(LoggerInterface::class); |
|
| 865 | + $logger->log($logLevel, $message, ['app' => 'core']); |
|
| 866 | + } |
|
| 867 | + }); |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * register hooks for the cleanup of cache and bruteforce protection |
|
| 872 | + */ |
|
| 873 | + public static function registerCleanupHooks(\OC\SystemConfig $systemConfig): void { |
|
| 874 | + //don't try to do this before we are properly setup |
|
| 875 | + if ($systemConfig->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 876 | + // NOTE: This will be replaced to use OCP |
|
| 877 | + $userSession = Server::get(\OC\User\Session::class); |
|
| 878 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 879 | + if (!defined('PHPUNIT_RUN') && $userSession->isLoggedIn()) { |
|
| 880 | + // reset brute force delay for this IP address and username |
|
| 881 | + $uid = $userSession->getUser()->getUID(); |
|
| 882 | + $request = Server::get(IRequest::class); |
|
| 883 | + $throttler = Server::get(IThrottler::class); |
|
| 884 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 885 | + } |
|
| 886 | + }); |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + private static function registerEncryptionWrapperAndHooks(): void { |
|
| 891 | + /** @var \OC\Encryption\Manager */ |
|
| 892 | + $manager = Server::get(\OCP\Encryption\IManager::class); |
|
| 893 | + Server::get(IEventDispatcher::class)->addListener( |
|
| 894 | + BeforeFileSystemSetupEvent::class, |
|
| 895 | + $manager->setupStorage(...), |
|
| 896 | + ); |
|
| 897 | + |
|
| 898 | + $enabled = $manager->isEnabled(); |
|
| 899 | + if ($enabled) { |
|
| 900 | + \OC\Encryption\EncryptionEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + private static function registerAccountHooks(): void { |
|
| 905 | + /** @var IEventDispatcher $dispatcher */ |
|
| 906 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
| 907 | + $dispatcher->addServiceListener(UserChangedEvent::class, \OC\Accounts\Hooks::class); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + private static function registerAppRestrictionsHooks(): void { |
|
| 911 | + /** @var \OC\Group\Manager $groupManager */ |
|
| 912 | + $groupManager = Server::get(\OCP\IGroupManager::class); |
|
| 913 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OCP\IGroup $group) { |
|
| 914 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 915 | + $apps = $appManager->getEnabledAppsForGroup($group); |
|
| 916 | + foreach ($apps as $appId) { |
|
| 917 | + $restrictions = $appManager->getAppRestriction($appId); |
|
| 918 | + if (empty($restrictions)) { |
|
| 919 | + continue; |
|
| 920 | + } |
|
| 921 | + $key = array_search($group->getGID(), $restrictions); |
|
| 922 | + unset($restrictions[$key]); |
|
| 923 | + $restrictions = array_values($restrictions); |
|
| 924 | + if (empty($restrictions)) { |
|
| 925 | + $appManager->disableApp($appId); |
|
| 926 | + } else { |
|
| 927 | + $appManager->enableAppForGroups($appId, $restrictions); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + }); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + private static function registerResourceCollectionHooks(): void { |
|
| 934 | + \OC\Collaboration\Resources\Listener::register(Server::get(IEventDispatcher::class)); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + private static function registerFileReferenceEventListener(): void { |
|
| 938 | + \OC\Collaboration\Reference\File\FileReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + private static function registerRenderReferenceEventListener() { |
|
| 942 | + \OC\Collaboration\Reference\RenderReferenceEventListener::register(Server::get(IEventDispatcher::class)); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * register hooks for sharing |
|
| 947 | + */ |
|
| 948 | + public static function registerShareHooks(\OC\SystemConfig $systemConfig): void { |
|
| 949 | + if ($systemConfig->getValue('installed')) { |
|
| 950 | + |
|
| 951 | + $dispatcher = Server::get(IEventDispatcher::class); |
|
| 952 | + $dispatcher->addServiceListener(UserRemovedEvent::class, UserRemovedListener::class); |
|
| 953 | + $dispatcher->addServiceListener(GroupDeletedEvent::class, GroupDeletedListener::class); |
|
| 954 | + $dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + /** |
|
| 959 | + * Handle the request |
|
| 960 | + */ |
|
| 961 | + public static function handleRequest(): void { |
|
| 962 | + Server::get(\OCP\Diagnostics\IEventLogger::class)->start('handle_request', 'Handle request'); |
|
| 963 | + $systemConfig = Server::get(\OC\SystemConfig::class); |
|
| 964 | + |
|
| 965 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 966 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 967 | + \OC::$server->getSession()->clear(); |
|
| 968 | + $controller = Server::get(\OC\Core\Controller\SetupController::class); |
|
| 969 | + $controller->run($_POST); |
|
| 970 | + exit(); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + $request = Server::get(IRequest::class); |
|
| 974 | + $request->throwDecodingExceptionIfAny(); |
|
| 975 | + $requestPath = $request->getRawPathInfo(); |
|
| 976 | + if ($requestPath === '/heartbeat') { |
|
| 977 | + return; |
|
| 978 | + } |
|
| 979 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 980 | + self::checkMaintenanceMode($systemConfig); |
|
| 981 | + |
|
| 982 | + if (\OCP\Util::needUpgrade()) { |
|
| 983 | + if (function_exists('opcache_reset')) { |
|
| 984 | + opcache_reset(); |
|
| 985 | + } |
|
| 986 | + if (!((bool)$systemConfig->getValue('maintenance', false))) { |
|
| 987 | + self::printUpgradePage($systemConfig); |
|
| 988 | + exit(); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + $appManager = Server::get(\OCP\App\IAppManager::class); |
|
| 994 | + |
|
| 995 | + // Always load authentication apps |
|
| 996 | + $appManager->loadApps(['authentication']); |
|
| 997 | + $appManager->loadApps(['extended_authentication']); |
|
| 998 | + |
|
| 999 | + // Load minimum set of apps |
|
| 1000 | + if (!\OCP\Util::needUpgrade() |
|
| 1001 | + && !((bool)$systemConfig->getValue('maintenance', false))) { |
|
| 1002 | + // For logged-in users: Load everything |
|
| 1003 | + if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
| 1004 | + $appManager->loadApps(); |
|
| 1005 | + } else { |
|
| 1006 | + // For guests: Load only filesystem and logging |
|
| 1007 | + $appManager->loadApps(['filesystem', 'logging']); |
|
| 1008 | + |
|
| 1009 | + // Don't try to login when a client is trying to get a OAuth token. |
|
| 1010 | + // OAuth needs to support basic auth too, so the login is not valid |
|
| 1011 | + // inside Nextcloud and the Login exception would ruin it. |
|
| 1012 | + if ($request->getRawPathInfo() !== '/apps/oauth2/api/v1/token') { |
|
| 1013 | + try { |
|
| 1014 | + self::handleLogin($request); |
|
| 1015 | + } catch (DisabledUserException $e) { |
|
| 1016 | + // Disabled users would not be seen as logged in and |
|
| 1017 | + // trying to log them in would fail, so the login |
|
| 1018 | + // exception is ignored for the themed stylesheets and |
|
| 1019 | + // images. |
|
| 1020 | + if ($request->getRawPathInfo() !== '/apps/theming/theme/default.css' |
|
| 1021 | + && $request->getRawPathInfo() !== '/apps/theming/theme/light.css' |
|
| 1022 | + && $request->getRawPathInfo() !== '/apps/theming/theme/dark.css' |
|
| 1023 | + && $request->getRawPathInfo() !== '/apps/theming/theme/light-highcontrast.css' |
|
| 1024 | + && $request->getRawPathInfo() !== '/apps/theming/theme/dark-highcontrast.css' |
|
| 1025 | + && $request->getRawPathInfo() !== '/apps/theming/theme/opendyslexic.css' |
|
| 1026 | + && $request->getRawPathInfo() !== '/apps/theming/image/background' |
|
| 1027 | + && $request->getRawPathInfo() !== '/apps/theming/image/logo' |
|
| 1028 | + && $request->getRawPathInfo() !== '/apps/theming/image/logoheader' |
|
| 1029 | + && !str_starts_with($request->getRawPathInfo(), '/apps/theming/favicon') |
|
| 1030 | + && !str_starts_with($request->getRawPathInfo(), '/apps/theming/icon')) { |
|
| 1031 | + throw $e; |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + if (!self::$CLI) { |
|
| 1039 | + try { |
|
| 1040 | + if (!\OCP\Util::needUpgrade()) { |
|
| 1041 | + $appManager->loadApps(['filesystem', 'logging']); |
|
| 1042 | + $appManager->loadApps(); |
|
| 1043 | + } |
|
| 1044 | + Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); |
|
| 1045 | + return; |
|
| 1046 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 1047 | + //header('HTTP/1.0 404 Not Found'); |
|
| 1048 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 1049 | + http_response_code(405); |
|
| 1050 | + return; |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + // Handle WebDAV |
|
| 1055 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1056 | + // not allowed any more to prevent people |
|
| 1057 | + // mounting this root directly. |
|
| 1058 | + // Users need to mount remote.php/webdav instead. |
|
| 1059 | + http_response_code(405); |
|
| 1060 | + return; |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + // Handle requests for JSON or XML |
|
| 1064 | + $acceptHeader = $request->getHeader('Accept'); |
|
| 1065 | + if (in_array($acceptHeader, ['application/json', 'application/xml'], true)) { |
|
| 1066 | + http_response_code(404); |
|
| 1067 | + return; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + // Handle resources that can't be found |
|
| 1071 | + // This prevents browsers from redirecting to the default page and then |
|
| 1072 | + // attempting to parse HTML as CSS and similar. |
|
| 1073 | + $destinationHeader = $request->getHeader('Sec-Fetch-Dest'); |
|
| 1074 | + if (in_array($destinationHeader, ['font', 'script', 'style'])) { |
|
| 1075 | + http_response_code(404); |
|
| 1076 | + return; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + // Redirect to the default app or login only as an entry point |
|
| 1080 | + if ($requestPath === '') { |
|
| 1081 | + // Someone is logged in |
|
| 1082 | + if (Server::get(IUserSession::class)->isLoggedIn()) { |
|
| 1083 | + header('Location: ' . Server::get(IURLGenerator::class)->linkToDefaultPageUrl()); |
|
| 1084 | + } else { |
|
| 1085 | + // Not handled and not logged in |
|
| 1086 | + header('Location: ' . Server::get(IURLGenerator::class)->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1087 | + } |
|
| 1088 | + return; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + try { |
|
| 1092 | + Server::get(\OC\Route\Router::class)->match('/error/404'); |
|
| 1093 | + } catch (\Exception $e) { |
|
| 1094 | + if (!$e instanceof MethodNotAllowedException) { |
|
| 1095 | + logger('core')->emergency($e->getMessage(), ['exception' => $e]); |
|
| 1096 | + } |
|
| 1097 | + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); |
|
| 1098 | + Server::get(ITemplateManager::class)->printErrorPage( |
|
| 1099 | + '404', |
|
| 1100 | + $l->t('The page could not be found on the server.'), |
|
| 1101 | + 404 |
|
| 1102 | + ); |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + /** |
|
| 1107 | + * Check login: apache auth, auth token, basic auth |
|
| 1108 | + */ |
|
| 1109 | + public static function handleLogin(OCP\IRequest $request): bool { |
|
| 1110 | + if ($request->getHeader('X-Nextcloud-Federation')) { |
|
| 1111 | + return false; |
|
| 1112 | + } |
|
| 1113 | + $userSession = Server::get(\OC\User\Session::class); |
|
| 1114 | + if (OC_User::handleApacheAuth()) { |
|
| 1115 | + return true; |
|
| 1116 | + } |
|
| 1117 | + if (self::tryAppAPILogin($request)) { |
|
| 1118 | + return true; |
|
| 1119 | + } |
|
| 1120 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1121 | + return true; |
|
| 1122 | + } |
|
| 1123 | + if (isset($_COOKIE['nc_username']) |
|
| 1124 | + && isset($_COOKIE['nc_token']) |
|
| 1125 | + && isset($_COOKIE['nc_session_id']) |
|
| 1126 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1127 | + return true; |
|
| 1128 | + } |
|
| 1129 | + if ($userSession->tryBasicAuthLogin($request, Server::get(IThrottler::class))) { |
|
| 1130 | + return true; |
|
| 1131 | + } |
|
| 1132 | + return false; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + protected static function handleAuthHeaders(): void { |
|
| 1136 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1137 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1138 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1142 | + $vars = [ |
|
| 1143 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1144 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1145 | + ]; |
|
| 1146 | + foreach ($vars as $var) { |
|
| 1147 | + if (isset($_SERVER[$var]) && is_string($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1148 | + $credentials = explode(':', base64_decode($matches[1]), 2); |
|
| 1149 | + if (count($credentials) === 2) { |
|
| 1150 | + $_SERVER['PHP_AUTH_USER'] = $credentials[0]; |
|
| 1151 | + $_SERVER['PHP_AUTH_PW'] = $credentials[1]; |
|
| 1152 | + break; |
|
| 1153 | + } |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + protected static function tryAppAPILogin(OCP\IRequest $request): bool { |
|
| 1159 | + if (!$request->getHeader('AUTHORIZATION-APP-API')) { |
|
| 1160 | + return false; |
|
| 1161 | + } |
|
| 1162 | + $appManager = Server::get(OCP\App\IAppManager::class); |
|
| 1163 | + if (!$appManager->isEnabledForAnyone('app_api')) { |
|
| 1164 | + return false; |
|
| 1165 | + } |
|
| 1166 | + try { |
|
| 1167 | + $appAPIService = Server::get(OCA\AppAPI\Service\AppAPIService::class); |
|
| 1168 | + return $appAPIService->validateExAppRequestToNC($request); |
|
| 1169 | + } catch (\Psr\Container\NotFoundExceptionInterface|\Psr\Container\ContainerExceptionInterface $e) { |
|
| 1170 | + return false; |
|
| 1171 | + } |
|
| 1172 | + } |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | OC::init(); |
@@ -34,250 +34,250 @@ |
||
| 34 | 34 | * @package OC\Core\Controller |
| 35 | 35 | */ |
| 36 | 36 | class AvatarController extends Controller { |
| 37 | - public function __construct( |
|
| 38 | - string $appName, |
|
| 39 | - IRequest $request, |
|
| 40 | - protected IAvatarManager $avatarManager, |
|
| 41 | - protected IL10N $l10n, |
|
| 42 | - protected IUserManager $userManager, |
|
| 43 | - protected IRootFolder $rootFolder, |
|
| 44 | - protected LoggerInterface $logger, |
|
| 45 | - protected ?string $userId, |
|
| 46 | - protected TimeFactory $timeFactory, |
|
| 47 | - protected GuestAvatarController $guestAvatarController, |
|
| 48 | - ) { |
|
| 49 | - parent::__construct($appName, $request); |
|
| 50 | - } |
|
| 37 | + public function __construct( |
|
| 38 | + string $appName, |
|
| 39 | + IRequest $request, |
|
| 40 | + protected IAvatarManager $avatarManager, |
|
| 41 | + protected IL10N $l10n, |
|
| 42 | + protected IUserManager $userManager, |
|
| 43 | + protected IRootFolder $rootFolder, |
|
| 44 | + protected LoggerInterface $logger, |
|
| 45 | + protected ?string $userId, |
|
| 46 | + protected TimeFactory $timeFactory, |
|
| 47 | + protected GuestAvatarController $guestAvatarController, |
|
| 48 | + ) { |
|
| 49 | + parent::__construct($appName, $request); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @NoSameSiteCookieRequired |
|
| 54 | - * |
|
| 55 | - * Get the dark avatar |
|
| 56 | - * |
|
| 57 | - * @param string $userId ID of the user |
|
| 58 | - * @param 64|512 $size Size of the avatar |
|
| 59 | - * @param bool $guestFallback Fallback to guest avatar if not found |
|
| 60 | - * @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, list<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}> |
|
| 61 | - * |
|
| 62 | - * 200: Avatar returned |
|
| 63 | - * 201: Avatar returned |
|
| 64 | - * 404: Avatar not found |
|
| 65 | - */ |
|
| 66 | - #[NoCSRFRequired] |
|
| 67 | - #[PublicPage] |
|
| 68 | - #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}/dark')] |
|
| 69 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 70 | - public function getAvatarDark(string $userId, int $size, bool $guestFallback = false) { |
|
| 71 | - if ($size <= 64) { |
|
| 72 | - if ($size !== 64) { |
|
| 73 | - $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 74 | - } |
|
| 75 | - $size = 64; |
|
| 76 | - } else { |
|
| 77 | - if ($size !== 512) { |
|
| 78 | - $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 79 | - } |
|
| 80 | - $size = 512; |
|
| 81 | - } |
|
| 52 | + /** |
|
| 53 | + * @NoSameSiteCookieRequired |
|
| 54 | + * |
|
| 55 | + * Get the dark avatar |
|
| 56 | + * |
|
| 57 | + * @param string $userId ID of the user |
|
| 58 | + * @param 64|512 $size Size of the avatar |
|
| 59 | + * @param bool $guestFallback Fallback to guest avatar if not found |
|
| 60 | + * @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, list<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}> |
|
| 61 | + * |
|
| 62 | + * 200: Avatar returned |
|
| 63 | + * 201: Avatar returned |
|
| 64 | + * 404: Avatar not found |
|
| 65 | + */ |
|
| 66 | + #[NoCSRFRequired] |
|
| 67 | + #[PublicPage] |
|
| 68 | + #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}/dark')] |
|
| 69 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 70 | + public function getAvatarDark(string $userId, int $size, bool $guestFallback = false) { |
|
| 71 | + if ($size <= 64) { |
|
| 72 | + if ($size !== 64) { |
|
| 73 | + $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 74 | + } |
|
| 75 | + $size = 64; |
|
| 76 | + } else { |
|
| 77 | + if ($size !== 512) { |
|
| 78 | + $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 79 | + } |
|
| 80 | + $size = 512; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - try { |
|
| 84 | - $avatar = $this->avatarManager->getAvatar($userId); |
|
| 85 | - $avatarFile = $avatar->getFile($size, true); |
|
| 86 | - $response = new FileDisplayResponse( |
|
| 87 | - $avatarFile, |
|
| 88 | - Http::STATUS_OK, |
|
| 89 | - ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
| 90 | - ); |
|
| 91 | - } catch (\Exception $e) { |
|
| 92 | - if ($guestFallback) { |
|
| 93 | - return $this->guestAvatarController->getAvatarDark($userId, $size); |
|
| 94 | - } |
|
| 95 | - return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
| 96 | - } |
|
| 83 | + try { |
|
| 84 | + $avatar = $this->avatarManager->getAvatar($userId); |
|
| 85 | + $avatarFile = $avatar->getFile($size, true); |
|
| 86 | + $response = new FileDisplayResponse( |
|
| 87 | + $avatarFile, |
|
| 88 | + Http::STATUS_OK, |
|
| 89 | + ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
| 90 | + ); |
|
| 91 | + } catch (\Exception $e) { |
|
| 92 | + if ($guestFallback) { |
|
| 93 | + return $this->guestAvatarController->getAvatarDark($userId, $size); |
|
| 94 | + } |
|
| 95 | + return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - // Cache for 1 day |
|
| 99 | - $response->cacheFor(60 * 60 * 24, false, true); |
|
| 100 | - return $response; |
|
| 101 | - } |
|
| 98 | + // Cache for 1 day |
|
| 99 | + $response->cacheFor(60 * 60 * 24, false, true); |
|
| 100 | + return $response; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @NoSameSiteCookieRequired |
|
| 106 | - * |
|
| 107 | - * Get the avatar |
|
| 108 | - * |
|
| 109 | - * @param string $userId ID of the user |
|
| 110 | - * @param 64|512 $size Size of the avatar |
|
| 111 | - * @param bool $guestFallback Fallback to guest avatar if not found |
|
| 112 | - * @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, list<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}> |
|
| 113 | - * |
|
| 114 | - * 200: Avatar returned |
|
| 115 | - * 201: Avatar returned |
|
| 116 | - * 404: Avatar not found |
|
| 117 | - */ |
|
| 118 | - #[NoCSRFRequired] |
|
| 119 | - #[PublicPage] |
|
| 120 | - #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}')] |
|
| 121 | - #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 122 | - public function getAvatar(string $userId, int $size, bool $guestFallback = false) { |
|
| 123 | - if ($size <= 64) { |
|
| 124 | - if ($size !== 64) { |
|
| 125 | - $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 126 | - } |
|
| 127 | - $size = 64; |
|
| 128 | - } else { |
|
| 129 | - if ($size !== 512) { |
|
| 130 | - $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 131 | - } |
|
| 132 | - $size = 512; |
|
| 133 | - } |
|
| 104 | + /** |
|
| 105 | + * @NoSameSiteCookieRequired |
|
| 106 | + * |
|
| 107 | + * Get the avatar |
|
| 108 | + * |
|
| 109 | + * @param string $userId ID of the user |
|
| 110 | + * @param 64|512 $size Size of the avatar |
|
| 111 | + * @param bool $guestFallback Fallback to guest avatar if not found |
|
| 112 | + * @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, list<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}> |
|
| 113 | + * |
|
| 114 | + * 200: Avatar returned |
|
| 115 | + * 201: Avatar returned |
|
| 116 | + * 404: Avatar not found |
|
| 117 | + */ |
|
| 118 | + #[NoCSRFRequired] |
|
| 119 | + #[PublicPage] |
|
| 120 | + #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}')] |
|
| 121 | + #[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)] |
|
| 122 | + public function getAvatar(string $userId, int $size, bool $guestFallback = false) { |
|
| 123 | + if ($size <= 64) { |
|
| 124 | + if ($size !== 64) { |
|
| 125 | + $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 126 | + } |
|
| 127 | + $size = 64; |
|
| 128 | + } else { |
|
| 129 | + if ($size !== 512) { |
|
| 130 | + $this->logger->debug('Avatar requested in deprecated size ' . $size); |
|
| 131 | + } |
|
| 132 | + $size = 512; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - try { |
|
| 136 | - $avatar = $this->avatarManager->getAvatar($userId); |
|
| 137 | - $avatarFile = $avatar->getFile($size); |
|
| 138 | - $response = new FileDisplayResponse( |
|
| 139 | - $avatarFile, |
|
| 140 | - Http::STATUS_OK, |
|
| 141 | - ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
| 142 | - ); |
|
| 143 | - } catch (\Exception $e) { |
|
| 144 | - if ($guestFallback) { |
|
| 145 | - return $this->guestAvatarController->getAvatar($userId, $size); |
|
| 146 | - } |
|
| 147 | - return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
| 148 | - } |
|
| 135 | + try { |
|
| 136 | + $avatar = $this->avatarManager->getAvatar($userId); |
|
| 137 | + $avatarFile = $avatar->getFile($size); |
|
| 138 | + $response = new FileDisplayResponse( |
|
| 139 | + $avatarFile, |
|
| 140 | + Http::STATUS_OK, |
|
| 141 | + ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] |
|
| 142 | + ); |
|
| 143 | + } catch (\Exception $e) { |
|
| 144 | + if ($guestFallback) { |
|
| 145 | + return $this->guestAvatarController->getAvatar($userId, $size); |
|
| 146 | + } |
|
| 147 | + return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - // Cache for 1 day |
|
| 151 | - $response->cacheFor(60 * 60 * 24, false, true); |
|
| 152 | - return $response; |
|
| 153 | - } |
|
| 150 | + // Cache for 1 day |
|
| 151 | + $response->cacheFor(60 * 60 * 24, false, true); |
|
| 152 | + return $response; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - #[NoAdminRequired] |
|
| 156 | - #[FrontpageRoute(verb: 'POST', url: '/avatar/')] |
|
| 157 | - public function postAvatar(?string $path = null): JSONResponse { |
|
| 158 | - $files = $this->request->getUploadedFile('files'); |
|
| 155 | + #[NoAdminRequired] |
|
| 156 | + #[FrontpageRoute(verb: 'POST', url: '/avatar/')] |
|
| 157 | + public function postAvatar(?string $path = null): JSONResponse { |
|
| 158 | + $files = $this->request->getUploadedFile('files'); |
|
| 159 | 159 | |
| 160 | - if (isset($path)) { |
|
| 161 | - $path = stripslashes($path); |
|
| 162 | - $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 163 | - /** @var File $node */ |
|
| 164 | - $node = $userFolder->get($path); |
|
| 165 | - if (!($node instanceof File)) { |
|
| 166 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('Please select a file.')]]); |
|
| 167 | - } |
|
| 168 | - if ($node->getSize() > 20 * 1024 * 1024) { |
|
| 169 | - return new JSONResponse( |
|
| 170 | - ['data' => ['message' => $this->l10n->t('File is too big')]], |
|
| 171 | - Http::STATUS_BAD_REQUEST |
|
| 172 | - ); |
|
| 173 | - } |
|
| 160 | + if (isset($path)) { |
|
| 161 | + $path = stripslashes($path); |
|
| 162 | + $userFolder = $this->rootFolder->getUserFolder($this->userId); |
|
| 163 | + /** @var File $node */ |
|
| 164 | + $node = $userFolder->get($path); |
|
| 165 | + if (!($node instanceof File)) { |
|
| 166 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('Please select a file.')]]); |
|
| 167 | + } |
|
| 168 | + if ($node->getSize() > 20 * 1024 * 1024) { |
|
| 169 | + return new JSONResponse( |
|
| 170 | + ['data' => ['message' => $this->l10n->t('File is too big')]], |
|
| 171 | + Http::STATUS_BAD_REQUEST |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
| 176 | - return new JSONResponse( |
|
| 177 | - ['data' => ['message' => $this->l10n->t('The selected file is not an image.')]], |
|
| 178 | - Http::STATUS_BAD_REQUEST |
|
| 179 | - ); |
|
| 180 | - } |
|
| 175 | + if ($node->getMimeType() !== 'image/jpeg' && $node->getMimeType() !== 'image/png') { |
|
| 176 | + return new JSONResponse( |
|
| 177 | + ['data' => ['message' => $this->l10n->t('The selected file is not an image.')]], |
|
| 178 | + Http::STATUS_BAD_REQUEST |
|
| 179 | + ); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - try { |
|
| 183 | - $content = $node->getContent(); |
|
| 184 | - } catch (NotPermittedException $e) { |
|
| 185 | - return new JSONResponse( |
|
| 186 | - ['data' => ['message' => $this->l10n->t('The selected file cannot be read.')]], |
|
| 187 | - Http::STATUS_BAD_REQUEST |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - } elseif (!is_null($files)) { |
|
| 191 | - if ( |
|
| 192 | - $files['error'][0] === 0 |
|
| 193 | - && is_uploaded_file($files['tmp_name'][0]) |
|
| 194 | - ) { |
|
| 195 | - if ($files['size'][0] > 20 * 1024 * 1024) { |
|
| 196 | - return new JSONResponse( |
|
| 197 | - ['data' => ['message' => $this->l10n->t('File is too big')]], |
|
| 198 | - Http::STATUS_BAD_REQUEST |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - $content = file_get_contents($files['tmp_name'][0]); |
|
| 202 | - unlink($files['tmp_name'][0]); |
|
| 203 | - } else { |
|
| 204 | - $phpFileUploadErrors = [ |
|
| 205 | - UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
| 206 | - UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 207 | - UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 208 | - UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
| 209 | - UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 210 | - UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 211 | - UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
| 212 | - UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
| 213 | - ]; |
|
| 214 | - $message = $phpFileUploadErrors[$files['error'][0]] ?? $this->l10n->t('Invalid file provided'); |
|
| 215 | - $this->logger->warning($message, ['app' => 'core']); |
|
| 216 | - return new JSONResponse( |
|
| 217 | - ['data' => ['message' => $message]], |
|
| 218 | - Http::STATUS_BAD_REQUEST |
|
| 219 | - ); |
|
| 220 | - } |
|
| 221 | - } else { |
|
| 222 | - //Add imgfile |
|
| 223 | - return new JSONResponse( |
|
| 224 | - ['data' => ['message' => $this->l10n->t('No image or file provided')]], |
|
| 225 | - Http::STATUS_BAD_REQUEST |
|
| 226 | - ); |
|
| 227 | - } |
|
| 182 | + try { |
|
| 183 | + $content = $node->getContent(); |
|
| 184 | + } catch (NotPermittedException $e) { |
|
| 185 | + return new JSONResponse( |
|
| 186 | + ['data' => ['message' => $this->l10n->t('The selected file cannot be read.')]], |
|
| 187 | + Http::STATUS_BAD_REQUEST |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + } elseif (!is_null($files)) { |
|
| 191 | + if ( |
|
| 192 | + $files['error'][0] === 0 |
|
| 193 | + && is_uploaded_file($files['tmp_name'][0]) |
|
| 194 | + ) { |
|
| 195 | + if ($files['size'][0] > 20 * 1024 * 1024) { |
|
| 196 | + return new JSONResponse( |
|
| 197 | + ['data' => ['message' => $this->l10n->t('File is too big')]], |
|
| 198 | + Http::STATUS_BAD_REQUEST |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + $content = file_get_contents($files['tmp_name'][0]); |
|
| 202 | + unlink($files['tmp_name'][0]); |
|
| 203 | + } else { |
|
| 204 | + $phpFileUploadErrors = [ |
|
| 205 | + UPLOAD_ERR_OK => $this->l10n->t('The file was uploaded'), |
|
| 206 | + UPLOAD_ERR_INI_SIZE => $this->l10n->t('The uploaded file exceeds the upload_max_filesize directive in php.ini'), |
|
| 207 | + UPLOAD_ERR_FORM_SIZE => $this->l10n->t('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), |
|
| 208 | + UPLOAD_ERR_PARTIAL => $this->l10n->t('The file was only partially uploaded'), |
|
| 209 | + UPLOAD_ERR_NO_FILE => $this->l10n->t('No file was uploaded'), |
|
| 210 | + UPLOAD_ERR_NO_TMP_DIR => $this->l10n->t('Missing a temporary folder'), |
|
| 211 | + UPLOAD_ERR_CANT_WRITE => $this->l10n->t('Could not write file to disk'), |
|
| 212 | + UPLOAD_ERR_EXTENSION => $this->l10n->t('A PHP extension stopped the file upload'), |
|
| 213 | + ]; |
|
| 214 | + $message = $phpFileUploadErrors[$files['error'][0]] ?? $this->l10n->t('Invalid file provided'); |
|
| 215 | + $this->logger->warning($message, ['app' => 'core']); |
|
| 216 | + return new JSONResponse( |
|
| 217 | + ['data' => ['message' => $message]], |
|
| 218 | + Http::STATUS_BAD_REQUEST |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | + } else { |
|
| 222 | + //Add imgfile |
|
| 223 | + return new JSONResponse( |
|
| 224 | + ['data' => ['message' => $this->l10n->t('No image or file provided')]], |
|
| 225 | + Http::STATUS_BAD_REQUEST |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - try { |
|
| 230 | - $image = new Image(); |
|
| 231 | - $image->loadFromData($content); |
|
| 232 | - $image->readExif($content); |
|
| 233 | - $image->fixOrientation(); |
|
| 229 | + try { |
|
| 230 | + $image = new Image(); |
|
| 231 | + $image->loadFromData($content); |
|
| 232 | + $image->readExif($content); |
|
| 233 | + $image->fixOrientation(); |
|
| 234 | 234 | |
| 235 | - if ($image->valid()) { |
|
| 236 | - $mimeType = $image->mimeType(); |
|
| 237 | - if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
| 238 | - return new JSONResponse( |
|
| 239 | - ['data' => ['message' => $this->l10n->t('Unknown filetype')]], |
|
| 240 | - Http::STATUS_OK |
|
| 241 | - ); |
|
| 242 | - } |
|
| 235 | + if ($image->valid()) { |
|
| 236 | + $mimeType = $image->mimeType(); |
|
| 237 | + if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { |
|
| 238 | + return new JSONResponse( |
|
| 239 | + ['data' => ['message' => $this->l10n->t('Unknown filetype')]], |
|
| 240 | + Http::STATUS_OK |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - if ($image->width() === $image->height()) { |
|
| 245 | - try { |
|
| 246 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 247 | - $avatar->set($image); |
|
| 248 | - return new JSONResponse(['status' => 'success']); |
|
| 249 | - } catch (\Throwable $e) { |
|
| 250 | - $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 251 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 252 | - } |
|
| 253 | - } |
|
| 244 | + if ($image->width() === $image->height()) { |
|
| 245 | + try { |
|
| 246 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 247 | + $avatar->set($image); |
|
| 248 | + return new JSONResponse(['status' => 'success']); |
|
| 249 | + } catch (\Throwable $e) { |
|
| 250 | + $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 251 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return new JSONResponse( |
|
| 256 | - ['data' => 'notsquare', 'image' => 'data:' . $mimeType . ';base64,' . base64_encode($image->data())], |
|
| 257 | - Http::STATUS_OK |
|
| 258 | - ); |
|
| 259 | - } else { |
|
| 260 | - return new JSONResponse( |
|
| 261 | - ['data' => ['message' => $this->l10n->t('Invalid image')]], |
|
| 262 | - Http::STATUS_OK |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - } catch (\Exception $e) { |
|
| 266 | - $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 267 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
| 268 | - } |
|
| 269 | - } |
|
| 255 | + return new JSONResponse( |
|
| 256 | + ['data' => 'notsquare', 'image' => 'data:' . $mimeType . ';base64,' . base64_encode($image->data())], |
|
| 257 | + Http::STATUS_OK |
|
| 258 | + ); |
|
| 259 | + } else { |
|
| 260 | + return new JSONResponse( |
|
| 261 | + ['data' => ['message' => $this->l10n->t('Invalid image')]], |
|
| 262 | + Http::STATUS_OK |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + } catch (\Exception $e) { |
|
| 266 | + $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 267 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_OK); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - #[NoAdminRequired] |
|
| 272 | - #[FrontpageRoute(verb: 'DELETE', url: '/avatar/')] |
|
| 273 | - public function deleteAvatar(): JSONResponse { |
|
| 274 | - try { |
|
| 275 | - $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 276 | - $avatar->remove(); |
|
| 277 | - return new JSONResponse(); |
|
| 278 | - } catch (\Exception $e) { |
|
| 279 | - $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 280 | - return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 281 | - } |
|
| 282 | - } |
|
| 271 | + #[NoAdminRequired] |
|
| 272 | + #[FrontpageRoute(verb: 'DELETE', url: '/avatar/')] |
|
| 273 | + public function deleteAvatar(): JSONResponse { |
|
| 274 | + try { |
|
| 275 | + $avatar = $this->avatarManager->getAvatar($this->userId); |
|
| 276 | + $avatar->remove(); |
|
| 277 | + return new JSONResponse(); |
|
| 278 | + } catch (\Exception $e) { |
|
| 279 | + $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => 'core']); |
|
| 280 | + return new JSONResponse(['data' => ['message' => $this->l10n->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -29,189 +29,189 @@ |
||
| 29 | 29 | use Sabre\HTTP\ResponseInterface; |
| 30 | 30 | |
| 31 | 31 | class Auth extends AbstractBasic { |
| 32 | - public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; |
|
| 33 | - private ?string $currentUser = null; |
|
| 34 | - |
|
| 35 | - public function __construct( |
|
| 36 | - private ISession $session, |
|
| 37 | - private Session $userSession, |
|
| 38 | - private IRequest $request, |
|
| 39 | - private Manager $twoFactorManager, |
|
| 40 | - private IThrottler $throttler, |
|
| 41 | - private SetupManager $setupManager, |
|
| 42 | - string $principalPrefix = 'principals/users/', |
|
| 43 | - ) { |
|
| 44 | - $this->principalPrefix = $principalPrefix; |
|
| 45 | - |
|
| 46 | - // setup realm |
|
| 47 | - $defaults = new Defaults(); |
|
| 48 | - $this->realm = $defaults->getName() ?: 'Nextcloud'; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Whether the user has initially authenticated via DAV |
|
| 53 | - * |
|
| 54 | - * This is required for WebDAV clients that resent the cookies even when the |
|
| 55 | - * account was changed. |
|
| 56 | - * |
|
| 57 | - * @see https://github.com/owncloud/core/issues/13245 |
|
| 58 | - */ |
|
| 59 | - public function isDavAuthenticated(string $username): bool { |
|
| 60 | - return !is_null($this->session->get(self::DAV_AUTHENTICATED)) |
|
| 61 | - && $this->session->get(self::DAV_AUTHENTICATED) === $username; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Validates a username and password |
|
| 66 | - * |
|
| 67 | - * This method should return true or false depending on if login |
|
| 68 | - * succeeded. |
|
| 69 | - * |
|
| 70 | - * @param string $username |
|
| 71 | - * @param string $password |
|
| 72 | - * @return bool |
|
| 73 | - * @throws PasswordLoginForbidden |
|
| 74 | - */ |
|
| 75 | - protected function validateUserPass($username, $password) { |
|
| 76 | - if ($this->userSession->isLoggedIn() |
|
| 77 | - && $this->isDavAuthenticated($this->userSession->getUser()->getUID()) |
|
| 78 | - ) { |
|
| 79 | - $this->session->close(); |
|
| 80 | - return true; |
|
| 81 | - } else { |
|
| 82 | - try { |
|
| 83 | - if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) { |
|
| 84 | - $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID()); |
|
| 85 | - $this->session->close(); |
|
| 86 | - return true; |
|
| 87 | - } else { |
|
| 88 | - $this->session->close(); |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - } catch (PasswordLoginForbiddenException $ex) { |
|
| 92 | - $this->session->close(); |
|
| 93 | - throw new PasswordLoginForbidden(); |
|
| 94 | - } catch (MaxDelayReached $ex) { |
|
| 95 | - $this->session->close(); |
|
| 96 | - throw new TooManyRequests(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return array{bool, string} |
|
| 103 | - * @throws NotAuthenticated |
|
| 104 | - * @throws ServiceUnavailable |
|
| 105 | - */ |
|
| 106 | - public function check(RequestInterface $request, ResponseInterface $response) { |
|
| 107 | - try { |
|
| 108 | - return $this->auth($request, $response); |
|
| 109 | - } catch (NotAuthenticated $e) { |
|
| 110 | - throw $e; |
|
| 111 | - } catch (Exception $e) { |
|
| 112 | - $class = get_class($e); |
|
| 113 | - $msg = $e->getMessage(); |
|
| 114 | - Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
|
| 115 | - throw new ServiceUnavailable("$class: $msg"); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Checks whether a CSRF check is required on the request |
|
| 121 | - */ |
|
| 122 | - private function requiresCSRFCheck(): bool { |
|
| 123 | - |
|
| 124 | - $methodsWithoutCsrf = ['GET', 'HEAD', 'OPTIONS']; |
|
| 125 | - if (in_array($this->request->getMethod(), $methodsWithoutCsrf)) { |
|
| 126 | - return false; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Official Nextcloud clients require no checks |
|
| 130 | - if ($this->request->isUserAgent([ |
|
| 131 | - IRequest::USER_AGENT_CLIENT_DESKTOP, |
|
| 132 | - IRequest::USER_AGENT_CLIENT_ANDROID, |
|
| 133 | - IRequest::USER_AGENT_CLIENT_IOS, |
|
| 134 | - ])) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // If not logged-in no check is required |
|
| 139 | - if (!$this->userSession->isLoggedIn()) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // POST always requires a check |
|
| 144 | - if ($this->request->getMethod() === 'POST') { |
|
| 145 | - return true; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // If logged-in AND DAV authenticated no check is required |
|
| 149 | - if ($this->userSession->isLoggedIn() |
|
| 150 | - && $this->isDavAuthenticated($this->userSession->getUser()->getUID())) { |
|
| 151 | - return false; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return true; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return array{bool, string} |
|
| 159 | - * @throws NotAuthenticated |
|
| 160 | - */ |
|
| 161 | - private function auth(RequestInterface $request, ResponseInterface $response): array { |
|
| 162 | - $forcedLogout = false; |
|
| 163 | - |
|
| 164 | - if (!$this->request->passesCSRFCheck() |
|
| 165 | - && $this->requiresCSRFCheck()) { |
|
| 166 | - // In case of a fail with POST we need to recheck the credentials |
|
| 167 | - if ($this->request->getMethod() === 'POST') { |
|
| 168 | - $forcedLogout = true; |
|
| 169 | - } else { |
|
| 170 | - $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 171 | - throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.'); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($forcedLogout) { |
|
| 176 | - $this->userSession->logout(); |
|
| 177 | - } else { |
|
| 178 | - if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) { |
|
| 179 | - throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.'); |
|
| 180 | - } |
|
| 181 | - if ( |
|
| 182 | - //Fix for broken webdav clients |
|
| 183 | - ($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) |
|
| 184 | - //Well behaved clients that only send the cookie are allowed |
|
| 185 | - || ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization'))) |
|
| 186 | - || \OC_User::handleApacheAuth() |
|
| 187 | - ) { |
|
| 188 | - $user = $this->userSession->getUser(); |
|
| 189 | - $this->setupManager->setupForUser($user); |
|
| 190 | - |
|
| 191 | - $uid = $user->getUID(); |
|
| 192 | - $this->currentUser = $uid; |
|
| 193 | - $this->session->close(); |
|
| 194 | - return [true, $this->principalPrefix . $uid]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $data = parent::check($request, $response); |
|
| 199 | - if ($data[0] === true) { |
|
| 200 | - $startPos = strrpos($data[1], '/') + 1; |
|
| 201 | - $user = $this->userSession->getUser()->getUID(); |
|
| 202 | - $data[1] = substr_replace($data[1], $user, $startPos); |
|
| 203 | - } elseif (in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With') ?? ''))) { |
|
| 204 | - // For ajax requests use dummy auth name to prevent browser popup in case of invalid creditials |
|
| 205 | - $response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"'); |
|
| 206 | - $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 207 | - throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $user = $this->userSession->getUser(); |
|
| 211 | - if ($user !== null) { |
|
| 212 | - $this->setupManager->setupForUser($user); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return $data; |
|
| 216 | - } |
|
| 32 | + public const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND'; |
|
| 33 | + private ?string $currentUser = null; |
|
| 34 | + |
|
| 35 | + public function __construct( |
|
| 36 | + private ISession $session, |
|
| 37 | + private Session $userSession, |
|
| 38 | + private IRequest $request, |
|
| 39 | + private Manager $twoFactorManager, |
|
| 40 | + private IThrottler $throttler, |
|
| 41 | + private SetupManager $setupManager, |
|
| 42 | + string $principalPrefix = 'principals/users/', |
|
| 43 | + ) { |
|
| 44 | + $this->principalPrefix = $principalPrefix; |
|
| 45 | + |
|
| 46 | + // setup realm |
|
| 47 | + $defaults = new Defaults(); |
|
| 48 | + $this->realm = $defaults->getName() ?: 'Nextcloud'; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Whether the user has initially authenticated via DAV |
|
| 53 | + * |
|
| 54 | + * This is required for WebDAV clients that resent the cookies even when the |
|
| 55 | + * account was changed. |
|
| 56 | + * |
|
| 57 | + * @see https://github.com/owncloud/core/issues/13245 |
|
| 58 | + */ |
|
| 59 | + public function isDavAuthenticated(string $username): bool { |
|
| 60 | + return !is_null($this->session->get(self::DAV_AUTHENTICATED)) |
|
| 61 | + && $this->session->get(self::DAV_AUTHENTICATED) === $username; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Validates a username and password |
|
| 66 | + * |
|
| 67 | + * This method should return true or false depending on if login |
|
| 68 | + * succeeded. |
|
| 69 | + * |
|
| 70 | + * @param string $username |
|
| 71 | + * @param string $password |
|
| 72 | + * @return bool |
|
| 73 | + * @throws PasswordLoginForbidden |
|
| 74 | + */ |
|
| 75 | + protected function validateUserPass($username, $password) { |
|
| 76 | + if ($this->userSession->isLoggedIn() |
|
| 77 | + && $this->isDavAuthenticated($this->userSession->getUser()->getUID()) |
|
| 78 | + ) { |
|
| 79 | + $this->session->close(); |
|
| 80 | + return true; |
|
| 81 | + } else { |
|
| 82 | + try { |
|
| 83 | + if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) { |
|
| 84 | + $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID()); |
|
| 85 | + $this->session->close(); |
|
| 86 | + return true; |
|
| 87 | + } else { |
|
| 88 | + $this->session->close(); |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } catch (PasswordLoginForbiddenException $ex) { |
|
| 92 | + $this->session->close(); |
|
| 93 | + throw new PasswordLoginForbidden(); |
|
| 94 | + } catch (MaxDelayReached $ex) { |
|
| 95 | + $this->session->close(); |
|
| 96 | + throw new TooManyRequests(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return array{bool, string} |
|
| 103 | + * @throws NotAuthenticated |
|
| 104 | + * @throws ServiceUnavailable |
|
| 105 | + */ |
|
| 106 | + public function check(RequestInterface $request, ResponseInterface $response) { |
|
| 107 | + try { |
|
| 108 | + return $this->auth($request, $response); |
|
| 109 | + } catch (NotAuthenticated $e) { |
|
| 110 | + throw $e; |
|
| 111 | + } catch (Exception $e) { |
|
| 112 | + $class = get_class($e); |
|
| 113 | + $msg = $e->getMessage(); |
|
| 114 | + Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
|
| 115 | + throw new ServiceUnavailable("$class: $msg"); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Checks whether a CSRF check is required on the request |
|
| 121 | + */ |
|
| 122 | + private function requiresCSRFCheck(): bool { |
|
| 123 | + |
|
| 124 | + $methodsWithoutCsrf = ['GET', 'HEAD', 'OPTIONS']; |
|
| 125 | + if (in_array($this->request->getMethod(), $methodsWithoutCsrf)) { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Official Nextcloud clients require no checks |
|
| 130 | + if ($this->request->isUserAgent([ |
|
| 131 | + IRequest::USER_AGENT_CLIENT_DESKTOP, |
|
| 132 | + IRequest::USER_AGENT_CLIENT_ANDROID, |
|
| 133 | + IRequest::USER_AGENT_CLIENT_IOS, |
|
| 134 | + ])) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // If not logged-in no check is required |
|
| 139 | + if (!$this->userSession->isLoggedIn()) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // POST always requires a check |
|
| 144 | + if ($this->request->getMethod() === 'POST') { |
|
| 145 | + return true; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // If logged-in AND DAV authenticated no check is required |
|
| 149 | + if ($this->userSession->isLoggedIn() |
|
| 150 | + && $this->isDavAuthenticated($this->userSession->getUser()->getUID())) { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return true; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return array{bool, string} |
|
| 159 | + * @throws NotAuthenticated |
|
| 160 | + */ |
|
| 161 | + private function auth(RequestInterface $request, ResponseInterface $response): array { |
|
| 162 | + $forcedLogout = false; |
|
| 163 | + |
|
| 164 | + if (!$this->request->passesCSRFCheck() |
|
| 165 | + && $this->requiresCSRFCheck()) { |
|
| 166 | + // In case of a fail with POST we need to recheck the credentials |
|
| 167 | + if ($this->request->getMethod() === 'POST') { |
|
| 168 | + $forcedLogout = true; |
|
| 169 | + } else { |
|
| 170 | + $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 171 | + throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.'); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($forcedLogout) { |
|
| 176 | + $this->userSession->logout(); |
|
| 177 | + } else { |
|
| 178 | + if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) { |
|
| 179 | + throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.'); |
|
| 180 | + } |
|
| 181 | + if ( |
|
| 182 | + //Fix for broken webdav clients |
|
| 183 | + ($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) |
|
| 184 | + //Well behaved clients that only send the cookie are allowed |
|
| 185 | + || ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization'))) |
|
| 186 | + || \OC_User::handleApacheAuth() |
|
| 187 | + ) { |
|
| 188 | + $user = $this->userSession->getUser(); |
|
| 189 | + $this->setupManager->setupForUser($user); |
|
| 190 | + |
|
| 191 | + $uid = $user->getUID(); |
|
| 192 | + $this->currentUser = $uid; |
|
| 193 | + $this->session->close(); |
|
| 194 | + return [true, $this->principalPrefix . $uid]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $data = parent::check($request, $response); |
|
| 199 | + if ($data[0] === true) { |
|
| 200 | + $startPos = strrpos($data[1], '/') + 1; |
|
| 201 | + $user = $this->userSession->getUser()->getUID(); |
|
| 202 | + $data[1] = substr_replace($data[1], $user, $startPos); |
|
| 203 | + } elseif (in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With') ?? ''))) { |
|
| 204 | + // For ajax requests use dummy auth name to prevent browser popup in case of invalid creditials |
|
| 205 | + $response->addHeader('WWW-Authenticate', 'DummyBasic realm="' . $this->realm . '"'); |
|
| 206 | + $response->setStatus(Http::STATUS_UNAUTHORIZED); |
|
| 207 | + throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $user = $this->userSession->getUser(); |
|
| 211 | + if ($user !== null) { |
|
| 212 | + $this->setupManager->setupForUser($user); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return $data; |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -102,332 +102,332 @@ |
||
| 102 | 102 | use SearchDAV\DAV\SearchPlugin; |
| 103 | 103 | |
| 104 | 104 | class Server { |
| 105 | - public Connector\Sabre\Server $server; |
|
| 106 | - private IProfiler $profiler; |
|
| 107 | - |
|
| 108 | - public function __construct( |
|
| 109 | - private IRequest $request, |
|
| 110 | - private string $baseUri, |
|
| 111 | - ) { |
|
| 112 | - $this->profiler = \OCP\Server::get(IProfiler::class); |
|
| 113 | - if ($this->profiler->isEnabled()) { |
|
| 114 | - /** @var IEventLogger $eventLogger */ |
|
| 115 | - $eventLogger = \OCP\Server::get(IEventLogger::class); |
|
| 116 | - $eventLogger->start('runtime', 'DAV Runtime'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $logger = \OCP\Server::get(LoggerInterface::class); |
|
| 120 | - $eventDispatcher = \OCP\Server::get(IEventDispatcher::class); |
|
| 121 | - |
|
| 122 | - $root = new RootCollection(); |
|
| 123 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 124 | - |
|
| 125 | - // Add maintenance plugin |
|
| 126 | - $this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav'))); |
|
| 127 | - |
|
| 128 | - $this->server->addPlugin(new AppleQuirksPlugin()); |
|
| 129 | - |
|
| 130 | - // Backends |
|
| 131 | - $authBackend = new Auth( |
|
| 132 | - \OCP\Server::get(ISession::class), |
|
| 133 | - \OCP\Server::get(IUserSession::class), |
|
| 134 | - \OCP\Server::get(IRequest::class), |
|
| 135 | - \OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 136 | - \OCP\Server::get(IThrottler::class), |
|
| 137 | - \OCP\Server::get(SetupManager::class), |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - // Set URL explicitly due to reverse-proxy situations |
|
| 141 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 142 | - $this->server->setBaseUri($this->baseUri); |
|
| 143 | - |
|
| 144 | - $this->server->addPlugin(new ProfilerPlugin($this->request)); |
|
| 145 | - $this->server->addPlugin(new BlockLegacyClientPlugin( |
|
| 146 | - \OCP\Server::get(IConfig::class), |
|
| 147 | - \OCP\Server::get(ThemingDefaults::class), |
|
| 148 | - )); |
|
| 149 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 150 | - $authPlugin = new Plugin(); |
|
| 151 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 152 | - $this->server->addPlugin($authPlugin); |
|
| 153 | - |
|
| 154 | - // allow setup of additional auth backends |
|
| 155 | - $event = new SabrePluginEvent($this->server); |
|
| 156 | - $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 157 | - |
|
| 158 | - $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
| 159 | - $eventDispatcher->dispatchTyped($newAuthEvent); |
|
| 160 | - |
|
| 161 | - $bearerAuthBackend = new BearerAuth( |
|
| 162 | - \OCP\Server::get(IUserSession::class), |
|
| 163 | - \OCP\Server::get(ISession::class), |
|
| 164 | - \OCP\Server::get(IRequest::class), |
|
| 165 | - \OCP\Server::get(IConfig::class), |
|
| 166 | - ); |
|
| 167 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 168 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 169 | - $authPlugin->addBackend($authBackend); |
|
| 170 | - |
|
| 171 | - // debugging |
|
| 172 | - if (\OCP\Server::get(IConfig::class)->getSystemValue('debug', false)) { |
|
| 173 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 174 | - } else { |
|
| 175 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger)); |
|
| 179 | - $this->server->addPlugin(new LockPlugin()); |
|
| 180 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 181 | - |
|
| 182 | - // acl |
|
| 183 | - $acl = new DavAclPlugin(); |
|
| 184 | - $acl->principalCollectionSet = [ |
|
| 185 | - 'principals/users', |
|
| 186 | - 'principals/groups', |
|
| 187 | - 'principals/calendar-resources', |
|
| 188 | - 'principals/calendar-rooms', |
|
| 189 | - ]; |
|
| 190 | - $this->server->addPlugin($acl); |
|
| 191 | - |
|
| 192 | - // calendar plugins |
|
| 193 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 194 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); |
|
| 195 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 196 | - $this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger)); |
|
| 197 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class))); |
|
| 198 | - |
|
| 199 | - $this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
| 200 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request)); |
|
| 201 | - if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') { |
|
| 202 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 206 | - $this->server->addPlugin(new PublishPlugin( |
|
| 207 | - \OCP\Server::get(IConfig::class), |
|
| 208 | - \OCP\Server::get(IURLGenerator::class) |
|
| 209 | - )); |
|
| 210 | - |
|
| 211 | - $this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class)); |
|
| 212 | - $this->server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // addressbook plugins |
|
| 216 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 217 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); |
|
| 218 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 219 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 220 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 221 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 222 | - $this->server->addPlugin(new ImageExportPlugin(\OCP\Server::get(PhotoCache::class))); |
|
| 223 | - |
|
| 224 | - $this->server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class)); |
|
| 225 | - $this->server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class)); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // system tags plugins |
|
| 229 | - $this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class)); |
|
| 230 | - |
|
| 231 | - // comments plugin |
|
| 232 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 233 | - \OCP\Server::get(ICommentsManager::class), |
|
| 234 | - \OCP\Server::get(IUserSession::class) |
|
| 235 | - )); |
|
| 236 | - |
|
| 237 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 238 | - $this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class))); |
|
| 239 | - $this->server->addPlugin(new UploadAutoMkcolPlugin()); |
|
| 240 | - $this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class))); |
|
| 241 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
| 242 | - $this->server->addPlugin(new ZipFolderPlugin( |
|
| 243 | - $this->server->tree, |
|
| 244 | - $logger, |
|
| 245 | - $eventDispatcher, |
|
| 246 | - )); |
|
| 247 | - $this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class)); |
|
| 248 | - |
|
| 249 | - // allow setup of additional plugins |
|
| 250 | - $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 251 | - $typedEvent = new SabrePluginAddEvent($this->server); |
|
| 252 | - $eventDispatcher->dispatchTyped($typedEvent); |
|
| 253 | - |
|
| 254 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 255 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 256 | - if ($this->request->isUserAgent([ |
|
| 257 | - '/WebDAVFS/', |
|
| 258 | - '/OneNote/', |
|
| 259 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 260 | - ])) { |
|
| 261 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 265 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $lazySearchBackend = new LazySearchBackend(); |
|
| 269 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 270 | - |
|
| 271 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 272 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void { |
|
| 273 | - // Allow view-only plugin for webdav requests |
|
| 274 | - $this->server->addPlugin(new ViewOnlyPlugin( |
|
| 275 | - \OC::$server->getUserFolder(), |
|
| 276 | - )); |
|
| 277 | - |
|
| 278 | - // custom properties plugin must be the last one |
|
| 279 | - $userSession = \OCP\Server::get(IUserSession::class); |
|
| 280 | - $user = $userSession->getUser(); |
|
| 281 | - if ($user !== null) { |
|
| 282 | - $view = Filesystem::getView(); |
|
| 283 | - $config = \OCP\Server::get(IConfig::class); |
|
| 284 | - $this->server->addPlugin( |
|
| 285 | - new FilesPlugin( |
|
| 286 | - $this->server->tree, |
|
| 287 | - $config, |
|
| 288 | - $this->request, |
|
| 289 | - \OCP\Server::get(IPreview::class), |
|
| 290 | - \OCP\Server::get(IUserSession::class), |
|
| 291 | - \OCP\Server::get(IFilenameValidator::class), |
|
| 292 | - \OCP\Server::get(IAccountManager::class), |
|
| 293 | - false, |
|
| 294 | - $config->getSystemValueBool('debug', false) === false, |
|
| 295 | - ) |
|
| 296 | - ); |
|
| 297 | - $this->server->addPlugin(new ChecksumUpdatePlugin()); |
|
| 298 | - |
|
| 299 | - $this->server->addPlugin( |
|
| 300 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 301 | - new CustomPropertiesBackend( |
|
| 302 | - $this->server, |
|
| 303 | - $this->server->tree, |
|
| 304 | - \OCP\Server::get(IDBConnection::class), |
|
| 305 | - \OCP\Server::get(IUserSession::class)->getUser(), |
|
| 306 | - \OCP\Server::get(DefaultCalendarValidator::class), |
|
| 307 | - ) |
|
| 308 | - ) |
|
| 309 | - ); |
|
| 310 | - if ($view !== null) { |
|
| 311 | - $this->server->addPlugin( |
|
| 312 | - new QuotaPlugin($view)); |
|
| 313 | - } |
|
| 314 | - $this->server->addPlugin( |
|
| 315 | - new TagsPlugin( |
|
| 316 | - $this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class) |
|
| 317 | - ) |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - // TODO: switch to LazyUserFolder |
|
| 321 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 322 | - $shareManager = \OCP\Server::get(\OCP\Share\IManager::class); |
|
| 323 | - $this->server->addPlugin(new SharesPlugin( |
|
| 324 | - $this->server->tree, |
|
| 325 | - $userSession, |
|
| 326 | - $userFolder, |
|
| 327 | - $shareManager, |
|
| 328 | - )); |
|
| 329 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 330 | - \OCP\Server::get(ICommentsManager::class), |
|
| 331 | - $userSession |
|
| 332 | - )); |
|
| 333 | - if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 334 | - $this->server->addPlugin(new IMipPlugin( |
|
| 335 | - \OCP\Server::get(IAppConfig::class), |
|
| 336 | - \OCP\Server::get(IMailer::class), |
|
| 337 | - \OCP\Server::get(LoggerInterface::class), |
|
| 338 | - \OCP\Server::get(ITimeFactory::class), |
|
| 339 | - \OCP\Server::get(Defaults::class), |
|
| 340 | - $userSession, |
|
| 341 | - \OCP\Server::get(IMipService::class), |
|
| 342 | - \OCP\Server::get(EventComparisonService::class), |
|
| 343 | - \OCP\Server::get(\OCP\Mail\Provider\IManager::class) |
|
| 344 | - )); |
|
| 345 | - } |
|
| 346 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 347 | - if ($view !== null) { |
|
| 348 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 349 | - $this->server->tree, |
|
| 350 | - $view, |
|
| 351 | - \OCP\Server::get(ISystemTagManager::class), |
|
| 352 | - \OCP\Server::get(ISystemTagObjectMapper::class), |
|
| 353 | - \OCP\Server::get(ITagManager::class), |
|
| 354 | - $userSession, |
|
| 355 | - \OCP\Server::get(IGroupManager::class), |
|
| 356 | - $userFolder, |
|
| 357 | - \OCP\Server::get(IAppManager::class) |
|
| 358 | - )); |
|
| 359 | - $lazySearchBackend->setBackend(new FileSearchBackend( |
|
| 360 | - $this->server, |
|
| 361 | - $this->server->tree, |
|
| 362 | - $user, |
|
| 363 | - \OCP\Server::get(IRootFolder::class), |
|
| 364 | - $shareManager, |
|
| 365 | - $view, |
|
| 366 | - \OCP\Server::get(IFilesMetadataManager::class) |
|
| 367 | - )); |
|
| 368 | - $this->server->addPlugin( |
|
| 369 | - new BulkUploadPlugin( |
|
| 370 | - $userFolder, |
|
| 371 | - $logger |
|
| 372 | - ) |
|
| 373 | - ); |
|
| 374 | - } |
|
| 375 | - $this->server->addPlugin(new EnablePlugin( |
|
| 376 | - \OCP\Server::get(IConfig::class), |
|
| 377 | - \OCP\Server::get(BirthdayService::class), |
|
| 378 | - $user |
|
| 379 | - )); |
|
| 380 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 381 | - \OCP\Server::get(IUserSession::class), |
|
| 382 | - \OCP\Server::get(IURLGenerator::class), |
|
| 383 | - \OCP\Server::get(ThemingDefaults::class), |
|
| 384 | - \OCP\Server::get(IRequest::class), |
|
| 385 | - \OC::$server->getL10N('dav'), |
|
| 386 | - function () { |
|
| 387 | - return UUIDUtil::getUUID(); |
|
| 388 | - } |
|
| 389 | - )); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // register plugins from apps |
|
| 393 | - $pluginManager = new PluginManager( |
|
| 394 | - \OC::$server, |
|
| 395 | - \OCP\Server::get(IAppManager::class) |
|
| 396 | - ); |
|
| 397 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 398 | - $this->server->addPlugin($appPlugin); |
|
| 399 | - } |
|
| 400 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 401 | - $root->addChild($appCollection); |
|
| 402 | - } |
|
| 403 | - }); |
|
| 404 | - |
|
| 405 | - $this->server->addPlugin( |
|
| 406 | - new PropfindCompressionPlugin() |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - public function exec() { |
|
| 411 | - /** @var IEventLogger $eventLogger */ |
|
| 412 | - $eventLogger = \OCP\Server::get(IEventLogger::class); |
|
| 413 | - $eventLogger->start('dav_server_exec', ''); |
|
| 414 | - $this->server->start(); |
|
| 415 | - $eventLogger->end('dav_server_exec'); |
|
| 416 | - if ($this->profiler->isEnabled()) { |
|
| 417 | - $eventLogger->end('runtime'); |
|
| 418 | - $profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response()); |
|
| 419 | - $this->profiler->saveProfile($profile); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - private function requestIsForSubtree(array $subTrees): bool { |
|
| 424 | - foreach ($subTrees as $subTree) { |
|
| 425 | - $subTree = trim($subTree, ' /'); |
|
| 426 | - if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) { |
|
| 427 | - return true; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - return false; |
|
| 431 | - } |
|
| 105 | + public Connector\Sabre\Server $server; |
|
| 106 | + private IProfiler $profiler; |
|
| 107 | + |
|
| 108 | + public function __construct( |
|
| 109 | + private IRequest $request, |
|
| 110 | + private string $baseUri, |
|
| 111 | + ) { |
|
| 112 | + $this->profiler = \OCP\Server::get(IProfiler::class); |
|
| 113 | + if ($this->profiler->isEnabled()) { |
|
| 114 | + /** @var IEventLogger $eventLogger */ |
|
| 115 | + $eventLogger = \OCP\Server::get(IEventLogger::class); |
|
| 116 | + $eventLogger->start('runtime', 'DAV Runtime'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $logger = \OCP\Server::get(LoggerInterface::class); |
|
| 120 | + $eventDispatcher = \OCP\Server::get(IEventDispatcher::class); |
|
| 121 | + |
|
| 122 | + $root = new RootCollection(); |
|
| 123 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 124 | + |
|
| 125 | + // Add maintenance plugin |
|
| 126 | + $this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav'))); |
|
| 127 | + |
|
| 128 | + $this->server->addPlugin(new AppleQuirksPlugin()); |
|
| 129 | + |
|
| 130 | + // Backends |
|
| 131 | + $authBackend = new Auth( |
|
| 132 | + \OCP\Server::get(ISession::class), |
|
| 133 | + \OCP\Server::get(IUserSession::class), |
|
| 134 | + \OCP\Server::get(IRequest::class), |
|
| 135 | + \OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 136 | + \OCP\Server::get(IThrottler::class), |
|
| 137 | + \OCP\Server::get(SetupManager::class), |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + // Set URL explicitly due to reverse-proxy situations |
|
| 141 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 142 | + $this->server->setBaseUri($this->baseUri); |
|
| 143 | + |
|
| 144 | + $this->server->addPlugin(new ProfilerPlugin($this->request)); |
|
| 145 | + $this->server->addPlugin(new BlockLegacyClientPlugin( |
|
| 146 | + \OCP\Server::get(IConfig::class), |
|
| 147 | + \OCP\Server::get(ThemingDefaults::class), |
|
| 148 | + )); |
|
| 149 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
| 150 | + $authPlugin = new Plugin(); |
|
| 151 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 152 | + $this->server->addPlugin($authPlugin); |
|
| 153 | + |
|
| 154 | + // allow setup of additional auth backends |
|
| 155 | + $event = new SabrePluginEvent($this->server); |
|
| 156 | + $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 157 | + |
|
| 158 | + $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
| 159 | + $eventDispatcher->dispatchTyped($newAuthEvent); |
|
| 160 | + |
|
| 161 | + $bearerAuthBackend = new BearerAuth( |
|
| 162 | + \OCP\Server::get(IUserSession::class), |
|
| 163 | + \OCP\Server::get(ISession::class), |
|
| 164 | + \OCP\Server::get(IRequest::class), |
|
| 165 | + \OCP\Server::get(IConfig::class), |
|
| 166 | + ); |
|
| 167 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 168 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 169 | + $authPlugin->addBackend($authBackend); |
|
| 170 | + |
|
| 171 | + // debugging |
|
| 172 | + if (\OCP\Server::get(IConfig::class)->getSystemValue('debug', false)) { |
|
| 173 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 174 | + } else { |
|
| 175 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger)); |
|
| 179 | + $this->server->addPlugin(new LockPlugin()); |
|
| 180 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 181 | + |
|
| 182 | + // acl |
|
| 183 | + $acl = new DavAclPlugin(); |
|
| 184 | + $acl->principalCollectionSet = [ |
|
| 185 | + 'principals/users', |
|
| 186 | + 'principals/groups', |
|
| 187 | + 'principals/calendar-resources', |
|
| 188 | + 'principals/calendar-rooms', |
|
| 189 | + ]; |
|
| 190 | + $this->server->addPlugin($acl); |
|
| 191 | + |
|
| 192 | + // calendar plugins |
|
| 193 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
| 194 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); |
|
| 195 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 196 | + $this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger)); |
|
| 197 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class))); |
|
| 198 | + |
|
| 199 | + $this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
| 200 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request)); |
|
| 201 | + if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') { |
|
| 202 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 206 | + $this->server->addPlugin(new PublishPlugin( |
|
| 207 | + \OCP\Server::get(IConfig::class), |
|
| 208 | + \OCP\Server::get(IURLGenerator::class) |
|
| 209 | + )); |
|
| 210 | + |
|
| 211 | + $this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class)); |
|
| 212 | + $this->server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // addressbook plugins |
|
| 216 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
| 217 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class))); |
|
| 218 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 219 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 220 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
| 221 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
| 222 | + $this->server->addPlugin(new ImageExportPlugin(\OCP\Server::get(PhotoCache::class))); |
|
| 223 | + |
|
| 224 | + $this->server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class)); |
|
| 225 | + $this->server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class)); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // system tags plugins |
|
| 229 | + $this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class)); |
|
| 230 | + |
|
| 231 | + // comments plugin |
|
| 232 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 233 | + \OCP\Server::get(ICommentsManager::class), |
|
| 234 | + \OCP\Server::get(IUserSession::class) |
|
| 235 | + )); |
|
| 236 | + |
|
| 237 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 238 | + $this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class))); |
|
| 239 | + $this->server->addPlugin(new UploadAutoMkcolPlugin()); |
|
| 240 | + $this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class))); |
|
| 241 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
| 242 | + $this->server->addPlugin(new ZipFolderPlugin( |
|
| 243 | + $this->server->tree, |
|
| 244 | + $logger, |
|
| 245 | + $eventDispatcher, |
|
| 246 | + )); |
|
| 247 | + $this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class)); |
|
| 248 | + |
|
| 249 | + // allow setup of additional plugins |
|
| 250 | + $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 251 | + $typedEvent = new SabrePluginAddEvent($this->server); |
|
| 252 | + $eventDispatcher->dispatchTyped($typedEvent); |
|
| 253 | + |
|
| 254 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 255 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 256 | + if ($this->request->isUserAgent([ |
|
| 257 | + '/WebDAVFS/', |
|
| 258 | + '/OneNote/', |
|
| 259 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 260 | + ])) { |
|
| 261 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 265 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $lazySearchBackend = new LazySearchBackend(); |
|
| 269 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
| 270 | + |
|
| 271 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 272 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void { |
|
| 273 | + // Allow view-only plugin for webdav requests |
|
| 274 | + $this->server->addPlugin(new ViewOnlyPlugin( |
|
| 275 | + \OC::$server->getUserFolder(), |
|
| 276 | + )); |
|
| 277 | + |
|
| 278 | + // custom properties plugin must be the last one |
|
| 279 | + $userSession = \OCP\Server::get(IUserSession::class); |
|
| 280 | + $user = $userSession->getUser(); |
|
| 281 | + if ($user !== null) { |
|
| 282 | + $view = Filesystem::getView(); |
|
| 283 | + $config = \OCP\Server::get(IConfig::class); |
|
| 284 | + $this->server->addPlugin( |
|
| 285 | + new FilesPlugin( |
|
| 286 | + $this->server->tree, |
|
| 287 | + $config, |
|
| 288 | + $this->request, |
|
| 289 | + \OCP\Server::get(IPreview::class), |
|
| 290 | + \OCP\Server::get(IUserSession::class), |
|
| 291 | + \OCP\Server::get(IFilenameValidator::class), |
|
| 292 | + \OCP\Server::get(IAccountManager::class), |
|
| 293 | + false, |
|
| 294 | + $config->getSystemValueBool('debug', false) === false, |
|
| 295 | + ) |
|
| 296 | + ); |
|
| 297 | + $this->server->addPlugin(new ChecksumUpdatePlugin()); |
|
| 298 | + |
|
| 299 | + $this->server->addPlugin( |
|
| 300 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 301 | + new CustomPropertiesBackend( |
|
| 302 | + $this->server, |
|
| 303 | + $this->server->tree, |
|
| 304 | + \OCP\Server::get(IDBConnection::class), |
|
| 305 | + \OCP\Server::get(IUserSession::class)->getUser(), |
|
| 306 | + \OCP\Server::get(DefaultCalendarValidator::class), |
|
| 307 | + ) |
|
| 308 | + ) |
|
| 309 | + ); |
|
| 310 | + if ($view !== null) { |
|
| 311 | + $this->server->addPlugin( |
|
| 312 | + new QuotaPlugin($view)); |
|
| 313 | + } |
|
| 314 | + $this->server->addPlugin( |
|
| 315 | + new TagsPlugin( |
|
| 316 | + $this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class) |
|
| 317 | + ) |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + // TODO: switch to LazyUserFolder |
|
| 321 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 322 | + $shareManager = \OCP\Server::get(\OCP\Share\IManager::class); |
|
| 323 | + $this->server->addPlugin(new SharesPlugin( |
|
| 324 | + $this->server->tree, |
|
| 325 | + $userSession, |
|
| 326 | + $userFolder, |
|
| 327 | + $shareManager, |
|
| 328 | + )); |
|
| 329 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 330 | + \OCP\Server::get(ICommentsManager::class), |
|
| 331 | + $userSession |
|
| 332 | + )); |
|
| 333 | + if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
| 334 | + $this->server->addPlugin(new IMipPlugin( |
|
| 335 | + \OCP\Server::get(IAppConfig::class), |
|
| 336 | + \OCP\Server::get(IMailer::class), |
|
| 337 | + \OCP\Server::get(LoggerInterface::class), |
|
| 338 | + \OCP\Server::get(ITimeFactory::class), |
|
| 339 | + \OCP\Server::get(Defaults::class), |
|
| 340 | + $userSession, |
|
| 341 | + \OCP\Server::get(IMipService::class), |
|
| 342 | + \OCP\Server::get(EventComparisonService::class), |
|
| 343 | + \OCP\Server::get(\OCP\Mail\Provider\IManager::class) |
|
| 344 | + )); |
|
| 345 | + } |
|
| 346 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 347 | + if ($view !== null) { |
|
| 348 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 349 | + $this->server->tree, |
|
| 350 | + $view, |
|
| 351 | + \OCP\Server::get(ISystemTagManager::class), |
|
| 352 | + \OCP\Server::get(ISystemTagObjectMapper::class), |
|
| 353 | + \OCP\Server::get(ITagManager::class), |
|
| 354 | + $userSession, |
|
| 355 | + \OCP\Server::get(IGroupManager::class), |
|
| 356 | + $userFolder, |
|
| 357 | + \OCP\Server::get(IAppManager::class) |
|
| 358 | + )); |
|
| 359 | + $lazySearchBackend->setBackend(new FileSearchBackend( |
|
| 360 | + $this->server, |
|
| 361 | + $this->server->tree, |
|
| 362 | + $user, |
|
| 363 | + \OCP\Server::get(IRootFolder::class), |
|
| 364 | + $shareManager, |
|
| 365 | + $view, |
|
| 366 | + \OCP\Server::get(IFilesMetadataManager::class) |
|
| 367 | + )); |
|
| 368 | + $this->server->addPlugin( |
|
| 369 | + new BulkUploadPlugin( |
|
| 370 | + $userFolder, |
|
| 371 | + $logger |
|
| 372 | + ) |
|
| 373 | + ); |
|
| 374 | + } |
|
| 375 | + $this->server->addPlugin(new EnablePlugin( |
|
| 376 | + \OCP\Server::get(IConfig::class), |
|
| 377 | + \OCP\Server::get(BirthdayService::class), |
|
| 378 | + $user |
|
| 379 | + )); |
|
| 380 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
| 381 | + \OCP\Server::get(IUserSession::class), |
|
| 382 | + \OCP\Server::get(IURLGenerator::class), |
|
| 383 | + \OCP\Server::get(ThemingDefaults::class), |
|
| 384 | + \OCP\Server::get(IRequest::class), |
|
| 385 | + \OC::$server->getL10N('dav'), |
|
| 386 | + function () { |
|
| 387 | + return UUIDUtil::getUUID(); |
|
| 388 | + } |
|
| 389 | + )); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // register plugins from apps |
|
| 393 | + $pluginManager = new PluginManager( |
|
| 394 | + \OC::$server, |
|
| 395 | + \OCP\Server::get(IAppManager::class) |
|
| 396 | + ); |
|
| 397 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 398 | + $this->server->addPlugin($appPlugin); |
|
| 399 | + } |
|
| 400 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 401 | + $root->addChild($appCollection); |
|
| 402 | + } |
|
| 403 | + }); |
|
| 404 | + |
|
| 405 | + $this->server->addPlugin( |
|
| 406 | + new PropfindCompressionPlugin() |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + public function exec() { |
|
| 411 | + /** @var IEventLogger $eventLogger */ |
|
| 412 | + $eventLogger = \OCP\Server::get(IEventLogger::class); |
|
| 413 | + $eventLogger->start('dav_server_exec', ''); |
|
| 414 | + $this->server->start(); |
|
| 415 | + $eventLogger->end('dav_server_exec'); |
|
| 416 | + if ($this->profiler->isEnabled()) { |
|
| 417 | + $eventLogger->end('runtime'); |
|
| 418 | + $profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response()); |
|
| 419 | + $this->profiler->saveProfile($profile); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + private function requestIsForSubtree(array $subTrees): bool { |
|
| 424 | + foreach ($subTrees as $subTree) { |
|
| 425 | + $subTree = trim($subTree, ' /'); |
|
| 426 | + if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) { |
|
| 427 | + return true; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + return false; |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | 433 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // no php execution timeout for webdav |
| 29 | 29 | if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) { |
| 30 | - @set_time_limit(0); |
|
| 30 | + @set_time_limit(0); |
|
| 31 | 31 | } |
| 32 | 32 | ignore_user_abort(true); |
| 33 | 33 | |
@@ -37,42 +37,42 @@ discard block |
||
| 37 | 37 | $dispatcher = Server::get(IEventDispatcher::class); |
| 38 | 38 | |
| 39 | 39 | $serverFactory = new ServerFactory( |
| 40 | - Server::get(IConfig::class), |
|
| 41 | - Server::get(LoggerInterface::class), |
|
| 42 | - Server::get(IDBConnection::class), |
|
| 43 | - Server::get(IUserSession::class), |
|
| 44 | - Server::get(IMountManager::class), |
|
| 45 | - Server::get(ITagManager::class), |
|
| 46 | - Server::get(IRequest::class), |
|
| 47 | - Server::get(IPreview::class), |
|
| 48 | - $dispatcher, |
|
| 49 | - \OC::$server->getL10N('dav') |
|
| 40 | + Server::get(IConfig::class), |
|
| 41 | + Server::get(LoggerInterface::class), |
|
| 42 | + Server::get(IDBConnection::class), |
|
| 43 | + Server::get(IUserSession::class), |
|
| 44 | + Server::get(IMountManager::class), |
|
| 45 | + Server::get(ITagManager::class), |
|
| 46 | + Server::get(IRequest::class), |
|
| 47 | + Server::get(IPreview::class), |
|
| 48 | + $dispatcher, |
|
| 49 | + \OC::$server->getL10N('dav') |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | // Backends |
| 53 | 53 | $authBackend = new Auth( |
| 54 | - Server::get(ISession::class), |
|
| 55 | - Server::get(IUserSession::class), |
|
| 56 | - Server::get(IRequest::class), |
|
| 57 | - Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 58 | - Server::get(IThrottler::class), |
|
| 59 | - Server::get(SetupManager::class), |
|
| 60 | - 'principals/' |
|
| 54 | + Server::get(ISession::class), |
|
| 55 | + Server::get(IUserSession::class), |
|
| 56 | + Server::get(IRequest::class), |
|
| 57 | + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 58 | + Server::get(IThrottler::class), |
|
| 59 | + Server::get(SetupManager::class), |
|
| 60 | + 'principals/' |
|
| 61 | 61 | ); |
| 62 | 62 | $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); |
| 63 | 63 | $bearerAuthPlugin = new BearerAuth( |
| 64 | - Server::get(IUserSession::class), |
|
| 65 | - Server::get(ISession::class), |
|
| 66 | - Server::get(IRequest::class), |
|
| 67 | - Server::get(IConfig::class), |
|
| 64 | + Server::get(IUserSession::class), |
|
| 65 | + Server::get(ISession::class), |
|
| 66 | + Server::get(IRequest::class), |
|
| 67 | + Server::get(IConfig::class), |
|
| 68 | 68 | ); |
| 69 | 69 | $authPlugin->addBackend($bearerAuthPlugin); |
| 70 | 70 | |
| 71 | 71 | $requestUri = Server::get(IRequest::class)->getRequestUri(); |
| 72 | 72 | |
| 73 | 73 | $server = $serverFactory->createServer(false, $baseuri, $requestUri, $authPlugin, function () { |
| 74 | - // use the view for the logged in user |
|
| 75 | - return Filesystem::getView(); |
|
| 74 | + // use the view for the logged in user |
|
| 75 | + return Filesystem::getView(); |
|
| 76 | 76 | }); |
| 77 | 77 | |
| 78 | 78 | // allow setup of additional plugins |
@@ -37,34 +37,34 @@ discard block |
||
| 37 | 37 | use Sabre\CardDAV\Plugin; |
| 38 | 38 | |
| 39 | 39 | $authBackend = new Auth( |
| 40 | - Server::get(ISession::class), |
|
| 41 | - Server::get(IUserSession::class), |
|
| 42 | - Server::get(IRequest::class), |
|
| 43 | - Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 44 | - Server::get(IThrottler::class), |
|
| 45 | - Server::get(SetupManager::class), |
|
| 46 | - 'principals/' |
|
| 40 | + Server::get(ISession::class), |
|
| 41 | + Server::get(IUserSession::class), |
|
| 42 | + Server::get(IRequest::class), |
|
| 43 | + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 44 | + Server::get(IThrottler::class), |
|
| 45 | + Server::get(SetupManager::class), |
|
| 46 | + 'principals/' |
|
| 47 | 47 | ); |
| 48 | 48 | $principalBackend = new Principal( |
| 49 | - Server::get(IUserManager::class), |
|
| 50 | - Server::get(IGroupManager::class), |
|
| 51 | - Server::get(IAccountManager::class), |
|
| 52 | - Server::get(\OCP\Share\IManager::class), |
|
| 53 | - Server::get(IUserSession::class), |
|
| 54 | - Server::get(IAppManager::class), |
|
| 55 | - Server::get(ProxyMapper::class), |
|
| 56 | - Server::get(KnownUserService::class), |
|
| 57 | - Server::get(IConfig::class), |
|
| 58 | - \OC::$server->getL10NFactory(), |
|
| 59 | - 'principals/' |
|
| 49 | + Server::get(IUserManager::class), |
|
| 50 | + Server::get(IGroupManager::class), |
|
| 51 | + Server::get(IAccountManager::class), |
|
| 52 | + Server::get(\OCP\Share\IManager::class), |
|
| 53 | + Server::get(IUserSession::class), |
|
| 54 | + Server::get(IAppManager::class), |
|
| 55 | + Server::get(ProxyMapper::class), |
|
| 56 | + Server::get(KnownUserService::class), |
|
| 57 | + Server::get(IConfig::class), |
|
| 58 | + \OC::$server->getL10NFactory(), |
|
| 59 | + 'principals/' |
|
| 60 | 60 | ); |
| 61 | 61 | $db = Server::get(IDBConnection::class); |
| 62 | 62 | $cardDavBackend = new CardDavBackend( |
| 63 | - $db, |
|
| 64 | - $principalBackend, |
|
| 65 | - Server::get(IUserManager::class), |
|
| 66 | - Server::get(IEventDispatcher::class), |
|
| 67 | - Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class), |
|
| 63 | + $db, |
|
| 64 | + $principalBackend, |
|
| 65 | + Server::get(IUserManager::class), |
|
| 66 | + Server::get(IEventDispatcher::class), |
|
| 67 | + Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class), |
|
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | 70 | $debugging = Server::get(IConfig::class)->getSystemValue('debug', false); |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
| 79 | 79 | |
| 80 | 80 | $nodes = [ |
| 81 | - $principalCollection, |
|
| 82 | - $addressBookRoot, |
|
| 81 | + $principalCollection, |
|
| 82 | + $addressBookRoot, |
|
| 83 | 83 | ]; |
| 84 | 84 | |
| 85 | 85 | // Fire up server |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $server->addPlugin(new LegacyDAVACL()); |
| 96 | 96 | if ($debugging) { |
| 97 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 97 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -36,26 +36,26 @@ discard block |
||
| 36 | 36 | use Psr\Log\LoggerInterface; |
| 37 | 37 | |
| 38 | 38 | $authBackend = new Auth( |
| 39 | - Server::get(ISession::class), |
|
| 40 | - Server::get(IUserSession::class), |
|
| 41 | - Server::get(IRequest::class), |
|
| 42 | - Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 43 | - Server::get(IThrottler::class), |
|
| 44 | - Server::get(SetupManager::class), |
|
| 45 | - 'principals/' |
|
| 39 | + Server::get(ISession::class), |
|
| 40 | + Server::get(IUserSession::class), |
|
| 41 | + Server::get(IRequest::class), |
|
| 42 | + Server::get(\OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 43 | + Server::get(IThrottler::class), |
|
| 44 | + Server::get(SetupManager::class), |
|
| 45 | + 'principals/' |
|
| 46 | 46 | ); |
| 47 | 47 | $principalBackend = new Principal( |
| 48 | - Server::get(IUserManager::class), |
|
| 49 | - Server::get(IGroupManager::class), |
|
| 50 | - Server::get(IAccountManager::class), |
|
| 51 | - Server::get(\OCP\Share\IManager::class), |
|
| 52 | - Server::get(IUserSession::class), |
|
| 53 | - Server::get(IAppManager::class), |
|
| 54 | - Server::get(ProxyMapper::class), |
|
| 55 | - Server::get(KnownUserService::class), |
|
| 56 | - Server::get(IConfig::class), |
|
| 57 | - \OC::$server->getL10NFactory(), |
|
| 58 | - 'principals/' |
|
| 48 | + Server::get(IUserManager::class), |
|
| 49 | + Server::get(IGroupManager::class), |
|
| 50 | + Server::get(IAccountManager::class), |
|
| 51 | + Server::get(\OCP\Share\IManager::class), |
|
| 52 | + Server::get(IUserSession::class), |
|
| 53 | + Server::get(IAppManager::class), |
|
| 54 | + Server::get(ProxyMapper::class), |
|
| 55 | + Server::get(KnownUserService::class), |
|
| 56 | + Server::get(IConfig::class), |
|
| 57 | + \OC::$server->getL10NFactory(), |
|
| 58 | + 'principals/' |
|
| 59 | 59 | ); |
| 60 | 60 | $db = Server::get(IDBConnection::class); |
| 61 | 61 | $userManager = Server::get(IUserManager::class); |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | $config = Server::get(IConfig::class); |
| 66 | 66 | |
| 67 | 67 | $calDavBackend = new CalDavBackend( |
| 68 | - $db, |
|
| 69 | - $principalBackend, |
|
| 70 | - $userManager, |
|
| 71 | - $random, |
|
| 72 | - $logger, |
|
| 73 | - $dispatcher, |
|
| 74 | - $config, |
|
| 75 | - Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class), |
|
| 76 | - true |
|
| 68 | + $db, |
|
| 69 | + $principalBackend, |
|
| 70 | + $userManager, |
|
| 71 | + $random, |
|
| 72 | + $logger, |
|
| 73 | + $dispatcher, |
|
| 74 | + $config, |
|
| 75 | + Server::get(\OCA\DAV\CalDAV\Sharing\Backend::class), |
|
| 76 | + true |
|
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | $debugging = Server::get(IConfig::class)->getSystemValue('debug', false); |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
| 88 | 88 | |
| 89 | 89 | $nodes = [ |
| 90 | - $principalCollection, |
|
| 91 | - $addressBookRoot, |
|
| 90 | + $principalCollection, |
|
| 91 | + $addressBookRoot, |
|
| 92 | 92 | ]; |
| 93 | 93 | |
| 94 | 94 | // Fire up server |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $server->addPlugin(new LegacyDAVACL()); |
| 106 | 106 | if ($debugging) { |
| 107 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 107 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(Server::get(IConfig::class), Server::get(LoggerInterface::class), Server::get(DefaultCalendarValidator::class))); |
| 113 | 113 | |
| 114 | 114 | if ($sendInvitations) { |
| 115 | - $server->addPlugin(Server::get(IMipPlugin::class)); |
|
| 115 | + $server->addPlugin(Server::get(IMipPlugin::class)); |
|
| 116 | 116 | } |
| 117 | 117 | $server->addPlugin(new ExceptionLoggerPlugin('caldav', $logger)); |
| 118 | 118 | $server->addPlugin(Server::get(RateLimitingPlugin::class)); |