OcxProviders.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\Settings\SetupChecks;
  8. use OCP\Http\Client\IClientService;
  9. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use OCP\IURLGenerator;
  12. use OCP\SetupCheck\ISetupCheck;
  13. use OCP\SetupCheck\SetupResult;
  14. use Psr\Log\LoggerInterface;
  15. /**
  16. * Checks if the webserver serves the OCM and OCS providers
  17. */
  18. class OcxProviders implements ISetupCheck {
  19. use CheckServerResponseTrait;
  20. public function __construct(
  21. protected IL10N $l10n,
  22. protected IConfig $config,
  23. protected IURLGenerator $urlGenerator,
  24. protected IClientService $clientService,
  25. protected LoggerInterface $logger,
  26. ) {
  27. }
  28. public function getCategory(): string {
  29. return 'network';
  30. }
  31. public function getName(): string {
  32. return $this->l10n->t('OCS provider resolving');
  33. }
  34. public function run(): SetupResult {
  35. // List of providers that work
  36. $workingProviders = [];
  37. // List of providers we tested (in case one or multiple do not yield any response)
  38. $testedProviders = [];
  39. // All providers that we need to test
  40. $providers = [
  41. '/ocm-provider/',
  42. '/ocs-provider/',
  43. ];
  44. foreach ($providers as $provider) {
  45. foreach ($this->runRequest('HEAD', $this->urlGenerator->getWebroot() . $provider, ['httpErrors' => false]) as $response) {
  46. $testedProviders[$provider] = true;
  47. if ($response->getStatusCode() === 200) {
  48. $workingProviders[] = $provider;
  49. break;
  50. }
  51. }
  52. }
  53. if (count($testedProviders) < count($providers)) {
  54. return SetupResult::warning(
  55. $this->l10n->t('Could not check if your web server properly resolves the OCM and OCS provider URLs.', ) . "\n" . $this->serverConfigHelp(),
  56. );
  57. }
  58. $missingProviders = array_diff($providers, $workingProviders);
  59. if (empty($missingProviders)) {
  60. return SetupResult::success();
  61. }
  62. return SetupResult::warning(
  63. $this->l10n->t('Your web server is not properly set up to resolve %1$s.
  64. This is most likely related to a web server configuration that was not updated to deliver this folder directly.
  65. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx.
  66. On Nginx those are typically the lines starting with "location ~" that need an update.', [join(', ', array_map(fn ($s) => '"'.$s.'"', $missingProviders))]),
  67. $this->urlGenerator->linkToDocs('admin-nginx'),
  68. );
  69. }
  70. }