|
|
|
|
@ -4,7 +4,6 @@
|
|
|
|
|
* Class for utility functions
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class OC_Util {
|
|
|
|
|
public static $scripts = 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
|
|
|
|
|
* necessity of a data folder being present.
|
|
|
|
|
* 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'
|
|
|
|
|
*/
|
|
|
|
|
private static function initObjectStoreRootFS($config) {
|
|
|
|
|
@ -53,6 +53,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Can be set up
|
|
|
|
|
*
|
|
|
|
|
* @param string $user
|
|
|
|
|
* @return boolean
|
|
|
|
|
* @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
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function isPublicLinkPasswordRequired() {
|
|
|
|
|
@ -172,6 +174,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check if share API enforces a default expire date
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function isDefaultExpireDateEnforced() {
|
|
|
|
|
@ -187,6 +190,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the quota of a user
|
|
|
|
|
*
|
|
|
|
|
* @param string $user
|
|
|
|
|
* @return int Quota bytes
|
|
|
|
|
*/
|
|
|
|
|
@ -205,6 +209,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* copies the user skeleton files into the fresh user home files
|
|
|
|
|
*
|
|
|
|
|
* @param string $userDirectory
|
|
|
|
|
*/
|
|
|
|
|
public static function copySkeleton($userDirectory) {
|
|
|
|
|
@ -216,6 +221,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* copies a directory recursively
|
|
|
|
|
*
|
|
|
|
|
* @param string $source
|
|
|
|
|
* @param string $target
|
|
|
|
|
* @return void
|
|
|
|
|
@ -246,6 +252,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the current installed version of ownCloud
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getVersion() {
|
|
|
|
|
@ -255,6 +262,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the current installed version string of ownCloud
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function getVersionString() {
|
|
|
|
|
@ -354,6 +362,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
@ -389,6 +398,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check if the current server configuration is suitable for ownCloud
|
|
|
|
|
*
|
|
|
|
|
* @return array arrays with error messages and hints
|
|
|
|
|
*/
|
|
|
|
|
public static function checkServer() {
|
|
|
|
|
@ -411,7 +421,8 @@ class OC_Util {
|
|
|
|
|
if (!(is_callable('sqlite_open') or class_exists('SQLite3'))
|
|
|
|
|
and !is_callable('mysql_connect')
|
|
|
|
|
and !is_callable('pg_connect')
|
|
|
|
|
and !is_callable('oci_connect')) {
|
|
|
|
|
and !is_callable('oci_connect')
|
|
|
|
|
) {
|
|
|
|
|
$errors[] = array(
|
|
|
|
|
'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
|
|
|
|
|
'hint' => '' //TODO: sane hint
|
|
|
|
|
@ -438,7 +449,8 @@ class OC_Util {
|
|
|
|
|
if (OC_Config::getValue('appstoreenabled', true)) {
|
|
|
|
|
if (OC_App::getInstallPath() === null
|
|
|
|
|
|| !is_writable(OC_App::getInstallPath())
|
|
|
|
|
|| !is_readable(OC_App::getInstallPath()) ) {
|
|
|
|
|
|| !is_readable(OC_App::getInstallPath())
|
|
|
|
|
) {
|
|
|
|
|
$errors[] = array(
|
|
|
|
|
'error' => $l->t('Cannot write into "apps" directory'),
|
|
|
|
|
'hint' => $l->t('This can usually be fixed by '
|
|
|
|
|
@ -569,7 +581,8 @@ class OC_Util {
|
|
|
|
|
if (((strtolower(@ini_get('safe_mode')) == 'on')
|
|
|
|
|
|| (strtolower(@ini_get('safe_mode')) == 'yes')
|
|
|
|
|
|| (strtolower(@ini_get('safe_mode')) == 'true')
|
|
|
|
|
|| (ini_get("safe_mode") == 1 ))) {
|
|
|
|
|
|| (ini_get("safe_mode") == 1))
|
|
|
|
|
) {
|
|
|
|
|
$errors[] = array(
|
|
|
|
|
'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. '
|
|
|
|
|
@ -609,6 +622,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the database version
|
|
|
|
|
*
|
|
|
|
|
* @return array errors array
|
|
|
|
|
*/
|
|
|
|
|
public static function checkDatabaseVersion() {
|
|
|
|
|
@ -644,6 +658,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check if there are still some encrypted files stored
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function encryptedFiles() {
|
|
|
|
|
@ -665,6 +680,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check if a backup from the encryption keys exists
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function backupKeysExists() {
|
|
|
|
|
@ -686,6 +702,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check for correct file permissions of data directory
|
|
|
|
|
*
|
|
|
|
|
* @param string $dataDirectory
|
|
|
|
|
* @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
|
|
|
|
|
*
|
|
|
|
|
* @param string $app
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
@ -774,6 +792,7 @@ class OC_Util {
|
|
|
|
|
/**
|
|
|
|
|
* 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() {
|
|
|
|
|
@ -788,6 +807,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the user is a admin, redirects to home if not
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function checkAdminUser() {
|
|
|
|
|
@ -821,6 +841,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the user is a subadmin, redirects to home if not
|
|
|
|
|
*
|
|
|
|
|
* @return null|boolean $groups where the current user is subadmin
|
|
|
|
|
*/
|
|
|
|
|
public static function checkSubAdminUser() {
|
|
|
|
|
@ -866,6 +887,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redirect to the user default page
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function redirectToDefaultPage() {
|
|
|
|
|
@ -876,6 +898,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get an id unique for this instance
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function getInstanceId() {
|
|
|
|
|
@ -890,6 +913,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Static lifespan (in seconds) when a request token expires.
|
|
|
|
|
*
|
|
|
|
|
* @see OC_Util::callRegister()
|
|
|
|
|
* @see OC_Util::isCallRegistered()
|
|
|
|
|
* @description
|
|
|
|
|
@ -901,6 +925,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register an get/post call. Important to prevent CSRF attacks.
|
|
|
|
|
*
|
|
|
|
|
* @todo Write howto: CSRF protection guide
|
|
|
|
|
* @return string Generated token.
|
|
|
|
|
* @description
|
|
|
|
|
@ -926,6 +951,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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()
|
|
|
|
|
@ -936,6 +962,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check an ajax get/post call if the request token is valid. Exit if not.
|
|
|
|
|
*
|
|
|
|
|
* @todo Write howto
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
@ -982,13 +1009,14 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the .htaccess file is working
|
|
|
|
|
*
|
|
|
|
|
* @throws OC\HintException If the testfile can't get written.
|
|
|
|
|
* @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() {
|
|
|
|
|
if (!\OC_Config::getValue("check_for_working_htaccess", true)) {
|
|
|
|
|
if (!OC::$server->getConfig()->getSystemValue('check_for_working_htaccess', true)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -997,7 +1025,7 @@ class OC_Util {
|
|
|
|
|
$testContent = 'testcontent';
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
return false;
|
|
|
|
|
@ -1013,23 +1041,21 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
// accessing the file via http
|
|
|
|
|
$url = OC_Helper::makeURLAbsolute(OC::$WEBROOT . '/data' . $fileName);
|
|
|
|
|
$fp = @fopen($url, 'r');
|
|
|
|
|
$content=@fread($fp, 2048);
|
|
|
|
|
@fclose($fp);
|
|
|
|
|
$content = self::getUrlContent($url);
|
|
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
@unlink($testFile);
|
|
|
|
|
|
|
|
|
|
// does it work ?
|
|
|
|
|
if($content==$testContent) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* If the content is not equal to test content our .htaccess
|
|
|
|
|
* is working as required
|
|
|
|
|
*/
|
|
|
|
|
return $content !== $testContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
@ -1077,6 +1103,7 @@ class OC_Util {
|
|
|
|
|
/**
|
|
|
|
|
* 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() {
|
|
|
|
|
@ -1106,6 +1133,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the PHP module fileinfo is loaded.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function fileInfoLoaded() {
|
|
|
|
|
@ -1114,6 +1142,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if a PHP version older then 5.3.8 is installed.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isPHPoutdated() {
|
|
|
|
|
@ -1122,6 +1151,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the ownCloud server can connect to the internet
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isInternetConnectionWorking() {
|
|
|
|
|
@ -1154,6 +1184,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the connection to the internet is disabled on purpose
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function isInternetConnectionEnabled() {
|
|
|
|
|
@ -1162,6 +1193,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* clear all levels of output buffering
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function obEnd() {
|
|
|
|
|
@ -1173,6 +1205,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
@ -1210,6 +1243,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if a secure random number generator is available
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function secureRNGAvailable() {
|
|
|
|
|
@ -1334,6 +1368,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the server is running on Windows
|
|
|
|
|
*
|
|
|
|
|
* @return bool true if running on Windows, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
public static function runningOnWindows() {
|
|
|
|
|
@ -1342,6 +1377,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the server is running on Mac OS X
|
|
|
|
|
*
|
|
|
|
|
* @return bool true if running on Mac OS X, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
* theme exists and take that one
|
|
|
|
|
*
|
|
|
|
|
* @return string the theme
|
|
|
|
|
*/
|
|
|
|
|
public static function getTheme() {
|
|
|
|
|
@ -1369,6 +1406,7 @@ class OC_Util {
|
|
|
|
|
* 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() {
|
|
|
|
|
@ -1396,6 +1434,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Normalize a unicode string
|
|
|
|
|
*
|
|
|
|
|
* @param string $value a not normalized string
|
|
|
|
|
* @return bool|string
|
|
|
|
|
*/
|
|
|
|
|
@ -1424,6 +1463,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A human readable string is generated based on version, channel and build number
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function getHumanVersion() {
|
|
|
|
|
@ -1437,6 +1477,7 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the given file name is valid
|
|
|
|
|
*
|
|
|
|
|
* @param string $file file name to check
|
|
|
|
|
* @return bool true if the file name is valid, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
|