Ejemplo n.º 1
0
 /**
  * @param string $pattern which should match within the $searchProperties
  * @param array $searchProperties defines the properties within the query pattern should match
  * @param array $options - for future use. One should always have options!
  * @return array an array of contacts which are arrays of key-value-pairs
  */
 public function search($pattern, $searchProperties, $options)
 {
     $users = array();
     if ($pattern == '') {
         // Fetch all contacts
         $users = $this->userManager->search('');
     } else {
         foreach ($searchProperties as $property) {
             $result = array();
             if ($property === 'FN') {
                 $result = $this->userManager->searchDisplayName($pattern);
             } else {
                 if ($property === 'id') {
                     $result = $this->userManager->search($pattern);
                 }
             }
             if (is_array($result)) {
                 $users = array_merge($users, $result);
             }
         }
     }
     $contacts = array();
     foreach ($users as $user) {
         $contact = array("id" => $user->getUID(), "FN" => $user->getDisplayname(), "EMAIL" => array(), "IMPP" => array("x-owncloud-handle:" . $user->getUID()));
         $contacts[] = $contact;
     }
     return $contacts;
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->sourceUser = $input->getArgument('source-user');
     $this->destinationUser = $input->getArgument('destination-user');
     if (!$this->userManager->userExists($this->sourceUser)) {
         $output->writeln("<error>Unknown source user {$this->sourceUser}</error>");
         return;
     }
     if (!$this->userManager->userExists($this->destinationUser)) {
         $output->writeln("<error>Unknown destination user {$this->destinationUser}</error>");
         return;
     }
     // target user has to be ready
     if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
         $output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>");
         return;
     }
     $date = date('c');
     $this->finalTarget = "{$this->destinationUser}/files/transferred from {$this->sourceUser} on {$date}";
     // setup filesystem
     Filesystem::initMountPoints($this->sourceUser);
     Filesystem::initMountPoints($this->destinationUser);
     // analyse source folder
     $this->analyse($output);
     // collect all the shares
     $this->collectUsersShares($output);
     // transfer the files
     $this->transfer($output);
     // restore the shares
     $this->restoreShares($output);
 }
Ejemplo n.º 3
0
 /**
  * @NoAdminRequired
  * @UseSession
  *
  * @param string $oldPassword
  * @param string $newPassword
  * @return DataResponse
  */
 public function updatePrivateKeyPassword($oldPassword, $newPassword)
 {
     $result = false;
     $uid = $this->userSession->getUser()->getUID();
     $errorMessage = $this->l->t('Could not update the private key password.');
     //check if password is correct
     $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword);
     if ($passwordCorrect !== false) {
         $encryptedKey = $this->keyManager->getPrivateKey($uid);
         $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword);
         if ($decryptedKey) {
             $encryptedKey = $this->crypt->symmetricEncryptFileContent($decryptedKey, $newPassword);
             $header = $this->crypt->generateHeader();
             if ($encryptedKey) {
                 $this->keyManager->setPrivateKey($uid, $header . $encryptedKey);
                 $this->session->setPrivateKey($decryptedKey);
                 $result = true;
             }
         } else {
             $errorMessage = $this->l->t('The old password was not correct, please try again.');
         }
     } else {
         $errorMessage = $this->l->t('The current log-in password was not correct, please try again.');
     }
     if ($result === true) {
         $this->session->setStatus(Session::INIT_SUCCESSFUL);
         return new DataResponse(['message' => (string) $this->l->t('Private key password successfully updated.')]);
     } else {
         return new DataResponse(['message' => (string) $errorMessage], Http::STATUS_BAD_REQUEST);
     }
 }
Ejemplo n.º 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->sourceUser = $input->getArgument('source-user');
     $this->destinationUser = $input->getArgument('destination-user');
     if (!$this->userManager->userExists($this->sourceUser)) {
         $output->writeln("<error>Unknown source user {$this->sourceUser}</error>");
         return;
     }
     if (!$this->userManager->userExists($this->destinationUser)) {
         $output->writeln("<error>Unknown destination user {$this->destinationUser}</error>");
         return;
     }
     $date = date('c');
     $this->finalTarget = "{$this->destinationUser}/files/transferred from {$this->sourceUser} on {$date}";
     // setup filesystem
     Filesystem::initMountPoints($this->sourceUser);
     Filesystem::initMountPoints($this->destinationUser);
     // analyse source folder
     $this->analyse($output);
     // collect all the shares
     $this->collectUsersShares($output);
     // transfer the files
     $this->transfer($output);
     // restore the shares
     $this->restoreShares($output);
 }
Ejemplo n.º 5
0
 /**
  * start migration
  *
  * @return array
  */
 public function startMigration()
 {
     // allow as long execution on the web server as possible
     set_time_limit(0);
     try {
         $migration = new Migration($this->config, $this->view, $this->connection);
         $migration->reorganizeSystemFolderStructure();
         $migration->updateDB();
         foreach ($this->userManager->getBackends() as $backend) {
             $limit = 500;
             $offset = 0;
             do {
                 $users = $backend->getUsers('', $limit, $offset);
                 foreach ($users as $user) {
                     $migration->reorganizeFolderStructureForUser($user);
                 }
                 $offset += $limit;
             } while (count($users) >= $limit);
         }
         $migration->finalCleanUp();
     } catch (\Exception $e) {
         return array('data' => array('message' => (string) $this->l10n->t('A problem occurred, please check your log files (Error: %s)', [$e->getMessage()])), 'status' => 'error');
     }
     return array('data' => array('message' => (string) $this->l10n->t('Migration Completed')), 'status' => 'success');
 }
Ejemplo n.º 6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$input->getOption('debug')) {
         $this->scanner->listen('\\OCA\\Music\\Utility\\Scanner', 'update', function ($path) use($output) {
             $output->writeln("Scanning <info>{$path}</info>");
         });
     }
     $inputPath = $input->getOption('path');
     $path = false;
     if ($inputPath) {
         $path = '/' . trim($inputPath, '/');
         list(, $user, ) = explode('/', $path, 3);
         $users = array($user);
     } else {
         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>");
         $this->scanner->rescan($user, true, $path ? $path : $this->resolveUserFolder($user), $input->getOption('debug'), $output);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @param bool $allowHtml   Should HTML be used to format the parameter?
  * @param bool $verbose     Should paths, names, etc be shortened or full length
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter, $allowHtml, $verbose = false)
 {
     // If the username is empty, the action has been performed by a remote
     // user, or via a public share. We don't know the username in that case
     if ($parameter === '') {
         if ($allowHtml === null) {
             return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
         }
         if ($allowHtml) {
             return '<strong>' . $this->l->t('"remote user"') . '</strong>';
         } else {
             return $this->l->t('"remote user"');
         }
     }
     $user = $this->manager->get($parameter);
     $displayName = $user ? $user->getDisplayName() : $parameter;
     $parameter = Util::sanitizeHTML($parameter);
     if ($allowHtml === null) {
         return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
     }
     if ($allowHtml) {
         $avatarPlaceholder = '';
         if ($this->config->getSystemValue('enable_avatars', true)) {
             $avatarPlaceholder = '<div class="avatar" data-user="******"></div>';
         }
         return $avatarPlaceholder . '<strong>' . Util::sanitizeHTML($displayName) . '</strong>';
     } else {
         return $displayName;
     }
 }
Ejemplo n.º 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $users = $input->getArgument('user_id');
     if (!empty($users)) {
         foreach ($users as $user) {
             if ($this->userManager->userExists($user)) {
                 $output->writeln("Delete versions of   <info>{$user}</info>");
                 $this->deleteVersions($user);
             } else {
                 $output->writeln("<error>Unknown user {$user}</error>");
             }
         }
     } else {
         $output->writeln('Delete all versions');
         foreach ($this->userManager->getBackends() as $backend) {
             $name = get_class($backend);
             if ($backend instanceof IUserBackend) {
                 $name = $backend->getBackendName();
             }
             $output->writeln("Delete versions 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>");
                     $this->deleteVersions($user);
                 }
                 $offset += $limit;
             } while (count($users) >= $limit);
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * return a user specific instance of \OCP\IAvatar
  * @see \OCP\IAvatar
  * @param string $user the ownCloud user id
  * @return \OCP\IAvatar
  * @throws \Exception In case the username is potentially dangerous
  */
 public function getAvatar($user)
 {
     if (!$this->userManager->userExists($user)) {
         throw new \Exception('user does not exist');
     }
     return new Avatar($this->rootFolder->getUserFolder($user)->getParent(), $this->l);
 }
Ejemplo n.º 10
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $principalBackend = new Principal($this->config, $this->userManager);
     $this->backend = new CardDavBackend($this->dbConnection, $principalBackend);
     // ensure system addressbook exists
     $systemAddressBook = $this->ensureSystemAddressBookExists();
     $converter = new Converter();
     $output->writeln('Syncing users ...');
     $progress = new ProgressBar($output);
     $progress->start();
     $this->userManager->callForAllUsers(function ($user) use($systemAddressBook, $converter, $progress) {
         /** @var IUser $user */
         $name = $user->getBackendClassName();
         $userId = $user->getUID();
         $cardId = "{$name}:{$userId}.vcf";
         $card = $this->backend->getCard($systemAddressBook['id'], $cardId);
         if ($card === false) {
             $vCard = $converter->createCardFromUser($user);
             $this->backend->createCard($systemAddressBook['id'], $cardId, $vCard->serialize());
         } else {
             $vCard = Reader::read($card['carddata']);
             if ($converter->updateCard($vCard, $user)) {
                 $this->backend->updateCard($systemAddressBook['id'], $cardId, $vCard->serialize());
             }
         }
         $progress->advance();
     });
     $progress->finish();
     $output->writeln('');
 }
Ejemplo n.º 11
0
 public function testGetAvatarValidUser()
 {
     $this->userManager->expects($this->once())->method('get')->with('validUser')->willReturn(true);
     $folder = $this->getMock('\\OCP\\Files\\Folder');
     $this->rootFolder->expects($this->once())->method('getUserFolder')->with('validUser')->willReturn($folder);
     $folder->expects($this->once())->method('getParent')->will($this->returnSelf());
     $this->avatarManager->getAvatar('validUser');
 }
Ejemplo n.º 12
0
 /**
  * @dataProvider usersProvider
  * @param $query
  * @param $uid
  */
 public function testImpersonate($query, $uid)
 {
     $user = $this->getMock('\\OCP\\IUser');
     $user->expects($this->once())->method('getUID')->will($this->returnValue($uid));
     $this->userManager->expects($this->once())->method('search')->with($query, 1, 0)->will($this->returnValue([$user]));
     $this->userSession->expects($this->once())->method('setUser')->with($user);
     $this->assertEquals(new JSONResponse(), $this->controller->impersonate($query));
 }
Ejemplo n.º 13
0
 /**
  * return a user specific instance of \OCP\IAvatar
  * @see \OCP\IAvatar
  * @param string $user the ownCloud user id
  * @return \OCP\IAvatar
  * @throws \Exception In case the username is potentially dangerous
  */
 public function getAvatar($userId)
 {
     $user = $this->userManager->get($userId);
     if (is_null($user)) {
         throw new \Exception('user does not exist');
     }
     return new Avatar($this->rootFolder->getUserFolder($userId)->getParent(), $this->l, $user);
 }
Ejemplo n.º 14
0
 /**
  * Act on behalf on trash item owner
  * @param string $user
  * @return boolean
  */
 private function setupFS($user)
 {
     if (!$this->userManager->userExists($user)) {
         return false;
     }
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($user);
     return true;
 }
Ejemplo n.º 15
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!$this->userManager->userExists($user)) {
         throw new \InvalidArgumentException("User <{$user}> in unknown.");
     }
     $name = $input->getArgument('name');
     $this->cardDavBackend->createAddressBook("principals/users/{$user}", $name, []);
 }
Ejemplo n.º 16
0
 public function testRunWithUsersAndOffsetAtEndOfUserList()
 {
     $this->config->expects($this->at(0))->method('getAppValue')->with('files', 'cronjob_scan_files', 0)->will($this->returnValue(50));
     $this->userManager->expects($this->at(0))->method('search')->with('', 500, 50)->will($this->returnValue([]));
     $this->userManager->expects($this->at(1))->method('search')->with('', 500)->will($this->returnValue([]));
     $this->config->expects($this->at(1))->method('setAppValue')->with('files', 'cronjob_scan_files', 500);
     $this->scanFiles->expects($this->never())->method('runScanner');
     $this->invokePrivate($this->scanFiles, 'run', [[]]);
 }
Ejemplo n.º 17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!$this->userManager->userExists($user)) {
         throw new \InvalidArgumentException("User <{$user}> in unknown.");
     }
     $name = $input->getArgument('name');
     $caldav = new CalDavBackend($this->dbConnection);
     $caldav->createCalendar("principals/{$user}", $name, []);
 }
Ejemplo n.º 18
0
 /**
  * Generates a temp user
  * @param int $num number of users to generate
  * @return IUser[]|Iuser
  */
 protected function generateUsers($num = 1)
 {
     $users = array();
     for ($i = 0; $i < $num; $i++) {
         $user = $this->userManager->createUser($this->getUniqueID(), 'password');
         $this->users[] = $user;
         $users[] = $user;
     }
     return count($users) == 1 ? reset($users) : $users;
 }
Ejemplo n.º 19
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $this->userManager->get($input->getArgument('uid'));
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</error>');
         return;
     }
     $user->setEnabled(false);
     $output->writeln('<info>The specified user is disabled</info>');
 }
Ejemplo n.º 20
0
 /**
  * @inheritdoc
  */
 public function run(IOutput $output)
 {
     $output->startProgress();
     $this->userManager->callForAllUsers(function ($user) use($output) {
         /** @var IUser $user */
         $output->advance(1, $user->getDisplayName());
         $this->birthdayService->syncUser($user->getUID());
     });
     $output->finishProgress();
 }
Ejemplo n.º 21
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!$this->userManager->userExists($user)) {
         throw new \InvalidArgumentException("User <{$user}> in unknown.");
     }
     $principalBackend = new Principal($this->userManager, $this->groupManager);
     $name = $input->getArgument('name');
     $carddav = new CardDavBackend($this->dbConnection, $principalBackend, $this->logger);
     $carddav->createAddressBook("principals/users/{$user}", $name, []);
 }
Ejemplo n.º 22
0
 /**
  * become another user
  * @UseSession
  */
 public function impersonate($userid)
 {
     $users = $this->userManager->search($userid, 1, 0);
     if (count($users) > 0) {
         $user = array_shift($users);
         if (strcasecmp($user->getUID(), $userid) === 0) {
             $this->userSession->setUser($user);
         }
     }
     return new JSONResponse();
 }
Ejemplo n.º 23
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $uid = $input->getArgument('uid');
     if ($this->userManager->userExists($uid)) {
         $output->writeln('<error>The user "' . $uid . '" already exists.</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');
         $password = $dialog->askHiddenResponse($output, '<question>Enter password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm 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 password!</error>");
         return 1;
     }
     $user = $this->userManager->createUser($input->getArgument('uid'), $password);
     if ($user instanceof IUser) {
         $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
     } else {
         $output->writeln('<error>An error occurred while creating the user</error>');
         return 1;
     }
     if ($input->getOption('display-name')) {
         $user->setDisplayName($input->getOption('display-name'));
         $output->writeln('Display name set to "' . $user->getDisplayName() . '"');
     }
     $groups = $input->getOption('group');
     if (!empty($groups)) {
         // Make sure we init the Filesystem for the user, in case we need to
         // init some group shares.
         Filesystem::init($user->getUID(), '');
     }
     foreach ($groups as $groupName) {
         $group = $this->groupManager->get($groupName);
         if (!$group) {
             $this->groupManager->createGroup($groupName);
             $group = $this->groupManager->get($groupName);
             $output->writeln('Created group "' . $group->getGID() . '"');
         }
         $group->addUser($user);
         $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"');
     }
 }
Ejemplo n.º 24
0
 /**
  * @param IEvent $event
  * @param string $parameter The parameter to be formatted
  * @return string The formatted parameter
  */
 public function format(IEvent $event, $parameter)
 {
     // If the username is empty, the action has been performed by a remote
     // user, or via a public share. We don't know the username in that case
     if ($parameter === '') {
         return '<user display-name="' . Util::sanitizeHTML($this->l->t('"remote user"')) . '">' . Util::sanitizeHTML('') . '</user>';
     }
     $user = $this->manager->get($parameter);
     $displayName = $user ? $user->getDisplayName() : $parameter;
     $parameter = Util::sanitizeHTML($parameter);
     return '<user display-name="' . Util::sanitizeHTML($displayName) . '">' . Util::sanitizeHTML($parameter) . '</user>';
 }
Ejemplo n.º 25
0
 /**
  * become another user
  * @param string $userid
  * @UseSession
  * @return JSONResponse
  */
 public function impersonate($userid)
 {
     $oldUserId = $this->userSession->getUser()->getUID();
     $this->logger->warning("User {$oldUserId} trying to impersonate user {$userid}", ['app' => 'impersonate']);
     $user = $this->userManager->get($userid);
     if ($user === null) {
         return new JSONResponse("No user found for {$userid}", Http::STATUS_NOT_FOUND);
     } else {
         $this->logger->warning("changing to user {$userid}", ['app' => 'impersonate']);
         $this->userSession->setUser($user);
     }
     return new JSONResponse();
 }
Ejemplo n.º 26
0
 /**
  * A hack to access files and views. Better than before.
  *
  * @return bool
  */
 protected function initFS()
 {
     //Need any valid user to mount FS
     $results = $this->userManager->search('', 2, 0);
     $anyUser = array_pop($results);
     if (is_null($anyUser)) {
         \OC::$server->getLogger()->error("Failed to setup file system", ['app' => 'files_antivirus']);
         return false;
     }
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($anyUser->getUID());
     return true;
 }
Ejemplo n.º 27
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $this->userManager->get($input->getArgument('uid'));
     if (is_null($user)) {
         $output->writeln('<error>User does not exist</error>');
         return;
     }
     if ($user->delete()) {
         $output->writeln('<info>The specified user was deleted</info>');
         return;
     }
     $output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
 }
 /**
  * A hack to access files and views. Better than before.
  */
 protected function initFS()
 {
     //Need any valid user to mount FS
     $results = $this->userManager->search('', 2, 0);
     $anyUser = array_pop($results);
     if (is_null($anyUser)) {
         \OCP\Util::writeLog('files_antivirus', "Failed to setup file system", \OCP\Util::ERROR);
         return false;
     }
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($anyUser->getUID());
     return true;
 }
Ejemplo n.º 29
0
 /**
  * Lookup user display names
  *
  * @NoAdminRequired
  *
  * @param array $users
  *
  * @return JSONResponse
  */
 public function getDisplayNames($users)
 {
     $result = array();
     foreach ($users as $user) {
         $userObject = $this->userManager->get($user);
         if (is_object($userObject)) {
             $result[$user] = $userObject->getDisplayName();
         } else {
             $result[$user] = $user;
         }
     }
     $json = array('users' => $result, 'status' => 'success');
     return new JSONResponse($json);
 }
Ejemplo n.º 30
0
 /**
  * Returns a specific principal, specified by it's path.
  * The returned structure should be the exact same as from
  * getPrincipalsByPrefix.
  *
  * @param string $path
  * @return array
  */
 public function getPrincipalByPath($path)
 {
     list($prefix, $name) = explode('/', $path);
     $user = $this->userManager->get($name);
     if ($prefix === 'principals' && !is_null($user)) {
         $principal = ['uri' => 'principals/' . $user->getUID(), '{DAV:}displayname' => $user->getUID()];
         $email = $this->config->getUserValue($user->getUID(), 'settings', 'email');
         if ($email) {
             $principal['{http://sabredav.org/ns}email-address'] = $email;
         }
         return $principal;
     }
     return null;
 }