diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/api.php | 2 | ||||
-rw-r--r-- | lib/private/app.php | 2 | ||||
-rw-r--r-- | lib/private/appframework/http/dispatcher.php | 2 | ||||
-rw-r--r-- | lib/private/appframework/middleware/security/securitymiddleware.php | 2 | ||||
-rw-r--r-- | lib/private/connector/sabre/objecttree.php | 10 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 2 | ||||
-rw-r--r-- | lib/private/files/mount/manager.php | 4 | ||||
-rw-r--r-- | lib/private/files/storage/dav.php | 44 | ||||
-rw-r--r-- | lib/private/group/database.php | 12 | ||||
-rw-r--r-- | lib/private/group/dummy.php | 33 | ||||
-rw-r--r-- | lib/private/user/database.php | 4 | ||||
-rw-r--r-- | lib/private/user/dummy.php | 11 | ||||
-rwxr-xr-x | lib/private/util.php | 32 |
13 files changed, 123 insertions, 37 deletions
diff --git a/lib/private/api.php b/lib/private/api.php index 74887690952..e9c144564f0 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -301,7 +301,7 @@ class OC_API { * @param OC_OCS_Result $result * @param string $format the format xml|json */ - private static function respond($result, $format='xml') { + public static function respond($result, $format='xml') { // Send 401 headers if unauthorised if($result->getStatusCode() === self::RESPOND_UNAUTHORISED) { header('WWW-Authenticate: Basic realm="Authorisation Required"'); diff --git a/lib/private/app.php b/lib/private/app.php index 9fb0ec2e34f..0ca2ca36bd2 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -163,7 +163,7 @@ class OC_App { /** * get all enabled apps */ - private static $enabledAppsCache = array(); + protected static $enabledAppsCache = array(); public static function getEnabledApps($forceRefresh = false) { if (!OC_Config::getValue('installed', false)) { diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php index fa8d3c47a8b..7f2717951a5 100644 --- a/lib/private/appframework/http/dispatcher.php +++ b/lib/private/appframework/http/dispatcher.php @@ -145,7 +145,7 @@ class Dispatcher { ) { $value = false; - } elseif(in_array($type, $types)) { + } elseif($value !== null && in_array($type, $types)) { settype($value, $type); } diff --git a/lib/private/appframework/middleware/security/securitymiddleware.php b/lib/private/appframework/middleware/security/securitymiddleware.php index 5b56210024d..948a43ce0f4 100644 --- a/lib/private/appframework/middleware/security/securitymiddleware.php +++ b/lib/private/appframework/middleware/security/securitymiddleware.php @@ -143,6 +143,8 @@ class SecurityMiddleware extends Middleware { // TODO: replace with link to route $url = $this->urlGenerator->getAbsoluteURL('index.php'); + // add redirect URL to redirect to the previous page after login + $url .= '?redirect_url=' . urlencode($this->request->server['REQUEST_URI']); $response = new RedirectResponse($url); $this->logger->debug($exception->getMessage()); } diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index 54596db3c47..d7a96cfc88e 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -11,6 +11,8 @@ namespace OC\Connector\Sabre; use OC\Files\FileInfo; use OC\Files\Filesystem; use OC\Files\Mount\MoveableMount; +use OCP\Files\StorageInvalidException; +use OCP\Files\StorageNotAvailableException; class ObjectTree extends \Sabre\DAV\ObjectTree { @@ -83,7 +85,13 @@ class ObjectTree extends \Sabre\DAV\ObjectTree { } } else { // read from cache - $info = $this->fileView->getFileInfo($path); + try { + $info = $this->fileView->getFileInfo($path); + } catch (StorageNotAvailableException $e) { + throw new \Sabre\DAV\Exception\ServiceUnavailable('Storage not available'); + } catch (StorageInvalidException $e){ + throw new \Sabre\DAV\Exception\NotFound('Storage ' . $path . ' is invalid'); + } } if (!$info) { diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index ee3d53b576a..a6d9e30cf80 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -58,7 +58,7 @@ class MDB2SchemaManager { /** * @return \OC\DB\Migrator */ - protected function getMigrator() { + public function getMigrator() { $platform = $this->conn->getDatabasePlatform(); if ($platform instanceof SqlitePlatform) { return new SQLiteMigrator($this->conn); diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php index 45a9f339fba..e5180cfe173 100644 --- a/lib/private/files/mount/manager.php +++ b/lib/private/files/mount/manager.php @@ -27,6 +27,10 @@ class Manager { * @param string $mountPoint */ public function removeMount($mountPoint) { + $mountPoint = Filesystem::normalizePath($mountPoint); + if (strlen($mountPoint) > 1) { + $mountPoint .= '/'; + } unset($this->mounts[$mountPoint]); } diff --git a/lib/private/files/storage/dav.php b/lib/private/files/storage/dav.php index 8b97f750204..726688fe444 100644 --- a/lib/private/files/storage/dav.php +++ b/lib/private/files/storage/dav.php @@ -8,6 +8,9 @@ namespace OC\Files\Storage; +use OCP\Files\StorageNotAvailableException; +use Sabre\DAV\Exception; + class DAV extends \OC\Files\Storage\Common { protected $password; protected $user; @@ -463,29 +466,36 @@ class DAV extends \OC\Files\Storage\Common { * * @param string $path * @param int $time + * @throws \OCP\Files\StorageNotAvailableException * @return bool */ public function hasUpdated($path, $time) { $this->init(); - $response = $this->client->propfind($this->encodePath($path), array( - '{DAV:}getlastmodified', - '{DAV:}getetag', - '{http://owncloud.org/ns}permissions' - )); - if (isset($response['{DAV:}getetag'])) { - $cachedData = $this->getCache()->get($path); - $etag = trim($response['{DAV:}getetag'], '"'); - if ($cachedData['etag'] !== $etag) { - return true; - } else if (isset($response['{http://owncloud.org/ns}permissions'])) { - $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); - return $permissions !== $cachedData['permissions']; + try { + $response = $this->client->propfind($this->encodePath($path), array( + '{DAV:}getlastmodified', + '{DAV:}getetag', + '{http://owncloud.org/ns}permissions' + )); + if (isset($response['{DAV:}getetag'])) { + $cachedData = $this->getCache()->get($path); + $etag = trim($response['{DAV:}getetag'], '"'); + if ($cachedData['etag'] !== $etag) { + return true; + } else if (isset($response['{http://owncloud.org/ns}permissions'])) { + $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']); + return $permissions !== $cachedData['permissions']; + } else { + return false; + } } else { - return false; + $remoteMtime = strtotime($response['{DAV:}getlastmodified']); + return $remoteMtime > $time; } - } else { - $remoteMtime = strtotime($response['{DAV:}getlastmodified']); - return $remoteMtime > $time; + } catch (Exception\NotFound $e) { + return false; + } catch (Exception $e) { + throw new StorageNotAvailableException(); } } } diff --git a/lib/private/group/database.php b/lib/private/group/database.php index baaf2cf2739..b7148f38fe3 100644 --- a/lib/private/group/database.php +++ b/lib/private/group/database.php @@ -169,7 +169,7 @@ class OC_Group_Database extends OC_Group_Backend { */ public function getGroups($search = '', $limit = null, $offset = null) { $stmt = OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups` WHERE `gid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($search.'%')); + $result = $stmt->execute(array('%' . $search . '%')); $groups = array(); while ($row = $result->fetchRow()) { $groups[] = $row['gid']; @@ -203,7 +203,7 @@ class OC_Group_Database extends OC_Group_Backend { $stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?', $limit, $offset); - $result = $stmt->execute(array($gid, $search.'%')); + $result = $stmt->execute(array($gid, '%'.$search.'%')); $users = array(); while ($row = $result->fetchRow()) { $users[] = $row['uid']; @@ -220,8 +220,12 @@ class OC_Group_Database extends OC_Group_Backend { */ public function countUsersInGroup($gid, $search = '') { $stmt = OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?'); - $result = $stmt->execute(array($gid, $search.'%')); - return $result->fetchOne(); + $result = $stmt->execute(array($gid, '%' . $search . '%')); + $count = $result->fetchOne(); + if($count !== false) { + $count = intval($count); + } + return $count; } } diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php index e48c6a0e266..4af18b267bc 100644 --- a/lib/private/group/dummy.php +++ b/lib/private/group/dummy.php @@ -143,7 +143,16 @@ class OC_Group_Dummy extends OC_Group_Backend { * @return array an array of group names */ public function getGroups($search = '', $limit = -1, $offset = 0) { - return array_keys($this->groups); + if(empty($search)) { + return array_keys($this->groups); + } + $result = array(); + foreach(array_keys($this->groups) as $group) { + if(stripos($group, $search) !== false) { + $result[] = $group; + } + } + return $result; } /** @@ -156,7 +165,16 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { if(isset($this->groups[$gid])) { - return $this->groups[$gid]; + if(empty($search)) { + return $this->groups[$gid]; + } + $result = array(); + foreach($this->groups[$gid] as $user) { + if(stripos($user, $search) !== false) { + $result[] = $user; + } + } + return $result; }else{ return array(); } @@ -172,7 +190,16 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function countUsersInGroup($gid, $search = '', $limit = -1, $offset = 0) { if(isset($this->groups[$gid])) { - return count($this->groups[$gid]); + if(empty($search)) { + return count($this->groups[$gid]); + } + $count = 0; + foreach($this->groups[$gid] as $user) { + if(stripos($user, $search) !== false) { + $count++; + } + } + return $count; } } diff --git a/lib/private/user/database.php b/lib/private/user/database.php index d9263f6b5de..e9844f0f79c 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -158,7 +158,7 @@ class OC_User_Database extends OC_User_Backend { $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`' . ' WHERE LOWER(`displayname`) LIKE LOWER(?) OR ' . 'LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); - $result = $query->execute(array($search . '%', $search . '%')); + $result = $query->execute(array('%' . $search . '%', '%' . $search . '%')); $users = array(); while ($row = $result->fetchRow()) { $displayNames[$row['uid']] = $row['displayname']; @@ -232,7 +232,7 @@ class OC_User_Database extends OC_User_Backend { */ public function getUsers($search = '', $limit = null, $offset = null) { $query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset); - $result = $query->execute(array($search . '%')); + $result = $query->execute(array('%' . $search . '%')); $users = array(); while ($row = $result->fetchRow()) { $users[] = $row['uid']; diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php index 776168048f6..dbcbb2a46f7 100644 --- a/lib/private/user/dummy.php +++ b/lib/private/user/dummy.php @@ -105,7 +105,16 @@ class OC_User_Dummy extends OC_User_Backend { * Get a list of all users. */ public function getUsers($search = '', $limit = null, $offset = null) { - return array_keys($this->users); + if(empty($search)) { + return array_keys($this->users); + } + $result = array(); + foreach(array_keys($this->users) as $user) { + if(stripos($user, $search) !== false) { + $result[] = $user; + } + } + return $result; } /** diff --git a/lib/private/util.php b/lib/private/util.php index 7836489832d..897795f7535 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -815,10 +815,13 @@ class OC_Util { } /** - * Redirect to the user default page - * @return void + * Returns the URL of the default page + * based on the system configuration and + * the apps visible for the current user + * + * @return string URL */ - public static function redirectToDefaultPage() { + public static function getDefaultPageUrl() { $urlGenerator = \OC::$server->getURLGenerator(); if(isset($_REQUEST['redirect_url'])) { $location = urldecode($_REQUEST['redirect_url']); @@ -827,11 +830,30 @@ class OC_Util { if ($defaultPage) { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/files'); + $appId = 'files'; + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); + // find the first app that is enabled for the current user + foreach ($defaultApps as $defaultApp) { + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); + if (OC_App::isEnabled($defaultApp)) { + $appId = $defaultApp; + break; + } + } + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); } } + return $location; + } + + /** + * Redirect to the user default page + * @return void + */ + public static function redirectToDefaultPage() { + $location = self::getDefaultPageUrl(); OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG); - header( 'Location: '.$location ); + header('Location: '.$location); exit(); } |