public function setUp() { //clear all proxies and hooks so we can do clean testing \OC_FileProxy::clearProxies(); \OC_Hook::clear('OC_Filesystem'); //disabled atm //enable only the encryption hook if needed //if(OC_App::isEnabled('files_encryption')) { // OC_FileProxy::register(new OC_FileProxy_Encryption()); //} //set up temporary storage \OC\Files\Filesystem::clearMounts(); $storage = new \OC\Files\Storage\Temporary(array()); \OC\Files\Filesystem::mount($storage, array(), '/'); $datadir = str_replace('local::', '', $storage->getId()); $this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT . '/data/cache'); \OC_Config::setValue('cachedirectory', $datadir); \OC_User::clearBackends(); \OC_User::useBackend(new \OC_User_Dummy()); //login \OC_User::createUser('test', 'test'); $this->user = \OC_User::getUser(); \OC_User::setUserId('test'); //set up the users dir $rootView = new \OC\Files\View(''); $rootView->mkdir('/test'); $this->instance = new \OC\Cache\UserCache(); }
protected function tearDown() { \OC_Config::setValue('datadirectory', $this->datadir); \OC_User::setUserId($this->uid); \OC_Util::setupFS($this->uid); \OC\Files\Filesystem::mount($this->originalStorage, array(), '/'); parent::tearDown(); }
protected function tearDown() { \OC_User::setUserId($this->user); \OC_Config::setValue('cachedirectory', $this->datadir); // Restore the original mount point \OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::mount($this->storage, array(), '/'); parent::tearDown(); }
/** * Sets a value * @param string $key key * @param string $value value * @return bool * * This function sets the value and writes the config.php. If the file can * not be written, false will be returned. */ public static function setSystemValue($key, $value) { try { \OC_Config::setValue($key, $value); } catch (Exception $e) { return false; } return true; }
public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(self::TEST_TRASHBIN_USER1); \OC_Config::setValue('trashbin_retention_obligation', self::$rememberRetentionObligation); \OC_Config::setValue('trashbin_auto_expire', self::$rememberAutoExpire); \OC_Hook::clear(); \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); parent::tearDownAfterClass(); }
public function setupDatabase($username) { //check if the database user has admin right $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword); if (!$connection) { throw new \OC\DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.')); } //user already specified in config $oldUser = \OC_Config::getValue('dbuser', false); //we don't have a dbuser specified in config if ($this->dbuser != $oldUser) { //add prefix to the admin username to prevent collisions $adminUser = substr('oc_' . $username, 0, 16); $i = 1; while (true) { //this should be enough to check for admin rights in mysql $query = "SELECT user FROM mysql.user WHERE user='******'"; $result = mysql_query($query, $connection); //current dbuser has admin rights if ($result) { //new dbuser does not exist if (mysql_num_rows($result) === 0) { //use the admin login data for the new database user $this->dbuser = $adminUser; //create a random password so we don't need to store the admin password in the config file $this->dbpassword = \OC_Util::generateRandomBytes(30); $this->createDBUser($connection); break; } else { //repeat with different username $length = strlen((string) $i); $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; $i++; } } else { break; } } \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); } //create the database $this->createDatabase($connection); //fill the database if needed $query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';"; $result = mysql_query($query, $connection); if ($result) { $row = mysql_fetch_row($result); } if (!$result or $row[0] == 0) { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } mysql_close($connection); }
public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(self::TEST_TRASHBIN_USER1); if (self::$encryptionStatus === true) { \OC_App::enable('files_encryption'); } \OC_Config::setValue('trashbin_retention_obligation', self::$rememberRetentionObligation); \OC_Config::setValue('trashbin_auto_expire', self::$rememberAutoExpire); \OC_Hook::clear(); }
public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(self::TEST_TRASHBIN_USER1); \OC_Config::setValue('trashbin_retention_obligation', self::$rememberRetentionObligation); \OC_Hook::clear(); \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); if (self::$trashBinStatus) { \OC::$server->getAppManager()->enableApp('files_trashbin'); } parent::tearDownAfterClass(); }
public function testIsMaxSizeWorking() { $maxX = 250; $maxY = 250; \OC_Config::setValue('preview_max_x', $maxX); \OC_Config::setValue('preview_max_y', $maxY); $sampleFile = '/' . $this->user . '/files/test.txt'; $this->rootView->file_put_contents($sampleFile, 'dummy file data'); $preview = new \OC\Preview($this->user, 'files/', 'test.txt', 1000, 1000); $image = $preview->getPreview(); $this->assertEquals($image->width(), $maxX); $this->assertEquals($image->height(), $maxY); }
/** * Execute the upgrade command * * @param InputInterface $input input interface * @param OutputInterface $output output interface */ protected function execute(InputInterface $input, OutputInterface $output) { global $RUNTIME_NOAPPS; $RUNTIME_NOAPPS = true; //no apps, yet require_once \OC::$SERVERROOT . '/lib/base.php'; // Don't do anything if ownCloud has not been installed if (!\OC_Config::getValue('installed', false)) { $output->writeln('<error>ownCloud has not yet been installed</error>'); return self::ERROR_NOT_INSTALLED; } if (\OC::checkUpgrade(false)) { $updater = new Updater(); $updater->listen('\\OC\\Updater', 'maintenanceStart', function () use($output) { $output->writeln('<info>Turned on maintenance mode</info>'); }); $updater->listen('\\OC\\Updater', 'maintenanceEnd', function () use($output) { $output->writeln('<info>Turned off maintenance mode</info>'); $output->writeln('<info>Update successful</info>'); }); $updater->listen('\\OC\\Updater', 'dbUpgrade', function () use($output) { $output->writeln('<info>Updated database</info>'); }); $updater->listen('\\OC\\Updater', 'filecacheStart', function () use($output) { $output->writeln('<info>Updating filecache, this may take really long...</info>'); }); $updater->listen('\\OC\\Updater', 'filecacheDone', function () use($output) { $output->writeln('<info>Updated filecache</info>'); }); $updater->listen('\\OC\\Updater', 'filecacheProgress', function ($out) use($output) { $output->writeln('... ' . $out . '% done ...'); }); $updater->listen('\\OC\\Updater', 'failure', function ($message) use($output) { $output->writeln($message); \OC_Config::setValue('maintenance', false); }); $updater->upgrade(); $this->postUpgradeCheck($input, $output); return self::ERROR_SUCCESS; } else { if (\OC_Config::getValue('maintenance', false)) { //Possible scenario: ownCloud core is updated but an app failed $output->writeln('<warning>ownCloud is in maintenance mode</warning>'); $output->write('<comment>Maybe an upgrade is already in process. Please check the ' . 'logfile (data/owncloud.log). If you want to re-run the ' . 'upgrade procedure, remove the "maintenance mode" from ' . 'config.php and call this script again.</comment>', true); return self::ERROR_MAINTENANCE_MODE; } else { $output->writeln('<info>ownCloud is already latest version</info>'); return self::ERROR_UP_TO_DATE; } } }
public function testMicrosecondsLogTimestamp() { # delete old logfile unlink(OC_Config::getValue('logfile')); # set format & write log line OC_Config::setValue('logdateformat', 'u'); OC_Log_Owncloud::write('test', 'message', \OCP\Util::ERROR); # read log line $handle = @fopen(OC_Config::getValue('logfile'), 'r'); $line = fread($handle, 1000); fclose($handle); # check timestamp has microseconds part $values = (array) json_decode($line); $microseconds = $values['time']; $this->assertNotEquals(0, $microseconds); }
/** * @dataProvider findLanguageData */ public function testFindLanguage($default, $preference, $expected) { OC_User::setUserId(null); if (is_null($default)) { OC_Config::deleteKey('default_language'); } else { OC_Config::setValue('default_language', $default); } $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $preference; $reflection = new \ReflectionClass('OC_L10N'); $prop = $reflection->getProperty('language'); $prop->setAccessible(1); $prop->setValue(''); $prop->setAccessible(0); $this->assertSame($expected, OC_L10N::findLanguage()); }
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('on')) { \OC_Config::setValue('singleuser', true); $output->writeln('Single user mode enabled'); } elseif ($input->getOption('off')) { \OC_Config::setValue('singleuser', false); $output->writeln('Single user mode disabled'); } else { if (\OC_Config::getValue('singleuser', false)) { $output->writeln('Single user mode is currently enabled'); } else { $output->writeln('Single user mode is currently disabled'); } } }
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_'; \OC_Config::setValue('dbname', $dbname); \OC_Config::setValue('dbhost', $dbhost); \OC_Config::setValue('dbtableprefix', $dbtableprefix); $this->dbuser = $dbuser; $this->dbpassword = $dbpass; $this->dbname = $dbname; $this->dbhost = $dbhost; $this->tableprefix = $dbtableprefix; }
/** * Test that checkServer() does not check the data dir validity * when an upgrade is required (else the upgrade cannot be * performed...) */ public function testCheckServerSkipDataDirValidityOnUpgrade() { // simulate old version that didn't have it unlink($this->datadir . '/.ocdata'); $session = \OC::$server->getSession(); $oldCurrentVersion = $session->get('OC_Version'); $oldInstallVersion = \OC_Config::getValue('version', '0.0.0'); // upgrade condition to simulate needUpgrade() === true $session->set('OC_Version', array(6, 0, 0, 2)); \OC_Config::setValue('version', '6.0.0.1'); // even though ".ocdata" is missing, the error isn't // triggered to allow for upgrade $result = \OC_Util::checkServer(); $this->assertEmpty($result); // restore versions $session->set('OC_Version', $oldCurrentVersion); \OC_Config::setValue('version', $oldInstallVersion); }
public function setupDatabase($username) { //check if the database user has admin right $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword); if (!$connection) { throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.')); } $oldUser = \OC_Config::getValue('dbuser', false); //this should be enough to check for admin rights in mysql $query = "SELECT user FROM mysql.user WHERE user='******'"; if (mysql_query($query, $connection)) { //use the admin login data for the new database user //add prefix to the mysql user name to prevent collisions $this->dbuser = substr('oc_' . $username, 0, 16); if ($this->dbuser != $oldUser) { //hash the password so we don't need to store the admin config in the config file $this->dbpassword = \OC_Util::generateRandomBytes(30); $this->createDBUser($connection); \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); } //create the database $this->createDatabase($connection); } else { if ($this->dbuser != $oldUser) { \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); } //create the database $this->createDatabase($connection); } //fill the database if needed $query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';"; $result = mysql_query($query, $connection); if ($result) { $row = mysql_fetch_row($result); } if (!$result or $row[0] == 0) { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } mysql_close($connection); }
public function setupDatabase() { //check if the database user has admin right $masterConnectionInfo = array("Database" => "master", "UID" => $this->dbuser, "PWD" => $this->dbpassword); $masterConnection = @sqlsrv_connect($this->dbhost, $masterConnectionInfo); if (!$masterConnection) { $entry = null; if (($errors = sqlsrv_errors()) != null) { $entry = 'DB Error: "' . print_r(sqlsrv_errors()) . '"<br />'; } else { $entry = ''; } throw new \OC\DatabaseSetupException($this->trans->t('MS SQL username and/or password not valid: %s', array($entry)), $this->trans->t('You need to enter either an existing account or the administrator.')); } \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); $this->createDBLogin($masterConnection); $this->createDatabase($masterConnection); $this->createDBUser($masterConnection); sqlsrv_close($masterConnection); $this->createDatabaseStructure(); }
/** * Set mail settings */ public static function setMailSettings() { \OC_Util::checkAdminUser(); \OCP\JSON::callCheck(); $l = \OC::$server->getL10N('settings'); $smtp_settings = array('mail_domain' => null, 'mail_from_address' => null, 'mail_smtpmode' => array('sendmail', 'smtp', 'qmail', 'php'), 'mail_smtpsecure' => array('', 'ssl', 'tls'), 'mail_smtphost' => null, 'mail_smtpport' => null, 'mail_smtpauthtype' => array('LOGIN', 'PLAIN', 'NTLM'), 'mail_smtpauth' => true, 'mail_smtpname' => null, 'mail_smtppassword' => null); foreach ($smtp_settings as $setting => $validate) { if (!$validate) { if (!isset($_POST[$setting]) || $_POST[$setting] === '') { \OC_Config::deleteKey($setting); } else { \OC_Config::setValue($setting, $_POST[$setting]); } } else { if (is_bool($validate)) { if (!empty($_POST[$setting])) { \OC_Config::setValue($setting, (bool) $_POST[$setting]); } else { \OC_Config::deleteKey($setting); } } else { if (is_array($validate)) { if (!isset($_POST[$setting]) || $_POST[$setting] === '') { \OC_Config::deleteKey($setting); } else { if (in_array($_POST[$setting], $validate)) { \OC_Config::setValue($setting, $_POST[$setting]); } else { $message = $l->t('Invalid value supplied for %s', array(self::getFieldname($setting, $l))); \OC_JSON::error(array("data" => array("message" => $message))); exit; } } } } } } \OC_JSON::success(array("data" => array("message" => $l->t("Saved")))); }
function testGetConfiguredEmailAddressFromConfig() { OC_Config::setValue('mail_domain', 'example.com'); OC_Config::setValue('mail_from_address', 'owncloud'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('*****@*****.**', $email); OC_Config::deleteKey('mail_domain'); OC_Config::deleteKey('mail_from_address'); }
/** * @param $options * @return array */ public static function install($options) { $l = self::getTrans(); $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(self::getTrans(), 'db_structure.xml'); $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; } //no errors, good if (isset($options['trusted_domains']) && is_array($options['trusted_domains'])) { $trustedDomains = $options['trusted_domains']; } else { $trustedDomains = array(OC_Request::serverHost()); } 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 = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(30); \OC::$server->getConfig()->setSystemValue('passwordsalt', $salt); // generate a secret $secret = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(48); \OC::$server->getConfig()->setSystemValue('secret', $secret); //write the config file \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains); \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir); \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT); \OC::$server->getConfig()->setSystemValue('dbtype', $dbType); \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion())); try { $dbSetup->initialize($options); $dbSetup->setupDatabase($username); } catch (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 try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { $appConfig = \OC::$server->getAppConfig(); $appConfig->setValue('core', 'installedat', microtime(true)); $appConfig->setValue('core', 'lastupdatedat', microtime(true)); OC_Group::createGroup('admin'); OC_Group::addToGroup($username, 'admin'); 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(OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data') . '/.ocdata', ''); // Update htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::updateHtaccess(); self::protectDataDirectory(); } //and we are done OC_Config::setValue('installed', true); } return $error; }
/** * 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 setValue($key, $value) { \OC_Config::setValue($key, $value); }
/** * 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 for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { \OC_Setup::updateHtaccess(); } // 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(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); /* * START CONFIG CHANGES FOR OLDER VERSIONS */ if (!\OC::$CLI && version_compare($installedVersion, '6.90.1', '<')) { // Add the trusted_domains config if it is not existant // This is added to prevent host header poisoning \OC_Config::setValue('trusted_domains', \OC_Config::getValue('trusted_domains', array(\OC_Request::serverHost()))); } /* * STOP CONFIG CHANGES FOR OLDER VERSIONS */ // pre-upgrade repairs $repair = new \OC\Repair(\OC\Repair::getBeforeUpgradeRepairSteps()); $repair->run(); // simulate DB upgrade if ($this->simulateStepEnabled) { $this->checkCoreUpgrade(); // simulate apps DB upgrade $this->checkAppUpgrade($currentVersion); } // upgrade from OC6 to OC7 // TODO removed it again for OC8 $sharePolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); if ($sharePolicy === 'groups_only') { \OC_Appconfig::setValue('core', 'shareapi_only_share_with_group_members', 'yes'); } if ($this->updateStepEnabled) { $this->doCoreUpgrade(); $disabledApps = \OC_App::checkAppsRequirements(); if (!empty($disabledApps)) { $this->emit('\\OC\\Updater', 'disabledApps', array($disabledApps)); } $this->doAppUpgrade(); // post-upgrade repairs $repair = new \OC\Repair(\OC\Repair::getRepairSteps()); $repair->run(); //Invalidate update feed \OC_Appconfig::setValue('core', 'lastupdatedat', 0); // only set the final version if everything went well \OC_Config::setValue('version', implode('.', \OC_Util::getVersion())); } }
protected function tearDown() { \OC_Config::setValue('datadirectory', $this->datadir); $this->logout(); parent::tearDown(); }
protected function tearDown() { OC_Installer::removeApp(self::$appid); OC_Config::setValue('appstoreenabled', $this->appstore); parent::tearDown(); }
<?php /** * Copyright (c) 2013, Lukas Reschke <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ OC_Util::checkAdminUser(); OCP\JSON::callCheck(); OC_Config::setValue('forcessl', filter_var($_POST['enforceHTTPS'], FILTER_VALIDATE_BOOLEAN)); echo 'true';
public static function checkUpgrade($showTemplate = true) { if (OC_Config::getValue('installed', false)) { $installedVersion = OC_Config::getValue('version', '0.0.0'); $currentVersion = implode('.', OC_Util::getVersion()); if (version_compare($currentVersion, $installedVersion, '>')) { if ($showTemplate && !OC_Config::getValue('maintenance', false)) { OC_Config::setValue('theme', ''); $minimizerCSS = new OC_Minimizer_CSS(); $minimizerCSS->clearCache(); $minimizerJS = new OC_Minimizer_JS(); $minimizerJS->clearCache(); OC_Util::addscript('update'); $tmpl = new OC_Template('', 'update', 'guest'); $tmpl->assign('version', OC_Util::getVersionString()); $tmpl->printPage(); exit; } else { return true; } } return false; } }
$updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) { $eventSource->send('notice', (string)$l->t('Repair warning: ') . $description); }); $updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) { $eventSource->send('notice', (string)$l->t('Repair error: ') . $description); }); $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { $incompatibleApps[]= $app; }); $updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) { $disabledThirdPartyApps[]= $app; }); $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource) { $eventSource->send('failure', $message); $eventSource->close(); OC_Config::setValue('maintenance', false); }); $updater->upgrade(); if (!empty($incompatibleApps)) { $eventSource->send('notice', (string)$l->t('Following incompatible apps have been disabled: %s', implode(', ', $incompatibleApps))); } if (!empty($disabledThirdPartyApps)) { $eventSource->send('notice', (string)$l->t('Following apps have been disabled: %s', implode(', ', $disabledThirdPartyApps))); } $eventSource->send('done', ''); $eventSource->close();
public function testServerHost() { OC_Config::deleteKey('overwritecondaddr'); OC_Config::setValue('overwritehost', 'overwritten.host:8080'); OC_Config::setValue('trusted_domains', array('trusted.host:8080', 'second.trusted.host:8080')); $_SERVER['HTTP_HOST'] = 'trusted.host:8080'; // CLI always gives localhost $oldCLI = OC::$CLI; OC::$CLI = true; $host = OC_Request::serverHost(); $this->assertEquals('localhost', $host); OC::$CLI = false; // overwritehost overrides trusted domain $host = OC_Request::serverHost(); $this->assertEquals('overwritten.host:8080', $host); // trusted domain returned when used OC_Config::deleteKey('overwritehost'); $host = OC_Request::serverHost(); $this->assertEquals('trusted.host:8080', $host); // trusted domain returned when untrusted one in header $_SERVER['HTTP_HOST'] = 'untrusted.host:8080'; OC_Config::deleteKey('overwritehost'); $host = OC_Request::serverHost(); $this->assertEquals('trusted.host:8080', $host); // clean up OC_Config::deleteKey('overwritecondaddr'); OC_Config::deleteKey('overwritehost'); unset($_SERVER['HTTP_HOST']); OC::$CLI = $oldCLI; }
public function setupDatabase($username) { $e_host = addslashes($this->dbhost); $e_dbname = addslashes($this->dbname); //check if the database user has admin right if ($e_host == '') { $easy_connect_string = $e_dbname; // use dbname as easy connect name } else { $easy_connect_string = '//' . $e_host . '/' . $e_dbname; } \OC_Log::write('setup oracle', 'connect string: ' . $easy_connect_string, \OC_Log::DEBUG); $connection = @oci_connect($this->dbuser, $this->dbpassword, $easy_connect_string); if (!$connection) { $errorMessage = $this->getLastError(); if ($errorMessage) { throw new \DatabaseSetupException($this->trans->t('Oracle connection could not be established'), $errorMessage . ' Check environment: ORACLE_HOME=' . getenv('ORACLE_HOME') . ' ORACLE_SID=' . getenv('ORACLE_SID') . ' LD_LIBRARY_PATH=' . getenv('LD_LIBRARY_PATH') . ' NLS_LANG=' . getenv('NLS_LANG') . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable'); } throw new \DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), 'Check environment: ORACLE_HOME=' . getenv('ORACLE_HOME') . ' ORACLE_SID=' . getenv('ORACLE_SID') . ' LD_LIBRARY_PATH=' . getenv('LD_LIBRARY_PATH') . ' NLS_LANG=' . getenv('NLS_LANG') . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable'); } //check for roles creation rights in oracle $query = 'SELECT count(*) FROM user_role_privs, role_sys_privs' . " WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); if ($result) { $row = oci_fetch_row($stmt); } if ($result and $row[0] > 0) { //use the admin login data for the new database user //add prefix to the oracle user name to prevent collisions $this->dbuser = '******' . $username; //create a new password so we don't need to store the admin config in the config file $this->dbpassword = \OC_Util::generateRandomBytes(30); //oracle passwords are treated as identifiers: // must start with alphanumeric char // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. $this->dbpassword = substr($this->dbpassword, 0, 30); $this->createDBUser($connection); \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbname', $this->dbuser); \OC_Config::setValue('dbpassword', $this->dbpassword); //create the database not necessary, oracle implies user = schema //$this->createDatabase($this->dbname, $this->dbuser, $connection); } else { \OC_Config::setValue('dbuser', $this->dbuser); \OC_Config::setValue('dbname', $this->dbname); \OC_Config::setValue('dbpassword', $this->dbpassword); //create the database not necessary, oracle implies user = schema //$this->createDatabase($this->dbname, $this->dbuser, $connection); } //FIXME check tablespace exists: select * from user_tablespaces // the connection to dbname=oracle is not needed anymore oci_close($connection); // connect to the oracle database (schema=$this->dbuser) an check if the schema needs to be filled $this->dbuser = \OC_Config::getValue('dbuser'); //$this->dbname = \OC_Config::getValue('dbname'); $this->dbpassword = \OC_Config::getValue('dbpassword'); $e_host = addslashes($this->dbhost); $e_dbname = addslashes($this->dbname); if ($e_host == '') { $easy_connect_string = $e_dbname; // use dbname as easy connect name } else { $easy_connect_string = '//' . $e_host . '/' . $e_dbname; } $connection = @oci_connect($this->dbuser, $this->dbpassword, $easy_connect_string); if (!$connection) { throw new \DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.')); } $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; $stmt = oci_parse($connection, $query); $un = $this->tableprefix . 'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { $entry = $this->trans->t('DB Error: "%s"', array($this->getLastError($connection))) . '<br />'; $entry .= $this->trans->t('Offending command was: "%s"', array($query)) . '<br />'; \OC_Log::write('setup.oci', $entry, \OC_Log::WARN); } $result = oci_execute($stmt); if ($result) { $row = oci_fetch_row($stmt); } if (!$result or $row[0] == 0) { \OC_DB::createDbFromStructure($this->dbDefinitionFile); } }
/** * @brief Sets a value * @param string $key key * @param string $value value * @return bool * * This function sets the value and writes the config.php. If the file can * not be written, false will be returned. */ public static function setSystemValue($key, $value) { return \OC_Config::setValue($key, $value); }