/** * get the free space in the users home folder * @return int */ private function getFreeSpace() { $rootInfo = OC_FileCache::get(''); $usedSpace = $rootInfo['size']; $totalSpace = $this->getQuota(); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
/** * get the free space in the users home folder * @return int */ private function getFreeSpace() { $rootInfo = OC_FileCache::get(''); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared')) { $sharedInfo = OC_FileCache::get('/Shared'); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; $totalSpace = $this->getQuota(); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
/** * get the filesystem info * @param string path * @return array * * returns an associative array with the following keys: * - size * - mtime * - ctime * - mimetype * - encrypted * - versioned */ public static function getFileInfo($path) { if (($path == '/Shared' || substr($path, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) { if ($path == '/Shared') { list($info) = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT); } else { $info['size'] = OC_Filesystem::filesize($path); $info['mtime'] = OC_Filesystem::filemtime($path); $info['ctime'] = OC_Filesystem::filectime($path); $info['mimetype'] = OC_Filesystem::getMimeType($path); $info['encrypted'] = false; $info['versioned'] = false; } } else { $info = OC_FileCache::get($path); } return $info; }
/** * get the free space in the path's owner home folder * @param path * @return int */ private function getFreeSpace($path) { $storage = OC_Filesystem::getStorage($path); $owner = $storage->getOwner($path); $totalSpace = $this->getQuota($owner); if ($totalSpace == -1) { return -1; } $rootInfo = OC_FileCache::get('', "/" . $owner . "/files"); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared', "/" . $owner . "/files")) { $sharedInfo = OC_FileCache::get('/Shared', "/" . $owner . "/files"); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; return $totalSpace - $usedSpace; }
<?php require_once OC::$APPSROOT . '/apps/files_sharing/lib_share.php'; OCP\JSON::checkAppEnabled('files_sharing'); OCP\JSON::checkLoggedIn(); $userDirectory = '/' . OCP\USER::getUser() . '/files'; $sources = explode(';', $_POST['sources']); $uid_shared_with = $_POST['uid_shared_with']; $permissions = $_POST['permissions']; foreach ($sources as $source) { $file = OC_FileCache::get($source); $path = ltrim($source, '/'); $source = $userDirectory . $source; // Check if the file exists or if the file is being reshared if ($source && $file['encrypted'] == false && (OC_FILESYSTEM::file_exists($path) && OC_FILESYSTEM::is_readable($path) || OC_Share::getSource($source))) { try { $shared = new OC_Share($source, $uid_shared_with, $permissions); // If this is a private link, return the token if ($uid_shared_with == OC_Share::PUBLICLINK) { OCP\JSON::success(array('data' => $shared->getToken())); } else { OCP\JSON::success(); } } catch (Exception $exception) { OCP\Util::writeLog('files_sharing', 'Unexpected Error : ' . $exception->getMessage(), OCP\Util::ERROR); OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); } } else { if ($file['encrypted'] == true) { OCP\JSON::error(array('data' => array('message' => 'Encrypted files cannot be shared'))); } else {
/** * return the content of a file or return a zip file containning multiply files * * @param dir $dir * @param file $file ; seperated 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) { if (strpos($files, ';')) { $files = explode(';', $files); } 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) { exit("cannot open <{$filename}>\n"); } foreach ($files as $file) { $file = $dir . '/' . $file; if (OC_Filesystem::is_file($file)) { $tmpFile = OC_Filesystem::toTmpFile($file); self::$tmpFiles[] = $tmpFile; $zip->addFile($tmpFile, basename($file)); } elseif (OC_Filesystem::is_dir($file)) { self::zipAddDir($file, $zip); } } $zip->close(); set_time_limit($executionTime); } elseif (OC_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) { exit("cannot open <{$filename}>\n"); } $file = $dir . '/' . $files; self::zipAddDir($file, $zip); $zip->close(); set_time_limit($executionTime); } else { $zip = false; $filename = $dir . '/' . $files; } @ob_end_clean(); if ($zip or OC_Filesystem::is_readable($filename)) { header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); 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)); } else { $fileData = OC_FileCache::get($filename); header('Content-Type: ' . $fileData['mimetype']); } } elseif ($zip or !OC_Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template('', '404', 'guest'); $tmpl->assign('file', $filename); $tmpl->printPage(); } else { header("HTTP/1.0 403 Forbidden"); die('403 Forbidden'); } if ($only_header) { if (!$zip) { header("Content-Length: " . OC_Filesystem::filesize($filename)); } return; } if ($zip) { $handle = fopen($filename, 'r'); if ($handle) { $chunkSize = 8 * 1024; // 1 MB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); flush(); } } unlink($filename); } else { OC_Filesystem::readfile($filename); } foreach (self::$tmpFiles as $tmpFile) { if (file_exists($tmpFile) and is_file($tmpFile)) { unlink($tmpFile); } } }
/** * get the quota of a user * @param string $format * @param string $user * @return string xml/json */ private static function quotaGet($format, $user) { $login = OC_OCS::checkpassword(); if (OC_Group::inGroup($login, 'admin') or $login == $user) { if (OC_User::userExists($user)) { // calculate the disc space $user_dir = '/' . $user . '/files'; OC_Filesystem::init($user_dir); $rootInfo = OC_FileCache::get(''); $sharedInfo = OC_FileCache::get('/Shared'); $used = $rootInfo['size'] - $sharedInfo['size']; $free = OC_Filesystem::free_space(); $total = $free + $used; if ($total == 0) { $total = 1; } // prevent division by zero $relative = round($used / $total * 10000) / 100; $xml = array(); $xml['quota'] = $total; $xml['free'] = $free; $xml['used'] = $used; $xml['relative'] = $relative; $txt = OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0); echo $txt; } else { echo self::generateXml('', 'fail', 300, 'User does not exist'); } } else { echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.'); } }
exit; } } $files = $_FILES['files']; $dir = $_POST['dir']; $error = ''; $totalSize = 0; foreach ($files['size'] as $size) { $totalSize += $size; } if ($totalSize > OC_Filesystem::free_space('/')) { OCP\JSON::error(array("data" => array("message" => "Not enough space available"))); exit; } $result = array(); if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); if (is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { $meta = OC_FileCache::get($target); $id = OC_FileCache::getId($target); $result[] = array("status" => "success", 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'id' => $id, 'name' => basename($target)); } } OCP\JSON::encodedPrint($result); exit; } else { $error = 'invalid dir'; } OCP\JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
/** * Copyright (c) 2011, Robin Appelman <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ require_once '../lib/base.php'; OC_Util::checkLoggedIn(); // Highlight navigation entry OC_Util::addScript('settings', 'personal'); OC_Util::addStyle('settings', 'settings'); OC_Util::addScript('3rdparty', 'chosen/chosen.jquery.min'); OC_Util::addStyle('3rdparty', 'chosen'); OC_App::setActiveNavigationEntry('personal'); // calculate the disc space $rootInfo = OC_FileCache::get(''); $used = $rootInfo['size']; $free = OC_Filesystem::free_space(); $total = $free + $used; if ($total == 0) { $total = 1; } // prevent division by zero $relative = round($used / $total * 10000) / 100; $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', ''); $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage()); $languageCodes = OC_L10N::findAvailableLanguages(); sort($languageCodes); //put the current language in the front unset($languageCodes[array_search($lang, $languageCodes)]); array_unshift($languageCodes, $lang);
$ctx = stream_context_create(null, array('notification' => 'progress')); $sourceStream = fopen($source, 'rb', false, $ctx); $target = $dir . '/' . $filename; $result = OC_Filesystem::file_put_contents($target, $sourceStream); if ($result) { $target = OC_Filesystem::normalizePath($target); $meta = OC_FileCache::get($target); $mime = $meta['mimetype']; $id = OC_FileCache::getId($target); $eventSource->send('success', array('mime' => $mime, 'size' => OC_Filesystem::filesize($target), 'id' => $id)); } else { $eventSource->send('error', "Error while downloading " . $source . ' to ' . $target); } $eventSource->close(); exit; } else { if ($content) { if (OC_Filesystem::file_put_contents($dir . '/' . $filename, $content)) { $meta = OC_FileCache::get($dir . '/' . $filename); $id = OC_FileCache::getId($dir . '/' . $filename); OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id))); exit; } } elseif (OC_Files::newFile($dir, $filename, 'file')) { $meta = OC_FileCache::get($dir . '/' . $filename); $id = OC_FileCache::getId($dir . '/' . $filename); OCP\JSON::success(array("data" => array('content' => $content, 'id' => $id))); exit; } } OCP\JSON::error(array("data" => array("message" => "Error when creating the file")));
/** * Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat */ protected function getFileinfoCache() { if (!isset($this->fileinfo_cache)) { if ($fileinfo_cache = OC_FileCache::get($this->path)) { } else { $fileinfo_cache = OC_Filesystem::stat($this->path); } $this->fileinfo_cache = $fileinfo_cache; } }
/** * Returns available diskspace information * * @return array */ public function getQuotaInfo() { $rootInfo = OC_FileCache::get(''); return array($rootInfo['size'], OC_Filesystem::free_space()); }
<?php $installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version'); if (version_compare($installedVersion, '0.3', '<')) { $update_error = false; $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*sharing`'); $result = $query->execute(); $groupShares = array(); //we need to set up user backends, otherwise creating the shares will fail with "because user does not exist" OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); OC_App::loadApps(array('authentication')); while ($row = $result->fetchRow()) { $itemSource = OC_FileCache::getId($row['source'], ''); if ($itemSource != -1) { $file = OC_FileCache::get($row['source'], ''); if ($file['mimetype'] == 'httpd/unix-directory') { $itemType = 'folder'; } else { $itemType = 'file'; } if ($row['permissions'] == 0) { $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_SHARE; } else { $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_SHARE; if ($itemType == 'folder') { $permissions |= OCP\Share::PERMISSION_CREATE; } } $pos = strrpos($row['uid_shared_with'], '@'); if ($pos !== false && OC_Group::groupExists(substr($row['uid_shared_with'], $pos + 1))) {
/** * Copyright (c) 2011, Robin Appelman <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ require_once '../lib/base.php'; OC_Util::checkLoggedIn(); // Highlight navigation entry OC_Util::addScript('settings', 'personal'); OC_Util::addStyle('settings', 'settings'); OC_Util::addScript('3rdparty', 'chosen/chosen.jquery.min'); OC_Util::addStyle('3rdparty', 'chosen'); OC_App::setActiveNavigationEntry('personal'); // calculate the disc space $rootInfo = OC_FileCache::get(''); $sharedInfo = OC_FileCache::get('/Shared'); if (!isset($sharedInfo['size'])) { $sharedSize = 0; } else { $sharedSize = $sharedInfo['size']; } $used = $rootInfo['size'] - $sharedSize; $free = OC_Filesystem::free_space(); $total = $free + $used; if ($total == 0) { $total = 1; } // prevent division by zero $relative = round($used / $total * 10000) / 100; $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', ''); $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage());