2012-11-04 21:42:18 +04:00
|
|
|
<?php
|
|
|
|
// Load other apps for file previews
|
|
|
|
OC_App::loadApps();
|
|
|
|
|
2014-02-13 19:28:49 +04:00
|
|
|
$appConfig = \OC::$server->getAppConfig();
|
|
|
|
|
|
|
|
if ($appConfig->getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
|
2013-05-02 04:39:02 +04:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
|
|
|
$tmpl = new OCP\Template('', '404', 'guest');
|
|
|
|
$tmpl->printPage();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2013-02-11 14:50:41 +04:00
|
|
|
function fileCmp($a, $b) {
|
|
|
|
if ($a['type'] == 'dir' and $b['type'] != 'dir') {
|
|
|
|
return -1;
|
|
|
|
} elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return strnatcasecmp($a['name'], $b['name']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 02:40:35 +04:00
|
|
|
function determineIcon($file, $sharingRoot, $sharingToken) {
|
|
|
|
// for folders we simply reuse the files logic
|
|
|
|
if($file['type'] == 'dir') {
|
2013-09-20 18:46:33 +04:00
|
|
|
return \OCA\Files\Helper::determineIcon($file);
|
2013-09-12 02:40:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$relativePath = substr($file['path'], 6);
|
|
|
|
$relativePath = substr($relativePath, strlen($sharingRoot));
|
|
|
|
if($file['isPreviewAvailable']) {
|
2013-10-28 14:22:34 +04:00
|
|
|
return OCP\publicPreview_icon($relativePath, $sharingToken) . '&c=' . $file['etag'];
|
2013-09-12 02:40:35 +04:00
|
|
|
}
|
|
|
|
return OCP\mimetype_icon($file['mimetype']);
|
|
|
|
}
|
|
|
|
|
2012-11-12 17:44:00 +04:00
|
|
|
if (isset($_GET['t'])) {
|
|
|
|
$token = $_GET['t'];
|
2014-01-21 13:42:47 +04:00
|
|
|
$linkItem = OCP\Share::getShareByToken($token, false);
|
2012-11-12 17:44:00 +04:00
|
|
|
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
|
|
|
// seems to be a valid share
|
|
|
|
$type = $linkItem['item_type'];
|
|
|
|
$fileSource = $linkItem['file_source'];
|
|
|
|
$shareOwner = $linkItem['uid_owner'];
|
2013-02-11 04:09:58 +04:00
|
|
|
$path = null;
|
2013-07-05 19:39:41 +04:00
|
|
|
$rootLinkItem = OCP\Share::resolveReShare($linkItem);
|
2014-01-21 14:32:30 +04:00
|
|
|
if (isset($rootLinkItem['uid_owner'])) {
|
|
|
|
OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
|
2013-05-22 23:02:11 +04:00
|
|
|
OC_Util::tearDownFS();
|
2014-01-21 14:32:30 +04:00
|
|
|
OC_Util::setupFS($rootLinkItem['uid_owner']);
|
2013-02-11 04:09:58 +04:00
|
|
|
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
|
2012-11-23 18:51:57 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-22 20:21:57 +04:00
|
|
|
}
|
2013-02-11 04:09:58 +04:00
|
|
|
if (isset($path)) {
|
2012-11-23 18:51:57 +04:00
|
|
|
if (!isset($linkItem['item_type'])) {
|
2012-12-02 15:12:20 +04:00
|
|
|
OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
|
2012-11-23 18:51:57 +04:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
|
|
|
$tmpl = new OCP\Template('', '404', 'guest');
|
|
|
|
$tmpl->printPage();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
if (isset($linkItem['share_with'])) {
|
|
|
|
// Authenticate share_with
|
2012-12-02 15:12:20 +04:00
|
|
|
$url = OCP\Util::linkToPublic('files') . '&t=' . $token;
|
2012-11-23 18:51:57 +04:00
|
|
|
if (isset($_GET['file'])) {
|
2012-12-02 15:12:20 +04:00
|
|
|
$url .= '&file=' . urlencode($_GET['file']);
|
|
|
|
} else {
|
|
|
|
if (isset($_GET['dir'])) {
|
|
|
|
$url .= '&dir=' . urlencode($_GET['dir']);
|
|
|
|
}
|
2012-11-23 18:51:57 +04:00
|
|
|
}
|
|
|
|
if (isset($_POST['password'])) {
|
|
|
|
$password = $_POST['password'];
|
|
|
|
if ($linkItem['share_type'] == OCP\Share::SHARE_TYPE_LINK) {
|
|
|
|
// Check Password
|
|
|
|
$forcePortable = (CRYPT_BLOWFISH != 1);
|
|
|
|
$hasher = new PasswordHash(8, $forcePortable);
|
2013-01-09 16:57:51 +04:00
|
|
|
if (!($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''),
|
|
|
|
$linkItem['share_with']))) {
|
2013-10-07 19:38:27 +04:00
|
|
|
OCP\Util::addStyle('files_sharing', 'authenticate');
|
2012-11-04 21:42:18 +04:00
|
|
|
$tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
|
|
|
|
$tmpl->assign('URL', $url);
|
2013-07-02 05:16:42 +04:00
|
|
|
$tmpl->assign('wrongpw', true);
|
2012-11-04 21:42:18 +04:00
|
|
|
$tmpl->printPage();
|
|
|
|
exit();
|
2012-11-23 18:51:57 +04:00
|
|
|
} else {
|
|
|
|
// Save item id in session for future requests
|
2013-05-28 03:04:09 +04:00
|
|
|
\OC::$session->set('public_link_authenticated', $linkItem['id']);
|
2012-11-04 21:42:18 +04:00
|
|
|
}
|
2012-11-23 18:51:57 +04:00
|
|
|
} else {
|
2013-01-09 16:57:51 +04:00
|
|
|
OCP\Util::writeLog('share', 'Unknown share type '.$linkItem['share_type']
|
|
|
|
.' for share id '.$linkItem['id'], \OCP\Util::ERROR);
|
2012-11-12 17:44:00 +04:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
|
|
|
$tmpl = new OCP\Template('', '404', 'guest');
|
|
|
|
$tmpl->printPage();
|
|
|
|
exit();
|
|
|
|
}
|
2013-01-14 23:30:39 +04:00
|
|
|
|
2013-01-09 16:57:51 +04:00
|
|
|
} else {
|
|
|
|
// Check if item id is set in session
|
2013-05-28 03:04:09 +04:00
|
|
|
if ( ! \OC::$session->exists('public_link_authenticated')
|
|
|
|
|| \OC::$session->get('public_link_authenticated') !== $linkItem['id']
|
2013-01-09 16:57:51 +04:00
|
|
|
) {
|
|
|
|
// Prompt for password
|
2013-10-07 19:38:27 +04:00
|
|
|
OCP\Util::addStyle('files_sharing', 'authenticate');
|
2013-01-09 16:57:51 +04:00
|
|
|
$tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
|
|
|
|
$tmpl->assign('URL', $url);
|
|
|
|
$tmpl->printPage();
|
|
|
|
exit();
|
|
|
|
}
|
2012-11-23 18:51:57 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-10 09:53:58 +04:00
|
|
|
$basePath = $path;
|
2014-01-15 16:36:14 +04:00
|
|
|
$rootName = basename($path);
|
2013-02-11 14:38:52 +04:00
|
|
|
if (isset($_GET['path']) && \OC\Files\Filesystem::isReadable($basePath . $_GET['path'])) {
|
2013-02-10 09:53:58 +04:00
|
|
|
$getPath = \OC\Files\Filesystem::normalizePath($_GET['path']);
|
|
|
|
$path .= $getPath;
|
|
|
|
} else {
|
|
|
|
$getPath = '';
|
2012-11-23 18:51:57 +04:00
|
|
|
}
|
|
|
|
$dir = dirname($path);
|
|
|
|
$file = basename($path);
|
|
|
|
// Download the file
|
|
|
|
if (isset($_GET['download'])) {
|
2013-02-11 04:09:58 +04:00
|
|
|
if (isset($_GET['files'])) { // download selected files
|
2013-03-13 14:15:17 +04:00
|
|
|
$files = urldecode($_GET['files']);
|
|
|
|
$files_list = json_decode($files);
|
|
|
|
// in case we get only a single file
|
|
|
|
if ($files_list === NULL ) {
|
|
|
|
$files_list = array($files);
|
|
|
|
}
|
2013-08-17 14:58:10 +04:00
|
|
|
OC_Files::get($path, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
|
2013-02-11 04:09:58 +04:00
|
|
|
} else {
|
2013-08-17 14:58:10 +04:00
|
|
|
OC_Files::get($dir, $file, $_SERVER['REQUEST_METHOD'] == 'HEAD');
|
2012-11-23 18:51:57 +04:00
|
|
|
}
|
2013-02-11 04:09:58 +04:00
|
|
|
exit();
|
2012-11-23 18:51:57 +04:00
|
|
|
} else {
|
2013-06-25 14:24:14 +04:00
|
|
|
OCP\Util::addScript('files', 'file-upload');
|
2012-11-23 18:51:57 +04:00
|
|
|
OCP\Util::addStyle('files_sharing', 'public');
|
2014-01-15 01:14:06 +04:00
|
|
|
OCP\Util::addStyle('files_sharing', 'mobile');
|
2012-11-23 18:51:57 +04:00
|
|
|
OCP\Util::addScript('files_sharing', 'public');
|
|
|
|
OCP\Util::addScript('files', 'fileactions');
|
2013-06-25 14:24:14 +04:00
|
|
|
OCP\Util::addScript('files', 'jquery.iframe-transport');
|
|
|
|
OCP\Util::addScript('files', 'jquery.fileupload');
|
|
|
|
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
|
2012-11-23 18:51:57 +04:00
|
|
|
$tmpl = new OCP\Template('files_sharing', 'public', 'base');
|
2013-01-25 16:01:53 +04:00
|
|
|
$tmpl->assign('displayName', \OCP\User::getDisplayName($shareOwner));
|
2012-11-23 18:51:57 +04:00
|
|
|
$tmpl->assign('filename', $file);
|
2013-06-25 14:24:14 +04:00
|
|
|
$tmpl->assign('directory_path', $linkItem['file_target']);
|
2013-01-07 03:16:10 +04:00
|
|
|
$tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
|
2013-06-25 14:24:14 +04:00
|
|
|
$tmpl->assign('dirToken', $linkItem['token']);
|
2013-11-15 19:27:41 +04:00
|
|
|
$tmpl->assign('sharingToken', $token);
|
2013-08-18 01:41:37 +04:00
|
|
|
$allowPublicUploadEnabled = (bool) ($linkItem['permissions'] & OCP\PERMISSION_CREATE);
|
2014-02-13 19:28:49 +04:00
|
|
|
if ($appConfig->getValue('core', 'shareapi_allow_public_upload', 'yes') === 'no') {
|
2013-07-14 23:58:08 +04:00
|
|
|
$allowPublicUploadEnabled = false;
|
|
|
|
}
|
2013-07-06 02:11:42 +04:00
|
|
|
if ($linkItem['item_type'] !== 'folder') {
|
2013-07-05 12:53:59 +04:00
|
|
|
$allowPublicUploadEnabled = false;
|
|
|
|
}
|
2013-06-25 14:24:14 +04:00
|
|
|
|
2013-01-09 16:57:51 +04:00
|
|
|
$urlLinkIdentifiers= (isset($token)?'&t='.$token:'')
|
|
|
|
.(isset($_GET['dir'])?'&dir='.$_GET['dir']:'')
|
|
|
|
.(isset($_GET['file'])?'&file='.$_GET['file']:'');
|
2012-11-23 18:51:57 +04:00
|
|
|
// Show file list
|
2013-01-07 03:16:10 +04:00
|
|
|
if (\OC\Files\Filesystem::is_dir($path)) {
|
2013-02-11 14:48:49 +04:00
|
|
|
$tmpl->assign('dir', $getPath);
|
|
|
|
|
2012-11-23 18:51:57 +04:00
|
|
|
OCP\Util::addStyle('files', 'files');
|
2013-09-18 19:20:14 +04:00
|
|
|
OCP\Util::addStyle('files', 'upload');
|
2012-11-23 18:51:57 +04:00
|
|
|
OCP\Util::addScript('files', 'files');
|
|
|
|
OCP\Util::addScript('files', 'filelist');
|
2013-01-28 12:47:21 +04:00
|
|
|
OCP\Util::addscript('files', 'keyboardshortcuts');
|
2012-11-23 18:51:57 +04:00
|
|
|
$files = array();
|
|
|
|
$rootLength = strlen($basePath) + 1;
|
2013-03-07 18:48:10 +04:00
|
|
|
$totalSize = 0;
|
2013-02-10 09:53:58 +04:00
|
|
|
foreach (\OC\Files\Filesystem::getDirectoryContent($path) as $i) {
|
2013-03-07 18:48:10 +04:00
|
|
|
$totalSize += $i['size'];
|
2012-11-23 18:51:57 +04:00
|
|
|
$i['date'] = OCP\Util::formatDate($i['mtime']);
|
|
|
|
if ($i['type'] == 'file') {
|
|
|
|
$fileinfo = pathinfo($i['name']);
|
|
|
|
$i['basename'] = $fileinfo['filename'];
|
2013-02-10 09:53:58 +04:00
|
|
|
if (!empty($fileinfo['extension'])) {
|
|
|
|
$i['extension'] = '.' . $fileinfo['extension'];
|
|
|
|
} else {
|
|
|
|
$i['extension'] = '';
|
|
|
|
}
|
2012-11-04 21:42:18 +04:00
|
|
|
}
|
2014-01-17 17:21:15 +04:00
|
|
|
$i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($i['mimetype']);
|
2013-02-11 14:48:49 +04:00
|
|
|
$i['directory'] = $getPath;
|
2013-02-11 05:01:25 +04:00
|
|
|
$i['permissions'] = OCP\PERMISSION_READ;
|
2013-09-12 02:40:35 +04:00
|
|
|
$i['icon'] = determineIcon($i, $basePath, $token);
|
2012-11-23 18:51:57 +04:00
|
|
|
$files[] = $i;
|
|
|
|
}
|
2013-02-11 14:50:41 +04:00
|
|
|
usort($files, "fileCmp");
|
|
|
|
|
2012-11-23 18:51:57 +04:00
|
|
|
// Make breadcrumb
|
|
|
|
$breadcrumb = array();
|
|
|
|
$pathtohere = '';
|
2013-02-11 14:44:18 +04:00
|
|
|
foreach (explode('/', $getPath) as $i) {
|
2012-11-23 18:51:57 +04:00
|
|
|
if ($i != '') {
|
2012-12-02 15:12:20 +04:00
|
|
|
$pathtohere .= '/' . $i;
|
2012-11-23 18:51:57 +04:00
|
|
|
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$list = new OCP\Template('files', 'part.list', '');
|
2013-02-28 00:37:14 +04:00
|
|
|
$list->assign('files', $files);
|
|
|
|
$list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=');
|
2013-02-15 01:37:49 +04:00
|
|
|
$list->assign('downloadURL',
|
2013-02-28 00:37:14 +04:00
|
|
|
OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=');
|
2013-07-11 13:58:52 +04:00
|
|
|
$list->assign('isPublic', true);
|
|
|
|
$list->assign('sharingtoken', $token);
|
2013-07-30 14:29:12 +04:00
|
|
|
$list->assign('sharingroot', $basePath);
|
2013-02-10 09:53:58 +04:00
|
|
|
$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
|
2013-02-28 00:37:14 +04:00
|
|
|
$breadcrumbNav->assign('breadcrumb', $breadcrumb);
|
2014-01-15 16:36:14 +04:00
|
|
|
$breadcrumbNav->assign('rootBreadCrumb', $rootName);
|
2013-02-28 00:37:14 +04:00
|
|
|
$breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=');
|
2013-06-25 14:24:14 +04:00
|
|
|
$maxUploadFilesize=OCP\Util::maxUploadFilesize($path);
|
2013-11-21 15:02:09 +04:00
|
|
|
$fileHeader = (!isset($files) or count($files) > 0);
|
|
|
|
$emptyContent = ($allowPublicUploadEnabled and !$fileHeader);
|
2014-02-06 08:06:16 +04:00
|
|
|
|
|
|
|
$freeSpace=OCP\Util::freeSpace($path);
|
|
|
|
$uploadLimit=OCP\Util::uploadLimit();
|
2012-11-23 18:51:57 +04:00
|
|
|
$folder = new OCP\Template('files', 'index', '');
|
2013-02-28 00:37:14 +04:00
|
|
|
$folder->assign('fileList', $list->fetchPage());
|
|
|
|
$folder->assign('breadcrumb', $breadcrumbNav->fetchPage());
|
2013-02-11 14:48:49 +04:00
|
|
|
$folder->assign('dir', $getPath);
|
2014-01-15 17:36:18 +04:00
|
|
|
$folder->assign('isCreatable', $allowPublicUploadEnabled);
|
|
|
|
$folder->assign('dirToken', $linkItem['token']);
|
2013-06-25 14:24:14 +04:00
|
|
|
$folder->assign('permissions', OCP\PERMISSION_READ);
|
|
|
|
$folder->assign('isPublic',true);
|
2013-07-14 23:58:08 +04:00
|
|
|
$folder->assign('publicUploadEnabled', 'no');
|
2012-11-23 18:51:57 +04:00
|
|
|
$folder->assign('files', $files);
|
2013-06-25 14:24:14 +04:00
|
|
|
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
|
|
|
|
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
|
2014-02-06 08:06:16 +04:00
|
|
|
$folder->assign('freeSpace', $freeSpace);
|
|
|
|
$folder->assign('uploadLimit', $uploadLimit); // PHP upload limit
|
2012-11-23 18:51:57 +04:00
|
|
|
$folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
|
2013-02-10 09:53:58 +04:00
|
|
|
$folder->assign('usedSpacePercent', 0);
|
2013-11-21 15:02:09 +04:00
|
|
|
$folder->assign('fileHeader', $fileHeader);
|
|
|
|
$folder->assign('disableSharing', true);
|
2013-11-21 15:06:35 +04:00
|
|
|
$folder->assign('trash', false);
|
2013-11-21 15:02:09 +04:00
|
|
|
$folder->assign('emptyContent', $emptyContent);
|
|
|
|
$folder->assign('ajaxLoad', false);
|
2013-02-28 00:37:14 +04:00
|
|
|
$tmpl->assign('folder', $folder->fetchPage());
|
2013-10-17 17:29:22 +04:00
|
|
|
$maxInputFileSize = OCP\Config::getSystemValue('maxZipInputSize', OCP\Util::computerFileSize('800 MB'));
|
2013-03-07 18:48:10 +04:00
|
|
|
$allowZip = OCP\Config::getSystemValue('allowZipDownload', true)
|
2013-10-17 17:29:22 +04:00
|
|
|
&& ( $maxInputFileSize === 0 || $totalSize <= $maxInputFileSize);
|
2013-03-07 18:48:10 +04:00
|
|
|
$tmpl->assign('allowZipDownload', intval($allowZip));
|
2013-02-15 01:37:49 +04:00
|
|
|
$tmpl->assign('downloadURL',
|
|
|
|
OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath));
|
2012-11-23 18:51:57 +04:00
|
|
|
} else {
|
2013-02-11 14:48:49 +04:00
|
|
|
$tmpl->assign('dir', $dir);
|
|
|
|
|
2013-02-10 09:53:58 +04:00
|
|
|
// Show file preview if viewer is available
|
|
|
|
if ($type == 'file') {
|
|
|
|
$tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download');
|
|
|
|
} else {
|
|
|
|
$tmpl->assign('downloadURL', OCP\Util::linkToPublic('files')
|
|
|
|
.$urlLinkIdentifiers.'&download&path='.urlencode($getPath));
|
|
|
|
}
|
2012-11-04 21:42:18 +04:00
|
|
|
}
|
2013-02-10 09:53:58 +04:00
|
|
|
$tmpl->printPage();
|
2012-11-04 21:42:18 +04:00
|
|
|
}
|
2013-02-10 09:53:58 +04:00
|
|
|
exit();
|
|
|
|
} else {
|
|
|
|
OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
|
2012-11-04 21:42:18 +04:00
|
|
|
}
|
2013-07-29 17:33:23 +04:00
|
|
|
|
|
|
|
$errorTemplate = new OCP\Template('files_sharing', 'part.404', '');
|
|
|
|
$errorContent = $errorTemplate->fetchPage();
|
|
|
|
|
2012-11-04 21:42:18 +04:00
|
|
|
header('HTTP/1.0 404 Not Found');
|
2013-07-29 18:36:59 +04:00
|
|
|
OCP\Util::addStyle('files_sharing', '404');
|
2012-11-04 21:42:18 +04:00
|
|
|
$tmpl = new OCP\Template('', '404', 'guest');
|
2013-07-29 17:33:23 +04:00
|
|
|
$tmpl->assign('content', $errorContent);
|
2012-11-04 21:42:18 +04:00
|
|
|
$tmpl->printPage();
|