diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 28 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenProvider.php | 1 | ||||
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 11 | ||||
-rw-r--r-- | lib/private/Installer.php | 42 | ||||
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 27 | ||||
-rw-r--r-- | lib/private/Server.php | 10 | ||||
-rw-r--r-- | lib/private/Settings/Manager.php | 5 | ||||
-rw-r--r-- | lib/private/Setup.php | 28 | ||||
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 3 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 41 | ||||
-rw-r--r-- | lib/private/Updater.php | 19 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/image.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/util.php | 21 |
15 files changed, 153 insertions, 119 deletions
diff --git a/lib/base.php b/lib/base.php index dc09d0f533d..f6b4f5555eb 100644 --- a/lib/base.php +++ b/lib/base.php @@ -730,7 +730,7 @@ class OC { OC_User::setIncognitoMode(true); } - self::registerCacheHooks(); + self::registerCleanupHooks(); self::registerFilesystemHooks(); self::registerShareHooks(); self::registerEncryptionWrapper(); @@ -802,15 +802,23 @@ class OC { } /** - * register hooks for the cache + * register hooks for the cleanup of cache and bruteforce protection */ - public static function registerCacheHooks() { + public static function registerCleanupHooks() { //don't try to do this before we are properly setup if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { // NOTE: This will be replaced to use OCP $userSession = self::$server->getUserSession(); - $userSession->listen('\OC\User', 'postLogin', function () { + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { + if (!defined('PHPUNIT_RUN')) { + // reset brute force delay for this IP address and username + $uid = \OC::$server->getUserSession()->getUser()->getUID(); + $request = \OC::$server->getRequest(); + $throttler = \OC::$server->getBruteForceThrottler(); + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); + } + try { $cache = new \OC\Cache\File(); $cache->gc(); @@ -915,9 +923,15 @@ class OC { // Check if Nextcloud is installed or in maintenance (update) mode if (!$systemConfig->getValue('installed', false)) { \OC::$server->getSession()->clear(); - $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), - \OC::$server->getSecureRandom()); + $setupHelper = new OC\Setup( + \OC::$server->getSystemConfig(), + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(\OCP\Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(\OC\Installer::class) + ); $controller = new OC\Core\Controller\SetupController($setupHelper); $controller->run($_POST); exit(); diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 3fca122d287..36a8b1d5464 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -97,6 +97,7 @@ class DefaultTokenProvider implements IProvider { $dbToken->setType($type); $dbToken->setRemember($remember); $dbToken->setLastActivity($this->time->getTime()); + $dbToken->setLastCheck($this->time->getTime()); $this->mapper->insert($dbToken); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 93af3fcf6b6..cf017c73960 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -259,7 +259,7 @@ class Cache implements ICache { $data['path'] = $file; $data['parent'] = $this->getParentId($file); - $data['name'] = \OC_Util::basename($file); + $data['name'] = basename($file); list($queryParts, $params) = $this->buildParts($data); $queryParts[] = '`storage`'; @@ -551,7 +551,7 @@ class Cache implements ICache { } $sql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?'; - $this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), \OC_Util::basename($targetPath), $newParentId, $sourceId)); + $this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId)); $this->connection->commit(); } else { $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index d477678c277..adee8ced772 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -60,6 +60,17 @@ class Jail extends Wrapper { } } + public function getJailedPath($path) { + $root = rtrim($this->rootPath, '/') . '/'; + + if (strpos($path, $root) !== 0) { + return null; + } else { + $path = substr($path, strlen($this->rootPath)); + return trim($path, '/'); + } + } + public function getId() { return parent::getId(); } diff --git a/lib/private/Installer.php b/lib/private/Installer.php index e754f28455b..48bd57f4c10 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -67,6 +67,10 @@ class Installer { private $logger; /** @var IConfig */ private $config; + /** @var array - for caching the result of app fetcher */ + private $apps = null; + /** @var bool|null - for caching the result of the ready status */ + private $isInstanceReadyForUpdates = null; /** * @param AppFetcher $appFetcher @@ -187,7 +191,7 @@ class Installer { * @return bool */ public function updateAppstoreApp($appId) { - if(self::isUpdateAvailable($appId, $this->appFetcher)) { + if($this->isUpdateAvailable($appId)) { try { $this->downloadApp($appId); } catch (\Exception $e) { @@ -375,27 +379,26 @@ class Installer { * Check if an update for the app is available * * @param string $appId - * @param AppFetcher $appFetcher * @return string|false false or the version number of the update */ - public static function isUpdateAvailable($appId, - AppFetcher $appFetcher) { - static $isInstanceReadyForUpdates = null; - - if ($isInstanceReadyForUpdates === null) { + public function isUpdateAvailable($appId) { + if ($this->isInstanceReadyForUpdates === null) { $installPath = OC_App::getInstallPath(); if ($installPath === false || $installPath === null) { - $isInstanceReadyForUpdates = false; + $this->isInstanceReadyForUpdates = false; } else { - $isInstanceReadyForUpdates = true; + $this->isInstanceReadyForUpdates = true; } } - if ($isInstanceReadyForUpdates === false) { + if ($this->isInstanceReadyForUpdates === false) { return false; } - $apps = $appFetcher->get(); + if ($this->apps === null) { + $apps = $this->appFetcher->get(); + } + foreach($apps as $app) { if($app['id'] === $appId) { $currentVersion = OC_App::getAppVersion($appId); @@ -589,23 +592,6 @@ class Installer { } /** - * check the code of an app with some static code checks - * @param string $folder the folder of the app to check - * @return boolean true for app is o.k. and false for app is not o.k. - */ - public static function checkCode($folder) { - // is the code checker enabled? - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { - return true; - } - - $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); - $errors = $codeChecker->analyseFolder(basename($folder), $folder); - - return empty($errors); - } - - /** * @param string $script */ private static function includeAppScript($script) { diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 1626cee8cb3..f08b721d143 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -243,6 +243,33 @@ class Throttler { } /** + * Reset the throttling delay for an IP address, action and metadata + * + * @param string $ip + * @param string $action + * @param string $metadata + */ + public function resetDelay($ip, $action, $metadata) { + $ipAddress = new IpAddress($ip); + if ($this->isIPWhitelisted((string)$ipAddress)) { + return; + } + + $cutoffTime = (new \DateTime()) + ->sub($this->getCutoff(43200)) + ->getTimestamp(); + + $qb = $this->db->getQueryBuilder(); + $qb->delete('bruteforce_attempts') + ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) + ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet()))) + ->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action))) + ->andWhere($qb->expr()->eq('metadata', $qb->createNamedParameter(json_encode($metadata)))); + + $qb->execute(); + } + + /** * Will sleep for the defined amount of time * * @param string $ip diff --git a/lib/private/Server.php b/lib/private/Server.php index faa0ce2f2ac..0c6338f6a4c 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1099,6 +1099,16 @@ class Server extends ServerContainer implements IServerContainer { $c->query(\OCP\Share\IManager::class) ); }); + + $this->registerService(Installer::class, function(Server $c) { + return new Installer( + $c->getAppFetcher(), + $c->getHTTPClientService(), + $c->getTempManager(), + $c->getLogger(), + $c->getConfig() + ); + }); } /** diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php index 6da499c31c4..cd0af5e7bb2 100644 --- a/lib/private/Settings/Manager.php +++ b/lib/private/Settings/Manager.php @@ -32,6 +32,7 @@ namespace OC\Settings; use OC\Accounts\AccountManager; use OCP\App\IAppManager; use OCP\AppFramework\QueryException; +use OCP\AutoloadNotAllowedException; use OCP\Encryption\IManager as EncryptionManager; use OCP\IConfig; use OCP\IDBConnection; @@ -471,6 +472,10 @@ class Manager implements IManager { $settings[$row['priority']][] = $this->query($row['class']); } catch (QueryException $e) { // skip + } catch (AutoloadNotAllowedException $e) { + // skip error and remove remnant of disabled app + $this->log->warning('Orphan setting entry will be removed from admin_settings: ' . json_encode($row)); + $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, $row['class']); } } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 8214db2d4ef..92246e8322e 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -65,6 +65,8 @@ class Setup { protected $logger; /** @var ISecureRandom */ protected $random; + /** @var Installer */ + protected $installer; /** * @param SystemConfig $config @@ -73,13 +75,15 @@ class Setup { * @param Defaults $defaults * @param ILogger $logger * @param ISecureRandom $random + * @param Installer $installer */ public function __construct(SystemConfig $config, IniGetWrapper $iniWrapper, IL10N $l10n, Defaults $defaults, ILogger $logger, - ISecureRandom $random + ISecureRandom $random, + Installer $installer ) { $this->config = $config; $this->iniWrapper = $iniWrapper; @@ -87,6 +91,7 @@ class Setup { $this->defaults = $defaults; $this->logger = $logger; $this->random = $random; + $this->installer = $installer; } static protected $dbSetupClasses = [ @@ -371,18 +376,11 @@ class Setup { // Install shipped apps and specified app bundles Installer::installShippedApps(); - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib')); $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle(); foreach($defaultInstallationBundles as $bundle) { try { - $installer->installAppBundle($bundle); + $this->installer->installAppBundle($bundle); } catch (Exception $e) {} } @@ -444,9 +442,15 @@ class Setup { $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; } - $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(), - \OC::$server->getSecureRandom()); + $setupHelper = new \OC\Setup( + $config, + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(Installer::class) + ); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index a440c36406b..844b36b2994 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -183,6 +183,9 @@ class DefaultShareProvider implements IShareProvider { throw new ShareNotFound(); } + $mailSendValue = $share->getMailSend(); + $data['mail_send'] = ($mailSendValue === null) ? true : $mailSendValue; + $share = $this->createShare($data); return $share; } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 4a31266bbe8..b22bfbc3878 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -669,26 +669,31 @@ class Manager implements IManager { $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { - $user = $this->userManager->get($share->getSharedWith()); - if ($user !== null) { - $emailAddress = $user->getEMailAddress(); - if ($emailAddress !== null && $emailAddress !== '') { - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); - $l = $this->l10nFactory->get('lib', $userLang); - $this->sendMailNotification( - $l, - $share->getNode()->getName(), - $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', [ 'fileid' => $share->getNode()->getId() ]), - $share->getSharedBy(), - $emailAddress, - $share->getExpirationDate() - ); - $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); + $mailSend = $share->getMailSend(); + if($mailSend === true) { + $user = $this->userManager->get($share->getSharedWith()); + if ($user !== null) { + $emailAddress = $user->getEMailAddress(); + if ($emailAddress !== null && $emailAddress !== '') { + $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); + $l = $this->l10nFactory->get('lib', $userLang); + $this->sendMailNotification( + $l, + $share->getNode()->getName(), + $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), + $share->getSharedBy(), + $emailAddress, + $share->getExpirationDate() + ); + $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); + } else { + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); + } } else { - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); } } else { - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); + $this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']); } } @@ -1390,7 +1395,7 @@ class Manager implements IManager { foreach ($tmp as $k => $v) { if (isset($al[$k])) { if (is_array($al[$k])) { - $al[$k] = array_merge($al[$k], $v); + $al[$k] += $v; } else { $al[$k] = $al[$k] || $v; } diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 4f5bb45ae15..996163daacc 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -63,6 +63,9 @@ class Updater extends BasicEmitter { /** @var Checker */ private $checker; + /** @var Installer */ + private $installer; + /** @var bool */ private $skip3rdPartyAppsDisable; @@ -78,13 +81,16 @@ class Updater extends BasicEmitter { * @param IConfig $config * @param Checker $checker * @param ILogger $log + * @param Installer $installer */ public function __construct(IConfig $config, Checker $checker, - ILogger $log = null) { + ILogger $log = null, + Installer $installer) { $this->log = $log; $this->config = $config; $this->checker = $checker; + $this->installer = $installer; // If at least PHP 7.0.0 is used we don't need to disable apps as we catch // fatal errors and exceptions and disable the app just instead. @@ -461,17 +467,10 @@ class Updater extends BasicEmitter { private function upgradeAppStoreApps(array $disabledApps) { foreach($disabledApps as $app) { try { - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - $this->log, - \OC::$server->getConfig() - ); $this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]); - if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) { + if ($this->installer->isUpdateAvailable($app)) { $this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]); - $installer->updateAppstoreApp($app); + $this->installer->updateAppstoreApp($app); } $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); } catch (\Exception $ex) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index d2b0f96d593..1b9fc28873e 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -375,13 +375,7 @@ class OC_App { self::$enabledAppsCache = []; // flush // Check if app is already downloaded - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(Installer::class); $isDownloaded = $installer->isDownloaded($appId); if(!$isDownloaded) { @@ -415,13 +409,7 @@ class OC_App { return false; } - $installer = new Installer( - \OC::$server->getAppFetcher(), - \OC::$server->getHTTPClientService(), - \OC::$server->getTempManager(), - \OC::$server->getLogger(), - \OC::$server->getConfig() - ); + $installer = \OC::$server->query(Installer::class); return $installer->removeApp($app); } diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php index fe9f054f5d4..a7d702ac032 100644 --- a/lib/private/legacy/image.php +++ b/lib/private/legacy/image.php @@ -63,22 +63,6 @@ class OC_Image implements \OCP\IImage { private $exif; /** - * Get mime type for an image file. - * - * @param string|null $filePath The path to a local image file. - * @return string The mime type if the it could be determined, otherwise an empty string. - */ - static public function getMimeTypeForFile($filePath) { - // exif_imagetype throws "read error!" if file is less than 12 byte - if ($filePath !== null && filesize($filePath) > 11) { - $imageType = exif_imagetype($filePath); - } else { - $imageType = false; - } - return $imageType ? image_type_to_mime_type($imageType) : ''; - } - - /** * Constructor. * * @param resource|string $imageRef The path to a local file, a base64 encoded string or a resource created by diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 2610ec3a7b6..3ce11746672 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -708,8 +708,15 @@ class OC_Util { } $webServerRestart = false; - $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), - \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); + $setup = new \OC\Setup( + $config, + \OC::$server->getIniWrapper(), + \OC::$server->getL10N('lib'), + \OC::$server->query(\OCP\Defaults::class), + \OC::$server->getLogger(), + \OC::$server->getSecureRandom(), + \OC::$server->query(\OC\Installer::class) + ); $urlGenerator = \OC::$server->getURLGenerator(); @@ -1408,16 +1415,6 @@ class OC_Util { } /** - * @param boolean|string $file - * @return string - */ - public static function basename($file) { - $file = rtrim($file, '/'); - $t = explode('/', $file); - return array_pop($t); - } - - /** * A human readable string is generated based on version and build number * * @return string |