/** * @NoAdminRequired */ public function set() { \OCP\Config::setUserValue($this->api->getUserId(), 'tasks_enhanced', $this->params('type') . '_' . $this->params('setting'), $this->params('value')); $response = new JSONResponse(); $response->setData(); return $response; }
private function updateEmail($dn) { $email = null; $emailAttribute = $this->connection->ldapEmailAttribute; if (!empty($emailAttribute)) { $aEmail = $this->readAttribute($dn, $emailAttribute); if ($aEmail && count($aEmail) > 0) { $email = $aEmail[0]; } if (!is_null($email)) { \OCP\Config::setUserValue($this->dn2username($dn), 'settings', 'email', $email); } } }
/** * @NoAdminRequired */ public function set() { $request = $this->request; //$request = json_decode(file_get_contents('php://input'), true); $key = $request->post['key']; $value = $request->post['value']; $response = new JSONResponse(); if (is_null($key) || $key === "") { $response->bailOut(App::$l10n->t('No key is given.')); } if (is_null($value) || $value === "") { $response->bailOut(App::$l10n->t('No value is given.')); } if (\OCP\Config::setUserValue(\OCP\User::getUser(), 'contacts', $key, $value)) { $response->setParams(array('key' => $key, 'value' => $value)); return $response; } else { $response->bailOut(App::$l10n->t('Could not set preference: ' . $key . ':' . $value)); } }
private static function update_quota($uid, $quota) { if (!empty($quota)) { \OCP\Config::setUserValue($uid, 'files', 'quota', \OCP\Util::computerFileSize($quota)); } }
\OC::$session->close(); $dispatcher = new Dispatcher($params); $dispatcher->dispatch('GroupController', 'deleteGroup'); }); $this->create('contacts_categories_rename', 'groups/rename')->post()->action(function ($params) { \OC::$session->close(); $dispatcher = new Dispatcher($params); $dispatcher->dispatch('GroupController', 'renameGroup'); }); $this->create('contacts_categories_addto', 'groups/addto/{categoryId}')->post()->action(function ($params) { \OC::$session->close(); $dispatcher = new Dispatcher($params); $dispatcher->dispatch('GroupController', 'addToGroup'); }); $this->create('contacts_categories_removefrom', 'groups/removefrom/{categoryId}')->post()->action(function ($params) { \OC::$session->close(); $dispatcher = new Dispatcher($params); $dispatcher->dispatch('GroupController', 'removeFromGroup'); })->requirements(array('categoryId')); $this->create('contacts_setpreference', 'preference/set')->post()->action(function ($params) { \OC::$session->close(); $dispatcher = new Dispatcher($params); $dispatcher->dispatch('SettingsController', 'set'); }); $this->create('contacts_index_properties', 'indexproperties/{user}/')->post()->action(function ($params) { \OC::$session->close(); // TODO: Add BackgroundJob for this. \OCP\Util::emitHook('OCA\\Contacts', 'indexProperties', array()); \OCP\Config::setUserValue($params['user'], 'contacts', 'contacts_properties_indexed', 'yes'); \OCP\JSON::success(array('isIndexed' => true)); })->requirements(array('user'))->defaults(array('user' => \OCP\User::getUser()));
/** * @brief sets the list of ldap addressbooks in the preferences * with the list given in parameter * @param the new list * @returns result|false */ protected function setAddressbookList(array $addressbookList) { $key = $this->name . "_list"; $data = json_encode($addressbookList); return $data ? \OCP\Config::setUserValue($this->userid, 'contacts', $key, $data) : false; }
/** * @NoAdminRequired */ public function disablefirstrun() { \OCP\Config::setUserValue(\OCP\User::getUser(), 'firstpassmanrun', 'show', 0); echo "Succes!"; }
/** * Set a user defined value * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we want to store the value under * @param string $key the key under which the value is being stored * @param string $value the value that you want to store */ public function setUserValue($userId, $appName, $key, $value) { \OCP\Config::setUserValue($userId, $appName, $key, $value); }
* 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/>. * */ \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('activity'); \OCP\JSON::callCheck(); $l = \OCP\Util::getL10N('activity'); $token = $tokenUrl = ''; if ($_POST['enable'] === 'true') { // Check for collisions $token = \OCP\Util::generateRandomBytes(); $preferences = new \OC\Preferences(\OC_DB::getConnection()); $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token); while (!empty($conflicts)) { $token = \OCP\Util::generateRandomBytes(); $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token); } $tokenUrl = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('activity.rss', array('token' => $token))); } \OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'rsstoken', $token); \OCP\JSON::success(array('data' => array('message' => $l->t('Your settings have been updated.'), 'rsslink' => $tokenUrl)));
<?php /** * ownCloud - Documents App * * @author Victor Dubiniuk * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com * * This file is licensed under the Affero General Public License version 3 or * later. */ namespace OCA\Documents; \OCP\JSON::callCheck(); \OCP\JSON::checkLoggedIn(); $l = \OC_L10N::get('documents'); $savePath = isset($_POST['savePath']) ? $_POST['savePath'] : null; if (!is_null($savePath)) { if (\OC\Files\Filesystem::file_exists($savePath) === false) { if (!\OC\Files\Filesystem::mkdir($savePath)) { \OCP\JSON::error(array('data' => array('message' => $l->t('An error occurred while changing directory.')))); } } \OCP\Config::setUserValue(\OCP\User::getUser(), 'documents', 'save_path', $savePath); \OCP\JSON::success(array('data' => array('message' => $l->t('Directory saved successfully.')))); exit; } exit;
* * 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/>. * */ \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('activity'); \OCP\JSON::callCheck(); $notify_email = $notify_stream = array(); $l = \OCP\Util::getL10N('activity'); $data = new \OCA\Activity\Data(\OC::$server->getActivityManager()); $types = $data->getNotificationTypes($l); foreach ($types as $type => $desc) { \OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'notify_email_' . $type, !empty($_POST[$type . '_email'])); \OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'notify_stream_' . $type, !empty($_POST[$type . '_stream'])); } $email_batch_time = 3600; if ($_POST['notify_setting_batchtime'] == \OCA\Activity\UserSettings::EMAIL_SEND_DAILY) { $email_batch_time = 3600 * 24; } if ($_POST['notify_setting_batchtime'] == \OCA\Activity\UserSettings::EMAIL_SEND_WEEKLY) { $email_batch_time = 3600 * 24 * 7; } \OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'notify_setting_batchtime', $email_batch_time); \OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'notify_setting_self', !empty($_POST['notify_setting_self'])); \OCP\JSON::success(array("data" => array("message" => $l->t('Your settings have been updated.'))));
/** * store meta data for a file or folder * * @param string $file * @param array $data * * @return int file id */ public function put($file, array $data) { if ($file === '' && isset($data['etag'])) { return \OCP\Config::setUserValue(\OCP\User::getUser(), 'files_sharing', 'etag', $data['etag']); } else { if ($cache = $this->getSourceCache($file)) { return $cache->put($this->files[$file], $data); } } return false; }
/** * @brief Sets a calendar (in)active * @param integer $id * @param boolean $active * @return boolean */ public static function setCalendarActive($id, $active) { $userid = \OCP\User::getUser(); $calendar = self::find($id); if ($calendar['userid'] !== $userid) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); if ($sharedCalendar) { \OCP\Config::setUserValue($userid, App::$appname, 'calendar_' . $id, $active); } } else { $dbObject = \OC::$server->getDb(); $calendarDB = new CalendarDAO($dbObject, $userid); $bUpdateCalendar = $calendarDB->activate($active, $id); return $bUpdateCalendar; } return true; }
/** * scan vcards for categories. * @param $vccontacts VCards to scan. null to check all vcards for the current user. */ public static function scanCategories($vccontacts = null) { if (\OCP\Config::getUserValue(\OCP\User::getUser(), 'contacts', 'categories_scanned', 'no') === 'yes') { return; } if (is_null($vccontacts)) { $vcaddressbooks = Addressbook::all(\OCP\USER::getUser()); if (count($vcaddressbooks) > 0) { $vcaddressbookids = array(); foreach ($vcaddressbooks as $vcaddressbook) { if ($vcaddressbook['userid'] === \OCP\User::getUser()) { $vcaddressbookids[] = $vcaddressbook['id']; } } $start = 0; $batchsize = 10; $categories = new \OC_VCategories('contact'); while ($vccontacts = VCard::all($vcaddressbookids, $start, $batchsize)) { $cards = array(); foreach ($vccontacts as $vccontact) { $cards[] = array($vccontact['id'], $vccontact['carddata']); } \OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, \OCP\Util::DEBUG); // only reset on first batch. $categories->rescan($cards, true, $start == 0 ? true : false); $start += $batchsize; } } } \OCP\Config::setUserValue(\OCP\User::getUser(), 'contacts', 'categories_scanned', 'yes'); }
/** * @brief set user config value * * @param string $key key for value to change * @param string $value value to use * @return bool success */ public static function set($key, $value) { return \OCP\Config::setUserValue(\OCP\User::getUser(), 'files_opds', $key, $value); }
/** * @NoAdminRequired */ public function deleteAddressBook() { $params = $this->request->urlParams; $response = new JSONResponse(); $backend = $this->app->getBackend($params['backend']); if (!$backend->hasAddressBookMethodFor(\OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('The "%s" backend does not support deleting address books', array($backend->name)), 501); } $addressBookInfo = $backend->getAddressBook($params['addressBookId']); if (!$addressBookInfo['permissions'] & \OCP\PERMISSION_DELETE) { throw new \Exception(App::$l10n->t('You do not have permissions to delete the "%s" address book', array($addressBookInfo['displayname'])), 403); } if (!$backend->deleteAddressBook($params['addressBookId'])) { throw new \Exception(App::$l10n->t('Error deleting address book'), 500); } \OCP\Config::setUserValue($this->userId, 'contacts', 'last_address_book_deleted', time()); return $response; }
/** * @brief Sets a calendar (in)active * @param integer $id * @param boolean $active * @return boolean */ public static function setCalendarActive($id, $active) { if ($id !== 'birthday_' . \OCP\User::getUser()) { $calendar = self::find($id); if ($calendar['userid'] !== \OCP\User::getUser()) { $sharedCalendar = \OCP\Share::getItemSharedWithBySource(App::SHARECALENDAR, App::SHARECALENDARPREFIX . $id); if ($sharedCalendar) { \OCP\Config::setUserValue(\OCP\USER::getUser(), App::$appname, 'calendar_' . $id, $active); } /* if (!$sharedCalendar || !($sharedCalendar['permissions'] & \OCP\PERMISSION_UPDATE)) { throw new \Exception( App::$l10n->t( 'You do not have the permissions to update this calendar.' ) ); }*/ } else { $stmt = \OCP\DB::prepare('UPDATE `' . App::CldCalendarTable . '` SET `active` = ? WHERE `id` = ?'); $stmt->execute(array((int) $active, $id)); } } else { \OCP\Config::setUserValue(\OCP\USER::getUser(), App::$appname, 'calendar_' . $id, $active); } return true; }
public function getUuid($uid) { //check backend status if (!$this->enabled) { return false; } $this->connect(); $uid = $this->access->escapeFilterPart($uid); //find out dn of the user name $filter = \OCP\Util::mb_str_replace('%uid', $uid, $this->access->connection->ldapLoginFilter, 'UTF-8'); $ldap_users = $this->access->fetchListOfUsers($filter, 'dn'); if (count($ldap_users) < 1) { return false; } $dn = $ldap_users[0]; //do we have a username for him/her? $ocname = $this->access->dn2username($dn); if ($ocname) { \OCP\Config::setUserValue($ocname, 'user_ldap', 'firstLoginAccomplished', 1); return $ocname; } return false; }
/** * @brief determine the user's home directory * @param string $uid the owncloud username * @return boolean */ private function determineHomeDir($uid) { if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { $attr = substr($this->connection->homeFolderNamingRule, strlen('attr:')); $homedir = $this->readAttribute($this->username2dn($uid), $attr); if ($homedir) { $homedir = \OCP\Config::getSystemValue("datadirectory", \OC::$SERVERROOT . "/data") . '/' . $homedir[0]; \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir); return $homedir; } } //fallback and default: username $homedir = \OCP\Config::getSystemValue("datadirectory", \OC::$SERVERROOT . "/data") . '/' . $uid; \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir); return $homedir; }
/** * @brief Enable the FirstRunWizard */ public static function disable() { \OCP\Config::setUserValue(\OCP\User::getUser(), 'firstrunwizard', 'show', 0); }
/** * mark the filecache as upgrade * * @param string $user */ static function upgradeDone($user) { \OCP\Config::setUserValue($user, 'files', 'cache_version', 5); }
/** * @param array $params */ public static function shareHook($params) { if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { if (isset($params['uidOwner'])) { $uidOwner = $params['uidOwner']; } else { $uidOwner = \OCP\User::getUser(); } $users = \OCP\Share::getUsersItemShared($params['itemType'], $params['fileSource'], $uidOwner, true, false); if (!empty($users)) { while (!empty($users)) { $reshareUsers = array(); foreach ($users as $user) { if ($user !== $uidOwner) { $etag = \OC\Files\Filesystem::getETag(''); \OCP\Config::setUserValue($user, 'files_sharing', 'etag', $etag); // Look for reshares $reshareUsers = array_merge($reshareUsers, \OCP\Share::getUsersItemShared('file', $params['fileSource'], $user, true)); } } $users = $reshareUsers; } } } }
/** * scan vcards for categories. * @param $vccontacts VCards to scan. null to check all vcards for the current user. */ public static function scanCategories($vccontacts = null) { if (\OCP\Config::getUserValue(\OCP\User::getUser(), self::$appname, 'categories_scanned', 'no') === 'yes') { return; } if (is_null($vccontacts)) { $vcaddressbooks = Addressbook::all(\OCP\USER::getUser()); if (count($vcaddressbooks) > 0) { $vcaddressbookids = array(); foreach ($vcaddressbooks as $vcaddressbook) { if ($vcaddressbook['userid'] === \OCP\User::getUser()) { $vcaddressbookids[] = $vcaddressbook['id']; } } $start = 0; $batchsize = 10; $categories = \OC::$server->getTagManager()->load(self::$appname); $getName = function ($tag) { return $tag['name']; }; $tags = array_map($getName, $categories->getTags()); $categories->delete($tags); while ($vccontacts = VCard::all($vcaddressbookids, $start, $batchsize)) { $cards = array(); foreach ($vccontacts as $vccontact) { $cards[] = array($vccontact['id'], $vccontact['carddata']); } \OCP\Util::writeLog(self::$appname, __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, \OCP\Util::DEBUG); // only reset on first batch. /* $categories->rescan($cards, true, ($start == 0 ? true : false));*/ $start += $batchsize; } } } \OCP\Config::setUserValue(\OCP\User::getUser(), self::$appname, 'categories_scanned', 'yes'); }
/** * @brief sets the preferences for the addressbook given in parameter * @param string $id * @param array the preferences, format array('param1' => 'value', 'param2' => 'value') * @return boolean */ public function setPreferences($addressbookid, array $params) { $key = 'prefs_' . $this->combinedKey($addressbookid); $data = json_encode($params); return $data ? \OCP\Config::setUserValue($this->userid, 'contacts', $key, $data) : false; }
/** * Generate a private/public key pair. * * @param * User ID$user. * @param * Passphrase to $passphrase * * @return array('privateKey', 'publicKey') */ public static function generateKeyPair($user, $passphrase) { /* Create the private and public key */ $res = openssl_pkey_new(); /* Extract the private key from $res to $privKey */ if (!openssl_pkey_export($res, $privKey, $passphrase)) { return false; } /* Extract the public key from $res to $pubKey */ $pubKey = openssl_pkey_get_details($res); if ($pubKey === false) { return false; } $pubKey = $pubKey['key']; // We now store the public key unencrypted in the user preferences. // The private key already is encrypted with the user's password, // so there is no need to encrypt it again. \OCP\Config::setUserValue($user, 'roundcube', 'publicSSLKey', $pubKey); \OCP\Config::setUserValue($user, 'roundcube', 'privateSSLKey', $privKey); $uncryptedPrivKey = openssl_get_privatekey($privKey, $passphrase); return array('privateKey' => $uncryptedPrivKey, 'publicKey' => $pubKey); }
public static function addAccount($user_id, $email, $host, $port, $user, $password, $ssl_mode) { $id = time(); $account_string = 'account[' . $id . ']'; \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[name]', $user); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[email]', $email); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[host]', $host); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[port]', $port); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[user]', $user); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[password]', base64_encode($password)); \OCP\Config::setUserValue($user_id, 'mail', $account_string . '[ssl_mode]', $ssl_mode); $account_ids = \OCP\Config::getUserValue($user_id, 'mail', 'accounts', ''); if ($account_ids) { $account_ids = explode(',', $account_ids); } else { $account_ids = array(); } $account_ids[] = $id; $account_ids = implode(",", $account_ids); \OCP\Config::setUserValue($user_id, 'mail', 'accounts', $account_ids); return $id; }
protected static function setUserValue($key, $value) { return \OCP\Config::setUserValue(\OCP\User::getUser(), self::APP_ID, $key, $value); }
/** * Shortcut for setting a user defined value * @param $key the key under which the value is being stored * @param $value the value that you want to store */ public function setUserValue($key, $value, $user = null) { if ($user === null) { $user = $this->getUserId(); } \OCP\Config::setUserValue($user, $this->appName, $key, $value); }
/** * @brief Check if the password is correct * @param $uid The username * @param $password The password * @returns true/false * * Check if the password is correct without logging in the user */ public function checkPassword($uid, $password) { $uid = $this->access->escapeFilterPart($uid); //find out dn of the user name $filter = \OCP\Util::mb_str_replace('%uid', $uid, $this->access->connection->ldapLoginFilter, 'UTF-8'); $ldap_users = $this->access->fetchListOfUsers($filter, 'dn'); if (count($ldap_users) < 1) { return false; } $dn = $ldap_users[0]; //do we have a username for him/her? $ocname = $this->access->dn2username($dn); if ($ocname) { //update some settings, if necessary $this->updateQuota($dn); $this->updateEmail($dn); //are the credentials OK? if (!$this->access->areCredentialsValid($dn, $password)) { return false; } \OCP\Config::setUserValue($ocname, 'user_ldap', 'firstLoginAccomplished', 1); $this->updateAvatar($ocname, $dn); //give back the display name return $ocname; } return false; }
/** * Shortcut for setting a user defined value * @param $key the key under which the value is being stored * @param $value the value that you want to store */ protected function setUserValue($key, $value) { \OCP\Config::setUserValue($this->userId, 'news', $key, $value); }