Ejemplo n.º 1
0
 /**
  * Formats the file info to be returned as OPDS to the client
  *
  * @param \OCP\Files\FileInfo $i
  * @return array formatted file info
  */
 public static function formatFileInfo(\OCP\Files\FileInfo $i)
 {
     $entry = array();
     $entry['id'] = $i['fileid'];
     $entry['mtime'] = $i['mtime'];
     $entry['name'] = $i->getName();
     $entry['type'] = $i['type'];
     if ($i['type'] === 'file') {
         $entry['mimetype'] = $i['mimetype'];
         $entry['humansize'] = \OC_Helper::humanFileSize($i['size']);
         $entry['meta'] = Meta::get($i['fileid']);
     }
     return $entry;
 }
Ejemplo n.º 2
0
 function testHumanFileSize()
 {
     $result = OC_Helper::humanFileSize(0);
     $expected = '0 B';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::humanFileSize(1024);
     $expected = '1 kB';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::humanFileSize(10000000);
     $expected = '9.5 MB';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::humanFileSize(500000000000.0);
     $expected = '465.7 GB';
     $this->assertEquals($result, $expected);
 }
Ejemplo n.º 3
0
 public function getSize($username, $mountData)
 {
     $keys = array_keys($mountData);
     $bucket = $mountData[$keys[0]]['options']['bucket'];
     $params = array('key' => \OCP\config::getSystemValue('S3key'), 'secret' => \OCP\config::getSystemValue('S3secret'), 'bucket' => $bucket, 'use_ssl' => 'false', 'hostname' => '', 'port' => '', 'region' => '', 'use_path_style' => '');
     $amazon = new AmazonS3($params);
     $client = $amazon->getConnection();
     // check if bucket exists
     if (!$client->doesBucketExist($bucket, $accept403 = true)) {
         return false;
     }
     // get bucket objects
     $objects = $client->getBucket(array('Bucket' => $bucket));
     $total_size_bytes = 0;
     $contents = $objects['Contents'];
     // iterate through all contents to get total size
     foreach ($contents as $key => $value) {
         $total_size_bytes += $value['Size'];
     }
     //$total_size_gb = $total_size_bytes / 1024 / 1024 / 1024;
     $total_size = \OC_Helper::humanFileSize($total_size_bytes);
     $node = array('username' => $username, 'usage' => $total_size);
     return $node;
 }
Ejemplo n.º 4
0
/**
 * make OC_Helper::humanFileSize available as a simple function
 * @param int $bytes size in bytes
 * @return string size as string
 *
 * For further information have a look at OC_Helper::humanFileSize
 */
function human_file_size($bytes)
{
    return OC_Helper::humanFileSize($bytes);
}
Ejemplo n.º 5
0
 /**
  * Make a human file size (2048 to 2 kB)
  * @param int $bytes file size in bytes
  * @return string a human readable file size
  * @since 4.0.0
  */
 public static function humanFileSize($bytes)
 {
     return \OC_Helper::humanFileSize($bytes);
 }
Ejemplo n.º 6
0
 /**
  * set the maximum upload size limit for apache hosts using .htaccess
  * @param int size filesisze in bytes
  * @return false on failure, size on success
  */
 static function setUploadLimit($size)
 {
     //don't allow user to break his config -- upper boundary
     if ($size > PHP_INT_MAX) {
         //max size is always 1 byte lower than computerFileSize returns
         if ($size > PHP_INT_MAX + 1) {
             return false;
         }
         $size -= 1;
     } else {
         $size = OC_Helper::humanFileSize($size);
         $size = substr($size, 0, -1);
         //strip the B
         $size = str_replace(' ', '', $size);
         //remove the space between the size and the postfix
     }
     //don't allow user to break his config -- broken or malicious size input
     if (intval($size) == 0) {
         return false;
     }
     $htaccess = @file_get_contents(OC::$SERVERROOT . '/.htaccess');
     //supress errors in case we don't have permissions for
     if (!$htaccess) {
         return false;
     }
     $phpValueKeys = array('upload_max_filesize', 'post_max_size');
     foreach ($phpValueKeys as $key) {
         $pattern = '/php_value ' . $key . ' (\\S)*/';
         $setting = 'php_value ' . $key . ' ' . $size;
         $hasReplaced = 0;
         $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
         if ($content !== NULL) {
             $htaccess = $content;
         }
         if ($hasReplaced == 0) {
             $htaccess .= "\n" . $setting;
         }
     }
     //supress errors in case we don't have permissions for it
     if (@file_put_contents(OC::$SERVERROOT . '/.htaccess', $htaccess)) {
         return OC_Helper::computerFileSize($size);
     }
     return false;
 }
Ejemplo n.º 7
0
 *
 * 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/>
 *
 */
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();
$username = isset($_POST["username"]) ? (string) $_POST["username"] : '';
if ($username === '' && !OC_User::isAdminUser(OC_User::getUser()) || !OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
    $l = \OC::$server->getL10N('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
    exit;
}
//make sure the quota is in the expected format
$quota = (string) $_POST["quota"];
if ($quota !== 'none' and $quota !== 'default') {
    $quota = OC_Helper::computerFileSize($quota);
    $quota = OC_Helper::humanFileSize($quota);
}
// Return Success story
if ($username) {
    \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
} else {
    //set the default quota when no username is specified
    if ($quota === 'default') {
        //'default' as default quota makes no sense
        $quota = 'none';
    }
    OC_Appconfig::setValue('files', 'default_quota', $quota);
}
OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
Ejemplo n.º 8
0
    return strcmp($a['name'], $b['name']);
});
//links to clients
$clients = array('desktop' => $config->getSystemValue('customclient_desktop', $defaults->getSyncClientUrl()), 'android' => $config->getSystemValue('customclient_android', $defaults->getAndroidClientUrl()), 'ios' => $config->getSystemValue('customclient_ios', $defaults->getiOSClientUrl()));
// only show root certificate import if external storages are enabled
$enableCertImport = false;
$externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
if ($externalStorageEnabled) {
    /** @var \OCA\Files_External\Service\BackendService $backendService */
    $backendService = \OC_Mount_Config::$app->getContainer()->query('\\OCA\\Files_External\\Service\\BackendService');
    $enableCertImport = $backendService->isUserMountingAllowed();
}
// Return template
$tmpl = new OC_Template('settings', 'personal', 'user');
$tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
$tmpl->assign('total_space', OC_Helper::humanFileSize($storageInfo['total']));
$tmpl->assign('usage_relative', $storageInfo['relative']);
$tmpl->assign('clients', $clients);
$tmpl->assign('email', $email);
$tmpl->assign('languages', $languages);
$tmpl->assign('commonlanguages', $commonLanguages);
$tmpl->assign('activelanguage', $userLang);
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
$tmpl->assign('displayName', OC_User::getDisplayName());
$tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true));
$tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
$tmpl->assign('certs', $certificateManager->listCertificates());
$tmpl->assign('showCertificates', $enableCertImport);
$tmpl->assign('urlGenerator', $urlGenerator);
// Get array of group ids for this user
Ejemplo n.º 9
0
// only show root certificate import if external storages are enabled
$enableCertImport = false;
$externalStorageEnabled = \OC::$server->getAppManager()->isEnabledForUser('files_external');
if ($externalStorageEnabled) {
    /** @var \OCA\Files_External\Service\BackendService $backendService */
    $backendService = \OC_Mount_Config::$app->getContainer()->query('\\OCA\\Files_External\\Service\\BackendService');
    $enableCertImport = $backendService->isUserMountingAllowed();
}
// Return template
$l = \OC::$server->getL10N('settings');
$tmpl = new OC_Template('settings', 'personal', 'user');
$tmpl->assign('usage', OC_Helper::humanFileSize($storageInfo['used']));
if ($storageInfo['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED) {
    $totalSpace = $l->t('Unlimited');
} else {
    $totalSpace = OC_Helper::humanFileSize($storageInfo['total']);
}
$tmpl->assign('total_space', $totalSpace);
$tmpl->assign('usage_relative', $storageInfo['relative']);
$tmpl->assign('clients', $clients);
$tmpl->assign('email', $email);
$tmpl->assign('languages', $languages);
$tmpl->assign('commonlanguages', $commonLanguages);
$tmpl->assign('activelanguage', $userLang);
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
$tmpl->assign('displayName', OC_User::getDisplayName());
$tmpl->assign('enableAvatars', $config->getSystemValue('enable_avatars', true) === true);
$tmpl->assign('avatarChangeSupported', OC_User::canUserChangeAvatar(OC_User::getUser()));
$tmpl->assign('certs', $certificateManager->listCertificates());
$tmpl->assign('showCertificates', $enableCertImport);
Ejemplo n.º 10
0
 /**
  * @dataProvider humanFileSizeProvider
  */
 public function testHumanFileSize($expected, $input)
 {
     $result = OC_Helper::humanFileSize($input);
     $this->assertEquals($expected, $result);
 }
$breadcrumb = array();
$pathtohere = "";
foreach (explode("/", $dir) as $i) {
    if ($i != "") {
        $pathtohere .= "/" . str_replace('+', '%20', urlencode($i));
        $breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
    }
}
// make breadcrumb und filelist markup
$list = new OC_Template("files", "part.list", "");
$list->assign("files", $files);
$list->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$list->assign("downloadURL", OC_Helper::linkTo("files", "download.php") . "?file=");
$breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
$breadcrumbNav->assign("breadcrumb", $breadcrumb);
$breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace = OC_Filesystem::free_space('/');
$freeSpace = max($freeSpace, 0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$tmpl = new OC_Template("files", "index", "user");
$tmpl->assign("fileList", $list->fetchPage());
$tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
$tmpl->assign('dir', $dir);
$tmpl->assign('readonly', !OC_Filesystem::is_writable($dir));
$tmpl->assign("files", $files);
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->printPage();
Ejemplo n.º 12
0
 /**
  * converts a zend lucene search object to a OC_SearchResult
  *
  * Example:
  * 
  * Text | Some Document.txt
  *      | /path/to/file, 148kb, Score: 0.55
  * 
  * @author Jörn Dreyer <*****@*****.**>
  *
  * @param Zend_Search_Lucene_Search_QueryHit $hit The Lucene Search Result
  * @return OC_Search_Result an OC_Search_Result
  */
 private static function asOCSearchResult(\Zend_Search_Lucene_Search_QueryHit $hit)
 {
     $mimeBase = self::baseTypeOf($hit->mimetype);
     switch ($mimeBase) {
         case 'audio':
             $type = 'Music';
             break;
         case 'text':
             $type = 'Text';
             break;
         case 'image':
             $type = 'Images';
             break;
         default:
             if ($hit->mimetype == 'application/xml') {
                 $type = 'Text';
             } else {
                 $type = 'Files';
             }
     }
     switch ($hit->mimetype) {
         case 'httpd/unix-directory':
             $url = Util::linkTo('files', 'index.php') . '?dir=' . $hit->path;
             break;
         default:
             $url = \OC::getRouter()->generate('download', array('file' => $hit->path));
     }
     return new \OC_Search_Result(basename($hit->path), dirname($hit->path) . ', ' . \OC_Helper::humanFileSize($hit->size) . ', Score: ' . number_format($hit->score, 2), $url, $type);
 }
Ejemplo n.º 13
0
sort($languageCodes);
//put the current language in the front
unset($languageCodes[array_search($lang, $languageCodes)]);
array_unshift($languageCodes, $lang);
$languageNames = (include 'languageCodes.php');
$languages = array();
foreach ($languageCodes as $lang) {
    $l = OC_L10N::get('settings', $lang);
    if (substr($l->t('__language_name__'), 0, 1) != '_') {
        //first check if the language name is in the translation file
        $languages[] = array('code' => $lang, 'name' => $l->t('__language_name__'));
    } elseif (isset($languageNames[$lang])) {
        $languages[] = array('code' => $lang, 'name' => $languageNames[$lang]);
    } else {
        //fallback to language code
        $languages[] = array('code' => $lang, 'name' => $lang);
    }
}
// Return template
$tmpl = new OC_Template('settings', 'personal', 'user');
$tmpl->assign('usage', OC_Helper::humanFileSize($used));
$tmpl->assign('total_space', OC_Helper::humanFileSize($total));
$tmpl->assign('usage_relative', $relative);
$tmpl->assign('email', $email);
$tmpl->assign('languages', $languages);
$forms = OC_App::getForms('personal');
$tmpl->assign('forms', array());
foreach ($forms as $form) {
    $tmpl->append('forms', $form);
}
$tmpl->printPage();
 /**
  * set the maximum upload size limit for apache hosts using .htaccess
  * @param int size filesisze in bytes
  */
 static function setUploadLimit($size)
 {
     $size = OC_Helper::humanFileSize($size);
     $size = substr($size, 0, -1);
     //strip the B
     $size = str_replace(' ', '', $size);
     //remove the space between the size and the postfix
     $content = "ErrorDocument 404 /" . OC::$WEBROOT . "/core/templates/404.php\n";
     //custom 404 error page
     $content .= "php_value upload_max_filesize {$size}\n";
     //upload limit
     $content .= "php_value post_max_size {$size}\n";
     $content .= "SetEnv htaccessWorking true\n";
     $content .= "Options -Indexes\n";
     @file_put_contents(OC::$SERVERROOT . '/.htaccess', $content);
     //supress errors in case we don't have permissions for it
 }
<?php

/**
 * 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::checkAdminUser();
// We have some javascript foo!
OC_Util::addScript('settings', 'users');
OC_Util::addScript('core', 'multiselect');
OC_Util::addStyle('settings', 'settings');
OC_App::setActiveNavigationEntry('core_users');
$users = array();
$groups = array();
foreach (OC_User::getUsers() as $i) {
    $users[] = array("name" => $i, "groups" => join(", ", OC_Group::getUserGroups($i)), 'quota' => OC_Helper::humanFileSize(OC_Preferences::getValue($i, 'files', 'quota', 0)));
}
foreach (OC_Group::getGroups() as $i) {
    // Do some more work here soon
    $groups[] = array("name" => $i);
}
$tmpl = new OC_Template("settings", "users", "user");
$tmpl->assign("users", $users);
$tmpl->assign("groups", $groups);
$tmpl->printPage();
?>

Ejemplo n.º 16
0
$json = json_decode($str, true);
$result = array();
//print_r ($json);
foreach ($json['user'] as $username => $user) {
    $keys = array_keys($user);
    $bucket = $user[$keys[0]]['options']['bucket'];
    $params = array('key' => \OCP\config::getSystemValue('S3key'), 'secret' => \OCP\config::getSystemValue('S3secret'), 'bucket' => $bucket, 'use_ssl' => 'false', 'hostname' => '', 'port' => '', 'region' => '', 'use_path_style' => '');
    $amazon = new AmazonS3($params);
    $client = $amazon->getConnection();
    // check if bucket exists
    if (!$client->doesBucketExist($bucket, $accept403 = true)) {
        return false;
    }
    // get bucket objects
    $objects = $client->getBucket(array('Bucket' => $bucket));
    $total_size_bytes = 0;
    $contents = $objects['Contents'];
    // iterate through all contents to get total size
    foreach ($contents as $key => $value) {
        $total_size_bytes += $value['Size'];
    }
    //$total_size_gb = $total_size_bytes / 1024 / 1024 / 1024;
    $total_size = OC_Helper::humanFileSize($total_size_bytes);
    $node = array('username' => $username, 'usage' => $total_size);
    array_push($result, $node);
}
header('Content-Type: application/json');
echo json_encode($result);
?>