/**
  * 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]);
 }
Beispiel #3
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();
 }
 /**
  * @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');
     }
 }
Beispiel #5
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);
             }
         }
     }
 }
Beispiel #6
0
 public function upgrade()
 {
     $previousVersion = $this->config->getAppValue($this->appName, 'installed_version');
     if (version_compare($previousVersion, '7', '<')) {
         $this->itemService->generateSearchIndices();
     }
 }
 /**
  * Checks whether public sharing (via links) is enabled
  *
  * @return bool
  */
 private function isSharingEnabled()
 {
     $shareApiAllowLinks = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
     if ($shareApiAllowLinks !== 'yes') {
         return false;
     }
     return true;
 }
 /**
  * @return array (string => string|int)
  */
 public function getData()
 {
     $data = ['enabled' => $this->config->getAppValue('core', 'encryption_enabled', 'no') ? 'yes' : 'no', 'default_module' => $this->config->getAppValue('core', 'default_encryption_module') === 'OC_DEFAULT_MODULE' ? 'yes' : 'no'];
     if ($data['enabled'] === 'yes') {
         unset($data['default_module']);
     }
     return $data;
 }
Beispiel #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') {
         $output->writeln('Encryption is already disabled');
     } else {
         $this->config->setAppValue('core', 'encryption_enabled', 'no');
         $output->writeln('<info>Encryption disabled</info>');
     }
 }
Beispiel #10
0
 /**
  * @param IConfig $config
  */
 public function __construct(IConfig $config)
 {
     $this->config = $config;
     // Load config values
     if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
         $this->userMountingAllowed = false;
     }
     $this->userMountingBackends = explode(',', $this->config->getAppValue('files_external', 'user_mounting_backends', ''));
 }
 /**
  * @param string $appName
  * @param string $oldId
  * @param string $newId
  * @return bool True if updated, false otherwise
  */
 public function fixOcsId($appName, $oldId, $newId)
 {
     $existingId = $this->config->getAppValue($appName, 'ocsid');
     if ($existingId === $oldId) {
         $this->config->setAppValue($appName, 'ocsid', $newId);
         return true;
     }
     return false;
 }
Beispiel #12
0
 /**
  * @param IConfig $config
  * @param View $view
  * @param Connection $connection
  * @param ILogger $logger
  */
 public function __construct(IConfig $config, View $view, Connection $connection, ILogger $logger)
 {
     $this->view = $view;
     $this->view->getUpdater()->disable();
     $this->connection = $connection;
     $this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
     $this->config = $config;
     $this->logger = $logger;
     $this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1');
 }
 /**
  * Get all shares we need to update the etag for
  *
  * @param array $shares the shares for the users
  * @return string[]
  */
 protected function getDirtyShares($shares)
 {
     $dirty = [];
     $userTime = $this->config->getUserValue($this->userId, 'files_sharing', 'last_propagate', 0);
     foreach ($shares as $share) {
         $updateTime = $this->config->getAppValue('files_sharing', $share['id'], 0);
         if ($updateTime >= $userTime) {
             $dirty[] = $share;
         }
     }
     return $dirty;
 }
Beispiel #14
0
 /**
  * @param IConfig $config
  */
 public function __construct(IConfig $config)
 {
     $this->config = $config;
     // Load config values
     if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') {
         $this->userMountingAllowed = false;
     }
     $this->userMountingBackends = explode(',', $this->config->getAppValue('files_external', 'user_mounting_backends', ''));
     // if no backend is in the list an empty string is in the array and user mounting is disabled
     if ($this->userMountingBackends === ['']) {
         $this->userMountingAllowed = false;
     }
 }
 /**
  * Check whether sharing is enabled
  * @return bool
  */
 private function isSharingEnabled()
 {
     // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app
     // Check whether the sharing application is enabled
     if (!$this->appManager->isEnabledForUser($this->appName)) {
         return false;
     }
     // Check whether public sharing is enabled
     if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
         return false;
     }
     return true;
 }
 /**
  * @return TemplateResponse
  */
 public function displayPanel()
 {
     $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($this->config->getAppValue('core', 'lastupdatedat'));
     $channels = ['daily', 'beta', 'stable', 'production'];
     $currentChannel = \OCP\Util::getChannel();
     // Remove the currently used channel from the channels list
     if (($key = array_search($currentChannel, $channels)) !== false) {
         unset($channels[$key]);
     }
     $updateState = $this->updateChecker->getUpdateState();
     $params = ['isNewVersionAvailable' => $updateState === [] ? false : true, 'lastChecked' => $lastUpdateCheck, 'currentChannel' => $currentChannel, 'channels' => $channels, 'newVersionString' => $updateState === [] ? '' : $updateState['updateVersion']];
     return new TemplateResponse($this->appName, 'admin', $params, '');
 }
Beispiel #17
0
	/**
	 * Check if a new version is available
	 *
	 * @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php'
	 * @return array|bool
	 */
	public function check($updaterUrl = null) {

		// Look up the cache - it is invalidated all 30 minutes
		if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
			return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
		}

		if (is_null($updaterUrl)) {
			$updaterUrl = 'https://apps.owncloud.com/updater.php';
		}

		$this->config->setAppValue('core', 'lastupdatedat', time());

		if ($this->config->getAppValue('core', 'installedat', '') == '') {
			$this->config->setAppValue('core', 'installedat', microtime(true));
		}

		$version = \OC_Util::getVersion();
		$version['installed'] = $this->config->getAppValue('core', 'installedat');
		$version['updated'] = $this->config->getAppValue('core', 'lastupdatedat');
		$version['updatechannel'] = \OC_Util::getChannel();
		$version['edition'] = \OC_Util::getEditionString();
		$version['build'] = \OC_Util::getBuild();
		$versionString = implode('x', $version);

		//fetch xml data from updater
		$url = $updaterUrl . '?version=' . $versionString;

		// set a sensible timeout of 10 sec to stay responsive even if the update server is down.

		$tmp = array();
		$xml = $this->httpHelper->getUrlContent($url);
		if ($xml) {
			$loadEntities = libxml_disable_entity_loader(true);
			$data = @simplexml_load_string($xml);
			libxml_disable_entity_loader($loadEntities);
			if ($data !== false) {
				$tmp['version'] = $data->version;
				$tmp['versionstring'] = $data->versionstring;
				$tmp['url'] = $data->url;
				$tmp['web'] = $data->web;
			}
		} else {
			$data = array();
		}

		// Cache the result
		$this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
		return $tmp;
	}
Beispiel #18
0
 /**
  * Get all mountpoints we need to update the etag for
  *
  * @return string[]
  */
 protected function getDirtyMountPoints()
 {
     $dirty = array();
     $mountPoints = $this->config->getAppKeys('files_external');
     foreach ($mountPoints as $mountPoint) {
         if (substr($mountPoint, 0, 1) === '/') {
             $updateTime = $this->config->getAppValue('files_external', $mountPoint);
             $userTime = $this->config->getUserValue($this->user->getUID(), 'files_external', $mountPoint);
             if ($updateTime > $userTime) {
                 $dirty[] = $mountPoint;
             }
         }
     }
     return $dirty;
 }
 protected function setUpEncryptionTrait()
 {
     $isReady = \OC::$server->getEncryptionManager()->isReady();
     if (!$isReady) {
         $this->markTestSkipped('Encryption not ready');
     }
     \OC_App::loadApp('encryption');
     $this->encryptionApp = new Application([], $isReady);
     $this->config = \OC::$server->getConfig();
     $this->encryptionWasEnabled = $this->config->getAppValue('core', 'encryption_enabled', 'no');
     $this->originalEncryptionModule = $this->config->getAppValue('core', 'default_encryption_module');
     $this->config->setAppValue('core', 'default_encryption_module', \OCA\Encryption\Crypto\Encryption::ID);
     $this->config->setAppValue('core', 'encryption_enabled', 'yes');
     $this->assertTrue(\OC::$server->getEncryptionManager()->isEnabled());
 }
Beispiel #20
0
 /**
  * returns the home directory of the user if specified by LDAP settings
  * @param string $valueFromLDAP
  * @return bool|string
  * @throws \Exception
  */
 public function getHomePath($valueFromLDAP = null)
 {
     $path = $valueFromLDAP;
     $attr = null;
     if (is_null($path) && strpos($this->access->connection->homeFolderNamingRule, 'attr:') === 0 && $this->access->connection->homeFolderNamingRule !== 'attr:') {
         $attr = substr($this->access->connection->homeFolderNamingRule, strlen('attr:'));
         $homedir = $this->access->readAttribute($this->access->username2dn($this->getUsername()), $attr);
         if ($homedir && isset($homedir[0])) {
             $path = $homedir[0];
         }
     }
     if (!empty($path)) {
         //if attribute's value is an absolute path take this, otherwise append it to data dir
         //check for / at the beginning or pattern c:\ resp. c:/
         if ('/' !== $path[0] && !(3 < strlen($path) && ctype_alpha($path[0]) && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2]))) {
             $path = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $path;
         }
         //we need it to store it in the DB as well in case a user gets
         //deleted so we can clean up afterwards
         $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', $path);
         return $path;
     }
     if (!is_null($attr) && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true)) {
         // a naming rule attribute is defined, but it doesn't exist for that LDAP user
         throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername());
     }
     //false will apply default behaviour as defined and done by OC_User
     $this->config->setUserValue($this->getUsername(), 'user_ldap', 'homePath', '');
     return false;
 }
Beispiel #21
0
 /**
  * @return \OC_OCS_Result
  */
 public function search()
 {
     $search = isset($_GET['search']) ? (string) $_GET['search'] : '';
     $itemType = isset($_GET['itemType']) ? (string) $_GET['itemType'] : null;
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $perPage = isset($_GET['perPage']) ? (int) $_GET['perPage'] : 200;
     if ($perPage <= 0) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST, 'Invalid perPage argument');
     }
     if ($page <= 0) {
         return new \OC_OCS_Result(null, Http::STATUS_BAD_REQUEST, 'Invalid page');
     }
     $shareTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE];
     if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
         $shareTypes = array_intersect($shareTypes, $_GET['shareType']);
         sort($shareTypes);
     } else {
         if (isset($_GET['shareType']) && is_numeric($_GET['shareType'])) {
             $shareTypes = array_intersect($shareTypes, [(int) $_GET['shareType']]);
             sort($shareTypes);
         }
     }
     if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes) && !$this->isRemoteSharingAllowed($itemType)) {
         // Remove remote shares from type array, because it is not allowed.
         $shareTypes = array_diff($shareTypes, [Share::SHARE_TYPE_REMOTE]);
     }
     $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
     $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
     $this->limit = (int) $perPage;
     $this->offset = $perPage * ($page - 1);
     return $this->searchSharees($search, $itemType, $shareTypes, $page, $perPage);
 }
Beispiel #22
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  * @return null|int null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $appName = $input->getArgument('app');
     $configName = $input->getArgument('name');
     $defaultValue = $input->getOption('default-value');
     if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) {
         return 1;
     }
     if (!in_array($configName, $this->config->getAppKeys($appName))) {
         $configValue = $defaultValue;
     } else {
         $configValue = $this->config->getAppValue($appName, $configName);
     }
     $this->writeMixedInOutputFormat($input, $output, $configValue);
     return 0;
 }
Beispiel #23
0
 /**
  * @param IStorage $keyStorage
  * @param Crypt $crypt
  * @param IConfig $config
  * @param IUserSession $userSession
  * @param Session $session
  * @param ILogger $log
  * @param Util $util
  */
 public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, IUserSession $userSession, Session $session, ILogger $log, Util $util)
 {
     $this->util = $util;
     $this->session = $session;
     $this->keyStorage = $keyStorage;
     $this->crypt = $crypt;
     $this->config = $config;
     $this->log = $log;
     $this->recoveryKeyId = $this->config->getAppValue('encryption', 'recoveryKeyId');
     if (empty($this->recoveryKeyId)) {
         $this->recoveryKeyId = 'recoveryKey_' . substr(md5(time()), 0, 8);
         $this->config->setAppValue('encryption', 'recoveryKeyId', $this->recoveryKeyId);
     }
     $this->publicShareKeyId = $this->config->getAppValue('encryption', 'publicShareKeyId');
     if (empty($this->publicShareKeyId)) {
         $this->publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
         $this->config->setAppValue('encryption', 'publicShareKeyId', $this->publicShareKeyId);
     }
     $this->masterKeyId = $this->config->getAppValue('encryption', 'masterKeyId');
     if (empty($this->masterKeyId)) {
         $this->masterKeyId = 'master_' . substr(md5(time()), 0, 8);
         $this->config->setAppValue('encryption', 'masterKeyId', $this->masterKeyId);
     }
     $this->keyId = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
     $this->log = $log;
 }
Beispiel #24
0
 /**
  * @param IStorage $keyStorage
  * @param Crypt $crypt
  * @param IConfig $config
  * @param IUserSession $userSession
  * @param Session $session
  * @param ILogger $log
  * @param Util $util
  */
 public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, IUserSession $userSession, Session $session, ILogger $log, Util $util)
 {
     $this->util = $util;
     $this->session = $session;
     $this->keyStorage = $keyStorage;
     $this->crypt = $crypt;
     $this->config = $config;
     $this->log = $log;
     $this->recoveryKeyId = $this->config->getAppValue('encryption', 'recoveryKeyId');
     if (empty($this->recoveryKeyId)) {
         $this->recoveryKeyId = 'recoveryKey_' . substr(md5(time()), 0, 8);
         $this->config->setAppValue('encryption', 'recoveryKeyId', $this->recoveryKeyId);
     }
     $this->publicShareKeyId = $this->config->getAppValue('encryption', 'publicShareKeyId');
     if (empty($this->publicShareKeyId)) {
         $this->publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8);
         $this->config->setAppValue('encryption', 'publicShareKeyId', $this->publicShareKeyId);
     }
     $shareKey = $this->getPublicShareKey();
     if (empty($shareKey)) {
         $keyPair = $this->crypt->createKeyPair();
         // Save public key
         $this->keyStorage->setSystemUserKey($this->publicShareKeyId . '.publicKey', $keyPair['publicKey']);
         // Encrypt private key empty passphrase
         $encryptedKey = $this->crypt->symmetricEncryptFileContent($keyPair['privateKey'], '');
         $this->keyStorage->setSystemUserKey($this->publicShareKeyId . '.privateKey', $encryptedKey);
     }
     $this->keyId = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false;
     $this->log = $log;
 }
Beispiel #25
0
 /**
  * @return \OC_OCS_Result
  */
 public function search()
 {
     $search = isset($_GET['search']) ? (string) $_GET['search'] : '';
     $itemType = isset($_GET['itemType']) ? (string) $_GET['itemType'] : null;
     $page = !empty($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
     $perPage = !empty($_GET['limit']) ? max(1, (int) $_GET['limit']) : 200;
     $shareTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE];
     if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
         $shareTypes = array_intersect($shareTypes, $_GET['shareType']);
         sort($shareTypes);
     } else {
         if (isset($_GET['shareType']) && is_numeric($_GET['shareType'])) {
             $shareTypes = array_intersect($shareTypes, [(int) $_GET['shareType']]);
             sort($shareTypes);
         }
     }
     if (in_array(Share::SHARE_TYPE_REMOTE, $shareTypes) && !$this->isRemoteSharingAllowed($itemType)) {
         // Remove remote shares from type array, because it is not allowed.
         $shareTypes = array_diff($shareTypes, [Share::SHARE_TYPE_REMOTE]);
     }
     $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
     $this->limit = (int) $perPage;
     $this->offset = $perPage * ($page - 1);
     return $this->searchSharees(strtolower($search), $itemType, $shareTypes, $page, $perPage);
 }
Beispiel #26
0
 /**
  * @return array
  */
 public function getResults()
 {
     $cachedResults = $this->cache->get(self::CACHE_KEY);
     if (!is_null($cachedResults)) {
         return json_decode($cachedResults, true);
     }
     return json_decode($this->config->getAppValue('core', self::CACHE_KEY, '{}'), true);
 }
Beispiel #27
0
 /**
  * get default encryption module Id
  *
  * @return string
  */
 protected function getDefaultEncryptionModuleId()
 {
     try {
         return $this->config->getAppValue('core', 'default_encryption_module');
     } catch (\Exception $e) {
         return '';
     }
 }
 /**
  * Determines if we can add external shared to this instance
  *
  * @return array<bool,string>
  */
 private function getServer2ServerProperties()
 {
     $server2ServerSharing = $this->appConfig->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
     $server2ServerSharing = $server2ServerSharing === 'yes' ? true : false;
     $password = $this->environment->getSharePassword();
     $passwordProtected = $password ? 'true' : 'false';
     return [$server2ServerSharing, $passwordProtected];
 }
Beispiel #29
0
 /**
  * get the users' quota
  *
  * @return string
  * @since 9.0.0
  */
 public function getQuota()
 {
     $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
     if ($quota === 'default') {
         $quota = $this->config->getAppValue('files', 'default_quota', 'none');
     }
     return $quota;
 }
 /**
  * Only run the repair once
  */
 public function testOnlyRunOnce()
 {
     $this->outputMock->expects($this->exactly(1))->method('info');
     $this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_'));
     $this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
     $this->repair->run($this->outputMock);
     $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
     $this->outputMock->expects($this->never())->method('info');
     $this->repair->run($this->outputMock);
     $this->assertEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone'));
 }