Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/util.php')
-rwxr-xr-xlib/private/util.php79
1 files changed, 64 insertions, 15 deletions
diff --git a/lib/private/util.php b/lib/private/util.php
index 6bccaa00261..dea5f2cafcf 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -11,8 +11,6 @@ class OC_Util {
public static $headers=array();
private static $rootMounted=false;
private static $fsSetup=false;
- public static $coreStyles=array();
- public static $coreScripts=array();
/**
* @brief Can be set up
@@ -63,7 +61,7 @@ class OC_Util {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
- return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
+ return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
}
}
@@ -88,10 +86,14 @@ class OC_Util {
return true;
}
+ /**
+ * @param string $user
+ */
public static function getUserQuota($user){
- $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default');
+ $config = \OC::$server->getConfig();
+ $userQuota = $config->getUserValue($user, 'files', 'quota', 'default');
if($userQuota === 'default') {
- $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
+ $userQuota = $config->getAppValue('files', 'default_quota', 'none');
}
if($userQuota === 'none') {
return \OC\Files\SPACE_UNLIMITED;
@@ -212,7 +214,7 @@ class OC_Util {
* @brief add a javascript file
*
* @param string $application
- * @param filename $file
+ * @param string|null $file filename
* @return void
*/
public static function addScript( $application, $file = null ) {
@@ -231,7 +233,7 @@ class OC_Util {
* @brief add a css file
*
* @param string $application
- * @param filename $file
+ * @param string|null $file filename
* @return void
*/
public static function addStyle( $application, $file = null ) {
@@ -286,13 +288,19 @@ class OC_Util {
* @return array arrays with error messages and hints
*/
public static function checkServer() {
+ $errors = array();
+ $CONFIG_DATADIRECTORY = OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data');
+
+ if (!\OC::needUpgrade() && OC_Config::getValue('installed', false)) {
+ // this check needs to be done every time
+ $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
+ }
+
// Assume that if checkServer() succeeded before in this session, then all is fine.
if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) {
- return array();
+ return $errors;
}
- $errors = array();
-
$defaults = new \OC_Defaults();
$webServerRestart = false;
@@ -337,7 +345,6 @@ class OC_Util {
);
}
}
- $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
// Create root dir.
if(!is_dir($CONFIG_DATADIRECTORY)) {
$success=@mkdir($CONFIG_DATADIRECTORY);
@@ -510,7 +517,7 @@ class OC_Util {
/**
* @brief Check for correct file permissions of data directory
- * @paran string $dataDirectory
+ * @param string $dataDirectory
* @return array arrays with error messages and hints
*/
public static function checkDataDirectoryPermissions($dataDirectory) {
@@ -522,7 +529,7 @@ class OC_Util {
.' cannot be listed by other users.';
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($perms, -1) != '0') {
- OC_Helper::chmodr($dataDirectory, 0770);
+ chmod($dataDirectory, 0770);
clearstatcache();
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
if (substr($perms, 2, 1) != '0') {
@@ -537,6 +544,25 @@ class OC_Util {
}
/**
+ * Check that the data directory exists and is valid by
+ * checking the existence of the ".ocdata" file.
+ *
+ * @param string $dataDirectory data directory path
+ * @return bool true if the data directory is valid, false otherwise
+ */
+ public static function checkDataDirectoryValidity($dataDirectory) {
+ $errors = array();
+ if (!file_exists($dataDirectory.'/.ocdata')) {
+ $errors[] = array(
+ 'error' => 'Data directory (' . $dataDirectory . ') is invalid',
+ 'hint' => 'Please check that the data directory contains a file' .
+ ' ".ocdata" in its root.'
+ );
+ }
+ return $errors;
+ }
+
+ /**
* @return void
*/
public static function displayLoginPage($errors = array()) {
@@ -564,6 +590,7 @@ class OC_Util {
/**
* @brief Check if the app is enabled, redirects to home if not
+ * @param string $app
* @return void
*/
public static function checkAppEnabled($app) {
@@ -623,7 +650,7 @@ class OC_Util {
/**
* @brief Check if the user is a subadmin, redirects to home if not
- * @return array $groups where the current user is subadmin
+ * @return null|boolean $groups where the current user is subadmin
*/
public static function checkSubAdminUser() {
OC_Util::checkLoggedIn();
@@ -922,7 +949,7 @@ class OC_Util {
/**
* @brief Check if the connection to the internet is disabled on purpose
- * @return bool
+ * @return string
*/
public static function isInternetConnectionEnabled(){
return \OC_Config::getValue("has_internet_connection", true);
@@ -1127,6 +1154,7 @@ class OC_Util {
}
/**
+ * @param boolean|string $file
* @return string
*/
public static function basename($file) {
@@ -1147,4 +1175,25 @@ class OC_Util {
}
return $version;
}
+
+ /**
+ * Returns whether the given file name is valid
+ * @param $file string file name to check
+ * @return bool true if the file name is valid, false otherwise
+ */
+ public static function isValidFileName($file) {
+ $trimmed = trim($file);
+ if ($trimmed === '') {
+ return false;
+ }
+ if ($trimmed === '.' || $trimmed === '..') {
+ return false;
+ }
+ foreach (str_split($trimmed) as $char) {
+ if (strpos(\OCP\FILENAME_INVALID_CHARS, $char) !== false) {
+ return false;
+ }
+ }
+ return true;
+ }
}