add recovery key to all files if the user enabled the feature and removes them again on disable
This commit is contained in:
parent
1a31dc036a
commit
57c0a7ed69
3 changed files with 42 additions and 1 deletions
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue