示例#1
0
 public function __destruct()
 {
     $this->config->setSystemValue('singleuser', $this->wasSingleUserModeEnabled);
     if ($this->wasTrashbinEnabled) {
         $this->appManager->enableApp('files_trashbin');
     }
 }
示例#2
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');
     }
 }
 /**
  * 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();
 }
示例#4
0
文件: repair.php 项目: kenwi/core
 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);
 }
示例#5
0
文件: manage.php 项目: rosarion/core
 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);
 }
 /**
  * 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]);
 }
示例#7
0
 /**
  * @return DataResponse
  */
 public function createCredentials()
 {
     // Create a new job and store the creation date
     $this->jobList->add('OCA\\UpdateNotification\\ResetTokenBackgroundJob');
     $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
     // Create a new token
     $newToken = $this->secureRandom->generate(64);
     $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
     return new DataResponse($newToken);
 }
示例#8
0
 /**
  * @param string $dataDir
  * @param string $userId
  * @throws \Exception
  */
 function prepareSettings($dataDir, $userId)
 {
     // hard-coded string as we want a predictable fixed length
     // no data will be written there
     $this->dataDir = $dataDir;
     $this->config->setSystemValue('datadirectory', $this->dataDir);
     $this->user = $userId;
     $this->legacyStorageId = 'local::' . $this->dataDir . $this->user . '/';
     $this->newStorageId = 'home::' . $this->user;
     \OC::$server->getUserManager()->createUser($this->user, $this->user);
 }
示例#9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('on')) {
         $this->config->setSystemValue('maintenance', true);
         $output->writeln('Maintenance mode enabled');
     } elseif ($input->getOption('off')) {
         $this->config->setSystemValue('maintenance', false);
         $output->writeln('Maintenance mode disabled');
     } else {
         if ($this->config->getSystemValue('maintenance', false)) {
             $output->writeln('Maintenance mode is currently enabled');
         } else {
             $output->writeln('Maintenance mode is currently disabled');
         }
     }
 }
示例#10
0
文件: crypt.php 项目: samj1912/repo
 /**
  * @medium
  * Test that data that is written by the crypto stream wrapper with AES 128
  * @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
  * @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
  * reassembly of its data
  */
 public function testStreamDecryptLongFileContentWithoutHeader()
 {
     // Generate a a random filename
     $filename = 'tmp-' . $this->getUniqueID() . '.test';
     $this->config->setSystemValue('cipher', 'AES-128-CFB');
     // Save long data as encrypted file using stream wrapper
     $cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
     $this->config->deleteSystemValue('cipher');
     // Test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // Disable encryption proxy to prevent recursive calls
     $proxyStatus = \OC_FileProxy::$enabled;
     \OC_FileProxy::$enabled = false;
     // Get file contents without using any wrapper to get it's actual contents on disk
     $retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
     // Check that the file was encrypted before being written to disk
     $this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
     // remove the header to check if we can also decrypt old files without a header,
     //  this files should fall back to AES-128
     $cryptedWithoutHeader = substr($retreivedCryptedFile, \OCA\Files_Encryption\Crypt::BLOCKSIZE);
     $this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader);
     // Re-enable proxy - our work is done
     \OC_FileProxy::$enabled = $proxyStatus;
     $decrypted = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
     $this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
     // Teardown
     $this->view->unlink($this->userId . '/files/' . $filename);
 }
示例#11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $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', 'error', function ($description) use($output) {
         $output->writeln('     - ERROR: ' . $description);
     });
     $this->repair->run();
     $this->config->setSystemValue('maintenance', $maintenanceMode);
 }
示例#12
0
 /**
  * runs the update actions in maintenance mode, does not upgrade the source files
  * except the main .htaccess file
  *
  * @param string $currentVersion current version to upgrade to
  * @param string $installedVersion previous version from which to upgrade from
  *
  * @throws \Exception
  */
 private function doUpgrade($currentVersion, $installedVersion)
 {
     // Stop update if the update is over several major versions
     $allowedPreviousVersion = $this->getAllowedPreviousVersion();
     if (!self::isUpgradePossible($installedVersion, $currentVersion, $allowedPreviousVersion)) {
         throw new \Exception('Updates between multiple major versions and downgrades are unsupported.');
     }
     // Update .htaccess files
     try {
         Setup::updateHtaccess();
         Setup::protectDataDirectory();
     } catch (\Exception $e) {
         throw new \Exception($e->getMessage());
     }
     // create empty file in data dir, so we can later find
     // out that this is indeed an ownCloud data directory
     // (in case it didn't exist before)
     file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
     // pre-upgrade repairs
     $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
     $repair->run();
     // simulate DB upgrade
     if ($this->simulateStepEnabled) {
         $this->checkCoreUpgrade();
         // simulate apps DB upgrade
         $this->checkAppUpgrade($currentVersion);
     }
     if ($this->updateStepEnabled) {
         $this->doCoreUpgrade();
         // update all shipped apps
         $disabledApps = $this->checkAppsRequirements();
         $this->doAppUpgrade();
         // upgrade appstore apps
         $this->upgradeAppStoreApps($disabledApps);
         // install new shipped apps on upgrade
         OC_App::loadApps('authentication');
         $errors = Installer::installShippedApps(true);
         foreach ($errors as $appId => $exception) {
             /** @var \Exception $exception */
             $this->log->logException($exception, ['app' => $appId]);
             $this->emit('\\OC\\Updater', 'failure', [$appId . ': ' . $exception->getMessage()]);
         }
         // post-upgrade repairs
         $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
         $repair->run();
         //Invalidate update feed
         $this->config->setAppValue('core', 'lastupdatedat', 0);
         // Check for code integrity if not disabled
         if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
             $this->emit('\\OC\\Updater', 'startCheckCodeIntegrity');
             $this->checker->runInstanceVerification();
             $this->emit('\\OC\\Updater', 'finishedCheckCodeIntegrity');
         }
         // only set the final version if everything went well
         $this->config->setSystemValue('version', implode('.', \OCP\Util::getVersion()));
     }
 }
示例#13
0
	/**
	 * runs the update actions in maintenance mode, does not upgrade the source files
	 * except the main .htaccess file
	 *
	 * @param string $currentVersion current version to upgrade to
	 * @param string $installedVersion previous version from which to upgrade from
	 *
	 * @throws \Exception
	 * @return bool true if the operation succeeded, false otherwise
	 */
	private function doUpgrade($currentVersion, $installedVersion) {
		// Stop update if the update is over several major versions
		if (!self::isUpgradePossible($installedVersion, $currentVersion)) {
			throw new \Exception('Updates between multiple major versions are unsupported.');
		}

		// Update .htaccess files
		try {
			Setup::updateHtaccess();
			Setup::protectDataDirectory();
		} catch (\Exception $e) {
			throw new \Exception($e->getMessage());
		}

		// create empty file in data dir, so we can later find
		// out that this is indeed an ownCloud data directory
		// (in case it didn't exist before)
		file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');

		// pre-upgrade repairs
		$repair = new Repair(Repair::getBeforeUpgradeRepairSteps());
		$this->emitRepairMessages($repair);
		$repair->run();

		// simulate DB upgrade
		if ($this->simulateStepEnabled) {
			$this->checkCoreUpgrade();

			// simulate apps DB upgrade
			$this->checkAppUpgrade($currentVersion);

		}

		if ($this->updateStepEnabled) {
			$this->doCoreUpgrade();

			// update all shipped apps
			$disabledApps = $this->checkAppsRequirements();
			$this->doAppUpgrade();

			// upgrade appstore apps
			$this->upgradeAppStoreApps($disabledApps);


			// post-upgrade repairs
			$repair = new Repair(Repair::getRepairSteps());
			$this->emitRepairMessages($repair);
			$repair->run();

			//Invalidate update feed
			$this->config->setAppValue('core', 'lastupdatedat', 0);

			// only set the final version if everything went well
			$this->config->setSystemValue('version', implode('.', \OC_Util::getVersion()));
		}
	}
示例#14
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $toBeSet = [];
     if ($input->getOption('enable')) {
         $toBeSet['log_type'] = 'owncloud';
     }
     if ($file = $input->getOption('file')) {
         $toBeSet['logfile'] = $file;
     }
     if (($rotateSize = $input->getOption('rotate-size')) !== null) {
         $rotateSize = \OCP\Util::computerFileSize($rotateSize);
         $this->validateRotateSize($rotateSize);
         $toBeSet['log_rotate_size'] = $rotateSize;
     }
     // set config
     foreach ($toBeSet as $option => $value) {
         $this->config->setSystemValue($option, $value);
     }
     // display config
     if ($this->config->getSystemValue('log_type', 'owncloud') === 'owncloud') {
         $enabledText = 'enabled';
     } else {
         $enabledText = 'disabled';
     }
     $output->writeln('Log backend ownCloud: ' . $enabledText);
     $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
     $defaultLogFile = rtrim($dataDir, '/') . '/owncloud.log';
     $output->writeln('Log file: ' . $this->config->getSystemValue('logfile', $defaultLogFile));
     $rotateSize = $this->config->getSystemValue('log_rotate_size', 0);
     if ($rotateSize) {
         $rotateString = \OCP\Util::humanFileSize($rotateSize);
     } else {
         $rotateString = 'disabled';
     }
     $output->writeln('Rotate at: ' . $rotateString);
 }
示例#15
0
 protected function saveDBInfo(InputInterface $input)
 {
     $type = $input->getArgument('type');
     $username = $input->getArgument('username');
     $dbhost = $input->getArgument('hostname');
     $dbname = $input->getArgument('database');
     $password = $input->getOption('password');
     if ($input->getOption('port')) {
         $dbhost .= ':' . $input->getOption('port');
     }
     $this->config->setSystemValue('dbtype', $type);
     $this->config->setSystemValue('dbname', $dbname);
     $this->config->setSystemValue('dbhost', $dbhost);
     $this->config->setSystemValue('dbuser', $username);
     $this->config->setSystemValue('dbpassword', $password);
 }
示例#16
0
文件: migrator.php 项目: kenwi/core
 public function testUpgradeDifferentPrefix()
 {
     $oldTablePrefix = $this->config->getSystemValue('dbtableprefix', 'oc_');
     $this->config->setSystemValue('dbtableprefix', 'ownc_');
     $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix') . 'test_'));
     list($startSchema, $endSchema) = $this->getDuplicateKeySchemas();
     $migrator = $this->manager->getMigrator();
     $migrator->migrate($startSchema);
     $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo'));
     $this->connection->insert($this->tableName, array('id' => 2, 'name' => 'bar'));
     $this->connection->insert($this->tableName, array('id' => 3, 'name' => 'qwerty'));
     $migrator->checkMigrate($endSchema);
     $migrator->migrate($endSchema);
     $this->assertTrue(true);
     $this->config->setSystemValue('dbtableprefix', $oldTablePrefix);
 }
示例#17
0
 protected function convertDB(Connection $fromDB, Connection $toDB, array $tables, InputInterface $input, OutputInterface $output)
 {
     $this->config->setSystemValue('maintenance', true);
     try {
         // copy table rows
         foreach ($tables as $table) {
             $output->writeln($table);
             $this->copyTable($fromDB, $toDB, $table, $input, $output);
         }
         if ($input->getArgument('type') === 'pgsql') {
             $tools = new \OC\DB\PgSqlTools($this->config);
             $tools->resynchronizeDatabaseSequences($toDB);
         }
         // save new database config
         $this->saveDBInfo($input);
     } catch (\Exception $e) {
         $this->config->setSystemValue('maintenance', false);
         throw $e;
     }
     $this->config->setSystemValue('maintenance', false);
 }
示例#18
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);
         }
     }
     $apps = \OC::$server->getAppManager()->getInstalledApps();
     foreach ($apps as $app) {
         if (!\OC_App::isEnabled($app)) {
             continue;
         }
         $info = \OC_App::getAppInfo($app);
         if (!is_array($info)) {
             continue;
         }
         $steps = $info['repair-steps']['post-migration'];
         foreach ($steps as $step) {
             try {
                 $this->repair->addStep($step);
             } catch (Exception $ex) {
                 $output->writeln("<error>Failed to load repair step for {$app}: {$ex->getMessage()}</error>");
             }
         }
     }
     $maintenanceMode = $this->config->getSystemValue('maintenance', false);
     $this->config->setSystemValue('maintenance', true);
     $this->progress = new ProgressBar($output);
     $this->output = $output;
     $this->dispatcher->addListener('\\OC\\Repair::startProgress', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::advance', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::finishProgress', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::step', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::info', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::warning', [$this, 'handleRepairFeedBack']);
     $this->dispatcher->addListener('\\OC\\Repair::error', [$this, 'handleRepairFeedBack']);
     $this->repair->run();
     $this->config->setSystemValue('maintenance', $maintenanceMode);
 }
示例#19
0
 /**
  * Sets a new system wide value
  *
  * @param string $key the key of the value, under which will be saved
  * @param mixed $value the value that should be stored
  */
 public function setSystemValue($key, $value)
 {
     return $this->owncloudConfig->setSystemValue($key, $value);
 }
示例#20
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->config->setSystemValue('data-fingerprint', md5($this->timeFactory->getTime()));
 }
 /**
  * Enables or disables the display of experimental apps
  * @param bool $state
  * @return DataResponse
  */
 public function changeExperimentalConfigState($state)
 {
     $this->config->setSystemValue('appstore.experimental.enabled', $state);
     $this->appManager->clearAppsCache();
     return new DataResponse();
 }
 /**
  * Store the credentials used for SMTP in the config
  * @param string $mail_smtpname
  * @param string $mail_smtppassword
  * @return array
  */
 public function storeCredentials($mail_smtpname, $mail_smtppassword)
 {
     $this->config->setSystemValue('mail_smtpname', $mail_smtpname);
     $this->config->setSystemValue('mail_smtppassword', $mail_smtppassword);
     return array('data' => array('message' => (string) $this->l10n->t('Saved')), 'status' => 'success');
 }