/** * @NoAdminRequired * @NoCSRFRequired */ public function Add() { \OCP\JSON::setContentTypeHeader('application/json'); if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) { try { $Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1)); // If target file exists, create a new one if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) { $Target = time() . '_' . $Target; } // Create the target file if the downloader is Aria2 if ($this->WhichDownloader == 0) { \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target); } else { if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) { \OC\Files\Filesystem::mkdir($this->DownloadsFolder); } } // Build OPTIONS array $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false); if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) { $OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser']; $OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd']; } if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) { $OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false; } if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort; if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) { $OPTIONS['all-proxy-user'] = $this->ProxyUser; $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd; } } $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS); if (isset($AddURI['result']) && !is_null($AddURI['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time())); sleep(1); $Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']); $Progress = 0; if ($Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided'))); } }
/** * test set and get share folder */ function testSetGetShareFolder() { $this->assertSame('/', \OCA\Files_Sharing\Helper::getShareFolder()); \OCA\Files_Sharing\Helper::setShareFolder('/Shared/Folder'); $sharedFolder = \OCA\Files_Sharing\Helper::getShareFolder(); $this->assertSame('/Shared/Folder', \OCA\Files_Sharing\Helper::getShareFolder()); $this->assertTrue(\OC\Files\Filesystem::is_dir($sharedFolder)); // cleanup \OCP\Config::deleteSystemValue('share_folder'); }
public static function ClearCache($parameters) { if (is_array($parameters)) { if (\OC\Files\Filesystem::is_dir($parameters['path'] . '/') || basename(getenv('REQUEST_URI')) == 'newfolder.php') { $cache = new OC\Cache\UserCache(); $parent = $_POST['dir']; $cache->remove('files_tree_cache' . $parent); } else { // Nothing to do here } } }
/** * check if the parent folder exists otherwise move the mount point up */ private function verifyMountPoint(&$share, $user) { $mountPoint = basename($share['file_target']); $parent = dirname($share['file_target']); if (!\OC\Files\Filesystem::is_dir($parent)) { $parent = Helper::getShareFolder(); } $newMountPoint = \OCA\Files_Sharing\Helper::generateUniqueTarget(\OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), array(), new \OC\Files\View('/' . $user . '/files')); if ($newMountPoint !== $share['file_target']) { self::updateFileTarget($newMountPoint, $share); $share['file_target'] = $newMountPoint; $share['unique_name'] = true; } return $newMountPoint; }
/** * @NoAdminRequired * @NoCSRFRequired */ public function Save() { \OCP\JSON::setContentTypeHeader('application/json'); $Error = false; $Message = ''; if (isset($_POST['KEY']) && strlen(trim($_POST['KEY'])) > 0 && isset($_POST['VAL']) && strlen(trim($_POST['VAL'])) > 0) { $PostKey = str_replace('OCD', '', $_POST['KEY']); $PostValue = ltrim(trim(str_replace(' ', '\\ ', $_POST['VAL'])), '/'); if (in_array($PostKey, $this->OCDSettingKeys)) { $this->Settings->SetKey($PostKey); // Pre-Save process if (strcmp($PostKey, 'DownloadsFolder') == 0 || strcmp($PostKey, 'TorrentsFolder') == 0) { // check folder exists, if not create it if (!\OC\Files\Filesystem::is_dir($PostValue)) { // Create the target file \OC\Files\Filesystem::mkdir($PostValue); $Message .= $this->L10N->t('The folder doesn\'t exist. It has been created.'); } } if (strlen(trim($PostValue)) <= 0) { $PostValue = null; } if ($this->Settings->CheckIfKeyExists()) { $this->Settings->UpdateValue($PostValue); } else { $this->Settings->InsertValue($PostValue); } } else { $Error = true; $Message = $this->L10N->t('Unknown field'); } } else { $Error = true; $Message = $this->L10N->t('Undefined field'); } return new JSONResponse(array('ERROR' => $Error, 'MESSAGE' => strlen(trim($Message)) == 0 ? (string) $this->L10N->t('Saved') : $Message)); }
/** * Stream directory recursively * @param string $dir * @param string $internalDir */ public function addDirRecursive($dir, $internalDir = '') { $dirname = basename($dir); $rootDir = $internalDir . $dirname; if (!empty($rootDir)) { $this->streamerInstance->addEmptyDir($rootDir); } $internalDir .= $dirname . '/'; // prevent absolute dirs $internalDir = ltrim($internalDir, '/'); $files = \OC\Files\Filesystem::getDirectoryContent($dir); foreach ($files as $file) { $filename = $file['name']; $file = $dir . '/' . $filename; if (\OC\Files\Filesystem::is_file($file)) { $filesize = \OC\Files\Filesystem::filesize($file); $fh = \OC\Files\Filesystem::fopen($file, 'r'); $this->addFileFromStream($fh, $internalDir . $filename, $filesize); fclose($fh); } elseif (\OC\Files\Filesystem::is_dir($file)) { $this->addDirRecursive($file, $internalDir); } } }
/** * get file * * @param string $user * @param int $fileSource * @return array with internal path of the file and a absolute link to it */ private function getFile($user, $fileSource) { \OC_Util::setupFS($user); $file = \OC\Files\Filesystem::getPath($fileSource); $args = \OC\Files\Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file); $link = \OCP\Util::linkToAbsolute('files', 'index.php', $args); return array($file, $link); }
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(); $rootLength = strlen($basePath) + 1; $maxUploadFilesize = OCP\Util::maxUploadFilesize($path); $freeSpace = OCP\Util::freeSpace($path); $uploadLimit = OCP\Util::uploadLimit(); $folder = new OCP\Template('files', 'list', ''); $folder->assign('dir', $getPath);
/** * store a new version of a file. */ public static function store($filename) { if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') { // if the file gets streamed we need to remove the .part extension // to get the right target $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext === 'part') { $filename = substr($filename, 0, strlen($filename) - 5); } // we only handle existing files if (!Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) { return false; } list($uid, $filename) = self::getUidAndFilename($filename); $files_view = new View('/' . $uid . '/files'); $users_view = new View('/' . $uid); // no use making versions for empty files if ($files_view->filesize($filename) === 0) { return false; } // create all parent folders self::createMissingDirectories($filename, $users_view); self::scheduleExpire($uid, $filename); // store a new version of a file $mtime = $users_view->filemtime('files/' . $filename); $users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime); // call getFileInfo to enforce a file cache entry for the new version $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function ListTorrentFiles() { \OCP\JSON::setContentTypeHeader('application/json'); try { if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) { \OC\Files\Filesystem::mkdir($this->TorrentsFolder); } $this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder); $Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc'); $Files = \OCA\Files\Helper::formatFileInfos($Files); return new JSONResponse(array('ERROR' => false, 'FILES' => $Files)); } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function Add() { \OCP\JSON::setContentTypeHeader('application/json'); if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) { try { if (!$this->AllowProtocolYT && !\OC_User::isAdminUser($this->CurrentUID)) { throw new \Exception((string) $this->L10N->t('You are not allowed to use the YouTube protocol')); } $YouTube = new YouTube($this->YTDLBinary, $_POST['FILE']); if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $YouTube->SetProxy($this->ProxyAddress, $this->ProxyPort); } if (isset($_POST['OPTIONS']['YTForceIPv4']) && strcmp($_POST['OPTIONS']['YTForceIPv4'], 'false') == 0) { $YouTube->SetForceIPv4(false); } // Extract Audio YES if (isset($_POST['OPTIONS']['YTExtractAudio']) && strcmp($_POST['OPTIONS']['YTExtractAudio'], 'true') == 0) { $VideoData = $YouTube->GetVideoData(true); if (!isset($VideoData['AUDIO']) || !isset($VideoData['FULLNAME'])) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube audio URL'))); } $DL = array('URL' => $VideoData['AUDIO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Audio'); } else { $VideoData = $YouTube->GetVideoData(); if (!isset($VideoData['VIDEO']) || !isset($VideoData['FULLNAME'])) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Unable to retrieve true YouTube video URL'))); } $DL = array('URL' => $VideoData['VIDEO'], 'FILENAME' => Tools::CleanString($VideoData['FULLNAME']), 'TYPE' => 'YT Video'); } // If target file exists, create a new one if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $DL['FILENAME'])) { $DL['FILENAME'] = time() . '_' . $DL['FILENAME']; } // Create the target file if the downloader is ARIA2 if ($this->WhichDownloader == 0) { \OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $DL['FILENAME']); } else { if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) { \OC\Files\Filesystem::mkdir($this->DownloadsFolder); } } $OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $DL['FILENAME']); if (!is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) { $OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort; if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) { $OPTIONS['all-proxy-user'] = $this->ProxyUser; $OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd; } } if (!is_null($this->MaxDownloadSpeed) && $this->MaxDownloadSpeed > 0) { $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K'; } $AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($DL['URL']), array('Params' => $OPTIONS)) : CURL::AddUri($DL['URL'], $OPTIONS); if (isset($AddURI['result']) && !is_null($AddURI['result'])) { $SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $DL['FILENAME'], $DL['TYPE'], 1, time())); sleep(1); $Status = Aria2::TellStatus($AddURI['result']); $Progress = 0; if ($Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } $ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($DL['FILENAME']) > 40 ? substr($DL['FILENAME'], 0, 40) . '...' : $DL['FILENAME'], 'PROTO' => $DL['TYPE'], 'ISTORRENT' => false)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Returned GID is null ! Is Aria2c running as a daemon ?'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided'))); } }
private function parserFileHandler($files, $userForSharing) { $saveFiles = ['file_fileid' => [], 'shared_with' => []]; if ($this->loginVirtualUser()) { $innerDir = date("Ymd", time()); foreach ($files as $file) { if (!\OC\Files\Filesystem::is_dir('/Talks')) { \OC\Files\Filesystem::mkdir('/Talks'); } if (!\OC\Files\Filesystem::is_dir('/Talks/' . $innerDir)) { \OC\Files\Filesystem::mkdir('/Talks/' . $innerDir); } if (is_file($file['tmpfile'])) { try { chmod($file['tmpfile'], 0755); } catch (\Exception $e) { } $filePathTo = '/Talks/' . $innerDir . '/' . $file['filename']; $fileInfoExist = \OC\Files\Filesystem::getFileInfo($filePathTo, false); if ($fileInfoExist) { $filePathTo = '/Talks/' . $innerDir . '/' . time() . '-' . $file['filename']; } $saved = \OC\Files\Filesystem::file_put_contents($filePathTo, file_get_contents($file['tmpfile'])); if ($saved) { unlink($file['tmpfile']); $saveFilesInfo = \OC\Files\Filesystem::getFileInfo($filePathTo); Helper::mailParserLoger('FILES INFO: ' . json_encode($saveFilesInfo)); $saveFiles['file_fileid'][] = $saveFilesInfo['fileid']; $saveFiles['shared_with'][] = $this->shareFileToUsers($saveFilesInfo, $userForSharing); //todo mails sands } } } } return $saveFiles; }
/** * get default share folder * * @return string */ public static function getShareFolder() { $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/'); $shareFolder = Filesystem::normalizePath($shareFolder); if (!Filesystem::file_exists($shareFolder)) { $dir = ''; $subdirs = explode('/', $shareFolder); foreach ($subdirs as $subdir) { $dir = $dir . '/' . $subdir; if (!Filesystem::is_dir($dir)) { Filesystem::mkdir($dir); } } } return $shareFolder; }
/** * checks if the selected files are within the size constraint. If not, outputs an error page. * * @param dir $dir * @param files $files */ static function validateZipDownload($dir, $files) { if (!OC_Config::getValue('allowZipDownload', true)) { $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); OC_Template::printErrorPage($l->t('ZIP download is turned off.'), $l->t('Files need to be downloaded one by one.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'); exit; } $zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB')); if ($zipLimit > 0) { $totalsize = 0; if (!is_array($files)) { $files = array($files); } foreach ($files as $file) { $path = $dir . '/' . $file; if (\OC\Files\Filesystem::is_dir($path)) { foreach (\OC\Files\Filesystem::getDirectoryContent($path) as $i) { $totalsize += $i['size']; } } else { $totalsize += \OC\Files\Filesystem::filesize($path); } } if ($totalsize > $zipLimit) { $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); OC_Template::printErrorPage($l->t('Selected files too large to generate zip file.'), $l->t('Please download the files separately in smaller chunks or kindly ask your administrator.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'); exit; } } }
/** * @PublicPage * @NoCSRFRequired * * @param string $token * @param string $files * @param string $path * @return void|RedirectResponse */ public function downloadShare($token, $files = null, $path = '') { \OC_User::setIncognitoMode(true); $linkItem = OCP\Share::getShareByToken($token, false); // Share is password protected - check whether the user is permitted to access the share if (isset($linkItem['share_with'])) { if (!Helper::authenticate($linkItem)) { return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token))); } } $originalSharePath = self::getPath($token); if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) { $originalSharePath = Filesystem::normalizePath($originalSharePath . $path); $type = \OC\Files\Filesystem::is_dir($originalSharePath) ? 'folder' : 'file'; $args = $type === 'folder' ? array('dir' => $originalSharePath) : array('dir' => dirname($originalSharePath), 'scrollto' => basename($originalSharePath)); $linkToFile = \OCP\Util::linkToAbsolute('files', 'index.php', $args); $subject = $type === 'folder' ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; $this->activityManager->publishActivity('files_sharing', $subject, array($originalSharePath), '', array(), $originalSharePath, $linkToFile, $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM); } if (!is_null($files)) { // download selected files $files_list = json_decode($files); // in case we get only a single file if ($files_list === NULL) { $files_list = array($files); } // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); exit; } else { // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD'); exit; } }
public function getListing($FOLDER, $showdel) { // Get the listing from the database $requery = false; $uid = \OCP\User::getUser(); $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name"); $results = $query->execute(array($uid))->fetchAll(); $results2 = $results; if ($results) { foreach ($results as $result) { foreach ($results2 as $result2) { if ($result['id'] != $result2['id'] && $result['name'] == $result2['name'] && $result['grouping'] == $result2['grouping']) { // We have a duplicate that should not exist. Need to remove the offending record first $delid = -1; if ($result['mtime'] == $result2['mtime']) { // If the mtime's match, delete the oldest ID. $delid = $result['id']; if ($result['id'] > $result2['id']) { $delid = $result2['id']; } } elseif ($result['mtime'] > $result2['mtime']) { // Again, delete the oldest $delid = $result2['id']; } elseif ($result['mtime'] < $result2['mtime']) { // The only thing left is if result is older $delid = $result['id']; } if ($delid != -1) { $delquery = \OCP\DB::prepare("DELETE FROM *PREFIX*ownnote WHERE id=?"); $delquery->execute(array($delid)); $requery = true; } } } } } if ($requery) { $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name"); $results = $query->execute(array($uid))->fetchAll(); $requery = false; } // Tests to add a bunch of notes //$now = new DateTime(); //for ($x = 0; $x < 199; $x++) { //saveNote('', "Test ".$x, '', '', $now->getTimestamp()); //} $farray = array(); if ($FOLDER != '') { // Create the folder if it doesn't exist if (!\OC\Files\Filesystem::is_dir($FOLDER)) { if (!\OC\Files\Filesystem::mkdir($FOLDER)) { echo "ERROR: Could not create ownNote directory."; exit; } } // Synchronize files to the database $filearr = array(); if ($listing = \OC\Files\Filesystem::opendir($FOLDER)) { if (!$listing) { echo "ERROR: Error listing directory."; exit; } while (($file = readdir($listing)) !== false) { $tmpfile = $file; if ($tmpfile == "." || $tmpfile == "..") { continue; } if (!$this->endsWith($tmpfile, ".htm") && !$this->endsWith($tmpfile, ".html")) { continue; } if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER . "/" . $tmpfile)) { // Check for EVERNOTE but wait to rename them to get around: // https://github.com/owncloud/core/issues/16202 if ($this->endsWith($tmpfile, ".html")) { $this->checkEvernote($FOLDER, $tmpfile); } // Separate the name and group name $name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $tmpfile); $group = ""; if (substr($name, 0, 1) == "[") { $end = strpos($name, ']'); $group = substr($name, 1, $end - 1); $name = substr($name, $end + 1, strlen($name) - $end + 1); $name = trim($name); } // Set array for later checking $filearr[] = $tmpfile; // Check to see if the file is in the DB $fileindb = false; if ($results) { foreach ($results as $result) { if ($result['deleted'] == 0) { if ($name == $result['name'] && $group == $result['grouping']) { $fileindb = true; // If it is in the DB, check if the filesystem file is newer than the DB if ($result['mtime'] < $info['mtime']) { // File is newer, this could happen if a user updates a file $html = ""; $html = \OC\Files\Filesystem::file_get_contents($FOLDER . "/" . $tmpfile); $this->saveNote('', $result['name'], $result['grouping'], $html, $info['mtime']); $requery = true; } } } } } if (!$fileindb) { // If it's not in the DB, add it. $html = ""; if ($html = \OC\Files\Filesystem::file_get_contents($FOLDER . "/" . $tmpfile)) { } else { $html = ""; } $this->saveNote('', $name, $group, $html, $info['mtime']); $requery = true; } // We moved the rename down here to overcome the OC issue if ($this->endsWith($tmpfile, ".html")) { $tmpfile = substr($tmpfile, 0, -1); if (!\OC\Files\Filesystem::file_exists($FOLDER . "/" . $tmpfile)) { \OC\Files\Filesystem::rename($FOLDER . "/" . $file, $FOLDER . "/" . $tmpfile); } } } } } if ($requery) { $query = \OCP\DB::prepare("SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name"); $results = $query->execute(array($uid))->fetchAll(); } // Now also make sure the files exist, they may not if the user switched folders in admin. if ($results) { foreach ($results as $result) { if ($result['deleted'] == 0) { $tmpfile = $result['name'] . ".htm"; if ($result['grouping'] != '') { $tmpfile = '[' . $result['grouping'] . '] ' . $result['name'] . '.htm'; } $filefound = false; foreach ($filearr as $f) { if ($f == $tmpfile) { $filefound = true; break; } } if (!$filefound) { $content = $this->editNote($result['name'], $result['grouping']); $this->saveNote($FOLDER, $result['name'], $result['grouping'], $content, 0); } } } } } // Now loop through and return the listing if ($results) { $count = 0; $now = new DateTime(); $filetime = new DateTime(); $l = \OCP\Util::getL10N('ownnote'); foreach ($results as $result) { if ($result['deleted'] == 0 || $showdel == true) { $filetime->setTimestamp($result['mtime']); $timestring = $this->getTimeString($filetime, $now, $l); $f = array(); $f['id'] = $result['id']; $f['name'] = $result['name']; $f['group'] = $result['grouping']; $f['timestring'] = $timestring; $f['mtime'] = $result['mtime']; $f['timediff'] = $now->getTimestamp() - $result['mtime']; $f['deleted'] = $result['deleted']; $farray[$count] = $f; $count++; } } } return $farray; }
public function testGetPermissions() { $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder)); // for the share root we expect: // the shared permissions (1) // the delete permission (8), to enable unshare $rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder); $this->assertSame(9, $rootInfo->getPermissions()); // for the file within the shared folder we expect: // the shared permissions (1) $subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename); $this->assertSame(1, $subfileInfo->getPermissions()); //cleanup $this->shareManager->deleteShare($share); }
/** * @NoAdminRequired * @NoCSRFRequired */ public function ListTorrentFiles() { \OCP\JSON::setContentTypeHeader('application/json'); try { if (!$this->AllowProtocolBT && !\OC_User::isAdminUser($this->CurrentUID)) { throw new \Exception((string) $this->L10N->t('You are not allowed to use the BitTorrent protocol')); } if (!\OC\Files\Filesystem::is_dir($this->TorrentsFolder)) { \OC\Files\Filesystem::mkdir($this->TorrentsFolder); } $this->TorrentsFolder = \OC\Files\Filesystem::normalizePath($this->TorrentsFolder); $Files = \OCA\Files\Helper::getFiles($this->TorrentsFolder, 'name', 'desc', 'application/octet-stream'); $Files = \OCA\Files\Helper::formatFileInfos($Files); return new JSONResponse(array('ERROR' => false, 'FILES' => $Files)); } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }
/** * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem */ public static function is_dir($path) { return \OC\Files\Filesystem::is_dir($path); }
private function getNodeForPath($path) { $info = Filesystem::getView()->getFileInfo($path); if (!$info) { $fullPath = Filesystem::getView()->getAbsolutePath($path); if (Filesystem::is_dir($path)) { return new NonExistingFolder($this->root, $this->view, $fullPath); } else { return new NonExistingFile($this->root, $this->view, $fullPath); } } if ($info->getType() === FileInfo::TYPE_FILE) { return new File($this->root, $this->view, $info->getPath(), $info); } else { return new Folder($this->root, $this->view, $info->getPath(), $info); } }
/** * * @param array $info the associative array of info for the file being processed */ public static function beforeFileRenameDelete($info) { $file = $info['path']; if (!$file) { $file = $info['oldpath']; } if (self::$DO_LOG) { error_log("path === {$file}"); } $pathsplit = explode("/", $file); $len = count($pathsplit); $lastelem = $pathsplit[$len - 1]; // the splitted path has always the first element empty, so $pathsplit[0] === "" $firstelem = $pathsplit[1]; if (is_valid_casestudy("/" . $firstelem) === null) { if (self::$DO_LOG) { error_log("{$firstelem} is a valid case study"); } if ($len > 3 && $pathsplit[2] === 'results' && \OC\Files\Filesystem::is_dir($file)) { // case 1: trying to delete/rename one the results directories of a running job if (is_job_running($firstelem, $lastelem)) { // since the job is still running, do not allow to rename/delete the results directory if (self::$DO_LOG) { error_log("beforeFileRenameDelete : trying to rename/delete {$file} while the job is still running"); } $info['run'] = false; } else { if (self::$DO_LOG) { error_log("beforeFileRenameDelete : no job running for {$file}"); } // the user is deleting a results directory: delete also the temp directory if existing $tempdir = get_job_exec_dir($file); if (is_dir($tempdir)) { rmdirr($tempdir); } } } if ($lastelem === 'data' || $lastelem === 'pipeline' || $lastelem === 'results') { // case 2: we are trying to rename/delete one of the directories data/pipeline/results of a case study if (any_jobs_running($firstelem)) { if (self::$DO_LOG) { error_log("beforeFileRenameDelete : trying to rename/delete {$file} while jobs are running"); } $info['run'] = false; } else { if (self::$DO_LOG) { error_log("beforeFileRenameDelete : no jobs running for {$file}"); } } } if ($len > 3 && $pathsplit[2] === 'data') { // case 3: renaming/deleting a file inside the data directory, while a job is running. Do not always allow it if (any_jobs_running($firstelem)) { if (self::$DO_LOG) { error_log("beforeFileRenameDelete : trying to rename/delete {$file} while jobs are running"); } $info['run'] = false; } else { if (self::$DO_LOG) { error_log("beforeFileRenameDelete : no jobs running for {$file}"); } } } } }
function getListing($FOLDER) { // Create directory if it doesn't exist if (!\OC\Files\Filesystem::is_dir($FOLDER)) { if (!\OC\Files\Filesystem::mkdir($FOLDER)) { echo "ERROR: Could not create ownNote directory."; exit; } } // Loop through and list files if ($listing = \OC\Files\Filesystem::opendir($FOLDER)) { if (!$listing) { echo "ERROR: Error listing directory."; exit; } $now = new DateTime(); $filetime = new DateTime(); $delete = OCP\Util::imagePath('ownnote','delete.png'); $farray = array(); $count = 0; while (($file = readdir($listing)) !== false) { $tmpfile = $file; if ($tmpfile == "." || $tmpfile == "..") continue; if (!endswith($tmpfile, ".htm") && !endswith($tmpfile, ".html")) continue; if ($info = \OC\Files\Filesystem::getFileInfo($FOLDER."/".$tmpfile)) { $filetime->setTimestamp($info['mtime']); $difftime = $filetime->diff($now); $years = $difftime->y; $months = $difftime->m; $days = $difftime->d; $hours = $difftime->h; $minutes = $difftime->i; $seconds = $difftime->s; $timestring = ""; if ($timestring == "" && $years == 1) $timestring = "$years year"; if ($timestring == "" && $years > 0) $timestring = "$years years"; if ($timestring == "" && $months == 1) $timestring = "$months month"; if ($timestring == "" && $months > 0) $timestring = "$months months"; if ($timestring == "" && $days == 1) $timestring = "$days day"; if ($timestring == "" && $days > 0) $timestring = "$days days"; if ($timestring == "" && $hours == 1) $timestring = "$hours hour"; if ($timestring == "" && $hours > 0) $timestring = "$hours hours"; if ($timestring == "" && $minutes == 1) $timestring = "$minutes minute"; if ($timestring == "" && $minutes > 0) $timestring = "$minutes minutes"; if ($timestring == "" && $seconds == 1) $timestring = "$seconds second"; if ($timestring == "" && $seconds > 0) $timestring = "$seconds seconds"; if (endswith($tmpfile, ".html")) { checkEvernote($FOLDER, $tmpfile); $tmpfile = substr($tmpfile,0,-1); if (!\OC\Files\Filesystem::file_exists($FOLDER."/".$tmpfile)) { if (!\OC\Files\Filesystem::rename($FOLDER."/".$file, $FOLDER."/".$tmpfile)) continue; } else { continue; } } $filename = preg_replace('/\\.[^.\\s]{3,4}$/', '', $tmpfile); $group = ""; if (substr($filename,0,1) == "[") { $end = strpos($filename, ']'); $group = substr($filename, 1, $end-1); $filename = substr($filename, $end+1, strlen($filename)-$end+1); $filename = trim($filename); } $f = array(); $f['file'] = $tmpfile; $f['filename'] = $filename; $f['group'] = $group; $f['timestring'] = $timestring; $f['mtime'] = $info['mtime']; $f['timediff'] = $now->getTimestamp()-$info['mtime']; $farray[$count] = $f; $count++; } else { echo "ERROR: Error retrieving file information."; exit; } } return $farray; } }
/** * return the content of a file or return a zip file containing multiple files * * @param string $dir * @param string $files ; separated list of files to download * @param boolean $onlyHeader ; boolean to only send header of the request */ public static function get($dir, $files, $onlyHeader = false) { $view = \OC\Files\Filesystem::getView(); $getType = self::FILE; $filename = $dir; try { if (is_array($files) && count($files) === 1) { $files = $files[0]; } if (!is_array($files)) { $filename = $dir . '/' . $files; if (!$view->is_dir($filename)) { self::getSingleFile($view, $dir, $files, $onlyHeader); return; } } $name = 'download'; if (is_array($files)) { $getType = self::ZIP_FILES; $basename = basename($dir); if ($basename) { $name = $basename; } $filename = $dir . '/' . $name; } else { $filename = $dir . '/' . $files; $getType = self::ZIP_DIR; // downloading root ? if ($files !== '') { $name = $files; } } $streamer = new Streamer(); OC_Util::obEnd(); self::lockFiles($view, $dir, $files); $streamer->sendHeaders($name); $executionTime = intval(OC::$server->getIniWrapper()->getNumeric('max_execution_time')); set_time_limit(0); if ($getType === self::ZIP_FILES) { foreach ($files as $file) { $file = $dir . '/' . $file; if (\OC\Files\Filesystem::is_file($file)) { $fileSize = \OC\Files\Filesystem::filesize($file); $fh = \OC\Files\Filesystem::fopen($file, 'r'); $streamer->addFileFromStream($fh, basename($file), $fileSize); fclose($fh); } elseif (\OC\Files\Filesystem::is_dir($file)) { $streamer->addDirRecursive($file); } } } elseif ($getType === self::ZIP_DIR) { $file = $dir . '/' . $files; $streamer->addDirRecursive($file); } $streamer->finalize(); set_time_limit($executionTime); self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); } catch (\OCP\Lock\LockedException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); } catch (\OCP\Files\ForbiddenException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage()); } catch (\Exception $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint); } }
/** * @dataProvider dataPaths */ function testMkdirr($path, $expected) { self::setUpUsers(); Helper::mkdirr($path, new \OC\Files\View('/' . self::TEST_ENCRYPTION_HELPER_USER1 . '/files')); // ignore the filename because we only check for the directories $dirParts = array_slice($expected, 0, -1); $expectedPath = implode('/', $dirParts); $this->assertTrue(\OC\Files\Filesystem::is_dir($expectedPath)); // cleanup \OC\Files\Filesystem::unlink('/' . $expected[0]); self::cleanUpUsers(); }
function testGetPermissions() { $fileinfoFolder = $this->view->getFileInfo($this->folder); $result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 1); $this->assertTrue($result); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder)); // for the share root we expect: // the shared permissions (1) // the delete permission (8), to enable unshare // the update permission (2), to allow renaming of the mount point $rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder); $this->assertSame(11, $rootInfo->getPermissions()); // for the file within the shared folder we expect: // the shared permissions (1) $subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename); $this->assertSame(1, $subfileInfo->getPermissions()); //cleanup self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); }
/** * @PublicPage * @NoCSRFRequired * * @param string $token * @param string $files * @param string $path * @return void|RedirectResponse */ public function downloadShare($token, $files = null, $path = '') { \OC_User::setIncognitoMode(true); $linkItem = OCP\Share::getShareByToken($token, false); // Share is password protected - check whether the user is permitted to access the share if (isset($linkItem['share_with'])) { if (!Helper::authenticate($linkItem)) { return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token))); } } $files_list = null; if (!is_null($files)) { // download selected files $files_list = json_decode($files); // in case we get only a single file if ($files_list === null) { $files_list = array($files); } } $originalSharePath = self::getPath($token); // Create the activities if (isset($originalSharePath) && Filesystem::isReadable($originalSharePath . $path)) { $originalSharePath = Filesystem::normalizePath($originalSharePath . $path); $isDir = \OC\Files\Filesystem::is_dir($originalSharePath); $activities = []; if (!$isDir) { // Single file public share $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; } else { if (!empty($files_list)) { // Only some files are downloaded foreach ($files_list as $file) { $filePath = Filesystem::normalizePath($originalSharePath . '/' . $file); $isDir = \OC\Files\Filesystem::is_dir($filePath); $activities[$filePath] = $isDir ? Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED : Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED; } } else { // The folder is downloaded $activities[$originalSharePath] = Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED; } } foreach ($activities as $filePath => $subject) { $this->activityManager->publishActivity('files_sharing', $subject, array($filePath), '', array(), $filePath, '', $linkItem['uid_owner'], Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM); } } // download selected files if (!is_null($files)) { // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD'); exit; } else { // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well // after dispatching the request which results in a "Cannot modify header information" notice. OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD'); exit; } }
/** * @param string $dir * @param ZipStreamer $zip * @param string $internalDir */ public static function zipAddDir($dir, ZipStreamer $zip, $internalDir = '') { $dirname = basename($dir); $rootDir = $internalDir . $dirname; if (!empty($rootDir)) { $zip->addEmptyDir($rootDir); } $internalDir .= $dirname .= '/'; // prevent absolute dirs $internalDir = ltrim($internalDir, '/'); $files = \OC\Files\Filesystem::getDirectoryContent($dir); foreach ($files as $file) { $filename = $file['name']; $file = $dir . '/' . $filename; if (\OC\Files\Filesystem::is_file($file)) { $fh = \OC\Files\Filesystem::fopen($file, 'r'); $zip->addFileFromStream($fh, $internalDir . $filename); fclose($fh); } elseif (\OC\Files\Filesystem::is_dir($file)) { self::zipAddDir($file, $zip, $internalDir); } } }
/** * return the content of a file or return a zip file containing multiple files * * @param string $dir * @param string $files ; separated list of files to download * @param boolean $onlyHeader ; boolean to only send header of the request */ public static function get($dir, $files, $onlyHeader = false) { $view = \OC\Files\Filesystem::getView(); if (is_array($files) && count($files) === 1) { $files = $files[0]; } if (is_array($files)) { $getType = self::ZIP_FILES; $basename = basename($dir); if ($basename) { $name = $basename; } else { $name = 'download'; } $filename = $dir . '/' . $name; } else { $filename = $dir . '/' . $files; if (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) { $getType = self::ZIP_DIR; // downloading root ? if ($files === '') { $name = 'download'; } else { $name = $files; } } else { $getType = self::FILE; $name = $files; } } if ($getType === self::FILE) { $streamer = false; } else { $streamer = new Streamer(); } OC_Util::obEnd(); try { if ($getType === self::FILE) { $view->lockFile($filename, ILockingProvider::LOCK_SHARED); } if ($streamer) { $streamer->sendHeaders($name); } elseif (\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; } if ($streamer) { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); if ($getType === self::ZIP_FILES) { foreach ($files as $file) { $file = $dir . '/' . $file; if (\OC\Files\Filesystem::is_file($file)) { $fileSize = \OC\Files\Filesystem::filesize($file); $fh = \OC\Files\Filesystem::fopen($file, 'r'); $streamer->addFileFromStream($fh, basename($file), $fileSize); fclose($fh); } elseif (\OC\Files\Filesystem::is_dir($file)) { $streamer->addDirRecursive($file); } } } elseif ($getType === self::ZIP_DIR) { $file = $dir . '/' . $files; $streamer->addDirRecursive($file); } $streamer->finalize(); set_time_limit($executionTime); } else { \OC\Files\Filesystem::readfile($filename); } if ($getType === self::FILE) { $view->unlockFile($filename, ILockingProvider::LOCK_SHARED); } } catch (\OCP\Lock\LockedException $ex) { $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); } catch (\Exception $ex) { $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint); } }
$password = null; if (isset($_POST['password'])) { $password = $_POST['password']; } $relativePath = null; if (isset($_GET['dir'])) { $relativePath = $_GET['dir']; } $sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name'; $sortDirection = isset($_GET['sortdirection']) ? $_GET['sortdirection'] === 'desc' : false; $data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); $linkItem = $data['linkItem']; // Load the files $dir = $data['realPath']; $dir = \OC\Files\Filesystem::normalizePath($dir); if (!\OC\Files\Filesystem::is_dir($dir . '/')) { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); \OCP\JSON::error(array('success' => false)); exit; } $data = array(); // make filelist $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); $formattedFiles = array(); foreach ($files as $file) { $entry = \OCA\Files\Helper::formatFileInfo($file); unset($entry['directory']); // for now $entry['permissions'] = \OCP\PERMISSION_READ; $formattedFiles[] = $entry; }
/** * Retrieves a list of jobs launched for a specln ific case study * @param type $study */ function get_jobs_for_study($study) { $jobids = array(); $directory = $study . "/results"; $content = OC_Files::getDirectoryContent($directory); foreach ($content as $c) { if (\OC\Files\Filesystem::is_dir($directory . "/" . $c["name"])) { $jobids[] = $c["name"]; } } array_multisort($jobids, SORT_DESC); return $jobids; }