|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright Copyright (c) 2024 Côme Chilliet <[email protected]> |
| 7 | + * |
| 8 | + * @author Côme Chilliet <[email protected]> |
| 9 | + * @author Ferdinand Thiessen <[email protected]> |
| 10 | + * |
| 11 | + * @license AGPL-3.0-or-later |
| 12 | + * |
| 13 | + * This program is free software: you can redistribute it and/or modify |
| 14 | + * it under the terms of the GNU Affero General Public License as |
| 15 | + * published by the Free Software Foundation, either version 3 of the |
| 16 | + * License, or (at your option) any later version. |
| 17 | + * |
| 18 | + * This program is distributed in the hope that it will be useful, |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | + * GNU Affero General Public License for more details. |
| 22 | + * |
| 23 | + * You should have received a copy of the GNU Affero General Public License |
| 24 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | + * |
| 26 | + */ |
| 27 | + |
| 28 | +namespace OCA\DAV\SetupChecks; |
| 29 | + |
| 30 | +use OCA\Settings\SetupChecks\CheckServerResponseTrait; |
| 31 | +use OCP\Http\Client\IClientService; |
| 32 | +use OCP\IConfig; |
| 33 | +use OCP\IL10N; |
| 34 | +use OCP\IURLGenerator; |
| 35 | +use OCP\SetupCheck\ISetupCheck; |
| 36 | +use OCP\SetupCheck\SetupResult; |
| 37 | +use Psr\Log\LoggerInterface; |
| 38 | + |
| 39 | +class WebdavEndpoint implements ISetupCheck { |
| 40 | + |
| 41 | + use CheckServerResponseTrait; |
| 42 | + |
| 43 | + public function __construct( |
| 44 | + protected IL10N $l10n, |
| 45 | + protected IConfig $config, |
| 46 | + protected IURLGenerator $urlGenerator, |
| 47 | + protected IClientService $clientService, |
| 48 | + protected LoggerInterface $logger, |
| 49 | + ) { |
| 50 | + } |
| 51 | + |
| 52 | + public function getCategory(): string { |
| 53 | + return 'network'; |
| 54 | + } |
| 55 | + |
| 56 | + public function getName(): string { |
| 57 | + return $this->l10n->t('WebDAV endpoint'); |
| 58 | + } |
| 59 | + |
| 60 | + public function run(): SetupResult { |
| 61 | + $urls = [ |
| 62 | + ['propfind', '/remote.php/webdav', [207, 401]], |
| 63 | + ]; |
| 64 | + |
| 65 | + foreach ($urls as [$verb,$url,$validStatuses]) { |
| 66 | + $works = null; |
| 67 | + foreach ($this->runRequest($verb, $url, ['httpErrors' => false]) as $response) { |
| 68 | + // Check that the response status matches |
| 69 | + $works = in_array($response->getStatusCode(), $validStatuses); |
| 70 | + // Skip the other requests if one works |
| 71 | + if ($works === true) { |
| 72 | + break; |
| 73 | + } |
| 74 | + } |
| 75 | + // If 'works' is null then we could not connect to the server |
| 76 | + if ($works === null) { |
| 77 | + return SetupResult::info( |
| 78 | + $this->l10n->t('Could not check that your web server is properly set up to allow file synchronization over WebDAV. Please check manually.') . "\n" . $this->serverConfigHelp(), |
| 79 | + $this->urlGenerator->linkToDocs('admin-setup-well-known-URL'), |
| 80 | + ); |
| 81 | + } |
| 82 | + // Otherwise if we fail we can abort here |
| 83 | + if ($works === false) { |
| 84 | + return SetupResult::error( |
| 85 | + $this->l10n->t('Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.') . "\n" . $this->serverConfigHelp(), |
| 86 | + ); |
| 87 | + } |
| 88 | + } |
| 89 | + return SetupResult::success( |
| 90 | + $this->l10n->t('Your web server is properly set up to allow file synchronization over WebDAV.') |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments