@@ -41,229 +41,229 @@ |
||
41 | 41 | |
42 | 42 | class ChangeKeyStorageRoot extends Command { |
43 | 43 | |
44 | - /** @var View */ |
|
45 | - protected $rootView; |
|
46 | - |
|
47 | - /** @var IUserManager */ |
|
48 | - protected $userManager; |
|
49 | - |
|
50 | - /** @var IConfig */ |
|
51 | - protected $config; |
|
52 | - |
|
53 | - /** @var Util */ |
|
54 | - protected $util; |
|
55 | - |
|
56 | - /** @var QuestionHelper */ |
|
57 | - protected $questionHelper; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param View $view |
|
61 | - * @param IUserManager $userManager |
|
62 | - * @param IConfig $config |
|
63 | - * @param Util $util |
|
64 | - * @param QuestionHelper $questionHelper |
|
65 | - */ |
|
66 | - public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, QuestionHelper $questionHelper) { |
|
67 | - parent::__construct(); |
|
68 | - $this->rootView = $view; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->config = $config; |
|
71 | - $this->util = $util; |
|
72 | - $this->questionHelper = $questionHelper; |
|
73 | - } |
|
74 | - |
|
75 | - protected function configure() { |
|
76 | - parent::configure(); |
|
77 | - $this |
|
78 | - ->setName('encryption:change-key-storage-root') |
|
79 | - ->setDescription('Change key storage root') |
|
80 | - ->addArgument( |
|
81 | - 'newRoot', |
|
82 | - InputArgument::OPTIONAL, |
|
83 | - 'new root of the key storage relative to the data folder' |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
88 | - $oldRoot = $this->util->getKeyStorageRoot(); |
|
89 | - $newRoot = $input->getArgument('newRoot'); |
|
90 | - |
|
91 | - if ($newRoot === null) { |
|
92 | - $question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false); |
|
93 | - if (!$this->questionHelper->ask($input, $output, $question)) { |
|
94 | - return 1; |
|
95 | - } |
|
96 | - $newRoot = ''; |
|
97 | - } |
|
98 | - |
|
99 | - $oldRootDescription = $oldRoot !== '' ? $oldRoot : 'default storage location'; |
|
100 | - $newRootDescription = $newRoot !== '' ? $newRoot : 'default storage location'; |
|
101 | - $output->writeln("Change key storage root from <info>$oldRootDescription</info> to <info>$newRootDescription</info>"); |
|
102 | - $success = $this->moveAllKeys($oldRoot, $newRoot, $output); |
|
103 | - if ($success) { |
|
104 | - $this->util->setKeyStorageRoot($newRoot); |
|
105 | - $output->writeln(''); |
|
106 | - $output->writeln("Key storage root successfully changed to <info>$newRootDescription</info>"); |
|
107 | - return 0; |
|
108 | - } |
|
109 | - return 1; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * move keys to new key storage root |
|
114 | - * |
|
115 | - * @param string $oldRoot |
|
116 | - * @param string $newRoot |
|
117 | - * @param OutputInterface $output |
|
118 | - * @return bool |
|
119 | - * @throws \Exception |
|
120 | - */ |
|
121 | - protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) { |
|
122 | - $output->writeln("Start to move keys:"); |
|
123 | - |
|
124 | - if ($this->rootView->is_dir($oldRoot) === false) { |
|
125 | - $output->writeln("No old keys found: Nothing needs to be moved"); |
|
126 | - return false; |
|
127 | - } |
|
128 | - |
|
129 | - $this->prepareNewRoot($newRoot); |
|
130 | - $this->moveSystemKeys($oldRoot, $newRoot); |
|
131 | - $this->moveUserKeys($oldRoot, $newRoot, $output); |
|
132 | - |
|
133 | - return true; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * prepare new key storage |
|
138 | - * |
|
139 | - * @param string $newRoot |
|
140 | - * @throws \Exception |
|
141 | - */ |
|
142 | - protected function prepareNewRoot($newRoot) { |
|
143 | - if ($this->rootView->is_dir($newRoot) === false) { |
|
144 | - throw new \Exception("New root folder doesn't exist. Please create the folder or check the permissions and try again."); |
|
145 | - } |
|
146 | - |
|
147 | - $result = $this->rootView->file_put_contents( |
|
148 | - $newRoot . '/' . Storage::KEY_STORAGE_MARKER, |
|
149 | - 'Nextcloud will detect this folder as key storage root only if this file exists' |
|
150 | - ); |
|
151 | - |
|
152 | - if (!$result) { |
|
153 | - throw new \Exception("Can't access the new root folder. Please check the permissions and make sure that the folder is in your data folder"); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * move system key folder |
|
160 | - * |
|
161 | - * @param string $oldRoot |
|
162 | - * @param string $newRoot |
|
163 | - */ |
|
164 | - protected function moveSystemKeys($oldRoot, $newRoot) { |
|
165 | - if ( |
|
166 | - $this->rootView->is_dir($oldRoot . '/files_encryption') && |
|
167 | - $this->targetExists($newRoot . '/files_encryption') === false |
|
168 | - ) { |
|
169 | - $this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption'); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * setup file system for the given user |
|
176 | - * |
|
177 | - * @param string $uid |
|
178 | - */ |
|
179 | - protected function setupUserFS($uid) { |
|
180 | - \OC_Util::tearDownFS(); |
|
181 | - \OC_Util::setupFS($uid); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * iterate over each user and move the keys to the new storage |
|
187 | - * |
|
188 | - * @param string $oldRoot |
|
189 | - * @param string $newRoot |
|
190 | - * @param OutputInterface $output |
|
191 | - */ |
|
192 | - protected function moveUserKeys($oldRoot, $newRoot, OutputInterface $output) { |
|
193 | - $progress = new ProgressBar($output); |
|
194 | - $progress->start(); |
|
195 | - |
|
196 | - |
|
197 | - foreach ($this->userManager->getBackends() as $backend) { |
|
198 | - $limit = 500; |
|
199 | - $offset = 0; |
|
200 | - do { |
|
201 | - $users = $backend->getUsers('', $limit, $offset); |
|
202 | - foreach ($users as $user) { |
|
203 | - $progress->advance(); |
|
204 | - $this->setupUserFS($user); |
|
205 | - $this->moveUserEncryptionFolder($user, $oldRoot, $newRoot); |
|
206 | - } |
|
207 | - $offset += $limit; |
|
208 | - } while (count($users) >= $limit); |
|
209 | - } |
|
210 | - $progress->finish(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * move user encryption folder to new root folder |
|
215 | - * |
|
216 | - * @param string $user |
|
217 | - * @param string $oldRoot |
|
218 | - * @param string $newRoot |
|
219 | - * @throws \Exception |
|
220 | - */ |
|
221 | - protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot) { |
|
222 | - if ($this->userManager->userExists($user)) { |
|
223 | - $source = $oldRoot . '/' . $user . '/files_encryption'; |
|
224 | - $target = $newRoot . '/' . $user . '/files_encryption'; |
|
225 | - if ( |
|
226 | - $this->rootView->is_dir($source) && |
|
227 | - $this->targetExists($target) === false |
|
228 | - ) { |
|
229 | - $this->prepareParentFolder($newRoot . '/' . $user); |
|
230 | - $this->rootView->rename($source, $target); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Make preparations to filesystem for saving a key file |
|
237 | - * |
|
238 | - * @param string $path relative to data/ |
|
239 | - */ |
|
240 | - protected function prepareParentFolder($path) { |
|
241 | - $path = Filesystem::normalizePath($path); |
|
242 | - // If the file resides within a subdirectory, create it |
|
243 | - if ($this->rootView->file_exists($path) === false) { |
|
244 | - $sub_dirs = explode('/', ltrim($path, '/')); |
|
245 | - $dir = ''; |
|
246 | - foreach ($sub_dirs as $sub_dir) { |
|
247 | - $dir .= '/' . $sub_dir; |
|
248 | - if ($this->rootView->file_exists($dir) === false) { |
|
249 | - $this->rootView->mkdir($dir); |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * check if target already exists |
|
257 | - * |
|
258 | - * @param $path |
|
259 | - * @return bool |
|
260 | - * @throws \Exception |
|
261 | - */ |
|
262 | - protected function targetExists($path) { |
|
263 | - if ($this->rootView->file_exists($path)) { |
|
264 | - throw new \Exception("new folder '$path' already exists"); |
|
265 | - } |
|
266 | - |
|
267 | - return false; |
|
268 | - } |
|
44 | + /** @var View */ |
|
45 | + protected $rootView; |
|
46 | + |
|
47 | + /** @var IUserManager */ |
|
48 | + protected $userManager; |
|
49 | + |
|
50 | + /** @var IConfig */ |
|
51 | + protected $config; |
|
52 | + |
|
53 | + /** @var Util */ |
|
54 | + protected $util; |
|
55 | + |
|
56 | + /** @var QuestionHelper */ |
|
57 | + protected $questionHelper; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param View $view |
|
61 | + * @param IUserManager $userManager |
|
62 | + * @param IConfig $config |
|
63 | + * @param Util $util |
|
64 | + * @param QuestionHelper $questionHelper |
|
65 | + */ |
|
66 | + public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, QuestionHelper $questionHelper) { |
|
67 | + parent::__construct(); |
|
68 | + $this->rootView = $view; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->config = $config; |
|
71 | + $this->util = $util; |
|
72 | + $this->questionHelper = $questionHelper; |
|
73 | + } |
|
74 | + |
|
75 | + protected function configure() { |
|
76 | + parent::configure(); |
|
77 | + $this |
|
78 | + ->setName('encryption:change-key-storage-root') |
|
79 | + ->setDescription('Change key storage root') |
|
80 | + ->addArgument( |
|
81 | + 'newRoot', |
|
82 | + InputArgument::OPTIONAL, |
|
83 | + 'new root of the key storage relative to the data folder' |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
88 | + $oldRoot = $this->util->getKeyStorageRoot(); |
|
89 | + $newRoot = $input->getArgument('newRoot'); |
|
90 | + |
|
91 | + if ($newRoot === null) { |
|
92 | + $question = new ConfirmationQuestion('No storage root given, do you want to reset the key storage root to the default location? (y/n) ', false); |
|
93 | + if (!$this->questionHelper->ask($input, $output, $question)) { |
|
94 | + return 1; |
|
95 | + } |
|
96 | + $newRoot = ''; |
|
97 | + } |
|
98 | + |
|
99 | + $oldRootDescription = $oldRoot !== '' ? $oldRoot : 'default storage location'; |
|
100 | + $newRootDescription = $newRoot !== '' ? $newRoot : 'default storage location'; |
|
101 | + $output->writeln("Change key storage root from <info>$oldRootDescription</info> to <info>$newRootDescription</info>"); |
|
102 | + $success = $this->moveAllKeys($oldRoot, $newRoot, $output); |
|
103 | + if ($success) { |
|
104 | + $this->util->setKeyStorageRoot($newRoot); |
|
105 | + $output->writeln(''); |
|
106 | + $output->writeln("Key storage root successfully changed to <info>$newRootDescription</info>"); |
|
107 | + return 0; |
|
108 | + } |
|
109 | + return 1; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * move keys to new key storage root |
|
114 | + * |
|
115 | + * @param string $oldRoot |
|
116 | + * @param string $newRoot |
|
117 | + * @param OutputInterface $output |
|
118 | + * @return bool |
|
119 | + * @throws \Exception |
|
120 | + */ |
|
121 | + protected function moveAllKeys($oldRoot, $newRoot, OutputInterface $output) { |
|
122 | + $output->writeln("Start to move keys:"); |
|
123 | + |
|
124 | + if ($this->rootView->is_dir($oldRoot) === false) { |
|
125 | + $output->writeln("No old keys found: Nothing needs to be moved"); |
|
126 | + return false; |
|
127 | + } |
|
128 | + |
|
129 | + $this->prepareNewRoot($newRoot); |
|
130 | + $this->moveSystemKeys($oldRoot, $newRoot); |
|
131 | + $this->moveUserKeys($oldRoot, $newRoot, $output); |
|
132 | + |
|
133 | + return true; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * prepare new key storage |
|
138 | + * |
|
139 | + * @param string $newRoot |
|
140 | + * @throws \Exception |
|
141 | + */ |
|
142 | + protected function prepareNewRoot($newRoot) { |
|
143 | + if ($this->rootView->is_dir($newRoot) === false) { |
|
144 | + throw new \Exception("New root folder doesn't exist. Please create the folder or check the permissions and try again."); |
|
145 | + } |
|
146 | + |
|
147 | + $result = $this->rootView->file_put_contents( |
|
148 | + $newRoot . '/' . Storage::KEY_STORAGE_MARKER, |
|
149 | + 'Nextcloud will detect this folder as key storage root only if this file exists' |
|
150 | + ); |
|
151 | + |
|
152 | + if (!$result) { |
|
153 | + throw new \Exception("Can't access the new root folder. Please check the permissions and make sure that the folder is in your data folder"); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * move system key folder |
|
160 | + * |
|
161 | + * @param string $oldRoot |
|
162 | + * @param string $newRoot |
|
163 | + */ |
|
164 | + protected function moveSystemKeys($oldRoot, $newRoot) { |
|
165 | + if ( |
|
166 | + $this->rootView->is_dir($oldRoot . '/files_encryption') && |
|
167 | + $this->targetExists($newRoot . '/files_encryption') === false |
|
168 | + ) { |
|
169 | + $this->rootView->rename($oldRoot . '/files_encryption', $newRoot . '/files_encryption'); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * setup file system for the given user |
|
176 | + * |
|
177 | + * @param string $uid |
|
178 | + */ |
|
179 | + protected function setupUserFS($uid) { |
|
180 | + \OC_Util::tearDownFS(); |
|
181 | + \OC_Util::setupFS($uid); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * iterate over each user and move the keys to the new storage |
|
187 | + * |
|
188 | + * @param string $oldRoot |
|
189 | + * @param string $newRoot |
|
190 | + * @param OutputInterface $output |
|
191 | + */ |
|
192 | + protected function moveUserKeys($oldRoot, $newRoot, OutputInterface $output) { |
|
193 | + $progress = new ProgressBar($output); |
|
194 | + $progress->start(); |
|
195 | + |
|
196 | + |
|
197 | + foreach ($this->userManager->getBackends() as $backend) { |
|
198 | + $limit = 500; |
|
199 | + $offset = 0; |
|
200 | + do { |
|
201 | + $users = $backend->getUsers('', $limit, $offset); |
|
202 | + foreach ($users as $user) { |
|
203 | + $progress->advance(); |
|
204 | + $this->setupUserFS($user); |
|
205 | + $this->moveUserEncryptionFolder($user, $oldRoot, $newRoot); |
|
206 | + } |
|
207 | + $offset += $limit; |
|
208 | + } while (count($users) >= $limit); |
|
209 | + } |
|
210 | + $progress->finish(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * move user encryption folder to new root folder |
|
215 | + * |
|
216 | + * @param string $user |
|
217 | + * @param string $oldRoot |
|
218 | + * @param string $newRoot |
|
219 | + * @throws \Exception |
|
220 | + */ |
|
221 | + protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot) { |
|
222 | + if ($this->userManager->userExists($user)) { |
|
223 | + $source = $oldRoot . '/' . $user . '/files_encryption'; |
|
224 | + $target = $newRoot . '/' . $user . '/files_encryption'; |
|
225 | + if ( |
|
226 | + $this->rootView->is_dir($source) && |
|
227 | + $this->targetExists($target) === false |
|
228 | + ) { |
|
229 | + $this->prepareParentFolder($newRoot . '/' . $user); |
|
230 | + $this->rootView->rename($source, $target); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Make preparations to filesystem for saving a key file |
|
237 | + * |
|
238 | + * @param string $path relative to data/ |
|
239 | + */ |
|
240 | + protected function prepareParentFolder($path) { |
|
241 | + $path = Filesystem::normalizePath($path); |
|
242 | + // If the file resides within a subdirectory, create it |
|
243 | + if ($this->rootView->file_exists($path) === false) { |
|
244 | + $sub_dirs = explode('/', ltrim($path, '/')); |
|
245 | + $dir = ''; |
|
246 | + foreach ($sub_dirs as $sub_dir) { |
|
247 | + $dir .= '/' . $sub_dir; |
|
248 | + if ($this->rootView->file_exists($dir) === false) { |
|
249 | + $this->rootView->mkdir($dir); |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * check if target already exists |
|
257 | + * |
|
258 | + * @param $path |
|
259 | + * @return bool |
|
260 | + * @throws \Exception |
|
261 | + */ |
|
262 | + protected function targetExists($path) { |
|
263 | + if ($this->rootView->file_exists($path)) { |
|
264 | + throw new \Exception("new folder '$path' already exists"); |
|
265 | + } |
|
266 | + |
|
267 | + return false; |
|
268 | + } |
|
269 | 269 | } |
@@ -28,31 +28,31 @@ |
||
28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | 29 | |
30 | 30 | class Status extends Base { |
31 | - /** @var IManager */ |
|
32 | - protected $encryptionManager; |
|
31 | + /** @var IManager */ |
|
32 | + protected $encryptionManager; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param IManager $encryptionManager |
|
36 | - */ |
|
37 | - public function __construct(IManager $encryptionManager) { |
|
38 | - parent::__construct(); |
|
39 | - $this->encryptionManager = $encryptionManager; |
|
40 | - } |
|
34 | + /** |
|
35 | + * @param IManager $encryptionManager |
|
36 | + */ |
|
37 | + public function __construct(IManager $encryptionManager) { |
|
38 | + parent::__construct(); |
|
39 | + $this->encryptionManager = $encryptionManager; |
|
40 | + } |
|
41 | 41 | |
42 | - protected function configure() { |
|
43 | - parent::configure(); |
|
42 | + protected function configure() { |
|
43 | + parent::configure(); |
|
44 | 44 | |
45 | - $this |
|
46 | - ->setName('encryption:status') |
|
47 | - ->setDescription('Lists the current status of encryption') |
|
48 | - ; |
|
49 | - } |
|
45 | + $this |
|
46 | + ->setName('encryption:status') |
|
47 | + ->setDescription('Lists the current status of encryption') |
|
48 | + ; |
|
49 | + } |
|
50 | 50 | |
51 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
52 | - $this->writeArrayInOutputFormat($input, $output, [ |
|
53 | - 'enabled' => $this->encryptionManager->isEnabled(), |
|
54 | - 'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(), |
|
55 | - ]); |
|
56 | - return 0; |
|
57 | - } |
|
51 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
52 | + $this->writeArrayInOutputFormat($input, $output, [ |
|
53 | + 'enabled' => $this->encryptionManager->isEnabled(), |
|
54 | + 'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(), |
|
55 | + ]); |
|
56 | + return 0; |
|
57 | + } |
|
58 | 58 | } |
@@ -43,157 +43,157 @@ |
||
43 | 43 | |
44 | 44 | class DecryptAll extends Command { |
45 | 45 | |
46 | - /** @var IManager */ |
|
47 | - protected $encryptionManager; |
|
48 | - |
|
49 | - /** @var IAppManager */ |
|
50 | - protected $appManager; |
|
51 | - |
|
52 | - /** @var IConfig */ |
|
53 | - protected $config; |
|
54 | - |
|
55 | - /** @var QuestionHelper */ |
|
56 | - protected $questionHelper; |
|
57 | - |
|
58 | - /** @var bool */ |
|
59 | - protected $wasTrashbinEnabled; |
|
60 | - |
|
61 | - /** @var bool */ |
|
62 | - protected $wasMaintenanceModeEnabled; |
|
63 | - |
|
64 | - /** @var \OC\Encryption\DecryptAll */ |
|
65 | - protected $decryptAll; |
|
66 | - |
|
67 | - /** |
|
68 | - * @param IManager $encryptionManager |
|
69 | - * @param IAppManager $appManager |
|
70 | - * @param IConfig $config |
|
71 | - * @param \OC\Encryption\DecryptAll $decryptAll |
|
72 | - * @param QuestionHelper $questionHelper |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - IManager $encryptionManager, |
|
76 | - IAppManager $appManager, |
|
77 | - IConfig $config, |
|
78 | - \OC\Encryption\DecryptAll $decryptAll, |
|
79 | - QuestionHelper $questionHelper |
|
80 | - ) { |
|
81 | - parent::__construct(); |
|
82 | - |
|
83 | - $this->appManager = $appManager; |
|
84 | - $this->encryptionManager = $encryptionManager; |
|
85 | - $this->config = $config; |
|
86 | - $this->decryptAll = $decryptAll; |
|
87 | - $this->questionHelper = $questionHelper; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Set maintenance mode and disable the trashbin app |
|
92 | - */ |
|
93 | - protected function forceMaintenanceAndTrashbin() { |
|
94 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
95 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
96 | - $this->config->setSystemValue('maintenance', true); |
|
97 | - $this->appManager->disableApp('files_trashbin'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Reset the maintenance mode and re-enable the trashbin app |
|
102 | - */ |
|
103 | - protected function resetMaintenanceAndTrashbin() { |
|
104 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
105 | - if ($this->wasTrashbinEnabled) { |
|
106 | - $this->appManager->enableApp('files_trashbin'); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - protected function configure() { |
|
111 | - parent::configure(); |
|
112 | - |
|
113 | - $this->setName('encryption:decrypt-all'); |
|
114 | - $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
115 | - $this->setHelp( |
|
116 | - 'This will disable server-side encryption and decrypt all files for ' |
|
117 | - . 'all users if it is supported by your encryption module. ' |
|
118 | - . 'Please make sure that no user access his files during this process!' |
|
119 | - ); |
|
120 | - $this->addArgument( |
|
121 | - 'user', |
|
122 | - InputArgument::OPTIONAL, |
|
123 | - 'user for which you want to decrypt all files (optional)', |
|
124 | - '' |
|
125 | - ); |
|
126 | - } |
|
127 | - |
|
128 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
129 | - if (!$input->isInteractive()) { |
|
130 | - $output->writeln('Invalid TTY.'); |
|
131 | - $output->writeln('If you are trying to execute the command in a Docker '); |
|
132 | - $output->writeln("container, do not forget to execute 'docker exec' with"); |
|
133 | - $output->writeln("the '-i' and '-t' options."); |
|
134 | - $output->writeln(''); |
|
135 | - return 1; |
|
136 | - } |
|
137 | - |
|
138 | - $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
139 | - if ($isMaintenanceModeEnabled) { |
|
140 | - $output->writeln("Maintenance mode must be disabled when starting decryption,"); |
|
141 | - $output->writeln("in order to load the relevant encryption modules correctly."); |
|
142 | - $output->writeln("Your instance will automatically be put to maintenance mode"); |
|
143 | - $output->writeln("during the actual decryption of the files."); |
|
144 | - return 1; |
|
145 | - } |
|
146 | - |
|
147 | - try { |
|
148 | - if ($this->encryptionManager->isEnabled() === true) { |
|
149 | - $output->write('Disable server side encryption... '); |
|
150 | - $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
151 | - $output->writeln('done.'); |
|
152 | - } else { |
|
153 | - $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
154 | - return 0; |
|
155 | - } |
|
156 | - |
|
157 | - $uid = $input->getArgument('user'); |
|
158 | - if ($uid === '') { |
|
159 | - $message = 'your Nextcloud'; |
|
160 | - } else { |
|
161 | - $message = "$uid's account"; |
|
162 | - } |
|
163 | - |
|
164 | - $output->writeln("\n"); |
|
165 | - $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
166 | - $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
167 | - $output->writeln('Depending on the number and size of your files this can take some time'); |
|
168 | - $output->writeln('Please make sure that no user access his files during this process!'); |
|
169 | - $output->writeln(''); |
|
170 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
171 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
172 | - $this->forceMaintenanceAndTrashbin(); |
|
173 | - $user = $input->getArgument('user'); |
|
174 | - $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
175 | - if ($result === false) { |
|
176 | - $output->writeln(' aborted.'); |
|
177 | - $output->writeln('Server side encryption remains enabled'); |
|
178 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
179 | - } elseif ($uid !== '') { |
|
180 | - $output->writeln('Server side encryption remains enabled'); |
|
181 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
182 | - } |
|
183 | - $this->resetMaintenanceAndTrashbin(); |
|
184 | - return 0; |
|
185 | - } else { |
|
186 | - $output->write('Enable server side encryption... '); |
|
187 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
188 | - $output->writeln('done.'); |
|
189 | - $output->writeln('aborted'); |
|
190 | - return 1; |
|
191 | - } |
|
192 | - } catch (\Exception $e) { |
|
193 | - // enable server side encryption again if something went wrong |
|
194 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
195 | - $this->resetMaintenanceAndTrashbin(); |
|
196 | - throw $e; |
|
197 | - } |
|
198 | - } |
|
46 | + /** @var IManager */ |
|
47 | + protected $encryptionManager; |
|
48 | + |
|
49 | + /** @var IAppManager */ |
|
50 | + protected $appManager; |
|
51 | + |
|
52 | + /** @var IConfig */ |
|
53 | + protected $config; |
|
54 | + |
|
55 | + /** @var QuestionHelper */ |
|
56 | + protected $questionHelper; |
|
57 | + |
|
58 | + /** @var bool */ |
|
59 | + protected $wasTrashbinEnabled; |
|
60 | + |
|
61 | + /** @var bool */ |
|
62 | + protected $wasMaintenanceModeEnabled; |
|
63 | + |
|
64 | + /** @var \OC\Encryption\DecryptAll */ |
|
65 | + protected $decryptAll; |
|
66 | + |
|
67 | + /** |
|
68 | + * @param IManager $encryptionManager |
|
69 | + * @param IAppManager $appManager |
|
70 | + * @param IConfig $config |
|
71 | + * @param \OC\Encryption\DecryptAll $decryptAll |
|
72 | + * @param QuestionHelper $questionHelper |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + IManager $encryptionManager, |
|
76 | + IAppManager $appManager, |
|
77 | + IConfig $config, |
|
78 | + \OC\Encryption\DecryptAll $decryptAll, |
|
79 | + QuestionHelper $questionHelper |
|
80 | + ) { |
|
81 | + parent::__construct(); |
|
82 | + |
|
83 | + $this->appManager = $appManager; |
|
84 | + $this->encryptionManager = $encryptionManager; |
|
85 | + $this->config = $config; |
|
86 | + $this->decryptAll = $decryptAll; |
|
87 | + $this->questionHelper = $questionHelper; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Set maintenance mode and disable the trashbin app |
|
92 | + */ |
|
93 | + protected function forceMaintenanceAndTrashbin() { |
|
94 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
95 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
96 | + $this->config->setSystemValue('maintenance', true); |
|
97 | + $this->appManager->disableApp('files_trashbin'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Reset the maintenance mode and re-enable the trashbin app |
|
102 | + */ |
|
103 | + protected function resetMaintenanceAndTrashbin() { |
|
104 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
105 | + if ($this->wasTrashbinEnabled) { |
|
106 | + $this->appManager->enableApp('files_trashbin'); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + protected function configure() { |
|
111 | + parent::configure(); |
|
112 | + |
|
113 | + $this->setName('encryption:decrypt-all'); |
|
114 | + $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
115 | + $this->setHelp( |
|
116 | + 'This will disable server-side encryption and decrypt all files for ' |
|
117 | + . 'all users if it is supported by your encryption module. ' |
|
118 | + . 'Please make sure that no user access his files during this process!' |
|
119 | + ); |
|
120 | + $this->addArgument( |
|
121 | + 'user', |
|
122 | + InputArgument::OPTIONAL, |
|
123 | + 'user for which you want to decrypt all files (optional)', |
|
124 | + '' |
|
125 | + ); |
|
126 | + } |
|
127 | + |
|
128 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
129 | + if (!$input->isInteractive()) { |
|
130 | + $output->writeln('Invalid TTY.'); |
|
131 | + $output->writeln('If you are trying to execute the command in a Docker '); |
|
132 | + $output->writeln("container, do not forget to execute 'docker exec' with"); |
|
133 | + $output->writeln("the '-i' and '-t' options."); |
|
134 | + $output->writeln(''); |
|
135 | + return 1; |
|
136 | + } |
|
137 | + |
|
138 | + $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
139 | + if ($isMaintenanceModeEnabled) { |
|
140 | + $output->writeln("Maintenance mode must be disabled when starting decryption,"); |
|
141 | + $output->writeln("in order to load the relevant encryption modules correctly."); |
|
142 | + $output->writeln("Your instance will automatically be put to maintenance mode"); |
|
143 | + $output->writeln("during the actual decryption of the files."); |
|
144 | + return 1; |
|
145 | + } |
|
146 | + |
|
147 | + try { |
|
148 | + if ($this->encryptionManager->isEnabled() === true) { |
|
149 | + $output->write('Disable server side encryption... '); |
|
150 | + $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
151 | + $output->writeln('done.'); |
|
152 | + } else { |
|
153 | + $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
154 | + return 0; |
|
155 | + } |
|
156 | + |
|
157 | + $uid = $input->getArgument('user'); |
|
158 | + if ($uid === '') { |
|
159 | + $message = 'your Nextcloud'; |
|
160 | + } else { |
|
161 | + $message = "$uid's account"; |
|
162 | + } |
|
163 | + |
|
164 | + $output->writeln("\n"); |
|
165 | + $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
166 | + $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
167 | + $output->writeln('Depending on the number and size of your files this can take some time'); |
|
168 | + $output->writeln('Please make sure that no user access his files during this process!'); |
|
169 | + $output->writeln(''); |
|
170 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
171 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
172 | + $this->forceMaintenanceAndTrashbin(); |
|
173 | + $user = $input->getArgument('user'); |
|
174 | + $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
175 | + if ($result === false) { |
|
176 | + $output->writeln(' aborted.'); |
|
177 | + $output->writeln('Server side encryption remains enabled'); |
|
178 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
179 | + } elseif ($uid !== '') { |
|
180 | + $output->writeln('Server side encryption remains enabled'); |
|
181 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
182 | + } |
|
183 | + $this->resetMaintenanceAndTrashbin(); |
|
184 | + return 0; |
|
185 | + } else { |
|
186 | + $output->write('Enable server side encryption... '); |
|
187 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
188 | + $output->writeln('done.'); |
|
189 | + $output->writeln('aborted'); |
|
190 | + return 1; |
|
191 | + } |
|
192 | + } catch (\Exception $e) { |
|
193 | + // enable server side encryption again if something went wrong |
|
194 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
195 | + $this->resetMaintenanceAndTrashbin(); |
|
196 | + throw $e; |
|
197 | + } |
|
198 | + } |
|
199 | 199 | } |
@@ -30,55 +30,55 @@ |
||
30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 31 | |
32 | 32 | class Enable extends Command { |
33 | - /** @var IConfig */ |
|
34 | - protected $config; |
|
33 | + /** @var IConfig */ |
|
34 | + protected $config; |
|
35 | 35 | |
36 | - /** @var IManager */ |
|
37 | - protected $encryptionManager; |
|
36 | + /** @var IManager */ |
|
37 | + protected $encryptionManager; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param IConfig $config |
|
41 | - * @param IManager $encryptionManager |
|
42 | - */ |
|
43 | - public function __construct(IConfig $config, IManager $encryptionManager) { |
|
44 | - parent::__construct(); |
|
39 | + /** |
|
40 | + * @param IConfig $config |
|
41 | + * @param IManager $encryptionManager |
|
42 | + */ |
|
43 | + public function __construct(IConfig $config, IManager $encryptionManager) { |
|
44 | + parent::__construct(); |
|
45 | 45 | |
46 | - $this->encryptionManager = $encryptionManager; |
|
47 | - $this->config = $config; |
|
48 | - } |
|
46 | + $this->encryptionManager = $encryptionManager; |
|
47 | + $this->config = $config; |
|
48 | + } |
|
49 | 49 | |
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('encryption:enable') |
|
53 | - ->setDescription('Enable encryption') |
|
54 | - ; |
|
55 | - } |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('encryption:enable') |
|
53 | + ->setDescription('Enable encryption') |
|
54 | + ; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
58 | - if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') { |
|
59 | - $output->writeln('Encryption is already enabled'); |
|
60 | - } else { |
|
61 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
62 | - $output->writeln('<info>Encryption enabled</info>'); |
|
63 | - } |
|
64 | - $output->writeln(''); |
|
57 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
58 | + if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') { |
|
59 | + $output->writeln('Encryption is already enabled'); |
|
60 | + } else { |
|
61 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
62 | + $output->writeln('<info>Encryption enabled</info>'); |
|
63 | + } |
|
64 | + $output->writeln(''); |
|
65 | 65 | |
66 | - $modules = $this->encryptionManager->getEncryptionModules(); |
|
67 | - if (empty($modules)) { |
|
68 | - $output->writeln('<error>No encryption module is loaded</error>'); |
|
69 | - return 1; |
|
70 | - } else { |
|
71 | - $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null); |
|
72 | - if ($defaultModule === null) { |
|
73 | - $output->writeln('<error>No default module is set</error>'); |
|
74 | - return 1; |
|
75 | - } elseif (!isset($modules[$defaultModule])) { |
|
76 | - $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>'); |
|
77 | - return 1; |
|
78 | - } else { |
|
79 | - $output->writeln('Default module: ' . $defaultModule); |
|
80 | - } |
|
81 | - } |
|
82 | - return 0; |
|
83 | - } |
|
66 | + $modules = $this->encryptionManager->getEncryptionModules(); |
|
67 | + if (empty($modules)) { |
|
68 | + $output->writeln('<error>No encryption module is loaded</error>'); |
|
69 | + return 1; |
|
70 | + } else { |
|
71 | + $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null); |
|
72 | + if ($defaultModule === null) { |
|
73 | + $output->writeln('<error>No default module is set</error>'); |
|
74 | + return 1; |
|
75 | + } elseif (!isset($modules[$defaultModule])) { |
|
76 | + $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>'); |
|
77 | + return 1; |
|
78 | + } else { |
|
79 | + $output->writeln('Default module: ' . $defaultModule); |
|
80 | + } |
|
81 | + } |
|
82 | + return 0; |
|
83 | + } |
|
84 | 84 | } |
@@ -73,10 +73,10 @@ |
||
73 | 73 | $output->writeln('<error>No default module is set</error>'); |
74 | 74 | return 1; |
75 | 75 | } elseif (!isset($modules[$defaultModule])) { |
76 | - $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>'); |
|
76 | + $output->writeln('<error>The current default module does not exist: '.$defaultModule.'</error>'); |
|
77 | 77 | return 1; |
78 | 78 | } else { |
79 | - $output->writeln('Default module: ' . $defaultModule); |
|
79 | + $output->writeln('Default module: '.$defaultModule); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | return 0; |
@@ -38,111 +38,111 @@ |
||
38 | 38 | |
39 | 39 | class EncryptAll extends Command { |
40 | 40 | |
41 | - /** @var IManager */ |
|
42 | - protected $encryptionManager; |
|
43 | - |
|
44 | - /** @var IAppManager */ |
|
45 | - protected $appManager; |
|
46 | - |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - |
|
50 | - /** @var QuestionHelper */ |
|
51 | - protected $questionHelper; |
|
52 | - |
|
53 | - /** @var bool */ |
|
54 | - protected $wasTrashbinEnabled; |
|
55 | - |
|
56 | - /** @var bool */ |
|
57 | - protected $wasMaintenanceModeEnabled; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IManager $encryptionManager |
|
61 | - * @param IAppManager $appManager |
|
62 | - * @param IConfig $config |
|
63 | - * @param QuestionHelper $questionHelper |
|
64 | - */ |
|
65 | - public function __construct( |
|
66 | - IManager $encryptionManager, |
|
67 | - IAppManager $appManager, |
|
68 | - IConfig $config, |
|
69 | - QuestionHelper $questionHelper |
|
70 | - ) { |
|
71 | - parent::__construct(); |
|
72 | - $this->appManager = $appManager; |
|
73 | - $this->encryptionManager = $encryptionManager; |
|
74 | - $this->config = $config; |
|
75 | - $this->questionHelper = $questionHelper; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Set maintenance mode and disable the trashbin app |
|
80 | - */ |
|
81 | - protected function forceMaintenanceAndTrashbin() { |
|
82 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
83 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
84 | - $this->config->setSystemValue('maintenance', true); |
|
85 | - $this->appManager->disableApp('files_trashbin'); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Reset the maintenance mode and re-enable the trashbin app |
|
90 | - */ |
|
91 | - protected function resetMaintenanceAndTrashbin() { |
|
92 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
93 | - if ($this->wasTrashbinEnabled) { |
|
94 | - $this->appManager->enableApp('files_trashbin'); |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - protected function configure() { |
|
99 | - parent::configure(); |
|
100 | - |
|
101 | - $this->setName('encryption:encrypt-all'); |
|
102 | - $this->setDescription('Encrypt all files for all users'); |
|
103 | - $this->setHelp( |
|
104 | - 'This will encrypt all files for all users. ' |
|
105 | - . 'Please make sure that no user access his files during this process!' |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
110 | - if (!$input->isInteractive()) { |
|
111 | - $output->writeln('Invalid TTY.'); |
|
112 | - $output->writeln('If you are trying to execute the command in a Docker '); |
|
113 | - $output->writeln("container, do not forget to execute 'docker exec' with"); |
|
114 | - $output->writeln("the '-i' and '-t' options."); |
|
115 | - $output->writeln(''); |
|
116 | - return 1; |
|
117 | - } |
|
118 | - |
|
119 | - if ($this->encryptionManager->isEnabled() === false) { |
|
120 | - throw new \Exception('Server side encryption is not enabled'); |
|
121 | - } |
|
122 | - |
|
123 | - $output->writeln("\n"); |
|
124 | - $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); |
|
125 | - $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); |
|
126 | - $output->writeln('Please ensure that no user accesses their files during this time!'); |
|
127 | - $output->writeln('Note: The encryption module you use determines which files get encrypted.'); |
|
128 | - $output->writeln(''); |
|
129 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
130 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
131 | - $this->forceMaintenanceAndTrashbin(); |
|
132 | - |
|
133 | - try { |
|
134 | - $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
135 | - $defaultModule->encryptAll($input, $output); |
|
136 | - } catch (\Exception $ex) { |
|
137 | - $this->resetMaintenanceAndTrashbin(); |
|
138 | - throw $ex; |
|
139 | - } |
|
140 | - |
|
141 | - $this->resetMaintenanceAndTrashbin(); |
|
142 | - } else { |
|
143 | - $output->writeln('aborted'); |
|
144 | - return 1; |
|
145 | - } |
|
146 | - return 0; |
|
147 | - } |
|
41 | + /** @var IManager */ |
|
42 | + protected $encryptionManager; |
|
43 | + |
|
44 | + /** @var IAppManager */ |
|
45 | + protected $appManager; |
|
46 | + |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + |
|
50 | + /** @var QuestionHelper */ |
|
51 | + protected $questionHelper; |
|
52 | + |
|
53 | + /** @var bool */ |
|
54 | + protected $wasTrashbinEnabled; |
|
55 | + |
|
56 | + /** @var bool */ |
|
57 | + protected $wasMaintenanceModeEnabled; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IManager $encryptionManager |
|
61 | + * @param IAppManager $appManager |
|
62 | + * @param IConfig $config |
|
63 | + * @param QuestionHelper $questionHelper |
|
64 | + */ |
|
65 | + public function __construct( |
|
66 | + IManager $encryptionManager, |
|
67 | + IAppManager $appManager, |
|
68 | + IConfig $config, |
|
69 | + QuestionHelper $questionHelper |
|
70 | + ) { |
|
71 | + parent::__construct(); |
|
72 | + $this->appManager = $appManager; |
|
73 | + $this->encryptionManager = $encryptionManager; |
|
74 | + $this->config = $config; |
|
75 | + $this->questionHelper = $questionHelper; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Set maintenance mode and disable the trashbin app |
|
80 | + */ |
|
81 | + protected function forceMaintenanceAndTrashbin() { |
|
82 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
83 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); |
|
84 | + $this->config->setSystemValue('maintenance', true); |
|
85 | + $this->appManager->disableApp('files_trashbin'); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Reset the maintenance mode and re-enable the trashbin app |
|
90 | + */ |
|
91 | + protected function resetMaintenanceAndTrashbin() { |
|
92 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
93 | + if ($this->wasTrashbinEnabled) { |
|
94 | + $this->appManager->enableApp('files_trashbin'); |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + protected function configure() { |
|
99 | + parent::configure(); |
|
100 | + |
|
101 | + $this->setName('encryption:encrypt-all'); |
|
102 | + $this->setDescription('Encrypt all files for all users'); |
|
103 | + $this->setHelp( |
|
104 | + 'This will encrypt all files for all users. ' |
|
105 | + . 'Please make sure that no user access his files during this process!' |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
110 | + if (!$input->isInteractive()) { |
|
111 | + $output->writeln('Invalid TTY.'); |
|
112 | + $output->writeln('If you are trying to execute the command in a Docker '); |
|
113 | + $output->writeln("container, do not forget to execute 'docker exec' with"); |
|
114 | + $output->writeln("the '-i' and '-t' options."); |
|
115 | + $output->writeln(''); |
|
116 | + return 1; |
|
117 | + } |
|
118 | + |
|
119 | + if ($this->encryptionManager->isEnabled() === false) { |
|
120 | + throw new \Exception('Server side encryption is not enabled'); |
|
121 | + } |
|
122 | + |
|
123 | + $output->writeln("\n"); |
|
124 | + $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.'); |
|
125 | + $output->writeln('Depending on the number of available files, and their size, this may take quite some time.'); |
|
126 | + $output->writeln('Please ensure that no user accesses their files during this time!'); |
|
127 | + $output->writeln('Note: The encryption module you use determines which files get encrypted.'); |
|
128 | + $output->writeln(''); |
|
129 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
130 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
131 | + $this->forceMaintenanceAndTrashbin(); |
|
132 | + |
|
133 | + try { |
|
134 | + $defaultModule = $this->encryptionManager->getEncryptionModule(); |
|
135 | + $defaultModule->encryptAll($input, $output); |
|
136 | + } catch (\Exception $ex) { |
|
137 | + $this->resetMaintenanceAndTrashbin(); |
|
138 | + throw $ex; |
|
139 | + } |
|
140 | + |
|
141 | + $this->resetMaintenanceAndTrashbin(); |
|
142 | + } else { |
|
143 | + $output->writeln('aborted'); |
|
144 | + return 1; |
|
145 | + } |
|
146 | + return 0; |
|
147 | + } |
|
148 | 148 | } |
@@ -31,70 +31,70 @@ |
||
31 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
32 | 32 | |
33 | 33 | class ListModules extends Base { |
34 | - /** @var IManager */ |
|
35 | - protected $encryptionManager; |
|
34 | + /** @var IManager */ |
|
35 | + protected $encryptionManager; |
|
36 | 36 | |
37 | - /** @var IConfig */ |
|
38 | - protected $config; |
|
37 | + /** @var IConfig */ |
|
38 | + protected $config; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param IManager $encryptionManager |
|
42 | - * @param IConfig $config |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - IManager $encryptionManager, |
|
46 | - IConfig $config |
|
47 | - ) { |
|
48 | - parent::__construct(); |
|
49 | - $this->encryptionManager = $encryptionManager; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param IManager $encryptionManager |
|
42 | + * @param IConfig $config |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + IManager $encryptionManager, |
|
46 | + IConfig $config |
|
47 | + ) { |
|
48 | + parent::__construct(); |
|
49 | + $this->encryptionManager = $encryptionManager; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | 52 | |
53 | - protected function configure() { |
|
54 | - parent::configure(); |
|
53 | + protected function configure() { |
|
54 | + parent::configure(); |
|
55 | 55 | |
56 | - $this |
|
57 | - ->setName('encryption:list-modules') |
|
58 | - ->setDescription('List all available encryption modules') |
|
59 | - ; |
|
60 | - } |
|
56 | + $this |
|
57 | + ->setName('encryption:list-modules') |
|
58 | + ->setDescription('List all available encryption modules') |
|
59 | + ; |
|
60 | + } |
|
61 | 61 | |
62 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | - $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
64 | - if ($isMaintenanceModeEnabled) { |
|
65 | - $output->writeln("Maintenance mode must be disabled when listing modules"); |
|
66 | - $output->writeln("in order to list the relevant encryption modules correctly."); |
|
67 | - return 1; |
|
68 | - } |
|
62 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | + $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
64 | + if ($isMaintenanceModeEnabled) { |
|
65 | + $output->writeln("Maintenance mode must be disabled when listing modules"); |
|
66 | + $output->writeln("in order to list the relevant encryption modules correctly."); |
|
67 | + return 1; |
|
68 | + } |
|
69 | 69 | |
70 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
71 | - $defaultEncryptionModuleId = $this->encryptionManager->getDefaultEncryptionModuleId(); |
|
70 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
71 | + $defaultEncryptionModuleId = $this->encryptionManager->getDefaultEncryptionModuleId(); |
|
72 | 72 | |
73 | - $encModules = []; |
|
74 | - foreach ($encryptionModules as $module) { |
|
75 | - $encModules[$module['id']]['displayName'] = $module['displayName']; |
|
76 | - $encModules[$module['id']]['default'] = $module['id'] === $defaultEncryptionModuleId; |
|
77 | - } |
|
78 | - $this->writeModuleList($input, $output, $encModules); |
|
79 | - return 0; |
|
80 | - } |
|
73 | + $encModules = []; |
|
74 | + foreach ($encryptionModules as $module) { |
|
75 | + $encModules[$module['id']]['displayName'] = $module['displayName']; |
|
76 | + $encModules[$module['id']]['default'] = $module['id'] === $defaultEncryptionModuleId; |
|
77 | + } |
|
78 | + $this->writeModuleList($input, $output, $encModules); |
|
79 | + return 0; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param InputInterface $input |
|
84 | - * @param OutputInterface $output |
|
85 | - * @param array $items |
|
86 | - */ |
|
87 | - protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { |
|
88 | - if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
89 | - array_walk($items, function (&$item) { |
|
90 | - if (!$item['default']) { |
|
91 | - $item = $item['displayName']; |
|
92 | - } else { |
|
93 | - $item = $item['displayName'] . ' [default*]'; |
|
94 | - } |
|
95 | - }); |
|
96 | - } |
|
82 | + /** |
|
83 | + * @param InputInterface $input |
|
84 | + * @param OutputInterface $output |
|
85 | + * @param array $items |
|
86 | + */ |
|
87 | + protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { |
|
88 | + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
89 | + array_walk($items, function (&$item) { |
|
90 | + if (!$item['default']) { |
|
91 | + $item = $item['displayName']; |
|
92 | + } else { |
|
93 | + $item = $item['displayName'] . ' [default*]'; |
|
94 | + } |
|
95 | + }); |
|
96 | + } |
|
97 | 97 | |
98 | - $this->writeArrayInOutputFormat($input, $output, $items); |
|
99 | - } |
|
98 | + $this->writeArrayInOutputFormat($input, $output, $items); |
|
99 | + } |
|
100 | 100 | } |
@@ -32,57 +32,57 @@ |
||
32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
33 | 33 | |
34 | 34 | class SetDefaultModule extends Command { |
35 | - /** @var IManager */ |
|
36 | - protected $encryptionManager; |
|
35 | + /** @var IManager */ |
|
36 | + protected $encryptionManager; |
|
37 | 37 | |
38 | - /** @var IConfig */ |
|
39 | - protected $config; |
|
38 | + /** @var IConfig */ |
|
39 | + protected $config; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IManager $encryptionManager |
|
43 | - * @param IConfig $config |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - IManager $encryptionManager, |
|
47 | - IConfig $config |
|
48 | - ) { |
|
49 | - parent::__construct(); |
|
50 | - $this->encryptionManager = $encryptionManager; |
|
51 | - $this->config = $config; |
|
52 | - } |
|
41 | + /** |
|
42 | + * @param IManager $encryptionManager |
|
43 | + * @param IConfig $config |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + IManager $encryptionManager, |
|
47 | + IConfig $config |
|
48 | + ) { |
|
49 | + parent::__construct(); |
|
50 | + $this->encryptionManager = $encryptionManager; |
|
51 | + $this->config = $config; |
|
52 | + } |
|
53 | 53 | |
54 | - protected function configure() { |
|
55 | - parent::configure(); |
|
54 | + protected function configure() { |
|
55 | + parent::configure(); |
|
56 | 56 | |
57 | - $this |
|
58 | - ->setName('encryption:set-default-module') |
|
59 | - ->setDescription('Set the encryption default module') |
|
60 | - ->addArgument( |
|
61 | - 'module', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'ID of the encryption module that should be used' |
|
64 | - ) |
|
65 | - ; |
|
66 | - } |
|
57 | + $this |
|
58 | + ->setName('encryption:set-default-module') |
|
59 | + ->setDescription('Set the encryption default module') |
|
60 | + ->addArgument( |
|
61 | + 'module', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'ID of the encryption module that should be used' |
|
64 | + ) |
|
65 | + ; |
|
66 | + } |
|
67 | 67 | |
68 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
69 | - $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
70 | - if ($isMaintenanceModeEnabled) { |
|
71 | - $output->writeln("Maintenance mode must be disabled when setting default module,"); |
|
72 | - $output->writeln("in order to load the relevant encryption modules correctly."); |
|
73 | - return 1; |
|
74 | - } |
|
68 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
69 | + $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
70 | + if ($isMaintenanceModeEnabled) { |
|
71 | + $output->writeln("Maintenance mode must be disabled when setting default module,"); |
|
72 | + $output->writeln("in order to load the relevant encryption modules correctly."); |
|
73 | + return 1; |
|
74 | + } |
|
75 | 75 | |
76 | - $moduleId = $input->getArgument('module'); |
|
76 | + $moduleId = $input->getArgument('module'); |
|
77 | 77 | |
78 | - if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) { |
|
79 | - $output->writeln('"' . $moduleId . '"" is already the default module'); |
|
80 | - } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) { |
|
81 | - $output->writeln('<info>Set default module to "' . $moduleId . '"</info>'); |
|
82 | - } else { |
|
83 | - $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>'); |
|
84 | - return 1; |
|
85 | - } |
|
86 | - return 0; |
|
87 | - } |
|
78 | + if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) { |
|
79 | + $output->writeln('"' . $moduleId . '"" is already the default module'); |
|
80 | + } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) { |
|
81 | + $output->writeln('<info>Set default module to "' . $moduleId . '"</info>'); |
|
82 | + } else { |
|
83 | + $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>'); |
|
84 | + return 1; |
|
85 | + } |
|
86 | + return 0; |
|
87 | + } |
|
88 | 88 | } |
@@ -76,11 +76,11 @@ |
||
76 | 76 | $moduleId = $input->getArgument('module'); |
77 | 77 | |
78 | 78 | if ($moduleId === $this->encryptionManager->getDefaultEncryptionModuleId()) { |
79 | - $output->writeln('"' . $moduleId . '"" is already the default module'); |
|
79 | + $output->writeln('"'.$moduleId.'"" is already the default module'); |
|
80 | 80 | } elseif ($this->encryptionManager->setDefaultEncryptionModule($moduleId)) { |
81 | - $output->writeln('<info>Set default module to "' . $moduleId . '"</info>'); |
|
81 | + $output->writeln('<info>Set default module to "'.$moduleId.'"</info>'); |
|
82 | 82 | } else { |
83 | - $output->writeln('<error>The specified module "' . $moduleId . '" does not exist</error>'); |
|
83 | + $output->writeln('<error>The specified module "'.$moduleId.'" does not exist</error>'); |
|
84 | 84 | return 1; |
85 | 85 | } |
86 | 86 | return 0; |
@@ -31,35 +31,35 @@ |
||
31 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
32 | 32 | |
33 | 33 | class Check extends Base { |
34 | - /** |
|
35 | - * @var SystemConfig |
|
36 | - */ |
|
37 | - private $config; |
|
34 | + /** |
|
35 | + * @var SystemConfig |
|
36 | + */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - public function __construct(SystemConfig $config) { |
|
40 | - parent::__construct(); |
|
41 | - $this->config = $config; |
|
42 | - } |
|
39 | + public function __construct(SystemConfig $config) { |
|
40 | + parent::__construct(); |
|
41 | + $this->config = $config; |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - parent::configure(); |
|
44 | + protected function configure() { |
|
45 | + parent::configure(); |
|
46 | 46 | |
47 | - $this |
|
48 | - ->setName('check') |
|
49 | - ->setDescription('check dependencies of the server environment') |
|
50 | - ; |
|
51 | - } |
|
47 | + $this |
|
48 | + ->setName('check') |
|
49 | + ->setDescription('check dependencies of the server environment') |
|
50 | + ; |
|
51 | + } |
|
52 | 52 | |
53 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
54 | - $errors = \OC_Util::checkServer($this->config); |
|
55 | - if (!empty($errors)) { |
|
56 | - $errors = array_map(function ($item) { |
|
57 | - return (string) $item['error']; |
|
58 | - }, $errors); |
|
53 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
54 | + $errors = \OC_Util::checkServer($this->config); |
|
55 | + if (!empty($errors)) { |
|
56 | + $errors = array_map(function ($item) { |
|
57 | + return (string) $item['error']; |
|
58 | + }, $errors); |
|
59 | 59 | |
60 | - $this->writeArrayInOutputFormat($input, $output, $errors); |
|
61 | - return 1; |
|
62 | - } |
|
63 | - return 0; |
|
64 | - } |
|
60 | + $this->writeArrayInOutputFormat($input, $output, $errors); |
|
61 | + return 1; |
|
62 | + } |
|
63 | + return 0; |
|
64 | + } |
|
65 | 65 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | protected function execute(InputInterface $input, OutputInterface $output): int { |
54 | 54 | $errors = \OC_Util::checkServer($this->config); |
55 | 55 | if (!empty($errors)) { |
56 | - $errors = array_map(function ($item) { |
|
56 | + $errors = array_map(function($item) { |
|
57 | 57 | return (string) $item['error']; |
58 | 58 | }, $errors); |
59 | 59 |
@@ -35,67 +35,67 @@ |
||
35 | 35 | |
36 | 36 | class Test extends Command { |
37 | 37 | |
38 | - /** @var IEventDispatcher */ |
|
39 | - private $eventDispatcher; |
|
40 | - |
|
41 | - public function __construct(IEventDispatcher $eventDispatcher) { |
|
42 | - parent::__construct(); |
|
43 | - $this->eventDispatcher = $eventDispatcher; |
|
44 | - } |
|
45 | - |
|
46 | - protected function configure(): void { |
|
47 | - $this |
|
48 | - ->setName('broadcast:test') |
|
49 | - ->setDescription('test the SSE broadcaster') |
|
50 | - ->addArgument( |
|
51 | - 'uid', |
|
52 | - InputArgument::REQUIRED, |
|
53 | - 'the UID of the users to receive the event' |
|
54 | - ) |
|
55 | - ->addArgument( |
|
56 | - 'name', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'the event name', |
|
59 | - 'test' |
|
60 | - ); |
|
61 | - } |
|
62 | - |
|
63 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | - $name = $input->getArgument('name'); |
|
65 | - $uid = $input->getArgument('uid'); |
|
66 | - |
|
67 | - $event = new class($name, $uid) extends ABroadcastedEvent { |
|
68 | - /** @var string */ |
|
69 | - private $name; |
|
70 | - /** @var string */ |
|
71 | - private $uid; |
|
72 | - |
|
73 | - public function __construct(string $name, |
|
74 | - string $uid) { |
|
75 | - parent::__construct(); |
|
76 | - $this->name = $name; |
|
77 | - $this->uid = $uid; |
|
78 | - } |
|
79 | - |
|
80 | - public function broadcastAs(): string { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - public function getUids(): array { |
|
85 | - return [ |
|
86 | - $this->uid, |
|
87 | - ]; |
|
88 | - } |
|
89 | - |
|
90 | - public function jsonSerialize() { |
|
91 | - return [ |
|
92 | - 'description' => 'this is a test event', |
|
93 | - ]; |
|
94 | - } |
|
95 | - }; |
|
96 | - |
|
97 | - $this->eventDispatcher->dispatch('broadcasttest', $event); |
|
98 | - |
|
99 | - return 0; |
|
100 | - } |
|
38 | + /** @var IEventDispatcher */ |
|
39 | + private $eventDispatcher; |
|
40 | + |
|
41 | + public function __construct(IEventDispatcher $eventDispatcher) { |
|
42 | + parent::__construct(); |
|
43 | + $this->eventDispatcher = $eventDispatcher; |
|
44 | + } |
|
45 | + |
|
46 | + protected function configure(): void { |
|
47 | + $this |
|
48 | + ->setName('broadcast:test') |
|
49 | + ->setDescription('test the SSE broadcaster') |
|
50 | + ->addArgument( |
|
51 | + 'uid', |
|
52 | + InputArgument::REQUIRED, |
|
53 | + 'the UID of the users to receive the event' |
|
54 | + ) |
|
55 | + ->addArgument( |
|
56 | + 'name', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'the event name', |
|
59 | + 'test' |
|
60 | + ); |
|
61 | + } |
|
62 | + |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
64 | + $name = $input->getArgument('name'); |
|
65 | + $uid = $input->getArgument('uid'); |
|
66 | + |
|
67 | + $event = new class($name, $uid) extends ABroadcastedEvent { |
|
68 | + /** @var string */ |
|
69 | + private $name; |
|
70 | + /** @var string */ |
|
71 | + private $uid; |
|
72 | + |
|
73 | + public function __construct(string $name, |
|
74 | + string $uid) { |
|
75 | + parent::__construct(); |
|
76 | + $this->name = $name; |
|
77 | + $this->uid = $uid; |
|
78 | + } |
|
79 | + |
|
80 | + public function broadcastAs(): string { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + public function getUids(): array { |
|
85 | + return [ |
|
86 | + $this->uid, |
|
87 | + ]; |
|
88 | + } |
|
89 | + |
|
90 | + public function jsonSerialize() { |
|
91 | + return [ |
|
92 | + 'description' => 'this is a test event', |
|
93 | + ]; |
|
94 | + } |
|
95 | + }; |
|
96 | + |
|
97 | + $this->eventDispatcher->dispatch('broadcasttest', $event); |
|
98 | + |
|
99 | + return 0; |
|
100 | + } |
|
101 | 101 | } |