diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1beceac88e28707aaeaa730130a3730520d5f194..ee84b50335652713e6cec82c67023ae1eabca69f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,6 +42,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\Files\Storage\IStorage; +use OCP\IRequest; use OCP\IUserManager; use OCP\User\Events\BeforeUserDeletedEvent; use OCP\User\Events\PasswordUpdatedEvent; @@ -62,7 +63,7 @@ class Application extends App implements IBootstrap { $context->registerEventListener(UserChangedEvent::class, UserChangedListener::class); $context->registerEventListener(StateChanged::class, TwoFactorStateChangedListener::class); $context->registerEventListener(PasswordUpdatedEvent::class, PasswordUpdatedListener::class); - + $context->registerMiddleware(AccountMiddleware::class); } @@ -89,13 +90,18 @@ class Application extends App implements IBootstrap { * @return StorageWrapper|IStorage */ public function addStorageWrapperCallback($mountPoint, IStorage $storage) { - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); - $appdataFolder = 'appdata_' . $instanceId; - if ($mountPoint !== '/' && strpos($mountPoint, '/' . $appdataFolder) !== 0) { - return new StorageWrapper([ - 'storage' => $storage, - 'mountPoint' => $mountPoint, - ]); + $request = \OC::$server->get(IRequest::class); + + if ($request !== null) { + $userAgent = $request->getHeader('USER_AGENT'); + $userAgent = strtolower($userAgent); + + if (strpos($userAgent, "eos") !== false || strpos($userAgent, "edrive") !== false) { + return new StorageWrapper([ + 'storage' => $storage, + 'mountPoint' => $mountPoint, + ]); + } } return $storage; diff --git a/lib/Filesystem/CacheWrapper.php b/lib/Filesystem/CacheWrapper.php index da6e32537a1603509f851e699e253113ae32d3fc..f26cced783a583b1dbda433c14a6d6da43e16cc3 100644 --- a/lib/Filesystem/CacheWrapper.php +++ b/lib/Filesystem/CacheWrapper.php @@ -8,7 +8,6 @@ use OC\Files\Cache\Wrapper\CacheWrapper as Wrapper; use OCP\Constants; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; -use OCP\Files\ForbiddenException; use OCP\Files\Search\ISearchQuery; class CacheWrapper extends Wrapper { @@ -25,26 +24,30 @@ class CacheWrapper extends Wrapper { } protected function formatCacheEntry($entry) { - if (isset($entry['path']) && isset($entry['permissions'])) { - try { - throw new ForbiddenException('Access denied', false); - } catch (ForbiddenException) { - $entry['permissions'] &= $this->mask; - } - } - return $entry; + throw new \OC\ServiceUnavailableException('Service unavailable'); + // if (isset($entry['path']) && isset($entry['permissions'])) { + // try { + // throw new \Exception('Access denied', 503); + // } catch (\Exception) { + // $entry['permissions'] &= $this->mask; + // } + // } + // return $entry; } public function insert($file, $data) { - throw new \Exception('User data cache insert is disabled.'); + throw new \OC\ServiceUnavailableException('Service unavailable'); + // throw new \Exception('User data cache insert is disabled.', 503); } public function update($id, $data) { - throw new \Exception('User data cache update is disabled.'); + throw new \OC\ServiceUnavailableException('Service unavailable'); + // throw new \Exception('User data cache update is disabled.', 503); } public function remove($fileId) { - throw new \Exception('User data cache removal is disabled.'); + throw new \OC\ServiceUnavailableException('Service unavailable'); + // throw new \Exception('User data cache removal is disabled.', 503); } public function searchQuery(ISearchQuery $searchQuery) { diff --git a/lib/Filesystem/StorageWrapper.php b/lib/Filesystem/StorageWrapper.php index f35a55105be582163fcfdbfbe44eab87292767be..4854aad1591d33e5e8c0e39ea2ef306a93161d65 100644 --- a/lib/Filesystem/StorageWrapper.php +++ b/lib/Filesystem/StorageWrapper.php @@ -7,9 +7,9 @@ namespace OCA\EcloudAccounts\Filesystem; use OC\Files\Cache\Cache; use OC\Files\Storage\Storage; use OC\Files\Storage\Wrapper\Wrapper; -use OCP\Files\ForbiddenException; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; +use OCP\Files\StorageNotAvailableException; class StorageWrapper extends Wrapper implements IWriteStreamStorage { /** @@ -20,10 +20,10 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { } /** - * @throws ForbiddenException + * @throws StorageNotAvailableException */ protected function checkFileAccess(string $path, bool $isDir = false): void { - throw new ForbiddenException('Access denied', false); + throw new StorageNotAvailableException('Service unavailable'); } /* @@ -35,7 +35,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * * @param string $path * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function mkdir($path) { $this->checkFileAccess($path, true); @@ -46,7 +46,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * * @param string $path * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function rmdir($path) { $this->checkFileAccess($path, true); @@ -59,11 +59,8 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @return bool */ public function isCreatable($path) { - try { - $this->checkFileAccess($path); - } catch (ForbiddenException $e) { - return false; - } + $this->checkFileAccess($path); + return false; } /** @@ -73,11 +70,8 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @return bool */ public function isReadable($path) { - try { - $this->checkFileAccess($path); - } catch (ForbiddenException $e) { - return false; - } + $this->checkFileAccess($path); + return false; } /** @@ -87,11 +81,8 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @return bool */ public function isUpdatable($path) { - try { - $this->checkFileAccess($path); - } catch (ForbiddenException $e) { - return false; - } + $this->checkFileAccess($path); + return false; } /** @@ -101,19 +92,13 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @return bool */ public function isDeletable($path) { - try { - $this->checkFileAccess($path); - } catch (ForbiddenException $e) { - return false; - } + $this->checkFileAccess($path); + return false; } public function getPermissions($path) { - try { - $this->checkFileAccess($path); - } catch (ForbiddenException $e) { - return $this->mask; - } + $this->checkFileAccess($path); + return $this->mask; } /** @@ -121,7 +106,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * * @param string $path * @return string - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function file_get_contents($path) { $this->checkFileAccess($path); @@ -133,7 +118,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $path * @param string $data * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function file_put_contents($path, $data) { $this->checkFileAccess($path); @@ -144,7 +129,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * * @param string $path * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function unlink($path) { $this->checkFileAccess($path); @@ -156,7 +141,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $path1 * @param string $path2 * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function rename($path1, $path2) { $this->checkFileAccess($path1); @@ -169,7 +154,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $path1 * @param string $path2 * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function copy($path1, $path2) { $this->checkFileAccess($path1); @@ -182,7 +167,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $path * @param string $mode * @return resource - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function fopen($path, $mode) { $this->checkFileAccess($path); @@ -195,7 +180,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $path * @param int $mtime * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function touch($path, $mtime = null) { $this->checkFileAccess($path); @@ -223,7 +208,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * * @param string $path * @return array - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function getDirectDownload($path) { $this->checkFileAccess($path); @@ -234,7 +219,7 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $this->checkFileAccess($targetInternalPath); @@ -245,14 +230,14 @@ class StorageWrapper extends Wrapper implements IWriteStreamStorage { * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $this->checkFileAccess($targetInternalPath); } /** - * @throws ForbiddenException + * @throws StorageNotAvailableException */ public function writeStream(string $path, $stream, ?int $size = null): int { $this->checkFileAccess($path);