protected function execute(InputInterface $input, OutputInterface $output) { if ($this->encryptionManager->isEnabled() === false) { throw new \Exception('Server side encryption is not enabled'); } $output->writeln("\n"); $output->writeln('You are about to start to encrypt all files stored in your ownCloud.'); $output->writeln('It will depend on the encryption module you use which files get encrypted.'); $output->writeln('Depending on the number and size of your files this can take some time'); $output->writeln('Please make sure that no user access his files during this process!'); $output->writeln(''); $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); if ($this->questionHelper->ask($input, $output, $question)) { $this->forceSingleUserAndTrashbin(); try { $defaultModule = $this->encryptionManager->getEncryptionModule(); $defaultModule->encryptAll($input, $output); } catch (\Exception $ex) { $this->resetSingleUserAndTrashbin(); throw $ex; } $this->resetSingleUserAndTrashbin(); } else { $output->writeln('aborted'); } }
/** * read encryption module needed to read/write the file located at $path * * @param string $path * @return null|\OCP\Encryption\IEncryptionModule * @throws ModuleDoesNotExistsException * @throws \Exception */ protected function getEncryptionModule($path) { $encryptionModule = null; $header = $this->getHeader($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); if (!empty($encryptionModuleId)) { try { $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); } catch (ModuleDoesNotExistsException $e) { $this->logger->critical('Encryption module defined in "' . $path . '" not loaded!'); throw $e; } } return $encryptionModule; }