1
0

OverwriteCliUrl.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\IConfig;
  9. use OCP\IL10N;
  10. use OCP\IRequest;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. class OverwriteCliUrl implements ISetupCheck {
  14. public function __construct(
  15. private IL10N $l10n,
  16. private IConfig $config,
  17. private IRequest $request,
  18. ) {
  19. }
  20. public function getCategory(): string {
  21. return 'config';
  22. }
  23. public function getName(): string {
  24. return $this->l10n->t('Overwrite CLI URL');
  25. }
  26. public function run(): SetupResult {
  27. $currentOverwriteCliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
  28. $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
  29. // Check correctness by checking if it is a valid URL
  30. if (filter_var($currentOverwriteCliUrl, FILTER_VALIDATE_URL)) {
  31. if ($currentOverwriteCliUrl == $suggestedOverwriteCliUrl) {
  32. return SetupResult::success(
  33. $this->l10n->t(
  34. 'The "overwrite.cli.url" option in your config.php is correctly set to "%s".',
  35. [$currentOverwriteCliUrl]
  36. )
  37. );
  38. } else {
  39. return SetupResult::success(
  40. $this->l10n->t(
  41. 'The "overwrite.cli.url" option in your config.php is set to "%s" which is a correct URL. Suggested URL is "%s".',
  42. [$currentOverwriteCliUrl, $suggestedOverwriteCliUrl]
  43. )
  44. );
  45. }
  46. } else {
  47. return SetupResult::warning(
  48. $this->l10n->t(
  49. 'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "%s". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)',
  50. [$suggestedOverwriteCliUrl]
  51. )
  52. );
  53. }
  54. }
  55. }