|
|
@ -11,12 +11,16 @@ class OC_Util {
|
|
|
|
public static $headers=array();
|
|
|
|
public static $headers=array();
|
|
|
|
private static $rootMounted=false;
|
|
|
|
private static $rootMounted=false;
|
|
|
|
private static $fsSetup=false;
|
|
|
|
private static $fsSetup=false;
|
|
|
|
public static $core_styles=array();
|
|
|
|
public static $coreStyles=array();
|
|
|
|
public static $core_scripts=array();
|
|
|
|
public static $coreScripts=array();
|
|
|
|
|
|
|
|
|
|
|
|
// Can be set up
|
|
|
|
/**
|
|
|
|
public static function setupFS( $user = '' ) {// configure the initial filesystem based on the configuration
|
|
|
|
* @brief Can be set up
|
|
|
|
if(self::$fsSetup) {//setting up the filesystem twice can only lead to trouble
|
|
|
|
* @param user string
|
|
|
|
|
|
|
|
* @return boolean
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static function setupFS( $user = '' ) { // configure the initial filesystem based on the configuration
|
|
|
|
|
|
|
|
if(self::$fsSetup) { //setting up the filesystem twice can only lead to trouble
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -37,42 +41,45 @@ class OC_Util {
|
|
|
|
self::$fsSetup=true;
|
|
|
|
self::$fsSetup=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
|
|
|
|
$configDataDirectory = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
|
|
|
|
//first set up the local "root" storage
|
|
|
|
//first set up the local "root" storage
|
|
|
|
\OC\Files\Filesystem::initMounts();
|
|
|
|
\OC\Files\Filesystem::initMounts();
|
|
|
|
if(!self::$rootMounted) {
|
|
|
|
if(!self::$rootMounted) {
|
|
|
|
\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/');
|
|
|
|
\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$configDataDirectory), '/');
|
|
|
|
self::$rootMounted=true;
|
|
|
|
self::$rootMounted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( $user != "" ) { //if we aren't logged in, there is no use to set up the filesystem
|
|
|
|
if( $user != "" ) { //if we aren't logged in, there is no use to set up the filesystem
|
|
|
|
$user_dir = '/'.$user.'/files';
|
|
|
|
$userDir = '/'.$user.'/files';
|
|
|
|
$user_root = OC_User::getHome($user);
|
|
|
|
$userRoot = OC_User::getHome($user);
|
|
|
|
$userdirectory = $user_root . '/files';
|
|
|
|
$userDirectory = $userRoot . '/files';
|
|
|
|
if( !is_dir( $userdirectory )) {
|
|
|
|
if( !is_dir( $userDirectory )) {
|
|
|
|
mkdir( $userdirectory, 0755, true );
|
|
|
|
mkdir( $userDirectory, 0755, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//jail the user into his "home" directory
|
|
|
|
//jail the user into his "home" directory
|
|
|
|
\OC\Files\Filesystem::init($user, $user_dir);
|
|
|
|
\OC\Files\Filesystem::init($user, $userDir);
|
|
|
|
|
|
|
|
|
|
|
|
$quotaProxy=new OC_FileProxy_Quota();
|
|
|
|
$quotaProxy = new OC_FileProxy_Quota();
|
|
|
|
$fileOperationProxy = new OC_FileProxy_FileOperations();
|
|
|
|
$fileOperationProxy = new OC_FileProxy_FileOperations();
|
|
|
|
OC_FileProxy::register($quotaProxy);
|
|
|
|
OC_FileProxy::register($quotaProxy);
|
|
|
|
OC_FileProxy::register($fileOperationProxy);
|
|
|
|
OC_FileProxy::register($fileOperationProxy);
|
|
|
|
|
|
|
|
|
|
|
|
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
|
|
|
|
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function tearDownFS() {
|
|
|
|
public static function tearDownFS() {
|
|
|
|
\OC\Files\Filesystem::tearDown();
|
|
|
|
\OC\Files\Filesystem::tearDown();
|
|
|
|
self::$fsSetup=false;
|
|
|
|
self::$fsSetup=false;
|
|
|
|
self::$rootMounted=false;
|
|
|
|
self::$rootMounted=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* get the current installed version of ownCloud
|
|
|
|
* @brief get the current installed version of ownCloud
|
|
|
|
* @return array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
public static function getVersion() {
|
|
|
@ -82,7 +89,7 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* get the current installed version string of ownCloud
|
|
|
|
* @brief get the current installed version string of ownCloud
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function getVersionString() {
|
|
|
|
public static function getVersionString() {
|
|
|
@ -90,7 +97,7 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* get the current installed edition of ownCloud. There is the community
|
|
|
|
* @description get the current installed edition of ownCloud. There is the community
|
|
|
|
* edition that just returns an empty string and the enterprise edition
|
|
|
|
* edition that just returns an empty string and the enterprise edition
|
|
|
|
* that returns "Enterprise".
|
|
|
|
* that returns "Enterprise".
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
@ -100,37 +107,39 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* add a javascript file
|
|
|
|
* @brief add a javascript file
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param appid $application
|
|
|
|
* @param appid $application
|
|
|
|
* @param filename $file
|
|
|
|
* @param filename $file
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function addScript( $application, $file = null ) {
|
|
|
|
public static function addScript( $application, $file = null ) {
|
|
|
|
if( is_null( $file )) {
|
|
|
|
if ( is_null( $file )) {
|
|
|
|
$file = $application;
|
|
|
|
$file = $application;
|
|
|
|
$application = "";
|
|
|
|
$application = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !empty( $application )) {
|
|
|
|
if ( !empty( $application )) {
|
|
|
|
self::$scripts[] = "$application/js/$file";
|
|
|
|
self::$scripts[] = "$application/js/$file";
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
self::$scripts[] = "js/$file";
|
|
|
|
self::$scripts[] = "js/$file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* add a css file
|
|
|
|
* @brief add a css file
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param appid $application
|
|
|
|
* @param appid $application
|
|
|
|
* @param filename $file
|
|
|
|
* @param filename $file
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function addStyle( $application, $file = null ) {
|
|
|
|
public static function addStyle( $application, $file = null ) {
|
|
|
|
if( is_null( $file )) {
|
|
|
|
if ( is_null( $file )) {
|
|
|
|
$file = $application;
|
|
|
|
$file = $application;
|
|
|
|
$application = "";
|
|
|
|
$application = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !empty( $application )) {
|
|
|
|
if ( !empty( $application )) {
|
|
|
|
self::$styles[] = "$application/css/$file";
|
|
|
|
self::$styles[] = "$application/css/$file";
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
self::$styles[] = "css/$file";
|
|
|
|
self::$styles[] = "css/$file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,63 +149,74 @@ class OC_Util {
|
|
|
|
* @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
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function addHeader( $tag, $attributes, $text='') {
|
|
|
|
public static function addHeader( $tag, $attributes, $text='') {
|
|
|
|
self::$headers[] = array('tag'=>$tag, 'attributes'=>$attributes, 'text'=>$text);
|
|
|
|
self::$headers[] = array(
|
|
|
|
|
|
|
|
'tag'=>$tag,
|
|
|
|
|
|
|
|
'attributes'=>$attributes,
|
|
|
|
|
|
|
|
'text'=>$text
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* formats a timestamp in the "right" way
|
|
|
|
* @brief formats a timestamp in the "right" way
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param int timestamp $timestamp
|
|
|
|
* @param int timestamp $timestamp
|
|
|
|
* @param bool dateOnly option to omit time from the result
|
|
|
|
* @param bool dateOnly option to omit time from the result
|
|
|
|
|
|
|
|
* @return string timestamp
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function formatDate( $timestamp, $dateOnly=false) {
|
|
|
|
public static function formatDate( $timestamp, $dateOnly=false) {
|
|
|
|
if(\OC::$session->exists('timezone')) {//adjust to clients timezone if we know it
|
|
|
|
if(\OC::$session->exists('timezone')) { //adjust to clients timezone if we know it
|
|
|
|
$systemTimeZone = intval(date('O'));
|
|
|
|
$systemTimeZone = intval(date('O'));
|
|
|
|
$systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100);
|
|
|
|
$systemTimeZone = (round($systemTimeZone/100, 0)*60) + ($systemTimeZone%100);
|
|
|
|
$clientTimeZone=\OC::$session->get('timezone')*60;
|
|
|
|
$clientTimeZone = \OC::$session->get('timezone')*60;
|
|
|
|
$offset=$clientTimeZone-$systemTimeZone;
|
|
|
|
$offset = $clientTimeZone - $systemTimeZone;
|
|
|
|
$timestamp=$timestamp+$offset*60;
|
|
|
|
$timestamp = $timestamp + $offset*60;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$l=OC_L10N::get('lib');
|
|
|
|
$l = OC_L10N::get('lib');
|
|
|
|
return $l->l($dateOnly ? 'date' : 'datetime', $timestamp);
|
|
|
|
return $l->l($dateOnly ? 'date' : 'datetime', $timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* check if the current server configuration is suitable for ownCloud
|
|
|
|
* @brief 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() {
|
|
|
|
// Assume that if checkServer() succeeded before in this session, then all is fine.
|
|
|
|
// Assume that if checkServer() succeeded before in this session, then all is fine.
|
|
|
|
if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded'))
|
|
|
|
if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) {
|
|
|
|
return array();
|
|
|
|
return array();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$errors=array();
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
|
|
|
|
$defaults = new \OC_Defaults();
|
|
|
|
$defaults = new \OC_Defaults();
|
|
|
|
|
|
|
|
|
|
|
|
$web_server_restart= false;
|
|
|
|
$webServerRestart = false;
|
|
|
|
//check for database drivers
|
|
|
|
//check for database drivers
|
|
|
|
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('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'');//TODO: sane hint
|
|
|
|
'error'=>'No database drivers (sqlite, mysql, or postgresql) installed.',
|
|
|
|
$web_server_restart= true;
|
|
|
|
'hint'=>'' //TODO: sane hint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//common hint for all file permissons error messages
|
|
|
|
//common hint for all file permissons error messages
|
|
|
|
$permissionsHint = 'Permissions can usually be fixed by '
|
|
|
|
$permissionsHint = 'Permissions can usually be fixed by '
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.';
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
|
|
|
|
|
|
|
|
.'#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.';
|
|
|
|
|
|
|
|
|
|
|
|
// Check if config folder is writable.
|
|
|
|
// Check if config folder is writable.
|
|
|
|
if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) {
|
|
|
|
if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) {
|
|
|
|
$errors[] = array(
|
|
|
|
$errors[] = array(
|
|
|
|
'error' => "Can't write into config directory",
|
|
|
|
'error' => "Can't write into config directory",
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
|
|
|
|
|
|
|
|
.'#set-the-directory-permissions" target="_blank">giving the webserver write access to the config directory</a>.'
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -208,7 +228,8 @@ class OC_Util {
|
|
|
|
$errors[] = array(
|
|
|
|
$errors[] = array(
|
|
|
|
'error' => "Can't write into apps directory",
|
|
|
|
'error' => "Can't write into apps directory",
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the apps directory</a> '
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
|
|
|
|
|
|
|
|
.'#set-the-directory-permissions" target="_blank">giving the webserver write access to the apps directory</a> '
|
|
|
|
.'or disabling the appstore in the config file.'
|
|
|
|
.'or disabling the appstore in the config file.'
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -223,94 +244,131 @@ class OC_Util {
|
|
|
|
$errors[] = array(
|
|
|
|
$errors[] = array(
|
|
|
|
'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")",
|
|
|
|
'error' => "Can't create data directory (".$CONFIG_DATADIRECTORY.")",
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
'hint' => 'This can usually be fixed by '
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.'
|
|
|
|
.'<a href="' . $defaults->getDocBaseUrl() . '/server/5.0/admin_manual/installation/installation_source.html'
|
|
|
|
|
|
|
|
.'#set-the-directory-permissions" target="_blank">giving the webserver write access to the root directory</a>.'
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
|
|
|
|
} else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
|
|
|
|
$errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>$permissionsHint);
|
|
|
|
'error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud',
|
|
|
|
|
|
|
|
'hint'=>$permissionsHint
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY));
|
|
|
|
$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
|
|
|
|
// check if all required php modules are present
|
|
|
|
if(!class_exists('ZipArchive')) {
|
|
|
|
if(!class_exists('ZipArchive')) {
|
|
|
|
$errors[]=array('error'=>'PHP module zip not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module zip not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!class_exists('DOMDocument')) {
|
|
|
|
if(!class_exists('DOMDocument')) {
|
|
|
|
$errors[] = array('error' => 'PHP module dom not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint' => 'Please ask your server administrator to install the module.');
|
|
|
|
'error' => 'PHP module dom not installed.',
|
|
|
|
$web_server_restart =true;
|
|
|
|
'hint' => $moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart =true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('xml_parser_create')) {
|
|
|
|
if(!function_exists('xml_parser_create')) {
|
|
|
|
$errors[] = array('error' => 'PHP module libxml not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint' => 'Please ask your server administrator to install the module.');
|
|
|
|
'error' => 'PHP module libxml not installed.',
|
|
|
|
$web_server_restart =true;
|
|
|
|
'hint' => $moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('mb_detect_encoding')) {
|
|
|
|
if(!function_exists('mb_detect_encoding')) {
|
|
|
|
$errors[]=array('error'=>'PHP module mb multibyte not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module mb multibyte not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('ctype_digit')) {
|
|
|
|
if(!function_exists('ctype_digit')) {
|
|
|
|
$errors[]=array('error'=>'PHP module ctype is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module ctype is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('json_encode')) {
|
|
|
|
if(!function_exists('json_encode')) {
|
|
|
|
$errors[]=array('error'=>'PHP module JSON is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module JSON is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!extension_loaded('gd') || !function_exists('gd_info')) {
|
|
|
|
if(!extension_loaded('gd') || !function_exists('gd_info')) {
|
|
|
|
$errors[]=array('error'=>'PHP module GD is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module GD is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('gzencode')) {
|
|
|
|
if(!function_exists('gzencode')) {
|
|
|
|
$errors[]=array('error'=>'PHP module zlib is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module zlib is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('iconv')) {
|
|
|
|
if(!function_exists('iconv')) {
|
|
|
|
$errors[]=array('error'=>'PHP module iconv is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module iconv is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!function_exists('simplexml_load_string')) {
|
|
|
|
if(!function_exists('simplexml_load_string')) {
|
|
|
|
$errors[]=array('error'=>'PHP module SimpleXML is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP module SimpleXML is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(floatval(phpversion())<5.3) {
|
|
|
|
if(floatval(phpversion()) < 5.3) {
|
|
|
|
$errors[]=array('error'=>'PHP 5.3 is required.',
|
|
|
|
$errors[] = array(
|
|
|
|
|
|
|
|
'error'=>'PHP 5.3 is required.',
|
|
|
|
'hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher.'
|
|
|
|
'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.');
|
|
|
|
.' PHP 5.2 is no longer supported by ownCloud and the PHP community.'
|
|
|
|
$web_server_restart=true;
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!defined('PDO::ATTR_DRIVER_NAME')) {
|
|
|
|
if(!defined('PDO::ATTR_DRIVER_NAME')) {
|
|
|
|
$errors[]=array('error'=>'PHP PDO module is not installed.',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to install the module.');
|
|
|
|
'error'=>'PHP PDO module is not installed.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'hint'=>$moduleHint
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$webServerRestart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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('error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.',
|
|
|
|
$errors[] = array(
|
|
|
|
'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.');
|
|
|
|
'error'=>'PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'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 ) {
|
|
|
|
if (get_magic_quotes_gpc() == 1 ) {
|
|
|
|
$errors[]=array('error'=>'Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.',
|
|
|
|
$errors[] = array(
|
|
|
|
'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.');
|
|
|
|
'error'=>'Magic Quotes is enabled. ownCloud requires that it is disabled to work properly.',
|
|
|
|
$web_server_restart=true;
|
|
|
|
'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($web_server_restart) {
|
|
|
|
if($webServerRestart) {
|
|
|
|
$errors[]=array('error'=>'PHP modules have been installed, but they are still listed as missing?',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint'=>'Please ask your server administrator to restart the web server.');
|
|
|
|
'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
|
|
|
|
// Cache the result of this function
|
|
|
@ -330,20 +388,25 @@ class OC_Util {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$permissionsModHint = 'Please change the permissions to 0770 so that the directory'
|
|
|
|
$permissionsModHint = 'Please change the permissions to 0770 so that the directory'
|
|
|
|
.' cannot be listed by other users.';
|
|
|
|
.' cannot be listed by other users.';
|
|
|
|
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
|
|
|
|
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
|
|
|
|
if (substr($prems, -1) != '0') {
|
|
|
|
if (substr($perms, -1) != '0') {
|
|
|
|
OC_Helper::chmodr($dataDirectory, 0770);
|
|
|
|
OC_Helper::chmodr($dataDirectory, 0770);
|
|
|
|
clearstatcache();
|
|
|
|
clearstatcache();
|
|
|
|
$prems = substr(decoct(@fileperms($dataDirectory)), -3);
|
|
|
|
$perms = substr(decoct(@fileperms($dataDirectory)), -3);
|
|
|
|
if (substr($prems, 2, 1) != '0') {
|
|
|
|
if (substr($perms, 2, 1) != '0') {
|
|
|
|
$errors[] = array('error' => 'Data directory ('.$dataDirectory.') is readable for other users',
|
|
|
|
$errors[] = array(
|
|
|
|
'hint' => $permissionsModHint);
|
|
|
|
'error' => 'Data directory ('.$dataDirectory.') is readable for other users',
|
|
|
|
|
|
|
|
'hint' => $permissionsModHint
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function displayLoginPage($errors = array()) {
|
|
|
|
public static function displayLoginPage($errors = array()) {
|
|
|
|
$parameters = array();
|
|
|
|
$parameters = array();
|
|
|
|
foreach( $errors as $key => $value ) {
|
|
|
|
foreach( $errors as $key => $value ) {
|
|
|
@ -357,8 +420,8 @@ class OC_Util {
|
|
|
|
$parameters['user_autofocus'] = true;
|
|
|
|
$parameters['user_autofocus'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($_REQUEST['redirect_url'])) {
|
|
|
|
if (isset($_REQUEST['redirect_url'])) {
|
|
|
|
$redirect_url = $_REQUEST['redirect_url'];
|
|
|
|
$redirectUrl = $_REQUEST['redirect_url'];
|
|
|
|
$parameters['redirect_url'] = urlencode($redirect_url);
|
|
|
|
$parameters['redirect_url'] = urlencode($redirectUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$parameters['alt_login'] = OC_App::getAlternativeLogIns();
|
|
|
|
$parameters['alt_login'] = OC_App::getAlternativeLogIns();
|
|
|
@ -367,7 +430,8 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the app is enabled, redirects to home if not
|
|
|
|
* @brief Check if the app is enabled, redirects to home if not
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function checkAppEnabled($app) {
|
|
|
|
public static function checkAppEnabled($app) {
|
|
|
|
if( !OC_App::isEnabled($app)) {
|
|
|
|
if( !OC_App::isEnabled($app)) {
|
|
|
@ -379,18 +443,21 @@ 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
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function checkLoggedIn() {
|
|
|
|
public static function checkLoggedIn() {
|
|
|
|
// Check if we are a user
|
|
|
|
// Check if we are a user
|
|
|
|
if( !OC_User::isLoggedIn()) {
|
|
|
|
if( !OC_User::isLoggedIn()) {
|
|
|
|
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php',
|
|
|
|
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php',
|
|
|
|
array('redirect_url' => OC_Request::requestUri())));
|
|
|
|
array('redirectUrl' => OC_Request::requestUri())
|
|
|
|
|
|
|
|
));
|
|
|
|
exit();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the user is a admin, redirects to home if not
|
|
|
|
* @brief Check if the user is a admin, redirects to home if not
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function checkAdminUser() {
|
|
|
|
public static function checkAdminUser() {
|
|
|
|
if( !OC_User::isAdminUser(OC_User::getUser())) {
|
|
|
|
if( !OC_User::isAdminUser(OC_User::getUser())) {
|
|
|
@ -400,7 +467,7 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the user is a subadmin, redirects to home if not
|
|
|
|
* @brief Check if the user is a subadmin, redirects to home if not
|
|
|
|
* @return array $groups where the current user is subadmin
|
|
|
|
* @return array $groups where the current user is subadmin
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function checkSubAdminUser() {
|
|
|
|
public static function checkSubAdminUser() {
|
|
|
@ -412,7 +479,8 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Redirect to the user default page
|
|
|
|
* @brief Redirect to the user default page
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function redirectToDefaultPage() {
|
|
|
|
public static function redirectToDefaultPage() {
|
|
|
|
if(isset($_REQUEST['redirect_url'])) {
|
|
|
|
if(isset($_REQUEST['redirect_url'])) {
|
|
|
@ -420,13 +488,11 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) {
|
|
|
|
else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) {
|
|
|
|
$location = OC_Helper::linkToAbsolute( OC::$REQUESTEDAPP, 'index.php' );
|
|
|
|
$location = OC_Helper::linkToAbsolute( OC::$REQUESTEDAPP, 'index.php' );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
$defaultPage = OC_Appconfig::getValue('core', 'defaultpage');
|
|
|
|
$defaultpage = OC_Appconfig::getValue('core', 'defaultpage');
|
|
|
|
if ($defaultPage) {
|
|
|
|
if ($defaultpage) {
|
|
|
|
$location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultPage);
|
|
|
|
$location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultpage);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
|
|
|
|
$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -435,19 +501,19 @@ class OC_Util {
|
|
|
|
exit();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* get an id unique for this instance
|
|
|
|
* @brief get an id unique for this instance
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function getInstanceId() {
|
|
|
|
public static function getInstanceId() {
|
|
|
|
$id = OC_Config::getValue('instanceid', null);
|
|
|
|
$id = OC_Config::getValue('instanceid', null);
|
|
|
|
if(is_null($id)) {
|
|
|
|
if(is_null($id)) {
|
|
|
|
// We need to guarantee at least one letter in instanceid so it can be used as the session_name
|
|
|
|
// We need to guarantee at least one letter in instanceid so it can be used as the session_name
|
|
|
|
$id = 'oc' . OC_Util::generate_random_bytes(10);
|
|
|
|
$id = 'oc' . self::generateRandomBytes(10);
|
|
|
|
OC_Config::setValue('instanceid', $id);
|
|
|
|
OC_Config::setValue('instanceid', $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Static lifespan (in seconds) when a request token expires.
|
|
|
|
* @brief Static lifespan (in seconds) when a request token expires.
|
|
|
@ -476,7 +542,7 @@ class OC_Util {
|
|
|
|
// Check if a token exists
|
|
|
|
// Check if a token exists
|
|
|
|
if(!\OC::$session->exists('requesttoken')) {
|
|
|
|
if(!\OC::$session->exists('requesttoken')) {
|
|
|
|
// No valid token found, generate a new one.
|
|
|
|
// No valid token found, generate a new one.
|
|
|
|
$requestToken = self::generate_random_bytes(20);
|
|
|
|
$requestToken = self::generateRandomBytes(20);
|
|
|
|
\OC::$session->set('requesttoken', $requestToken);
|
|
|
|
\OC::$session->set('requesttoken', $requestToken);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Valid token already exists, send it
|
|
|
|
// Valid token already exists, send it
|
|
|
@ -497,11 +563,11 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($_GET['requesttoken'])) {
|
|
|
|
if(isset($_GET['requesttoken'])) {
|
|
|
|
$token=$_GET['requesttoken'];
|
|
|
|
$token = $_GET['requesttoken'];
|
|
|
|
} elseif(isset($_POST['requesttoken'])) {
|
|
|
|
} elseif(isset($_POST['requesttoken'])) {
|
|
|
|
$token=$_POST['requesttoken'];
|
|
|
|
$token = $_POST['requesttoken'];
|
|
|
|
} elseif(isset($_SERVER['HTTP_REQUESTTOKEN'])) {
|
|
|
|
} elseif(isset($_SERVER['HTTP_REQUESTTOKEN'])) {
|
|
|
|
$token=$_SERVER['HTTP_REQUESTTOKEN'];
|
|
|
|
$token = $_SERVER['HTTP_REQUESTTOKEN'];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//no token found.
|
|
|
|
//no token found.
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -519,11 +585,12 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Check an ajax get/post call if the request token is valid. exit if not.
|
|
|
|
* @brief Check an ajax get/post call if the request token is valid. exit if not.
|
|
|
|
* Todo: Write howto
|
|
|
|
* @todo Write howto
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function callCheck() {
|
|
|
|
public static function callCheck() {
|
|
|
|
if(!OC_Util::isCallRegistered()) {
|
|
|
|
if(!OC_Util::isCallRegistered()) {
|
|
|
|
exit;
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -562,12 +629,13 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the htaccess file is working by creating a test file in the data directory and trying to access via http
|
|
|
|
* @brief Check if the htaccess file is working by creating a test file in the data directory and trying to access via http
|
|
|
|
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function ishtaccessworking() {
|
|
|
|
public static function isHtaccessWorking() {
|
|
|
|
// testdata
|
|
|
|
// testdata
|
|
|
|
$filename='/htaccesstest.txt';
|
|
|
|
$filename = '/htaccesstest.txt';
|
|
|
|
$testcontent='testcontent';
|
|
|
|
$testcontent = 'testcontent';
|
|
|
|
|
|
|
|
|
|
|
|
// creating a test file
|
|
|
|
// creating a test file
|
|
|
|
$testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename;
|
|
|
|
$testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename;
|
|
|
@ -591,19 +659,20 @@ class OC_Util {
|
|
|
|
|
|
|
|
|
|
|
|
// does it work ?
|
|
|
|
// does it work ?
|
|
|
|
if($content==$testcontent) {
|
|
|
|
if($content==$testcontent) {
|
|
|
|
return(false);
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
return(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* we test if webDAV is working properly
|
|
|
|
* @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 basic assumption is that if the server returns 401/Not Authenticated for an unauthenticated PROPFIND
|
|
|
|
* the web server it self is setup properly.
|
|
|
|
* the web server it self is setup properly.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Why not an authenticated PROFIND and other verbs?
|
|
|
|
* Why not an authenticated PROPFIND and other verbs?
|
|
|
|
* - We don't have the password available
|
|
|
|
* - We don't have the password available
|
|
|
|
* - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header)
|
|
|
|
* - We have no idea about other auth methods implemented (e.g. OAuth with Bearer header)
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -617,7 +686,7 @@ class OC_Util {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// save the old timeout so that we can restore it later
|
|
|
|
// save the old timeout so that we can restore it later
|
|
|
|
$old_timeout=ini_get("default_socket_timeout");
|
|
|
|
$oldTimeout = ini_get("default_socket_timeout");
|
|
|
|
|
|
|
|
|
|
|
|
// use a 5 sec timeout for the check. Should be enough for local requests.
|
|
|
|
// use a 5 sec timeout for the check. Should be enough for local requests.
|
|
|
|
ini_set("default_socket_timeout", 5);
|
|
|
|
ini_set("default_socket_timeout", 5);
|
|
|
@ -631,15 +700,15 @@ class OC_Util {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// test PROPFIND
|
|
|
|
// test PROPFIND
|
|
|
|
$client->propfind('', array('{DAV:}resourcetype'));
|
|
|
|
$client->propfind('', array('{DAV:}resourcetype'));
|
|
|
|
} catch(\Sabre_DAV_Exception_NotAuthenticated $e) {
|
|
|
|
} catch (\Sabre_DAV_Exception_NotAuthenticated $e) {
|
|
|
|
$return = true;
|
|
|
|
$return = true;
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e->getMessage(). ' ('.get_class($e).')', OC_Log::WARN);
|
|
|
|
OC_Log::write('core', 'isWebDAVWorking: NO - Reason: '.$e->getMessage(). ' ('.get_class($e).')', OC_Log::WARN);
|
|
|
|
$return = false;
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// restore the original timeout
|
|
|
|
// restore the original timeout
|
|
|
|
ini_set("default_socket_timeout", $old_timeout);
|
|
|
|
ini_set("default_socket_timeout", $oldTimeout);
|
|
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -647,8 +716,9 @@ class OC_Util {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the setlocal call doesn't work. This can happen if the right
|
|
|
|
* Check if the setlocal call doesn't 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
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function issetlocaleworking() {
|
|
|
|
public static function isSetlocaleWorking() {
|
|
|
|
// setlocale test is pointless on Windows
|
|
|
|
// setlocale test is pointless on Windows
|
|
|
|
if (OC_Util::runningOnWindows() ) {
|
|
|
|
if (OC_Util::runningOnWindows() ) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -662,7 +732,7 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the PHP module fileinfo is loaded.
|
|
|
|
* @brief Check if the PHP module fileinfo is loaded.
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function fileInfoLoaded() {
|
|
|
|
public static function fileInfoLoaded() {
|
|
|
@ -670,7 +740,8 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the ownCloud server can connect to the internet
|
|
|
|
* @brief Check if the ownCloud server can connect to the internet
|
|
|
|
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function isInternetConnectionWorking() {
|
|
|
|
public static function isInternetConnectionWorking() {
|
|
|
|
// in case there is no internet connection on purpose return false
|
|
|
|
// in case there is no internet connection on purpose return false
|
|
|
@ -683,30 +754,29 @@ class OC_Util {
|
|
|
|
if ($connected) {
|
|
|
|
if ($connected) {
|
|
|
|
fclose($connected);
|
|
|
|
fclose($connected);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// second try in case one server is down
|
|
|
|
// second try in case one server is down
|
|
|
|
$connected = @fsockopen("apps.owncloud.com", 80);
|
|
|
|
$connected = @fsockopen("apps.owncloud.com", 80);
|
|
|
|
if ($connected) {
|
|
|
|
if ($connected) {
|
|
|
|
fclose($connected);
|
|
|
|
fclose($connected);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Check if the connection to the internet is disabled on purpose
|
|
|
|
* @brief Check if the connection to the internet is disabled on purpose
|
|
|
|
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function isInternetConnectionEnabled(){
|
|
|
|
public static function isInternetConnectionEnabled(){
|
|
|
|
return \OC_Config::getValue("has_internet_connection", true);
|
|
|
|
return \OC_Config::getValue("has_internet_connection", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* clear all levels of output buffering
|
|
|
|
* @brief clear all levels of output buffering
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function obEnd(){
|
|
|
|
public static function obEnd(){
|
|
|
|
while (ob_get_level()) {
|
|
|
|
while (ob_get_level()) {
|
|
|
@ -719,44 +789,44 @@ class OC_Util {
|
|
|
|
* @brief Generates a cryptographical secure pseudorandom string
|
|
|
|
* @brief Generates a cryptographical secure pseudorandom string
|
|
|
|
* @param Int with the length of the random string
|
|
|
|
* @param Int with the length of the random string
|
|
|
|
* @return String
|
|
|
|
* @return String
|
|
|
|
* Please also update secureRNG_available if you change something here
|
|
|
|
* Please also update secureRNGAvailable if you change something here
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function generate_random_bytes($length = 30) {
|
|
|
|
public static function generateRandomBytes($length = 30) {
|
|
|
|
|
|
|
|
|
|
|
|
// Try to use openssl_random_pseudo_bytes
|
|
|
|
// Try to use openssl_random_pseudo_bytes
|
|
|
|
if(function_exists('openssl_random_pseudo_bytes')) {
|
|
|
|
if (function_exists('openssl_random_pseudo_bytes')) {
|
|
|
|
$pseudo_byte = bin2hex(openssl_random_pseudo_bytes($length, $strong));
|
|
|
|
$pseudoByte = bin2hex(openssl_random_pseudo_bytes($length, $strong));
|
|
|
|
if($strong == true) {
|
|
|
|
if($strong == true) {
|
|
|
|
return substr($pseudo_byte, 0, $length); // Truncate it to match the length
|
|
|
|
return substr($pseudoByte, 0, $length); // Truncate it to match the length
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to use /dev/urandom
|
|
|
|
// Try to use /dev/urandom
|
|
|
|
$fp = @file_get_contents('/dev/urandom', false, null, 0, $length);
|
|
|
|
if (!self::runningOnWindows()) {
|
|
|
|
if ($fp !== false) {
|
|
|
|
$fp = @file_get_contents('/dev/urandom', false, null, 0, $length);
|
|
|
|
$string = substr(bin2hex($fp), 0, $length);
|
|
|
|
if ($fp !== false) {
|
|
|
|
return $string;
|
|
|
|
$string = substr(bin2hex($fp), 0, $length);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback to mt_rand()
|
|
|
|
// Fallback to mt_rand()
|
|
|
|
$characters = '0123456789';
|
|
|
|
$characters = '0123456789';
|
|
|
|
$characters .= 'abcdefghijklmnopqrstuvwxyz';
|
|
|
|
$characters .= 'abcdefghijklmnopqrstuvwxyz';
|
|
|
|
$charactersLength = strlen($characters)-1;
|
|
|
|
$charactersLength = strlen($characters)-1;
|
|
|
|
$pseudo_byte = "";
|
|
|
|
$pseudoByte = "";
|
|
|
|
|
|
|
|
|
|
|
|
// Select some random characters
|
|
|
|
// Select some random characters
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
$pseudo_byte .= $characters[mt_rand(0, $charactersLength)];
|
|
|
|
$pseudoByte .= $characters[mt_rand(0, $charactersLength)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $pseudo_byte;
|
|
|
|
return $pseudoByte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @brief Checks if a secure random number generator is available
|
|
|
|
* @brief Checks if a secure random number generator is available
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function secureRNG_available() {
|
|
|
|
public static function secureRNGAvailable() {
|
|
|
|
|
|
|
|
|
|
|
|
// Check openssl_random_pseudo_bytes
|
|
|
|
// Check openssl_random_pseudo_bytes
|
|
|
|
if(function_exists('openssl_random_pseudo_bytes')) {
|
|
|
|
if(function_exists('openssl_random_pseudo_bytes')) {
|
|
|
|
openssl_random_pseudo_bytes(1, $strong);
|
|
|
|
openssl_random_pseudo_bytes(1, $strong);
|
|
|
@ -766,9 +836,11 @@ class OC_Util {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check /dev/urandom
|
|
|
|
// Check /dev/urandom
|
|
|
|
$fp = @file_get_contents('/dev/urandom', false, null, 0, 1);
|
|
|
|
if (!self::runningOnWindows()) {
|
|
|
|
if ($fp !== false) {
|
|
|
|
$fp = @file_get_contents('/dev/urandom', false, null, 0, 1);
|
|
|
|
return true;
|
|
|
|
if ($fp !== false) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -781,11 +853,8 @@ class OC_Util {
|
|
|
|
* This function get the content of a page via curl, if curl is enabled.
|
|
|
|
* 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_element is used.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public static function getUrlContent($url){
|
|
|
|
public static function getUrlContent($url){
|
|
|
|
|
|
|
|
if (function_exists('curl_init')) {
|
|
|
|
if (function_exists('curl_init')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$curl = curl_init();
|
|
|
|
$curl = curl_init();
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
@ -796,10 +865,10 @@ class OC_Util {
|
|
|
|
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
|
|
|
|
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler");
|
|
|
|
curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler");
|
|
|
|
if(OC_Config::getValue('proxy', '')<>'') {
|
|
|
|
if(OC_Config::getValue('proxy', '') != '') {
|
|
|
|
curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy'));
|
|
|
|
curl_setopt($curl, CURLOPT_PROXY, OC_Config::getValue('proxy'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(OC_Config::getValue('proxyuserpwd', '')<>'') {
|
|
|
|
if(OC_Config::getValue('proxyuserpwd', '') != '') {
|
|
|
|
curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd'));
|
|
|
|
curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data = curl_exec($curl);
|
|
|
|
$data = curl_exec($curl);
|
|
|
@ -808,7 +877,7 @@ class OC_Util {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$contextArray = null;
|
|
|
|
$contextArray = null;
|
|
|
|
|
|
|
|
|
|
|
|
if(OC_Config::getValue('proxy', '')<>'') {
|
|
|
|
if(OC_Config::getValue('proxy', '') != '') {
|
|
|
|
$contextArray = array(
|
|
|
|
$contextArray = array(
|
|
|
|
'http' => array(
|
|
|
|
'http' => array(
|
|
|
|
'timeout' => 10,
|
|
|
|
'timeout' => 10,
|
|
|
@ -823,11 +892,10 @@ class OC_Util {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ctx = stream_context_create(
|
|
|
|
$ctx = stream_context_create(
|
|
|
|
$contextArray
|
|
|
|
$contextArray
|
|
|
|
);
|
|
|
|
);
|
|
|
|
$data=@file_get_contents($url, 0, $ctx);
|
|
|
|
$data = @file_get_contents($url, 0, $ctx);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
return $data;
|
|
|
@ -840,7 +908,6 @@ class OC_Util {
|
|
|
|
return (substr(PHP_OS, 0, 3) === "WIN");
|
|
|
|
return (substr(PHP_OS, 0, 3) === "WIN");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
@ -850,20 +917,19 @@ class OC_Util {
|
|
|
|
$theme = OC_Config::getValue("theme", '');
|
|
|
|
$theme = OC_Config::getValue("theme", '');
|
|
|
|
|
|
|
|
|
|
|
|
if($theme === '') {
|
|
|
|
if($theme === '') {
|
|
|
|
|
|
|
|
|
|
|
|
if(is_dir(OC::$SERVERROOT . '/themes/default')) {
|
|
|
|
if(is_dir(OC::$SERVERROOT . '/themes/default')) {
|
|
|
|
$theme = 'default';
|
|
|
|
$theme = 'default';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $theme;
|
|
|
|
return $theme;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Clear the opcode cache if one exists
|
|
|
|
* @brief 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 doesn't revalidate files
|
|
|
|
* in case the opcode cache doesn't revalidate files
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function clearOpcodeCache() {
|
|
|
|
public static function clearOpcodeCache() {
|
|
|
|
// APC
|
|
|
|
// APC
|
|
|
@ -902,8 +968,10 @@ class OC_Util {
|
|
|
|
return $value;
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function basename($file)
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static function basename($file) {
|
|
|
|
$file = rtrim($file, '/');
|
|
|
|
$file = rtrim($file, '/');
|
|
|
|
$t = explode('/', $file);
|
|
|
|
$t = explode('/', $file);
|
|
|
|
return array_pop($t);
|
|
|
|
return array_pop($t);
|
|
|
|