Example #1
0
 /**
  * @param string $filename
  * @param string $name
  */
 private static function sendHeaders($filename, $name)
 {
     OC_Response::setContentDispositionHeader($name, 'attachment');
     header('Content-Transfer-Encoding: binary');
     OC_Response::disableCaching();
     $filesize = \OC\Files\Filesystem::filesize($filename);
     header('Content-Type: ' . \OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)));
     if ($filesize > -1) {
         OC_Response::setContentLengthHeader($filesize);
     }
 }
Example #2
0
 /**
  * scan a file for music
  *
  * @param string $path
  * @return boolean
  */
 public function scanFile($path)
 {
     $mimeType = \OC\Files\Filesystem::getMimeType($path);
     if ($mimeType === 'application/ogg' or substr($mimeType, 0, 5) === 'audio') {
         $track = new Track($path);
         $data = $track->getTags();
         if (!empty($data)) {
             $artistId = $this->collection->addArtist($data['artist']);
             $albumId = $this->collection->addAlbum($data['album'], $artistId);
             $this->collection->addSong($data['title'], $path, $artistId, $albumId, $data['length'], $data['track'], $data['size']);
         }
     }
     return true;
 }
Example #3
0
 /**
  * @param string $filename
  * @param string $name
  * @param boolean $isAttachment ; enforce download of file
  */
 private static function sendHeaders($filename, $name, $isAttachment = true)
 {
     if ($isAttachment) {
         OC_Response::setContentDispositionHeader($name, 'attachment');
     }
     header('Content-Transfer-Encoding: binary');
     OC_Response::disableCaching();
     $fileSize = \OC\Files\Filesystem::filesize($filename);
     $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
     header('Content-Type: ' . $type);
     if ($fileSize > -1) {
         OC_Response::setContentLengthHeader($fileSize);
     }
 }
Example #4
0
 /**
  * @param string $filename
  * @param string $name
  * @param bool $zip
  */
 private static function sendHeaders($filename, $name, $zip = false)
 {
     OC_Response::setContentDispositionHeader($name, 'attachment');
     header('Content-Transfer-Encoding: binary');
     OC_Response::disableCaching();
     if ($zip) {
         header('Content-Type: application/zip');
     } else {
         $filesize = \OC\Files\Filesystem::filesize($filename);
         header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
         if ($filesize > -1) {
             header("Content-Length: " . $filesize);
         }
     }
 }
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $path
  * @return TemplateResponse|RedirectResponse
  */
 public function showShare($token, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     // Check whether share exists
     $linkItem = Share::getShareByToken($token, false);
     if ($linkItem === false) {
         return new NotFoundResponse();
     }
     $shareOwner = $linkItem['uid_owner'];
     $originalSharePath = $this->getPath($token);
     // Share is password protected - check whether the user is permitted to access the share
     if (isset($linkItem['share_with']) && !Helper::authenticate($linkItem)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
     }
     if (Filesystem::isReadable($originalSharePath . $path)) {
         $getPath = Filesystem::normalizePath($path);
         $originalSharePath .= $path;
     } else {
         throw new OCP\Files\NotFoundException();
     }
     $file = basename($originalSharePath);
     $shareTmpl = [];
     $shareTmpl['displayName'] = User::getDisplayName($shareOwner);
     $shareTmpl['filename'] = $file;
     $shareTmpl['directory_path'] = $linkItem['file_target'];
     $shareTmpl['mimetype'] = Filesystem::getMimeType($originalSharePath);
     $shareTmpl['previewSupported'] = \OC::$server->getPreviewManager()->isMimeSupported($shareTmpl['mimetype']);
     $shareTmpl['dirToken'] = $linkItem['token'];
     $shareTmpl['sharingToken'] = $token;
     $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
     $shareTmpl['protected'] = isset($linkItem['share_with']) ? 'true' : 'false';
     $shareTmpl['dir'] = '';
     $nonHumanFileSize = \OC\Files\Filesystem::filesize($originalSharePath);
     $shareTmpl['nonHumanFileSize'] = $nonHumanFileSize;
     $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($nonHumanFileSize);
     // Show file list
     if (Filesystem::is_dir($originalSharePath)) {
         $shareTmpl['dir'] = $getPath;
         $maxUploadFilesize = Util::maxUploadFilesize($originalSharePath);
         $freeSpace = Util::freeSpace($originalSharePath);
         $uploadLimit = Util::uploadLimit();
         $folder = new Template('files', 'list', '');
         $folder->assign('dir', $getPath);
         $folder->assign('dirToken', $linkItem['token']);
         $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
         $folder->assign('isPublic', true);
         $folder->assign('publicUploadEnabled', 'no');
         $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
         $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
         $folder->assign('freeSpace', $freeSpace);
         $folder->assign('uploadLimit', $uploadLimit);
         // PHP upload limit
         $folder->assign('usedSpacePercent', 0);
         $folder->assign('trash', false);
         $shareTmpl['folder'] = $folder->fetchPage();
     }
     $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
     $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
     $csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
     $csp->addAllowedFrameDomain('\'self\'');
     $response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
     $response->setContentSecurityPolicy($csp);
     return $response;
 }
Example #6
0
 /**
  * Returns the mime-type for a file
  *
  * If null is returned, we'll assume application/octet-stream
  *
  * @return mixed
  */
 public function getContentType()
 {
     if (isset($this->fileinfo_cache['mimetype'])) {
         $mimeType = $this->fileinfo_cache['mimetype'];
     } else {
         $mimeType = \OC\Files\Filesystem::getMimeType($this->path);
     }
     return \OC_Helper::getSecureMimeType($mimeType);
 }
Example #7
0
 /**
  * Returns the mime-type for a file
  *
  * If null is returned, we'll assume application/octet-stream
  *
  * @return mixed
  */
 public function getContentType()
 {
     if (isset($this->fileinfo_cache['mimetype'])) {
         return $this->fileinfo_cache['mimetype'];
     }
     return \OC\Files\Filesystem::getMimeType($this->path);
 }
Example #8
0
<?php

/**
 * ownCloud - Documents App
 *
 * @author Victor Dubiniuk
 * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Documents;

\OCP\JSON::checkLoggedIn();
$path = Helper::getArrayValueByKey($_GET, 'path');
if (!empty($path)) {
    if (\OC\Files\Filesystem::getMimeType($path) !== Filter_Office::NATIVE_MIMETYPE) {
        $fileInfo = \OC\Files\Filesystem::getFileInfo($path);
        $file = new File($fileInfo->getId());
        $genesis = new Genesis($file);
        $fullPath = $genesis->getPath();
    } else {
        $fullPath = '/files' . $path;
    }
    $download = new Download(\OCP\User::getUser(), $fullPath);
    $download->sendResponse();
}
exit;
Example #9
0
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
// Set the session key for the file we are about to edit.
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$filename = isset($_GET['file']) ? $_GET['file'] : '';
if (!empty($filename)) {
    $path = $dir . '/' . $filename;
    $writeable = \OC\Files\Filesystem::isUpdatable($path);
    $mime = \OC\Files\Filesystem::getMimeType($path);
    $mtime = \OC\Files\Filesystem::filemtime($path);
    $filecontents = \OC\Files\Filesystem::file_get_contents($path);
    $encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
    if ($encoding == "") {
        // set default encoding if it couldn't be detected
        $encoding = 'ISO-8859-15';
    }
    $filecontents = iconv($encoding, "UTF-8", $filecontents);
    OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'writeable' => $writeable, 'mime' => $mime, 'mtime' => $mtime)));
} else {
    OCP\JSON::error(array('data' => array('message' => 'Invalid file path supplied.')));
}
Example #10
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);
         }
     }
 }
Example #11
0
 /**
  * @param View $view
  * @param string $name
  * @param string $dir
  * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header
  */
 private static function getSingleFile($view, $dir, $name, $params)
 {
     $filename = $dir . '/' . $name;
     OC_Util::obEnd();
     $view->lockFile($filename, ILockingProvider::LOCK_SHARED);
     $rangeArray = array();
     if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') {
         $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), \OC\Files\Filesystem::filesize($filename));
     }
     if (\OC\Files\Filesystem::isReadable($filename)) {
         self::sendHeaders($filename, $name, $rangeArray);
     } elseif (!\OC\Files\Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->printPage();
         exit;
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if (isset($params['head']) && $params['head']) {
         return;
     }
     if (!empty($rangeArray)) {
         try {
             if (count($rangeArray) == 1) {
                 $view->readfilePart($filename, $rangeArray[0]['from'], $rangeArray[0]['to']);
             } else {
                 // check if file is seekable (if not throw UnseekableException)
                 // we have to check it before body contents
                 $view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']);
                 $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
                 foreach ($rangeArray as $range) {
                     echo "\r\n--" . self::getBoundary() . "\r\n" . "Content-type: " . $type . "\r\n" . "Content-range: bytes " . $range['from'] . "-" . $range['to'] . "/" . $range['size'] . "\r\n\r\n";
                     $view->readfilePart($filename, $range['from'], $range['to']);
                 }
                 echo "\r\n--" . self::getBoundary() . "--\r\n";
             }
         } catch (\OCP\Files\UnseekableException $ex) {
             // file is unseekable
             header_remove('Accept-Ranges');
             header_remove('Content-Range');
             header("HTTP/1.1 200 OK");
             self::sendHeaders($filename, $name, array());
             $view->readfile($filename);
         }
     } else {
         $view->readfile($filename);
     }
 }
Example #12
0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!\OC\Files\Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename));
OC_Util::obEnd();
\OC\Files\Filesystem::readfile($filename);
Example #13
0
<?php

// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!\OC\Files\Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = \OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename));
OC_Util::obEnd();
\OC\Files\Filesystem::readfile($filename);
Example #14
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);
         }
     }
 }
Example #15
0
	//400 Bad Request
	\OC_Response::setStatus(400);
	\OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
	exit;
}

if ($maxX === 0 || $maxY === 0) {
	//400 Bad Request
	\OC_Response::setStatus(400);
	\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
	exit;
}

try {
	$preview = new \OC\Preview(\OC_User::getUser(), 'files');
	if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) {
		\OC_Response::setStatus(404);
	} else {
		$preview->setFile($file);
		$preview->setMaxX($maxX);
		$preview->setMaxY($maxY);
		$preview->setScalingUp($scalingUp);
		$preview->setKeepAspect($keepAspect);
	}

	$preview->showPreview();
} catch (\Exception $e) {
	\OC_Response::setStatus(500);
	\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
}
Example #16
0
         $songId = $collection->getSongByPath($arguments['path']);
         if ($songId == 0) {
             unset($_SESSION['collection']);
             $scanner = new Scanner($collection);
             $songId = $scanner->scanFile($arguments['path']);
         }
         if ($songId > 0) {
             $song = $collection->getSong($songId);
             $song['artist'] = $collection->getArtistName($song['song_artist']);
             $song['album'] = $collection->getAlbumName($song['song_album']);
             \OCP\JSON::encodedPrint($song);
         }
     }
     break;
 case 'play':
     $ftype = \OC\Files\Filesystem::getMimeType($arguments['path']);
     if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') {
         echo 'Not an audio file';
         exit;
     }
     $songId = $collection->getSongByPath($arguments['path']);
     $collection->registerPlay($songId);
     header('Content-Type:' . $ftype);
     \OCP\Response::enableCaching(3600 * 24);
     // 24 hour
     header('Accept-Ranges: bytes');
     header('Content-Length: ' . \OC\Files\Filesystem::filesize($arguments['path']));
     $mtime = \OC\Files\Filesystem::filemtime($arguments['path']);
     \OCP\Response::setLastModifiedHeader($mtime);
     \OC\Files\Filesystem::readfile($arguments['path']);
     exit;
Example #17
0
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!\OC\Files\Filesystem::file_exists($filename)) {
    header("HTTP/1.0 404 Not Found");
    $tmpl = new OCP\Template('', '404', 'guest');
    $tmpl->assign('file', $filename);
    $tmpl->printPage();
    exit;
}
$ftype = \OC\Files\Filesystem::getMimeType($filename);
header('Content-Type:' . $ftype);
if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
    header('Content-Disposition: attachment; filename="' . rawurlencode(basename($filename)) . '"');
} else {
    header('Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode(basename($filename)) . '; filename="' . rawurlencode(basename($filename)) . '"');
}
OCP\Response::disableCaching();
header('Content-Length: ' . \OC\Files\Filesystem::filesize($filename));
OC_Util::obEnd();
\OC\Files\Filesystem::readfile($filename);
Example #18
0
 /**
  * @param View $view
  * @param string $name
  */
 private static function getSingleFile($view, $dir, $name, $onlyHeader)
 {
     $filename = $dir . '/' . $name;
     OC_Util::obEnd();
     $view->lockFile($filename, ILockingProvider::LOCK_SHARED);
     if (\OC\Files\Filesystem::isReadable($filename)) {
         self::sendHeaders($filename, $name);
     } elseif (!\OC\Files\Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->printPage();
         exit;
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if ($onlyHeader) {
         return;
     }
     $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
     $pos = strpos(strtolower($type), "video");
     if ($pos != -1) {
         $view->streamVideoFile($filename);
     } else {
         $view->readfile($filename);
     }
 }
Example #19
0
     }
     exit;
 } else {
     OCP\Util::addScript('files', 'file-upload');
     OCP\Util::addStyle('files_sharing', 'public');
     OCP\Util::addStyle('files_sharing', 'mobile');
     OCP\Util::addScript('files_sharing', 'public');
     OCP\Util::addScript('files', 'fileactions');
     OCP\Util::addScript('files', 'jquery.iframe-transport');
     OCP\Util::addScript('files', 'jquery.fileupload');
     $maxUploadFilesize = OCP\Util::maxUploadFilesize($path);
     $tmpl = new OCP\Template('files_sharing', 'public', 'base');
     $tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
     $tmpl->assign('filename', $file);
     $tmpl->assign('directory_path', $linkItem['file_target']);
     $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
     $tmpl->assign('dirToken', $linkItem['token']);
     $tmpl->assign('sharingToken', $token);
     $tmpl->assign('protected', isset($linkItem['share_with']) ? 'true' : 'false');
     $urlLinkIdentifiers = (isset($token) ? '&t=' . $token : '') . (isset($_GET['dir']) ? '&dir=' . $_GET['dir'] : '') . (isset($_GET['file']) ? '&file=' . $_GET['file'] : '');
     // Show file list
     if (\OC\Files\Filesystem::is_dir($path)) {
         $tmpl->assign('dir', $getPath);
         OCP\Util::addStyle('files', 'files');
         OCP\Util::addStyle('files', 'upload');
         OCP\Util::addScript('files', 'filesummary');
         OCP\Util::addScript('files', 'breadcrumb');
         OCP\Util::addScript('files', 'files');
         OCP\Util::addScript('files', 'filelist');
         OCP\Util::addscript('files', 'keyboardshortcuts');
         $files = array();
Example #20
0
<?php

/**
 * ownCloud - Documents App
 *
 * @author Victor Dubiniuk
 * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Documents;

\OCP\JSON::checkLoggedIn();
$path = Helper::getArrayValueByKey($_GET, 'path');
if (!empty($path)) {
    if (\OC\Files\Filesystem::getMimeType($path) !== \OCA\Documents\Filter\Office::NATIVE_MIMETYPE) {
        $fileInfo = \OC\Files\Filesystem::getFileInfo($path);
        $file = new File($fileInfo->getId());
        $genesis = new Genesis($file);
        $fullPath = $genesis->getPath();
    } else {
        $fullPath = '/files' . $path;
    }
    $download = new Download(\OCP\User::getUser(), $fullPath);
    $download->sendResponse();
}
exit;
Example #21
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $path
  * @return TemplateResponse
  */
 public function showShare($token, $path = '')
 {
     \OC_User::setIncognitoMode(true);
     // Check whether share exists
     $linkItem = Share::getShareByToken($token, false);
     if ($linkItem === false) {
         return new TemplateResponse('core', '404', array(), 'guest');
     }
     $linkItem = OCP\Share::getShareByToken($token, false);
     $shareOwner = $linkItem['uid_owner'];
     $originalSharePath = null;
     $rootLinkItem = OCP\Share::resolveReShare($linkItem);
     if (isset($rootLinkItem['uid_owner'])) {
         OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
         OC_Util::tearDownFS();
         OC_Util::setupFS($rootLinkItem['uid_owner']);
         $originalSharePath = Filesystem::getPath($linkItem['file_source']);
     }
     // Share is password protected - check whether the user is permitted to access the share
     if (isset($linkItem['share_with']) && !Helper::authenticate($linkItem)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
     }
     if (Filesystem::isReadable($originalSharePath . $path)) {
         $getPath = Filesystem::normalizePath($path);
         $originalSharePath .= $path;
     }
     $file = basename($originalSharePath);
     $shareTmpl = array();
     $shareTmpl['displayName'] = User::getDisplayName($shareOwner);
     $shareTmpl['filename'] = $file;
     $shareTmpl['directory_path'] = $linkItem['file_target'];
     $shareTmpl['mimetype'] = Filesystem::getMimeType($originalSharePath);
     $shareTmpl['dirToken'] = $linkItem['token'];
     $shareTmpl['sharingToken'] = $token;
     $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
     $shareTmpl['protected'] = isset($linkItem['share_with']) ? 'true' : 'false';
     $shareTmpl['dir'] = '';
     $shareTmpl['fileSize'] = \OCP\Util::humanFileSize(\OC\Files\Filesystem::filesize($originalSharePath));
     // Show file list
     if (Filesystem::is_dir($originalSharePath)) {
         $shareTmpl['dir'] = $getPath;
         $files = array();
         $maxUploadFilesize = Util::maxUploadFilesize($originalSharePath);
         $freeSpace = Util::freeSpace($originalSharePath);
         $uploadLimit = Util::uploadLimit();
         $folder = new Template('files', 'list', '');
         $folder->assign('dir', $getPath);
         $folder->assign('dirToken', $linkItem['token']);
         $folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
         $folder->assign('isPublic', true);
         $folder->assign('publicUploadEnabled', 'no');
         $folder->assign('files', $files);
         $folder->assign('uploadMaxFilesize', $maxUploadFilesize);
         $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
         $folder->assign('freeSpace', $freeSpace);
         $folder->assign('uploadLimit', $uploadLimit);
         // PHP upload limit
         $folder->assign('usedSpacePercent', 0);
         $folder->assign('trash', false);
         $shareTmpl['folder'] = $folder->fetchPage();
     }
     $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
     return new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
 }
Example #22
0
 /**
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  */
 public static function getMimeType($path)
 {
     return \OC\Files\Filesystem::getMimeType($path);
 }