protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); /** @var $user \OC\User\User */ $user = $this->userManager->get($username); if (is_null($user)) { $output->writeln("<error>There is no user called " . $username . "</error>"); return 1; } if ($input->isInteractive()) { /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); $password = $dialog->askHiddenResponse($output, '<question>Enter a new password: </question>', false); $confirm = $dialog->askHiddenResponse($output, '<question>Confirm the new password: </question>', false); if ($password === $confirm) { $success = $user->setPassword($password); if ($success) { $output->writeln("<info>Successfully reset password for " . $username . "</info>"); } else { $output->writeln("<error>Error while resetting password!</error>"); return 1; } } else { $output->writeln("<error>Passwords did not match!</error>"); return 1; } } else { $output->writeln("<error>Interactive input is needed for entering a new password!</error>"); return 1; } }
protected function execute(InputInterface $input, OutputInterface $output) { $path = $input->getOption('path'); if ($path) { $path = '/' . trim($path, '/'); list(, $user, ) = explode('/', $path, 3); $users = array($user); } else { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } } $quiet = $input->getOption('quiet'); if (count($users) === 0) { $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); return; } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } if ($this->userManager->userExists($user)) { $this->scanFiles($user, $path, $quiet, $output); } else { $output->writeln("<error>Unknown user {$user}</error>"); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $wasSuccessful = $this->userManager->get($input->getArgument('uid'))->delete(); if ($wasSuccessful === true) { $output->writeln('The specified user was deleted'); return; } $output->writeln('<error>The specified could not be deleted. Please check the logs.</error>'); }
protected function execute(InputInterface $input, OutputInterface $output) { $uid = $input->getArgument('uid'); $user = $this->userManager->get($uid); if (is_null($user)) { $output->writeln("<error>Invalid UID</error>"); return; } $this->manager->enableTwoFactorAuthentication($user); $output->writeln("Two-factor authentication enabled for user {$uid}"); }
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } $this->scanFiles($user, $output); } }
/** * get a list of all display names in a group * @param string $gid * @param string $search * @param int $limit * @param int $offset * @return array an array of display names (value) and user ids (key) */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $group = $this->get($gid); if (is_null($group)) { return array(); } // only user backends have the capability to do a complex search for users $groupUsers = $group->searchUsers('', $limit, $offset); $search = trim($search); if (!empty($search)) { //TODO: for OC 7 earliest: user backend should get a method to check selected users against a pattern $filteredUsers = $this->userManager->search($search); $testUsers = true; } else { $filteredUsers = array(); $testUsers = false; } $matchingUsers = array(); foreach ($groupUsers as $user) { if (!$testUsers || isset($filteredUsers[$user->getUID()])) { $matchingUsers[$user->getUID()] = $user->getDisplayName(); } } return $matchingUsers; }
public function updateCard($addressBookId, $uid) { /** * @param \Sabre\VObject\Component\VCard $vCard * @param \OC\User\User $user */ $user = $this->userManager->get($uid); $userId = $user->getUID(); $cardId = md5($userId) . ".vcf"; $card = $this->cardDavBackend->getCard($addressBookId, $cardId); if (!$card) { $this->insertCard($addressBookId, $uid); } else { $vCard = Reader::read($card['carddata']); $needsUpdate = $this->converterUser->updateCard($vCard, $user); if ($needsUpdate) { $groups = \OC::$server->getGroupManager()->getUserGroups($user); if ($groups) { foreach ($groups as $groupName => $groupInfo) { $vCard->add(new Text($vCard, 'CATEGORIES', $groupName)); } } $this->cardDavBackend->updateCard($addressBookId, $cardId, $vCard->serialize()); // $this->cardDavBackend->deleteCard($addressBookId, $cardId); // $this->insertCard($addressBookId, $uid); } } }
/** * logout the user from the session */ public function logout() { $this->manager->emit('\\OC\\User', 'logout'); $this->setUser(null); $this->setLoginname(null); $this->unsetMagicInCookie(); }
protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } if (count($users) === 0) { $output->writeln("<error>Please specify the user id to scan or \"--all\" to scan for all users</error>"); return; } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } $this->scanFiles($user, $output); } }
/** * Get all groups a user belongs to * @param string $uid Name of the user * @return array an array of group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ public static function getUserGroups($uid) { $user = self::$userManager->get($uid); if ($user) { return self::getManager()->getUserGroupIds($user); } else { return array(); } }
protected function execute(InputInterface $input, OutputInterface $output) { \OC_App::loadApps('authentication'); if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } if ($this->userManager->userExists($user)) { $this->scanFiles($user, $output); } else { $output->writeln("<error>Unknown user {$user}</error>"); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('user'); /** @var $user \OC\User\User */ $user = $this->userManager->get($username); if (is_null($user)) { $output->writeln("<error>There is no user called " . $username . "</error>"); return 1; } if ($input->getOption('password-from-env')) { $password = getenv('OC_PASS'); if (!$password) { $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); return 1; } } elseif ($input->isInteractive()) { /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ $dialog = $this->getHelperSet()->get('dialog'); if (\OCP\App::isEnabled('files_encryption')) { $output->writeln('<error>Warning: Resetting the password when using encryption will result in data loss!</error>'); if (!$dialog->askConfirmation($output, '<question>Do you want to continue?</question>', true)) { return 1; } } $password = $dialog->askHiddenResponse($output, '<question>Enter a new password: </question>', false); $confirm = $dialog->askHiddenResponse($output, '<question>Confirm the new password: </question>', false); if ($password !== $confirm) { $output->writeln("<error>Passwords did not match!</error>"); return 1; } } else { $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); return 1; } $success = $user->setPassword($password); if ($success) { $output->writeln("<info>Successfully reset password for " . $username . "</info>"); } else { $output->writeln("<error>Error while resetting password!</error>"); return 1; } }
protected function execute(InputInterface $input, OutputInterface $output) { $scanner = $this->container['Scanner']; $scanner->listen('\\OCA\\Music\\Utility\\Scanner', 'update', function ($path) use($output) { $output->writeln("Scanning <info>{$path}</info>"); }); if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } \OC_Util::tearDownFS(); \OC_Util::setupFS($user); $output->writeln("Start scan for <info>{$user}</info>"); $scanner->rescan($user, true); } }
protected function execute(InputInterface $input, OutputInterface $output) { $inputPath = $input->getOption('path'); if ($inputPath) { $inputPath = '/' . trim($inputPath, '/'); list(, $user, ) = explode('/', $inputPath, 3); $users = array($user); } else { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } } if (count($users) === 0) { $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); return; } # no messaging level option means: no full printout but statistics # $quiet means no print at all # $verbose means full printout including statistics # -q -v full stat # 0 0 no yes # 0 1 yes yes # 1 -- no no (quiet overrules verbose) $verbose = $input->getOption('verbose'); $quiet = $input->getOption('quiet'); # restrict the verbosity level to VERBOSITY_VERBOSE if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } if ($quiet) { $verbose = false; } $this->initTools(); foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } $path = $inputPath ? $inputPath : '/' . $user; if ($this->userManager->userExists($user)) { # full: printout data if $verbose was set $this->scanFiles($user, $path, $verbose, $output); } else { $output->writeln("<error>Unknown user {$user}</error>"); } } # stat: printout statistics if $quiet was not set if (!$quiet) { $this->presentStats($output); } }
protected function execute(InputInterface $input, OutputInterface $output) { // perform system reorganization $migration = new Migration($this->config, $this->view, $this->connection, $this->logger); $users = $input->getArgument('user_id'); if (!empty($users)) { foreach ($users as $user) { if ($this->userManager->userExists($user)) { $output->writeln("Migrating keys <info>{$user}</info>"); $migration->reorganizeFolderStructureForUser($user); } else { $output->writeln("<error>Unknown user {$user}</error>"); } } } else { $output->writeln("Reorganize system folder structure"); $migration->reorganizeSystemFolderStructure(); $migration->updateDB(); foreach ($this->userManager->getBackends() as $backend) { $name = get_class($backend); if ($backend instanceof IUserBackend) { $name = $backend->getBackendName(); } $output->writeln("Migrating keys for users on backend <info>{$name}</info>"); $limit = 500; $offset = 0; do { $users = $backend->getUsers('', $limit, $offset); foreach ($users as $user) { $output->writeln(" <info>{$user}</info>"); $migration->reorganizeFolderStructureForUser($user); } $offset += $limit; } while (count($users) >= $limit); } } $migration->finalCleanUp(); }
/** * Generate a new access token clients can authenticate with * * @PublicPage * @NoCSRFRequired * * @param string $user * @param string $password * @param string $name the name of the client * @return JSONResponse */ public function generateToken($user, $password, $name = 'unknown client') { if (is_null($user) || is_null($password)) { $response = new JSONResponse(); $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); return $response; } $loginName = $user; $user = $this->userManager->checkPassword($loginName, $password); if ($user === false) { $response = new JSONResponse(); $response->setStatus(Http::STATUS_UNAUTHORIZED); return $response; } if ($this->twoFactorAuthManager->isTwoFactorAuthenticated($user)) { $resp = new JSONResponse(); $resp->setStatus(Http::STATUS_UNAUTHORIZED); return $resp; } $token = $this->secureRandom->generate(128); $this->tokenProvider->generateToken($token, $user->getUID(), $loginName, $password, $name, IToken::PERMANENT_TOKEN); return ['token' => $token]; }
/** * returns all the Users from an array that really exists * @param string[] $userIds an array containing user IDs * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value */ private function getVerifiedUsers($userIds) { if (!is_array($userIds)) { return array(); } $users = array(); foreach ($userIds as $userId) { $user = $this->userManager->get($userId); if (!is_null($user)) { $users[$userId] = $user; } } return $users; }
/** * @brief Get all groups a user belongs to * @param string $uid Name of the user * @return array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ public static function getUserGroups($uid) { $user = self::$userManager->get($uid); if ($user) { $groups = self::getManager()->getUserGroups($user); $groupIds = array(); foreach ($groups as $group) { $groupIds[] = $group->getGID(); } return $groupIds; } else { return array(); } }
/** * Set the password of the user * * @param string $password * @param string $recoveryPassword for the encryption app to reset encryption keys * @return bool */ public function setPassword($password, $recoveryPassword = null) { if ($this->emitter) { $this->emitter->emit('\\OC\\User', 'preSetPassword', array($this, $password, $recoveryPassword)); } if ($this->backend->implementsActions(\OC_USER_BACKEND_SET_PASSWORD)) { $result = $this->backend->setPassword($this->uid, $password); if ($this->emitter) { $this->emitter->emit('\\OC\\User', 'postSetPassword', array($this, $password, $recoveryPassword)); } return !($result === false); } else { return false; } }
/** * check if it is a path which is excluded by ownCloud from encryption * * @param string $path * @return boolean */ public function isExcluded($path) { $normalizedPath = \OC\Files\Filesystem::normalizePath($path); $root = explode('/', $normalizedPath, 4); if (count($root) > 1) { //detect system wide folders if (in_array($root[1], $this->excludedPaths)) { return true; } // detect user specific folders if ($this->userManager->userExists($root[1]) && in_array($root[2], $this->excludedPaths)) { return true; } } return false; }
/** * @param string $token * @return string Resolved file path of the token * @throws \Exception In case share could not get properly resolved */ private function getPath($token) { $linkItem = Share::getShareByToken($token, false); if (is_array($linkItem) && isset($linkItem['uid_owner'])) { // seems to be a valid share $rootLinkItem = Share::resolveReShare($linkItem); if (isset($rootLinkItem['uid_owner'])) { if (!$this->userManager->userExists($rootLinkItem['uid_owner'])) { throw new \Exception('Owner of the share does not exist anymore'); } OC_Util::tearDownFS(); OC_Util::setupFS($rootLinkItem['uid_owner']); $path = Filesystem::getPath($linkItem['file_source']); if (!empty($path) && Filesystem::isReadable($path)) { return $path; } } } throw new \Exception('No file found belonging to file.'); }
/** * check if it is a path which is excluded by ownCloud from encryption * * @param string $path * @return boolean */ public function isExcluded($path) { $normalizedPath = Filesystem::normalizePath($path); $root = explode('/', $normalizedPath, 4); if (count($root) > 1) { // detect alternative key storage root $rootDir = $this->getKeyStorageRoot(); if ($rootDir !== '' && 0 === strpos(Filesystem::normalizePath($path), Filesystem::normalizePath($rootDir))) { return true; } //detect system wide folders if (in_array($root[1], $this->excludedPaths)) { return true; } // detect user specific folders if ($this->userManager->userExists($root[1]) && in_array($root[2], $this->excludedPaths)) { return true; } } return false; }
/** * get a list of all display names in a group * @param string $gid * @param string $search * @param int $limit * @param int $offset * @return array an array of display names (value) and user ids (key) */ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { $group = $this->get($gid); if (is_null($group)) { return array(); } $search = trim($search); $groupUsers = array(); if (!empty($search)) { // only user backends have the capability to do a complex search for users $searchOffset = 0; $searchLimit = $limit * 100; if ($limit === -1) { $searchLimit = 500; } do { $filteredUsers = $this->userManager->searchDisplayName($search, $searchLimit, $searchOffset); foreach ($filteredUsers as $filteredUser) { if ($group->inGroup($filteredUser)) { $groupUsers[] = $filteredUser; } } $searchOffset += $searchLimit; } while (count($groupUsers) < $searchLimit + $offset && count($filteredUsers) >= $searchLimit); if ($limit === -1) { $groupUsers = array_slice($groupUsers, $offset); } else { $groupUsers = array_slice($groupUsers, $offset, $limit); } } else { $groupUsers = $group->searchUsers('', $limit, $offset); } $matchingUsers = array(); foreach ($groupUsers as $groupUser) { $matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName(); } return $matchingUsers; }
public function triggerChange() { if ($this->emitter) { $this->emitter->emit('\\OC\\User', 'changeUser', array($this)); } }
public function listen(Manager $manager) { $manager->listen('\\OC\\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']); }
protected function execute(InputInterface $input, OutputInterface $output) { $inputPath = $input->getOption('path'); if ($inputPath) { $inputPath = '/' . trim($inputPath, '/'); list(, $user, ) = explode('/', $inputPath, 3); $users = array($user); } else { if ($input->getOption('all')) { $users = $this->userManager->search(''); } else { $users = $input->getArgument('user_id'); } } # no messaging level option means: no full printout but statistics # $quiet means no print at all # $verbose means full printout including statistics # -q -v full stat # 0 0 no yes # 0 1 yes yes # 1 -- no no (quiet overrules verbose) $verbose = $input->getOption('verbose'); $quiet = $input->getOption('quiet'); # restrict the verbosity level to VERBOSITY_VERBOSE if ($output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } if ($quiet) { $verbose = false; } # check quantity of users to be process and show it on the command line $users_total = count($users); if ($users_total === 0) { $output->writeln("<error>Please specify the user id to scan, \"--all\" to scan for all users or \"--path=...\"</error>"); return; } else { if ($users_total > 1) { $output->writeln("\nScanning files for {$users_total} users"); } } $this->initTools(); $user_count = 0; foreach ($users as $user) { if (is_object($user)) { $user = $user->getUID(); } $path = $inputPath ? $inputPath : '/' . $user; $user_count += 1; if ($this->userManager->userExists($user)) { # add an extra line when verbose is set to optical seperate users if ($verbose) { $output->writeln(""); } $output->writeln("Starting scan for user {$user_count} out of {$users_total} ({$user})"); # full: printout data if $verbose was set $this->scanFiles($user, $path, $verbose, $output); } else { $output->writeln("<error>Unknown user {$user_count} {$user}</error>"); } # check on each user if there was a user interrupt (ctrl-c) and exit foreach if ($this->hasBeenInterrupted()) { break; } } # stat: printout statistics if $quiet was not set if (!$quiet) { $this->presentStats($output); } }
public function triggerChange($feature, $value = null) { if ($this->emitter) { $this->emitter->emit('\\OC\\User', 'changeUser', array($this, $feature, $value)); } }