OcxProviders.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use OCP\Http\Client\IClientService;
  26. use OCP\IConfig;
  27. use OCP\IL10N;
  28. use OCP\IURLGenerator;
  29. use OCP\SetupCheck\ISetupCheck;
  30. use OCP\SetupCheck\SetupResult;
  31. use Psr\Log\LoggerInterface;
  32. /**
  33. * Checks if the webserver serves the OCM and OCS providers
  34. */
  35. class OcxProviders implements ISetupCheck {
  36. use CheckServerResponseTrait;
  37. public function __construct(
  38. protected IL10N $l10n,
  39. protected IConfig $config,
  40. protected IURLGenerator $urlGenerator,
  41. protected IClientService $clientService,
  42. protected LoggerInterface $logger,
  43. ) {
  44. }
  45. public function getCategory(): string {
  46. return 'network';
  47. }
  48. public function getName(): string {
  49. return $this->l10n->t('OCS provider resolving');
  50. }
  51. public function run(): SetupResult {
  52. // List of providers that work
  53. $workingProviders = [];
  54. // List of providers we tested (in case one or multiple do not yield any response)
  55. $testedProviders = [];
  56. // All providers that we need to test
  57. $providers = [
  58. '/ocm-provider/',
  59. '/ocs-provider/',
  60. ];
  61. foreach ($providers as $provider) {
  62. foreach ($this->runRequest('HEAD', $this->urlGenerator->getWebroot() . $provider, ['httpErrors' => false]) as $response) {
  63. $testedProviders[$provider] = true;
  64. if ($response->getStatusCode() === 200) {
  65. $workingProviders[] = $provider;
  66. break;
  67. }
  68. }
  69. }
  70. if (count($testedProviders) < count($providers)) {
  71. return SetupResult::warning(
  72. $this->l10n->t('Could not check if your web server properly resolves the OCM and OCS provider URLs.', ) . "\n" . $this->serverConfigHelp(),
  73. );
  74. }
  75. $missingProviders = array_diff($providers, $workingProviders);
  76. if (empty($missingProviders)) {
  77. return SetupResult::success();
  78. }
  79. return SetupResult::warning(
  80. $this->l10n->t('Your web server is not properly set up to resolve %1$s.
  81. This is most likely related to a web server configuration that was not updated to deliver this folder directly.
  82. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx.
  83. On Nginx those are typically the lines starting with "location ~" that need an update.', [join(', ', array_map(fn ($s) => '"'.$s.'"', $missingProviders))]),
  84. $this->urlGenerator->linkToDocs('admin-nginx'),
  85. );
  86. }
  87. }