Exemplo n.º 1
0
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @throws \Sabre_DAV_Exception_NotFound
  * @return \Sabre_DAV_INode
  */
 public function getNodeForPath($path)
 {
     $path = trim($path, '/');
     if (isset($this->cache[$path])) {
         return $this->cache[$path];
     }
     // Is it the root node?
     if (!strlen($path)) {
         return $this->rootNode;
     }
     if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
         // read from storage
         $absPath = $this->getFileView()->getAbsolutePath($path);
         list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath);
         if ($storage) {
             $scanner = $storage->getScanner($internalPath);
             // get data directly
             $info = $scanner->getData($internalPath);
         }
     } else {
         // read from cache
         $info = $this->getFileView()->getFileInfo($path);
     }
     if (!$info) {
         throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
     }
     if ($info['mimetype'] === 'httpd/unix-directory') {
         $node = new \OC_Connector_Sabre_Directory($path);
     } else {
         $node = new \OC_Connector_Sabre_File($path);
     }
     $node->setFileinfoCache($info);
     $this->cache[$path] = $node;
     return $node;
 }
Exemplo n.º 2
0
 /**
  * check if path is excluded from encryption
  *
  * @param string $path relative to data/
  * @return boolean
  */
 protected function isExcludedPath($path)
 {
     $view = new \OC\Files\View();
     $normalizedPath = \OC\Files\Filesystem::normalizePath($path);
     $parts = explode('/', $normalizedPath);
     // we only encrypt/decrypt files in the files and files_versions folder
     if (sizeof($parts) < 3) {
         /**
          * Less then 3 parts means, we can't match:
          * - /{$uid}/files/* nor
          * - /{$uid}/files_versions/*
          * So this is not a path we are looking for.
          */
         return true;
     }
     if (!($parts[2] === 'files' && \OCP\User::userExists($parts[1])) && !($parts[2] === 'files_versions' && \OCP\User::userExists($parts[1]))) {
         return true;
     }
     if (!$view->file_exists($normalizedPath)) {
         $normalizedPath = dirname($normalizedPath);
     }
     // we don't encrypt server-to-server shares
     list($storage, ) = \OC\Files\Filesystem::resolvePath($normalizedPath);
     /**
      * @var \OCP\Files\Storage $storage
      */
     if ($storage->instanceOfStorage('OCA\\Files_Sharing\\External\\Storage')) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * @param string $internalPath
  * @param int $time
  * @return array[] all propagated entries
  */
 public function propagateChange($internalPath, $time)
 {
     $source = $this->storage->getSourcePath($internalPath);
     /** @var \OC\Files\Storage\Storage $storage */
     list($storage, $sourceInternalPath) = \OC\Files\Filesystem::resolvePath($source);
     return $storage->getPropagator()->propagateChange($sourceInternalPath, $time);
 }
Exemplo n.º 4
0
 /**
  * if the parent of the mount point is gone then the mount point should move up
  *
  * @medium
  */
 function testParentOfMountPointIsGone()
 {
     // share to user
     $fileinfo = $this->view->getFileInfo($this->folder);
     $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $this->assertTrue($result);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($user2View->file_exists($this->folder));
     // create a local folder
     $result = $user2View->mkdir('localfolder');
     $this->assertTrue($result);
     // move mount point to local folder
     $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
     $this->assertTrue($result);
     // mount point in the root folder should no longer exist
     $this->assertFalse($user2View->is_dir($this->folder));
     // delete the local folder
     /** @var \OC\Files\Storage\Storage $storage */
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
     $storage->rmdir($internalPath);
     //enforce reload of the mount points
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     //mount point should be back at the root
     $this->assertTrue($user2View->is_dir($this->folder));
     //cleanup
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->view->unlink($this->folder);
 }
Exemplo n.º 5
0
 /**
  * Get the source cache of a shared file or folder
  *
  * @param string $target Shared target file path
  * @return \OC\Files\Cache\Cache
  */
 private function getSourceCache($target)
 {
     if ($target === false || $target === $this->storage->getMountPoint()) {
         $target = '';
     }
     $source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
     if (isset($source['path']) && isset($source['fileOwner'])) {
         try {
             \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
         } catch (NoUserException $e) {
             \OC::$server->getLogger()->warning('The user \'' . $source['uid_owner'] . '\' of a share can\'t be retrieved.', array('app' => 'files_sharing'));
             return false;
         }
         $mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
         if (is_array($mounts) and !empty($mounts)) {
             $fullPath = $mounts[0]->getMountPoint() . $source['path'];
             list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
             if ($storage) {
                 $this->files[$target] = $internalPath;
                 $cache = $storage->getCache();
                 $this->storageId = $storage->getId();
                 $this->numericId = $cache->getNumericStorageId();
                 return $cache;
             }
         }
     }
     return false;
 }
Exemplo n.º 6
0
 /**
  * Returns metadata from the shared storage, but
  * with permissions from the source storage.
  *
  * @param string $path path of the file for which to retrieve metadata
  *
  * @return array an array of metadata of the file
  */
 protected function getData($path)
 {
     $data = parent::getData($path);
     $sourcePath = $this->storage->getSourcePath($path);
     list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath);
     $data['permissions'] = $sourceStorage->getPermissions($internalPath);
     return $data;
 }
Exemplo n.º 7
0
 public function __construct($user = null)
 {
     if (is_null($user)) {
         $user = \OCP\User::getUser();
     }
     $root = $user . '/files/';
     list($storage, $internalPath) = Filesystem::resolvePath($root);
     $this->fileview = new View($root);
     $this->cache = new Cache($storage);
 }
Exemplo n.º 8
0
 /**
  * write key to disk
  *
  *
  * @param string $path path to key directory
  * @param string $name key name
  * @param string $key key
  * @param \OC\Files\View $view
  * @return bool
  */
 private static function setKey($path, $name, $key, $view)
 {
     self::keySetPreparation($view, $path);
     /** @var \OCP\Files\Storage $storage */
     $pathToKey = \OC\Files\Filesystem::normalizePath($path . '/' . $name);
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($pathToKey);
     $result = $storage->file_put_contents($internalPath, $key);
     if (is_int($result) && $result > 0) {
         self::$key_cache[$pathToKey] = $key;
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @throws \Sabre\DAV\Exception\ServiceUnavailable
  * @throws \Sabre\DAV\Exception\NotFound
  * @return \Sabre\DAV\INode
  */
 public function getNodeForPath($path)
 {
     if (!$this->fileView) {
         throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
     }
     $path = trim($path, '/');
     if (isset($this->cache[$path])) {
         return $this->cache[$path];
     }
     // Is it the root node?
     if (!strlen($path)) {
         return $this->rootNode;
     }
     if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
         // read from storage
         $absPath = $this->fileView->getAbsolutePath($path);
         list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath);
         if ($storage) {
             /**
              * @var \OC\Files\Storage\Storage $storage
              */
             $scanner = $storage->getScanner($internalPath);
             // get data directly
             $data = $scanner->getData($internalPath);
             $info = new FileInfo($absPath, $storage, $internalPath, $data);
         } else {
             $info = null;
         }
     } else {
         // read from cache
         try {
             $info = $this->fileView->getFileInfo($path);
         } catch (StorageNotAvailableException $e) {
             throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available');
         } catch (StorageInvalidException $e) {
             throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid');
         }
     }
     if (!$info) {
         throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
     }
     if ($info->getType() === 'dir') {
         $node = new \OC_Connector_Sabre_Directory($this->fileView, $info);
     } else {
         $node = new \OC_Connector_Sabre_File($this->fileView, $info);
     }
     $this->cache[$path] = $node;
     return $node;
 }
Exemplo n.º 10
0
 /**
  * get the free space in the path's owner home folder
  * @param path
  * @return int
  */
 private function getFreeSpace($path)
 {
     /**
      * @var \OC\Files\Storage\Storage $storage
      * @var string $internalPath
      */
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path);
     $owner = $storage->getOwner($internalPath);
     if (!$owner) {
         return -1;
     }
     $totalSpace = $this->getQuota($owner);
     if ($totalSpace == -1) {
         return -1;
     }
     $view = new \OC\Files\View("/" . $owner . "/files");
     $rootInfo = $view->getFileInfo('/');
     $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0;
     return $totalSpace - $usedSpace;
 }
Exemplo n.º 11
0
 /**
  * @brief Get the source cache of a shared file or folder
  * @param string $target Shared target file path
  * @return \OC\Files\Cache\Cache
  */
 private function getSourceCache($target)
 {
     $source = \OC_Share_Backend_File::getSource($target);
     if (isset($source['path']) && isset($source['fileOwner'])) {
         \OC\Files\Filesystem::initMountPoints($source['fileOwner']);
         $mount = \OC\Files\Mount::findByNumericId($source['storage']);
         if ($mount) {
             $fullPath = $mount->getMountPoint() . $source['path'];
             list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
             if ($storage) {
                 $this->files[$target] = $internalPath;
                 $cache = $storage->getCache();
                 $this->storageId = $storage->getId();
                 $this->numericId = $cache->getNumericStorageId();
                 return $cache;
             }
         }
     }
     return false;
 }
Exemplo n.º 12
0
 /**
  * check if path is excluded from encryption
  *
  * @param string $path relative to data/
  * @param string $uid user
  * @return boolean
  */
 private function isExcludedPath($path, $uid)
 {
     $view = new \OC\Files\View();
     // files outside of the files-folder are excluded
     if (strpos($path, '/' . $uid . '/files') !== 0) {
         return true;
     }
     if (!$view->file_exists($path)) {
         $path = dirname($path);
     }
     // we don't encrypt server-to-server shares
     list($storage, ) = \OC\Files\Filesystem::resolvePath($path);
     /**
      * @var \OCP\Files\Storage $storage
      */
     if ($storage->instanceOfStorage('OCA\\Files_Sharing\\External\\Storage')) {
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 /**
  * check if path is excluded from encryption
  *
  * @param string $path relative to data/
  * @param string $uid user
  * @return boolean
  */
 protected function isExcludedPath($path, $uid)
 {
     $view = new \OC\Files\View();
     $path = \OC\Files\Filesystem::normalizePath($path);
     // we only encrypt/decrypt files in the files and files_versions folder
     if (strpos($path, '/' . $uid . '/files/') !== 0 && strpos($path, '/' . $uid . '/files_versions/') !== 0) {
         return true;
     }
     if (!$view->file_exists($path)) {
         $path = dirname($path);
     }
     // we don't encrypt server-to-server shares
     list($storage, ) = \OC\Files\Filesystem::resolvePath($path);
     /**
      * @var \OCP\Files\Storage $storage
      */
     if ($storage->instanceOfStorage('OCA\\Files_Sharing\\External\\Storage')) {
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
	/**
	 * Get the source cache of a shared file or folder
	 *
	 * @param string $target Shared target file path
	 * @return \OC\Files\Cache\Cache
	 */
	private function getSourceCache($target) {
		if ($target === false || $target === $this->storage->getMountPoint()) {
			$target = '';
		}
		$source = \OC_Share_Backend_File::getSource($target, $this->storage->getMountPoint(), $this->storage->getItemType());
		if (isset($source['path']) && isset($source['fileOwner'])) {
			\OC\Files\Filesystem::initMountPoints($source['fileOwner']);
			$mounts = \OC\Files\Filesystem::getMountByNumericId($source['storage']);
			if (is_array($mounts) and !empty($mounts)) {
				$fullPath = $mounts[0]->getMountPoint() . $source['path'];
				list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($fullPath);
				if ($storage) {
					$this->files[$target] = $internalPath;
					$cache = $storage->getCache();
					$this->storageId = $storage->getId();
					$this->numericId = $cache->getNumericStorageId();
					return $cache;
				}
			}
		}
		return false;
	}
Exemplo n.º 15
0
 /**
  * check if it is allowed to move a mount point to a given target.
  * It is not allowed to move a mount point into a different mount point
  *
  * @param string $target path
  * @return boolean
  */
 private function isTargetAllowed($target)
 {
     $result = false;
     list($targetStorage, ) = \OC\Files\Filesystem::resolvePath($target);
     if ($targetStorage->instanceOfStorage('\\OCP\\Files\\IHomeStorage')) {
         $result = true;
     } else {
         \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into another one', \OCP\Util::DEBUG);
     }
     return $result;
 }
Exemplo n.º 16
0
 public function testGetPathByIdShareSubFolder()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC\Files\Filesystem::mkdir('foo');
     \OC\Files\Filesystem::mkdir('foo/bar');
     \OC\Files\Filesystem::touch('foo/bar/test.txt', 'bar');
     $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
     \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\PERMISSION_ALL);
     \OC_Util::tearDownFS();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
     list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
     /**
      * @var \OC\Files\Storage\Shared $sharedStorage
      */
     $sharedCache = $sharedStorage->getCache();
     $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
     $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
 }
Exemplo n.º 17
0
 /**
  * change file metadata
  *
  * @param string $path
  * @param array|\OCP\Files\FileInfo $data
  * @return int
  *
  * returns the fileid of the updated file
  */
 public function putFileInfo($path, $data)
 {
     $this->assertPathLength($path);
     if ($data instanceof FileInfo) {
         $data = $data->getData();
     }
     $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
     /**
      * @var \OC\Files\Storage\Storage $storage
      * @var string $internalPath
      */
     list($storage, $internalPath) = Filesystem::resolvePath($path);
     if ($storage) {
         $cache = $storage->getCache($path);
         if (!$cache->inCache($internalPath)) {
             $scanner = $storage->getScanner($internalPath);
             $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
         }
         return $cache->put($internalPath, $data);
     } else {
         return -1;
     }
 }
Exemplo n.º 18
0
 /**
  * check if it is allowed to move a mount point to a given target.
  * It is not allowed to move a mount point into a different mount point or
  * into an already shared folder
  *
  * @param string $target path
  * @return boolean
  */
 private function isTargetAllowed($target)
 {
     list($targetStorage, $targetInternalPath) = \OC\Files\Filesystem::resolvePath($target);
     if (!$targetStorage->instanceOfStorage('\\OCP\\Files\\IHomeStorage')) {
         \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into another one', \OCP\Util::DEBUG);
         return false;
     }
     // note: cannot use the view because the target is already locked
     $fileId = (int) $targetStorage->getCache()->getId($targetInternalPath);
     if ($fileId === -1) {
         // target might not exist, need to check parent instead
         $fileId = (int) $targetStorage->getCache()->getId(dirname($targetInternalPath));
     }
     // check if any of the parents were shared by the current owner (include collections)
     $shares = \OCP\Share::getItemShared('folder', $fileId, \OCP\Share::FORMAT_NONE, null, true);
     if (count($shares) > 0) {
         \OCP\Util::writeLog('files', 'It is not allowed to move one mount point into a shared folder', \OCP\Util::DEBUG);
         return false;
     }
     return true;
 }
Exemplo n.º 19
0
 public function getETag($path)
 {
     if ($path == '') {
         $path = $this->getMountPoint();
     }
     if ($source = $this->getSourcePath($path)) {
         list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
         return $storage->getETag($internalPath);
     }
     return null;
 }
Exemplo n.º 20
0
 /**
  * Inserts uploaded file into database
  * @param array $file
  */
 public function newFile($file, $path)
 {
     $sql = "SELECT id FROM *PREFIX*mimetypes WHERE mimetype = '" . $file['mimetype'] . "'";
     $res = $this->connect->query($sql);
     $mimetype = $res['id'];
     $sql = "SELECT numeric_id FROM *PREFIX*storages WHERE id = 'home::" . $file['owner'] . "'";
     $res = $this->connect->query($sql);
     $storageid = $res['numeric_id'];
     $sql = "SELECT fileid FROM *PREFIX*filecache WHERE path = '" . $file['path'] . "'";
     $res = $this->connect->query($sql);
     $parent = $res['fileid'];
     //$path = '/var/www/owncloud.loc/data/admin/files/Photos/San Francisco.jpg';
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($path . '/' . $file['filename']);
     $etag = $storage->getETag($internalPath);
     $data = array('storage' => $storageid, 'path' => $file['path'] . '/' . $file['filename'], 'path_hash' => md5($file['path'] . '/' . $file['filename']), 'parent' => $parent, 'name' => $file['filename'], 'mimetype' => $mimetype, 'mimepart' => 5, 'size' => $file['size'], 'mtime' => $file['mtime'], 'storage_mtime' => $file['storage_mtime'], 'etag' => $etag, 'permissions' => \OCP\Constants::PERMISSION_ALL);
     $filecache = $this->save($data);
     /* file_put_contents('/tmp/inb.log', "\nPath : /\n", FILE_APPEND);
             try { 
     		$fileInfo = \OC\Files\Filesystem::getFileInfo('/', false); 
             } 
             catch (\Exception $e) {
     		file_put_contents('/tmp/inb.log', "\nGet File Info error : " . $e->getMessage() . "\n", FILE_APPEND);
     	}
             file_put_contents('/tmp/inb.log', "\nFile info : " . print_r($fileInfo, true) . "\n", FILE_APPEND);
             try { 
     		$icon = \OCA\Files\Helper::determineIcon($fileInfo); 
             } 
             catch (\Exception $e) {
     		file_put_contents('/tmp/inb.log', "\nDetermine Icon error : " . $e->getMessage() . "\n", FILE_APPEND);
     	} */
     $activity = array('activity_id' => NULL, 'timestamp' => $file['mtime'], 'priority' => 30, 'type' => 'file_created', 'user' => $file['owner'], 'affecteduser' => $file['owner'], 'app' => 'files', 'subject' => 'created_self', 'subjectparams' => '["\\/' . $file['filename'] . '"]', 'message' => '', 'messageparams' => '[]', 'file' => '/' . $file['filename'], 'link' => $file['domain'] . '/index.php/apps/files?dir=%2F', 'object_type' => 'files', 'object_id' => $filecache);
     $id = $this->connect->insert('*PREFIX*activity', $activity);
     if ($id) {
         return $filecache;
     } else {
         return false;
     }
 }
Exemplo n.º 21
0
 /**
  * return the content of a file or return a zip file containing multiple files
  *
  * @param string $dir
  * @param string $file ; separated list of files to download
  * @param boolean $only_header ; boolean to only send header of the request
  */
 public static function get($dir, $files, $only_header = false)
 {
     $xsendfile = false;
     if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
         $xsendfile = true;
     }
     if (is_array($files) && count($files) == 1) {
         $files = $files[0];
     }
     if (is_array($files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         if ($xsendfile) {
             $filename = OC_Helper::tmpFileNoClean('.zip');
         } else {
             $filename = OC_Helper::tmpFile('.zip');
         }
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             exit("cannot open <{$filename}>\n");
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (\OC\Files\Filesystem::is_file($file)) {
                 $tmpFile = \OC\Files\Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (\OC\Files\Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
         $basename = basename($dir);
         if ($basename) {
             $name = $basename . '.zip';
         } else {
             $name = 'owncloud.zip';
         }
         set_time_limit($executionTime);
     } elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         if ($xsendfile) {
             $filename = OC_Helper::tmpFileNoClean('.zip');
         } else {
             $filename = OC_Helper::tmpFile('.zip');
         }
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             exit("cannot open <{$filename}>\n");
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
         $name = $files . '.zip';
         set_time_limit($executionTime);
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
         $name = $files;
     }
     OC_Util::obEnd();
     if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
         if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
             header('Content-Disposition: attachment; filename="' . rawurlencode($name) . '"');
         } else {
             header('Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($name) . '; filename="' . rawurlencode($name) . '"');
         }
         header('Content-Transfer-Encoding: binary');
         OC_Response::disableCaching();
         if ($zip) {
             ini_set('zlib.output_compression', 'off');
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
             self::addSendfileHeader($filename);
         } else {
             header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
             header("Content-Length: " . \OC\Files\Filesystem::filesize($filename));
             list($storage) = \OC\Files\Filesystem::resolvePath($filename);
             if ($storage instanceof \OC\Files\Storage\Local) {
                 self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
             }
         }
     } elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $name);
         $tmpl->printPage();
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if ($only_header) {
         return;
     }
     if ($zip) {
         $handle = fopen($filename, 'r');
         if ($handle) {
             $chunkSize = 8 * 1024;
             // 1 MB chunks
             while (!feof($handle)) {
                 echo fread($handle, $chunkSize);
                 flush();
             }
         }
         if (!$xsendfile) {
             unlink($filename);
         }
     } else {
         \OC\Files\Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
Exemplo n.º 22
0
 /**
  * resolve a path to a storage and internal path
  *
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  * @param string $path
  * @return array consisting of the storage and the internal path
  */
 public static function resolvePath($path)
 {
     return \OC\Files\Filesystem::resolvePath($path);
 }
Exemplo n.º 23
0
 /**
  * get the new data array from the old one
  *
  * @param array $data the data from the old cache
  * Example data array
  * Array
  *	(
  *		[id] => 418
  *		[path] => /tina/files/picture.jpg		//relative to datadir
  *		[path_hash] => 66d4547e372888deed80b24fec9b192b
  *		[parent] => 234
  *		[name] => picture.jpg
  *		[user] => tina
  *		[size] => 1265283
  *		[ctime] => 1363909709
  *		[mtime] => 1363909709
  *		[mimetype] => image/jpeg
  *		[mimepart] => image
  *		[encrypted] => 0
  *		[versioned] => 0
  *		[writable] => 1
  *	)
  *
  * @return array
  */
 function getNewData($data)
 {
     //Make sure there is a path, otherwise we can do nothing.
     if (!isset($data['path'])) {
         return false;
     }
     $newData = $data;
     /**
      * @var \OC\Files\Storage\Storage $storage
      * @var string $internalPath;
      */
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
     if ($storage) {
         $newData['etag'] = $data['etag'];
         $newData['path_hash'] = md5($internalPath);
         $newData['path'] = $internalPath;
         $newData['storage'] = $this->getNumericId($storage);
         $newData['parent'] = $internalPath === '' ? -1 : $data['parent'];
         $newData['permissions'] = $data['writable'] ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
         $newData['storage_object'] = $storage;
         $newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
         $newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage);
         return $newData;
     } else {
         \OC_Log::write('core', 'Unable to migrate data from old cache for ' . $data['path'] . ' because the storage was not found', \OC_Log::ERROR);
         return false;
     }
 }
Exemplo n.º 24
0
 /**
  * Test that an external cache is mounted into
  * the user's home
  */
 public function testMountExternalCacheDir()
 {
     $userId = $this->getUniqueID('user_');
     $config = \OC::$server->getConfig();
     $oldCachePath = $config->getSystemValue('cache_path', '');
     // set cache path to temp dir
     $cachePath = \OC::$server->getTempManager()->getTemporaryFolder() . '/extcache';
     $config->setSystemValue('cache_path', $cachePath);
     \OC::$server->getUserManager()->createUser($userId, $userId);
     \OC\Files\Filesystem::initMountPoints($userId);
     $this->assertEquals('/' . $userId . '/cache/', \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache'));
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
     $this->assertTrue($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local'));
     $this->assertEquals('', $internalPath);
     $user = \OC::$server->getUserManager()->get($userId);
     if ($user !== null) {
         $user->delete();
     }
     $config->setSystemValue('cache_path', $oldCachePath);
 }
Exemplo n.º 25
0
 /**
  * return the content of a file or return a zip file containing multiple files
  *
  * @param string $dir
  * @param string $file ; separated list of files to download
  * @param boolean $only_header ; boolean to only send header of the request
  */
 public static function get($dir, $files, $only_header = false)
 {
     $xsendfile = false;
     if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
         $xsendfile = true;
     }
     if (is_array($files) && count($files) == 1) {
         $files = $files[0];
     }
     if (is_array($files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         $filename = OC_Helper::tmpFile('.zip');
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             $l = OC_L10N::get('lib');
             throw new Exception($l->t('cannot open "%s"', array($filename)));
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (\OC\Files\Filesystem::is_file($file)) {
                 $tmpFile = \OC\Files\Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (\OC\Files\Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
         if ($xsendfile) {
             $filename = OC_Helper::moveToNoClean($filename);
         }
         $basename = basename($dir);
         if ($basename) {
             $name = $basename . '.zip';
         } else {
             $name = 'download.zip';
         }
         set_time_limit($executionTime);
     } elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         $filename = OC_Helper::tmpFile('.zip');
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             $l = OC_L10N::get('lib');
             throw new Exception($l->t('cannot open "%s"', array($filename)));
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
         if ($xsendfile) {
             $filename = OC_Helper::moveToNoClean($filename);
         }
         $name = $files . '.zip';
         set_time_limit($executionTime);
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
         $name = $files;
         if ($xsendfile && OC_App::isEnabled('files_encryption')) {
             $xsendfile = false;
         }
     }
     OC_Util::obEnd();
     if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
         OC_Response::setContentDispositionHeader($name, 'attachment');
         header('Content-Transfer-Encoding: binary');
         OC_Response::disableCaching();
         if ($zip) {
             ini_set('zlib.output_compression', 'off');
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
             self::addSendfileHeader($filename);
         } else {
             $filesize = \OC\Files\Filesystem::filesize($filename);
             header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
             if ($filesize > -1) {
                 header("Content-Length: " . $filesize);
             }
             if ($xsendfile) {
                 list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename));
                 /**
                  * @var \OC\Files\Storage\Storage $storage
                  */
                 if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local')) {
                     self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
                 }
             }
         }
     } elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $name);
         $tmpl->printPage();
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if ($only_header) {
         return;
     }
     if ($zip) {
         $handle = fopen($filename, 'r');
         if ($handle) {
             $chunkSize = 8 * 1024;
             // 1 MB chunks
             while (!feof($handle)) {
                 echo fread($handle, $chunkSize);
                 flush();
             }
         }
         if (!$xsendfile) {
             unlink($filename);
         }
     } else {
         \OC\Files\Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
Exemplo n.º 26
0
 /**
  * Test that an external cache is mounted into
  * the user's home
  */
 public function testMountExternalCacheDir()
 {
     $userId = $this->getUniqueID('user_');
     $oldCachePath = \OC_Config::getValue('cache_path', '');
     // set cache path to temp dir
     $cachePath = \OC_Helper::tmpFolder() . '/extcache';
     \OC_Config::setValue('cache_path', $cachePath);
     \OC_User::createUser($userId, $userId);
     \OC\Files\Filesystem::initMountPoints($userId);
     $this->assertEquals('/' . $userId . '/cache/', \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache'));
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
     $this->assertTrue($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local'));
     $this->assertEquals('', $internalPath);
     \OC_User::deleteUser($userId);
     \OC_Config::setValue('cache_path', $oldCachePath);
 }
Exemplo n.º 27
0
 /**
  * Resolve the path for the source of the share
  *
  * @param string $path
  * @return array
  */
 private function resolvePath($path)
 {
     $source = $this->getSourcePath($path);
     return \OC\Files\Filesystem::resolvePath($source);
 }
Exemplo n.º 28
0
 public function testGetPathByIdShareSubFolder()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     \OC\Files\Filesystem::mkdir('foo');
     \OC\Files\Filesystem::mkdir('foo/bar');
     \OC\Files\Filesystem::touch('foo/bar/test.txt');
     $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
     $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
     $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
     $node = $rootFolder->get('foo');
     $share = $this->shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $this->shareManager->createShare($share);
     \OC_Util::tearDownFS();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
     list($sharedStorage) = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
     /**
      * @var \OC\Files\Storage\Shared $sharedStorage
      */
     $sharedCache = $sharedStorage->getCache();
     $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
     $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
 }