public static function getUserQuota($user) { $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default'); if ($userQuota === 'default') { $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none'); } if ($userQuota === 'none') { return \OC\Files\SPACE_UNLIMITED; } else { return OC_Helper::computerFileSize($userQuota); } }
/** * get the quota for the current user * @return int */ private function getQuota() { if ($this->userQuota != -1) { return $this->userQuota; } $userQuota = OC_Preferences::getValue(OC_User::getUser(), 'files', 'quota', 'default'); if ($userQuota == 'default') { $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none'); } if ($userQuota == 'none') { $this->userQuota = 0; } else { $this->userQuota = OC_Helper::computerFileSize($userQuota); } return $this->userQuota; }
/** * get the quota for the user * @param user * @return int */ private function getQuota($user) { if (in_array($user, $this->userQuota)) { return $this->userQuota[$user]; } $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default'); if ($userQuota == 'default') { $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none'); } if ($userQuota == 'none') { $this->userQuota[$user] = -1; } else { $this->userQuota[$user] = OC_Helper::computerFileSize($userQuota); } return $this->userQuota[$user]; }
public function __construct($renderas) { // Decide which page we show if ($renderas == 'user') { parent::__construct('core', 'layout.user'); if (in_array(OC_APP::getCurrentApp(), array('settings', 'admin', 'help')) !== false) { $this->assign('bodyid', 'body-settings', false); } else { $this->assign('bodyid', 'body-user', false); } // Add navigation entry $navigation = OC_App::getNavigation(); $this->assign('navigation', $navigation, false); $this->assign('settingsnavigation', OC_App::getSettingsNavigation(), false); foreach ($navigation as $entry) { if ($entry['active']) { $this->assign('application', $entry['name'], false); break; } } } else { if ($renderas == 'guest') { parent::__construct('core', 'layout.guest'); } else { parent::__construct('core', 'layout.base'); } } $apps_paths = array(); foreach (OC_App::getEnabledApps() as $app) { $apps_paths[$app] = OC_App::getAppWebPath($app); } $this->assign('apps_paths', str_replace('\\/', '/', json_encode($apps_paths)), false); // Ugly unescape slashes waiting for better solution if (OC_Config::getValue('installed', false) && !OC_AppConfig::getValue('core', 'remote_core.css', false)) { OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); } // Add the js files $jsfiles = self::findJavascriptFiles(OC_Util::$scripts); $this->assign('jsfiles', array(), false); if (!empty(OC_Util::$core_scripts)) { $this->append('jsfiles', OC_Helper::linkToRemoteBase('core.js', false)); } foreach ($jsfiles as $info) { $root = $info[0]; $web = $info[1]; $file = $info[2]; $this->append('jsfiles', $web . '/' . $file); } // Add the css files $cssfiles = self::findStylesheetFiles(OC_Util::$styles); $this->assign('cssfiles', array()); if (!empty(OC_Util::$core_styles)) { $this->append('cssfiles', OC_Helper::linkToRemoteBase('core.css', false)); } foreach ($cssfiles as $info) { $root = $info[0]; $web = $info[1]; $file = $info[2]; $paths = explode('/', $file); $in_root = false; foreach (OC::$APPSROOTS as $app_root) { if ($root == $app_root['path']) { $in_root = true; break; } } if ($in_root) { $app = $paths[0]; unset($paths[0]); $path = implode('/', $paths); $this->append('cssfiles', OC_Helper::linkTo($app, $path)); } else { $this->append('cssfiles', $web . '/' . $file); } } }
public static function install($options) { $l = self::getTrans(); $error = array(); $dbtype = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } if (empty($options['directory'])) { $options['directory'] = OC::$SERVERROOT . "/data"; } if (!isset(self::$dbSetupClasses[$dbtype])) { $dbtype = 'sqlite'; } $class = self::$dbSetupClasses[$dbtype]; $dbSetup = new $class(self::getTrans(), 'db_structure.xml'); $error = array_merge($error, $dbSetup->validate($options)); if (count($error) != 0) { return $error; } //no errors, good $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = array(OC_Request::serverHost()); } if (OC_Util::runningOnWindows()) { $datadir = rtrim(realpath($datadir), '\\'); } //use sqlite3 when available, otherise sqlite2 will be used. if ($dbtype == 'sqlite' and class_exists('SQLite3')) { $dbtype = 'sqlite3'; } //generate a random salt that is used to salt the local user passwords $salt = OC_Util::generateRandomBytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file OC_Config::setValue('trusted_domains', $trustedDomains); OC_Config::setValue('datadirectory', $datadir); OC_Config::setValue('dbtype', $dbtype); OC_Config::setValue('version', implode('.', OC_Util::getVersion())); try { $dbSetup->initialize($options); $dbSetup->setupDatabase($username); } catch (DatabaseSetupException $e) { $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint()); return $error; } catch (Exception $e) { $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => ''); return $error; } //create the user and group try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { OC_Appconfig::setValue('core', 'installedat', microtime(true)); OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); //guess what this does OC_Installer::installShippedApps(); // create empty file in data dir, so we can later find // out that this is indeed an ownCloud data directory file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', ''); //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } //and we are done OC_Config::setValue('installed', true); } return $error; }
public static function gc() { $last_run = \OC_AppConfig::getValue('core', 'global_cache_gc_lastrun', 0); $now = time(); if ($now - $last_run < 300) { // only do cleanup every 5 minutes return; } \OC_AppConfig::setValue('core', 'global_cache_gc_lastrun', $now); $cache_dir = self::getCacheDir(); if ($cache_dir and is_dir($cache_dir)) { $dh = opendir($cache_dir); if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { if ($file != '.' and $file != '..') { $mtime = filemtime($cache_dir . $file); if ($mtime < $now) { unlink($cache_dir . $file); } } } } } }
<?php $RUNTIME_NOAPPS = TRUE; require_once 'lib/base.php'; $path_info = OC_Request::getPathInfo(); if ($path_info === false || $path_info === '') { OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); exit; } if (!($pos = strpos($path_info, '/', 1))) { $pos = strlen($path_info); } $service = substr($path_info, 1, $pos - 1); $file = OC_AppConfig::getValue('core', 'remote_' . $service); if (is_null($file)) { OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); exit; } $file = ltrim($file, '/'); $parts = explode('/', $file, 2); $app = $parts[0]; switch ($app) { case 'core': $file = OC::$SERVERROOT . '/' . $file; break; default: OC_Util::checkAppEnabled($app); OC_App::loadApp($app); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $file = OC_App::getAppPath($app) . '/' . $parts[1]; } else {
public static function install($options) { $l = self::getTrans(); $error = array(); $dbtype = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); } if (empty($options['adminpass'])) { $error[] = $l->t('Set an admin password.'); } if (empty($options['directory'])) { $error[] = $l->t('Specify a data folder.'); } if ($dbtype == 'mysql' or $dbtype == 'pgsql' or $dbtype == 'oci' or $dbtype == 'mssql') { //mysql and postgresql needs more config options if ($dbtype == 'mysql') { $dbprettyname = 'MySQL'; } else { if ($dbtype == 'pgsql') { $dbprettyname = 'PostgreSQL'; } else { if ($dbtype == 'mssql') { $dbprettyname = 'MS SQL Server'; } else { $dbprettyname = 'Oracle'; } } } if (empty($options['dbuser'])) { $error[] = $l->t("%s enter the database username.", array($dbprettyname)); } if (empty($options['dbname'])) { $error[] = $l->t("%s enter the database name.", array($dbprettyname)); } if (substr_count($options['dbname'], '.') >= 1) { $error[] = $l->t("%s you may not use dots in the database name", array($dbprettyname)); } if ($dbtype != 'oci' && empty($options['dbhost'])) { $error[] = $l->t("%s set the database host.", array($dbprettyname)); } } if (count($error) == 0) { //no errors, good $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); if (OC_Util::runningOnWindows()) { $datadir = rtrim(realpath($datadir), '\\'); } //use sqlite3 when available, otherise sqlite2 will be used. if ($dbtype == 'sqlite' and class_exists('SQLite3')) { $dbtype = 'sqlite3'; } //generate a random salt that is used to salt the local user passwords $salt = OC_Util::generate_random_bytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file OC_Config::setValue('datadirectory', $datadir); OC_Config::setValue('dbtype', $dbtype); OC_Config::setValue('version', implode('.', OC_Util::getVersion())); if ($dbtype == 'mysql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); try { self::setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username); } catch (DatabaseSetupException $e) { $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint()); return $error; } catch (Exception $e) { $error[] = array('error' => $e->getMessage(), 'hint' => ''); return $error; } } elseif ($dbtype == 'pgsql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); try { self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username); } catch (Exception $e) { $error[] = array('error' => $l->t('PostgreSQL username and/or password not valid'), 'hint' => $l->t('You need to enter either an existing account or the administrator.')); return $error; } } elseif ($dbtype == 'oci') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; if (array_key_exists('dbtablespace', $options)) { $dbtablespace = $options['dbtablespace']; } else { $dbtablespace = 'USERS'; } $dbhost = isset($options['dbhost']) ? $options['dbhost'] : ''; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); try { self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username); } catch (Exception $e) { $error[] = array('error' => $l->t('Oracle connection could not be established'), 'hint' => $e->getMessage() . ' Check environment: ORACLE_HOME=' . getenv('ORACLE_HOME') . ' ORACLE_SID=' . getenv('ORACLE_SID') . ' LD_LIBRARY_PATH=' . getenv('LD_LIBRARY_PATH') . ' NLS_LANG=' . getenv('NLS_LANG') . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable'); return $error; } } elseif ($dbtype == 'mssql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbuser', $dbuser); OC_Config::setValue('dbpassword', $dbpass); OC_Config::setValue('dbtableprefix', $dbtableprefix); try { self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix); } catch (Exception $e) { $error[] = array('error' => 'MS SQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.'); return $error; } } else { //delete the old sqlite database first, might cause infinte loops otherwise if (file_exists("{$datadir}/owncloud.db")) { unlink("{$datadir}/owncloud.db"); } //in case of sqlite, we can always fill the database OC_DB::createDbFromStructure('db_structure.xml'); } //create the user and group try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { OC_Appconfig::setValue('core', 'installedat', microtime(true)); OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); OC_User::login($username, $password); //guess what this does OC_Installer::installShippedApps(); //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } //and we are done OC_Config::setValue('installed', true); } } return $error; }