parent
4550ae6a69
commit
aae9b0b1bf
|
@ -168,11 +168,25 @@ class Hooks {
|
|||
*/
|
||||
public static function postShared( $params ) {
|
||||
|
||||
// NOTE: $params is an array with these keys:
|
||||
// NOTE: $params has keys:
|
||||
// [itemType] => file
|
||||
// itemSource -> int, filecache file ID
|
||||
// [parent] =>
|
||||
// [itemTarget] => /13
|
||||
// shareWith -> string, uid of user being shared to
|
||||
// fileTarget -> path of file being shared
|
||||
// uidOwner -> owner of the original file being shared
|
||||
// [shareType] => 0
|
||||
// [shareWith] => test1
|
||||
// [uidOwner] => admin
|
||||
// [permissions] => 17
|
||||
// [fileSource] => 13
|
||||
// [fileTarget] => /test8
|
||||
// [id] => 10
|
||||
// [token] =>
|
||||
|
||||
// TODO: Should other kinds of item be encrypted too?
|
||||
if ( $params['itemType'] === 'file' ) {
|
||||
|
||||
$view = new \OC_FilesystemView( '/' );
|
||||
$session = new Session();
|
||||
|
@ -209,18 +223,52 @@ class Hooks {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
public static function postUnshare( $params ) {
|
||||
|
||||
// $view = new \OC_FilesystemView( '/' );
|
||||
// $session = new Session();
|
||||
// $userId = \OCP\User::getUser();
|
||||
// $util = new Util( $view, $userId );
|
||||
// $path = $util->fileIdToPath( $params['itemSource'] );
|
||||
//
|
||||
// return Crypt::updateKeyfile( $view, $util, $session, $userId, $path );
|
||||
// NOTE: $params has keys:
|
||||
// [itemType] => file
|
||||
// [itemSource] => 13
|
||||
// [shareType] => 0
|
||||
// [shareWith] => test1
|
||||
|
||||
// TODO: Should other kinds of item be encrypted too?
|
||||
if ( $params['itemType'] === 'file' ) {
|
||||
|
||||
$view = new \OC_FilesystemView( '/' );
|
||||
$session = new Session();
|
||||
$userId = \OCP\User::getUser();
|
||||
$util = new Util( $view, $userId );
|
||||
$path = $util->fileIdToPath( $params['itemSource'] );
|
||||
|
||||
$allPaths = $util->getPaths( $path );
|
||||
|
||||
foreach ( $allPaths as $path ) {
|
||||
|
||||
if ( ! Keymanager::delShareKey( $view, $userId, $path ) ) {
|
||||
|
||||
$failed[] = $path;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If no attempts to set keyfiles failed
|
||||
if ( empty( $failed ) ) {
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -350,6 +350,30 @@ class Keymanager {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a single user's shareKey for a single file
|
||||
*/
|
||||
public static function delShareKey( \OC_FilesystemView $view, $userId, $filePath ) {
|
||||
|
||||
$trimmed = ltrim( $filePath, '/' );
|
||||
$shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $trimmed . '.shareKey';
|
||||
|
||||
// Unlink doesn't tell us if file was deleted (not found returns
|
||||
// true), so we perform our own test
|
||||
if ( $view->file_exists( $shareKeyPath ) ) {
|
||||
|
||||
return $view->unlink( $shareKeyPath );
|
||||
|
||||
} else {
|
||||
|
||||
\OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath, \OC_Log::ERROR );
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make preparations to vars and filesystem for saving a keyfile
|
||||
*/
|
||||
|
|
|
@ -580,7 +580,8 @@ class Util {
|
|||
* @brief Expand given path to all sub files & folders
|
||||
* @param Session $session
|
||||
* @param string $path path which needs to be updated
|
||||
* @return bool outcome of attempt to set keyfiles
|
||||
* @return array $pathsArray all found file paths
|
||||
* @note Paths of directories excluded, only *file* paths are returned
|
||||
*/
|
||||
public function getPaths( $path ) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue