/** * store a new version of a file. */ public function store($filename) { if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') { list($uid, $filename) = self::getUidAndFilename($filename); $files_view = new \OC_FilesystemView('/' . $uid . '/files'); $users_view = new \OC_FilesystemView('/' . $uid); //check if source file already exist as version to avoid recursions. // todo does this check work? if ($users_view->file_exists($filename)) { return false; } // check if filename is a directory if ($files_view->is_dir($filename)) { return false; } // check filetype blacklist $blacklist = explode(' ', \OCP\Config::getSystemValue('files_versionsblacklist', Storage::DEFAULTBLACKLIST)); foreach ($blacklist as $bl) { $parts = explode('.', $filename); $ext = end($parts); if (strtolower($ext) == $bl) { return false; } } // we should have a source file to work with if (!$files_view->file_exists($filename)) { return false; } // check filesize if ($files_view->filesize($filename) > \OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)) { return false; } // check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval) if ($uid == \OCP\User::getUser()) { $versions_fileview = new \OC_FilesystemView('/' . $uid . '/files_versions'); $versionsName = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath($filename); $versionsFolderName = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath(''); $matches = glob($versionsName . '.v*'); sort($matches); $parts = explode('.v', end($matches)); if (end($parts) + Storage::DEFAULTMININTERVAL > time()) { return false; } } // create all parent folders $info = pathinfo($filename); if (!file_exists($versionsFolderName . '/' . $info['dirname'])) { mkdir($versionsFolderName . '/' . $info['dirname'], 0750, true); } // store a new version of a file $users_view->copy('files' . $filename, 'files_versions' . $filename . '.v' . time()); // expire old revisions if necessary Storage::expire($filename); } }
/** * @medium * @brief test if postFileSize returns the unencrypted file size */ function testPostFileSize() { // generate filename $filename = 'tmp-' . time() . '.txt'; $this->view->file_put_contents($filename, $this->data); \OC_FileProxy::$enabled = false; $unencryptedSize = $this->view->filesize($filename); \OC_FileProxy::$enabled = true; $encryptedSize = $this->view->filesize($filename); $this->assertTrue($encryptedSize !== $unencryptedSize); }
function testPostFileSizeWithDirectory() { $this->view->file_put_contents($this->filename, $this->data); \OC_FileProxy::$enabled = false; // get root size, must match the file's unencrypted size $unencryptedSize = $this->view->filesize(''); \OC_FileProxy::$enabled = true; $encryptedSize = $this->view->filesize(''); $this->assertTrue($encryptedSize !== $unencryptedSize); // cleanup $this->view->unlink($this->filename); }
* 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"]; $view = new OC_FilesystemView('/' . \OCP\User::getUser() . '/files_trashbin/files'); if (!$view->file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OCP\Template('', '404', 'guest'); $tmpl->assign('file', $filename); $tmpl->printPage(); exit; } $ftype = $view->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: ' . $view->filesize($filename)); OC_Util::obEnd(); $view->readfile($filename);