You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckUserCertificates.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  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\IConfig;
  26. use OCP\IL10N;
  27. use OCP\IURLGenerator;
  28. class CheckUserCertificates {
  29. /** @var IL10N */
  30. private $l10n;
  31. /** @var string */
  32. private $configValue;
  33. /** @var IURLGenerator */
  34. private $urlGenerator;
  35. public function __construct(IL10N $l10n, IConfig $config, IURLGenerator $urlGenerator) {
  36. $this->l10n = $l10n;
  37. $configValue = $config->getAppValue('files_external', 'user_certificate_scan', false);
  38. if (!is_string($configValue)) {
  39. $configValue = '';
  40. }
  41. $this->configValue = $configValue;
  42. $this->urlGenerator = $urlGenerator;
  43. }
  44. public function description(): string {
  45. if ($this->configValue === '') {
  46. return '';
  47. }
  48. if ($this->configValue === 'not-run-yet') {
  49. return $this->l10n->t('A background job is pending that checks for user imported SSL certificates. Please check back later.');
  50. }
  51. return $this->l10n->t('There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.');
  52. }
  53. public function severity(): string {
  54. return 'warning';
  55. }
  56. public function run(): bool {
  57. // all fine if neither "not-run-yet" nor a result
  58. return $this->configValue === '';
  59. }
  60. public function elements(): array {
  61. if ($this->configValue === '' || $this->configValue === 'not-run-yet') {
  62. return [];
  63. }
  64. $data = json_decode($this->configValue);
  65. if (!is_array($data)) {
  66. return [];
  67. }
  68. return $data;
  69. }
  70. }