diff --git a/apps/files_encryption/ajax/userrecovery.php b/apps/files_encryption/ajax/userrecovery.php index 85a799011d7d4733f9849e2989dd8c3ec46c4c9a..1f42b376e422f0a044a22ce0dcd2d9d7af3eff85 100644 --- a/apps/files_encryption/ajax/userrecovery.php +++ b/apps/files_encryption/ajax/userrecovery.php @@ -24,6 +24,12 @@ if ( // Save recovery preference to DB $return = $util->setRecoveryForUser( $_POST['userEnableRecovery'] ); + + if ($_POST['userEnableRecovery'] == "1") { + $util->addRecoveryKeys(); + } else { + $util->removeRecoveryKeys(); + } } else { diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 6cb4ccb808501ef9705ef88ca874878f2979ecf9..6eee1ada8a873ee1e68138c25cbacf94f0c78ae1 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1310,4 +1310,38 @@ class Util { return $this->recoveryKeyId; } + /** + * @brief add recovery key to all encrypted files + */ + public function addRecoveryKeys($path = '/') { + $dirContent = $this->view->getDirectoryContent($this->keyfilesPath.$path); + foreach ($dirContent as $item) { + $filePath = substr($item['path'], 25); + if ($item['type'] == 'dir') { + $this->addRecoveryKey($filePath.'/'); + } else { + $session = new Session(new \OC_FilesystemView('/')); + $sharingEnabled = \OCP\Share::isEnabled(); + $file = substr($filePath, 0, -4); + $usersSharing = $this->getSharingUsersArray($sharingEnabled, $file); + $this->setSharedFileKeyfiles( $session, $usersSharing, $file ); + } + } + } + + /** + * @brief remove recovery key to all encrypted files + */ + public function removeRecoveryKeys($path = '/') { + $dirContent = $this->view->getDirectoryContent($this->keyfilesPath.$path); + foreach ($dirContent as $item) { + $filePath = substr($item['path'], 25); + if ($item['type'] == 'dir') { + $this->removeRecoveryKeys($filePath.'/'); + } else { + $file = substr($filePath, 0, -4); + $this->view->unlink($this->shareKeysPath.'/'.$file.'.'.$this->recoveryKeyId.'.shareKey'); + } + } + } } diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php index 00f567ecb2665c085453e2ebe5f520675b7691f4..33989416d33de4f4666ad69da9e8636f72ff49d2 100644 --- a/apps/files_encryption/templates/settings-personal.php +++ b/apps/files_encryption/templates/settings-personal.php @@ -48,6 +48,7 @@ </p> <?php endif; ?> <br /> +<!-- <p> <label for="encryptAll"><?php p( $l->t( "Scan for unencrypted files and encrypt them" ) ); ?></label> <br /> @@ -59,6 +60,6 @@ <div id="encryptAllSuccess"><?php p( $l->t( 'Scan complete' ) );?></div> <div id="encryptAllError"><?php p( $l->t( 'Unable to scan and encrypt files' ) );?></div> </p> - +--> </fieldset> </form>