コード例 #1
0
ファイル: hooks.php プロジェクト: hjimmy/owncloud
 /**
  * @brief
  */
 public static function postUnshare($params)
 {
     // NOTE: $params has keys:
     // [itemType] => file
     // [itemSource] => 13
     // [shareType] => 0
     // [shareWith] => test1
     // [itemParent] =>
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
         $view = new \OC_FilesystemView('/');
         $userId = \OCP\User::getUser();
         $util = new Util($view, $userId);
         $path = $util->fileIdToPath($params['itemSource']);
         // check if this is a re-share
         if ($params['itemParent']) {
             // get the parent from current share
             $parent = $util->getShareParent($params['itemParent']);
             // get target path
             $targetPath = $util->fileIdToPath($params['itemSource']);
             $targetPathSplit = array_reverse(explode('/', $targetPath));
             // init values
             $path = '';
             $sharedPart = ltrim($parent['file_target'], '/');
             // rebuild path
             foreach ($targetPathSplit as $pathPart) {
                 if ($pathPart !== $sharedPart) {
                     $path = '/' . $pathPart . $path;
                 } else {
                     break;
                 }
             }
             // prefix path with Shared
             $path = '/Shared' . $parent['file_target'] . $path;
         }
         // for group shares get a list of the group members
         if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
             $userIds = \OC_Group::usersInGroup($params['shareWith']);
         } else {
             if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) {
                 $userIds = array($util->getPublicShareKeyId());
             } else {
                 $userIds = array($params['shareWith']);
             }
         }
         // get the path including mount point only if not a shared folder
         if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
             // get path including the the storage mount point
             $path = $util->getPathWithMountPoint($params['itemSource']);
         }
         // if we unshare a folder we need a list of all (sub-)files
         if ($params['itemType'] === 'folder') {
             $allFiles = $util->getAllFiles($path);
         } else {
             $allFiles = array($path);
         }
         foreach ($allFiles as $path) {
             // check if the user still has access to the file, otherwise delete share key
             $sharingUsers = $util->getSharingUsersArray(true, $path);
             // Unshare every user who no longer has access to the file
             $delUsers = array_diff($userIds, $sharingUsers);
             // delete share key
             Keymanager::delShareKey($view, $delUsers, $path);
         }
     }
 }
コード例 #2
0
ファイル: hooks.php プロジェクト: olucao/owncloud-core
 /**
  * after a file is renamed, rename its keyfile and share-keys also fix the file size and fix also the sharing
  * @param array $params array with oldpath and newpath
  *
  * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
  * of the stored versions along the actual file
  */
 public static function postRename($params)
 {
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $view = new \OC\Files\View('/');
     $session = new \OCA\Encryption\Session($view);
     $userId = \OCP\User::getUser();
     $util = new Util($view, $userId);
     if (isset(self::$renamedFiles[$params['oldpath']]['uid']) && isset(self::$renamedFiles[$params['oldpath']]['path'])) {
         $ownerOld = self::$renamedFiles[$params['oldpath']]['uid'];
         $pathOld = self::$renamedFiles[$params['oldpath']]['path'];
     } else {
         \OCP\Util::writeLog('Encryption library', "can't get path and owner from the file before it was renamed", \OCP\Util::DEBUG);
         return false;
     }
     list($ownerNew, $pathNew) = $util->getUidAndFilename($params['newpath']);
     // Format paths to be relative to user files dir
     if ($util->isSystemWideMountPoint($pathOld)) {
         $oldKeyfilePath = 'files_encryption/keyfiles/' . $pathOld;
         $oldShareKeyPath = 'files_encryption/share-keys/' . $pathOld;
     } else {
         $oldKeyfilePath = $ownerOld . '/' . 'files_encryption/keyfiles/' . $pathOld;
         $oldShareKeyPath = $ownerOld . '/' . 'files_encryption/share-keys/' . $pathOld;
     }
     if ($util->isSystemWideMountPoint($pathNew)) {
         $newKeyfilePath = 'files_encryption/keyfiles/' . $pathNew;
         $newShareKeyPath = 'files_encryption/share-keys/' . $pathNew;
     } else {
         $newKeyfilePath = $ownerNew . '/files_encryption/keyfiles/' . $pathNew;
         $newShareKeyPath = $ownerNew . '/files_encryption/share-keys/' . $pathNew;
     }
     // create new key folders if it doesn't exists
     if (!$view->file_exists(dirname($newShareKeyPath))) {
         $view->mkdir(dirname($newShareKeyPath));
     }
     if (!$view->file_exists(dirname($newKeyfilePath))) {
         $view->mkdir(dirname($newKeyfilePath));
     }
     // handle share keys
     if (!$view->is_dir($oldKeyfilePath)) {
         $oldKeyfilePath .= '.key';
         $newKeyfilePath .= '.key';
         // handle share-keys
         $matches = Helper::findShareKeys($oldShareKeyPath, $view);
         foreach ($matches as $src) {
             $dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));
             $view->rename($src, $dst);
         }
     } else {
         // handle share-keys folders
         $view->rename($oldShareKeyPath, $newShareKeyPath);
     }
     // Rename keyfile so it isn't orphaned
     if ($view->file_exists($oldKeyfilePath)) {
         $view->rename($oldKeyfilePath, $newKeyfilePath);
     }
     // update share keys
     $sharingEnabled = \OCP\Share::isEnabled();
     // get users
     $usersSharing = $util->getSharingUsersArray($sharingEnabled, $pathNew);
     // update sharing-keys
     $util->setSharedFileKeyfiles($session, $usersSharing, $pathNew);
     \OC_FileProxy::$enabled = $proxyStatus;
 }
コード例 #3
0
ファイル: hooks.php プロジェクト: omusico/isle-web-framework
 /**
  * @brief after a file is renamed, rename its keyfile and share-keys also fix the file size and fix also the sharing
  * @param array with oldpath and newpath
  *
  * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
  * of the stored versions along the actual file
  */
 public static function postRename($params)
 {
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     $view = new \OC_FilesystemView('/');
     $session = new \OCA\Encryption\Session($view);
     $userId = \OCP\User::getUser();
     $util = new Util($view, $userId);
     // Format paths to be relative to user files dir
     if ($util->isSystemWideMountPoint($params['oldpath'])) {
         $baseDir = 'files_encryption/';
         $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath'];
     } else {
         $baseDir = $userId . '/' . 'files_encryption/';
         $oldKeyfilePath = $baseDir . 'keyfiles/' . $params['oldpath'];
     }
     if ($util->isSystemWideMountPoint($params['newpath'])) {
         $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath'];
     } else {
         $newKeyfilePath = $baseDir . 'keyfiles/' . $params['newpath'];
     }
     // add key ext if this is not an folder
     if (!$view->is_dir($oldKeyfilePath)) {
         $oldKeyfilePath .= '.key';
         $newKeyfilePath .= '.key';
         // handle share-keys
         $localKeyPath = $view->getLocalFile($baseDir . 'share-keys/' . $params['oldpath']);
         $escapedPath = Helper::escapeGlobPattern($localKeyPath);
         $matches = glob($escapedPath . '*.shareKey');
         foreach ($matches as $src) {
             $dst = \OC\Files\Filesystem::normalizePath(str_replace($params['oldpath'], $params['newpath'], $src));
             // create destination folder if not exists
             if (!file_exists(dirname($dst))) {
                 mkdir(dirname($dst), 0750, true);
             }
             rename($src, $dst);
         }
     } else {
         // handle share-keys folders
         $oldShareKeyfilePath = $baseDir . 'share-keys/' . $params['oldpath'];
         $newShareKeyfilePath = $baseDir . 'share-keys/' . $params['newpath'];
         // create destination folder if not exists
         if (!$view->file_exists(dirname($newShareKeyfilePath))) {
             $view->mkdir(dirname($newShareKeyfilePath), 0750, true);
         }
         $view->rename($oldShareKeyfilePath, $newShareKeyfilePath);
     }
     // Rename keyfile so it isn't orphaned
     if ($view->file_exists($oldKeyfilePath)) {
         // create destination folder if not exists
         if (!$view->file_exists(dirname($newKeyfilePath))) {
             $view->mkdir(dirname($newKeyfilePath), 0750, true);
         }
         $view->rename($oldKeyfilePath, $newKeyfilePath);
     }
     // build the path to the file
     $newPath = '/' . $userId . '/files' . $params['newpath'];
     $newPathRelative = $params['newpath'];
     if ($util->fixFileSize($newPath)) {
         // get sharing app state
         $sharingEnabled = \OCP\Share::isEnabled();
         // get users
         $usersSharing = $util->getSharingUsersArray($sharingEnabled, $newPathRelative);
         // update sharing-keys
         $util->setSharedFileKeyfiles($session, $usersSharing, $newPathRelative);
     }
     \OC_FileProxy::$enabled = $proxyStatus;
 }
コード例 #4
0
ファイル: hooks.php プロジェクト: ArcherSys/ArcherSysOSCloud7
 /**
  * unshare file/folder from a user with whom you shared the file before
  */
 public static function postUnshare($params)
 {
     if (\OCP\App::isEnabled('files_encryption') === false) {
         return true;
     }
     if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
         $view = new \OC\Files\View('/');
         $userId = \OCP\User::getUser();
         $util = new Util($view, $userId);
         $path = \OC\Files\Filesystem::getPath($params['fileSource']);
         // for group shares get a list of the group members
         if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
             $userIds = \OC_Group::usersInGroup($params['shareWith']);
         } else {
             if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) {
                 $userIds = array($util->getPublicShareKeyId());
             } else {
                 $userIds = array($params['shareWith']);
             }
         }
         $mountManager = \OC\Files\Filesystem::getMountManager();
         $mount = $mountManager->find('/' . $userId . '/files' . $path);
         $mountPoint = $mount->getMountPoint();
         // if we unshare a folder we need a list of all (sub-)files
         if ($params['itemType'] === 'folder') {
             $allFiles = $util->getAllFiles($path, $mountPoint);
         } else {
             $allFiles = array($path);
         }
         foreach ($allFiles as $path) {
             // check if the user still has access to the file, otherwise delete share key
             $sharingUsers = $util->getSharingUsersArray(true, $path);
             // Unshare every user who no longer has access to the file
             $delUsers = array_diff($userIds, $sharingUsers);
             list($owner, $ownerPath) = $util->getUidAndFilename($path);
             // delete share key
             Keymanager::delShareKey($view, $delUsers, $ownerPath, $owner);
         }
     }
 }