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.

CheckForUserCertificates.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author J0WI <J0WI@users.noreply.github.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Core\BackgroundJobs;
  26. use OC\BackgroundJob\QueuedJob;
  27. use OCP\Files\Folder;
  28. use OCP\Files\IRootFolder;
  29. use OCP\Files\NotFoundException;
  30. use OCP\IConfig;
  31. use OCP\IUser;
  32. use OCP\IUserManager;
  33. class CheckForUserCertificates extends QueuedJob {
  34. protected IConfig $config;
  35. private IUserManager $userManager;
  36. private IRootFolder $rootFolder;
  37. public function __construct(IConfig $config, IUserManager $userManager, IRootFolder $rootFolder) {
  38. $this->config = $config;
  39. $this->userManager = $userManager;
  40. $this->rootFolder = $rootFolder;
  41. }
  42. /**
  43. * Checks all user directories for old user uploaded certificates
  44. */
  45. public function run($arguments): void {
  46. $uploadList = [];
  47. $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) {
  48. $userId = $user->getUID();
  49. try {
  50. \OC_Util::setupFS($userId);
  51. $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads');
  52. } catch (NotFoundException $e) {
  53. \OC_Util::tearDownFS();
  54. return;
  55. }
  56. if ($filesExternalUploadsFolder instanceof Folder) {
  57. $files = $filesExternalUploadsFolder->getDirectoryListing();
  58. foreach ($files as $file) {
  59. $filename = $file->getName();
  60. $uploadList[] = "$userId/files_external/uploads/$filename";
  61. }
  62. }
  63. \OC_Util::tearDownFS();
  64. });
  65. if (empty($uploadList)) {
  66. $this->config->deleteAppValue('files_external', 'user_certificate_scan');
  67. } else {
  68. $this->config->setAppValue('files_external', 'user_certificate_scan', json_encode($uploadList));
  69. }
  70. }
  71. }