summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2014-02-10 21:32:17 +0100
committerBart Visscher <bartv@thisnet.nl>2014-02-10 21:32:17 +0100
commit082abdc62080730f70ac0fac67628e4d3bb0cc7b (patch)
tree0054fcb95d954b31933aaafbbdcd69d66a6c944e /lib/private
parent5c3c379f351be913fe7abd500fadd69a83687ebc (diff)
parentbea80ffe2060407e5d849a86f71fae2eed80b08e (diff)
downloadnextcloud-server-082abdc62080730f70ac0fac67628e4d3bb0cc7b.tar.gz
nextcloud-server-082abdc62080730f70ac0fac67628e4d3bb0cc7b.zip
Merge branch 'master' into migration_unit_tests
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/api.php42
-rw-r--r--lib/private/app.php6
-rw-r--r--lib/private/config.php2
-rw-r--r--lib/private/connector/sabre/exceptionloggerplugin.php50
-rw-r--r--lib/private/connector/sabre/file.php13
-rw-r--r--lib/private/connector/sabre/objecttree.php15
-rw-r--r--lib/private/files.php9
-rw-r--r--lib/private/files/cache/cache.php22
-rw-r--r--lib/private/files/cache/homecache.php2
-rw-r--r--lib/private/files/cache/scanner.php2
-rw-r--r--lib/private/files/cache/storage.php19
-rw-r--r--lib/private/files/cache/watcher.php4
-rw-r--r--lib/private/files/storage/wrapper/quota.php2
-rw-r--r--lib/private/files/type/detection.php3
-rw-r--r--lib/private/files/view.php20
-rw-r--r--lib/private/helper.php72
-rw-r--r--lib/private/image.php4
-rw-r--r--lib/private/installer.php3
-rw-r--r--lib/private/json.php14
-rw-r--r--lib/private/l10n.php4
-rw-r--r--lib/private/legacy/config.php1
-rw-r--r--lib/private/log/errorhandler.php31
-rw-r--r--lib/private/log/owncloud.php1
-rw-r--r--lib/private/memcache/apc.php29
-rw-r--r--lib/private/memcache/apcu.php7
-rw-r--r--lib/private/memcache/cache.php2
-rw-r--r--lib/private/memcache/factory.php17
-rw-r--r--lib/private/memcache/memcached.php12
-rw-r--r--lib/private/mimetypes.list.php123
-rw-r--r--lib/private/ocs/result.php18
-rw-r--r--lib/private/preview/movies.php2
-rw-r--r--lib/private/preview/office.php4
-rw-r--r--lib/private/preview/pdf.php2
-rw-r--r--lib/private/preview/svg.php2
-rw-r--r--lib/private/preview/unknown.php2
-rwxr-xr-xlib/private/request.php24
-rw-r--r--lib/private/response.php18
-rw-r--r--lib/private/server.php19
-rw-r--r--lib/private/setup.php3
-rw-r--r--lib/private/setup/mysql.php12
-rw-r--r--lib/private/urlgenerator.php25
-rw-r--r--lib/private/user.php5
-rw-r--r--lib/private/user/backend.php17
-rw-r--r--lib/private/user/database.php15
-rw-r--r--lib/private/user/dummy.php9
-rw-r--r--lib/private/user/manager.php22
-rw-r--r--lib/private/user/session.php14
-rwxr-xr-xlib/private/util.php21
48 files changed, 537 insertions, 228 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index 03d7b7382a5..c713368125c 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -33,7 +33,7 @@ class OC_API {
const USER_AUTH = 1;
const SUBADMIN_AUTH = 2;
const ADMIN_AUTH = 3;
-
+
/**
* API Response Codes
*/
@@ -41,13 +41,13 @@ class OC_API {
const RESPOND_SERVER_ERROR = 996;
const RESPOND_NOT_FOUND = 998;
const RESPOND_UNKNOWN_ERROR = 999;
-
+
/**
* api actions
*/
protected static $actions = array();
private static $logoutRequired = false;
-
+
/**
* registers an api call
* @param string $method the http method
@@ -58,7 +58,7 @@ class OC_API {
* @param array $defaults
* @param array $requirements
*/
- public static function register($method, $url, $action, $app,
+ public static function register($method, $url, $action, $app,
$authLevel = OC_API::USER_AUTH,
$defaults = array(),
$requirements = array()) {
@@ -75,7 +75,7 @@ class OC_API {
}
self::$actions[$name][] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel);
}
-
+
/**
* handles an api call
* @param array $parameters
@@ -125,7 +125,7 @@ class OC_API {
self::respond($response, $format);
}
-
+
/**
* merge the returned result objects into one response
* @param array $responses
@@ -166,32 +166,31 @@ class OC_API {
// Maybe any that are not OC_API::RESPOND_SERVER_ERROR
// Merge failed responses if more than one
$data = array();
- $meta = array();
foreach($shipped['failed'] as $failure) {
$data = array_merge_recursive($data, $failure['response']->getData());
}
$picked = reset($shipped['failed']);
$code = $picked['response']->getStatusCode();
- $response = new OC_OCS_Result($data, $code);
+ $meta = $picked['response']->getMeta();
+ $response = new OC_OCS_Result($data, $code, $meta['message']);
return $response;
} elseif(!empty($shipped['succeeded'])) {
$responses = array_merge($shipped['succeeded'], $thirdparty['succeeded']);
} elseif(!empty($thirdparty['failed'])) {
// Merge failed responses if more than one
$data = array();
- $meta = array();
foreach($thirdparty['failed'] as $failure) {
$data = array_merge_recursive($data, $failure['response']->getData());
}
$picked = reset($thirdparty['failed']);
$code = $picked['response']->getStatusCode();
- $response = new OC_OCS_Result($data, $code);
+ $meta = $picked['response']->getMeta();
+ $response = new OC_OCS_Result($data, $code, $meta['message']);
return $response;
} else {
$responses = $thirdparty['succeeded'];
}
// Merge the successful responses
- $meta = array();
$data = array();
foreach($responses as $app => $response) {
@@ -200,22 +199,25 @@ class OC_API {
} else {
$data = array_merge_recursive($data, $response['response']->getData());
}
- $codes[] = $response['response']->getStatusCode();
+ $codes[] = array('code' => $response['response']->getStatusCode(),
+ 'meta' => $response['response']->getMeta());
}
// Use any non 100 status codes
$statusCode = 100;
+ $statusMessage = null;
foreach($codes as $code) {
- if($code != 100) {
- $statusCode = $code;
+ if($code['code'] != 100) {
+ $statusCode = $code['code'];
+ $statusMessage = $code['meta']['message'];
break;
}
}
- $result = new OC_OCS_Result($data, $statusCode);
+ $result = new OC_OCS_Result($data, $statusCode, $statusMessage);
return $result;
}
-
+
/**
* authenticate the api call
* @param array $action the action details as supplied to OC_API::register()
@@ -261,8 +263,8 @@ class OC_API {
return false;
break;
}
- }
-
+ }
+
/**
* http basic auth
* @return string|false (username, or false on failure)
@@ -294,7 +296,7 @@ class OC_API {
return false;
}
-
+
/**
* respond to a call
* @param OC_OCS_Result $result
@@ -343,5 +345,5 @@ class OC_API {
}
}
}
-
+
}
diff --git a/lib/private/app.php b/lib/private/app.php
index 34c00e97fb9..da09021cf3f 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -63,8 +63,8 @@ class OC_App{
ob_start();
foreach( $apps as $app ) {
if((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) {
- self::loadApp($app);
self::$loadedApps[] = $app;
+ self::loadApp($app);
}
}
ob_end_clean();
@@ -555,6 +555,10 @@ class OC_App{
}elseif($child->getName()=='description') {
$xml=(string)$child->asXML();
$data[$child->getName()]=substr($xml, 13, -14);//script <description> tags
+ }elseif($child->getName()=='documentation') {
+ foreach($child as $subchild) {
+ $data["documentation"][$subchild->getName()] = (string)$subchild;
+ }
}else{
$data[$child->getName()]=(string)$child;
}
diff --git a/lib/private/config.php b/lib/private/config.php
index caf7b1d7066..8a9d5ca6158 100644
--- a/lib/private/config.php
+++ b/lib/private/config.php
@@ -50,7 +50,7 @@ class Config {
protected $debugMode;
/**
- * @param $configDir path to the config dir, needs to end with '/'
+ * @param string $configDir path to the config dir, needs to end with '/'
*/
public function __construct($configDir) {
$this->configDir = $configDir;
diff --git a/lib/private/connector/sabre/exceptionloggerplugin.php b/lib/private/connector/sabre/exceptionloggerplugin.php
new file mode 100644
index 00000000000..8e77afaf207
--- /dev/null
+++ b/lib/private/connector/sabre/exceptionloggerplugin.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @author Vincent Petry
+ * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
+ *
+ * @license AGPL3
+ */
+
+class OC_Connector_Sabre_ExceptionLoggerPlugin extends Sabre_DAV_ServerPlugin
+{
+ private $appName;
+
+ /**
+ * @param string $loggerAppName app name to use when logging
+ */
+ public function __construct($loggerAppName = 'webdav') {
+ $this->appName = $loggerAppName;
+ }
+
+ /**
+ * This initializes the plugin.
+ *
+ * This function is called by Sabre_DAV_Server, after
+ * addPlugin is called.
+ *
+ * This method should set up the required event subscriptions.
+ *
+ * @param Sabre_DAV_Server $server
+ * @return void
+ */
+ public function initialize(Sabre_DAV_Server $server) {
+
+ $server->subscribeEvent('exception', array($this, 'logException'), 10);
+ }
+
+ /**
+ * Log exception
+ *
+ * @internal param Exception $e exception
+ */
+ public function logException($e) {
+ $exceptionClass = get_class($e);
+ if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') {
+ \OCP\Util::logException($this->appName, $e);
+ }
+ }
+}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 295575f0af6..ed27cef440d 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -64,7 +64,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
}
// mark file as partial while uploading (ignored by the scanner)
- $partpath = $this->path . '.part';
+ $partpath = $this->path . '.ocTransferId' . rand() . '.part';
// if file is located in /Shared we write the part file to the users
// root folder because we can't create new files in /shared
@@ -79,7 +79,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
\OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR);
$fs->unlink($partpath);
// because we have no clue about the cause we can only throw back a 500/Internal Server Error
- throw new Sabre_DAV_Exception();
+ throw new Sabre_DAV_Exception('Could not write file contents');
}
} catch (\OCP\Files\NotPermittedException $e) {
// a more general case - due to whatever reason the content could not be written
@@ -105,7 +105,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if ($renameOkay === false || $fileExists === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
$fs->unlink($partpath);
- throw new Sabre_DAV_Exception();
+ throw new Sabre_DAV_Exception('Could not rename part file to final file');
}
// allow sync clients to send the mtime along in a header
@@ -242,8 +242,11 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
$fileExists = $fs->file_exists($targetPath);
if ($renameOkay === false || $fileExists === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR);
- $fs->unlink($targetPath);
- throw new Sabre_DAV_Exception();
+ // only delete if an error occurred and the target file was already created
+ if ($fileExists) {
+ $fs->unlink($targetPath);
+ }
+ throw new Sabre_DAV_Exception('Could not rename part file assembled from chunks');
}
// allow sync clients to send the mtime along in a header
diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php
index cd3f081f7cc..d1e179af2ec 100644
--- a/lib/private/connector/sabre/objecttree.php
+++ b/lib/private/connector/sabre/objecttree.php
@@ -38,7 +38,20 @@ class ObjectTree extends \Sabre_DAV_ObjectTree {
return $this->rootNode;
}
- $info = $this->getFileView()->getFileInfo($path);
+ if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
+ // read from storage
+ $absPath = $this->getFileView()->getAbsolutePath($path);
+ list($storage, $internalPath) = Filesystem::resolvePath('/' . $absPath);
+ if ($storage) {
+ $scanner = $storage->getScanner($internalPath);
+ // get data directly
+ $info = $scanner->getData($internalPath);
+ }
+ }
+ else {
+ // read from cache
+ $info = $this->getFileView()->getFileInfo($path);
+ }
if (!$info) {
throw new \Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located');
diff --git a/lib/private/files.php b/lib/private/files.php
index 6ffa14c0d91..8ce632013cf 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -83,7 +83,7 @@ class OC_Files {
if ($basename) {
$name = $basename . '.zip';
} else {
- $name = 'owncloud.zip';
+ $name = 'download.zip';
}
set_time_limit($executionTime);
@@ -115,12 +115,7 @@ class OC_Files {
}
OC_Util::obEnd();
if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
- if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) {
- header( 'Content-Disposition: attachment; filename="' . rawurlencode($name) . '"' );
- } else {
- header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($name)
- . '; filename="' . rawurlencode($name) . '"' );
- }
+ OC_Response::setContentDispositionHeader($name, 'attachment');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 8e682a96b75..1e7936ca26d 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -178,7 +178,7 @@ class Cache {
if ($file['storage_mtime'] == 0) {
$file['storage_mtime'] = $file['mtime'];
}
- if ($file['encrypted']) {
+ if ($file['encrypted'] or ($file['unencrypted_size'] > 0 and $file['mimetype'] === 'httpd/unix-directory')) {
$file['encrypted_size'] = $file['size'];
$file['size'] = $file['unencrypted_size'];
}
@@ -511,22 +511,34 @@ class Cache {
$entry = $this->get($path);
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
- $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 FROM `*PREFIX*filecache` '.
+ $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2, ' .
+ 'SUM(`unencrypted_size`) AS f3 ' .
+ 'FROM `*PREFIX*filecache` ' .
'WHERE `parent` = ? AND `storage` = ?';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
- list($sum, $min) = array_values($row);
+ list($sum, $min, $unencryptedSum) = array_values($row);
$sum = (int)$sum;
$min = (int)$min;
+ $unencryptedSum = (int)$unencryptedSum;
if ($min === -1) {
$totalSize = $min;
} else {
$totalSize = $sum;
}
+ $update = array();
if ($entry['size'] !== $totalSize) {
- $this->update($id, array('size' => $totalSize));
+ $update['size'] = $totalSize;
+ }
+ if ($entry['unencrypted_size'] !== $unencryptedSum) {
+ $update['unencrypted_size'] = $unencryptedSum;
+ }
+ if (count($update) > 0) {
+ $this->update($id, $update);
+ }
+ if ($totalSize !== -1 and $unencryptedSum > 0) {
+ $totalSize = $unencryptedSum;
}
-
}
}
return $totalSize;
diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php
index 18dfbfe3191..71bb944da71 100644
--- a/lib/private/files/cache/homecache.php
+++ b/lib/private/files/cache/homecache.php
@@ -16,7 +16,7 @@ class HomeCache extends Cache {
* @return int
*/
public function calculateFolderSize($path) {
- if ($path !== '/' and $path !== '') {
+ if ($path !== '/' and $path !== '' and $path !== 'files') {
return parent::calculateFolderSize($path);
}
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index a8c069ee99f..92a4c01841b 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -122,7 +122,7 @@ class Scanner extends BasicEmitter {
$propagateETagChange = true;
}
// only reuse data if the file hasn't explicitly changed
- if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) {
+ if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) {
if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
$data['size'] = $cacheData['size'];
}
diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php
index 5657cf06e12..5b1b30176e8 100644
--- a/lib/private/files/cache/storage.php
+++ b/lib/private/files/cache/storage.php
@@ -70,4 +70,23 @@ class Storage {
return false;
}
}
+
+ /**
+ * remove the entry for the storage
+ *
+ * @param string $storageId
+ */
+ public static function remove($storageId) {
+ $storageCache = new Storage($storageId);
+ $numericId = $storageCache->getNumericId();
+
+ if (strlen($storageId) > 64) {
+ $storageId = md5($storageId);
+ }
+ $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
+ \OC_DB::executeAudited($sql, array($storageId));
+
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
+ \OC_DB::executeAudited($sql, array($numericId));
+ }
}
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 58f624c8990..251ecbe7071 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -40,7 +40,7 @@ class Watcher {
* check $path for updates
*
* @param string $path
- * @return boolean true if path was updated, false otherwise
+ * @return boolean | array true if path was updated, otherwise the cached data is returned
*/
public function checkUpdate($path) {
$cachedEntry = $this->cache->get($path);
@@ -56,7 +56,7 @@ class Watcher {
$this->cache->correctFolderSize($path);
return true;
}
- return false;
+ return $cachedEntry;
}
/**
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index 43016e0892f..a430e3e4617 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -95,7 +95,7 @@ class Quota extends Wrapper {
public function fopen($path, $mode) {
$source = $this->storage->fopen($path, $mode);
$free = $this->free_space('');
- if ($free >= 0 && $mode !== 'r') {
+ if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
return \OC\Files\Stream\Quota::wrap($source, $free);
} else {
return $source;
diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php
index d7cc9ebbf4e..11e439032ce 100644
--- a/lib/private/files/type/detection.php
+++ b/lib/private/files/type/detection.php
@@ -72,11 +72,12 @@ class Detection {
and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)
) {
$info = @strtolower(finfo_file($finfo, $path));
+ finfo_close($finfo);
if ($info) {
$mimeType = substr($info, 0, strpos($info, ';'));
return empty($mimeType) ? 'application/octet-stream' : $mimeType;
}
- finfo_close($finfo);
+
}
$isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://');
if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) {
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index ac45a881331..d97544b865e 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -336,6 +336,19 @@ class View {
}
public function unlink($path) {
+ if ($path === '' || $path === '/') {
+ // do not allow deleting the root
+ return false;
+ }
+ $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+ $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
+ list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
+ if (!$internalPath || $internalPath === '' || $internalPath === '/') {
+ // do not allow deleting the storage's root / the mount point
+ // because for some storages it might delete the whole contents
+ // but isn't supposed to work that way
+ return false;
+ }
return $this->basicOperation('unlink', $path, array('delete'));
}
@@ -788,6 +801,7 @@ class View {
* @var string $internalPath
*/
list($storage, $internalPath) = Filesystem::resolvePath($path);
+ $data = null;
if ($storage) {
$cache = $storage->getCache($internalPath);
$permissionsCache = $storage->getPermissionsCache($internalPath);
@@ -798,10 +812,12 @@ class View {
$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
} else {
$watcher = $storage->getWatcher($internalPath);
- $watcher->checkUpdate($internalPath);
+ $data = $watcher->checkUpdate($internalPath);
}
- $data = $cache->get($internalPath);
+ if (!is_array($data)) {
+ $data = $cache->get($internalPath);
+ }
if ($data and $data['fileid']) {
if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
diff --git a/lib/private/helper.php b/lib/private/helper.php
index 4fe3097af26..580f81acc62 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -161,6 +161,7 @@ class OC_Helper {
'application/vnd.oasis.opendocument.text-template' => 'x-office/document',
'application/vnd.oasis.opendocument.text-web' => 'x-office/document',
'application/vnd.oasis.opendocument.text-master' => 'x-office/document',
+ 'application/mspowerpoint' => 'x-office/presentation',
'application/vnd.ms-powerpoint' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation',
@@ -171,6 +172,7 @@ class OC_Helper {
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation',
'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation',
'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation',
+ 'application/msexcel' => 'x-office/spreadsheet',
'application/vnd.ms-excel' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet',
@@ -180,6 +182,7 @@ class OC_Helper {
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet',
+ 'application/msaccess' => 'database',
);
if (isset($alias[$mimetype])) {
@@ -445,29 +448,6 @@ class OC_Helper {
*
*/
- //FIXME: should also check for value validation (i.e. the email is an email).
- public static function init_var($s, $d = "") {
- $r = $d;
- if (isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) {
- $r = OC_Util::sanitizeHTML($_REQUEST[$s]);
- }
-
- return $r;
- }
-
- /**
- * returns "checked"-attribute if request contains selected radio element
- * OR if radio element is the default one -- maybe?
- *
- * @param string $s Name of radio-button element name
- * @param string $v Value of current radio-button element
- * @param string $d Value of default radio-button element
- */
- public static function init_radio($s, $v, $d) {
- if ((isset($_REQUEST[$s]) && $_REQUEST[$s] == $v) || (!isset($_REQUEST[$s]) && $v == $d))
- print "checked=\"checked\" ";
- }
-
/**
* detect if a given program is found in the search PATH
*
@@ -828,23 +808,39 @@ class OC_Helper {
* @return number of bytes representing
*/
public static function maxUploadFilesize($dir) {
- $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
- $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
- $freeSpace = \OC\Files\Filesystem::free_space($dir);
- if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
- $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED;
- } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
- $maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts
- } else {
- $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
- }
+ return min(self::freeSpace($dir), self::uploadLimit());
+ }
+ /**
+ * Calculate free space left within user quota
+ *
+ * @param $dir the current folder where the user currently operates
+ * @return number of bytes representing
+ */
+ public static function freeSpace($dir) {
+ $freeSpace = \OC\Files\Filesystem::free_space($dir);
if ($freeSpace !== \OC\Files\SPACE_UNKNOWN) {
$freeSpace = max($freeSpace, 0);
+ return $freeSpace;
+ } else {
+ return INF;
+ }
+ }
- return min($maxUploadFilesize, $freeSpace);
+ /**
+ * Calculate PHP upload limit
+ *
+ * @return PHP upload file size limit
+ */
+ public static function uploadLimit() {
+ $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
+ $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
+ if ((int)$upload_max_filesize === 0 and (int)$post_max_size === 0) {
+ return INF;
+ } elseif ((int)$upload_max_filesize === 0 or (int)$post_max_size === 0) {
+ return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
} else {
- return $maxUploadFilesize;
+ return min($upload_max_filesize, $post_max_size);
}
}
@@ -858,11 +854,13 @@ class OC_Helper {
if (!function_exists($function_name)) {
return false;
}
- $disabled = explode(', ', ini_get('disable_functions'));
+ $disabled = explode(',', ini_get('disable_functions'));
+ $disabled = array_map('trim', $disabled);
if (in_array($function_name, $disabled)) {
return false;
}
- $disabled = explode(', ', ini_get('suhosin.executor.func.blacklist'));
+ $disabled = explode(',', ini_get('suhosin.executor.func.blacklist'));
+ $disabled = array_map('trim', $disabled);
if (in_array($function_name, $disabled)) {
return false;
}
diff --git a/lib/private/image.php b/lib/private/image.php
index 7761a3c7737..91a9f91e1d6 100644
--- a/lib/private/image.php
+++ b/lib/private/image.php
@@ -409,14 +409,14 @@ class OC_Image {
/**
* @brief Loads an image from a local file.
- * @param $imageref The path to a local file.
+ * @param $imagePath The path to a local file.
* @returns An image resource or false on error
*/
public function loadFromFile($imagePath=false) {
// exif_imagetype throws "read error!" if file is less than 12 byte
if(!@is_file($imagePath) || !file_exists($imagePath) || filesize($imagePath) < 12 || !is_readable($imagePath)) {
// Debug output disabled because this method is tried before loadFromBase64?
- OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagePath, OC_Log::DEBUG);
+ OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: ' . (string) urlencode($imagePath), OC_Log::DEBUG);
return false;
}
$iType = exif_imagetype($imagePath);
diff --git a/lib/private/installer.php b/lib/private/installer.php
index 8375b231e9b..835b6b4c01a 100644
--- a/lib/private/installer.php
+++ b/lib/private/installer.php
@@ -407,6 +407,9 @@ class OC_Installer{
include OC_App::getAppPath($app)."/appinfo/install.php";
}
$info=OC_App::getAppInfo($app);
+ if (is_null($info)) {
+ return false;
+ }
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
//set remote/public handelers
diff --git a/lib/private/json.php b/lib/private/json.php
index 6a9e5a2df5e..5c5d7e3a3da 100644
--- a/lib/private/json.php
+++ b/lib/private/json.php
@@ -65,6 +65,20 @@ class OC_JSON{
}
/**
+ * Check is a given user exists - send json error msg if not
+ * @param string $user
+ */
+ public static function checkUserExists($user) {
+ if (!OCP\User::userExists($user)) {
+ $l = OC_L10N::get('lib');
+ OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'))));
+ exit;
+ }
+ }
+
+
+
+ /**
* Check if the user is a subadmin, send json error msg if not
*/
public static function checkSubAdminUser() {
diff --git a/lib/private/l10n.php b/lib/private/l10n.php
index 98665c84c55..1aa1dc5ea28 100644
--- a/lib/private/l10n.php
+++ b/lib/private/l10n.php
@@ -132,10 +132,10 @@ class OC_L10N implements \OCP\IL10N {
$i18ndir = self::findI18nDir($app);
// Localization is in /l10n, Texts are in $i18ndir
// (Just no need to define date/time format etc. twice)
- if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/')
- || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')
+ if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')
|| OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/')
|| OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings')
+ || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/')
)
&& file_exists($i18ndir.$lang.'.php')) {
// Include the file, save the data from $CONFIG
diff --git a/lib/private/legacy/config.php b/lib/private/legacy/config.php
index c457979113e..ab67c8d3020 100644
--- a/lib/private/legacy/config.php
+++ b/lib/private/legacy/config.php
@@ -38,7 +38,6 @@
* This class is responsible for reading and writing config.php, the very basic
* configuration file of ownCloud.
*/
-OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/');
class OC_Config {
/**
diff --git a/lib/private/log/errorhandler.php b/lib/private/log/errorhandler.php
index 69cb960de91..1dde6b507fc 100644
--- a/lib/private/log/errorhandler.php
+++ b/lib/private/log/errorhandler.php
@@ -14,10 +14,23 @@ class ErrorHandler {
/** @var LoggerInterface */
private static $logger;
- public static function register() {
+ /**
+ * @brief remove password in URLs
+ * @param string $msg
+ * @return string
+ */
+ protected static function removePassword($msg) {
+ return preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $msg);
+ }
+
+ public static function register($debug=false) {
$handler = new ErrorHandler();
- set_error_handler(array($handler, 'onError'));
+ if ($debug) {
+ set_error_handler(array($handler, 'onAll'), E_ALL);
+ } else {
+ set_error_handler(array($handler, 'onError'));
+ }
register_shutdown_function(array($handler, 'onShutdown'));
set_exception_handler(array($handler, 'onException'));
}
@@ -32,14 +45,14 @@ class ErrorHandler {
if($error && self::$logger) {
//ob_end_clean();
$msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line'];
- self::$logger->critical($msg, array('app' => 'PHP'));
+ self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
}
}
// Uncaught exception handler
public static function onException($exception) {
$msg = $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine();
- self::$logger->critical($msg, array('app' => 'PHP'));
+ self::$logger->critical(self::removePassword($msg), array('app' => 'PHP'));
}
//Recoverable errors handler
@@ -48,7 +61,15 @@ class ErrorHandler {
return;
}
$msg = $message . ' at ' . $file . '#' . $line;
- self::$logger->warning($msg, array('app' => 'PHP'));
+ self::$logger->error(self::removePassword($msg), array('app' => 'PHP'));
+
+ }
+
+ //Recoverable handler which catch all errors, warnings and notices
+ public static function onAll($number, $message, $file, $line) {
+ $msg = $message . ' at ' . $file . '#' . $line;
+ self::$logger->debug(self::removePassword($msg), array('app' => 'PHP'));
}
+
}
diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php
index 4c86d0e45e0..3590bbd436d 100644
--- a/lib/private/log/owncloud.php
+++ b/lib/private/log/owncloud.php
@@ -69,7 +69,6 @@ class OC_Log_Owncloud {
}
$time = new DateTime(null, $timezone);
// remove username/passswords from URLs before writing the to the log file
- $message = preg_replace('/\/\/(.*):(.*)@/', '//xxx:xxx@', $message);
$entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time->format($format));
$entry = json_encode($entry);
$handle = @fopen(self::$logFile, 'a');
diff --git a/lib/private/memcache/apc.php b/lib/private/memcache/apc.php
index 575ee4427db..332bbfead00 100644
--- a/lib/private/memcache/apc.php
+++ b/lib/private/memcache/apc.php
@@ -9,15 +9,8 @@
namespace OC\Memcache;
class APC extends Cache {
- /**
- * entries in APC gets namespaced to prevent collisions between owncloud instances and users
- */
- protected function getNameSpace() {
- return $this->prefix;
- }
-
public function get($key) {
- $result = apc_fetch($this->getNamespace() . $key, $success);
+ $result = apc_fetch($this->getPrefix() . $key, $success);
if (!$success) {
return null;
}
@@ -25,31 +18,29 @@ class APC extends Cache {
}
public function set($key, $value, $ttl = 0) {
- return apc_store($this->getNamespace() . $key, $value, $ttl);
+ return apc_store($this->getPrefix() . $key, $value, $ttl);
}
public function hasKey($key) {
- return apc_exists($this->getNamespace() . $key);
+ return apc_exists($this->getPrefix() . $key);
}
public function remove($key) {
- return apc_delete($this->getNamespace() . $key);
+ return apc_delete($this->getPrefix() . $key);
}
public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $cache = apc_cache_info('user');
- foreach ($cache['cache_list'] as $entry) {
- if (strpos($entry['info'], $ns) === 0) {
- apc_delete($entry['info']);
- }
- }
- return true;
+ $ns = $this->getPrefix() . $prefix;
+ $ns = preg_quote($ns, '/');
+ $iter = new \APCIterator('user', '/^' . $ns . '/');
+ return apc_delete($iter);
}
static public function isAvailable() {
if (!extension_loaded('apc')) {
return false;
+ } elseif (!ini_get('apc.enabled')) {
+ return false;
} elseif (!ini_get('apc.enable_cli') && \OC::$CLI) {
return false;
} else {
diff --git a/lib/private/memcache/apcu.php b/lib/private/memcache/apcu.php
index dac0f5f208a..7f780f32718 100644
--- a/lib/private/memcache/apcu.php
+++ b/lib/private/memcache/apcu.php
@@ -9,13 +9,6 @@
namespace OC\Memcache;
class APCu extends APC {
- public function clear($prefix = '') {
- $ns = $this->getNamespace() . $prefix;
- $ns = preg_quote($ns, '/');
- $iter = new \APCIterator('user', '/^'.$ns.'/');
- return apc_delete($iter);
- }
-
static public function isAvailable() {
if (!extension_loaded('apcu')) {
return false;
diff --git a/lib/private/memcache/cache.php b/lib/private/memcache/cache.php
index 0ad1cc7ec03..03671b3f240 100644
--- a/lib/private/memcache/cache.php
+++ b/lib/private/memcache/cache.php
@@ -18,7 +18,7 @@ abstract class Cache implements \ArrayAccess {
* @param string $prefix
*/
public function __construct($prefix = '') {
- $this->prefix = \OC_Util::getInstanceId() . '/' . $prefix;
+ $this->prefix = $prefix;
}
public function getPrefix() {
diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php
index fde7d947567..334cf9a1f0e 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -8,7 +8,21 @@
namespace OC\Memcache;
-class Factory {
+use \OCP\ICacheFactory;
+
+class Factory implements ICacheFactory {
+ /**
+ * @var string $globalPrefix
+ */
+ private $globalPrefix;
+
+ /**
+ * @param string $globalPrefix
+ */
+ public function __construct($globalPrefix) {
+ $this->globalPrefix = $globalPrefix;
+ }
+
/**
* get a cache instance, will return null if no backend is available
*
@@ -16,6 +30,7 @@ class Factory {
* @return \OC\Memcache\Cache
*/
function create($prefix = '') {
+ $prefix = $this->globalPrefix . '/' . $prefix;
if (XCache::isAvailable()) {
return new XCache($prefix);
} elseif (APCu::isAvailable()) {
diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php
index 978e6c2eff1..075828eebad 100644
--- a/lib/private/memcache/memcached.php
+++ b/lib/private/memcache/memcached.php
@@ -18,8 +18,16 @@ class Memcached extends Cache {
parent::__construct($prefix);
if (is_null(self::$cache)) {
self::$cache = new \Memcached();
- list($host, $port) = \OC_Config::getValue('memcached_server', array('localhost', 11211));
- self::$cache->addServer($host, $port);
+ $servers = \OC_Config::getValue('memcached_servers');
+ if (!$servers) {
+ $server = \OC_Config::getValue('memcached_server');
+ if ($server) {
+ $servers = array($server);
+ } else {
+ $servers = array(array('localhost', 11211));
+ }
+ }
+ self::$cache->addServers($servers);
}
}
diff --git a/lib/private/mimetypes.list.php b/lib/private/mimetypes.list.php
index 740982910e0..40fb1d2d97d 100644
--- a/lib/private/mimetypes.list.php
+++ b/lib/private/mimetypes.list.php
@@ -21,94 +21,91 @@
*/
/**
- * list of mimetypes by extension
+ * Array mapping file extensions to mimetypes (in alphabetical order).
*/
-
return array(
+ 'accdb'=>'application/msaccess',
+ 'ai' => 'application/illustrator',
+ 'avi'=>'video/x-msvideo',
+ 'bash' => 'text/x-shellscript',
+ 'blend'=>'application/x-blender',
+ 'cc' => 'text/x-c',
+ 'cdr' => 'application/coreldraw',
+ 'cpp' => 'text/x-c++src',
'css'=>'text/css',
+ 'c' => 'text/x-c',
+ 'c++' => 'text/x-c++src',
+ 'doc'=>'application/msword',
+ 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ 'dot'=>'application/msword',
+ 'dotx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
+ 'dv'=>'video/dv',
+ 'epub' => 'application/epub+zip',
+ 'exe'=>'application/x-ms-dos-executable',
'flac'=>'audio/flac',
'gif'=>'image/gif',
- 'gzip'=>'application/x-gzip',
'gz'=>'application/x-gzip',
+ 'gzip'=>'application/x-gzip',
'html'=>'text/html',
'htm'=>'text/html',
- 'ics'=>'text/calendar',
'ical'=>'text/calendar',
+ 'ics'=>'text/calendar',
+ 'impress' => 'text/impress',
'jpeg'=>'image/jpeg',
'jpg'=>'image/jpeg',
'js'=>'application/javascript',
+ 'keynote'=>'application/x-iwork-keynote-sffkey',
+ 'kra'=>'application/x-krita',
+ 'm2t'=>'video/mp2t',
+ 'm4v'=>'video/mp4',
+ 'markdown' => 'text/markdown',
+ 'mdown' => 'text/markdown',
+ 'md' => 'text/markdown',
+ 'mdb'=>'application/msaccess',
+ 'mdwn' => 'text/markdown',
+ 'mobi' => 'application/x-mobipocket-ebook',
+ 'mov'=>'video/quicktime',
+ 'mp3'=>'audio/mpeg',
+ 'mp4'=>'video/mp4',
+ 'mpeg'=>'video/mpeg',
+ 'mpg'=>'video/mpeg',
+ 'msi'=>'application/x-msi',
+ 'numbers'=>'application/x-iwork-numbers-sffnumbers',
+ 'odg'=>'application/vnd.oasis.opendocument.graphics',
+ 'odp'=>'application/vnd.oasis.opendocument.presentation',
+ 'ods'=>'application/vnd.oasis.opendocument.spreadsheet',
+ 'odt'=>'application/vnd.oasis.opendocument.text',
'oga'=>'audio/ogg',
'ogg'=>'audio/ogg',
'ogv'=>'video/ogg',
+ 'pages'=>'application/x-iwork-pages-sffpages',
'pdf'=>'application/pdf',
+ 'php'=>'application/x-php',
+ 'pl'=>'application/x-pearl',
'png'=>'image/png',
+ 'ppt'=>'application/mspowerpoint',
+ 'pptx'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ 'psd'=>'application/x-photoshop',
+ 'py'=>'text/x-script.python',
+ 'reveal' => 'text/reveal',
+ 'sgf' => 'application/sgf',
+ 'sh-lib' => 'text/x-shellscript',
+ 'sh' => 'text/x-shellscript',
'svg'=>'image/svg+xml',
'tar'=>'application/x-tar',
- 'tgz'=>'application/x-compressed',
'tar.gz'=>'application/x-compressed',
- 'tif'=>'image/tiff',
+ 'tgz'=>'application/x-compressed',
'tiff'=>'image/tiff',
+ 'tif'=>'image/tiff',
'txt'=>'text/plain',
- 'zip'=>'application/zip',
+ 'vcard' => 'text/vcard',
+ 'vcf' => 'text/vcard',
'wav'=>'audio/wav',
- 'odt'=>'application/vnd.oasis.opendocument.text',
- 'ods'=>'application/vnd.oasis.opendocument.spreadsheet',
- 'odg'=>'application/vnd.oasis.opendocument.graphics',
- 'odp'=>'application/vnd.oasis.opendocument.presentation',
- 'pages'=>'application/x-iwork-pages-sffpages',
- 'numbers'=>'application/x-iwork-numbers-sffnumbers',
- 'keynote'=>'application/x-iwork-keynote-sffkey',
- 'kra'=>'application/x-krita',
- 'mp3'=>'audio/mpeg',
- 'doc'=>'application/msword',
- 'docx'=>'application/msword',
- 'xls'=>'application/msexcel',
- 'xlsx'=>'application/msexcel',
- 'php'=>'application/x-php',
- 'exe'=>'application/x-ms-dos-executable',
- 'pl'=>'application/x-pearl',
- 'py'=>'application/x-python',
- 'blend'=>'application/x-blender',
- 'xcf'=>'application/x-gimp',
- 'psd'=>'application/x-photoshop',
- 'xml'=>'application/xml',
- 'avi'=>'video/x-msvideo',
- 'dv'=>'video/dv',
- 'm2t'=>'video/mp2t',
- 'mp4'=>'video/mp4',
- 'm4v'=>'video/mp4',
- 'mpg'=>'video/mpeg',
- 'mpeg'=>'video/mpeg',
- 'mov'=>'video/quicktime',
'webm'=>'video/webm',
'wmv'=>'video/x-ms-asf',
- 'py'=>'text/x-script.python',
- 'vcf' => 'text/vcard',
- 'vcard' => 'text/vcard',
- 'doc'=>'application/msword',
- 'docx'=>'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ 'xcf'=>'application/x-gimp',
'xls'=>'application/msexcel',
'xlsx'=>'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'ppt'=>'application/mspowerpoint',
- 'pptx'=>'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- 'sgf' => 'application/sgf',
- 'cdr' => 'application/coreldraw',
- 'impress' => 'text/impress',
- 'ai' => 'application/illustrator',
- 'epub' => 'application/epub+zip',
- 'mobi' => 'application/x-mobipocket-ebook',
- 'exe' => 'application',
- 'msi' => 'application',
- 'md' => 'text/markdown',
- 'markdown' => 'text/markdown',
- 'mdown' => 'text/markdown',
- 'mdwn' => 'text/markdown',
- 'reveal' => 'text/reveal',
- 'c' => 'text/x-c',
- 'cc' => 'text/x-c',
- 'cpp' => 'text/x-c++src',
- 'c++' => 'text/x-c++src',
- 'sh' => 'text/x-shellscript',
- 'bash' => 'text/x-shellscript',
- 'sh-lib' => 'text/x-shellscript',
+ 'xml'=>'application/xml',
+ 'zip'=>'application/zip',
);
diff --git a/lib/private/ocs/result.php b/lib/private/ocs/result.php
index 84f06fa01c7..9f14e8da7e8 100644
--- a/lib/private/ocs/result.php
+++ b/lib/private/ocs/result.php
@@ -29,7 +29,13 @@ class OC_OCS_Result{
* @param $data mixed the data to return
*/
public function __construct($data=null, $code=100, $message=null) {
- $this->data = $data;
+ if ($data === null) {
+ $this->data = array();
+ } elseif (!is_array($data)) {
+ $this->data = array($this->data);
+ } else {
+ $this->data = $data;
+ }
$this->statusCode = $code;
$this->message = $message;
}
@@ -49,7 +55,7 @@ class OC_OCS_Result{
public function setItemsPerPage(int $items) {
$this->perPage = $items;
}
-
+
/**
* get the status code
* @return int
@@ -57,7 +63,7 @@ class OC_OCS_Result{
public function getStatusCode() {
return $this->statusCode;
}
-
+
/**
* get the meta data for the result
* @return array
@@ -76,15 +82,15 @@ class OC_OCS_Result{
return $meta;
}
-
+
/**
* get the result data
- * @return array|string|int
+ * @return array
*/
public function getData() {
return $this->data;
}
-
+
/**
* return bool if the method succedded
* @return bool
diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php
index ac771deb413..71cd3bae057 100644
--- a/lib/private/preview/movies.php
+++ b/lib/private/preview/movies.php
@@ -18,7 +18,7 @@ function findBinaryPath($program) {
// movie preview is currently not supported on Windows
if (!\OC_Util::runningOnWindows()) {
- $isExecEnabled = !in_array('exec', explode(', ', ini_get('disable_functions')));
+ $isExecEnabled = \OC_Helper::is_function_enabled('exec');
$ffmpegBinary = null;
$avconvBinary = null;
diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php
index 318ab51f851..884b6e7dc9b 100644
--- a/lib/private/preview/office.php
+++ b/lib/private/preview/office.php
@@ -6,8 +6,8 @@
* See the COPYING-README file.
*/
//both, libreoffice backend and php fallback, need imagick
-if (extension_loaded('imagick')) {
- $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions')));
+if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) {
+ $isShellExecEnabled = \OC_Helper::is_function_enabled('shell_exec');
// LibreOffice preview is currently not supported on Windows
if (!\OC_Util::runningOnWindows()) {
diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php
index cc974b68818..572b8788ac9 100644
--- a/lib/private/preview/pdf.php
+++ b/lib/private/preview/pdf.php
@@ -7,7 +7,7 @@
*/
namespace OC\Preview;
-if (extension_loaded('imagick')) {
+if (extension_loaded('imagick') && count(\Imagick::queryFormats("PDF")) === 1) {
class PDF extends Provider {
diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php
index b49e51720fa..07a37e8f8c1 100644
--- a/lib/private/preview/svg.php
+++ b/lib/private/preview/svg.php
@@ -7,7 +7,7 @@
*/
namespace OC\Preview;
-if (extension_loaded('imagick')) {
+if (extension_loaded('imagick') && count(\Imagick::queryFormats("SVG")) === 1) {
class SVG extends Provider {
diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php
index 4747f9e25ed..8145c826149 100644
--- a/lib/private/preview/unknown.php
+++ b/lib/private/preview/unknown.php
@@ -22,7 +22,7 @@ class Unknown extends Provider {
$svgPath = substr_replace($path, 'svg', -3);
- if (extension_loaded('imagick') && file_exists($svgPath)) {
+ if (extension_loaded('imagick') && file_exists($svgPath) && count(\Imagick::queryFormats("SVG")) === 1) {
// http://www.php.net/manual/de/imagick.setresolution.php#85284
$svg = new \Imagick();
diff --git a/lib/private/request.php b/lib/private/request.php
index b2afda35922..2c5b907846e 100755
--- a/lib/private/request.php
+++ b/lib/private/request.php
@@ -7,6 +7,12 @@
*/
class OC_Request {
+
+ const USER_AGENT_IE = '/MSIE/';
+ // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent
+ const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#';
+ const USER_AGENT_FREEBOX = '#^Mozilla/5\.0$#';
+
/**
* @brief Check overwrite condition
* @param string $type
@@ -210,4 +216,22 @@ class OC_Request {
return false;
}
}
+
+ /**
+ * Checks whether the user agent matches a given regex
+ * @param string|array $agent agent name or array of agent names
+ * @return boolean true if at least one of the given agent matches,
+ * false otherwise
+ */
+ static public function isUserAgent($agent) {
+ if (!is_array($agent)) {
+ $agent = array($agent);
+ }
+ foreach ($agent as $regex) {
+ if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/lib/private/response.php b/lib/private/response.php
index 674176d078b..52dbb9d90f8 100644
--- a/lib/private/response.php
+++ b/lib/private/response.php
@@ -148,6 +148,24 @@ class OC_Response {
}
/**
+ * Sets the content disposition header (with possible workarounds)
+ * @param string $filename file name
+ * @param string $type disposition type, either 'attachment' or 'inline'
+ */
+ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) {
+ if (OC_Request::isUserAgent(array(
+ OC_Request::USER_AGENT_IE,
+ OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME,
+ OC_Request::USER_AGENT_FREEBOX
+ ))) {
+ header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' );
+ } else {
+ header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename )
+ . '; filename="' . rawurlencode( $filename ) . '"' );
+ }
+ }
+
+ /**
* @brief Send file as response, checking and setting caching headers
* @param $filepath of file to send
*/
diff --git a/lib/private/server.php b/lib/private/server.php
index bee70dec2df..c9e593ec2ed 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -128,7 +128,9 @@ class Server extends SimpleContainer implements IServerContainer {
return new \OC\L10N\Factory();
});
$this->registerService('URLGenerator', function($c) {
- return new \OC\URLGenerator();
+ /** @var $c SimpleContainer */
+ $config = $c->query('AllConfig');
+ return new \OC\URLGenerator($config);
});
$this->registerService('AppHelper', function($c) {
return new \OC\AppHelper();
@@ -136,6 +138,10 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('UserCache', function($c) {
return new UserCache();
});
+ $this->registerService('MemCacheFactory', function ($c) {
+ $instanceId = \OC_Util::getInstanceId();
+ return new \OC\Memcache\Factory($instanceId);
+ });
$this->registerService('ActivityManager', function($c) {
return new ActivityManager();
});
@@ -257,7 +263,7 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
- * @return \OC\Config
+ * @return \OCP\IConfig
*/
function getConfig() {
return $this->query('AllConfig');
@@ -296,6 +302,15 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
+ * Returns an \OCP\CacheFactory instance
+ *
+ * @return \OCP\CacheFactory
+ */
+ function getMemCacheFactory() {
+ return $this->query('MemCacheFactory');
+ }
+
+ /**
* Returns the current session
*
* @return \OCP\ISession
diff --git a/lib/private/setup.php b/lib/private/setup.php
index b5c530a091f..5232398d1d7 100644
--- a/lib/private/setup.php
+++ b/lib/private/setup.php
@@ -159,6 +159,9 @@ class OC_Setup {
$content.= "</IfModule>\n";
$content.= "AddDefaultCharset utf-8\n";
$content.= "Options -Indexes\n";
+ $content.= "<IfModule pagespeed_module>\n";
+ $content.= "ModPagespeed Off\n";
+ $content.= "</IfModule>\n";
@file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it
self::protectDataDirectory();
diff --git a/lib/private/setup/mysql.php b/lib/private/setup/mysql.php
index d97b6d2602f..b2c28173b1c 100644
--- a/lib/private/setup/mysql.php
+++ b/lib/private/setup/mysql.php
@@ -3,13 +3,13 @@
namespace OC\Setup;
class MySQL extends AbstractDatabase {
- public $dbprettyname = 'MySQL';
+ public $dbprettyname = 'MySQL/MariaDB';
public function setupDatabase($username) {
//check if the database user has admin right
$connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
if(!$connection) {
- throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'),
+ throw new \DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'),
$this->trans->t('You need to enter either an existing account or the administrator.'));
}
$oldUser=\OC_Config::getValue('dbuser', false);
@@ -82,14 +82,14 @@ class MySQL extends AbstractDatabase {
$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
- throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'localhost' exists already.", array($name)),
- $this->trans->t("Drop this user from MySQL", array($name)));
+ throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'localhost' exists already.", array($name)),
+ $this->trans->t("Drop this user from MySQL/MariaDB", array($name)));
}
$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
- throw new \DatabaseSetupException($this->trans->t("MySQL user '%s'@'%%' already exists", array($name)),
- $this->trans->t("Drop this user from MySQL."));
+ throw new \DatabaseSetupException($this->trans->t("MySQL/MariaDB user '%s'@'%%' already exists", array($name)),
+ $this->trans->t("Drop this user from MySQL/MariaDB."));
}
}
}
diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php
index 7795011fd06..4e3c1109000 100644
--- a/lib/private/urlgenerator.php
+++ b/lib/private/urlgenerator.php
@@ -15,6 +15,19 @@ use RuntimeException;
* Class to generate URLs
*/
class URLGenerator implements IURLGenerator {
+
+ /**
+ * @var \OCP\IConfig
+ */
+ private $config;
+
+ /**
+ * @param \OCP\IConfig $config
+ */
+ public function __construct($config) {
+ $this->config = $config;
+ }
+
/**
* @brief Creates an url using a defined route
* @param $route
@@ -41,12 +54,18 @@ class URLGenerator implements IURLGenerator {
* Returns a url to the given app and file.
*/
public function linkTo( $app, $file, $args = array() ) {
+ $frontControllerActive=($this->config->getSystemValue('front_controller_active', 'false') == 'true');
+
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;
+ if ($frontControllerActive) {
+ $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
+ }
$urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
} else {
$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
@@ -58,7 +77,11 @@ class URLGenerator implements IURLGenerator {
if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
} else {
- $urlLinkTo = \OC::$WEBROOT . '/' . $file;
+ if ($frontControllerActive && $file === 'index.php') {
+ $urlLinkTo = \OC::$WEBROOT;
+ } else {
+ $urlLinkTo = \OC::$WEBROOT . '/' . $file;
+ }
}
}
diff --git a/lib/private/user.php b/lib/private/user.php
index e0d6b9f3f51..2519200d0f0 100644
--- a/lib/private/user.php
+++ b/lib/private/user.php
@@ -205,6 +205,9 @@ class OC_User {
// Delete user files in /data/
OC_Helper::rmdirr(\OC_User::getHome($uid));
+ // Delete the users entry in the storage table
+ \OC\Files\Cache\Storage::remove('home::' . $uid);
+
// Remove it from the Cache
self::getManager()->delete($uid);
}
@@ -246,6 +249,8 @@ class OC_User {
session_regenerate_id(true);
self::setUserId($uid);
self::setDisplayName($uid);
+ self::getUserSession()->setLoginName($uid);
+
OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>'' ));
return true;
}
diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php
index 02c93d13bdf..f4e5618e04a 100644
--- a/lib/private/user/backend.php
+++ b/lib/private/user/backend.php
@@ -31,13 +31,15 @@ define('OC_USER_BACKEND_NOT_IMPLEMENTED', -501);
/**
* actions that user backends can define
*/
-define('OC_USER_BACKEND_CREATE_USER', 0x0000001);
-define('OC_USER_BACKEND_SET_PASSWORD', 0x0000010);
-define('OC_USER_BACKEND_CHECK_PASSWORD', 0x0000100);
-define('OC_USER_BACKEND_GET_HOME', 0x0001000);
-define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x0010000);
-define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x0100000);
-define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x1000000);
+define('OC_USER_BACKEND_CREATE_USER', 0x00000001);
+define('OC_USER_BACKEND_SET_PASSWORD', 0x00000010);
+define('OC_USER_BACKEND_CHECK_PASSWORD', 0x00000100);
+define('OC_USER_BACKEND_GET_HOME', 0x00001000);
+define('OC_USER_BACKEND_GET_DISPLAYNAME', 0x00010000);
+define('OC_USER_BACKEND_SET_DISPLAYNAME', 0x00100000);
+define('OC_USER_BACKEND_PROVIDE_AVATAR', 0x01000000);
+define('OC_USER_BACKEND_COUNT_USERS', 0x10000000);
+//more actions cannot be defined without breaking 32bit platforms!
/**
* Abstract base class for user management. Provides methods for querying backend
@@ -55,6 +57,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
OC_USER_BACKEND_GET_DISPLAYNAME => 'getDisplayName',
OC_USER_BACKEND_SET_DISPLAYNAME => 'setDisplayName',
OC_USER_BACKEND_PROVIDE_AVATAR => 'canChangeAvatar',
+ OC_USER_BACKEND_COUNT_USERS => 'countUsers',
);
/**
diff --git a/lib/private/user/database.php b/lib/private/user/database.php
index c99db3b27ca..1a63755b980 100644
--- a/lib/private/user/database.php
+++ b/lib/private/user/database.php
@@ -253,4 +253,19 @@ class OC_User_Database extends OC_User_Backend {
return true;
}
+ /**
+ * counts the users in the database
+ *
+ * @return int | bool
+ */
+ public function countUsers() {
+ $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
+ $result = $query->execute();
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
+ return $result->fetchOne();
+ }
+
}
diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php
index 52be7edfa75..fc15a630cf3 100644
--- a/lib/private/user/dummy.php
+++ b/lib/private/user/dummy.php
@@ -123,4 +123,13 @@ class OC_User_Dummy extends OC_User_Backend {
public function hasUserListings() {
return true;
}
+
+ /**
+ * counts the users in the database
+ *
+ * @return int | bool
+ */
+ public function countUsers() {
+ return 0;
+ }
}
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index cf83a75ba25..90970ef9963 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -270,4 +270,26 @@ class Manager extends PublicEmitter {
}
return false;
}
+
+ /**
+ * returns how many users per backend exist (if supported by backend)
+ *
+ * @return array with backend class as key and count number as value
+ */
+ public function countUsers() {
+ $userCountStatistics = array();
+ foreach ($this->backends as $backend) {
+ if ($backend->implementsActions(\OC_USER_BACKEND_COUNT_USERS)) {
+ $backendusers = $backend->countUsers();
+ if($backendusers !== false) {
+ if(isset($userCountStatistics[get_class($backend)])) {
+ $userCountStatistics[get_class($backend)] += $backendusers;
+ } else {
+ $userCountStatistics[get_class($backend)] = $backendusers;
+ }
+ }
+ }
+ }
+ return $userCountStatistics;
+ }
}
diff --git a/lib/private/user/session.php b/lib/private/user/session.php
index c2885d00413..1e299416fb3 100644
--- a/lib/private/user/session.php
+++ b/lib/private/user/session.php
@@ -115,13 +115,13 @@ class Session implements Emitter, \OCP\IUserSession {
/**
* set the login name
*
- * @param string login name for the logged in user
+ * @param string $loginName for the logged in user
*/
- public function setLoginname($loginname) {
- if (is_null($loginname)) {
+ public function setLoginName($loginName) {
+ if (is_null($loginName)) {
$this->session->remove('loginname');
} else {
- $this->session->set('loginname', $loginname);
+ $this->session->set('loginname', $loginName);
}
}
@@ -130,7 +130,7 @@ class Session implements Emitter, \OCP\IUserSession {
*
* @return string
*/
- public function getLoginname() {
+ public function getLoginName() {
if ($this->activeUser) {
return $this->session->get('loginname');
} else {
@@ -158,7 +158,7 @@ class Session implements Emitter, \OCP\IUserSession {
if (!is_null($user)) {
if ($user->isEnabled()) {
$this->setUser($user);
- $this->setLoginname($uid);
+ $this->setLoginName($uid);
$this->manager->emit('\OC\User', 'postLogin', array($user, $password));
return true;
} else {
@@ -176,7 +176,7 @@ class Session implements Emitter, \OCP\IUserSession {
public function logout() {
$this->manager->emit('\OC\User', 'logout');
$this->setUser(null);
- $this->setLoginname(null);
+ $this->setLoginName(null);
$this->unsetMagicInCookie();
}
diff --git a/lib/private/util.php b/lib/private/util.php
index c0e618cc863..0585749d615 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -51,6 +51,10 @@ class OC_Util {
self::$rootMounted = true;
}
+ if ($user != '' && !OCP\User::userExists($user)) {
+ return false;
+ }
+
//if we aren't logged in, there is no use to set up the filesystem
if( $user != "" ) {
\OC\Files\Filesystem::addStorageWrapper(function($mountPoint, $storage){
@@ -312,7 +316,7 @@ class OC_Util {
.'" target="_blank">giving the webserver write access to the root directory</a>.';
// Check if config folder is writable.
- if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) {
+ if(!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) {
$errors[] = array(
'error' => "Can't write into config directory",
'hint' => 'This can usually be fixed by '
@@ -580,7 +584,7 @@ class OC_Util {
// Check if we are a user
if( !OC_User::isLoggedIn()) {
header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php',
- array('redirectUrl' => OC_Request::requestUri())
+ array('redirect_url' => OC_Request::requestUri())
));
exit();
}
@@ -784,8 +788,12 @@ class OC_Util {
}
$fp = @fopen($testFile, 'w');
- @fwrite($fp, $testContent);
- @fclose($fp);
+ if (!$fp) {
+ throw new OC\HintException('Can\'t create test file to check for working .htaccess file.',
+ 'Make sure it is possible for the webserver to write to '.$testFile);
+ }
+ fwrite($fp, $testContent);
+ fclose($fp);
// accessing the file via http
$url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$fileName);
@@ -892,6 +900,11 @@ class OC_Util {
return false;
}
+ // in case the connection is via proxy return true to avoid connecting to owncloud.org
+ if(OC_Config::getValue('proxy', '') != '') {
+ return true;
+ }
+
// try to connect to owncloud.org to see if http connections to the internet are possible.
$connected = @fsockopen("www.owncloud.org", 80);
if ($connected) {