/**
  * Enables the files app if it is disabled
  */
 public function run()
 {
     if ($this->config->getAppValue('files', 'enabled', 'no') !== 'yes') {
         $this->config->setAppValue('files', 'enabled', 'yes');
         $this->emit('\\OC\\Repair', 'info', ['Files app was disabled - re-enabled']);
     }
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function index()
 {
     $userId = $this->userSession->getUser()->getUID();
     $appVersion = $this->config->getAppValue($this->appName, 'installed_version');
     $defaultView = $this->config->getUserValue($userId, $this->appName, 'currentView', 'month');
     return new TemplateResponse('calendar', 'main', ['appVersion' => $appVersion, 'defaultView' => $defaultView]);
 }
Example #3
0
 /**
  * Validates a username and password
  *
  * This method should return true or false depending on if login
  * succeeded.
  *
  * @param string $username
  * @param string $password
  *
  * @return bool
  */
 protected function validateUserPass($username, $password)
 {
     $linkItem = \OCP\Share::getShareByToken($username, false);
     \OC_User::setIncognitoMode(true);
     $this->share = $linkItem;
     if (!$linkItem) {
         return false;
     }
     // check if the share is password protected
     if (isset($linkItem['share_with'])) {
         if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
             // Check Password
             $forcePortable = CRYPT_BLOWFISH != 1;
             $hasher = new \PasswordHash(8, $forcePortable);
             if (!$hasher->CheckPassword($password . $this->config->getSystemValue('passwordsalt', ''), $linkItem['share_with'])) {
                 return false;
             } else {
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
Example #4
0
 /**
  * @param $argument
  * @throws \Exception
  */
 protected function run($argument)
 {
     $maxAge = $this->expiration->getMaxAgeAsTimestamp();
     if (!$maxAge) {
         return;
     }
     $offset = $this->config->getAppValue('files_trashbin', 'cronjob_user_offset', 0);
     $users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
     if (!count($users)) {
         // No users found, reset offset and retry
         $offset = 0;
         $users = $this->userManager->search('', self::USERS_PER_SESSION);
     }
     $offset += self::USERS_PER_SESSION;
     $this->config->setAppValue('files_trashbin', 'cronjob_user_offset', $offset);
     foreach ($users as $user) {
         $uid = $user->getUID();
         if (!$this->setupFS($uid)) {
             continue;
         }
         $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
         Trashbin::deleteExpiredFiles($dirContent, $uid);
     }
     \OC_Util::tearDownFS();
 }
Example #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $includeExpensive = $input->getOption('include-expensive');
     if ($includeExpensive) {
         foreach ($this->repair->getExpensiveRepairSteps() as $step) {
             $this->repair->addStep($step);
         }
     }
     $maintenanceMode = $this->config->getSystemValue('maintenance', false);
     $this->config->setSystemValue('maintenance', true);
     $this->repair->listen('\\OC\\Repair', 'step', function ($description) use($output) {
         $output->writeln(' - ' . $description);
     });
     $this->repair->listen('\\OC\\Repair', 'info', function ($description) use($output) {
         $output->writeln('     - ' . $description);
     });
     $this->repair->listen('\\OC\\Repair', 'warning', function ($description) use($output) {
         $output->writeln('     - WARNING: ' . $description);
     });
     $this->repair->listen('\\OC\\Repair', 'error', function ($description) use($output) {
         $output->writeln('     - ERROR: ' . $description);
     });
     $this->repair->run();
     $this->config->setSystemValue('maintenance', $maintenanceMode);
 }
Example #6
0
 /**
  * Generate a keypair
  *
  * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
  */
 public function createKey()
 {
     $rsa = new RSACrypt();
     $rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
     $rsa->setPassword($this->config->getSystemValue('secret', ''));
     return $rsa->createKey(self::CREATE_KEY_BITS);
 }
Example #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $importFile = $input->getArgument('file');
     if ($importFile !== null) {
         $content = $this->getArrayFromFile($importFile);
     } else {
         $content = $this->getArrayFromStdin();
     }
     try {
         $configs = $this->validateFileContent($content);
     } catch (\UnexpectedValueException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     if (!empty($configs['system'])) {
         $this->config->setSystemValues($configs['system']);
     }
     if (!empty($configs['apps'])) {
         foreach ($configs['apps'] as $app => $appConfigs) {
             foreach ($appConfigs as $key => $value) {
                 if ($value === null) {
                     $this->config->deleteAppValue($app, $key);
                 } else {
                     $this->config->setAppValue($app, $key, $value);
                 }
             }
         }
     }
     $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>');
 }
 public function testSetException()
 {
     $this->config->expects($this->once())->method('setUserValue')->with('JohnDoe', 'contacts', 'keyValue', 'valueValue')->will($this->throwException(new \Exception()));
     $expected = new JSONResponse();
     $expected->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR);
     $this->assertEquals($expected, $this->controller->set('keyValue', 'valueValue'));
 }
Example #9
0
 /**
  * @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;
     }
 }
Example #10
0
 /**
  * @param array $parameters
  * @return \OC_OCS_Result
  */
 public function deleteAppValue($parameters)
 {
     $app = $parameters['appid'];
     $configKey = $parameters['configkey'];
     $this->config->deleteAppValue($app, $configKey);
     return new \OC_OCS_Result();
 }
Example #11
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $l = Util::getL10N('activity', $userLang);
         $l->forceLanguage($userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
     } catch (\UnexpectedValueException $e) {
         $l = Util::getL10N('activity');
         $description = (string) $l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
Example #12
0
 /**
  * Creates an url
  * @param string $app app
  * @param string $file file
  * @param array $args array with param=>value, will be appended to the returned url
  *    The value of $args will be urlencoded
  * @return string the url
  *
  * Returns a url to the given app and file.
  */
 public function linkTo($app, $file, $args = array())
 {
     $frontControllerActive = $this->config->getSystemValue('front_controller_active', 'false') == 'true';
     if ($app != '') {
         $app_path = \OC_App::getAppPath($app);
         // Check if the app is in the app folder
         if ($app_path && file_exists($app_path . '/' . $file)) {
             if (substr($file, -3) == 'php') {
                 $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
                 if ($frontControllerActive) {
                     $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
                 }
                 $urlLinkTo .= $file != 'index.php' ? '/' . $file : '';
             } else {
                 $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
             }
         } else {
             $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
         }
     } else {
         if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
             $urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
         } else {
             if ($frontControllerActive && $file === 'index.php') {
                 $urlLinkTo = \OC::$WEBROOT;
             } else {
                 $urlLinkTo = \OC::$WEBROOT . '/' . $file;
             }
         }
     }
     if ($args && ($query = http_build_query($args, '', '&'))) {
         $urlLinkTo .= '?' . $query;
     }
     return $urlLinkTo;
 }
Example #13
0
 public function upgrade()
 {
     $previousVersion = $this->config->getAppValue($this->appName, 'installed_version');
     if (version_compare($previousVersion, '7', '<')) {
         $this->itemService->generateSearchIndices();
     }
 }
Example #14
0
 /**
  * Send an email to {$limit} users
  *
  * @param int $limit Number of users we want to send an email to
  * @param int $sendTime The latest send time
  * @return int Number of users we sent an email to
  */
 protected function runStep($limit, $sendTime)
 {
     // Get all users which should receive an email
     $affectedUsers = $this->mqHandler->getAffectedUsers($limit, $sendTime);
     if (empty($affectedUsers)) {
         // No users found to notify, mission abort
         return 0;
     }
     $userLanguages = $this->config->getUserValueForUsers('core', 'lang', $affectedUsers);
     $userTimezones = $this->config->getUserValueForUsers('core', 'timezone', $affectedUsers);
     $userEmails = $this->config->getUserValueForUsers('settings', 'email', $affectedUsers);
     // Send Email
     $default_lang = $this->config->getSystemValue('default_language', 'en');
     $defaultTimeZone = date_default_timezone_get();
     foreach ($affectedUsers as $user) {
         if (empty($userEmails[$user])) {
             // The user did not setup an email address
             // So we will not send an email :(
             $this->logger->debug("Couldn't send notification email to user '" . $user . "' (email address isn't set for that user)", ['app' => 'activity']);
             continue;
         }
         $language = !empty($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
         $timezone = !empty($userTimezones[$user]) ? $userTimezones[$user] : $defaultTimeZone;
         $this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $sendTime);
     }
     // Delete all entries we dealt with
     $this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
     return sizeof($affectedUsers);
 }
Example #15
0
 /**
  * @param OutputInterface $output
  */
 public function loadCommands(OutputInterface $output)
 {
     // $application is required to be defined in the register_command scripts
     $application = $this->application;
     require_once \OC::$SERVERROOT . '/core/register_command.php';
     if ($this->config->getSystemValue('installed', false)) {
         if (!\OCP\Util::needUpgrade()) {
             OC_App::loadApps();
             foreach (OC_App::getAllApps() as $app) {
                 $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
                 if (file_exists($file)) {
                     require $file;
                 }
             }
         } else {
             $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
         }
     } else {
         $output->writeln("ownCloud is not installed - only a limited number of commands are available");
     }
     $input = new ArgvInput();
     if ($input->getFirstArgument() !== 'check') {
         $errors = \OC_Util::checkServer(\OC::$server->getConfig());
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $output->writeln($error['error']);
                 $output->writeln($error['hint']);
                 $output->writeln('');
             }
             throw new \Exception("Environment not properly prepared.");
         }
     }
 }
 /**
  * Returns all certificates trusted by the user
  *
  * @return \OCP\ICertificate[]
  */
 public function listCertificates()
 {
     if (!$this->config->getSystemValue('installed', false)) {
         return array();
     }
     $path = $this->getPathToCertificates() . 'uploads/';
     if (!$this->view->is_dir($path)) {
         return array();
     }
     $result = array();
     $handle = $this->view->opendir($path);
     if (!is_resource($handle)) {
         return array();
     }
     while (false !== ($file = readdir($handle))) {
         if ($file != '.' && $file != '..') {
             try {
                 $result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
             } catch (\Exception $e) {
             }
         }
     }
     closedir($handle);
     return $result;
 }
 /**
  * Send an email to {$limit} users
  *
  * @param int $limit Number of users we want to send an email to
  * @return int Number of users we sent an email to
  */
 protected function runStep($limit)
 {
     // We don't use time() but "time() - 1" here, so we don't run into
     // runtime issues later and delete emails, which were created in the
     // same second, but were not collected for the emails.
     $sendTime = time() - 1;
     // Get all users which should receive an email
     $affectedUsers = $this->mqHandler->getAffectedUsers($limit, $sendTime);
     if (empty($affectedUsers)) {
         // No users found to notify, mission abort
         return 0;
     }
     $userLanguages = $this->config->getUserValueForUsers('core', 'lang', $affectedUsers);
     $userTimezones = $this->config->getUserValueForUsers('core', 'timezone', $affectedUsers);
     $userEmails = $this->config->getUserValueForUsers('settings', 'email', $affectedUsers);
     // Get all items for these users
     $mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
     // Send Email
     $default_lang = $this->config->getSystemValue('default_language', 'en');
     $defaultTimeZone = date_default_timezone_get();
     foreach ($mailData as $user => $data) {
         if (empty($userEmails[$user])) {
             // The user did not setup an email address
             // So we will not send an email :(
             $this->logger->debug("Couldn't send notification email to user '" . $user . "' (email address isn't set for that user)", ['app' => 'activity']);
             continue;
         }
         $language = !empty($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
         $timezone = !empty($userTimezones[$user]) ? $userTimezones[$user] : $defaultTimeZone;
         $this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $timezone, $data);
     }
     // Delete all entries we dealt with
     $this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
     return sizeof($affectedUsers);
 }
Example #18
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->config->getAppValue('core', 'encryption_enabled', 'no') === 'yes') {
         $output->writeln('Encryption is already enabled');
     } else {
         $this->config->setAppValue('core', 'encryption_enabled', 'yes');
         $output->writeln('<info>Encryption enabled</info>');
     }
     $output->writeln('');
     $modules = $this->encryptionManager->getEncryptionModules();
     if (empty($modules)) {
         $output->writeln('<error>No encryption module is loaded</error>');
     } else {
         $defaultModule = $this->config->getAppValue('core', 'default_encryption_module', null);
         if ($defaultModule === null) {
             $output->writeln('<error>No default module is set</error>');
         } else {
             if (!isset($modules[$defaultModule])) {
                 $output->writeln('<error>The current default module does not exist: ' . $defaultModule . '</error>');
             } else {
                 $output->writeln('Default module: ' . $defaultModule);
             }
         }
     }
 }
 /**
  * Add a new trusted domain
  * @param string $newTrustedDomain The newly to add trusted domain
  * @return array
  */
 public function trustedDomains($newTrustedDomain)
 {
     $trustedDomains = $this->config->getSystemValue('trusted_domains');
     $trustedDomains[] = $newTrustedDomain;
     $this->config->setSystemValue('trusted_domains', $trustedDomains);
     return $this->returnSuccess();
 }
 /**
  * @param $argument
  */
 protected function run($argument)
 {
     // Delete old tokens after 2 days
     if ($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) {
         $this->config->deleteSystemValue('updater.secret');
     }
 }
 protected function tearDownEncryptionTrait()
 {
     if ($this->config) {
         $this->config->setAppValue('core', 'encryption_enabled', $this->encryptionWasEnabled);
         $this->config->setAppValue('core', 'default_encryption_module', $this->originalEncryptionModule);
     }
 }
Example #22
0
 /**
  * Reset the single user mode and re-enable the trashbin app
  */
 protected function resetSingleUserAndTrashbin()
 {
     $this->config->setSystemValue('singleuser', $this->wasSingleUserModeEnabled);
     if ($this->wasTrashbinEnabled) {
         $this->appManager->enableApp('files_trashbin');
     }
 }
Example #23
0
 public function __destruct()
 {
     $this->config->setSystemValue('singleuser', $this->wasSingleUserModeEnabled);
     if ($this->wasTrashbinEnabled) {
         $this->appManager->enableApp('files_trashbin');
     }
 }
 public function testBeforeControllerWithSharingEnabled()
 {
     $this->appManager->expects($this->once())->method('isEnabledForUser')->with('files_sharing')->will($this->returnValue(true));
     $this->config->expects($this->at(0))->method('getAppValue')->with('core', 'shareapi_enabled', 'yes')->will($this->returnValue('yes'));
     $this->config->expects($this->at(1))->method('getAppValue')->with('core', 'shareapi_allow_links', 'yes')->will($this->returnValue('yes'));
     $this->sharingCheckMiddleware->beforeController($this->controllerMock, 'myMethod');
 }
Example #25
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // collate config setting to the end, to avoid partial configuration
     $toBeSet = [];
     if ($backend = $input->getOption('backend')) {
         $this->validateBackend($backend);
         $toBeSet['log_type'] = $backend;
     }
     if ($level = $input->getOption('level')) {
         if (is_numeric($level)) {
             $levelNum = $level;
             // sanity check
             $this->convertLevelNumber($levelNum);
         } else {
             $levelNum = $this->convertLevelString($level);
         }
         $toBeSet['loglevel'] = $levelNum;
     }
     if ($timezone = $input->getOption('timezone')) {
         $this->validateTimezone($timezone);
         $toBeSet['logtimezone'] = $timezone;
     }
     // set config
     foreach ($toBeSet as $option => $value) {
         $this->config->setSystemValue($option, $value);
     }
     // display configuration
     $backend = $this->config->getSystemValue('log_type', self::DEFAULT_BACKEND);
     $output->writeln('Enabled logging backend: ' . $backend);
     $levelNum = $this->config->getSystemValue('loglevel', self::DEFAULT_LOG_LEVEL);
     $level = $this->convertLevelNumber($levelNum);
     $output->writeln('Log level: ' . $level . ' (' . $levelNum . ')');
     $timezone = $this->config->getSystemValue('logtimezone', self::DEFAULT_TIMEZONE);
     $output->writeln('Log timezone: ' . $timezone);
 }
Example #26
0
 public function testIsTwoFactorAuthenticated()
 {
     $this->prepareProviders();
     $this->user->expects($this->once())->method('getUID')->will($this->returnValue('user123'));
     $this->config->expects($this->once())->method('getUserValue')->with('user123', 'core', 'two_factor_auth_disabled', 0)->will($this->returnValue(0));
     $this->assertTrue($this->manager->isTwoFactorAuthenticated($this->user));
 }
Example #27
0
 public function __construct(IConfig $config, ITimeFactory $timeFactory)
 {
     $this->timeFactory = $timeFactory;
     $this->retentionObligation = $config->getSystemValue('trashbin_retention_obligation', 'auto');
     if ($this->retentionObligation !== 'disabled') {
         $this->parseRetentionObligation();
     }
 }
 /**
  * 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]);
 }
 /**
  * @dataProvider newAndAlternateDesktopClientProvider
  * @param string $userAgent
  */
 public function testBeforeHandlerSuccess($userAgent)
 {
     /** @var \Sabre\HTTP\RequestInterface $request */
     $request = $this->getMock('\\Sabre\\HTTP\\RequestInterface');
     $request->expects($this->once())->method('getHeader')->with('User-Agent')->will($this->returnValue($userAgent));
     $this->config->expects($this->once())->method('getSystemValue')->with('minimum.supported.desktop.version', '1.7.0')->will($this->returnValue('1.7.0'));
     $this->blockLegacyClientVersionPlugin->beforeHandler($request);
 }
 public function testRunWithExpiredToken()
 {
     $this->timeFactory->expects($this->at(0))->method('getTime')->willReturn(1455131633);
     $this->timeFactory->expects($this->at(1))->method('getTime')->willReturn(1455045234);
     $this->config->expects($this->once())->method('getAppValue')->with('core', 'updater.secret.created', 1455045234);
     $this->config->expects($this->once())->method('deleteSystemValue')->with('updater.secret');
     $this->invokePrivate($this->resetTokenBackgroundJob, 'run', ['']);
 }