public static function setUpBeforeClass() { // reset backend \OC_User::clearBackends(); \OC_User::useBackend('database'); // enable resharing \OC_Appconfig::setValue('core', 'shareapi_allow_resharing', 'yes'); // clear share hooks \OC_Hook::clear('OCP\\Share'); \OC::registerShareHooks(); \OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup'); // Sharing related hooks \OCA\Encryption\Helper::registerShareHooks(); // Filesystem related hooks \OCA\Encryption\Helper::registerFilesystemHooks(); // clear and register hooks \OC_FileProxy::clearProxies(); \OC_FileProxy::register(new OCA\Encryption\Proxy()); // create users \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1, true); \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, true); \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, true); \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, true); // create group and assign users \OC_Group::createGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); \OC_Group::addToGroup(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_GROUP1); }
/** * 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) { // Look up the cache - it is invalidated all 30 minutes if (\OC_Appconfig::getValue('core', 'lastupdatedat') + 1800 > time()) { return json_decode(\OC_Appconfig::getValue('core', 'lastupdateResult'), true); } \OC_Appconfig::setValue('core', 'lastupdatedat', time()); if (\OC_Appconfig::getValue('core', 'installedat', '') == '') { \OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $version = \OC_Util::getVersion(); $version['installed'] = \OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = \OC_Appconfig::getValue('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. $ctx = stream_context_create(array('http' => array('timeout' => 10))); $xml = @file_get_contents($url, 0, $ctx); if ($xml == false) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; // Cache the result \OC_Appconfig::setValue('core', 'lastupdateResult', json_encode($data)); return $tmp; }
/** * Check if a new version is available */ public static function check() { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); if (OC_Appconfig::getValue('core', 'installedat', '') == '') { OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $updaterurl = 'http://apps.owncloud.com/updater.php'; $version = OC_Util::getVersion(); $version['installed'] = OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = OC_Appconfig::getValue('core', 'lastupdatedat'); $version['updatechannel'] = 'stable'; $version['edition'] = OC_Util::getEditionString(); $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. $ctx = stream_context_create(array('http' => array('timeout' => 10))); $xml = @file_get_contents($url, 0, $ctx); if ($xml == false) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; return $tmp; }
/** * Check if a new version is available */ public static function check() { OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); if (OC_Appconfig::getValue('core', 'installedat', '') == '') { OC_Appconfig::setValue('core', 'installedat', microtime(true)); } $updaterurl = 'http://apps.owncloud.com/updater.php'; $version = OC_Util::getVersion(); $version['installed'] = OC_Appconfig::getValue('core', 'installedat'); $version['updated'] = OC_Appconfig::getValue('core', 'lastupdatedat'); $version['updatechannel'] = 'stable'; $version['edition'] = OC_Util::getEditionString(); $versionstring = implode('x', $version); //fetch xml data from updater $url = $updaterurl . '?version=' . $versionstring; $xml = @file_get_contents($url); if ($xml == FALSE) { return array(); } $data = @simplexml_load_string($xml); $tmp = array(); $tmp['version'] = $data->version; $tmp['versionstring'] = $data->versionstring; $tmp['url'] = $data->url; $tmp['web'] = $data->web; return $tmp; }
/** * sets the background jobs execution type * @param string $type execution type * @return false|null * * This method sets the execution type of the background jobs. Possible types * are "none", "ajax", "webcron", "cron" */ public static function setExecutionType($type) { if (!in_array($type, array('none', 'ajax', 'webcron', 'cron'))) { return false; } return OC_Appconfig::setValue('core', 'backgroundjobs_mode', $type); }
public function testSetValue() { \OC_Appconfig::setValue('testapp', 'installed_version', '1.33.7'); $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); $result = $query->execute(array('testapp', 'installed_version')); $value = $result->fetchRow(); $this->assertEquals('1.33.7', $value['configvalue']); \OC_Appconfig::setValue('someapp', 'somekey', 'somevalue'); $query = \OC_DB::prepare('SELECT `configvalue` FROM `*PREFIX*appconfig` WHERE `appid` = ? AND `configkey` = ?'); $result = $query->execute(array('someapp', 'somekey')); $value = $result->fetchRow(); $this->assertEquals('somevalue', $value['configvalue']); }
public static function checkNext() { // check both 1 file and 1 folder, this way new files are detected quicker because there are less folders than files usually $previousFile = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_file', 0); $previousFolder = \OC_Appconfig::getValue('files', 'backgroundwatcher_previous_folder', 0); $nextFile = self::getNextFileId($previousFile, false); $nextFolder = self::getNextFileId($previousFolder, true); \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_file', $nextFile); \OC_Appconfig::setValue('files', 'backgroundwatcher_previous_folder', $nextFolder); if ($nextFile > 0) { self::checkUpdate($nextFile); } if ($nextFolder > 0) { self::checkUpdate($nextFolder); } }
/** * @brief if session is started, check if ownCloud key pair is set up, if not create it * @param \OC_FilesystemView $view * * @note The ownCloud key pair is used to allow public link sharing even if encryption is enabled */ public function __construct($view) { $this->view = $view; if (!$this->view->is_dir('owncloud_private_key')) { $this->view->mkdir('owncloud_private_key'); } $publicShareKeyId = \OC_Appconfig::getValue('files_encryption', 'publicShareKeyId'); if ($publicShareKeyId === null) { $publicShareKeyId = 'pubShare_' . substr(md5(time()), 0, 8); \OC_Appconfig::setValue('files_encryption', 'publicShareKeyId', $publicShareKeyId); } if (!$this->view->file_exists("/public-keys/" . $publicShareKeyId . ".public.key") || !$this->view->file_exists("/owncloud_private_key/" . $publicShareKeyId . ".private.key")) { $keypair = Crypt::createKeypair(); // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; // Save public key if (!$view->is_dir('/public-keys')) { $view->mkdir('/public-keys'); } $this->view->file_put_contents('/public-keys/' . $publicShareKeyId . '.public.key', $keypair['publicKey']); // Encrypt private key empty passphrase $encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], ''); // Save private key $this->view->file_put_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key', $encryptedPrivateKey); \OC_FileProxy::$enabled = $proxyStatus; } if (\OCA\Encryption\Helper::isPublicAccess()) { // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $encryptedKey = $this->view->file_get_contents('/owncloud_private_key/' . $publicShareKeyId . '.private.key'); $privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); $this->setPublicSharePrivateKey($privateKey); \OC_FileProxy::$enabled = $proxyStatus; } }
public function getParams() { $array = array(); foreach ($this->params as $key => $param) { $array[$param] = OC_Appconfig::getValue('user_wordpress', $param, ''); } if (empty($array['wordpress_db_host'])) { $array['wordpress_db_host'] = OC_Config::getValue("dbhost", ""); } if (empty($array['wordpress_db_name'])) { $array['wordpress_db_name'] = OC_Config::getValue("dbname", "owncloud"); } if (empty($array['wordpress_db_user'])) { $array['wordpress_db_user'] = OC_Config::getValue("dbuser", ""); } if (empty($array['wordpress_db_password'])) { $array['wordpress_db_password'] = OC_Config::getValue("dbpassword", ""); } if (empty($array['wordpress_have_to_be_logged'])) { $array['wordpress_have_to_be_logged'] = '0'; OC_Appconfig::setValue('user_wordpress', 'wordpress_have_to_be_logged', '0'); } return $array; }
/** * @brief sets a value in the appconfig * @param string $app app * @param string $key key * @param string $value value * @return string true/false * * Sets a value. If the key did not exist before it will be created. */ public static function setAppValue($app, $key, $value) { return \OC_Appconfig::setValue($app, $key, $value); }
public static function install($options) { $error = array(); $dbtype = $options['dbtype']; if (empty($options['adminlogin'])) { $error[] = 'Set an admin username.'; } if (empty($options['adminpass'])) { $error[] = 'Set an admin password.'; } if (empty($options['directory'])) { $error[] = 'Specify a data folder.'; } if ($dbtype == 'mysql' or $dbtype == 'pgsql') { //mysql and postgresql needs more config options if ($dbtype == 'mysql') { $dbprettyname = 'MySQL'; } else { $dbprettyname = 'PostgreSQL'; } if (empty($options['dbuser'])) { $error[] = "{$dbprettyname} enter the database username."; } if (empty($options['dbname'])) { $error[] = "{$dbprettyname} enter the database name."; } if (empty($options['dbhost'])) { $error[] = "{$dbprettyname} set the database host."; } } if (count($error) == 0) { //no errors, good $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); //use sqlite3 when available, otherise 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_Util::generate_random_bytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file OC_Config::setValue('datadirectory', $datadir); OC_Config::setValue('dbtype', $dbtype); OC_Config::setValue('version', implode('.', OC_Util::getVersion())); if ($dbtype == 'mysql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); //check if the database user has admin right $connection = @mysql_connect($dbhost, $dbuser, $dbpass); if (!$connection) { $error[] = array('error' => 'MySQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.'); return $error; } else { $oldUser = OC_Config::getValue('dbuser', false); $oldPassword = OC_Config::getValue('dbpassword', false); $query = "SELECT user FROM mysql.user WHERE user='******'"; //this should be enough to check for admin rights in mysql if (mysql_query($query, $connection)) { //use the admin login data for the new database user //add prefix to the mysql user name to prevent collissions $dbusername = substr('oc_' . $username, 0, 16); if ($dbusername != $oldUser) { //hash the password so we don't need to store the admin config in the config file $dbpassword = md5(time() . $password); self::createDBUser($dbusername, $dbpassword, $connection); OC_Config::setValue('dbuser', $dbusername); OC_Config::setValue('dbpassword', $dbpassword); } //create the database self::createDatabase($dbname, $dbusername, $connection); } else { if ($dbuser != $oldUser) { OC_Config::setValue('dbuser', $dbuser); OC_Config::setValue('dbpassword', $dbpass); } //create the database self::createDatabase($dbname, $dbuser, $connection); } //fill the database if needed $query = "select count(*) from information_schema.tables where table_schema='{$dbname}' AND table_name = '{$dbtableprefix}users';"; $result = mysql_query($query, $connection); if ($result) { $row = mysql_fetch_row($result); } if (!$result or $row[0] == 0) { OC_DB::createDbFromStructure('db_structure.xml'); } mysql_close($connection); } } elseif ($dbtype == 'pgsql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_CONFIG::setValue('dbname', $dbname); OC_CONFIG::setValue('dbhost', $dbhost); OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); //check if the database user has admin right $connection_string = "host={$dbhost} dbname=postgres user={$dbuser} password={$dbpass}"; $connection = @pg_connect($connection_string); if (!$connection) { $error[] = array('error' => 'PostgreSQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.'); return $error; } else { //check for roles creation rights in postgresql $query = "SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='{$dbuser}'"; $result = pg_query($connection, $query); if ($result and pg_num_rows($result) > 0) { //use the admin login data for the new database user //add prefix to the postgresql user name to prevent collissions $dbusername = '******' . $username; //create a new password so we don't need to store the admin config in the config file $dbpassword = md5(time()); self::pg_createDBUser($dbusername, $dbpassword, $connection); OC_CONFIG::setValue('dbuser', $dbusername); OC_CONFIG::setValue('dbpassword', $dbpassword); //create the database self::pg_createDatabase($dbname, $dbusername, $connection); } else { OC_CONFIG::setValue('dbuser', $dbuser); OC_CONFIG::setValue('dbpassword', $dbpass); //create the database self::pg_createDatabase($dbname, $dbuser, $connection); } // the connection to dbname=postgres is not needed anymore pg_close($connection); // connect to the ownCloud database (dbname=$dbname) an check if it needs to be filled $dbuser = OC_CONFIG::getValue('dbuser'); $dbpass = OC_CONFIG::getValue('dbpassword'); $connection_string = "host={$dbhost} dbname={$dbname} user={$dbuser} password={$dbpass}"; $connection = @pg_connect($connection_string); if (!$connection) { $error[] = array('error' => 'PostgreSQL username and/or password not valid', 'hint' => 'You need to enter either an existing account or the administrator.'); } else { $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; $result = pg_query($connection, $query); if ($result) { $row = pg_fetch_row($result); } if (!$result or $row[0] == 0) { OC_DB::createDbFromStructure('db_structure.xml'); } } } } else { //delete the old sqlite database first, might cause infinte loops otherwise if (file_exists("{$datadir}/owncloud.db")) { unlink("{$datadir}/owncloud.db"); } //in case of sqlite, we can always fill the database OC_DB::createDbFromStructure('db_structure.xml'); } //create the user and group try { OC_User::createUser($username, $password); } catch (Exception $exception) { $error[] = $exception->getMessage(); } if (count($error) == 0) { OC_Appconfig::setValue('core', 'installedat', microtime(true)); OC_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 htaccess files for apache hosts if (strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } //and we are done OC_Config::setValue('installed', true); } } return $error; }
/** * 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())); } }
/** * check if the app needs updating and update when needed */ public static function checkUpgrade($app) { if (in_array($app, self::$checkedApps)) { return; } self::$checkedApps[] = $app; $versions = self::getAppVersions(); $currentVersion = OC_App::getAppVersion($app); if ($currentVersion) { $installedVersion = $versions[$app]; if (version_compare($currentVersion, $installedVersion, '>')) { $info = self::getAppInfo($app); OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG); try { OC_App::updateApp($app); OC_Hook::emit('update', 'success', 'Updated ' . $info['name'] . ' app'); } catch (Exception $e) { OC_Hook::emit('update', 'failure', 'Failed to update ' . $info['name'] . ' app: ' . $e->getMessage()); $l = OC_L10N::get('lib'); throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e); } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } }
/** * install an app already placed in the app folder * @param string $app id of the app to install * @returns array see OC_App::getAppInfo */ public static function installShippedApp($app) { //install the database if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml")) { OC_DB::createDbFromStructure(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml"); } //run appinfo/install.php if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/install.php")) { include OC::$APPSROOT . "/apps/{$app}/appinfo/install.php"; } $info = OC_App::getAppInfo($app); OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); //set remote/public handelers foreach ($info['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, '/apps/' . $app . '/' . $path); } foreach ($info['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, '/apps/' . $app . '/' . $path); } OC_App::setAppTypes($info['id']); return $info; }
/** * check if the app need updating and update when needed */ public static function checkUpgrade($app) { if (in_array($app, self::$checkedApps)) { return; } self::$checkedApps[] = $app; $versions = self::getAppVersions(); $currentVersion = OC_App::getAppVersion($app); if ($currentVersion) { $installedVersion = $versions[$app]; if (version_compare($currentVersion, $installedVersion, '>')) { OC_Log::write($app, 'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG); try { OC_App::updateApp($app); } catch (Exception $e) { echo 'Failed to upgrade "' . $app . '". Exception="' . $e->getMessage() . '"'; die; } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } }
public function testShareItemWithLinkAndDefaultExpireDate() { OC_User::setUserId($this->user1); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertInternalType('string', $token, 'Failed asserting that user 1 successfully shared text.txt as link with token.'); // share should have default expire date $row = $this->getShareByValidToken($token); $this->assertNotEmpty($row['expiration'], 'Failed asserting that the returned row has an default expiration date.'); \OC_Appconfig::deleteKey('core', 'shareapi_default_expire_date'); \OC_Appconfig::deleteKey('core', 'shareapi_expire_after_n_days'); }
/** * install an app already placed in the app folder * @param string $app id of the app to install * @returns array see OC_App::getAppInfo */ public static function installShippedApp($app) { //install the database if (is_file(OC::$SERVERROOT . "/apps/{$app}/appinfo/database.xml")) { OC_DB::createDbFromStructure(OC::$SERVERROOT . "/apps/{$app}/appinfo/database.xml"); } //run appinfo/install.php if (is_file(OC::$SERVERROOT . "/apps/{$app}/appinfo/install.php")) { include OC::$SERVERROOT . "/apps/{$app}/appinfo/install.php"; } $info = OC_App::getAppInfo(OC::$SERVERROOT . "/apps/{$app}/appinfo/info.xml"); OC_Appconfig::setValue($app, 'installed_version', $info['version']); return $info; }
$jobList = \OC::$server->getJobList(); $jobs = $jobList->getAll(); foreach ($jobs as $job) { $job->execute($jobList, $logger); } } else { // We call cron.php from some website if ($appmode == 'cron') { // Cron is cron :-P OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); } else { // Work and success :-) $jobList = \OC::$server->getJobList(); $job = $jobList->getNext(); if ($job != null) { $job->execute($jobList, $logger); $jobList->setLastJob($job); } OC_JSON::success(); } } // done! TemporaryCronClass::$sent = true; // Log the successfull cron exec if (OC_Config::getValue('cron_log', true)) { OC_Appconfig::setValue('core', 'lastcron', time()); } exit; } catch (Exception $ex) { \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); }
} // An admin should not be able to add remote and public services // on its own. This should only be possible programmatically. // This change is due the fact that an admin may not be expected // to execute arbitrary code in every environment. if ($app === 'core' && isset($_POST['key']) && (substr($_POST['key'], 0, 7) === 'remote_' || substr($_POST['key'], 0, 7) === 'public_')) { OC_JSON::error(array('data' => array('message' => 'Unexpected error!'))); return; } $result = false; switch ($action) { case 'getValue': $result = OC_Appconfig::getValue($app, $_GET['key'], $_GET['defaultValue']); break; case 'setValue': $result = OC_Appconfig::setValue($app, $_POST['key'], $_POST['value']); break; case 'getApps': $result = OC_Appconfig::getApps(); break; case 'getKeys': $result = OC_Appconfig::getKeys($app); break; case 'hasKey': $result = OC_Appconfig::hasKey($app, $_GET['key']); break; case 'deleteKey': $result = OC_Appconfig::deleteKey($app, $_POST['key']); break; case 'deleteApp': $result = OC_Appconfig::deleteApp($app);
/** * @brief enables an app * @param $app app * @returns true/false * * This function set an app as enabled in appconfig. */ public static function disable($app) { OC_Appconfig::setValue($app, 'enabled', 'no'); }
/** * @brief disable recovery * * @param $recoveryPassword * @return bool */ public static function adminDisableRecovery($recoveryPassword) { $util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); $return = $util->checkRecoveryPassword($recoveryPassword); if ($return) { // Set recoveryAdmin as disabled \OC_Appconfig::setValue('files_encryption', 'recoveryAdminEnabled', 0); } return $return; }
public function testDefaultExpireDate() { \Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'yes'); \OC_Appconfig::setValue('core', 'shareapi_expire_after_n_days', '2'); // default expire date is set to 2 days // the time when the share was created is set to 3 days in the past // user defined expire date is set to +2 days from now on // -> link should be already expired by the default expire date but the user // share should still exists. $now = time(); $dateFormat = 'Y-m-d H:i:s'; $shareCreated = $now - 3 * 24 * 60 * 60; $expireDate = date($dateFormat, $now + 2 * 24 * 60 * 60); $info = OC\Files\Filesystem::getFileInfo($this->filename); $this->assertTrue($info instanceof \OC\Files\FileInfo); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_LINK, null, \OCP\PERMISSION_READ); $this->assertTrue(is_string($result)); $result = \OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31); $this->assertTrue($result); $result = \OCP\Share::setExpirationDate('file', $info->getId(), $expireDate); $this->assertTrue($result); //manipulate stime so that both shares are older then the default expire date $statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?"; $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_LINK)); $this->assertSame(1, $result); $query = \OCP\DB::prepare($statement); $result = $query->execute(array($shareCreated, \OCP\Share::SHARE_TYPE_USER)); $this->assertSame(1, $result); // now the link share should expire because of enforced default expire date // the user share should still exist $result = \OCP\Share::getItemShared('file', $info->getId()); $this->assertTrue(is_array($result)); $this->assertSame(1, count($result)); $share = reset($result); $this->assertSame(\OCP\Share::SHARE_TYPE_USER, $share['share_type']); //cleanup $result = \OCP\Share::unshare('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); $this->assertTrue($result); \OC_Appconfig::setValue('core', 'shareapi_default_expire_date', 'no'); \OC_Appconfig::setValue('core', 'shareapi_enforce_expire_date', 'no'); }
/** * Sets a value in the appconfig * @param string $app app * @param string $key key * @param string $value value * @return string true/false * * Sets a value. If the key did not exist before it will be created. */ public static function setAppValue($app, $key, $value) { try { \OC_Appconfig::setValue($app, $key, $value); } catch (Exception $e) { return false; } return true; }
/** * install an app already placed in the app folder * @param string $app id of the app to install * @return integer */ public static function installShippedApp($app) { //install the database if (is_file(OC_App::getAppPath($app) . "/appinfo/database.xml")) { OC_DB::createDbFromStructure(OC_App::getAppPath($app) . "/appinfo/database.xml"); } //run appinfo/install.php if (is_file(OC_App::getAppPath($app) . "/appinfo/install.php")) { include OC_App::getAppPath($app) . "/appinfo/install.php"; } $info = OC_App::getAppInfo($app); if (is_null($info)) { return false; } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); if (array_key_exists('ocsid', $info)) { OC_Appconfig::setValue($app, 'ocsid', $info['ocsid']); } //set remote/public handelers foreach ($info['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, $app . '/' . $path); } foreach ($info['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, $app . '/' . $path); } OC_App::setAppTypes($info['id']); return $info['id']; }
/** * @brief does a single task * @return boolean * * This method executes one task. It saves the last state and continues * with the next step. This method should be used by webcron and ajax * services. */ public static function doNextStep() { $laststep = OC_Appconfig::getValue('core', 'backgroundjobs_step', 'regular_tasks'); if ($laststep == 'regular_tasks') { // get last app $lasttask = OC_Appconfig::getValue('core', 'backgroundjobs_task', ''); // What's the next step? $regular_tasks = OC_BackgroundJob_RegularTask::all(); ksort($regular_tasks); $done = false; // search for next background job foreach ($regular_tasks as $key => $value) { if (strcmp($key, $lasttask) > 0) { OC_Appconfig::setValue('core', 'backgroundjobs_task', $key); $done = true; call_user_func($value); break; } } if ($done == false) { // Next time load queued tasks OC_Appconfig::setValue('core', 'backgroundjobs_step', 'queued_tasks'); } } else { $tasks = OC_BackgroundJob_QueuedTask::all(); if (count($tasks)) { $task = $tasks[0]; // delete job before we execute it. This prevents endless loops // of failing jobs. OC_BackgroundJob_QueuedTask::delete($task['id']); // execute job call_user_func(array($task['klass'], $task['method']), $task['parameters']); } else { // Next time load queued tasks OC_Appconfig::setValue('core', 'backgroundjobs_step', 'regular_tasks'); OC_Appconfig::setValue('core', 'backgroundjobs_task', ''); } } return true; }
* @copyright 2011 Dominik Schmidt dev@dominik-schmidt.de * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ $params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter'); foreach ($params as $param) { if (isset($_POST[$param])) { OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]); } } // fill template $tmpl = new OC_Template('user_ldap', 'settings'); foreach ($params as $param) { $value = OC_Appconfig::getValue('user_ldap', $param, ''); $tmpl->assign($param, $value); } // ldap_port has a default value $tmpl->assign('ldap_port', OC_Appconfig::getValue('user_ldap', 'ldap_port', OC_USER_BACKEND_LDAP_DEFAULT_PORT)); return $tmpl->fetchPage();
* * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ OC_JSON::checkSubAdminUser(); OCP\JSON::callCheck(); $username = isset($_POST["username"]) ? (string) $_POST["username"] : ''; if ($username === '' && !OC_User::isAdminUser(OC_User::getUser()) || !OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) { $l = \OC::$server->getL10N('core'); OC_JSON::error(array('data' => array('message' => $l->t('Authentication error')))); exit; } //make sure the quota is in the expected format $quota = (string) $_POST["quota"]; if ($quota !== 'none' and $quota !== 'default') { $quota = OC_Helper::computerFileSize($quota); $quota = OC_Helper::humanFileSize($quota); } // Return Success story if ($username) { \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota); } else { //set the default quota when no username is specified if ($quota === 'default') { //'default' as default quota makes no sense $quota = 'none'; } OC_Appconfig::setValue('files', 'default_quota', $quota); } OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
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'; } $class = self::$dbSetupClasses[$dbtype]; $dbSetup = new $class(self::getTrans(), 'db_structure.xml'); $error = array_merge($error, $dbSetup->validate($options)); if (count($error) != 0) { return $error; } //no errors, good $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); $datadir = htmlspecialchars_decode($options['directory']); 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, otherise 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_Util::generateRandomBytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file OC_Config::setValue('trusted_domains', $trustedDomains); OC_Config::setValue('datadirectory', $datadir); OC_Config::setValue('dbtype', $dbtype); OC_Config::setValue('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) { OC_Appconfig::setValue('core', 'installedat', microtime(true)); OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true)); OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); 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', ''); //create htaccess files for apache hosts if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } //and we are done OC_Config::setValue('installed', true); } return $error; }
/** * update the database for the app and call the update script * * @param string $appId * @return bool */ public static function updateApp($appId) { if (file_exists(self::getAppPath($appId) . '/appinfo/database.xml')) { OC_DB::updateDbFromStructure(self::getAppPath($appId) . '/appinfo/database.xml'); } if (!self::isEnabled($appId)) { return false; } if (file_exists(self::getAppPath($appId) . '/appinfo/update.php')) { self::loadApp($appId, false); include self::getAppPath($appId) . '/appinfo/update.php'; } //set remote/public handlers $appData = self::getAppInfo($appId); if (array_key_exists('ocsid', $appData)) { OC_Appconfig::setValue($appId, 'ocsid', $appData['ocsid']); } foreach ($appData['remote'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'remote_' . $name, $appId . '/' . $path); } foreach ($appData['public'] as $name => $path) { OCP\CONFIG::setAppValue('core', 'public_' . $name, $appId . '/' . $path); } self::setAppTypes($appId); $version = \OC_App::getAppVersion($appId); \OC_Appconfig::setValue($appId, 'installed_version', $version); return true; }
<?php OC_JSON::checkSubAdminUser(); OCP\JSON::callCheck(); $selectedGroups = isset($_POST["selectedGroups"]) ? json_decode($_POST["selectedGroups"]) : array(); $changedGroup = isset($_POST["changedGroup"]) ? $_POST["changedGroup"] : ''; if ($changedGroup !== '') { if (($key = array_search($changedGroup, $selectedGroups)) !== false) { unset($selectedGroups[$key]); } else { $selectedGroups[] = $changedGroup; } } else { \OCP\Util::writeLog('core', 'Can not update list of excluded groups from sharing, parameter missing', \OCP\Util::WARN); } \OC_Appconfig::setValue('core', 'shareapi_exclude_groups_list', implode(',', $selectedGroups));