Throw exception if file cannot be accessed via http

Format file

Removing calls to deprecated classes and using internal method to get via http

Missed a character

Fix inverted logic
remotes/origin/fix-10825
Clark Tomlinson 12 years ago
parent a77d468d35
commit 2ad0d3f1be
  1. 71
      lib/private/util.php

@ -4,7 +4,6 @@
* Class for utility functions * Class for utility functions
* *
*/ */
class OC_Util { class OC_Util {
public static $scripts = array(); public static $scripts = array();
public static $styles = array(); public static $styles = array();
@ -27,6 +26,7 @@ class OC_Util {
* mounting an object storage as the root fs will in essence remove the * mounting an object storage as the root fs will in essence remove the
* necessity of a data folder being present. * necessity of a data folder being present.
* TODO make home storage aware of this and use the object storage instead of local disk access * TODO make home storage aware of this and use the object storage instead of local disk access
*
* @param array $config containing 'class' and optional 'arguments' * @param array $config containing 'class' and optional 'arguments'
*/ */
private static function initObjectStoreRootFS($config) { private static function initObjectStoreRootFS($config) {
@ -53,6 +53,7 @@ class OC_Util {
/** /**
* Can be set up * Can be set up
*
* @param string $user * @param string $user
* @return boolean * @return boolean
* @description configure the initial filesystem based on the configuration * @description configure the initial filesystem based on the configuration
@ -139,6 +140,7 @@ class OC_Util {
/** /**
* check if a password is required for each public link * check if a password is required for each public link
*
* @return boolean * @return boolean
*/ */
public static function isPublicLinkPasswordRequired() { public static function isPublicLinkPasswordRequired() {
@ -172,6 +174,7 @@ class OC_Util {
/** /**
* check if share API enforces a default expire date * check if share API enforces a default expire date
*
* @return boolean * @return boolean
*/ */
public static function isDefaultExpireDateEnforced() { public static function isDefaultExpireDateEnforced() {
@ -187,6 +190,7 @@ class OC_Util {
/** /**
* Get the quota of a user * Get the quota of a user
*
* @param string $user * @param string $user
* @return int Quota bytes * @return int Quota bytes
*/ */
@ -205,6 +209,7 @@ class OC_Util {
/** /**
* copies the user skeleton files into the fresh user home files * copies the user skeleton files into the fresh user home files
*
* @param string $userDirectory * @param string $userDirectory
*/ */
public static function copySkeleton($userDirectory) { public static function copySkeleton($userDirectory) {
@ -216,6 +221,7 @@ class OC_Util {
/** /**
* copies a directory recursively * copies a directory recursively
*
* @param string $source * @param string $source
* @param string $target * @param string $target
* @return void * @return void
@ -246,6 +252,7 @@ class OC_Util {
/** /**
* get the current installed version of ownCloud * get the current installed version of ownCloud
*
* @return array * @return array
*/ */
public static function getVersion() { public static function getVersion() {
@ -255,6 +262,7 @@ class OC_Util {
/** /**
* get the current installed version string of ownCloud * get the current installed version string of ownCloud
*
* @return string * @return string
*/ */
public static function getVersionString() { public static function getVersionString() {
@ -354,6 +362,7 @@ class OC_Util {
/** /**
* Add a custom element to the header * Add a custom element to the header
*
* @param string $tag tag name of the element * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element * @param array $attributes array of attributes for the element
* @param string $text the text content for the element * @param string $text the text content for the element
@ -389,6 +398,7 @@ class OC_Util {
/** /**
* check if the current server configuration is suitable for ownCloud * check if the current server configuration is suitable for ownCloud
*
* @return array arrays with error messages and hints * @return array arrays with error messages and hints
*/ */
public static function checkServer() { public static function checkServer() {
@ -411,7 +421,8 @@ class OC_Util {
if (!(is_callable('sqlite_open') or class_exists('SQLite3')) if (!(is_callable('sqlite_open') or class_exists('SQLite3'))
and !is_callable('mysql_connect') and !is_callable('mysql_connect')
and !is_callable('pg_connect') and !is_callable('pg_connect')
and !is_callable('oci_connect')) { and !is_callable('oci_connect')
) {
$errors[] = array( $errors[] = array(
'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
'hint' => '' //TODO: sane hint 'hint' => '' //TODO: sane hint
@ -438,7 +449,8 @@ class OC_Util {
if (OC_Config::getValue('appstoreenabled', true)) { if (OC_Config::getValue('appstoreenabled', true)) {
if (OC_App::getInstallPath() === null if (OC_App::getInstallPath() === null
|| !is_writable(OC_App::getInstallPath()) || !is_writable(OC_App::getInstallPath())
|| !is_readable(OC_App::getInstallPath()) ) { || !is_readable(OC_App::getInstallPath())
) {
$errors[] = array( $errors[] = array(
'error' => $l->t('Cannot write into "apps" directory'), 'error' => $l->t('Cannot write into "apps" directory'),
'hint' => $l->t('This can usually be fixed by ' 'hint' => $l->t('This can usually be fixed by '
@ -569,7 +581,8 @@ class OC_Util {
if (((strtolower(@ini_get('safe_mode')) == 'on') if (((strtolower(@ini_get('safe_mode')) == 'on')
|| (strtolower(@ini_get('safe_mode')) == 'yes') || (strtolower(@ini_get('safe_mode')) == 'yes')
|| (strtolower(@ini_get('safe_mode')) == 'true') || (strtolower(@ini_get('safe_mode')) == 'true')
|| (ini_get("safe_mode") == 1 ))) { || (ini_get("safe_mode") == 1))
) {
$errors[] = array( $errors[] = array(
'error' => $l->t('PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.'), 'error' => $l->t('PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.'),
'hint' => $l->t('PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. ' 'hint' => $l->t('PHP Safe Mode is a deprecated and mostly useless setting that should be disabled. '
@ -609,6 +622,7 @@ class OC_Util {
/** /**
* Check the database version * Check the database version
*
* @return array errors array * @return array errors array
*/ */
public static function checkDatabaseVersion() { public static function checkDatabaseVersion() {
@ -644,6 +658,7 @@ class OC_Util {
/** /**
* check if there are still some encrypted files stored * check if there are still some encrypted files stored
*
* @return boolean * @return boolean
*/ */
public static function encryptedFiles() { public static function encryptedFiles() {
@ -665,6 +680,7 @@ class OC_Util {
/** /**
* check if a backup from the encryption keys exists * check if a backup from the encryption keys exists
*
* @return boolean * @return boolean
*/ */
public static function backupKeysExists() { public static function backupKeysExists() {
@ -686,6 +702,7 @@ class OC_Util {
/** /**
* Check for correct file permissions of data directory * Check for correct file permissions of data directory
*
* @param string $dataDirectory * @param string $dataDirectory
* @return array arrays with error messages and hints * @return array arrays with error messages and hints
*/ */
@ -761,6 +778,7 @@ class OC_Util {
/** /**
* Check if the app is enabled, redirects to home if not * Check if the app is enabled, redirects to home if not
*
* @param string $app * @param string $app
* @return void * @return void
*/ */
@ -774,6 +792,7 @@ class OC_Util {
/** /**
* Check if the user is logged in, redirects to home if not. With * Check if the user is logged in, redirects to home if not. With
* redirect URL parameter to the request URI. * redirect URL parameter to the request URI.
*
* @return void * @return void
*/ */
public static function checkLoggedIn() { public static function checkLoggedIn() {
@ -788,6 +807,7 @@ class OC_Util {
/** /**
* Check if the user is a admin, redirects to home if not * Check if the user is a admin, redirects to home if not
*
* @return void * @return void
*/ */
public static function checkAdminUser() { public static function checkAdminUser() {
@ -821,6 +841,7 @@ class OC_Util {
/** /**
* Check if the user is a subadmin, redirects to home if not * Check if the user is a subadmin, redirects to home if not
*
* @return null|boolean $groups where the current user is subadmin * @return null|boolean $groups where the current user is subadmin
*/ */
public static function checkSubAdminUser() { public static function checkSubAdminUser() {
@ -866,6 +887,7 @@ class OC_Util {
/** /**
* Redirect to the user default page * Redirect to the user default page
*
* @return void * @return void
*/ */
public static function redirectToDefaultPage() { public static function redirectToDefaultPage() {
@ -876,6 +898,7 @@ class OC_Util {
/** /**
* get an id unique for this instance * get an id unique for this instance
*
* @return string * @return string
*/ */
public static function getInstanceId() { public static function getInstanceId() {
@ -890,6 +913,7 @@ class OC_Util {
/** /**
* Static lifespan (in seconds) when a request token expires. * Static lifespan (in seconds) when a request token expires.
*
* @see OC_Util::callRegister() * @see OC_Util::callRegister()
* @see OC_Util::isCallRegistered() * @see OC_Util::isCallRegistered()
* @description * @description
@ -901,6 +925,7 @@ class OC_Util {
/** /**
* Register an get/post call. Important to prevent CSRF attacks. * Register an get/post call. Important to prevent CSRF attacks.
*
* @todo Write howto: CSRF protection guide * @todo Write howto: CSRF protection guide
* @return string Generated token. * @return string Generated token.
* @description * @description
@ -926,6 +951,7 @@ class OC_Util {
/** /**
* Check an ajax get/post call if the request token is valid. * Check an ajax get/post call if the request token is valid.
*
* @return boolean False if request token is not set or is invalid. * @return boolean False if request token is not set or is invalid.
* @see OC_Util::$callLifespan * @see OC_Util::$callLifespan
* @see OC_Util::callRegister() * @see OC_Util::callRegister()
@ -936,6 +962,7 @@ class OC_Util {
/** /**
* Check an ajax get/post call if the request token is valid. Exit if not. * Check an ajax get/post call if the request token is valid. Exit if not.
*
* @todo Write howto * @todo Write howto
* @return void * @return void
*/ */
@ -982,13 +1009,14 @@ class OC_Util {
/** /**
* Check if the .htaccess file is working * Check if the .htaccess file is working
*
* @throws OC\HintException If the testfile can't get written. * @throws OC\HintException If the testfile can't get written.
* @return bool * @return bool
* @description Check if the .htaccess file is working by creating a test * @description Check if the .htaccess file is working by creating a test
* file in the data directory and trying to access via http * file in the data directory and trying to access via http
*/ */
public static function isHtaccessWorking() { public static function isHtaccessWorking() {
if (!\OC_Config::getValue("check_for_working_htaccess", true)) { if (!OC::$server->getConfig()->getSystemValue('check_for_working_htaccess', true)) {
return true; return true;
} }
@ -997,7 +1025,7 @@ class OC_Util {
$testContent = 'testcontent'; $testContent = 'testcontent';
// creating a test file // creating a test file
$testFile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$fileName; $testFile = OC::$server->getConfig()->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName;
if (file_exists($testFile)) {// already running this test, possible recursive call if (file_exists($testFile)) {// already running this test, possible recursive call
return false; return false;
@ -1013,23 +1041,21 @@ class OC_Util {
// accessing the file via http // accessing the file via http
$url = OC_Helper::makeURLAbsolute(OC::$WEBROOT . '/data' . $fileName); $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT . '/data' . $fileName);
$fp = @fopen($url, 'r'); $content = self::getUrlContent($url);
$content=@fread($fp, 2048);
@fclose($fp);
// cleanup // cleanup
@unlink($testFile); @unlink($testFile);
// does it work ? /*
if($content==$testContent) { * If the content is not equal to test content our .htaccess
return false; * is working as required
} else { */
return true; return $content !== $testContent;
}
} }
/** /**
* test if webDAV is working properly * test if webDAV is working properly
*
* @return bool * @return bool
* @description * @description
* The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND * The basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND
@ -1077,6 +1103,7 @@ class OC_Util {
/** /**
* Check if the setlocal call does not work. This can happen if the right * Check if the setlocal call does not work. This can happen if the right
* local packages are not available on the server. * local packages are not available on the server.
*
* @return bool * @return bool
*/ */
public static function isSetLocaleWorking() { public static function isSetLocaleWorking() {
@ -1106,6 +1133,7 @@ class OC_Util {
/** /**
* Check if the PHP module fileinfo is loaded. * Check if the PHP module fileinfo is loaded.
*
* @return bool * @return bool
*/ */
public static function fileInfoLoaded() { public static function fileInfoLoaded() {
@ -1114,6 +1142,7 @@ class OC_Util {
/** /**
* Check if a PHP version older then 5.3.8 is installed. * Check if a PHP version older then 5.3.8 is installed.
*
* @return bool * @return bool
*/ */
public static function isPHPoutdated() { public static function isPHPoutdated() {
@ -1122,6 +1151,7 @@ class OC_Util {
/** /**
* Check if the ownCloud server can connect to the internet * Check if the ownCloud server can connect to the internet
*
* @return bool * @return bool
*/ */
public static function isInternetConnectionWorking() { public static function isInternetConnectionWorking() {
@ -1154,6 +1184,7 @@ class OC_Util {
/** /**
* Check if the connection to the internet is disabled on purpose * Check if the connection to the internet is disabled on purpose
*
* @return string * @return string
*/ */
public static function isInternetConnectionEnabled() { public static function isInternetConnectionEnabled() {
@ -1162,6 +1193,7 @@ class OC_Util {
/** /**
* clear all levels of output buffering * clear all levels of output buffering
*
* @return void * @return void
*/ */
public static function obEnd() { public static function obEnd() {
@ -1173,6 +1205,7 @@ class OC_Util {
/** /**
* Generates a cryptographic secure pseudo-random string * Generates a cryptographic secure pseudo-random string
*
* @param int $length of the random string * @param int $length of the random string
* @return string * @return string
* Please also update secureRNGAvailable if you change something here * Please also update secureRNGAvailable if you change something here
@ -1210,6 +1243,7 @@ class OC_Util {
/** /**
* Checks if a secure random number generator is available * Checks if a secure random number generator is available
*
* @return bool * @return bool
*/ */
public static function secureRNGAvailable() { public static function secureRNGAvailable() {
@ -1334,6 +1368,7 @@ class OC_Util {
/** /**
* Checks whether the server is running on Windows * Checks whether the server is running on Windows
*
* @return bool true if running on Windows, false otherwise * @return bool true if running on Windows, false otherwise
*/ */
public static function runningOnWindows() { public static function runningOnWindows() {
@ -1342,6 +1377,7 @@ class OC_Util {
/** /**
* Checks whether the server is running on Mac OS X * Checks whether the server is running on Mac OS X
*
* @return bool true if running on Mac OS X, false otherwise * @return bool true if running on Mac OS X, false otherwise
*/ */
public static function runningOnMac() { public static function runningOnMac() {
@ -1351,6 +1387,7 @@ class OC_Util {
/** /**
* Handles the case that there may not be a theme, then check if a "default" * Handles the case that there may not be a theme, then check if a "default"
* theme exists and take that one * theme exists and take that one
*
* @return string the theme * @return string the theme
*/ */
public static function getTheme() { public static function getTheme() {
@ -1369,6 +1406,7 @@ class OC_Util {
* Clear the opcode cache if one exists * Clear the opcode cache if one exists
* This is necessary for writing to the config file * This is necessary for writing to the config file
* in case the opcode cache does not re-validate files * in case the opcode cache does not re-validate files
*
* @return void * @return void
*/ */
public static function clearOpcodeCache() { public static function clearOpcodeCache() {
@ -1396,6 +1434,7 @@ class OC_Util {
/** /**
* Normalize a unicode string * Normalize a unicode string
*
* @param string $value a not normalized string * @param string $value a not normalized string
* @return bool|string * @return bool|string
*/ */
@ -1424,6 +1463,7 @@ class OC_Util {
/** /**
* A human readable string is generated based on version, channel and build number * A human readable string is generated based on version, channel and build number
*
* @return string * @return string
*/ */
public static function getHumanVersion() { public static function getHumanVersion() {
@ -1437,6 +1477,7 @@ class OC_Util {
/** /**
* Returns whether the given file name is valid * Returns whether the given file name is valid
*
* @param string $file file name to check * @param string $file file name to check
* @return bool true if the file name is valid, false otherwise * @return bool true if the file name is valid, false otherwise
*/ */

Loading…
Cancel
Save