From 9c9dc276b7a1d2592c4fb0a887888632dc1f1e29 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 25 Sep 2013 13:36:30 +0200 Subject: move the private namespace OC into lib/private - OCP will stay in lib/public Conflicts: lib/private/vcategories.php --- lib/private/util.php | 1019 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1019 insertions(+) create mode 100755 lib/private/util.php (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php new file mode 100755 index 00000000000..6be56d07c9a --- /dev/null +++ b/lib/private/util.php @@ -0,0 +1,1019 @@ +$configDataDirectory), '/'); + self::$rootMounted = true; + } + + //if we aren't logged in, there is no use to set up the filesystem + if( $user != "" ) { + $quota = self::getUserQuota($user); + if ($quota !== \OC\Files\SPACE_UNLIMITED) { + \OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage) use ($quota, $user) { + if ($mountPoint === '/' . $user . '/'){ + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota)); + } else { + return $storage; + } + }); + } + $userDir = '/'.$user.'/files'; + $userRoot = OC_User::getHome($user); + $userDirectory = $userRoot . '/files'; + if( !is_dir( $userDirectory )) { + mkdir( $userDirectory, 0755, true ); + } + //jail the user into his "home" directory + \OC\Files\Filesystem::init($user, $userDir); + + $fileOperationProxy = new OC_FileProxy_FileOperations(); + OC_FileProxy::register($fileOperationProxy); + + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); + } + return true; + } + + 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); + } + } + + /** + * @return void + */ + public static function tearDownFS() { + \OC\Files\Filesystem::tearDown(); + self::$fsSetup=false; + self::$rootMounted=false; + } + + /** + * @brief get the current installed version of ownCloud + * @return array + */ + public static function getVersion() { + // hint: We only can count up. Reset minor/patchlevel when + // updating major/minor version number. + return array(5, 80, 07); + } + + /** + * @brief get the current installed version string of ownCloud + * @return string + */ + public static function getVersionString() { + return '6.0 pre alpha'; + } + + /** + * @description get the current installed edition of ownCloud. There is the community + * edition that just returns an empty string and the enterprise edition + * that returns "Enterprise". + * @return string + */ + public static function getEditionString() { + return ''; + } + + /** + * @brief add a javascript file + * + * @param string $application + * @param filename $file + * @return void + */ + public static function addScript( $application, $file = null ) { + if ( is_null( $file )) { + $file = $application; + $application = ""; + } + if ( !empty( $application )) { + self::$scripts[] = "$application/js/$file"; + } else { + self::$scripts[] = "js/$file"; + } + } + + /** + * @brief add a css file + * + * @param string $application + * @param filename $file + * @return void + */ + public static function addStyle( $application, $file = null ) { + if ( is_null( $file )) { + $file = $application; + $application = ""; + } + if ( !empty( $application )) { + self::$styles[] = "$application/css/$file"; + } else { + self::$styles[] = "css/$file"; + } + } + + /** + * @brief Add a custom element to the header + * @param string $tag tag name of the element + * @param array $attributes array of attributes for the element + * @param string $text the text content for the element + * @return void + */ + public static function addHeader( $tag, $attributes, $text='') { + self::$headers[] = array( + 'tag'=>$tag, + 'attributes'=>$attributes, + 'text'=>$text + ); + } + + /** + * @brief formats a timestamp in the "right" way + * + * @param int $timestamp + * @param bool $dateOnly option to omit time from the result + * @return string timestamp + * @description adjust to clients timezone if we know it + */ + public static function formatDate( $timestamp, $dateOnly=false) { + if(\OC::$session->exists('timezone')) { + $systemTimeZone = intval(date('O')); + $systemTimeZone = (round($systemTimeZone/100, 0)*60) + ($systemTimeZone%100); + $clientTimeZone = \OC::$session->get('timezone')*60; + $offset = $clientTimeZone - $systemTimeZone; + $timestamp = $timestamp + $offset*60; + } + $l = OC_L10N::get('lib'); + return $l->l($dateOnly ? 'date' : 'datetime', $timestamp); + } + + /** + * @brief check if the current server configuration is suitable for ownCloud + * @return array arrays with error messages and hints + */ + public static function checkServer() { + // 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(); + } + + $errors = array(); + + $defaults = new \OC_Defaults(); + + $webServerRestart = false; + //check for database drivers + if(!(is_callable('sqlite_open') or class_exists('SQLite3')) + and !is_callable('mysql_connect') + and !is_callable('pg_connect') + and !is_callable('oci_connect')) { + $errors[] = array( + 'error'=>'No database drivers (sqlite, mysql, or postgresql) installed.', + 'hint'=>'' //TODO: sane hint + ); + $webServerRestart = true; + } + + //common hint for all file permissions error messages + $permissionsHint = 'Permissions can usually be fixed by ' + .'giving the webserver write access to the root directory.'; + + // Check if config folder is writable. + if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) { + $errors[] = array( + 'error' => "Can't write into config directory", + 'hint' => 'This can usually be fixed by ' + .'giving the webserver write access to the config directory.' + ); + } + + // Check if there is a writable install folder. + if(OC_Config::getValue('appstoreenabled', true)) { + if( OC_App::getInstallPath() === null + || !is_writable(OC_App::getInstallPath()) + || !is_readable(OC_App::getInstallPath()) ) { + $errors[] = array( + 'error' => "Can't write into apps directory", + 'hint' => 'This can usually be fixed by ' + .'giving the webserver write access to the apps directory ' + .'or disabling the appstore in the config file.' + ); + } + } + $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); + // Create root dir. + if(!is_dir($CONFIG_DATADIRECTORY)) { + $success=@mkdir($CONFIG_DATADIRECTORY); + if ($success) { + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); + } else { + $errors[] = array( + 'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")", + 'hint' => 'This can usually be fixed by ' + .'giving the webserver write access to the root directory.' + ); + } + } else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { + $errors[] = array( + 'error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud', + 'hint'=>$permissionsHint + ); + } else { + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); + } + + $moduleHint = "Please ask your server administrator to install the module."; + // check if all required php modules are present + if(!class_exists('ZipArchive')) { + $errors[] = array( + 'error'=>'PHP module zip not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!class_exists('DOMDocument')) { + $errors[] = array( + 'error' => 'PHP module dom not installed.', + 'hint' => $moduleHint + ); + $webServerRestart =true; + } + if(!function_exists('xml_parser_create')) { + $errors[] = array( + 'error' => 'PHP module libxml not installed.', + 'hint' => $moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('mb_detect_encoding')) { + $errors[] = array( + 'error'=>'PHP module mb multibyte not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('ctype_digit')) { + $errors[] = array( + 'error'=>'PHP module ctype is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('json_encode')) { + $errors[] = array( + 'error'=>'PHP module JSON is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!extension_loaded('gd') || !function_exists('gd_info')) { + $errors[] = array( + 'error'=>'PHP module GD is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('gzencode')) { + $errors[] = array( + 'error'=>'PHP module zlib is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('iconv')) { + $errors[] = array( + 'error'=>'PHP module iconv is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(!function_exists('simplexml_load_string')) { + $errors[] = array( + 'error'=>'PHP module SimpleXML is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if(floatval(phpversion()) < 5.3) { + $errors[] = array( + 'error'=>'PHP 5.3 is required.', + 'hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher.' + .' PHP 5.2 is no longer supported by ownCloud and the PHP community.' + ); + $webServerRestart = true; + } + if(!defined('PDO::ATTR_DRIVER_NAME')) { + $errors[] = array( + 'error'=>'PHP PDO module is not installed.', + 'hint'=>$moduleHint + ); + $webServerRestart = true; + } + if (((strtolower(@ini_get('safe_mode')) == 'on') + || (strtolower(@ini_get('safe_mode')) == 'yes') + || (strtolower(@ini_get('safe_mode')) == 'true') + || (ini_get("safe_mode") == 1 ))) { + $errors[] = array( + 'error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.', + 'hint'=>'PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. ' + .'Please ask your server administrator to disable it in php.ini or in your webserver config.' + ); + $webServerRestart = true; + } + if (get_magic_quotes_gpc() == 1 ) { + $errors[] = array( + 'error'=>'Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.', + 'hint'=>'Magic Quotes is a deprecated and mostly useless setting that should be disabled. ' + .'Please ask your server administrator to disable it in php.ini or in your webserver config.' + ); + $webServerRestart = true; + } + + if($webServerRestart) { + $errors[] = array( + 'error'=>'PHP modules have been installed, but they are still listed as missing?', + 'hint'=>'Please ask your server administrator to restart the web server.' + ); + } + + // Cache the result of this function + \OC::$session->set('checkServer_suceeded', count($errors) == 0); + + return $errors; + } + + /** + * @brief check if there are still some encrypted files stored + * @return boolean + */ + public static function encryptedFiles() { + //check if encryption was enabled in the past + $encryptedFiles = false; + if (OC_App::isEnabled('files_encryption') === false) { + $view = new OC\Files\View('/' . OCP\User::getUser()); + $keyfilePath = '/files_encryption/keyfiles'; + if ($view->is_dir($keyfilePath)) { + $dircontent = $view->getDirectoryContent($keyfilePath); + if (!empty($dircontent)) { + $encryptedFiles = true; + } + } + } + + return $encryptedFiles; + } + + /** + * @brief Check for correct file permissions of data directory + * @paran string $dataDirectory + * @return array arrays with error messages and hints + */ + public static function checkDataDirectoryPermissions($dataDirectory) { + $errors = array(); + if (self::runningOnWindows()) { + //TODO: permissions checks for windows hosts + } else { + $permissionsModHint = 'Please change the permissions to 0770 so that the directory' + .' cannot be listed by other users.'; + $perms = substr(decoct(@fileperms($dataDirectory)), -3); + if (substr($perms, -1) != '0') { + OC_Helper::chmodr($dataDirectory, 0770); + clearstatcache(); + $perms = substr(decoct(@fileperms($dataDirectory)), -3); + if (substr($perms, 2, 1) != '0') { + $errors[] = array( + 'error' => 'Data directory ('.$dataDirectory.') is readable for other users', + 'hint' => $permissionsModHint + ); + } + } + } + return $errors; + } + + /** + * @return void + */ + public static function displayLoginPage($errors = array()) { + $parameters = array(); + foreach( $errors as $key => $value ) { + $parameters[$value] = true; + } + if (!empty($_POST['user'])) { + $parameters["username"] = $_POST['user']; + $parameters['user_autofocus'] = false; + } else { + $parameters["username"] = ''; + $parameters['user_autofocus'] = true; + } + if (isset($_REQUEST['redirect_url'])) { + $redirectUrl = $_REQUEST['redirect_url']; + $parameters['redirect_url'] = urlencode($redirectUrl); + } + + $parameters['alt_login'] = OC_App::getAlternativeLogIns(); + OC_Template::printGuestPage("", "login", $parameters); + } + + + /** + * @brief Check if the app is enabled, redirects to home if not + * @return void + */ + public static function checkAppEnabled($app) { + if( !OC_App::isEnabled($app)) { + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); + exit(); + } + } + + /** + * Check if the user is logged in, redirects to home if not. With + * redirect URL parameter to the request URI. + * @return void + */ + public static function checkLoggedIn() { + // Check if we are a user + if( !OC_User::isLoggedIn()) { + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', + array('redirectUrl' => OC_Request::requestUri()) + )); + exit(); + } + } + + /** + * @brief Check if the user is a admin, redirects to home if not + * @return void + */ + public static function checkAdminUser() { + if( !OC_User::isAdminUser(OC_User::getUser())) { + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); + exit(); + } + } + + /** + * @brief Check if the user is a subadmin, redirects to home if not + * @return array $groups where the current user is subadmin + */ + public static function checkSubAdminUser() { + if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); + exit(); + } + return true; + } + + /** + * @brief Redirect to the user default page + * @return void + */ + public static function redirectToDefaultPage() { + if(isset($_REQUEST['redirect_url'])) { + $location = OC_Helper::makeURLAbsolute(urldecode($_REQUEST['redirect_url'])); + } + else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) { + $location = OC_Helper::linkToAbsolute( OC::$REQUESTEDAPP, 'index.php' ); + } else { + $defaultPage = OC_Appconfig::getValue('core', 'defaultpage'); + if ($defaultPage) { + $location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultPage); + } else { + $location = OC_Helper::linkToAbsolute( 'files', 'index.php' ); + } + } + OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG); + header( 'Location: '.$location ); + exit(); + } + + /** + * @brief get an id unique for this instance + * @return string + */ + public static function getInstanceId() { + $id = OC_Config::getValue('instanceid', null); + if(is_null($id)) { + // We need to guarantee at least one letter in instanceid so it can be used as the session_name + $id = 'oc' . self::generateRandomBytes(10); + OC_Config::setValue('instanceid', $id); + } + return $id; + } + + /** + * @brief Static lifespan (in seconds) when a request token expires. + * @see OC_Util::callRegister() + * @see OC_Util::isCallRegistered() + * @description + * Also required for the client side to compute the point in time when to + * request a fresh token. The client will do so when nearly 97% of the + * time span coded here has expired. + */ + public static $callLifespan = 3600; // 3600 secs = 1 hour + + /** + * @brief Register an get/post call. Important to prevent CSRF attacks. + * @todo Write howto: CSRF protection guide + * @return $token Generated token. + * @description + * Creates a 'request token' (random) and stores it inside the session. + * Ever subsequent (ajax) request must use such a valid token to succeed, + * otherwise the request will be denied as a protection against CSRF. + * The tokens expire after a fixed lifespan. + * @see OC_Util::$callLifespan + * @see OC_Util::isCallRegistered() + */ + public static function callRegister() { + // Check if a token exists + if(!\OC::$session->exists('requesttoken')) { + // No valid token found, generate a new one. + $requestToken = self::generateRandomBytes(20); + \OC::$session->set('requesttoken', $requestToken); + } else { + // Valid token already exists, send it + $requestToken = \OC::$session->get('requesttoken'); + } + return($requestToken); + } + + /** + * @brief Check an ajax get/post call if the request token is valid. + * @return boolean False if request token is not set or is invalid. + * @see OC_Util::$callLifespan + * @see OC_Util::callRegister() + */ + public static function isCallRegistered() { + if(!\OC::$session->exists('requesttoken')) { + return false; + } + + if(isset($_GET['requesttoken'])) { + $token = $_GET['requesttoken']; + } elseif(isset($_POST['requesttoken'])) { + $token = $_POST['requesttoken']; + } elseif(isset($_SERVER['HTTP_REQUESTTOKEN'])) { + $token = $_SERVER['HTTP_REQUESTTOKEN']; + } else { + //no token found. + return false; + } + + // Check if the token is valid + if($token !== \OC::$session->get('requesttoken')) { + // Not valid + return false; + } else { + // Valid token + return true; + } + } + + /** + * @brief Check an ajax get/post call if the request token is valid. exit if not. + * @todo Write howto + * @return void + */ + public static function callCheck() { + if(!OC_Util::isCallRegistered()) { + exit(); + } + } + + /** + * @brief Public function to sanitize HTML + * + * This function is used to sanitize HTML and should be applied on any + * string or array of strings before displaying it on a web page. + * + * @param string|array of strings + * @return array with sanitized strings or a single sanitized string, depends on the input parameter. + */ + public static function sanitizeHTML( &$value ) { + if (is_array($value)) { + array_walk_recursive($value, 'OC_Util::sanitizeHTML'); + } else { + //Specify encoding for PHP<5.4 + $value = htmlentities((string)$value, ENT_QUOTES, 'UTF-8'); + } + return $value; + } + + /** + * @brief Public function to encode url parameters + * + * This function is used to encode path to file before output. + * Encoding is done according to RFC 3986 with one exception: + * Character '/' is preserved as is. + * + * @param string $component part of URI to encode + * @return string + */ + public static function encodePath($component) { + $encoded = rawurlencode($component); + $encoded = str_replace('%2F', '/', $encoded); + return $encoded; + } + + /** + * @brief Check if the htaccess file is working + * @return bool + * @description Check if the htaccess file is working by creating a test + * file in the data directory and trying to access via http + */ + public static function isHtAccessWorking() { + // testdata + $fileName = '/htaccesstest.txt'; + $testContent = 'testcontent'; + + // creating a test file + $testFile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$fileName; + + if(file_exists($testFile)) {// already running this test, possible recursive call + return false; + } + + $fp = @fopen($testFile, 'w'); + @fwrite($fp, $testContent); + @fclose($fp); + + // accessing the file via http + $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$fileName); + $fp = @fopen($url, 'r'); + $content=@fread($fp, 2048); + @fclose($fp); + + // cleanup + @unlink($testFile); + + // does it work ? + if($content==$testContent) { + return false; + } else { + return true; + } + } + + /** + * @brief test if webDAV is working properly + * @return bool + * @description + * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND + * the web server it self is setup properly. + * + * Why not an authenticated PROPFIND and other verbs? + * - We don't have the password available + * - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header) + * + */ + public static function isWebDAVWorking() { + if (!function_exists('curl_init')) { + return true; + } + $settings = array( + 'baseUri' => OC_Helper::linkToRemote('webdav'), + ); + + $client = new \Sabre_DAV_Client($settings); + + // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified. + $client->setVerifyPeer(false); + + $return = true; + try { + // test PROPFIND + $client->propfind('', array('{DAV:}resourcetype')); + } catch (\Sabre_DAV_Exception_NotAuthenticated $e) { + $return = true; + } catch (\Exception $e) { + OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e->getMessage(). ' ('.get_class($e).')', OC_Log::WARN); + $return = false; + } + + return $return; + } + + /** + * Check if the setlocal call does not work. This can happen if the right + * local packages are not available on the server. + * @return bool + */ + public static function isSetLocaleWorking() { + // setlocale test is pointless on Windows + if (OC_Util::runningOnWindows() ) { + return true; + } + + $result = setlocale(LC_ALL, 'en_US.UTF-8', 'en_US.UTF8'); + if($result == false) { + return false; + } + return true; + } + + /** + * @brief Check if the PHP module fileinfo is loaded. + * @return bool + */ + public static function fileInfoLoaded() { + return function_exists('finfo_open'); + } + + /** + * @brief Check if the ownCloud server can connect to the internet + * @return bool + */ + public static function isInternetConnectionWorking() { + // in case there is no internet connection on purpose return false + if (self::isInternetConnectionEnabled() === false) { + return false; + } + + // try to connect to owncloud.org to see if http connections to the internet are possible. + $connected = @fsockopen("www.owncloud.org", 80); + if ($connected) { + fclose($connected); + return true; + } else { + // second try in case one server is down + $connected = @fsockopen("apps.owncloud.com", 80); + if ($connected) { + fclose($connected); + return true; + } else { + return false; + } + } + } + + /** + * @brief Check if the connection to the internet is disabled on purpose + * @return bool + */ + public static function isInternetConnectionEnabled(){ + return \OC_Config::getValue("has_internet_connection", true); + } + + /** + * @brief clear all levels of output buffering + * @return void + */ + public static function obEnd(){ + while (ob_get_level()) { + ob_end_clean(); + } + } + + + /** + * @brief Generates a cryptographic secure pseudo-random string + * @param Int $length of the random string + * @return String + * Please also update secureRNGAvailable if you change something here + */ + public static function generateRandomBytes($length = 30) { + // Try to use openssl_random_pseudo_bytes + if (function_exists('openssl_random_pseudo_bytes')) { + $pseudoByte = bin2hex(openssl_random_pseudo_bytes($length, $strong)); + if($strong == true) { + return substr($pseudoByte, 0, $length); // Truncate it to match the length + } + } + + // Try to use /dev/urandom + if (!self::runningOnWindows()) { + $fp = @file_get_contents('/dev/urandom', false, null, 0, $length); + if ($fp !== false) { + $string = substr(bin2hex($fp), 0, $length); + return $string; + } + } + + // Fallback to mt_rand() + $characters = '0123456789'; + $characters .= 'abcdefghijklmnopqrstuvwxyz'; + $charactersLength = strlen($characters)-1; + $pseudoByte = ""; + + // Select some random characters + for ($i = 0; $i < $length; $i++) { + $pseudoByte .= $characters[mt_rand(0, $charactersLength)]; + } + return $pseudoByte; + } + + /** + * @brief Checks if a secure random number generator is available + * @return bool + */ + public static function secureRNGAvailable() { + // Check openssl_random_pseudo_bytes + if(function_exists('openssl_random_pseudo_bytes')) { + openssl_random_pseudo_bytes(1, $strong); + if($strong == true) { + return true; + } + } + + // Check /dev/urandom + if (!self::runningOnWindows()) { + $fp = @file_get_contents('/dev/urandom', false, null, 0, 1); + if ($fp !== false) { + return true; + } + } + + return false; + } + + /** + * @Brief Get file content via curl. + * @param string $url Url to get content + * @return string of the response or false on error + * This function get the content of a page via curl, if curl is enabled. + * If not, file_get_element is used. + */ + public static function getUrlContent($url){ + if (function_exists('curl_init')) { + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_MAXREDIRS, 10); + + curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + if(OC_Config::getValue('proxy', '') != '') { + curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy')); + } + if(OC_Config::getValue('proxyuserpwd', '') != '') { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd')); + } + $data = curl_exec($curl); + curl_close($curl); + + } else { + $contextArray = null; + + if(OC_Config::getValue('proxy', '') != '') { + $contextArray = array( + 'http' => array( + 'timeout' => 10, + 'proxy' => OC_Config::getValue('proxy') + ) + ); + } else { + $contextArray = array( + 'http' => array( + 'timeout' => 10 + ) + ); + } + + $ctx = stream_context_create( + $contextArray + ); + $data = @file_get_contents($url, 0, $ctx); + + } + return $data; + } + + /** + * @return bool - well are we running on windows or not + */ + public static function runningOnWindows() { + return (substr(PHP_OS, 0, 3) === "WIN"); + } + + /** + * Handles the case that there may not be a theme, then check if a "default" + * theme exists and take that one + * @return string the theme + */ + public static function getTheme() { + $theme = OC_Config::getValue("theme", ''); + + if($theme === '') { + if(is_dir(OC::$SERVERROOT . '/themes/default')) { + $theme = 'default'; + } + } + + return $theme; + } + + /** + * @brief Clear the opcode cache if one exists + * This is necessary for writing to the config file + * in case the opcode cache does not re-validate files + * @return void + */ + public static function clearOpcodeCache() { + // APC + if (function_exists('apc_clear_cache')) { + apc_clear_cache(); + } + // Zend Opcache + if (function_exists('accelerator_reset')) { + accelerator_reset(); + } + // XCache + if (function_exists('xcache_clear_cache')) { + xcache_clear_cache(XC_TYPE_VAR, 0); + } + // Opcache (PHP >= 5.5) + if (function_exists('opcache_reset')) { + opcache_reset(); + } + } + + /** + * Normalize a unicode string + * @param string $value a not normalized string + * @return bool|string + */ + public static function normalizeUnicode($value) { + if(class_exists('Patchwork\PHP\Shim\Normalizer')) { + $normalizedValue = \Patchwork\PHP\Shim\Normalizer::normalize($value); + if($normalizedValue === false) { + \OC_Log::write( 'core', 'normalizing failed for "' . $value . '"', \OC_Log::WARN); + } else { + $value = $normalizedValue; + } + } + + return $value; + } + + /** + * @return string + */ + public static function basename($file) { + $file = rtrim($file, '/'); + $t = explode('/', $file); + return array_pop($t); + } +} -- cgit v1.2.3 From e40afbebc64547219e88dc0045d6a04cd06e76f8 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Thu, 3 Oct 2013 23:22:11 +0200 Subject: make it possible to prepopulate a new user gome with a skeleton --- core/skeleton/.gitignore | 4 ++++ lib/private/util.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 core/skeleton/.gitignore (limited to 'lib/private/util.php') diff --git a/core/skeleton/.gitignore b/core/skeleton/.gitignore new file mode 100644 index 00000000000..5e7d2734cfc --- /dev/null +++ b/core/skeleton/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/lib/private/util.php b/lib/private/util.php index 1cbb19eaec4..004e82d7d26 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -68,6 +68,7 @@ class OC_Util { $userDirectory = $userRoot . '/files'; if( !is_dir( $userDirectory )) { mkdir( $userDirectory, 0755, true ); + OC_Util::copySkeleton($userDirectory); } //jail the user into his "home" directory \OC\Files\Filesystem::init($user, $userDir); @@ -92,6 +93,37 @@ class OC_Util { } } + /** + * @brief copies the user skeleton files into the fresh userr home files + * @param string $userDirectory + * @return void + */ + public static function copySkeleton($userDirectory) { + error_log('skeleton init '.$userDirectory); + OC_Util::copyr(\OC::$SERVERROOT.'/core/skeleton' , $userDirectory); + } + + /** + * @brief copies a directory recursively + * @param string $source + * @param string $target + * @return void + */ + function copyr($source,$target) { + $dir = opendir($source); + @mkdir($target); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($source . '/' . $file) ) { + OC_Util::copyr($source . '/' . $file , $target . '/' . $file); + } else { + copy($source . '/' . $file,$target . '/' . $file); + } + } + } + closedir($dir); + } + /** * @return void */ -- cgit v1.2.3 From 6d954366950c57a8d999a652a7c1b22b95659ee3 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 4 Oct 2013 09:24:07 +0200 Subject: add public static --- lib/private/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 004e82d7d26..d5c44795e10 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -109,7 +109,7 @@ class OC_Util { * @param string $target * @return void */ - function copyr($source,$target) { + public static function copyr($source,$target) { $dir = opendir($source); @mkdir($target); while(false !== ( $file = readdir($dir)) ) { -- cgit v1.2.3 From f0a98cc92374f62a1fdd884c206424242427c8c5 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 4 Oct 2013 09:25:54 +0200 Subject: fix typo --- lib/private/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index d5c44795e10..d0b0fbfc807 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -94,7 +94,7 @@ class OC_Util { } /** - * @brief copies the user skeleton files into the fresh userr home files + * @brief copies the user skeleton files into the fresh user home files * @param string $userDirectory * @return void */ -- cgit v1.2.3 From e49ee47e7b9cd6bc03851281d270885b9fd2d70c Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 4 Oct 2013 09:28:46 +0200 Subject: use Filesystem::isIgnoredDir --- lib/private/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index d0b0fbfc807..cb33e3597a2 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -113,7 +113,7 @@ class OC_Util { $dir = opendir($source); @mkdir($target); while(false !== ( $file = readdir($dir)) ) { - if (( $file != '.' ) && ( $file != '..' )) { + if ( !\OC\Files\Filesystem::isIgnoredDir($file) ) { if ( is_dir($source . '/' . $file) ) { OC_Util::copyr($source . '/' . $file , $target . '/' . $file); } else { -- cgit v1.2.3 From 47666796a73e28097be03d9de8a333907c69e5cc Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 4 Oct 2013 09:42:38 +0200 Subject: ups. remove debug --- lib/private/util.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index cb33e3597a2..a4e9d07147e 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -96,10 +96,8 @@ class OC_Util { /** * @brief copies the user skeleton files into the fresh user home files * @param string $userDirectory - * @return void */ public static function copySkeleton($userDirectory) { - error_log('skeleton init '.$userDirectory); OC_Util::copyr(\OC::$SERVERROOT.'/core/skeleton' , $userDirectory); } -- cgit v1.2.3 From 61a9098b7d88656d0297a18c1b7685c04d1c64dc Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 26 Sep 2013 18:41:19 +0200 Subject: Add Helper and URLGenerator interfaces to server container --- lib/apphelper.php | 25 +++++++++ lib/private/helper.php | 52 ++----------------- lib/private/server.php | 20 ++++++++ lib/private/util.php | 4 +- lib/public/ihelper.php | 23 +++++++++ lib/public/iservercontainer.php | 10 ++++ lib/public/iurlgenerator.php | 47 +++++++++++++++++ lib/urlgenerator.php | 111 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 242 insertions(+), 50 deletions(-) create mode 100644 lib/apphelper.php create mode 100644 lib/public/ihelper.php create mode 100644 lib/public/iurlgenerator.php create mode 100644 lib/urlgenerator.php (limited to 'lib/private/util.php') diff --git a/lib/apphelper.php b/lib/apphelper.php new file mode 100644 index 00000000000..bd02f3aabfa --- /dev/null +++ b/lib/apphelper.php @@ -0,0 +1,25 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OC; + +/** + * TODO: Description + */ +class AppHelper implements \OCP\IHelper { + /** + * Gets the content of an URL by using CURL or a fallback if it is not + * installed + * @param string $url the url that should be fetched + * @return string the content of the webpage + */ + public function getUrlContent($url) { + return \OC_Util::getUrlContent($url); + } +} diff --git a/lib/private/helper.php b/lib/private/helper.php index 66e7acb407a..a34640d8e36 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -41,8 +41,7 @@ class OC_Helper { * Returns a url to the given app and file. */ public static function linkToRoute($route, $parameters = array()) { - $urlLinkTo = OC::getRouter()->generate($route, $parameters); - return $urlLinkTo; + return OC::$server->getURLGenerator()->linkToRoute($route, $parameters); } /** @@ -56,32 +55,7 @@ class OC_Helper { * Returns a url to the given app and file. */ public static function linkTo( $app, $file, $args = array() ) { - if( $app != '' ) { - $app_path = OC_App::getAppPath($app); - // Check if the app is in the app folder - if ($app_path && file_exists($app_path . '/' . $file)) { - if (substr($file, -3) == 'php' || substr($file, -3) == 'css') { - $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app; - $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; - } else { - $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file; - } - } else { - $urlLinkTo = OC::$WEBROOT . '/' . $app . '/' . $file; - } - } else { - if (file_exists(OC::$SERVERROOT . '/core/' . $file)) { - $urlLinkTo = OC::$WEBROOT . '/core/' . $file; - } else { - $urlLinkTo = OC::$WEBROOT . '/' . $file; - } - } - - if ($args && $query = http_build_query($args, '', '&')) { - $urlLinkTo .= '?' . $query; - } - - return $urlLinkTo; + return OC::$server->getURLGenerator()->linkTo($app, $file, $args); } /** @@ -107,7 +81,7 @@ class OC_Helper { * Returns a absolute url to the given app and file. */ public static function makeURLAbsolute($url) { - return OC_Request::serverProtocol() . '://' . OC_Request::serverHost() . $url; + return OC::$server->getURLGenerator()->makeURLAbsolute($url); } /** @@ -156,25 +130,7 @@ class OC_Helper { * Returns the path to the image. */ public static function imagePath($app, $image) { - // Read the selected theme from the config file - $theme = OC_Util::getTheme(); - - // Check if the app is in the app folder - if (file_exists(OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { - return OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; - } elseif (file_exists(OC_App::getAppPath($app) . "/img/$image")) { - return OC_App::getAppWebPath($app) . "/img/$image"; - } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { - return OC::$WEBROOT . "/themes/$theme/$app/img/$image"; - } elseif (!empty($app) and file_exists(OC::$SERVERROOT . "/$app/img/$image")) { - return OC::$WEBROOT . "/$app/img/$image"; - } elseif (file_exists(OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { - return OC::$WEBROOT . "/themes/$theme/core/img/$image"; - } elseif (file_exists(OC::$SERVERROOT . "/core/img/$image")) { - return OC::$WEBROOT . "/core/img/$image"; - } else { - throw new RuntimeException('image not found: image:' . $image . ' webroot:' . OC::$WEBROOT . ' serverroot:' . OC::$SERVERROOT); - } + return OC::$server->getURLGenerator()->imagePath($app, $image); } /** diff --git a/lib/private/server.php b/lib/private/server.php index e4cc0c6da81..4000f546a3b 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -105,6 +105,12 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('L10NFactory', function($c) { return new \OC\L10N\Factory(); }); + $this->registerService('URLGenerator', function($c) { + return new \OC\URLGenerator(); + }); + $this->registerService('AppHelper', function($c) { + return new \OC\AppHelper(); + }); $this->registerService('UserCache', function($c) { return new UserCache(); }); @@ -229,6 +235,20 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('L10NFactory')->get($app); } + /** + * @return \OC\URLGenerator + */ + function getURLGenerator() { + return $this->query('URLGenerator'); + } + + /** + * @return \OC\Helper + */ + function getHelper() { + return $this->query('AppHelper'); + } + /** * Returns an ICache instance * diff --git a/lib/private/util.php b/lib/private/util.php index ae9aef69b4c..04a020ff006 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -982,9 +982,9 @@ class OC_Util { * @param string $url Url to get content * @return string of the response or false on error * This function get the content of a page via curl, if curl is enabled. - * If not, file_get_element is used. + * If not, file_get_contents is used. */ - public static function getUrlContent($url){ + public static function getUrlContent($url) { if (function_exists('curl_init')) { $curl = curl_init(); diff --git a/lib/public/ihelper.php b/lib/public/ihelper.php new file mode 100644 index 00000000000..fad02f7556a --- /dev/null +++ b/lib/public/ihelper.php @@ -0,0 +1,23 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * Functions that don't have any specific interface to place + */ +interface IHelper { + /** + * Gets the content of an URL by using CURL or a fallback if it is not + * installed + * @param string $url the url that should be fetched + * @return string the content of the webpage + */ + public function getUrlContent($url); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index e8bc1bedf91..3afb2b6599d 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -108,6 +108,16 @@ interface IServerContainer { */ function getL10N($app); + /** + * @return \OCP\IURLGenerator + */ + function getURLGenerator(); + + /** + * @return \OCP\IHelper + */ + function getHelper(); + /** * Returns an ICache instance * diff --git a/lib/public/iurlgenerator.php b/lib/public/iurlgenerator.php new file mode 100644 index 00000000000..4eb4c0f8312 --- /dev/null +++ b/lib/public/iurlgenerator.php @@ -0,0 +1,47 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * Class to generate URLs + */ +interface IURLGenerator { + /** + * Returns the URL for a route + * @param string $routeName the name of the route + * @param array $arguments an array with arguments which will be filled into the url + * @return string the url + */ + public function linkToRoute($routeName, $arguments = array()); + + /** + * Returns an URL for an image or file + * @param string $appName the name of the app + * @param string $file the name of the file + * @return string the url + */ + public function linkTo($appName, $file); + + /** + * Returns the link to an image, like linkTo but only with prepending img/ + * @param string $appName the name of the app + * @param string $file the name of the file + * @return string the url + */ + public function imagePath($appName, $file); + + + /** + * Makes an URL absolute + * @param string $url the url in the owncloud host + * @return string the absolute version of the url + */ + public function getAbsoluteURL($url); +} diff --git a/lib/urlgenerator.php b/lib/urlgenerator.php new file mode 100644 index 00000000000..1db4c36cc58 --- /dev/null +++ b/lib/urlgenerator.php @@ -0,0 +1,111 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OC; + +/** + * Class to generate URLs + */ +class URLGenerator { + /** + * @brief Creates an url using a defined route + * @param $route + * @param array $parameters + * @return + * @internal param array $args with param=>value, will be appended to the returned url + * @returns the url + * + * Returns a url to the given app and file. + */ + public function linkToRoute($route, $parameters = array()) { + $urlLinkTo = \OC::getRouter()->generate($route, $parameters); + return $urlLinkTo; + } + + /** + * @brief Creates an url + * @param string $app app + * @param string $file file + * @param array $args array with param=>value, will be appended to the returned url + * The value of $args will be urlencoded + * @return string the url + * + * Returns a url to the given app and file. + */ + public function linkTo( $app, $file, $args = array() ) { + if( $app != '' ) { + $app_path = \OC_App::getAppPath($app); + // Check if the app is in the app folder + if ($app_path && file_exists($app_path . '/' . $file)) { + if (substr($file, -3) == 'php' || substr($file, -3) == 'css') { + $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; + $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; + } else { + $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; + } + } else { + $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; + } + } else { + if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { + $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; + } else { + $urlLinkTo = \OC::$WEBROOT . '/' . $file; + } + } + + if ($args && $query = http_build_query($args, '', '&')) { + $urlLinkTo .= '?' . $query; + } + + return $urlLinkTo; + } + + /** + * @brief Creates path to an image + * @param string $app app + * @param string $image image name + * @return string the url + * + * Returns the path to the image. + */ + public function imagePath($app, $image) { + // Read the selected theme from the config file + $theme = \OC_Util::getTheme(); + + // Check if the app is in the app folder + if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { + return \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; + } elseif (file_exists(\OC_App::getAppPath($app) . "/img/$image")) { + return \OC_App::getAppWebPath($app) . "/img/$image"; + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { + return \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { + return \OC::$WEBROOT . "/$app/img/$image"; + } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { + return \OC::$WEBROOT . "/themes/$theme/core/img/$image"; + } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { + return \OC::$WEBROOT . "/core/img/$image"; + } else { + throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); + } + } + + /** + * @brief Makes an $url absolute + * @param string $url the url + * @return string the absolute url + * + * Returns a absolute url to the given app and file. + */ + public function makeURLAbsolute($url) { + return \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . $url; + } + +} -- cgit v1.2.3 From 21cbef0d2cc80228d2a473ccfb6ad5b071f314c7 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 27 Sep 2013 15:16:34 +0200 Subject: passesCSRFCheck added to OCP\IRequest --- lib/private/appframework/http/request.php | 38 ++++++++++++++++++++++++++++--- lib/private/server.php | 17 +++++++++++++- lib/private/util.php | 24 +------------------ lib/public/irequest.php | 5 ++++ 4 files changed, 57 insertions(+), 27 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php index f152956c8cf..3e1f4ff87ed 100644 --- a/lib/private/appframework/http/request.php +++ b/lib/private/appframework/http/request.php @@ -43,7 +43,8 @@ class Request implements \ArrayAccess, \Countable, IRequest { 'cookies', 'urlParams', 'parameters', - 'method' + 'method', + 'requesttoken', ); /** @@ -54,9 +55,9 @@ class Request implements \ArrayAccess, \Countable, IRequest { * @param array 'files' the $_FILES array * @param array 'server' the $_SERVER array * @param array 'env' the $_ENV array - * @param array 'session' the $_SESSION array * @param array 'cookies' the $_COOKIE array * @param string 'method' the request method (GET, POST etc) + * @param string|false 'requesttoken' the requesttoken or false when not available * @see http://www.php.net/manual/en/reserved.variables.php */ public function __construct(array $vars=array()) { @@ -354,4 +355,35 @@ class Request implements \ArrayAccess, \Countable, IRequest { return $this->content; } -} + + /** + * Checks if the CSRF check was correct + * @return bool true if CSRF check passed + * @see OC_Util::$callLifespan + * @see OC_Util::callRegister() + */ + public function passesCSRFCheck() { + if($this->items['requesttoken'] === false) { + return false; + } + + if (isset($this->items['get']['requesttoken'])) { + $token = $this->items['get']['requesttoken']; + } elseif (isset($this->items['post']['requesttoken'])) { + $token = $this->items['post']['requesttoken']; + } elseif (isset($this->items['server']['HTTP_REQUESTTOKEN'])) { + $token = $this->items['server']['HTTP_REQUESTTOKEN']; + } else { + //no token found. + return false; + } + + // Check if the token is valid + if($token !== $this->items['requesttoken']) { + // Not valid + return false; + } else { + // Valid token + return true; + } + }} diff --git a/lib/private/server.php b/lib/private/server.php index 4000f546a3b..73a0cbd6ce6 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -22,6 +22,19 @@ class Server extends SimpleContainer implements IServerContainer { return new ContactsManager(); }); $this->registerService('Request', function($c) { + if (isset($c['urlParams'])) { + $urlParams = $c['urlParams']; + } else { + $urlParams = array(); + } + + if (\OC::$session->exists('requesttoken')) { + $requesttoken = \OC::$session->get('requesttoken'); + } else { + $requesttoken = false; + } + + return new Request( array( 'get' => $_GET, @@ -33,7 +46,9 @@ class Server extends SimpleContainer implements IServerContainer { 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : null, - 'urlParams' => $c['urlParams'] + 'params' => $params, + 'urlParams' => $urlParams, + 'requesttoken' => $requesttoken, ) ); }); diff --git a/lib/private/util.php b/lib/private/util.php index 04a020ff006..c5b4d2ae93e 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -695,29 +695,7 @@ class OC_Util { * @see OC_Util::callRegister() */ public static function isCallRegistered() { - if(!\OC::$session->exists('requesttoken')) { - return false; - } - - if(isset($_GET['requesttoken'])) { - $token = $_GET['requesttoken']; - } elseif(isset($_POST['requesttoken'])) { - $token = $_POST['requesttoken']; - } elseif(isset($_SERVER['HTTP_REQUESTTOKEN'])) { - $token = $_SERVER['HTTP_REQUESTTOKEN']; - } else { - //no token found. - return false; - } - - // Check if the token is valid - if($token !== \OC::$session->get('requesttoken')) { - // Not valid - return false; - } else { - // Valid token - return true; - } + return \OC::$server->getRequest()->passesCSRFCheck(); } /** diff --git a/lib/public/irequest.php b/lib/public/irequest.php index 054f15d9eb2..45b27868d70 100644 --- a/lib/public/irequest.php +++ b/lib/public/irequest.php @@ -107,4 +107,9 @@ interface IRequest { function getCookie($key); + /** + * Checks if the CSRF check was correct + * @return bool true if CSRF check passed + */ + public function passesCSRFCheck(); } -- cgit v1.2.3 From 72b30e3e453bb6500278391861d52a084e96e988 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Sat, 5 Oct 2013 12:50:36 +0200 Subject: correctly expire cache if version file changed. Fixes problem that ownCloud only starts upgrading during login --- lib/private/util.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index ae9aef69b4c..1718ae6a041 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -182,9 +182,12 @@ class OC_Util { * @description load the version.php into the session as cache */ private static function loadVersion() { - if(!\OC::$server->getSession()->exists('OC_Version')) { + $timestamp=filemtime(OC::$SERVERROOT.'/version.php'); + if(!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp')<>$timestamp) { require 'version.php'; $session = \OC::$server->getSession(); + /** @var $timestamp int */ + $session->set('OC_Version_Timestamp', $timestamp); /** @var $OC_Version string */ $session->set('OC_Version', $OC_Version); /** @var $OC_VersionString string */ -- cgit v1.2.3 From 3f29e4ebeab9fee22ca16656388080e3be92cc12 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Mon, 7 Oct 2013 12:27:02 +0200 Subject: a few styleguide fixes --- lib/private/util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 1718ae6a041..e2093a230c0 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -182,8 +182,8 @@ class OC_Util { * @description load the version.php into the session as cache */ private static function loadVersion() { - $timestamp=filemtime(OC::$SERVERROOT.'/version.php'); - if(!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp')<>$timestamp) { + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); + if(!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp') != $timestamp) { require 'version.php'; $session = \OC::$server->getSession(); /** @var $timestamp int */ -- cgit v1.2.3 From 52e31405f7848e4fd9f9d19297bbb87facb09376 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 16 Oct 2013 12:33:30 +0200 Subject: Added timeout value to WebDAV post setup check Fixes #5357 --- lib/private/util.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 6c0a8d7bab5..43f2c9bb635 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -806,7 +806,9 @@ class OC_Util { 'baseUri' => OC_Helper::linkToRemote('webdav'), ); - $client = new \Sabre_DAV_Client($settings); + $client = new \OC_DAVClient($settings); + + $client->setRequestTimeout(10); // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified. $client->setVerifyPeer(false); -- cgit v1.2.3 From 6a60a47d595d29d9034f0bc1d565542cc76389d9 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Thu, 17 Oct 2013 16:27:43 +0200 Subject: add options to disable the check for a working .htaccess file in data and for a working WebDAV server. This are advanced settings that are needed in special situations where our check fail and the user runs into an http timeout. --- config/config.sample.php | 6 ++++++ lib/private/util.php | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'lib/private/util.php') diff --git a/config/config.sample.php b/config/config.sample.php index 9a24c9364e0..54dbf3f7c33 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -129,6 +129,12 @@ $CONFIG = array( /* Are we connected to the internet or are we running in a closed network? */ "has_internet_connection" => true, +/* Check if the ownCloud WebDAV server is working correctly. Can be disabled if not needed in special situations*/ +"check_for_working_webdav" => true, + +/* Check if .htaccess protection of data is working correctly. Can be disabled if not needed in special situations*/ +"check_for_working_htaccess" => true, + /* Place to log to, can be owncloud and syslog (owncloud is log menu item in admin menu) */ "log_type" => "owncloud", diff --git a/lib/private/util.php b/lib/private/util.php index 6c0a8d7bab5..dbe0dc4f6ad 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -754,6 +754,10 @@ class OC_Util { * file in the data directory and trying to access via http */ public static function isHtAccessWorking() { + if (!\OC_Config::getValue("check_for_working_htaccess", true)) { + return true; + } + // testdata $fileName = '/htaccesstest.txt'; $testContent = 'testcontent'; @@ -802,6 +806,9 @@ class OC_Util { if (!function_exists('curl_init')) { return true; } + if (!\OC_Config::getValue("check_for_working_webdav", true)) { + return true; + } $settings = array( 'baseUri' => OC_Helper::linkToRemote('webdav'), ); -- cgit v1.2.3 From 148d2616e554964b59c5acaebf76333e5ae7f5eb Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 21 Oct 2013 21:29:45 +0200 Subject: introduce link_to_docs() and migrate links --- apps/user_ldap/templates/settings.php | 2 +- core/templates/installation.php | 2 +- lib/base.php | 2 +- lib/private/config.php | 2 +- lib/private/setup.php | 2 +- lib/private/template/functions.php | 5 +++++ lib/private/util.php | 16 ++++++++-------- settings/templates/admin.php | 2 +- settings/templates/personal.php | 2 +- 9 files changed, 20 insertions(+), 15 deletions(-) (limited to 'lib/private/util.php') diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 319dc38a62d..2530d9c04c7 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -106,7 +106,7 @@

t('Usernames are used to store and assign (meta) data. In order to precisely identify and recognize users, each LDAP user will have a internal username. This requires a mapping from username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found. The internal username is used all over. Clearing the mappings will have leftovers everywhere. Clearing the mappings is not configuration sensitive, it affects all LDAP configurations! Never clear the mappings in a production environment, only in a testing or experimental stage.'));?>


- t('Help'));?> + t('Help'));?> diff --git a/core/templates/installation.php b/core/templates/installation.php index a6f55cb0e28..3457a3c9a99 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -39,7 +39,7 @@

t('Your data directory and files are probably accessible from the internet because the .htaccess file does not work.'));?>
t( 'For information how to properly configure your server, please see the documentation.', - $theme->getDocBaseUrl().'/server/5.0/admin_manual/installation.html' + link_to_docs('admin-install') )); ?>

diff --git a/lib/base.php b/lib/base.php index ee925b8f736..ef574b2d895 100644 --- a/lib/base.php +++ b/lib/base.php @@ -181,7 +181,7 @@ class OC { OC_Template::printErrorPage( "Can't write into config directory!", 'This can usually be fixed by ' - .'giving the webserver write access to the config directory.' + .'giving the webserver write access to the config directory.' ); } } diff --git a/lib/private/config.php b/lib/private/config.php index 72423137fa3..c28669f56a3 100644 --- a/lib/private/config.php +++ b/lib/private/config.php @@ -172,7 +172,7 @@ class Config { $result = @file_put_contents($this->configFilename, $content); if (!$result) { $defaults = new \OC_Defaults; - $url = $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions'; + $url = link_to_docs('admin-dir-permissions'); throw new HintException( "Can't write into config directory!", 'This can usually be fixed by ' diff --git a/lib/private/setup.php b/lib/private/setup.php index 6bf3c88370f..3cc1d29c6a4 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -183,7 +183,7 @@ class OC_Setup { $error = $l->t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.'); $hint = $l->t('Please double check the installation guides.', - 'http://doc.owncloud.org/server/5.0/admin_manual/installation.html'); + link_to_docs('admin-install')); OC_Template::printErrorPage($error, $hint); exit(); diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php index 0aa2b27b96b..94b87d1e507 100644 --- a/lib/private/template/functions.php +++ b/lib/private/template/functions.php @@ -35,6 +35,11 @@ function link_to( $app, $file, $args = array() ) { return OC_Helper::linkTo( $app, $file, $args ); } +function link_to_docs($key) { + $theme = new OC_Defaults(); + return $theme->getDocBaseUrl() . '/server/5.0/go.php?to=' . $key; +} + /** * @brief make OC_Helper::imagePath available as a simple function * @param string $app app diff --git a/lib/private/util.php b/lib/private/util.php index 885cce87541..04b27ee61ae 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -303,16 +303,16 @@ class OC_Util { //common hint for all file permissions error messages $permissionsHint = 'Permissions can usually be fixed by ' - .'giving the webserver write access to the root directory.'; + .'giving the webserver write access to the root directory.'; // Check if config folder is writable. if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) { $errors[] = array( 'error' => "Can't write into config directory", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the config directory.' + .'giving the webserver write access to the config directory.' ); } @@ -324,8 +324,8 @@ class OC_Util { $errors[] = array( 'error' => "Can't write into apps directory", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the apps directory ' + .'giving the webserver write access to the apps directory ' .'or disabling the appstore in the config file.' ); } @@ -340,8 +340,8 @@ class OC_Util { $errors[] = array( 'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the root directory.' + .'giving the webserver write access to the root directory.' ); } } else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { diff --git a/settings/templates/admin.php b/settings/templates/admin.php index a2c877340ee..a5724bf3b17 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -30,7 +30,7 @@ if (!$_['isWebDavWorking']) { t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.')); ?> - t('Please double check the installation guides.', $theme->getDocBaseUrl().'/server/5.0/admin_manual/installation.html')); ?> + t('Please double check the installation guides.', link_to_docs('admin-install'))); ?> diff --git a/settings/templates/personal.php b/settings/templates/personal.php index 60c509b4a1c..6c758e659a8 100644 --- a/settings/templates/personal.php +++ b/settings/templates/personal.php @@ -132,7 +132,7 @@ if($_['passwordChangeSupported']) {

t('WebDAV'));?>


- t('Use this address to access your Files via WebDAV', array($theme->getDocBaseUrl())));?> + t('Use this address to access your Files via WebDAV', array(link_to_docs('user-webdav'))));?>
Date: Mon, 21 Oct 2013 22:01:27 +0200 Subject: introduce OC_Helper::linkToDocs() --- lib/private/helper.php | 9 +++++++++ lib/private/template/functions.php | 7 +++++-- lib/private/util.php | 8 ++++---- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/helper.php b/lib/private/helper.php index e9b129db0ca..fca08adca8b 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -58,6 +58,15 @@ class OC_Helper { return OC::$server->getURLGenerator()->linkTo($app, $file, $args); } + /** + * @param $key + * @return string url to the online documentation + */ + public static function linkToDocs($key) { + $theme = new OC_Defaults(); + return $theme->getDocBaseUrl() . '/server/5.0/go.php?to=' . $key; + } + /** * @brief Creates an absolute url * @param string $app app diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php index 94b87d1e507..ce42633b364 100644 --- a/lib/private/template/functions.php +++ b/lib/private/template/functions.php @@ -35,9 +35,12 @@ function link_to( $app, $file, $args = array() ) { return OC_Helper::linkTo( $app, $file, $args ); } +/** + * @param $key + * @return string url to the online documentation + */ function link_to_docs($key) { - $theme = new OC_Defaults(); - return $theme->getDocBaseUrl() . '/server/5.0/go.php?to=' . $key; + return OC_Helper::linkToDocs($key); } /** diff --git a/lib/private/util.php b/lib/private/util.php index 04b27ee61ae..f63884c0f32 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -303,7 +303,7 @@ class OC_Util { //common hint for all file permissions error messages $permissionsHint = 'Permissions can usually be fixed by ' - .'giving the webserver write access to the root directory.'; // Check if config folder is writable. @@ -311,7 +311,7 @@ class OC_Util { $errors[] = array( 'error' => "Can't write into config directory", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the config directory.' ); } @@ -324,7 +324,7 @@ class OC_Util { $errors[] = array( 'error' => "Can't write into apps directory", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the apps directory ' .'or disabling the appstore in the config file.' ); @@ -340,7 +340,7 @@ class OC_Util { $errors[] = array( 'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")", 'hint' => 'This can usually be fixed by ' - .'giving the webserver write access to the root directory.' ); } -- cgit v1.2.3 From 3f42c890be86fdeebbf9008ccac117cb4f292e02 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 30 Oct 2013 22:59:31 +0100 Subject: we should check if a user is logged in before we check for admin privilege --- lib/private/util.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index f63884c0f32..176eb4bc369 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -579,6 +579,7 @@ class OC_Util { * @return void */ public static function checkAdminUser() { + OC_Util::checkLoggedIn(); if( !OC_User::isAdminUser(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); @@ -611,6 +612,7 @@ class OC_Util { * @return array $groups where the current user is subadmin */ public static function checkSubAdminUser() { + OC_Util::checkLoggedIn(); if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php' )); exit(); -- cgit v1.2.3 From a6d8854d2af234d0613467f12b45f229e0431b35 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 8 Nov 2013 14:30:08 +0100 Subject: Make working en_US.UTF-8 locale a hard requirement --- lib/base.php | 8 +------- lib/private/util.php | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/base.php b/lib/base.php index 4f8d97ac95d..cf9230c367e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -241,7 +241,7 @@ class OC { $minimizerCSS->clearCache(); $minimizerJS = new OC_Minimizer_JS(); $minimizerJS->clearCache(); - OC_Util::addscript('update'); + OC_Util::addScript('update'); $tmpl = new OC_Template('', 'update.admin', 'guest'); $tmpl->assign('version', OC_Util::getVersionString()); $tmpl->printPage(); @@ -564,12 +564,6 @@ class OC { } } - // write error into log if locale can't be set - if (OC_Util::isSetLocaleWorking() == false) { - OC_Log::write('core', - 'setting locale to en_US.UTF-8/en_US.UTF8 failed. Support is probably not installed on your system', - OC_Log::ERROR); - } if (OC_Config::getValue('installed', false) && !self::checkUpgrade(false)) { if (OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { OC_Util::addScript('backgroundjobs'); diff --git a/lib/private/util.php b/lib/private/util.php index 176eb4bc369..f285f83cf5c 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -353,6 +353,13 @@ class OC_Util { $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); } + if(!OC_Util::isSetLocaleWorking()) { + $errors[] = array( + 'error' => 'Setting locale to en_US.UTF-8/en_US.UTF8 failed', + 'hint' => 'Please install the locale on your system and restart your webserver.' + ); + } + $moduleHint = "Please ask your server administrator to install the module."; // check if all required php modules are present if(!class_exists('ZipArchive')) { -- cgit v1.2.3 From bcf56b04078f4a8b9381f110c379b0d33d0db48c Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Nov 2013 13:06:35 +0100 Subject: Use \Patchwork\Utf8\Bootup::initLocale --- lib/private/util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index f285f83cf5c..d44ae09ecbc 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -854,8 +854,8 @@ class OC_Util { return true; } - $result = setlocale(LC_ALL, 'en_US.UTF-8', 'en_US.UTF8'); - if($result == false) { + \Patchwork\Utf8\Bootup::initLocale(); + if ('' === basename('§')) { return false; } return true; -- cgit v1.2.3 From 368342a085cd33d6f6ea9fa037b9695c82571992 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 15 Nov 2013 14:46:00 +0100 Subject: Update error messages --- lib/private/util.php | 2 +- settings/admin.php | 2 +- settings/templates/admin.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index d44ae09ecbc..115deaceb56 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -355,7 +355,7 @@ class OC_Util { if(!OC_Util::isSetLocaleWorking()) { $errors[] = array( - 'error' => 'Setting locale to en_US.UTF-8/en_US.UTF8 failed', + 'error' => 'Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed', 'hint' => 'Please install the locale on your system and restart your webserver.' ); } diff --git a/settings/admin.php b/settings/admin.php index 120f15bec19..0d3868afea8 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -25,7 +25,7 @@ $tmpl->assign('entries', $entries); $tmpl->assign('entriesremain', $entriesremain); $tmpl->assign('htaccessworking', $htaccessworking); $tmpl->assign('internetconnectionworking', OC_Util::isInternetConnectionEnabled() ? OC_Util::isInternetConnectionWorking() : false); -$tmpl->assign('islocaleworking', OC_Util::isSetLocaleWorking()); +$tmpl->assign('isLocaleWorking', OC_Util::isSetLocaleWorking()); $tmpl->assign('isWebDavWorking', OC_Util::isWebDAVWorking()); $tmpl->assign('has_fileinfo', OC_Util::fileInfoLoaded()); $tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax')); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 5413b700936..66bcfa21c3f 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -59,14 +59,14 @@ if (!$_['has_fileinfo']) { } // is locale working ? -if (!$_['islocaleworking']) { +if (!$_['isLocaleWorking']) { ?>

t('Locale not working'));?>

t('System locale can\'t be set to %s. This means that there might be problems with certain characters in file names. We strongly suggest to install the required packages on your system to support %s.', array($locales, $locales))); ?> -- cgit v1.2.3 From 356eef07398f8829a2558eee809599be60441b59 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 6 Nov 2013 11:57:04 +0100 Subject: Quota storage wrapper is now used for all users in sharing mode When accessing a shared folder, the folder's owner appears as mountpoint but wasn't wrapped by a quota storage wrapper. This fix makes sure that all home storages are wrapped by a quota storage wrapper, if applicable, to make sure quotas are respected when uploading into shared folders. --- apps/files/tests/ajax_rename.php | 15 ++++++++++++ lib/private/util.php | 33 +++++++++++++++++++-------- tests/lib/util.php | 49 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 9 deletions(-) (limited to 'lib/private/util.php') diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index e654255c407..3735b0a49c8 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -22,9 +22,18 @@ */ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { + private static $user; function setUp() { // mock OC_L10n + if (!self::$user) { + self::$user = uniqid(); + } + \OC_User::createUser(self::$user, 'password'); + \OC_User::setUserId(self::$user); + + \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); + $l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false); $l10nMock->expects($this->any()) ->method('t') @@ -39,6 +48,12 @@ class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { $this->files = new \OCA\Files\App($viewMock, $l10nMock); } + function tearDown() { + $result = \OC_User::deleteUser(self::$user); + $this->assertTrue($result); + \OC\Files\Filesystem::tearDown(); + } + /** * @brief test rename of file/folder named "Shared" */ diff --git a/lib/private/util.php b/lib/private/util.php index 176eb4bc369..88f1f197b5d 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -53,16 +53,31 @@ class OC_Util { //if we aren't logged in, there is no use to set up the filesystem if( $user != "" ) { - $quota = self::getUserQuota($user); - if ($quota !== \OC\Files\SPACE_UNLIMITED) { - \OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage) use ($quota, $user) { - if ($mountPoint === '/' . $user . '/'){ - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota)); - } else { - return $storage; + \OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage){ + // set up quota for home storages, even for other users + // which can happen when using sharing + + if (strlen($mountPoint) > 1) { + // the user name will be extracted from the mountpoint + // with the format '/username/' (no suffix) + $user = null; + // find second separator + $nextSepPos = strpos($mountPoint, '/', 1); + // next separator is the last one, format matches + if ($nextSepPos === strlen($mountPoint) - 1) { + $user = substr($mountPoint, 1, $nextSepPos - 1); } - }); - } + if ($user) { + $quota = OC_Util::getUserQuota($user); + if ($quota !== \OC\Files\SPACE_UNLIMITED) { + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota)); + } + } + } + + return $storage; + }); + $userDir = '/'.$user.'/files'; $userRoot = OC_User::getHome($user); $userDirectory = $userRoot . '/files'; diff --git a/tests/lib/util.php b/tests/lib/util.php index d607a3e7725..852caaeccc3 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -93,6 +93,55 @@ class Test_Util extends PHPUnit_Framework_TestCase { $this->assertStringStartsWith('oc', OC_Util::getInstanceId()); } + /** + * Tests that the home storage is not wrapped when no quota exists. + */ + function testHomeStorageWrapperWithoutQuota() { + $user1 = uniqid(); + \OC_User::createUser($user1, 'test'); + OC_Preferences::setValue($user1, 'files', 'quota', 'none'); + \OC_User::setUserId($user1); + + \OC_Util::setupFS($user1); + + $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/'); + $this->assertNotNull($userMount); + $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage()); + + // clean up + \OC_User::setUserId(''); + \OC_User::deleteUser($user1); + OC_Preferences::deleteUser($user1); + \OC_Util::tearDownFS(); + } + + /** + * Tests that the home storage is not wrapped when no quota exists. + */ + function testHomeStorageWrapperWithQuota() { + $user1 = uniqid(); + \OC_User::createUser($user1, 'test'); + OC_Preferences::setValue($user1, 'files', 'quota', '1024'); + \OC_User::setUserId($user1); + + \OC_Util::setupFS($user1); + + $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/'); + $this->assertNotNull($userMount); + $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage()); + + // ensure that root wasn't wrapped + $rootMount = \OC\Files\Filesystem::getMountManager()->find('/'); + $this->assertNotNull($rootMount); + $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $rootMount->getStorage()); + + // clean up + \OC_User::setUserId(''); + \OC_User::deleteUser($user1); + OC_Preferences::deleteUser($user1); + \OC_Util::tearDownFS(); + } + /** * @dataProvider baseNameProvider */ -- cgit v1.2.3 From 69e8e7dbd5039652cceb078025248c308ffd0d55 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 21 Nov 2013 12:17:47 +0100 Subject: Now using the "Home" storage detection approach for quota To find out whether to apply a quota, we now try and detect whether the storage to wrap is a "Home" storage. --- lib/private/files/storage/home.php | 17 +++++++++++++++++ lib/private/util.php | 20 +++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php index b4ceb8f4f9b..1c2a682f197 100644 --- a/lib/private/files/storage/home.php +++ b/lib/private/files/storage/home.php @@ -22,6 +22,12 @@ class Home extends Local { */ protected $user; + /** + * @brief Construct a Home storage instance + * @param array $arguments array with "user" containing the + * storage owner and "legacy" containing "true" if the storage is + * a legacy storage with "local::" URL instead of the new "home::" one. + */ public function __construct($arguments) { $this->user = $arguments['user']; $datadir = $this->user->getHome(); @@ -40,10 +46,21 @@ class Home extends Local { return $this->id; } + /** + * @return \OC\Files\Cache\HomeCache + */ public function getCache($path = '') { if (!isset($this->cache)) { $this->cache = new \OC\Files\Cache\HomeCache($this); } return $this->cache; } + + /** + * @brief Returns the owner of this home storage + * @return \OC\User\User owner of this home storage + */ + public function getUser() { + return $this->user; + } } diff --git a/lib/private/util.php b/lib/private/util.php index 88f1f197b5d..959d36a89e9 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -57,21 +57,11 @@ class OC_Util { // set up quota for home storages, even for other users // which can happen when using sharing - if (strlen($mountPoint) > 1) { - // the user name will be extracted from the mountpoint - // with the format '/username/' (no suffix) - $user = null; - // find second separator - $nextSepPos = strpos($mountPoint, '/', 1); - // next separator is the last one, format matches - if ($nextSepPos === strlen($mountPoint) - 1) { - $user = substr($mountPoint, 1, $nextSepPos - 1); - } - if ($user) { - $quota = OC_Util::getUserQuota($user); - if ($quota !== \OC\Files\SPACE_UNLIMITED) { - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota)); - } + if ($storage instanceof \OC\Files\Storage\Home) { + $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)); } } -- cgit v1.2.3 From cd1cf58875ffacf427420d6dbe94d8718e4075e0 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 21 Nov 2013 14:44:25 +0100 Subject: Fixing the warning notifications --- lib/private/util.php | 2 +- settings/templates/admin.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 115deaceb56..695d641b5b1 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -356,7 +356,7 @@ class OC_Util { if(!OC_Util::isSetLocaleWorking()) { $errors[] = array( 'error' => 'Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed', - 'hint' => 'Please install the locale on your system and restart your webserver.' + 'hint' => 'Please install one of theses locales on your system and restart your webserver.' ); } diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 66bcfa21c3f..f655a14be87 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -67,7 +67,15 @@ if (!$_['isLocaleWorking']) { t('System locale can\'t be set to %s. This means that there might be problems with certain characters in file names. We strongly suggest to install the required packages on your system to support %s.', array($locales, $locales))); + p($l->t('System locale can not be set to a one which supports UTF-8.')); + ?> +
+ t('This means that there might be problems with certain characters in file names.')); + ?> +
+ t('We strongly suggest to install the required packages on your system to support one of the following locales: %s.', array($locales))); ?>
-- cgit v1.2.3 From 228f1788fa2e93d333849a471c3b236f69f90904 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Sun, 24 Nov 2013 21:26:34 +0100 Subject: add new function to generate the human readable version string based on version, channel and build number --- lib/private/util.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 426c5a025f3..b5c5546da35 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -1111,4 +1111,17 @@ class OC_Util { $t = explode('/', $file); return array_pop($t); } + + /** + * A human readable string is generated based on version, channel and build number + * @return string + */ + public static function getHumanVersion() { + $version = OC_Util::getVersionString().' ('.OC_Util::getChannel().')'; + $build = OC_Util::getBuild(); + if(!empty($build) and OC_Util::getChannel() === 'daily') { + $version .= ' Build:' . $build; + } + return $version; + } } -- cgit v1.2.3 From 7ca0de9bd33eed65d4fb4fb8acc88e97622155e5 Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Fri, 29 Nov 2013 15:46:10 +0100 Subject: make 5.3.8 the minimum supported version. This fixes several issues with broken PHP versions like: https://github.com/owncloud/core/issues/5734 Also make the version compare clearer. It was pure luck that floatval on a php version returned the correct value. --- lib/private/util.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index b5c5546da35..38de07abc92 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -437,11 +437,11 @@ class OC_Util { ); $webServerRestart = true; } - if(floatval(phpversion()) < 5.3) { + if(version_compare(phpversion(), '5.3.8', '<')) { $errors[] = array( - 'error'=>'PHP 5.3 is required.', - 'hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher.' - .' PHP 5.2 is no longer supported by ownCloud and the PHP community.' + 'error'=>'PHP 5.3.8 or higher is required.', + 'hint'=>'Please ask your server administrator to update PHP to the latest version.' + .' Your PHP version is no longer supported by ownCloud and the PHP community.' ); $webServerRestart = true; } -- cgit v1.2.3 From 61296ed7bbf638e8285f29fa65fc4a0ad6c2529a Mon Sep 17 00:00:00 2001 From: Frank Karlitschek Date: Tue, 3 Dec 2013 14:30:32 +0100 Subject: lower required php version to 5.3.3 --- lib/private/util.php | 12 ++++++++++-- settings/admin.php | 1 + settings/templates/admin.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/private/util.php') diff --git a/lib/private/util.php b/lib/private/util.php index 38de07abc92..a73564b3f68 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -437,9 +437,9 @@ class OC_Util { ); $webServerRestart = true; } - if(version_compare(phpversion(), '5.3.8', '<')) { + if(version_compare(phpversion(), '5.3.3', '<')) { $errors[] = array( - 'error'=>'PHP 5.3.8 or higher is required.', + 'error'=>'PHP 5.3.3 or higher is required.', 'hint'=>'Please ask your server administrator to update PHP to the latest version.' .' Your PHP version is no longer supported by ownCloud and the PHP community.' ); @@ -874,6 +874,14 @@ class OC_Util { return function_exists('finfo_open'); } + /** + * @brief Check if a PHP version older then 5.3.8 is installed. + * @return bool + */ + public static function isPHPoutdated() { + return version_compare(phpversion(), '5.3.8', '<'); + } + /** * @brief Check if the ownCloud server can connect to the internet * @return bool diff --git a/settings/admin.php b/settings/admin.php index 0d3868afea8..c0e4570658a 100755 --- a/settings/admin.php +++ b/settings/admin.php @@ -28,6 +28,7 @@ $tmpl->assign('internetconnectionworking', OC_Util::isInternetConnectionEnabled( $tmpl->assign('isLocaleWorking', OC_Util::isSetLocaleWorking()); $tmpl->assign('isWebDavWorking', OC_Util::isWebDAVWorking()); $tmpl->assign('has_fileinfo', OC_Util::fileInfoLoaded()); +$tmpl->assign('old_php', OC_Util::isPHPoutdated()); $tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'ajax')); $tmpl->assign('shareAPIEnabled', OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes')); diff --git a/settings/templates/admin.php b/settings/templates/admin.php index 523bbd66248..0eabffb9316 100644 --- a/settings/templates/admin.php +++ b/settings/templates/admin.php @@ -72,6 +72,20 @@ if (!$_['has_fileinfo']) { +
+

t('Your PHP version is outdated'));?>

+ + + t('Your PHP version is outdated. We strongly recommend to update to 5.3.8 or newer because older versions are known to be broken. It is possible that this installation is not working correctly.')); ?> + + +
+ -- cgit v1.2.3