diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/App/AppStore/Fetcher/AppFetcher.php | 29 | ||||
-rw-r--r-- | lib/private/App/AppStore/Fetcher/Fetcher.php | 47 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php | 4 | ||||
-rw-r--r-- | lib/private/Preview/Generator.php | 7 | ||||
-rw-r--r-- | lib/private/PreviewManager.php | 3 | ||||
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 4 | ||||
-rw-r--r-- | lib/private/Server.php | 7 | ||||
-rw-r--r-- | lib/private/Updater.php | 4 | ||||
-rw-r--r-- | lib/private/legacy/defaults.php | 2 | ||||
-rw-r--r-- | lib/private/legacy/image.php | 8 |
10 files changed, 83 insertions, 32 deletions
diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 7c5efafc92f..e020390988e 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -46,14 +46,7 @@ class AppFetcher extends Fetcher { ); $this->fileName = 'apps.json'; - - $versionArray = explode('.', $this->config->getSystemValue('version')); - $this->endpointUrl = sprintf( - 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', - $versionArray[0], - $versionArray[1], - $versionArray[2] - ); + $this->setEndpoint(); } /** @@ -68,7 +61,7 @@ class AppFetcher extends Fetcher { /** @var mixed[] $response */ $response = parent::fetch($ETag, $content); - $ncVersion = $this->config->getSystemValue('version'); + $ncVersion = $this->getVersion(); $ncMajorVersion = explode('.', $ncVersion)[0]; foreach($response['data'] as $dataKey => $app) { $releases = []; @@ -118,4 +111,22 @@ class AppFetcher extends Fetcher { $response['data'] = array_values($response['data']); return $response; } + + private function setEndpoint() { + $versionArray = explode('.', $this->getVersion()); + $this->endpointUrl = sprintf( + 'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json', + $versionArray[0], + $versionArray[1], + $versionArray[2] + ); + } + + /** + * @param string $version + */ + public function setVersion($version) { + parent::setVersion($version); + $this->setEndpoint(); + } } diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index ab0e299f0a2..5354d334eb1 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -43,6 +43,8 @@ abstract class Fetcher { protected $fileName; /** @var string */ protected $endpointUrl; + /** @var string */ + protected $version; /** * @param IAppData $appData @@ -95,7 +97,7 @@ abstract class Fetcher { } $responseJson['timestamp'] = $this->timeFactory->getTime(); - $responseJson['ncversion'] = $this->config->getSystemValue('version'); + $responseJson['ncversion'] = $this->getVersion(); if ($ETag !== '') { $responseJson['ETag'] = $ETag; } @@ -125,19 +127,19 @@ abstract class Fetcher { $file = $rootFolder->getFile($this->fileName); $jsonBlob = json_decode($file->getContent(), true); if (is_array($jsonBlob)) { - /* - * If the timestamp is older than 300 seconds request the files new - * If the version changed (update!) also refresh - */ - if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS) && - isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->config->getSystemValue('version', '0.0.0') - ) { - return $jsonBlob['data']; - } - if (isset($jsonBlob['ETag'])) { - $ETag = $jsonBlob['ETag']; - $content = json_encode($jsonBlob['data']); + // No caching when the version has been updated + if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) { + + // If the timestamp is older than 300 seconds request the files new + if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) { + return $jsonBlob['data']; + } + + if (isset($jsonBlob['ETag'])) { + $ETag = $jsonBlob['ETag']; + $content = json_encode($jsonBlob['data']); + } } } } catch (NotFoundException $e) { @@ -154,4 +156,23 @@ abstract class Fetcher { return []; } } + + /** + * Get the currently Nextcloud version + * @return string + */ + protected function getVersion() { + if ($this->version === null) { + $this->version = $this->config->getSystemValue('version', '0.0.0'); + } + return $this->version; + } + + /** + * Set the current Nextcloud version + * @param string $version + */ + public function setVersion($version) { + $this->version = $version; + } } diff --git a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php index d5630e6420d..242fbd06a22 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/EMailProvider.php @@ -52,6 +52,10 @@ class EMailProvider implements IProvider { public function process(IEntry $entry) { $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); foreach ($entry->getEMailAddresses() as $address) { + if (empty($address)) { + // Skip + continue; + } $action = $this->actionFactory->newEMailAction($iconUrl, $address, $address); $entry->addAction($action); } diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index fd75e51b638..5a264c2bbd5 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -84,6 +84,7 @@ class Generator { * @param string $mimeType * @return ISimpleFile * @throws NotFoundException + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { $this->eventDispatcher->dispatch( @@ -299,10 +300,15 @@ class Generator { * @param int $maxHeight * @return ISimpleFile * @throws NotFoundException + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) */ private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) { $preview = $this->helper->getImage($maxPreview); + if (!$preview->valid()) { + throw new \InvalidArgumentException('Failed to generate preview, failed to load image'); + } + if ($crop) { if ($height !== $preview->height() && $width !== $preview->width()) { //Resize @@ -325,6 +331,7 @@ class Generator { $preview->resize(max($width, $height)); } + $path = $this->generatePath($width, $height, $crop); try { $file = $previewFolder->newFile($path); diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 8c5a7ad29f1..12fcc292c63 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -182,7 +182,8 @@ class PreviewManager implements IPreview { * @param string $mimeType * @return ISimpleFile * @throws NotFoundException - * @since 11.0.0 + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { if ($this->generator === null) { diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index b2524b63c63..ee02bc5a1c4 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -133,6 +133,10 @@ class Throttler { * @return bool */ private function isIPWhitelisted($ip) { + if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) { + return true; + } + $keys = $this->config->getAppKeys('bruteForce'); $keys = array_filter($keys, function($key) { $regex = '/^whitelist_/S'; diff --git a/lib/private/Server.php b/lib/private/Server.php index 6bc9a1429cd..07e449ee4a9 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -420,7 +420,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('AppHelper', function ($c) { return new \OC\AppHelper(); }); - $this->registerService('AppFetcher', function ($c) { + $this->registerService(AppFetcher::class, function ($c) { return new AppFetcher( $this->getAppDataDir('appstore'), $this->getHTTPClientService(), @@ -428,6 +428,8 @@ class Server extends ServerContainer implements IServerContainer { $this->getConfig() ); }); + $this->registerAlias('AppFetcher', AppFetcher::class); + $this->registerService('CategoryFetcher', function ($c) { return new CategoryFetcher( $this->getAppDataDir('appstore'), @@ -821,9 +823,6 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService(BundleFetcher::class, function () { return new BundleFetcher($this->getL10N('lib')); }); - $this->registerService(AppFetcher::class, function() { - return $this->getAppFetcher(); - }); $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { return new Manager( $c->query(IValidator::class) diff --git a/lib/private/Updater.php b/lib/private/Updater.php index c080ee0eb43..5c4a7725a1b 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -32,6 +32,7 @@ namespace OC; +use OC\App\AppStore\Fetcher\AppFetcher; use OC\Hooks\BasicEmitter; use OC\IntegrityCheck\Checker; use OC_App; @@ -246,6 +247,9 @@ class Updater extends BasicEmitter { $this->checkAppsRequirements(); $this->doAppUpgrade(); + // Update the appfetchers version so it downloads the correct list from the appstore + \OC::$server->getAppFetcher()->setVersion($currentVersion); + // upgrade appstore apps $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); diff --git a/lib/private/legacy/defaults.php b/lib/private/legacy/defaults.php index 7835707b19d..cc4991efd3e 100644 --- a/lib/private/legacy/defaults.php +++ b/lib/private/legacy/defaults.php @@ -61,7 +61,7 @@ class OC_Defaults { $this->defaultiTunesAppId = '1125420102'; $this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.nextcloud.client'; $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; - $this->defaultDocVersion = '11'; // used to generate doc links + $this->defaultDocVersion = '12'; // used to generate doc links $this->defaultSlogan = $this->l->t('a safe home for all your data'); $this->defaultLogoClaim = ''; $this->defaultColorPrimary = '#0082c9'; diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php index e26148bdf15..120b19d1cff 100644 --- a/lib/private/legacy/image.php +++ b/lib/private/legacy/image.php @@ -563,7 +563,7 @@ class OC_Image implements \OCP\IImage { case IMAGETYPE_JPEG: if (imagetypes() & IMG_JPG) { if (getimagesize($imagePath) !== false) { - $this->resource = imagecreatefromjpeg($imagePath); + $this->resource = @imagecreatefromjpeg($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core')); } @@ -573,7 +573,7 @@ class OC_Image implements \OCP\IImage { break; case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { - $this->resource = imagecreatefrompng($imagePath); + $this->resource = @imagecreatefrompng($imagePath); // Preserve transparency imagealphablending($this->resource, true); imagesavealpha($this->resource, true); @@ -583,14 +583,14 @@ class OC_Image implements \OCP\IImage { break; case IMAGETYPE_XBM: if (imagetypes() & IMG_XPM) { - $this->resource = imagecreatefromxbm($imagePath); + $this->resource = @imagecreatefromxbm($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core')); } break; case IMAGETYPE_WBMP: if (imagetypes() & IMG_WBMP) { - $this->resource = imagecreatefromwbmp($imagePath); + $this->resource = @imagecreatefromwbmp($imagePath); } else { $this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core')); } |