@@ -6,57 +6,57 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitEncryption |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\Encryption\\' => 15, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\Encryption\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
| 25 | - 'OCA\\Encryption\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 26 | - 'OCA\\Encryption\\Command\\CleanOrphanedKeys' => __DIR__ . '/..' . '/../lib/Command/CleanOrphanedKeys.php', |
|
| 27 | - 'OCA\\Encryption\\Command\\DisableMasterKey' => __DIR__ . '/..' . '/../lib/Command/DisableMasterKey.php', |
|
| 28 | - 'OCA\\Encryption\\Command\\DropLegacyFileKey' => __DIR__ . '/..' . '/../lib/Command/DropLegacyFileKey.php', |
|
| 29 | - 'OCA\\Encryption\\Command\\EnableMasterKey' => __DIR__ . '/..' . '/../lib/Command/EnableMasterKey.php', |
|
| 30 | - 'OCA\\Encryption\\Command\\FixEncryptedVersion' => __DIR__ . '/..' . '/../lib/Command/FixEncryptedVersion.php', |
|
| 31 | - 'OCA\\Encryption\\Command\\FixKeyLocation' => __DIR__ . '/..' . '/../lib/Command/FixKeyLocation.php', |
|
| 32 | - 'OCA\\Encryption\\Command\\RecoverUser' => __DIR__ . '/..' . '/../lib/Command/RecoverUser.php', |
|
| 33 | - 'OCA\\Encryption\\Command\\ScanLegacyFormat' => __DIR__ . '/..' . '/../lib/Command/ScanLegacyFormat.php', |
|
| 34 | - 'OCA\\Encryption\\Controller\\RecoveryController' => __DIR__ . '/..' . '/../lib/Controller/RecoveryController.php', |
|
| 35 | - 'OCA\\Encryption\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', |
|
| 36 | - 'OCA\\Encryption\\Controller\\StatusController' => __DIR__ . '/..' . '/../lib/Controller/StatusController.php', |
|
| 37 | - 'OCA\\Encryption\\Crypto\\Crypt' => __DIR__ . '/..' . '/../lib/Crypto/Crypt.php', |
|
| 38 | - 'OCA\\Encryption\\Crypto\\DecryptAll' => __DIR__ . '/..' . '/../lib/Crypto/DecryptAll.php', |
|
| 39 | - 'OCA\\Encryption\\Crypto\\EncryptAll' => __DIR__ . '/..' . '/../lib/Crypto/EncryptAll.php', |
|
| 40 | - 'OCA\\Encryption\\Crypto\\Encryption' => __DIR__ . '/..' . '/../lib/Crypto/Encryption.php', |
|
| 41 | - 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => __DIR__ . '/..' . '/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 42 | - 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => __DIR__ . '/..' . '/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 43 | - 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => __DIR__ . '/..' . '/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 44 | - 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => __DIR__ . '/..' . '/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 45 | - 'OCA\\Encryption\\KeyManager' => __DIR__ . '/..' . '/../lib/KeyManager.php', |
|
| 46 | - 'OCA\\Encryption\\Listeners\\UserEventsListener' => __DIR__ . '/..' . '/../lib/Listeners/UserEventsListener.php', |
|
| 47 | - 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => __DIR__ . '/..' . '/../lib/Migration/SetMasterKeyStatus.php', |
|
| 48 | - 'OCA\\Encryption\\Recovery' => __DIR__ . '/..' . '/../lib/Recovery.php', |
|
| 49 | - 'OCA\\Encryption\\Services\\PassphraseService' => __DIR__ . '/..' . '/../lib/Services/PassphraseService.php', |
|
| 50 | - 'OCA\\Encryption\\Session' => __DIR__ . '/..' . '/../lib/Session.php', |
|
| 51 | - 'OCA\\Encryption\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
| 52 | - 'OCA\\Encryption\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php', |
|
| 53 | - 'OCA\\Encryption\\Users\\Setup' => __DIR__ . '/..' . '/../lib/Users/Setup.php', |
|
| 54 | - 'OCA\\Encryption\\Util' => __DIR__ . '/..' . '/../lib/Util.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
| 25 | + 'OCA\\Encryption\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 26 | + 'OCA\\Encryption\\Command\\CleanOrphanedKeys' => __DIR__.'/..'.'/../lib/Command/CleanOrphanedKeys.php', |
|
| 27 | + 'OCA\\Encryption\\Command\\DisableMasterKey' => __DIR__.'/..'.'/../lib/Command/DisableMasterKey.php', |
|
| 28 | + 'OCA\\Encryption\\Command\\DropLegacyFileKey' => __DIR__.'/..'.'/../lib/Command/DropLegacyFileKey.php', |
|
| 29 | + 'OCA\\Encryption\\Command\\EnableMasterKey' => __DIR__.'/..'.'/../lib/Command/EnableMasterKey.php', |
|
| 30 | + 'OCA\\Encryption\\Command\\FixEncryptedVersion' => __DIR__.'/..'.'/../lib/Command/FixEncryptedVersion.php', |
|
| 31 | + 'OCA\\Encryption\\Command\\FixKeyLocation' => __DIR__.'/..'.'/../lib/Command/FixKeyLocation.php', |
|
| 32 | + 'OCA\\Encryption\\Command\\RecoverUser' => __DIR__.'/..'.'/../lib/Command/RecoverUser.php', |
|
| 33 | + 'OCA\\Encryption\\Command\\ScanLegacyFormat' => __DIR__.'/..'.'/../lib/Command/ScanLegacyFormat.php', |
|
| 34 | + 'OCA\\Encryption\\Controller\\RecoveryController' => __DIR__.'/..'.'/../lib/Controller/RecoveryController.php', |
|
| 35 | + 'OCA\\Encryption\\Controller\\SettingsController' => __DIR__.'/..'.'/../lib/Controller/SettingsController.php', |
|
| 36 | + 'OCA\\Encryption\\Controller\\StatusController' => __DIR__.'/..'.'/../lib/Controller/StatusController.php', |
|
| 37 | + 'OCA\\Encryption\\Crypto\\Crypt' => __DIR__.'/..'.'/../lib/Crypto/Crypt.php', |
|
| 38 | + 'OCA\\Encryption\\Crypto\\DecryptAll' => __DIR__.'/..'.'/../lib/Crypto/DecryptAll.php', |
|
| 39 | + 'OCA\\Encryption\\Crypto\\EncryptAll' => __DIR__.'/..'.'/../lib/Crypto/EncryptAll.php', |
|
| 40 | + 'OCA\\Encryption\\Crypto\\Encryption' => __DIR__.'/..'.'/../lib/Crypto/Encryption.php', |
|
| 41 | + 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => __DIR__.'/..'.'/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 42 | + 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => __DIR__.'/..'.'/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 43 | + 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => __DIR__.'/..'.'/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 44 | + 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => __DIR__.'/..'.'/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 45 | + 'OCA\\Encryption\\KeyManager' => __DIR__.'/..'.'/../lib/KeyManager.php', |
|
| 46 | + 'OCA\\Encryption\\Listeners\\UserEventsListener' => __DIR__.'/..'.'/../lib/Listeners/UserEventsListener.php', |
|
| 47 | + 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => __DIR__.'/..'.'/../lib/Migration/SetMasterKeyStatus.php', |
|
| 48 | + 'OCA\\Encryption\\Recovery' => __DIR__.'/..'.'/../lib/Recovery.php', |
|
| 49 | + 'OCA\\Encryption\\Services\\PassphraseService' => __DIR__.'/..'.'/../lib/Services/PassphraseService.php', |
|
| 50 | + 'OCA\\Encryption\\Session' => __DIR__.'/..'.'/../lib/Session.php', |
|
| 51 | + 'OCA\\Encryption\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
| 52 | + 'OCA\\Encryption\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php', |
|
| 53 | + 'OCA\\Encryption\\Users\\Setup' => __DIR__.'/..'.'/../lib/Users/Setup.php', |
|
| 54 | + 'OCA\\Encryption\\Util' => __DIR__.'/..'.'/../lib/Util.php', |
|
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | 57 | public static function getInitializer(ClassLoader $loader) |
| 58 | 58 | { |
| 59 | - return \Closure::bind(function () use ($loader) { |
|
| 59 | + return \Closure::bind(function() use ($loader) { |
|
| 60 | 60 | $loader->prefixLengthsPsr4 = ComposerStaticInitEncryption::$prefixLengthsPsr4; |
| 61 | 61 | $loader->prefixDirsPsr4 = ComposerStaticInitEncryption::$prefixDirsPsr4; |
| 62 | 62 | $loader->classMap = ComposerStaticInitEncryption::$classMap; |
@@ -6,35 +6,35 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
| 10 | - 'OCA\\Encryption\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 11 | - 'OCA\\Encryption\\Command\\CleanOrphanedKeys' => $baseDir . '/../lib/Command/CleanOrphanedKeys.php', |
|
| 12 | - 'OCA\\Encryption\\Command\\DisableMasterKey' => $baseDir . '/../lib/Command/DisableMasterKey.php', |
|
| 13 | - 'OCA\\Encryption\\Command\\DropLegacyFileKey' => $baseDir . '/../lib/Command/DropLegacyFileKey.php', |
|
| 14 | - 'OCA\\Encryption\\Command\\EnableMasterKey' => $baseDir . '/../lib/Command/EnableMasterKey.php', |
|
| 15 | - 'OCA\\Encryption\\Command\\FixEncryptedVersion' => $baseDir . '/../lib/Command/FixEncryptedVersion.php', |
|
| 16 | - 'OCA\\Encryption\\Command\\FixKeyLocation' => $baseDir . '/../lib/Command/FixKeyLocation.php', |
|
| 17 | - 'OCA\\Encryption\\Command\\RecoverUser' => $baseDir . '/../lib/Command/RecoverUser.php', |
|
| 18 | - 'OCA\\Encryption\\Command\\ScanLegacyFormat' => $baseDir . '/../lib/Command/ScanLegacyFormat.php', |
|
| 19 | - 'OCA\\Encryption\\Controller\\RecoveryController' => $baseDir . '/../lib/Controller/RecoveryController.php', |
|
| 20 | - 'OCA\\Encryption\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', |
|
| 21 | - 'OCA\\Encryption\\Controller\\StatusController' => $baseDir . '/../lib/Controller/StatusController.php', |
|
| 22 | - 'OCA\\Encryption\\Crypto\\Crypt' => $baseDir . '/../lib/Crypto/Crypt.php', |
|
| 23 | - 'OCA\\Encryption\\Crypto\\DecryptAll' => $baseDir . '/../lib/Crypto/DecryptAll.php', |
|
| 24 | - 'OCA\\Encryption\\Crypto\\EncryptAll' => $baseDir . '/../lib/Crypto/EncryptAll.php', |
|
| 25 | - 'OCA\\Encryption\\Crypto\\Encryption' => $baseDir . '/../lib/Crypto/Encryption.php', |
|
| 26 | - 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => $baseDir . '/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 27 | - 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => $baseDir . '/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 28 | - 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => $baseDir . '/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 29 | - 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => $baseDir . '/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 30 | - 'OCA\\Encryption\\KeyManager' => $baseDir . '/../lib/KeyManager.php', |
|
| 31 | - 'OCA\\Encryption\\Listeners\\UserEventsListener' => $baseDir . '/../lib/Listeners/UserEventsListener.php', |
|
| 32 | - 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => $baseDir . '/../lib/Migration/SetMasterKeyStatus.php', |
|
| 33 | - 'OCA\\Encryption\\Recovery' => $baseDir . '/../lib/Recovery.php', |
|
| 34 | - 'OCA\\Encryption\\Services\\PassphraseService' => $baseDir . '/../lib/Services/PassphraseService.php', |
|
| 35 | - 'OCA\\Encryption\\Session' => $baseDir . '/../lib/Session.php', |
|
| 36 | - 'OCA\\Encryption\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
|
| 37 | - 'OCA\\Encryption\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php', |
|
| 38 | - 'OCA\\Encryption\\Users\\Setup' => $baseDir . '/../lib/Users/Setup.php', |
|
| 39 | - 'OCA\\Encryption\\Util' => $baseDir . '/../lib/Util.php', |
|
| 9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
| 10 | + 'OCA\\Encryption\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 11 | + 'OCA\\Encryption\\Command\\CleanOrphanedKeys' => $baseDir.'/../lib/Command/CleanOrphanedKeys.php', |
|
| 12 | + 'OCA\\Encryption\\Command\\DisableMasterKey' => $baseDir.'/../lib/Command/DisableMasterKey.php', |
|
| 13 | + 'OCA\\Encryption\\Command\\DropLegacyFileKey' => $baseDir.'/../lib/Command/DropLegacyFileKey.php', |
|
| 14 | + 'OCA\\Encryption\\Command\\EnableMasterKey' => $baseDir.'/../lib/Command/EnableMasterKey.php', |
|
| 15 | + 'OCA\\Encryption\\Command\\FixEncryptedVersion' => $baseDir.'/../lib/Command/FixEncryptedVersion.php', |
|
| 16 | + 'OCA\\Encryption\\Command\\FixKeyLocation' => $baseDir.'/../lib/Command/FixKeyLocation.php', |
|
| 17 | + 'OCA\\Encryption\\Command\\RecoverUser' => $baseDir.'/../lib/Command/RecoverUser.php', |
|
| 18 | + 'OCA\\Encryption\\Command\\ScanLegacyFormat' => $baseDir.'/../lib/Command/ScanLegacyFormat.php', |
|
| 19 | + 'OCA\\Encryption\\Controller\\RecoveryController' => $baseDir.'/../lib/Controller/RecoveryController.php', |
|
| 20 | + 'OCA\\Encryption\\Controller\\SettingsController' => $baseDir.'/../lib/Controller/SettingsController.php', |
|
| 21 | + 'OCA\\Encryption\\Controller\\StatusController' => $baseDir.'/../lib/Controller/StatusController.php', |
|
| 22 | + 'OCA\\Encryption\\Crypto\\Crypt' => $baseDir.'/../lib/Crypto/Crypt.php', |
|
| 23 | + 'OCA\\Encryption\\Crypto\\DecryptAll' => $baseDir.'/../lib/Crypto/DecryptAll.php', |
|
| 24 | + 'OCA\\Encryption\\Crypto\\EncryptAll' => $baseDir.'/../lib/Crypto/EncryptAll.php', |
|
| 25 | + 'OCA\\Encryption\\Crypto\\Encryption' => $baseDir.'/../lib/Crypto/Encryption.php', |
|
| 26 | + 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => $baseDir.'/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 27 | + 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => $baseDir.'/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 28 | + 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => $baseDir.'/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 29 | + 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => $baseDir.'/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 30 | + 'OCA\\Encryption\\KeyManager' => $baseDir.'/../lib/KeyManager.php', |
|
| 31 | + 'OCA\\Encryption\\Listeners\\UserEventsListener' => $baseDir.'/../lib/Listeners/UserEventsListener.php', |
|
| 32 | + 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => $baseDir.'/../lib/Migration/SetMasterKeyStatus.php', |
|
| 33 | + 'OCA\\Encryption\\Recovery' => $baseDir.'/../lib/Recovery.php', |
|
| 34 | + 'OCA\\Encryption\\Services\\PassphraseService' => $baseDir.'/../lib/Services/PassphraseService.php', |
|
| 35 | + 'OCA\\Encryption\\Session' => $baseDir.'/../lib/Session.php', |
|
| 36 | + 'OCA\\Encryption\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php', |
|
| 37 | + 'OCA\\Encryption\\Settings\\Personal' => $baseDir.'/../lib/Settings/Personal.php', |
|
| 38 | + 'OCA\\Encryption\\Users\\Setup' => $baseDir.'/../lib/Users/Setup.php', |
|
| 39 | + 'OCA\\Encryption\\Util' => $baseDir.'/../lib/Util.php', |
|
| 40 | 40 | ); |
@@ -29,174 +29,174 @@ |
||
| 29 | 29 | |
| 30 | 30 | class CleanOrphanedKeys extends Command { |
| 31 | 31 | |
| 32 | - public function __construct( |
|
| 33 | - protected IConfig $config, |
|
| 34 | - protected QuestionHelper $questionHelper, |
|
| 35 | - private IUserManager $userManager, |
|
| 36 | - private Util $encryptionUtil, |
|
| 37 | - private SetupManager $setupManager, |
|
| 38 | - private IRootFolder $rootFolder, |
|
| 39 | - private LoggerInterface $logger, |
|
| 40 | - ) { |
|
| 41 | - parent::__construct(); |
|
| 42 | - |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - protected function configure(): void { |
|
| 46 | - $this |
|
| 47 | - ->setName('encryption:clean-orphaned-keys') |
|
| 48 | - ->setDescription('Scan the keys storage for orphaned keys and remove them'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 52 | - $orphanedKeys = []; |
|
| 53 | - $headline = 'Scanning all keys for file parity'; |
|
| 54 | - $output->writeln($headline); |
|
| 55 | - $output->writeln(str_pad('', strlen($headline), '=')); |
|
| 56 | - $output->writeln("\n"); |
|
| 57 | - $progress = new ProgressBar($output); |
|
| 58 | - $progress->setFormat(" %message% \n [%bar%]"); |
|
| 59 | - |
|
| 60 | - foreach ($this->userManager->getSeenUsers() as $user) { |
|
| 61 | - $uid = $user->getUID(); |
|
| 62 | - $progress->setMessage('Scanning all keys for: ' . $uid); |
|
| 63 | - $progress->advance(); |
|
| 64 | - $this->setupUserFileSystem($user); |
|
| 65 | - $root = $this->encryptionUtil->getKeyStorageRoot() . '/' . $uid . '/files_encryption/keys'; |
|
| 66 | - $userOrphanedKeys = $this->scanFolder($output, $root, $uid); |
|
| 67 | - $orphanedKeys = array_merge($orphanedKeys, $userOrphanedKeys); |
|
| 68 | - } |
|
| 69 | - $progress->setMessage('Scanned orphaned keys for all users'); |
|
| 70 | - $progress->finish(); |
|
| 71 | - $output->writeln("\n"); |
|
| 72 | - foreach ($orphanedKeys as $keyPath) { |
|
| 73 | - $output->writeln('Orphaned key found: ' . $keyPath); |
|
| 74 | - } |
|
| 75 | - if (count($orphanedKeys) == 0) { |
|
| 76 | - return self::SUCCESS; |
|
| 77 | - } |
|
| 78 | - $question = new ConfirmationQuestion('Do you want to delete all orphaned keys? (y/n) ', false); |
|
| 79 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 80 | - $this->deleteAll($orphanedKeys, $output); |
|
| 81 | - } else { |
|
| 82 | - |
|
| 83 | - $question = new ConfirmationQuestion('Do you want to delete specific keys? (y/n) ', false); |
|
| 84 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 85 | - $this->deleteSpecific($input, $output, $orphanedKeys); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return self::SUCCESS; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - private function scanFolder(OutputInterface $output, string $folderPath, string $user) : array { |
|
| 93 | - $orphanedKeys = []; |
|
| 94 | - try { |
|
| 95 | - $folder = $this->rootFolder->get($folderPath); |
|
| 96 | - } catch (NotFoundException $e) { |
|
| 97 | - // Happens when user doesn't have encrypted files |
|
| 98 | - $this->logger->error('Error when accessing folder ' . $folderPath . ' for user ' . $user, ['exception' => $e]); |
|
| 99 | - return []; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (!($folder instanceof Folder)) { |
|
| 103 | - $this->logger->error('Invalid folder'); |
|
| 104 | - return []; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - foreach ($folder->getDirectoryListing() as $item) { |
|
| 108 | - $path = $folderPath . '/' . $item->getName(); |
|
| 109 | - $stopValue = $this->stopCondition($path); |
|
| 110 | - if ($stopValue === null) { |
|
| 111 | - $this->logger->error('Reached unexpected state when scanning user\'s filesystem for orphaned encryption keys' . $path); |
|
| 112 | - } elseif ($stopValue) { |
|
| 113 | - $filePath = str_replace('files_encryption/keys/', '', $path); |
|
| 114 | - try { |
|
| 115 | - $this->rootFolder->get($filePath); |
|
| 116 | - } catch (NotFoundException $e) { |
|
| 117 | - // We found an orphaned key |
|
| 118 | - $orphanedKeys[] = $path; |
|
| 119 | - continue; |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $orphanedKeys = array_merge($orphanedKeys, $this->scanFolder($output, $path, $user)); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - return $orphanedKeys; |
|
| 126 | - } |
|
| 127 | - /** |
|
| 128 | - * Checks the stop considition for the recursion |
|
| 129 | - * following the logic that keys are stored in files_encryption/keys/<user>/<path>/<fileName>/OC_DEFAULT_MODULE/<key>.sharekey |
|
| 130 | - * @param string $path path of the current folder |
|
| 131 | - * @return bool|null true if we should stop and found a key, false if we should continue, null if we shouldn't end up here |
|
| 132 | - */ |
|
| 133 | - private function stopCondition(string $path) : ?bool { |
|
| 134 | - $folder = $this->rootFolder->get($path); |
|
| 135 | - if ($folder instanceof Folder) { |
|
| 136 | - $content = $folder->getDirectoryListing(); |
|
| 137 | - $subfolder = $content[0]; |
|
| 138 | - if (count($content) === 1 && $subfolder->getName() === Encryption::ID) { |
|
| 139 | - if ($subfolder instanceof Folder) { |
|
| 140 | - $content = $subfolder->getDirectoryListing(); |
|
| 141 | - if (count($content) === 1 && $content[0] instanceof File) { |
|
| 142 | - return strtolower($content[0]->getExtension()) === 'sharekey' ; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - // We shouldn't end up here, because we return true when reaching the folder named after the file containing OC_DEFAULT_MODULE |
|
| 149 | - return null; |
|
| 150 | - } |
|
| 151 | - private function deleteAll(array $keys, OutputInterface $output) { |
|
| 152 | - foreach ($keys as $key) { |
|
| 153 | - $file = $this->rootFolder->get($key); |
|
| 154 | - try { |
|
| 155 | - $file->delete(); |
|
| 156 | - $output->writeln('Key deleted: ' . $key); |
|
| 157 | - } catch (\Exception $e) { |
|
| 158 | - $output->writeln('Failed to delete ' . $key); |
|
| 159 | - $this->logger->error('Error when deleting orphaned key ' . $key . '. ' . $e->getMessage()); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - private function deleteSpecific(InputInterface $input, OutputInterface $output, array $orphanedKeys) { |
|
| 165 | - $question = new Question('Please enter path for key to delete: '); |
|
| 166 | - $path = $this->questionHelper->ask($input, $output, $question); |
|
| 167 | - if (!in_array(trim($path), $orphanedKeys)) { |
|
| 168 | - $output->writeln('Wrong key path'); |
|
| 169 | - } else { |
|
| 170 | - try { |
|
| 171 | - $this->rootFolder->get(trim($path))->delete(); |
|
| 172 | - $output->writeln('Key deleted: ' . $path); |
|
| 173 | - } catch (\Exception $e) { |
|
| 174 | - $output->writeln('Failed to delete ' . $path); |
|
| 175 | - $this->logger->error('Error when deleting orphaned key ' . $path . '. ' . $e->getMessage()); |
|
| 176 | - } |
|
| 177 | - $orphanedKeys = array_filter($orphanedKeys, function ($k) use ($path) { |
|
| 178 | - return $k !== trim($path); |
|
| 179 | - }); |
|
| 180 | - } |
|
| 181 | - if (count($orphanedKeys) == 0) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 184 | - $output->writeln('Remaining orphaned keys: '); |
|
| 185 | - foreach ($orphanedKeys as $keyPath) { |
|
| 186 | - $output->writeln($keyPath); |
|
| 187 | - } |
|
| 188 | - $question = new ConfirmationQuestion('Do you want to delete more orphaned keys? (y/n) ', false); |
|
| 189 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 190 | - $this->deleteSpecific($input, $output, $orphanedKeys); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * setup user file system |
|
| 197 | - */ |
|
| 198 | - protected function setupUserFileSystem(IUser $user): void { |
|
| 199 | - $this->setupManager->tearDown(); |
|
| 200 | - $this->setupManager->setupForUser($user); |
|
| 201 | - } |
|
| 32 | + public function __construct( |
|
| 33 | + protected IConfig $config, |
|
| 34 | + protected QuestionHelper $questionHelper, |
|
| 35 | + private IUserManager $userManager, |
|
| 36 | + private Util $encryptionUtil, |
|
| 37 | + private SetupManager $setupManager, |
|
| 38 | + private IRootFolder $rootFolder, |
|
| 39 | + private LoggerInterface $logger, |
|
| 40 | + ) { |
|
| 41 | + parent::__construct(); |
|
| 42 | + |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + protected function configure(): void { |
|
| 46 | + $this |
|
| 47 | + ->setName('encryption:clean-orphaned-keys') |
|
| 48 | + ->setDescription('Scan the keys storage for orphaned keys and remove them'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 52 | + $orphanedKeys = []; |
|
| 53 | + $headline = 'Scanning all keys for file parity'; |
|
| 54 | + $output->writeln($headline); |
|
| 55 | + $output->writeln(str_pad('', strlen($headline), '=')); |
|
| 56 | + $output->writeln("\n"); |
|
| 57 | + $progress = new ProgressBar($output); |
|
| 58 | + $progress->setFormat(" %message% \n [%bar%]"); |
|
| 59 | + |
|
| 60 | + foreach ($this->userManager->getSeenUsers() as $user) { |
|
| 61 | + $uid = $user->getUID(); |
|
| 62 | + $progress->setMessage('Scanning all keys for: ' . $uid); |
|
| 63 | + $progress->advance(); |
|
| 64 | + $this->setupUserFileSystem($user); |
|
| 65 | + $root = $this->encryptionUtil->getKeyStorageRoot() . '/' . $uid . '/files_encryption/keys'; |
|
| 66 | + $userOrphanedKeys = $this->scanFolder($output, $root, $uid); |
|
| 67 | + $orphanedKeys = array_merge($orphanedKeys, $userOrphanedKeys); |
|
| 68 | + } |
|
| 69 | + $progress->setMessage('Scanned orphaned keys for all users'); |
|
| 70 | + $progress->finish(); |
|
| 71 | + $output->writeln("\n"); |
|
| 72 | + foreach ($orphanedKeys as $keyPath) { |
|
| 73 | + $output->writeln('Orphaned key found: ' . $keyPath); |
|
| 74 | + } |
|
| 75 | + if (count($orphanedKeys) == 0) { |
|
| 76 | + return self::SUCCESS; |
|
| 77 | + } |
|
| 78 | + $question = new ConfirmationQuestion('Do you want to delete all orphaned keys? (y/n) ', false); |
|
| 79 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 80 | + $this->deleteAll($orphanedKeys, $output); |
|
| 81 | + } else { |
|
| 82 | + |
|
| 83 | + $question = new ConfirmationQuestion('Do you want to delete specific keys? (y/n) ', false); |
|
| 84 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 85 | + $this->deleteSpecific($input, $output, $orphanedKeys); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return self::SUCCESS; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + private function scanFolder(OutputInterface $output, string $folderPath, string $user) : array { |
|
| 93 | + $orphanedKeys = []; |
|
| 94 | + try { |
|
| 95 | + $folder = $this->rootFolder->get($folderPath); |
|
| 96 | + } catch (NotFoundException $e) { |
|
| 97 | + // Happens when user doesn't have encrypted files |
|
| 98 | + $this->logger->error('Error when accessing folder ' . $folderPath . ' for user ' . $user, ['exception' => $e]); |
|
| 99 | + return []; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (!($folder instanceof Folder)) { |
|
| 103 | + $this->logger->error('Invalid folder'); |
|
| 104 | + return []; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + foreach ($folder->getDirectoryListing() as $item) { |
|
| 108 | + $path = $folderPath . '/' . $item->getName(); |
|
| 109 | + $stopValue = $this->stopCondition($path); |
|
| 110 | + if ($stopValue === null) { |
|
| 111 | + $this->logger->error('Reached unexpected state when scanning user\'s filesystem for orphaned encryption keys' . $path); |
|
| 112 | + } elseif ($stopValue) { |
|
| 113 | + $filePath = str_replace('files_encryption/keys/', '', $path); |
|
| 114 | + try { |
|
| 115 | + $this->rootFolder->get($filePath); |
|
| 116 | + } catch (NotFoundException $e) { |
|
| 117 | + // We found an orphaned key |
|
| 118 | + $orphanedKeys[] = $path; |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $orphanedKeys = array_merge($orphanedKeys, $this->scanFolder($output, $path, $user)); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + return $orphanedKeys; |
|
| 126 | + } |
|
| 127 | + /** |
|
| 128 | + * Checks the stop considition for the recursion |
|
| 129 | + * following the logic that keys are stored in files_encryption/keys/<user>/<path>/<fileName>/OC_DEFAULT_MODULE/<key>.sharekey |
|
| 130 | + * @param string $path path of the current folder |
|
| 131 | + * @return bool|null true if we should stop and found a key, false if we should continue, null if we shouldn't end up here |
|
| 132 | + */ |
|
| 133 | + private function stopCondition(string $path) : ?bool { |
|
| 134 | + $folder = $this->rootFolder->get($path); |
|
| 135 | + if ($folder instanceof Folder) { |
|
| 136 | + $content = $folder->getDirectoryListing(); |
|
| 137 | + $subfolder = $content[0]; |
|
| 138 | + if (count($content) === 1 && $subfolder->getName() === Encryption::ID) { |
|
| 139 | + if ($subfolder instanceof Folder) { |
|
| 140 | + $content = $subfolder->getDirectoryListing(); |
|
| 141 | + if (count($content) === 1 && $content[0] instanceof File) { |
|
| 142 | + return strtolower($content[0]->getExtension()) === 'sharekey' ; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + // We shouldn't end up here, because we return true when reaching the folder named after the file containing OC_DEFAULT_MODULE |
|
| 149 | + return null; |
|
| 150 | + } |
|
| 151 | + private function deleteAll(array $keys, OutputInterface $output) { |
|
| 152 | + foreach ($keys as $key) { |
|
| 153 | + $file = $this->rootFolder->get($key); |
|
| 154 | + try { |
|
| 155 | + $file->delete(); |
|
| 156 | + $output->writeln('Key deleted: ' . $key); |
|
| 157 | + } catch (\Exception $e) { |
|
| 158 | + $output->writeln('Failed to delete ' . $key); |
|
| 159 | + $this->logger->error('Error when deleting orphaned key ' . $key . '. ' . $e->getMessage()); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + private function deleteSpecific(InputInterface $input, OutputInterface $output, array $orphanedKeys) { |
|
| 165 | + $question = new Question('Please enter path for key to delete: '); |
|
| 166 | + $path = $this->questionHelper->ask($input, $output, $question); |
|
| 167 | + if (!in_array(trim($path), $orphanedKeys)) { |
|
| 168 | + $output->writeln('Wrong key path'); |
|
| 169 | + } else { |
|
| 170 | + try { |
|
| 171 | + $this->rootFolder->get(trim($path))->delete(); |
|
| 172 | + $output->writeln('Key deleted: ' . $path); |
|
| 173 | + } catch (\Exception $e) { |
|
| 174 | + $output->writeln('Failed to delete ' . $path); |
|
| 175 | + $this->logger->error('Error when deleting orphaned key ' . $path . '. ' . $e->getMessage()); |
|
| 176 | + } |
|
| 177 | + $orphanedKeys = array_filter($orphanedKeys, function ($k) use ($path) { |
|
| 178 | + return $k !== trim($path); |
|
| 179 | + }); |
|
| 180 | + } |
|
| 181 | + if (count($orphanedKeys) == 0) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | + $output->writeln('Remaining orphaned keys: '); |
|
| 185 | + foreach ($orphanedKeys as $keyPath) { |
|
| 186 | + $output->writeln($keyPath); |
|
| 187 | + } |
|
| 188 | + $question = new ConfirmationQuestion('Do you want to delete more orphaned keys? (y/n) ', false); |
|
| 189 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
| 190 | + $this->deleteSpecific($input, $output, $orphanedKeys); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * setup user file system |
|
| 197 | + */ |
|
| 198 | + protected function setupUserFileSystem(IUser $user): void { |
|
| 199 | + $this->setupManager->tearDown(); |
|
| 200 | + $this->setupManager->setupForUser($user); |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | foreach ($this->userManager->getSeenUsers() as $user) { |
| 61 | 61 | $uid = $user->getUID(); |
| 62 | - $progress->setMessage('Scanning all keys for: ' . $uid); |
|
| 62 | + $progress->setMessage('Scanning all keys for: '.$uid); |
|
| 63 | 63 | $progress->advance(); |
| 64 | 64 | $this->setupUserFileSystem($user); |
| 65 | - $root = $this->encryptionUtil->getKeyStorageRoot() . '/' . $uid . '/files_encryption/keys'; |
|
| 65 | + $root = $this->encryptionUtil->getKeyStorageRoot().'/'.$uid.'/files_encryption/keys'; |
|
| 66 | 66 | $userOrphanedKeys = $this->scanFolder($output, $root, $uid); |
| 67 | 67 | $orphanedKeys = array_merge($orphanedKeys, $userOrphanedKeys); |
| 68 | 68 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $progress->finish(); |
| 71 | 71 | $output->writeln("\n"); |
| 72 | 72 | foreach ($orphanedKeys as $keyPath) { |
| 73 | - $output->writeln('Orphaned key found: ' . $keyPath); |
|
| 73 | + $output->writeln('Orphaned key found: '.$keyPath); |
|
| 74 | 74 | } |
| 75 | 75 | if (count($orphanedKeys) == 0) { |
| 76 | 76 | return self::SUCCESS; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $folder = $this->rootFolder->get($folderPath); |
| 96 | 96 | } catch (NotFoundException $e) { |
| 97 | 97 | // Happens when user doesn't have encrypted files |
| 98 | - $this->logger->error('Error when accessing folder ' . $folderPath . ' for user ' . $user, ['exception' => $e]); |
|
| 98 | + $this->logger->error('Error when accessing folder '.$folderPath.' for user '.$user, ['exception' => $e]); |
|
| 99 | 99 | return []; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | foreach ($folder->getDirectoryListing() as $item) { |
| 108 | - $path = $folderPath . '/' . $item->getName(); |
|
| 108 | + $path = $folderPath.'/'.$item->getName(); |
|
| 109 | 109 | $stopValue = $this->stopCondition($path); |
| 110 | 110 | if ($stopValue === null) { |
| 111 | - $this->logger->error('Reached unexpected state when scanning user\'s filesystem for orphaned encryption keys' . $path); |
|
| 111 | + $this->logger->error('Reached unexpected state when scanning user\'s filesystem for orphaned encryption keys'.$path); |
|
| 112 | 112 | } elseif ($stopValue) { |
| 113 | 113 | $filePath = str_replace('files_encryption/keys/', '', $path); |
| 114 | 114 | try { |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | if ($subfolder instanceof Folder) { |
| 140 | 140 | $content = $subfolder->getDirectoryListing(); |
| 141 | 141 | if (count($content) === 1 && $content[0] instanceof File) { |
| 142 | - return strtolower($content[0]->getExtension()) === 'sharekey' ; |
|
| 142 | + return strtolower($content[0]->getExtension()) === 'sharekey'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | $file = $this->rootFolder->get($key); |
| 154 | 154 | try { |
| 155 | 155 | $file->delete(); |
| 156 | - $output->writeln('Key deleted: ' . $key); |
|
| 156 | + $output->writeln('Key deleted: '.$key); |
|
| 157 | 157 | } catch (\Exception $e) { |
| 158 | - $output->writeln('Failed to delete ' . $key); |
|
| 159 | - $this->logger->error('Error when deleting orphaned key ' . $key . '. ' . $e->getMessage()); |
|
| 158 | + $output->writeln('Failed to delete '.$key); |
|
| 159 | + $this->logger->error('Error when deleting orphaned key '.$key.'. '.$e->getMessage()); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | } else { |
| 170 | 170 | try { |
| 171 | 171 | $this->rootFolder->get(trim($path))->delete(); |
| 172 | - $output->writeln('Key deleted: ' . $path); |
|
| 172 | + $output->writeln('Key deleted: '.$path); |
|
| 173 | 173 | } catch (\Exception $e) { |
| 174 | - $output->writeln('Failed to delete ' . $path); |
|
| 175 | - $this->logger->error('Error when deleting orphaned key ' . $path . '. ' . $e->getMessage()); |
|
| 174 | + $output->writeln('Failed to delete '.$path); |
|
| 175 | + $this->logger->error('Error when deleting orphaned key '.$path.'. '.$e->getMessage()); |
|
| 176 | 176 | } |
| 177 | - $orphanedKeys = array_filter($orphanedKeys, function ($k) use ($path) { |
|
| 177 | + $orphanedKeys = array_filter($orphanedKeys, function($k) use ($path) { |
|
| 178 | 178 | return $k !== trim($path); |
| 179 | 179 | }); |
| 180 | 180 | } |