コード例 #1
0
ファイル: import.php プロジェクト: evanjt/core
 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>');
 }
コード例 #2
0
 public function initialize($config)
 {
     $dbUser = $config['dbuser'];
     $dbPass = $config['dbpass'];
     $dbName = $config['dbname'];
     $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost';
     $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_';
     $this->config->setSystemValues(['dbname' => $dbName, 'dbhost' => $dbHost, 'dbtableprefix' => $dbTablePrefix]);
     $this->dbUser = $dbUser;
     $this->dbPassword = $dbPass;
     $this->dbName = $dbName;
     $this->dbHost = $dbHost;
     $this->tablePrefix = $dbTablePrefix;
 }
コード例 #3
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->setSystemValues(['dbtype' => $type, 'dbname' => $dbName, 'dbhost' => $dbHost, 'dbuser' => $username, 'dbpassword' => $password]);
 }
コード例 #4
0
 /**
  * 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->setSystemValues(['mail_smtpname' => $mail_smtpname, 'mail_smtppassword' => $mail_smtppassword]);
     return array('data' => array('message' => (string) $this->l10n->t('Saved')), 'status' => 'success');
 }
コード例 #5
0
ファイル: setup.php プロジェクト: kenwi/core
 /**
  * @param $options
  * @return array
  */
 public function install($options)
 {
     $l = $this->l10n;
     $error = array();
     $dbType = $options['dbtype'];
     if (empty($options['adminlogin'])) {
         $error[] = $l->t('Set an admin username.');
     }
     if (empty($options['adminpass'])) {
         $error[] = $l->t('Set an admin password.');
     }
     if (empty($options['directory'])) {
         $options['directory'] = \OC::$SERVERROOT . "/data";
     }
     if (!isset(self::$dbSetupClasses[$dbType])) {
         $dbType = 'sqlite';
     }
     $username = htmlspecialchars_decode($options['adminlogin']);
     $password = htmlspecialchars_decode($options['adminpass']);
     $dataDir = htmlspecialchars_decode($options['directory']);
     $class = self::$dbSetupClasses[$dbType];
     /** @var \OC\Setup\AbstractDatabase $dbSetup */
     $dbSetup = new $class($l, 'db_structure.xml', $this->config, $this->logger, $this->random);
     $error = array_merge($error, $dbSetup->validate($options));
     // validate the data directory
     if (!is_dir($dataDir) and !mkdir($dataDir) or !is_writable($dataDir)) {
         $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir));
     }
     if (count($error) != 0) {
         return $error;
     }
     $request = \OC::$server->getRequest();
     //no errors, good
     if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) {
         $trustedDomains = $options['trusted_domains'];
     } else {
         $trustedDomains = [$request->getInsecureServerHost()];
     }
     if (\OC_Util::runningOnWindows()) {
         $dataDir = rtrim(realpath($dataDir), '\\');
     }
     //use sqlite3 when available, otherwise sqlite2 will be used.
     if ($dbType == 'sqlite' and class_exists('SQLite3')) {
         $dbType = 'sqlite3';
     }
     //generate a random salt that is used to salt the local user passwords
     $salt = $this->random->generate(30);
     // generate a secret
     $secret = $this->random->generate(48);
     //write the config file
     $this->config->setSystemValues(['passwordsalt' => $salt, 'secret' => $secret, 'trusted_domains' => $trustedDomains, 'datadirectory' => $dataDir, 'overwrite.cli.url' => $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT, 'dbtype' => $dbType, 'version' => implode('.', \OCP\Util::getVersion())]);
     try {
         $dbSetup->initialize($options);
         $dbSetup->setupDatabase($username);
     } catch (\OC\DatabaseSetupException $e) {
         $error[] = array('error' => $e->getMessage(), 'hint' => $e->getHint());
         return $error;
     } catch (Exception $e) {
         $error[] = array('error' => 'Error while trying to create admin user: '******'hint' => '');
         return $error;
     }
     //create the user and group
     $user = null;
     try {
         $user = \OC::$server->getUserManager()->createUser($username, $password);
         if (!$user) {
             $error[] = "User <{$username}> could not be created.";
         }
     } catch (Exception $exception) {
         $error[] = $exception->getMessage();
     }
     if (count($error) == 0) {
         $config = \OC::$server->getConfig();
         $config->setAppValue('core', 'installedat', microtime(true));
         $config->setAppValue('core', 'lastupdatedat', microtime(true));
         $group = \OC::$server->getGroupManager()->createGroup('admin');
         $group->addUser($user);
         \OC_User::login($username, $password);
         //guess what this does
         \OC_Installer::installShippedApps();
         // create empty file in data dir, so we can later find
         // out that this is indeed an ownCloud data directory
         file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
         // Update .htaccess files
         Setup::updateHtaccess();
         Setup::protectDataDirectory();
         //try to write logtimezone
         if (date_default_timezone_get()) {
             $config->setSystemValue('logtimezone', date_default_timezone_get());
         }
         //and we are done
         $config->setSystemValue('installed', true);
     }
     return $error;
 }