// Check if sharing is enabled\r
if ( OC_App::isEnabled( 'files_sharing' ) ) {\r
\r
-// // Check if file was shared with other users\r
-// $query = \OC_DB::prepare( "\r
-// SELECT \r
-// uid_owner\r
-// , source\r
-// , target\r
-// , uid_shared_with \r
-// FROM \r
-// `*PREFIX*sharing` \r
-// WHERE \r
-// ( target = ? AND uid_shared_with = ? ) \r
-// OR source = ? \r
-// " );\r
-// \r
-// $result = $query->execute( array ( $filepath, $userId, $filepath ) );\r
-// \r
-// $users = array();\r
-// \r
-// if ( $row = $result->fetchRow() ) \r
-// {\r
-// $source = $row['source'];\r
-// $owner = $row['uid_owner'];\r
-// $users[] = $owner;\r
-// // get the uids of all user with access to the file\r
-// $query = \OC_DB::prepare( "SELECT source, uid_shared_with FROM `*PREFIX*sharing` WHERE source = ?" );\r
-// $result = $query->execute( array ($source));\r
-// while ( ($row = $result->fetchRow()) ) {\r
-// $users[] = $row['uid_shared_with'];\r
-// \r
-// }\r
-// \r
-// }\r
+\r
\r
} else {\r
\r
\r
$targetPath = self::keySetPreparation( $view, $path, $basePath, $userId );\r
\r
-// // update $keytarget and $userId if key belongs to a file shared by someone else\r
-// $query = $dbClassName::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );\r
-// \r
-// $result = $query->execute( array ( '/'.$userId.'/files/'.$targetPath, $userId ) );\r
-// \r
-// if ( $row = $result->fetchRow( ) ) {\r
-// \r
-// $targetPath = $row['source'];\r
-// \r
-// $targetPath_parts = explode( '/', $targetPath );\r
-// \r
-// $userId = $targetPath_parts[1];\r
-// \r
-// $rootview = new \OC_FilesystemView( '/' );\r
-// \r
-// if ( ! $rootview->is_writable( $targetPath ) ) {\r
-// \r
-// \OC_Log::write( 'Encryption library', "File Key not updated because you don't have write access for the corresponding file", \OC_Log::ERROR );\r
-// \r
-// return false;\r
-// \r
-// }\r
-// \r
-// $targetPath = str_replace( '/'.$userId.'/files/', '', $targetPath );\r
-// \r
-// //TODO: check for write permission on shared file once the new sharing API is in place\r
-// \r
-// }\r
- \r
- // Save the keyfile in parallel directory\r
- return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );\r
+ if ( $view->is_dir( $basePath . '/' . $targetPath ) ) {\r
+ \r
+ \r
+ \r
+ } else {\r
+\r
+ // Save the keyfile in parallel directory\r
+ return $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );\r
+ \r
+ }\r
\r
}\r
\r
public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) {\r
\r
$filePath_f = ltrim( $filePath, '/' );\r
-\r
-// // update $keypath and $userId if path point to a file shared by someone else\r
-// $query = \OC_DB::prepare( "SELECT uid_owner, source, target FROM `*PREFIX*sharing` WHERE target = ? AND uid_shared_with = ?" );\r
-// \r
-// $result = $query->execute( array ('/'.$userId.'/files/'.$keypath, $userId));\r
-// \r
-// if ($row = $result->fetchRow()) {\r
-// \r
-// $keypath = $row['source'];\r
-// $keypath_parts = explode( '/', $keypath );\r
-// $userId = $keypath_parts[1];\r
-// $keypath = str_replace( '/' . $userId . '/files/', '', $keypath );\r
-// \r
-// }\r
-\r
+ \r
$catfilePath = '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f . '.key';\r
\r
if ( $view->file_exists( $catfilePath ) ) {\r
* @brief Make preparations to vars and filesystem for saving a keyfile\r
*/\r
public static function keySetPreparation( \OC_FilesystemView $view, $path, $basePath, $userId ) {\r
- \r
+ \r
$targetPath = ltrim( $path, '/' );\r
\r
$path_parts = pathinfo( $targetPath );\r
// If the file resides within a subdirectory, create it\r
if ( \r
isset( $path_parts['dirname'] )\r
- && ! $view->file_exists( $basePath . $path_parts['dirname'] ) \r
+ && ! $view->file_exists( $basePath . '/' . $path_parts['dirname'] ) \r
) {\r
\r
- $view->mkdir( $basePath . $path_parts['dirname'] );\r
+ $view->mkdir( $basePath . '/' . $path_parts['dirname'] );\r
\r
}\r
\r
*
*/
+/**
+* @brief Encryption proxy which handles filesystem operations before and after
+* execution and encrypts, and handles keyfiles accordingly. Used for
+* webui.
+*/
+
namespace OCA\Encryption;
class Proxy extends \OC_FileProxy {
$view = new \OC_FilesystemView( '/' );
+ $userId = \OCP\USER::getUser();
+
// Format path to be relative to user files dir
$trimmed = ltrim( $path, '/' );
$split = explode( '/', $trimmed );
// Dirs must be handled separately as deleteFileKey
// doesn't handle them
- $view->unlink( 'files_encryption/keyfiles/'. $relPath );
+ $view->unlink( $userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/'. $relPath );
} else {
-
- $userId = \OCP\USER::getUser();
// Delete keyfile so it isn't orphaned
$result = Keymanager::deleteFileKey( $view, $userId, $relPath );