Ejemplo n.º 1
0
 public function file_assemble($path)
 {
     $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path));
     $data = '';
     // use file_put_contents as method because that best matches what this function does
     if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) {
         $path = OC_Filesystem::getView()->getRelativePath($absolutePath);
         $exists = OC_Filesystem::file_exists($path);
         $run = true;
         if (!$exists) {
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
         }
         OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
         if (!$run) {
             return false;
         }
         $target = OC_Filesystem::fopen($path, 'w');
         if ($target) {
             $count = $this->assemble($target);
             fclose($target);
             if (!$exists) {
                 OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array(OC_Filesystem::signal_param_path => $path));
             }
             OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array(OC_Filesystem::signal_param_path => $path));
             OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
             return $count > 0;
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @brief abstraction layer for basic filesystem functions: wrapper for OC_Filestorage
  * @param string $operation
  * @param string #path
  * @param array (optional) hooks
  * @param mixed (optional) $extraParam
  * @return mixed
  *
  * This method takes requests for basic filesystem functions (e.g. reading & writing
  * files), processes hooks and proxies, sanitises paths, and finally passes them on to
  * OC_Filestorage for delegation to a storage backend for execution
  */
 private function basicOperation($operation, $path, $hooks = array(), $extraParam = null)
 {
     $postFix = substr($path, -1, 1) === '/' ? '/' : '';
     $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
     if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
         $path = $this->getRelativePath($absolutePath);
         if ($path == null) {
             return false;
         }
         $internalPath = $this->getInternalPath($path . $postFix);
         $run = $this->runHooks($hooks, $path);
         if ($run and $storage = $this->getStorage($path . $postFix)) {
             if (!is_null($extraParam)) {
                 $result = $storage->{$operation}($internalPath, $extraParam);
             } else {
                 $result = $storage->{$operation}($internalPath);
             }
             $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
             if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
                 if ($operation != 'fopen') {
                     //no post hooks for fopen, the file stream is still open
                     $this->runHooks($hooks, $path, true);
                 }
             }
             return $result;
         }
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * abstraction for running most basic operations
  * @param string $operation
  * @param string #path
  * @param array (optional) hooks
  * @param mixed (optional) $extraParam
  * @return mixed
  */
 private function basicOperation($operation, $path, $hooks = array(), $extraParam = null)
 {
     $absolutePath = $this->getAbsolutePath($path);
     if (OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
         $path = $this->getRelativePath($absolutePath);
         if ($path == null) {
             return false;
         }
         $internalPath = $this->getInternalPath($path);
         $run = true;
         if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
             foreach ($hooks as $hook) {
                 if ($hook != 'read') {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run));
                 } else {
                     OC_Hook::emit(OC_Filesystem::CLASSNAME, $hook, array(OC_Filesystem::signal_param_path => $path));
                 }
             }
         }
         if ($run and $storage = $this->getStorage($path)) {
             if (!is_null($extraParam)) {
                 $result = $storage->{$operation}($internalPath, $extraParam);
             } else {
                 $result = $storage->{$operation}($internalPath);
             }
             $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
             if (OC_Filesystem::$loaded and $this->fakeRoot == OC_Filesystem::getRoot()) {
                 if ($operation != 'fopen') {
                     //no post hooks for fopen, the file stream is still open
                     foreach ($hooks as $hook) {
                         if ($hook != 'read') {
                             OC_Hook::emit(OC_Filesystem::CLASSNAME, 'post_' . $hook, array(OC_Filesystem::signal_param_path => $path));
                         }
                     }
                 }
             }
             return $result;
         }
     }
     return null;
 }
Ejemplo n.º 4
0
     } else {
         if (!isset($_SESSION['public_link_authenticated']) || $_SESSION['public_link_authenticated'] !== $linkItem['id']) {
             // Prompt for password
             $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
             $tmpl->assign('URL', $url);
             $tmpl->printPage();
             exit;
         }
     }
 }
 $basePath = substr($pathAndUser['path'], strlen('/' . $fileOwner . '/files'));
 $path = $basePath;
 if (isset($_GET['path'])) {
     $path .= $_GET['path'];
 }
 if (!$path || !OC_Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
     OCP\Util::writeLog('share', 'Invalid path ' . $path . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
     header('HTTP/1.0 404 Not Found');
     $tmpl = new OCP\Template('', '404', 'guest');
     $tmpl->printPage();
     exit;
 }
 $dir = dirname($path);
 $file = basename($path);
 // Download the file
 if (isset($_GET['download'])) {
     if (isset($_GET['path']) && $_GET['path'] !== '') {
         if (isset($_GET['files'])) {
             // download selected files
             OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
         } else {