1
0

WebdavEndpoint.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\SetupChecks;
  8. use OCA\Settings\SetupChecks\CheckServerResponseTrait;
  9. use OCP\Http\Client\IClientService;
  10. use OCP\IConfig;
  11. use OCP\IL10N;
  12. use OCP\IURLGenerator;
  13. use OCP\SetupCheck\ISetupCheck;
  14. use OCP\SetupCheck\SetupResult;
  15. use Psr\Log\LoggerInterface;
  16. class WebdavEndpoint implements ISetupCheck {
  17. use CheckServerResponseTrait;
  18. public function __construct(
  19. protected IL10N $l10n,
  20. protected IConfig $config,
  21. protected IURLGenerator $urlGenerator,
  22. protected IClientService $clientService,
  23. protected LoggerInterface $logger,
  24. ) {
  25. }
  26. public function getCategory(): string {
  27. return 'network';
  28. }
  29. public function getName(): string {
  30. return $this->l10n->t('WebDAV endpoint');
  31. }
  32. public function run(): SetupResult {
  33. $urls = [
  34. ['propfind', '/remote.php/webdav', [207, 401]],
  35. ];
  36. foreach ($urls as [$verb,$url,$validStatuses]) {
  37. $works = null;
  38. foreach ($this->runRequest($verb, $url, ['httpErrors' => false]) as $response) {
  39. // Check that the response status matches
  40. $works = in_array($response->getStatusCode(), $validStatuses);
  41. // Skip the other requests if one works
  42. if ($works === true) {
  43. break;
  44. }
  45. }
  46. // If 'works' is null then we could not connect to the server
  47. if ($works === null) {
  48. return SetupResult::info(
  49. $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(),
  50. $this->urlGenerator->linkToDocs('admin-setup-well-known-URL'),
  51. );
  52. }
  53. // Otherwise if we fail we can abort here
  54. if ($works === false) {
  55. return SetupResult::error(
  56. $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(),
  57. );
  58. }
  59. }
  60. return SetupResult::success(
  61. $this->l10n->t('Your web server is properly set up to allow file synchronization over WebDAV.')
  62. );
  63. }
  64. }