/**
  * download file
  * 
  * @param string $path
  */
 public function downloadNode($path)
 {
     try {
         $splittedPath = explode('/', trim($path, '/'));
         $downloadId = array_shift($splittedPath);
         $download = $this->_getDownloadLink($downloadId);
         $this->_setDownloadLinkOwnerAsUser($download);
         $node = Filemanager_Controller_DownloadLink::getInstance()->getNode($download, $splittedPath);
         if ($node->type === Tinebase_Model_Tree_Node::TYPE_FILE) {
             $nodeController = Filemanager_Controller_Node::getInstance();
             $nodeController->resolveMultipleTreeNodesPath($node);
             $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($node->path));
             Filemanager_Controller_DownloadLink::getInstance()->increaseAccessCount($download);
             $this->_downloadFileNode($node, $pathRecord->streamwrapperpath);
         }
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' exception: ' . $e->getMessage());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' exception: ' . $e->getTraceAsString());
         }
         header('HTTP/1.0 404 Not found');
         $view = new Zend_View();
         $view->setScriptPath('Filemanager/views');
         header('Content-Type: text/html; charset=utf-8');
         die($view->render('notfound.phtml'));
     }
     exit;
 }
Ejemplo n.º 2
0
 /**
  * parse given path (filter value): check validity, set container type, do replacements
  */
 protected function _parsePath()
 {
     $this->_path = Tinebase_Model_Tree_Node_Path::createFromPath($this->_value);
     if (!$this->_options['ignoreAcl'] && !Tinebase_Core::getUser()->hasRight($this->_path->application->name, Tinebase_Acl_Rights_Abstract::RUN)) {
         throw new Tinebase_Exception_AccessDenied('You don\'t have the right to run this application');
     }
 }
 /**
  * download file
  * 
  * @param string $path
  * @param string $id
  * 
  * @todo allow to download a folder as ZIP file
  */
 public function downloadFile($path, $id)
 {
     $nodeController = Filemanager_Controller_Node::getInstance();
     if ($path) {
         $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($path));
         $node = $nodeController->getFileNode($pathRecord);
     } elseif ($id) {
         $node = $nodeController->get($id);
         $nodeController->resolveMultipleTreeNodesPath($node);
         $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($node->path));
     } else {
         Tinebase_Exception_InvalidArgument('Either a path or id is needed to download a file.');
     }
     $this->_downloadFileNode($node, $pathRecord->streamwrapperpath);
     exit;
 }
Ejemplo n.º 4
0
 /**
  * download file
  * 
  * @param string $_path
  * 
  * @todo allow to download a folder as ZIP file
  */
 public function downloadFile($path)
 {
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Download file ' . $path);
     }
     $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath(Filemanager_Controller_Node::getInstance()->addBasePath($path));
     $node = Filemanager_Controller_Node::getInstance()->getFileNode($pathRecord);
     // cache for 3600 seconds
     $maxAge = 3600;
     header('Cache-Control: private, max-age=' . $maxAge);
     header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
     // overwrite Pragma header from session
     header("Pragma: cache");
     header('Content-Disposition: attachment; filename="' . $node->name . '"');
     header("Content-Type: " . $node->contenttype);
     $handle = fopen($pathRecord->streamwrapperpath, 'r');
     fpassthru($handle);
     fclose($handle);
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     exit;
 }
 /**
  * delete node
  * 
  * @param string $_flatpath
  * @return boolean
  * @throws Tinebase_Exception_NotFound
  */
 protected function _deleteNode($_flatpath)
 {
     $flatpathWithBasepath = $this->addBasePath($_flatpath);
     list($parentPathRecord, $nodeName) = Tinebase_Model_Tree_Node_Path::getParentAndChild($flatpathWithBasepath);
     $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($flatpathWithBasepath);
     $this->_checkPathACL($parentPathRecord, 'delete');
     if (!$parentPathRecord->container) {
         // check acl for deleting toplevel container
         $this->_checkPathACL($pathRecord, 'delete');
     }
     $success = $this->_deleteNodeInBackend($pathRecord);
     if ($success && !$parentPathRecord->container) {
         if (!is_object($pathRecord->container)) {
             throw new Tinebase_Exception_NotFound('Container not found');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Delete container ' . $pathRecord->container->name);
         }
         Tinebase_Container::getInstance()->delete($pathRecord->container->getId());
     }
     return $success;
 }
 /**
  * testSetContainerInPathRecord
  * 
  * @todo move this to Tinebase?
  */
 public function testSetContainerInPathRecord()
 {
     $flatpath = Filemanager_Controller_Node::getInstance()->addBasePath('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . $this->_getPersonalFilemanagerContainer()->name);
     $path = Tinebase_Model_Tree_Node_Path::createFromPath($flatpath);
     $path->setContainer($this->_getSharedContainer());
     $this->assertEquals('/' . $this->_application->getId() . '/folders/shared/' . $this->_getSharedContainer()->getId(), $path->statpath);
     // move it back
     $path->setContainer($this->_getPersonalFilemanagerContainer());
     $this->assertEquals('/' . $this->_application->getId() . '/folders/personal/' . Tinebase_Core::getUser()->getId() . '/' . $this->_getPersonalFilemanagerContainer()->getId(), $path->statpath, 'wrong statpath: ' . print_r($path->toArray(), TRUE));
 }
 /**
  * checks filter acl and adds base path
  *
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string $_action get|update
  * @return Tinebase_Model_Tree_Node_Path
  * @throws Tinebase_Exception_AccessDenied
  */
 protected function _checkFilterACL(Tinebase_Model_Filter_FilterGroup $_filter, $_action = 'get')
 {
     if ($_filter === NULL) {
         $_filter = new Expressodriver_Model_NodeFilter();
     }
     $pathFilters = $_filter->getFilter('path', TRUE);
     if (count($pathFilters) !== 1) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . 'Exactly one path filter required.');
         }
         $pathFilter = count($pathFilters) > 1 ? $pathFilters[0] : new Tinebase_Model_Tree_Node_PathFilter(array('field' => 'path', 'operator' => 'equals', 'value' => '/'));
         $_filter->removeFilter('path');
         $_filter->addFilter($pathFilter);
     } else {
         $pathFilter = $pathFilters[0];
     }
     // add base path and check grants
     try {
         $path = Tinebase_Model_Tree_Node_Path::createFromPath($this->addBasePath($pathFilter->getValue()));
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
             Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not determine path, setting root path (' . $e->getMessage() . ')');
         }
         $path = Tinebase_Model_Tree_Node_Path::createFromPath($this->addBasePath('/'));
     }
     $pathFilter->setValue($path);
     $this->_checkPathACL($path, $_action);
     return $path;
 }