1
0

OcxProviders.php 2.4 KB

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