Beispiel #1
0
 /**
  * get the UID of the owner of the file and the path to the file relative to
  * owners files folder
  *
  * @param string $filename
  * @return array
  * @throws \OC\User\NoUserException
  */
 public static function getUidAndFilename($filename)
 {
     $uid = Filesystem::getOwner($filename);
     $userManager = \OC::$server->getUserManager();
     // if the user with the UID doesn't exists, e.g. because the UID points
     // to a remote user with a federated cloud ID we use the current logged-in
     // user. We need a valid local user to create the versions
     if (!$userManager->userExists($uid)) {
         $uid = User::getUser();
     }
     Filesystem::initMountPoints($uid);
     if ($uid != User::getUser()) {
         $info = Filesystem::getFileInfo($filename);
         $ownerView = new View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
             // make sure that the file name doesn't end with a trailing slash
             // can for example happen single files shared across servers
             $filename = rtrim($filename, '/');
         } catch (NotFoundException $e) {
             $filename = null;
         }
     }
     return [$uid, $filename];
 }
Beispiel #2
0
 /**
  * Correct the parent folders' ETags for all users shared the file at $target
  *
  * @param string $target
  */
 public static function correctFolders($target)
 {
     $uid = \OCP\User::getUser();
     $uidOwner = \OC\Files\Filesystem::getOwner($target);
     $info = \OC\Files\Filesystem::getFileInfo($target);
     // Correct Shared folders of other users shared with
     $users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
     if (!empty($users)) {
         while (!empty($users)) {
             $reshareUsers = array();
             foreach ($users as $user) {
                 if ($user !== $uidOwner) {
                     $etag = \OC\Files\Filesystem::getETag('');
                     \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag);
                     // Look for reshares
                     $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true));
                 }
             }
             $users = $reshareUsers;
         }
         // Correct folders of shared file owner
         $target = substr($target, 8);
         if ($uidOwner !== $uid && ($source = \OC_Share_Backend_File::getSource($target))) {
             \OC\Files\Filesystem::initMountPoints($uidOwner);
             $source = '/' . $uidOwner . '/' . $source['path'];
             \OC\Files\Cache\Updater::correctFolder($source, $info['mtime']);
         }
     }
 }
Beispiel #3
0
 public static function getUidAndFilename($filename)
 {
     $uid = \OC\Files\Filesystem::getOwner($filename);
     \OC\Files\Filesystem::initMountPoints($uid);
     if ($uid != \OCP\User::getUser()) {
         $info = \OC\Files\Filesystem::getFileInfo($filename);
         $ownerView = new \OC\Files\View('/' . $uid . '/files');
         $filename = $ownerView->getPath($info['fileid']);
     }
     return array($uid, $filename);
 }
Beispiel #4
0
 /**
  * @param string $filename
  * @return array
  * @throws \OC\User\NoUserException
  */
 public static function getUidAndFilename($filename)
 {
     $uid = \OC\Files\Filesystem::getOwner($filename);
     \OC\Files\Filesystem::initMountPoints($uid);
     if ($uid != \OCP\User::getUser()) {
         $info = \OC\Files\Filesystem::getFileInfo($filename);
         $ownerView = new \OC\Files\View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
         } catch (NotFoundException $e) {
             $filename = null;
         }
     }
     return [$uid, $filename];
 }
Beispiel #5
0
 /**
  * update keyfiles and share keys recursively
  *
  * @param int $fileSource file source id
  */
 private function update($fileSource)
 {
     $path = \OC\Files\Filesystem::getPath($fileSource);
     $info = \OC\Files\Filesystem::getFileInfo($path);
     $owner = \OC\Files\Filesystem::getOwner($path);
     $view = new \OC\Files\View('/' . $owner . '/files');
     $ownerPath = $view->getPath($info->getId());
     $absPath = '/' . $owner . '/files' . $ownerPath;
     $mount = $this->mountManager->find($path);
     $mountPoint = $mount->getMountPoint();
     // if a folder was shared, get a list of all (sub-)folders
     if ($this->view->is_dir($absPath)) {
         $allFiles = $this->util->getAllFiles($absPath, $mountPoint);
     } else {
         $allFiles = array($absPath);
     }
     $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule();
     foreach ($allFiles as $path) {
         $usersSharing = $this->file->getAccessList($path);
         $encryptionModule->update($path, $this->uid, $usersSharing);
     }
 }
Beispiel #6
0
 /**
  * get the UID of the owner of the file and the path to the file relative to
  * owners files folder
  *
  * @param string $filename
  * @return array
  * @throws \OC\User\NoUserException
  */
 public static function getUidAndFilename($filename)
 {
     $uid = Filesystem::getOwner($filename);
     $userManager = \OC::$server->getUserManager();
     // if the user with the UID doesn't exists, e.g. because the UID points
     // to a remote user with a federated cloud ID we use the current logged-in
     // user. We need a valid local user to move the file to the right trash bin
     if (!$userManager->userExists($uid)) {
         $uid = User::getUser();
     }
     Filesystem::initMountPoints($uid);
     if ($uid != User::getUser()) {
         $info = Filesystem::getFileInfo($filename);
         $ownerView = new View('/' . $uid . '/files');
         try {
             $filename = $ownerView->getPath($info['fileid']);
         } catch (NotFoundException $e) {
             $filename = null;
         }
     }
     return [$uid, $filename];
 }
Beispiel #7
0
 /**
  * Correct the parent folders' ETags for all users shared the file at $target
  *
  * @param string $target
  */
 public static function correctFolders($target)
 {
     $uid = \OCP\User::getUser();
     $uidOwner = \OC\Files\Filesystem::getOwner($target);
     $info = \OC\Files\Filesystem::getFileInfo($target);
     $checkedUser = array($uidOwner);
     // Correct Shared folders of other users shared with
     $users = \OCP\Share::getUsersItemShared('file', $info['fileid'], $uidOwner, true);
     if (!empty($users)) {
         while (!empty($users)) {
             $reshareUsers = array();
             foreach ($users as $user) {
                 if (!in_array($user, $checkedUser)) {
                     $etag = \OC\Files\Filesystem::getETag('');
                     \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag);
                     // Look for reshares
                     $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $info['fileid'], $user, true));
                     $checkedUser[] = $user;
                 }
             }
             $users = $reshareUsers;
         }
     }
 }
Beispiel #8
0
 /**
  * @brief Store the delete hook events
  * @param array $params The hook params
  */
 public static function file_delete($params)
 {
     $link = \OCP\Util::linkToAbsolute('files', 'index.php', array('dir' => dirname($params['path'])));
     $subject = '%s deleted';
     Data::send('files', $subject, substr($params['path'], 1), '', array(), $params['path'], $link, \OCP\User::getUser(), 2);
     if (substr($params['path'], 0, 8) == '/Shared/') {
         $uidOwner = \OC\Files\Filesystem::getOwner($params['path']);
         $realfile = substr($params['path'], 7);
         $link = \OCP\Util::linkToAbsolute('files', 'index.php', array('dir' => dirname($realfile)));
         $subject = '%s deleted by %s';
         Data::send('files', $subject, array($realfile, \OCP\User::getUser()), '', array(), $realfile, $link, $uidOwner, 7, Data::PRIORITY_HIGH);
     }
 }
Beispiel #9
0
 public static function getSharesFromItem($target)
 {
     $result = array();
     $owner = \OC\Files\Filesystem::getOwner($target);
     \OC\Files\Filesystem::initMountPoints($owner);
     $info = \OC\Files\Filesystem::getFileInfo($target);
     $ownerView = new \OC\Files\View('/' . $owner . '/files');
     if ($owner != \OCP\User::getUser()) {
         $path = $ownerView->getPath($info['fileid']);
     } else {
         $path = $target;
     }
     $ids = array();
     while ($path !== dirname($path)) {
         $info = $ownerView->getFileInfo($path);
         if ($info instanceof \OC\Files\FileInfo) {
             $ids[] = $info['fileid'];
         } else {
             \OCP\Util::writeLog('sharing', 'No fileinfo available for: ' . $path, \OCP\Util::WARN);
         }
         $path = dirname($path);
     }
     if (!empty($ids)) {
         $idList = array_chunk($ids, 99, true);
         foreach ($idList as $subList) {
             $statement = "SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN (" . implode(',', $subList) . ") AND `share_type` IN (0, 1, 2)";
             $query = \OCP\DB::prepare($statement);
             $r = $query->execute();
             $result = array_merge($result, $r->fetchAll());
         }
     }
     return $result;
 }
Beispiel #10
0
 /**
  * Return the source
  *
  * @param string $path
  * @return array
  */
 protected function getSourcePathAndOwner($path)
 {
     $uidOwner = Filesystem::getOwner($path);
     if ($uidOwner !== $this->currentUser) {
         Filesystem::initMountPoints($uidOwner);
         $info = Filesystem::getFileInfo($path);
         if ($info !== false) {
             $ownerView = new View('/' . $uidOwner . '/files');
             $path = $ownerView->getPath((int) $info['fileid']);
         }
     }
     return array($path, $uidOwner);
 }
Beispiel #11
0
 /**
  * get owner and path relative to data/<owner>/files
  *
  * @param string $path path to file for current user
  * @return array ['owner' => $owner, 'path' => $path]
  * @throw \InvalidArgumentException
  */
 protected function getOwnerPath($path)
 {
     $info = Filesystem::getFileInfo($path);
     $owner = Filesystem::getOwner($path);
     $view = new View('/' . $owner . '/files');
     $path = $view->getPath($info->getId());
     if ($path === null) {
         throw new \InvalidArgumentException('No file found for ' . $info->getId());
     }
     return array($owner, $path);
 }
Beispiel #12
0
	/**
	 * get file owner and path
	 * @param string $filename
	 * @return string[] with the owner's uid and the owner's path
	 */
	private static function getUidAndFilename($filename) {

		$uid = \OC\Files\Filesystem::getOwner($filename);
		\OC\Files\Filesystem::initMountPoints($uid);

		$filename = (strpos($filename, '/') !== 0) ? '/' . $filename : $filename;
		if ($uid != \OCP\User::getUser()) {
			$info = \OC\Files\Filesystem::getFileInfo($filename);
			if (!$info) {
				return array($uid, '/files' . $filename);
			}
			$ownerView = new \OC\Files\View('/' . $uid . '/files');
			$filename = $ownerView->getPath($info['fileid']);
		}
		return array($uid, '/files' . $filename);
	}
Beispiel #13
0
 /**
  * Return the source
  *
  * @param string $path
  * @return array
  */
 public static function getSourcePathAndOwner($path)
 {
     $uidOwner = \OC\Files\Filesystem::getOwner($path);
     if ($uidOwner != \OCP\User::getUser()) {
         \OC\Files\Filesystem::initMountPoints($uidOwner);
         $info = \OC\Files\Filesystem::getFileInfo($path);
         $ownerView = new \OC\Files\View('/' . $uidOwner . '/files');
         $path = $ownerView->getPath($info['fileid']);
     }
     return array($path, $uidOwner);
 }
Beispiel #14
0
 /**
  * @brief Encrypt keyfile to multiple users
  * @param Session $session
  * @param array $users list of users which should be able to access the file
  * @param string $filePath path of the file to be shared
  * @return bool
  */
 public function setSharedFileKeyfiles(Session $session, array $users, $filePath)
 {
     // Make sure users are capable of sharing
     $filteredUids = $this->filterShareReadyUsers($users);
     // If we're attempting to share to unready users
     if (!empty($filteredUids['unready'])) {
         \OCP\Util::writeLog('Encryption library', 'Sharing to these user(s) failed as they are unready for encryption:"' . print_r($filteredUids['unready'], 1), \OCP\Util::WARN);
         return false;
     }
     // Get public keys for each user, ready for generating sharekeys
     $userPubKeys = Keymanager::getPublicKeys($this->view, $filteredUids['ready']);
     // Note proxy status then disable it
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // Get the current users's private key for decrypting existing keyfile
     $privateKey = $session->getPrivateKey();
     $fileOwner = \OC\Files\Filesystem::getOwner($filePath);
     // Decrypt keyfile
     $plainKeyfile = $this->decryptKeyfile($filePath, $privateKey);
     // Re-enc keyfile to (additional) sharekeys
     $multiEncKey = Crypt::multiKeyEncrypt($plainKeyfile, $userPubKeys);
     // Save the recrypted key to it's owner's keyfiles directory
     // Save new sharekeys to all necessary user directory
     if (!Keymanager::setFileKey($this->view, $this, $filePath, $multiEncKey['data']) || !Keymanager::setShareKeys($this->view, $this, $filePath, $multiEncKey['keys'])) {
         \OCP\Util::writeLog('Encryption library', 'Keyfiles could not be saved for users sharing ' . $filePath, \OCP\Util::ERROR);
         return false;
     }
     // Return proxy to original status
     \OC_FileProxy::$enabled = $proxyStatus;
     return true;
 }
Beispiel #15
0
 /**
  * Share selected files with selected users
  */
 public function shareFiles()
 {
     $this->prepareUsersForShare();
     $files = array();
     foreach ($this->files as $id) {
         $files[] = $file = $this->files->getById($id)[0];
         $fileOwner = \OC\Files\Filesystem::getOwner($file['path']);
         $sharetype = $file['mimetype'] == 2 ? 'folder' : 'file';
         $sharedWith = \OCP\Share::getUsersItemShared($sharetype, $file['fileid'], $fileOwner, false, true);
         foreach ($this->subscriberToShare as $userid) {
             if (isset($file['fileid']) && is_array($file) && !in_array($userid, $sharedWith) && !($userid == $this->author) && ($fileOwner == $this->author || $file['permissions'] >= 16)) {
                 \OCP\Share::shareItem($sharetype, $file['fileid'], \OCP\Share::SHARE_TYPE_USER, $userid, 1);
             }
         }
     }
     $this->forSend['messagedata']['attachlinks'] = Helper::makeAttachLinks($this->files, $files);
 }
Beispiel #16
0
 /**
  * Share selected files with selected users
  */
 public function shareFiles()
 {
     $this->prepareUsersForShare();
     $files = array();
     foreach ($this->files as $id) {
         $file = $this->Files->getById($id)[0];
         $fileOwner = \OC\Files\Filesystem::getOwner($file['path']);
         $sharetype = $file['mimetype'] == 2 ? 'folder' : 'file';
         $sharedWith = \OCP\Share::getUsersItemShared($sharetype, $file['fileid'], $fileOwner, false, true);
         $isenabled = \OCP\Share::isEnabled();
         $isallowed = \OCP\Share::isResharingAllowed();
         foreach ($this->subscriberToShare as $userid) {
             if (isset($file['fileid']) && is_array($file) && !in_array($userid, $sharedWith) && !($userid == $this->author) && ($fileOwner == $this->author || $file['permissions'] >= 16) && $isenabled && $isallowed) {
                 //try {
                 \OCP\Share::shareItem($sharetype, $file['fileid'], \OCP\Share::SHARE_TYPE_USER, $userid, 1);
                 $files[] = $file['fileid'];
                 //}
                 //catch (\Exception $e) {
                 //	echo $e->getMessage();
                 //}
             }
         }
     }
     $this->forSaveData['attachements'] = $files;
     $this->fileLinks = Helper::makeAttachLinks($files, $this->Files);
     //print_r($this->fileLinks);
     //file_put_contents('/tmp/inb.log', "\n\nfileLinks : "print_r($this->fileLinks, true)."\n", FILE_APPEND);
     /* foreach ($_POST['select-files'] as $id => $on) {
     			if ($on == 'on') {
     				$file = $files->getById($id)[0];
     				$fileOwner = \OC\Files\Filesystem::getOwner($file['path']);
     				$sharetype = $file['mimetype'] == 2 ? 'folder' : 'file';
     				$sharedWith = \OCP\Share::getUsersItemShared($sharetype, $file['fileid'], $fileOwner, false, true);
     				foreach ($allusers as $userid => $user) {
     					if (isset($file['fileid']) && is_array($file) && isset($file['fileid']) && !in_array($userid, $sharedWith) && !($userid == $this->userId)) {
     						//Helper::shareFile($file['name'], $user, $userid);
     						\OCP\Share::shareItem($sharetype, $file['fileid'], \OCP\Share::SHARE_TYPE_USER, $userid, 1);
     						$filesid[] = $id;
     					}
     				}
     			}
     		} */
 }
 public function save()
 {
     $files = $this->connect->files();
     $users = $this->connect->users();
     //$user = $users->getById($this->userId)[0];
     //Helper::uploadFile($_FILES['uploadfile'], $this->userId);
     foreach ($_POST['users'] as $s => $subscriber) {
         if (!($subscriber == $this->userId)) {
             $subscribers[$subscriber] = $users->getUserDetails($subscriber);
         }
     }
     // Get subscribers group
     foreach ($_POST['groups'] as $group) {
         $groupsid = array();
         if (!empty($group)) {
             $groupsid[] = $group;
         }
     }
     $from = count($groupsid) > 0 ? $groupsid : $this->userId;
     // Share selected files with selected users
     $filesid = array();
     foreach ($_POST['upload-files'] as $id) {
         $file = $files->getById($id)[0];
         $fileOwner = \OC\Files\Filesystem::getOwner($file['path']);
         $sharetype = $file['mimetype'] == 2 ? 'folder' : 'file';
         $sharedWith = \OCP\Share::getUsersItemShared($sharetype, $file['fileid'], $fileOwner, false, true);
         foreach ($subscribers as $userid => $user) {
             if (isset($file['fileid']) && is_array($file) && isset($file['fileid']) && !in_array($userid, $sharedWith) && !($userid == $this->userId)) {
                 \OCP\Share::shareItem($sharetype, $file['fileid'], \OCP\Share::SHARE_TYPE_USER, $userid, 1);
                 $filesid[] = $id;
             }
         }
     }
     foreach ($_POST['select-files'] as $id => $on) {
         if ($on == 'on') {
             $file = $files->getById($id)[0];
             $fileOwner = \OC\Files\Filesystem::getOwner($file['path']);
             $sharetype = $file['mimetype'] == 2 ? 'folder' : 'file';
             $sharedWith = \OCP\Share::getUsersItemShared($sharetype, $file['fileid'], $fileOwner, false, true);
             foreach ($subscribers as $userid => $user) {
                 if (isset($file['fileid']) && is_array($file) && isset($file['fileid']) && !in_array($userid, $sharedWith) && !($userid == $this->userId)) {
                     //Helper::shareFile($file['name'], $user, $userid);
                     \OCP\Share::shareItem($sharetype, $file['fileid'], \OCP\Share::SHARE_TYPE_USER, $userid, 1);
                     $filesid[] = $id;
                 }
             }
         }
     }
     $messagedata = array('rid' => $_POST['replyid'], 'date' => date("Y-m-d h:i:s"), 'title' => $_POST['title'], 'text' => Helper::checkTxt($_POST['message-body']), 'attachements' => implode(',', $filesid), 'author' => $this->userId, 'subscribers' => implode(',', array_keys($subscribers)), 'hash' => isset($_POST['talkhash']) && !empty($_POST['talkhash']) ? $_POST['talkhash'] : md5(date("Y-m-d h:i:s") . '' . $_POST['title']), 'status' => 0);
     $messages = $this->connect->messages();
     $saved = $messages->save($messagedata);
     if ($saved) {
         $messagedata['attachlinks'] = Helper::makeAttachLinks($filesid, $files);
         $this->sendMessage($saved, $subscribers, $from, $messagedata);
     }
     $canwrite = true;
     //TODO: Створити перевірку на право починати бесіди
     $usermessages = $this->getUserMessages();
     $talks = $usermessages->getByAuthorOrSubscriber($this->userId, '0');
     $firsttalk = $messages->getByParent($talks[0]['messageid'], 'date ASC');
     if ($canwrite) {
         header('Location: /index.php/apps/' . $this->appName . '/all');
         exit;
         /* $params = array(
         				'user' => $this->userId,
         				'message' => $_POST,
         				'messages' => $talks,
         				'answers' => $firsttalk,
         				'appname' => $this->appName,
         				'files' => $files,
         				'mode' => 'list',
         				'menu' => 'all'
         			);
         
         			return new TemplateResponse($this->appName, 'talk', $params);  // templates/talk.php
         			 */
     } else {
         return;
     }
 }