/** * @NoAdminRequired * @UseSession * * @param string $oldPassword * @param string $newPassword * @return DataResponse */ public function updatePrivateKeyPassword($oldPassword, $newPassword) { $result = false; $uid = $this->userSession->getUser()->getUID(); $errorMessage = $this->l->t('Could not update the private key password.'); //check if password is correct $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); if ($passwordCorrect !== false) { $encryptedKey = $this->keyManager->getPrivateKey($uid); $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword); if ($decryptedKey) { $encryptedKey = $this->crypt->symmetricEncryptFileContent($decryptedKey, $newPassword); $header = $this->crypt->generateHeader(); if ($encryptedKey) { $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); $this->session->setPrivateKey($decryptedKey); $result = true; } } else { $errorMessage = $this->l->t('The old password was not correct, please try again.'); } } else { $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); } if ($result === true) { $this->session->setStatus(Session::INIT_SUCCESSFUL); return new DataResponse(['message' => (string) $this->l->t('Private key password successfully updated.')]); } else { return new DataResponse(['message' => (string) $errorMessage], Http::STATUS_BAD_REQUEST); } }
public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { parent::__construct($caldavBackend, $calendarInfo); if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); } }
public function __construct(IL10N $l, ISession $session, ICrypto $crypto) { $this->session = $session; $this->crypto = $crypto; $this->setIdentifier('password::sessioncredentials')->setScheme(self::SCHEME_PASSWORD)->setText($l->t('Session credentials'))->addParameters([]); \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); }
/** * @param IEvent $event * @param string $parameter The parameter to be formatted * @param bool $allowHtml Should HTML be used to format the parameter? * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { // If the username is empty, the action has been performed by a remote // user, or via a public share. We don't know the username in that case if ($parameter === '') { if ($allowHtml === null) { return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>'; } if ($allowHtml) { return '<strong>' . $this->l->t('"remote user"') . '</strong>'; } else { return $this->l->t('"remote user"'); } } $user = $this->manager->get($parameter); $displayName = $user ? $user->getDisplayName() : $parameter; $parameter = Util::sanitizeHTML($parameter); if ($allowHtml === null) { return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>'; } if ($allowHtml) { $avatarPlaceholder = ''; if ($this->config->getSystemValue('enable_avatars', true)) { $avatarPlaceholder = '<div class="avatar" data-user="******"></div>'; } return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>'; } else { return $displayName; } }
/** * Asynchronously scan data that are written to the file * @param string $path * @param string $mode * @return resource | bool */ public function fopen($path, $mode) { $stream = $this->storage->fopen($path, $mode); if (is_resource($stream) && $this->isWritingMode($mode)) { try { $scanner = $this->scannerFactory->getScanner(); $scanner->initAsyncScan(); return CallBackWrapper::wrap($stream, null, function ($data) use($scanner) { $scanner->onAsyncData($data); }, function () use($scanner, $path) { $status = $scanner->completeAsyncScan(); if (intval($status->getNumericStatus()) === \OCA\Files_Antivirus\Status::SCANRESULT_INFECTED) { //prevent from going to trashbin if (App::isEnabled('files_trashbin')) { \OCA\Files_Trashbin\Storage::preRenameHook([]); } $owner = $this->getOwner($path); $this->unlink($path); if (App::isEnabled('files_trashbin')) { \OCA\Files_Trashbin\Storage::postRenameHook([]); } \OC::$server->getActivityManager()->publishActivity('files_antivirus', Activity::SUBJECT_VIRUS_DETECTED, [$path, $status->getDetails()], Activity::MESSAGE_FILE_DELETED, [], $path, '', $owner, Activity::TYPE_VIRUS_DETECTED, Activity::PRIORITY_HIGH); throw new InvalidContentException($this->l10n->t('Virus %s is detected in the file. Upload cannot be completed.', $status->getDetails())); } }); } catch (\Exception $e) { $message = implode(' ', [__CLASS__, __METHOD__, $e->getMessage()]); $this->logger->warning($message); } } return $stream; }
public function __construct(IL10N $l, ISession $session, ICredentialsManager $credentialsManager) { $this->session = $session; $this->credentialsManager = $credentialsManager; $this->setIdentifier('password::logincredentials')->setScheme(self::SCHEME_PASSWORD)->setText($l->t('Log-in credentials, save in database'))->addParameters([]); \OCP\Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); }
public function setUp() { parent::setUp(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($text, $parameters = array()) { return vsprintf($text, $parameters); })); }
/** * set log level for logger * * @param int $level * @return JSONResponse */ public function setLogLevel($level) { if ($level < 0 || $level > 4) { return new JSONResponse(['message' => (string) $this->l10n->t('log-level out of allowed range')], Http::STATUS_BAD_REQUEST); } $this->config->setSystemValue('loglevel', $level); return new JSONResponse(['level' => $level]); }
private function validatePrice() { $price = $this->request->getParam("price"); $name = $this->l10n->t("Price"); if (!$this->validator->validateRequired($name, $price)) { return; } $this->validator->validateFloat($name, $price); }
/** * Log error message and return a response which can be displayed to the user * * @param \OCP\AppFramework\Controller $controller * @param string $methodName * @param \Exception $exception * @return JSONResponse */ public function afterException($controller, $methodName, \Exception $exception) { $this->logger->error($exception->getMessage(), ['app' => $this->appName]); if ($exception instanceof HintException) { $message = $exception->getHint(); } else { $message = $this->l->t('Unknown error'); } return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST); }
/** * @param \OCP\IL10N $l * @return array Array "stringID of the type" => "translated string description for the setting" */ public function getNotificationTypes(\OCP\IL10N $l) { if (isset($this->notificationTypes[$l->getLanguageCode()])) { return $this->notificationTypes[$l->getLanguageCode()]; } // Allow apps to add new notification types $notificationTypes = $this->activityManager->getNotificationTypes($l->getLanguageCode()); $this->notificationTypes[$l->getLanguageCode()] = $notificationTypes; return $notificationTypes; }
protected function setUp() { parent::setUp(); $this->urlGenerator = $this->getMockBuilder('OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $this->infoCache = $this->getMockBuilder('OCA\\Activity\\ViewInfoCache')->disableOriginalConstructor()->getMock(); $this->l = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l->expects($this->any())->method('t')->willReturnCallback(function ($string, $parameters) { return vsprintf($string, $parameters); }); }
/** * @param string $id * @return DataResponse */ public function destroy($id) { $group = $this->groupManager->get($id); if ($group) { if ($group->delete()) { return new DataResponse(array('status' => 'success', 'data' => array('groupname' => $id)), Http::STATUS_NO_CONTENT); } } return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to delete group.'))), Http::STATUS_FORBIDDEN); }
protected function setUp() { parent::setUp(); $this->sessionMock = $this->getMockBuilder('OCA\\Encryption\\Session')->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMock('OCP\\IRequest'); $this->l10nMock = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10nMock->expects($this->any())->method('t')->will($this->returnCallback(function ($message) { return $message; })); $this->controller = new StatusController('encryptionTest', $this->requestMock, $this->l10nMock, $this->sessionMock); }
/** * Save Parameters * @param string $avMode - antivirus mode * @param string $avSocket - path to socket (Socket mode) * @param string $avHost - antivirus url * @param int $avPort - port * @param string $avCmdOptions - extra command line options * @param int $avChunkSize - Size of one portion * @param string $avPath - path to antivirus executable (Executable mode) * @param string $avInfectedAction - action performed on infected files * @return JSONResponse */ public function save($avMode, $avSocket, $avHost, $avPort, $avCmdOptions, $avChunkSize, $avPath, $avInfectedAction) { $this->settings->setAvMode($avMode); $this->settings->setAvSocket($avSocket); $this->settings->setAvHost($avHost); $this->settings->setAvPort($avPort); $this->settings->setAvCmdOptions($avCmdOptions); $this->settings->setAvChunkSize($avChunkSize); $this->settings->setAvPath($avPath); $this->settings->setAvInfectedAction($avInfectedAction); return new JSONResponse(array('data' => array('message' => (string) $this->l10n->t('Saved')), 'status' => 'success', 'settings' => $this->settings->getAllValues())); }
/** * @param \OCP\IL10N $l * @return array Array "stringID of the type" => "translated string description for the setting" */ public function getNotificationTypes(\OCP\IL10N $l) { if (isset($this->notificationTypes[$l->getLanguageCode()])) { return $this->notificationTypes[$l->getLanguageCode()]; } $notificationTypes = array(self::TYPE_SHARED => $l->t('A file or folder has been <strong>shared</strong>'), self::TYPE_SHARE_CREATED => $l->t('A new file or folder has been <strong>created</strong>'), self::TYPE_SHARE_CHANGED => $l->t('A file or folder has been <strong>changed</strong>'), self::TYPE_SHARE_DELETED => $l->t('A file or folder has been <strong>deleted</strong>'), self::TYPE_SHARE_RESTORED => $l->t('A file or folder has been <strong>restored</strong>')); // Allow other apps to add new notification types $additionalNotificationTypes = $this->activityManager->getNotificationTypes($l->getLanguageCode()); $notificationTypes = array_merge($notificationTypes, $additionalNotificationTypes); $this->notificationTypes[$l->getLanguageCode()] = $notificationTypes; return $notificationTypes; }
/** * @param IEvent $event * @param string $parameter The parameter to be formatted * @return string The formatted parameter */ public function format(IEvent $event, $parameter) { // If the username is empty, the action has been performed by a remote // user, or via a public share. We don't know the username in that case if ($parameter === '') { return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>'; } $user = $this->manager->get($parameter); $displayName = $user ? $user->getDisplayName() : $parameter; $parameter = Util::sanitizeHTML($parameter); return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>'; }
public function getNameString(IL10N $l10n) { $name = $this->getName(); if ($name === null) { $name = $l10n->t('Unknown artist'); if (!is_string($name)) { /** @var \OC_L10N_String $name */ $name = $name->__toString(); } } return $name; }
protected function setUp() { parent::setUp(); $this->manager = $this->getMockBuilder('OCA\\AnnouncementCenter\\Manager')->disableOriginalConstructor()->getMock(); $this->l = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l->expects($this->any())->method('t')->willReturnCallback(function ($string, $args) { return vsprintf($string, $args); }); $this->factory = $this->getMockBuilder('OCP\\L10N\\IFactory')->disableOriginalConstructor()->getMock(); $this->factory->expects($this->any())->method('get')->willReturn($this->l); $this->notifier = new NotificationsNotifier($this->manager, $this->factory); }
/** * @ControllerManaged * * @param boolean $scheduled */ protected function setBackupScheduled($scheduled) { $statusContainer = $this->backupService->createStatusInformation(); if ($statusContainer->getOverallStatus() == StatusContainer::ERROR) { throw new EasyBackupException($this->trans->t('Not all preconditions are met, backup cannot be scheduled')); } $this->configService->setBackupScheduled($scheduled); if ($scheduled) { $this->backupService->scheduleBackupJob(); } else { $this->backupService->unScheduleBackupJob(); } }
/** * @brief Translate an event string with the translations from the app where it was send from * @param string $app The app where this event comes from * @param string $text The text including placeholders * @param array $params The parameter for the placeholder * @param bool $stripPath Shall we strip the path from file names? * @param bool $highlightParams Shall we highlight the parameters in the string? * They will be highlighted with `<strong>`, all data will be passed through * \OCP\Util::sanitizeHTML() before, so no XSS is possible. * @return string translated */ public function translation($app, $text, $params, $stripPath = false, $highlightParams = false) { if (!$text) { return ''; } $preparedParams = $this->parameterHelper->prepareParameters($params, $this->parameterHelper->getSpecialParameterList($app, $text), $stripPath, $highlightParams); // Allow apps to correctly translate their activities $translation = $this->activityManager->translate($app, $text, $preparedParams, $stripPath, $highlightParams, $this->l->getLanguageCode()); if ($translation !== false) { return $translation; } $l = Util::getL10N($app, $this->l->getLanguageCode()); return $l->t($text, $preparedParams); }
/** * add server to the list of trusted ownCloud servers * * @param string $url * @return int * @throws HintException */ public function addServer($url) { $hash = $this->hash($url); $query = $this->connection->getQueryBuilder(); $query->insert($this->dbTable)->values(['url' => $query->createParameter('url'), 'url_hash' => $query->createParameter('url_hash')])->setParameter('url', $url)->setParameter('url_hash', $hash); $result = $query->execute(); if ($result) { return (int) $this->connection->lastInsertId('*PREFIX*' . $this->dbTable); } else { $message = 'Internal failure, Could not add ownCloud as trusted server: ' . $url; $message_t = $this->l->t('Could not add server'); throw new HintException($message, $message_t); } }
/** * Get all available categories * @return array */ public function listCategories() { $categories = array(array('id' => 0, 'displayName' => (string) $this->l10n->t('Enabled')), array('id' => 1, 'displayName' => (string) $this->l10n->t('Not enabled'))); if ($this->config->getSystemValue('appstoreenabled', true)) { $categories[] = array('id' => 2, 'displayName' => (string) $this->l10n->t('Recommended')); // apps from external repo via OCS $ocs = \OC_OCSClient::getCategories(); foreach ($ocs as $k => $v) { $categories[] = array('id' => $k, 'displayName' => str_replace('ownCloud ', '', $v)); } } $categories['status'] = 'success'; return $categories; }
public function setUp() { $this->request = $this->getMockBuilder('\\OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($message, array $replace) { return vsprintf($message, $replace); })); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->connection = $this->getMockBuilder('\\OC\\DB\\Connection')->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder('\\OCP\\IUserManager')->disableOriginalConstructor()->getMock(); $this->view = $this->getMockBuilder('\\OC\\Files\\View')->disableOriginalConstructor()->getMock(); $this->logger = $this->getMockBuilder('\\OCP\\ILogger')->disableOriginalConstructor()->getMock(); $this->encryptionController = $this->getMockBuilder('\\OC\\Settings\\Controller\\EncryptionController')->setConstructorArgs(['settings', $this->request, $this->l10n, $this->config, $this->connection, $this->userManager, $this->view, $this->logger])->setMethods(['getMigration'])->getMock(); }
public function setUp() { parent::setUp(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMockBuilder('\\OCP\\Mail\\IMailer')->disableOriginalConstructor()->getMock(); $this->logger = $this->getMockBuilder('\\OCP\\ILogger')->disableOriginalConstructor()->getMock(); $this->defaults = $this->getMockBuilder('\\OCP\\Defaults')->disableOriginalConstructor()->getMock(); $this->user = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($text, $parameters = array()) { return vsprintf($text, $parameters); })); $this->defaults->expects($this->once())->method('getName')->will($this->returnValue('UnitTestCloud')); $this->user->expects($this->once())->method('getEMailAddress')->willReturn('*****@*****.**'); $this->user->expects($this->once())->method('getDisplayName')->willReturn('TestUser'); }
public function setUp() { parent::setUp(); $this->storageMock = $this->getMockBuilder('OCP\\Files\\Storage')->disableOriginalConstructor()->getMock(); $this->cryptMock = $this->getMockBuilder('OCA\\Encryption\\Crypto\\Crypt')->disableOriginalConstructor()->getMock(); $this->utilMock = $this->getMockBuilder('OCA\\Encryption\\Util')->disableOriginalConstructor()->getMock(); $this->keyManagerMock = $this->getMockBuilder('OCA\\Encryption\\KeyManager')->disableOriginalConstructor()->getMock(); $this->sessionMock = $this->getMockBuilder('OCA\\Encryption\\Session')->disableOriginalConstructor()->getMock(); $this->encryptAllMock = $this->getMockBuilder('OCA\\Encryption\\Crypto\\EncryptAll')->disableOriginalConstructor()->getMock(); $this->decryptAllMock = $this->getMockBuilder('OCA\\Encryption\\Crypto\\DecryptAll')->disableOriginalConstructor()->getMock(); $this->loggerMock = $this->getMockBuilder('OCP\\ILogger')->disableOriginalConstructor()->getMock(); $this->l10nMock = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10nMock->expects($this->any())->method('t')->with($this->anything())->willReturnArgument(0); $this->instance = new Encryption($this->cryptMock, $this->keyManagerMock, $this->utilMock, $this->sessionMock, $this->encryptAllMock, $this->decryptAllMock, $this->loggerMock, $this->l10nMock); }
public function setUp() { parent::setUp(); $this->request = $this->getMockBuilder('\\OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $this->clientService = $this->getMockBuilder('\\OCP\\Http\\Client\\IClientService')->disableOriginalConstructor()->getMock(); $this->util = $this->getMockBuilder('\\OC_Util')->disableOriginalConstructor()->getMock(); $this->urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnCallback(function ($message, array $replace) { return vsprintf($message, $replace); })); $this->checkSetupController = $this->getMockBuilder('\\OC\\Settings\\Controller\\CheckSetupController')->setConstructorArgs(['settings', $this->request, $this->config, $this->clientService, $this->urlGenerator, $this->util, $this->l10n])->setMethods(['getCurlVersion'])->getMock(); }
public function setUp() { parent::setUp(); $this->request = $this->getMockBuilder('\\OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->l10n = $this->getMockBuilder('\\OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l10n->expects($this->any())->method('t')->will($this->returnArgument(0)); $this->config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock(); $cacheFactory = $this->getMockBuilder('\\OCP\\ICacheFactory')->disableOriginalConstructor()->getMock(); $this->cache = $this->getMockBuilder('\\OCP\\ICache')->disableOriginalConstructor()->getMock(); $cacheFactory->expects($this->once())->method('create')->with('settings')->will($this->returnValue($this->cache)); $this->navigationManager = $this->getMockBuilder('\\OCP\\INavigationManager')->disableOriginalConstructor()->getMock(); $this->appManager = $this->getMockBuilder('\\OCP\\App\\IAppManager')->disableOriginalConstructor()->getMock(); $this->ocsClient = $this->getMockBuilder('\\OC\\OCSClient')->disableOriginalConstructor()->getMock(); $this->appSettingsController = new AppSettingsController('settings', $this->request, $this->l10n, $this->config, $cacheFactory, $this->navigationManager, $this->appManager, $this->ocsClient); }
public function setUp() { $this->logger = $this->getMock('\\OCP\\ILogger'); $this->config = $this->getMock('\\OCP\\IConfig'); $this->defaultProvider = $this->getMock('\\OC\\Share20\\IShareProvider'); $this->secureRandom = $this->getMock('\\OCP\\Security\\ISecureRandom'); $this->hasher = $this->getMock('\\OCP\\Security\\IHasher'); $this->mountManager = $this->getMock('\\OCP\\Files\\Mount\\IMountManager'); $this->groupManager = $this->getMock('\\OCP\\IGroupManager'); $this->l = $this->getMock('\\OCP\\IL10N'); $this->l->method('t')->will($this->returnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); })); $this->manager = new Manager($this->logger, $this->config, $this->defaultProvider, $this->secureRandom, $this->hasher, $this->mountManager, $this->groupManager, $this->l); }
protected function setUp() { parent::setUp(); $this->request = $this->getMockBuilder('OCP\\IRequest')->disableOriginalConstructor()->getMock(); $this->groupManager = $this->getMockBuilder('OCP\\IGroupManager')->disableOriginalConstructor()->getMock(); $this->userManager = $this->getMockBuilder('OCP\\IUserManager')->disableOriginalConstructor()->getMock(); $this->activityManager = $this->getMockBuilder('OCP\\Activity\\IManager')->disableOriginalConstructor()->getMock(); $this->notificationManager = $this->getMockBuilder('OC\\Notification\\IManager')->disableOriginalConstructor()->getMock(); $this->l = $this->getMockBuilder('OCP\\IL10N')->disableOriginalConstructor()->getMock(); $this->l->expects($this->any())->method('t')->willReturnCallback(function ($string, $args) { return vsprintf($string, $args); }); $this->urlGenerator = $this->getMockBuilder('OCP\\IURLGenerator')->disableOriginalConstructor()->getMock(); $this->manager = $this->getMockBuilder('OCA\\AnnouncementCenter\\Manager')->disableOriginalConstructor()->getMock(); }