예제 #1
0
파일: scanfiles.php 프로젝트: loulancn/core
 /**
  * @param IUser $user
  */
 protected function runScanner(IUser $user)
 {
     try {
         $scanner = new Scanner($user->getUID(), $this->dbConnection, $this->logger);
         $scanner->backgroundScan('');
     } catch (\Exception $e) {
         $this->logger->logException($e, ['app' => 'files']);
     }
     \OC_Util::tearDownFS();
 }
예제 #2
0
파일: logger.php 프로젝트: evanjt/core
 /**
  * @dataProvider userAndPasswordData
  */
 public function testDetectcheckPassword($user, $password)
 {
     $e = new \Exception('test');
     $this->logger->logException($e);
     $logLines = $this->getLogs();
     foreach ($logLines as $logLine) {
         $this->assertNotContains($user, $logLine);
         $this->assertNotContains($password, $logLine);
         $this->assertContains('checkPassword(*** username and password replaced ***)', $logLine);
     }
 }
예제 #3
0
 /**
  * @param int $calendarId
  * @param int $newCalendarId
  */
 private function migrateCalendar($calendarId, $newCalendarId)
 {
     $this->adapter->foreachCalendarObject($calendarId, function ($calObject) use($newCalendarId) {
         try {
             $this->backend->createCalendarObject($newCalendarId, $calObject['uri'], $calObject['calendardata']);
         } catch (\Exception $ex) {
             $eventId = $calObject['id'];
             $calendarId = $calObject['calendarId'];
             $msg = "One event could not be migrated. (id: {$eventId}, calendarid: {$calendarId})";
             $this->logger->logException($ex, ['app' => 'dav', 'message' => $msg]);
             if (!is_null($this->consoleOutput)) {
                 $this->consoleOutput->writeln($msg);
             }
         }
     });
 }
예제 #4
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     try {
         $result = $this->httpClient->post($target . $this->endPoint, ['body' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         $this->logger->logException($e);
     } catch (\Exception $e) {
         $status = HTTP::STATUS_INTERNAL_SERVER_ERROR;
         $this->logger->logException($e);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\RequestSharedSecret', $argument);
     }
     if ($status === Http::STATUS_FORBIDDEN) {
         // clear token if remote server refuses to ask for shared secret
         $this->dbHandler->addToken($target, '');
     }
 }
예제 #5
0
파일: scanner.php 프로젝트: gvde/core
 /**
  * @param string $dir
  * @throws \OC\ForbiddenException
  */
 public function scan($dir = '')
 {
     if (!Filesystem::isValidPath($dir)) {
         throw new \InvalidArgumentException('Invalid path to scan');
     }
     $mounts = $this->getMounts($dir);
     foreach ($mounts as $mount) {
         if (is_null($mount->getStorage())) {
             continue;
         }
         $storage = $mount->getStorage();
         // if the home storage isn't writable then the scanner is run as the wrong user
         if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files'))) {
             throw new ForbiddenException();
         }
         $relativePath = $mount->getInternalPath($dir);
         $scanner = $storage->getScanner();
         $scanner->setUseTransactions(false);
         $this->attachListener($mount);
         $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider;
         if (!$isDbLocking) {
             $this->db->beginTransaction();
         }
         try {
             $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
         } catch (StorageNotAvailableException $e) {
             $this->logger->error('Storage ' . $storage->getId() . ' not available');
             $this->logger->logException($e);
             $this->emit('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', [$e]);
         }
         if (!$isDbLocking) {
             $this->db->commit();
         }
     }
 }
예제 #6
0
 /**
  * @param array $argument
  * @throws \Exception
  * @throws \OC\NeedsUpdateException
  */
 protected function run($argument)
 {
     if (!isset($argument['app']) || !isset($argument['step'])) {
         // remove the job - we can never execute it
         $this->jobList->remove($this, $this->argument);
         return;
     }
     $app = $argument['app'];
     try {
         $this->loadApp($app);
     } catch (NeedsUpdateException $ex) {
         // as long as the app is not yet done with it's offline migration
         // we better not start with the live migration
         return;
     }
     $step = $argument['step'];
     $repair = new Repair([], $this->dispatcher);
     try {
         $repair->addStep($step);
     } catch (\Exception $ex) {
         $this->logger->logException($ex, ['app' => 'migration']);
         // remove the job - we can never execute it
         $this->jobList->remove($this, $this->argument);
         return;
     }
     // execute the repair step
     $repair->run();
     // remove the job once executed successfully
     $this->jobList->remove($this, $this->argument);
 }
예제 #7
0
 /**
  * @NoAdminRequired
  *
  * @param array $crop
  * @return DataResponse
  */
 public function postCroppedAvatar($crop)
 {
     $userId = $this->userSession->getUser()->getUID();
     if (is_null($crop)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     if (!isset($crop['x'], $crop['y'], $crop['w'], $crop['h'])) {
         return new DataResponse(['data' => ['message' => $this->l->t("No valid crop data provided")]], Http::STATUS_BAD_REQUEST);
     }
     $tmpAvatar = $this->cache->get('tmpAvatar');
     if (is_null($tmpAvatar)) {
         return new DataResponse(['data' => ['message' => $this->l->t("No temporary profile picture available, try again")]], Http::STATUS_BAD_REQUEST);
     }
     $image = new \OC_Image($tmpAvatar);
     $image->crop($crop['x'], $crop['y'], round($crop['w']), round($crop['h']));
     try {
         $avatar = $this->avatarManager->getAvatar($userId);
         $avatar->set($image);
         // Clean up
         $this->cache->remove('tmpAvatar');
         return new DataResponse(['status' => 'success']);
     } catch (\OC\NotSquareException $e) {
         return new DataResponse(['data' => ['message' => $this->l->t('Crop is not square')]], Http::STATUS_BAD_REQUEST);
     } catch (\Exception $e) {
         $this->logger->logException($e, ['app' => 'core']);
         return new DataResponse(['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], Http::STATUS_BAD_REQUEST);
     }
 }
예제 #8
0
 function getPhoto(Card $node)
 {
     // TODO: this is kind of expensive - load carddav data from database and parse it
     //       we might want to build up a cache one day
     try {
         $vObject = $this->readCard($node->get());
         if (!$vObject->PHOTO) {
             return false;
         }
         $photo = $vObject->PHOTO;
         $type = $this->getType($photo);
         $val = $photo->getValue();
         if ($photo->getValueType() === 'URI') {
             $parsed = \Sabre\URI\parse($val);
             //only allow data://
             if ($parsed['scheme'] !== 'data') {
                 return false;
             }
             if (substr_count($parsed['path'], ';') === 1) {
                 list($type, ) = explode(';', $parsed['path']);
             }
             $val = file_get_contents($val);
         }
         return ['Content-Type' => $type, 'body' => $val];
     } catch (\Exception $ex) {
         $this->logger->logException($ex);
     }
     return false;
 }
예제 #9
0
 /**
  * @param int $addressBookId
  * @param int $newAddressBookId
  */
 private function migrateBook($addressBookId, $newAddressBookId)
 {
     $this->adapter->foreachCard($addressBookId, function ($card) use($newAddressBookId) {
         try {
             $this->backend->createCard($newAddressBookId, $card['uri'], $card['carddata']);
         } catch (\Exception $ex) {
             $eventId = $card['id'];
             $addressBookId = $card['addressbookid'];
             $msg = "One event could not be migrated. (id: {$eventId}, addressbookid: {$addressBookId})";
             $this->logger->logException($ex, ['app' => 'dav', 'message' => $msg]);
             if (!is_null($this->consoleOutput)) {
                 $this->consoleOutput->writeln($msg);
             }
         }
     });
 }
예제 #10
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     try {
         $result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         $this->logger->logException($e);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', $argument);
     } else {
         // reset token if we received a valid response
         $this->dbHandler->addToken($target, '');
     }
     if ($status === Http::STATUS_OK) {
         $body = $result->getBody();
         $result = json_decode($body, true);
         if (isset($result['ocs']['data']['sharedSecret'])) {
             $this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
         } else {
             $this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
             $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
         }
     }
 }
예제 #11
0
 /**
  * Create a storage from its parameters
  *
  * @param string $mountPoint storage mount point
  * @param string $backend backend identifier
  * @param string $authMechanism authentication mechanism identifier
  * @param array $backendOptions backend-specific options
  * @param array|null $mountOptions mount-specific options
  * @param array|null $applicableUsers users for which to mount the storage
  * @param array|null $applicableGroups groups for which to mount the storage
  * @param int|null $priority priority
  *
  * @return StorageConfig|DataResponse
  */
 protected function createStorage($mountPoint, $backend, $authMechanism, $backendOptions, $mountOptions = null, $applicableUsers = null, $applicableGroups = null, $priority = null)
 {
     try {
         return $this->service->createStorage($mountPoint, $backend, $authMechanism, $backendOptions, $mountOptions, $applicableUsers, $applicableGroups, $priority);
     } catch (\InvalidArgumentException $e) {
         $this->logger->logException($e);
         return new DataResponse(['message' => (string) $this->l10n->t('Invalid backend or authentication mechanism class')], Http::STATUS_UNPROCESSABLE_ENTITY);
     }
 }
예제 #12
0
 /**
  * @param string $dir
  * @throws \OC\ForbiddenException
  */
 public function scan($dir = '')
 {
     if (!Filesystem::isValidPath($dir)) {
         throw new \InvalidArgumentException('Invalid path to scan');
     }
     $mounts = $this->getMounts($dir);
     foreach ($mounts as $mount) {
         if (is_null($mount->getStorage())) {
             continue;
         }
         $storage = $mount->getStorage();
         // if the home storage isn't writable then the scanner is run as the wrong user
         if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') and (!$storage->isCreatable('') or !$storage->isCreatable('files'))) {
             if ($storage->file_exists('') or $storage->getCache()->inCache('')) {
                 throw new ForbiddenException();
             } else {
                 // if the root exists in neither the cache nor the storage the user isn't setup yet
                 break;
             }
         }
         $relativePath = $mount->getInternalPath($dir);
         $scanner = $storage->getScanner();
         $scanner->setUseTransactions(false);
         $this->attachListener($mount);
         $isDbLocking = \OC::$server->getLockingProvider() instanceof DBLockingProvider;
         $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'removeFromCache', function ($path) use($storage) {
             $this->triggerPropagator($storage, $path);
         });
         $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'updateCache', function ($path) use($storage) {
             $this->triggerPropagator($storage, $path);
         });
         $scanner->listen('\\OC\\Files\\Cache\\Scanner', 'addToCache', function ($path) use($storage) {
             $this->triggerPropagator($storage, $path);
         });
         if (!$isDbLocking) {
             $this->db->beginTransaction();
         }
         try {
             $storage->getPropagator()->beginBatch();
             $scanner->scan($relativePath, \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
             $cache = $storage->getCache();
             if ($cache instanceof Cache) {
                 // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner
                 $cache->correctFolderSize($relativePath);
             }
             $storage->getPropagator()->commitBatch();
         } catch (StorageNotAvailableException $e) {
             $this->logger->error('Storage ' . $storage->getId() . ' not available');
             $this->logger->logException($e);
             $this->emit('\\OC\\Files\\Utils\\Scanner', 'StorageNotAvailable', [$e]);
         }
         if (!$isDbLocking) {
             $this->db->commit();
         }
     }
 }
예제 #13
0
 /**
  * Generate url based on $name and $parameters
  *
  * @param string $name Name of the route to use.
  * @param array $parameters Parameters for the route
  * @param bool $absolute
  * @return string
  */
 public function generate($name, $parameters = array(), $absolute = false)
 {
     $this->loadRoutes();
     try {
         return $this->getGenerator()->generate($name, $parameters, $absolute);
     } catch (RouteNotFoundException $e) {
         $this->logger->logException($e);
         return '';
     }
 }
예제 #14
0
파일: Job.php 프로젝트: GitHubUser4234/core
 /**
  * @param JobList $jobList
  * @param ILogger $logger
  */
 public function execute($jobList, ILogger $logger = null)
 {
     $jobList->setLastRun($this);
     try {
         $this->run($this->argument);
     } catch (\Exception $e) {
         if ($logger) {
             $logger->logException($e, ['app' => 'core', 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')']);
         }
     }
 }
예제 #15
0
파일: commentnode.php 프로젝트: Pookay/core
 /**
  * update the comment's message
  *
  * @param $propertyValue
  * @return bool
  */
 public function updateComment($propertyValue)
 {
     try {
         $this->comment->setMessage($propertyValue);
         $this->commentsManager->save($this->comment);
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e, ['app' => 'dav/comments']);
         return false;
     }
 }
예제 #16
0
 /**
  * Get all mountpoints applicable for the user and check for shares where we need to update the etags
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $storageFactory
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $storageFactory)
 {
     $shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
     $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
     // filter out excluded shares and group shares that includes self
     $shares = array_filter($shares, function (\OCP\Share\IShare $share) use($user) {
         return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
     });
     $mounts = [];
     foreach ($shares as $share) {
         try {
             $mounts[] = new SharedMount('\\OC\\Files\\Storage\\Shared', $mounts, ['user' => $user->getUID(), 'newShare' => $share], $storageFactory);
         } catch (\Exception $e) {
             $this->logger->logException($e);
             $this->logger->error('Error while trying to create shared mount');
         }
     }
     // array_filter removes the null values from the array
     return array_filter($mounts);
 }
예제 #17
0
 /**
  * @dataProvider userAndPasswordData
  */
 public function testDetectvalidateUserPass($user, $password)
 {
     $e = new \Exception('test');
     $this->logger->logException($e);
     $logLines = $this->getLogs();
     foreach ($logLines as $logLine) {
         $this->assertNotContains($user, $logLine);
         $this->assertNotContains($password, $logLine);
         $this->assertContains('validateUserPass(*** sensitive parameters replaced ***)', $logLine);
     }
 }
예제 #18
0
 /**
  * deletes the read markers on the specified object
  *
  * @param string $objectType
  * @param string $objectId
  * @return bool
  * @since 9.0.0
  */
 public function deleteReadMarksOnObject($objectType, $objectId)
 {
     $this->checkRoleParameters('Object', $objectType, $objectId);
     $qb = $this->dbConn->getQueryBuilder();
     $query = $qb->delete('comments_read_markers')->where($qb->expr()->eq('object_type', $qb->createParameter('object_type')))->andWhere($qb->expr()->eq('object_id', $qb->createParameter('object_id')))->setParameter('object_type', $objectType)->setParameter('object_id', $objectId);
     try {
         $affectedRows = $query->execute();
     } catch (DriverException $e) {
         $this->logger->logException($e, ['app' => 'core_comments']);
         return false;
     }
     return $affectedRows > 0;
 }
예제 #19
0
 private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService)
 {
     $existingStorage = $legacyService->getAllStorages();
     $this->connection->beginTransaction();
     try {
         foreach ($existingStorage as $storage) {
             $storageService->addStorage($storage);
         }
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->connection->rollBack();
     }
 }
예제 #20
0
 /**
  * Generate url based on $name and $parameters
  *
  * @param string $name Name of the route to use.
  * @param array $parameters Parameters for the route
  * @param bool $absolute
  * @return string
  */
 public function generate($name, $parameters = [], $absolute = false)
 {
     $this->loadRoutes();
     try {
         $referenceType = UrlGenerator::ABSOLUTE_URL;
         if ($absolute === false) {
             $referenceType = UrlGenerator::ABSOLUTE_PATH;
         }
         return $this->getGenerator()->generate($name, $parameters, $referenceType);
     } catch (RouteNotFoundException $e) {
         $this->logger->logException($e);
         return '';
     }
 }
예제 #21
0
 /**
  * @param array $disabledApps
  * @throws \Exception
  */
 private function upgradeAppStoreApps(array $disabledApps)
 {
     foreach ($disabledApps as $app) {
         try {
             if (Installer::isUpdateAvailable($app)) {
                 $ocsId = \OC::$server->getConfig()->getAppValue($app, 'ocsid', '');
                 $this->emit('\\OC\\Updater', 'upgradeAppStoreApp', array($app));
                 Installer::updateAppByOCSId($ocsId);
             }
         } catch (\Exception $ex) {
             $this->log->logException($ex, ['app' => 'core']);
         }
     }
 }
예제 #22
0
 private function init()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     try {
         Filesystem::initMountPoints($this->superShare->getShareOwner());
         $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
         list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
         $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
     } catch (\Exception $e) {
         $this->logger->logException($e);
     }
 }
예제 #23
0
파일: imipplugin.php 프로젝트: kenwi/core
 /**
  * Event handler for the 'schedule' event.
  *
  * @param ITip\Message $iTipMessage
  * @return void
  */
 function schedule(ITip\Message $iTipMessage)
 {
     // Not sending any emails if the system considers the update
     // insignificant.
     if (!$iTipMessage->significantChange) {
         if (!$iTipMessage->scheduleStatus) {
             $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
         }
         return;
     }
     $summary = $iTipMessage->message->VEVENT->SUMMARY;
     if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
         return;
     }
     if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
         return;
     }
     $sender = substr($iTipMessage->sender, 7);
     $recipient = substr($iTipMessage->recipient, 7);
     $senderName = $iTipMessage->senderName ? $iTipMessage->senderName : null;
     $recipientName = $iTipMessage->recipientName ? $iTipMessage->recipientName : null;
     $subject = 'SabreDAV iTIP message';
     switch (strtoupper($iTipMessage->method)) {
         case 'REPLY':
             $subject = 'Re: ' . $summary;
             break;
         case 'REQUEST':
             $subject = $summary;
             break;
         case 'CANCEL':
             $subject = 'Cancelled: ' . $summary;
             break;
     }
     $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
     $message = $this->mailer->createMessage();
     $message->setReplyTo([$sender => $senderName])->setTo([$recipient => $recipientName])->setSubject($subject)->setBody($iTipMessage->message->serialize(), $contentType);
     try {
         $failed = $this->mailer->send($message);
         if ($failed) {
             $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
             $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
         }
         $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
     } catch (\Exception $ex) {
         $this->logger->logException($ex, ['app' => 'dav']);
         $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
     }
 }
예제 #24
0
 /**
  * update the comment's message
  *
  * @param $propertyValue
  * @return bool
  * @throws BadRequest
  * @throws Forbidden
  */
 public function updateComment($propertyValue)
 {
     $this->checkWriteAccessOnComment();
     try {
         $this->comment->setMessage($propertyValue);
         $this->commentsManager->save($this->comment);
         return true;
     } catch (\Exception $e) {
         $this->logger->logException($e, ['app' => 'dav/comments']);
         if ($e instanceof MessageTooLongException) {
             $msg = 'Message exceeds allowed character limit of ';
             throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e);
         }
         throw $e;
     }
 }
예제 #25
0
파일: manager.php 프로젝트: matt407/core
 /**
  * permanently deletes the comment specified by the ID
  *
  * When the comment has child comments, their parent ID will be changed to
  * the parent ID of the item that is to be deleted.
  *
  * @param string $id
  * @return bool
  * @throws \InvalidArgumentException
  * @since 9.0.0
  */
 public function delete($id)
 {
     if (!is_string($id)) {
         throw new \InvalidArgumentException('Parameter must be string');
     }
     $qb = $this->dbConn->getQueryBuilder();
     $query = $qb->delete('comments')->where($qb->expr()->eq('id', $qb->createParameter('id')))->setParameter('id', $id);
     try {
         $affectedRows = $query->execute();
         $this->uncache($id);
     } catch (DriverException $e) {
         $this->logger->logException($e, ['app' => 'core_comments']);
         return false;
     }
     return $affectedRows > 0;
 }
예제 #26
0
 /**
  * perform some plausibility checks if the the unencrypted size is correct.
  * If not, we calculate the correct unencrypted size and return it
  *
  * @param string $path internal path relative to the storage root
  * @param int $unencryptedSize size of the unencrypted file
  *
  * @return int unencrypted size
  */
 protected function verifyUnencryptedSize($path, $unencryptedSize)
 {
     $size = $this->storage->filesize($path);
     $result = $unencryptedSize;
     if ($unencryptedSize < 0 || $size > 0 && $unencryptedSize === $size) {
         // check if we already calculate the unencrypted size for the
         // given path to avoid recursions
         if (isset($this->fixUnencryptedSizeOf[$this->getFullPath($path)]) === false) {
             $this->fixUnencryptedSizeOf[$this->getFullPath($path)] = true;
             try {
                 $result = $this->fixUnencryptedSize($path, $size, $unencryptedSize);
             } catch (\Exception $e) {
                 $this->logger->error('Couldn\'t re-calculate unencrypted size for ' . $path);
                 $this->logger->logException($e);
             }
             unset($this->fixUnencryptedSizeOf[$this->getFullPath($path)]);
         }
     }
     return $result;
 }
예제 #27
0
 private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService)
 {
     $existingStorage = $legacyService->getAllStorages();
     $this->connection->beginTransaction();
     try {
         foreach ($existingStorage as $storage) {
             $mountOptions = $storage->getMountOptions();
             if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) {
                 // existing mounts must have sharing enabled by default to avoid surprises
                 $mountOptions['enable_sharing'] = true;
                 $storage->setMountOptions($mountOptions);
             }
             $storageService->addStorage($storage);
         }
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->connection->rollBack();
     }
 }
예제 #28
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     $result = null;
     try {
         $result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         if ($status === Http::STATUS_FORBIDDEN) {
             $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']);
         } else {
             $this->logger->logException($e, ['app' => 'federation']);
         }
     } catch (\Exception $e) {
         $status = Http::STATUS_INTERNAL_SERVER_ERROR;
         $this->logger->logException($e, ['app' => 'federation']);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->retainJob = true;
     } else {
         // reset token if we received a valid response
         $this->dbHandler->addToken($target, '');
     }
     if ($status === Http::STATUS_OK && $result instanceof IResponse) {
         $body = $result->getBody();
         $result = json_decode($body, true);
         if (isset($result['ocs']['data']['sharedSecret'])) {
             $this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
         } else {
             $this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
             $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
         }
     }
 }
예제 #29
0
 /**
  * @inheritdoc
  */
 public function logException(\Exception $exception, array $context = array())
 {
     $this->logger->logException($exception, array_merge($this->context, $context));
 }