예제 #1
0
파일: decryptall.php 프로젝트: kenwi/core
 /**
  * start to decrypt all files
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $user which users data folder should be decrypted, default = all users
  * @return bool
  * @throws \Exception
  */
 public function decryptAll(InputInterface $input, OutputInterface $output, $user = '')
 {
     $this->input = $input;
     $this->output = $output;
     if (!empty($user) && $this->userManager->userExists($user) === false) {
         $this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again');
         return false;
     }
     $this->output->writeln('prepare encryption modules...');
     if ($this->prepareEncryptionModules($user) === false) {
         return false;
     }
     $this->output->writeln(' done.');
     $this->decryptAllUsersFiles($user);
     if (empty($this->failed)) {
         $this->output->writeln('all files could be decrypted successfully!');
     } else {
         $this->output->writeln('Files for following users couldn\'t be decrypted, ');
         $this->output->writeln('maybe the user is not set up in a way that supports this operation: ');
         foreach ($this->failed as $uid => $paths) {
             $this->output->writeln('    ' . $uid);
         }
         $this->output->writeln('');
     }
     return true;
 }
예제 #2
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);
 }
예제 #3
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);
 }
예제 #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;
     }
     // 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);
 }
예제 #5
0
파일: cleanup.php 프로젝트: kenwi/core
 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);
         }
     }
 }
예제 #6
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;
 }
예제 #7
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, []);
 }
예제 #8
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, []);
 }
예제 #9
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, []);
 }
예제 #10
0
파일: add.php 프로젝트: BacLuc/newGryfiPage
 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() . '"');
     }
 }
 /**
  * Delete a share (owner unShares the file)
  *
  * @param IShare $share
  */
 public function delete(IShare $share)
 {
     list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith());
     $isOwner = false;
     // if the local user is the owner we can send the unShare request directly...
     if ($this->userManager->userExists($share->getShareOwner())) {
         $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken());
         $this->revokeShare($share, true);
         $isOwner = true;
     } else {
         // ... if not we need to correct ID for the unShare request
         $remoteId = $this->getRemoteId($share);
         $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken());
         $this->revokeShare($share, false);
     }
     // send revoke notification to the other user, if initiator and owner are not the same user
     if ($share->getShareOwner() !== $share->getSharedBy()) {
         $remoteId = $this->getRemoteId($share);
         if ($isOwner) {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
         } else {
             list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner());
         }
         $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken());
     }
     $this->removeShareFromTable($share);
 }
 /**
  * @NoAdminRequired
  *
  * @param string $username
  * @param string $password
  * @param array $groups
  * @param string $email
  * @return DataResponse
  */
 public function create($username, $password, array $groups = array(), $email = '')
 {
     if ($email !== '' && !$this->mail->validateAddress($email)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$this->isAdmin) {
         $userId = $this->userSession->getUser()->getUID();
         if (!empty($groups)) {
             foreach ($groups as $key => $group) {
                 if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) {
                     unset($groups[$key]);
                 }
             }
         }
         if (empty($groups)) {
             $groups = $this->subAdminFactory->getSubAdminsOfGroups($userId);
         }
     }
     if ($this->userManager->userExists($username)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
     }
     try {
         $user = $this->userManager->createUser($username, $password);
     } catch (\Exception $exception) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
     }
     if ($user instanceof User) {
         if ($groups !== null) {
             foreach ($groups as $groupName) {
                 $group = $this->groupManager->get($groupName);
                 if (empty($group)) {
                     $group = $this->groupManager->createGroup($groupName);
                 }
                 $group->addUser($user);
             }
         }
         /**
          * Send new user mail only if a mail is set
          */
         if ($email !== '') {
             $this->config->setUserValue($username, 'settings', 'email', $email);
             // data for the mail template
             $mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
             $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
             $mailContent = $mail->render();
             $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
             $plainTextMailContent = $mail->render();
             $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
             try {
                 $this->mail->send($email, $username, $subject, $mailContent, $this->fromMailAddress, $this->defaults->getName(), 1, $plainTextMailContent);
             } catch (\Exception $e) {
                 $this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
             }
         }
         // fetch users groups
         $userGroups = $this->groupManager->getUserGroupIds($user);
         return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
     }
     return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
 }
예제 #13
0
 /**
  * @NoCSRFRequired
  * @PublicPage
  *
  * @param string $userId
  * @param int $size
  * @return DataResponse|DataDisplayResponse
  */
 public function getAvatar($userId, $size)
 {
     if (!$this->userManager->userExists($userId)) {
         return new DataResponse([], Http::STATUS_NOT_FOUND);
     }
     if ($size > 2048) {
         $size = 2048;
     } elseif ($size <= 0) {
         $size = 64;
     }
     $avatar = $this->avatarManager->getAvatar($userId);
     $image = $avatar->get($size);
     if ($image instanceof \OCP\IImage) {
         $resp = new DataDisplayResponse($image->data(), Http::STATUS_OK, ['Content-Type' => $image->mimeType()]);
         $resp->setETag(crc32($image->data()));
     } else {
         $user = $this->userManager->get($userId);
         $userName = $user ? $user->getDisplayName() : '';
         $resp = new DataResponse(['data' => ['displayname' => $userName]]);
     }
     $resp->addHeader('Pragma', 'public');
     $resp->cacheFor(0);
     $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
     return $resp;
 }
예제 #14
0
 /**
  * check if we are the initiator or the owner of a re-share and return the correct UID
  *
  * @param Share\IShare $share
  * @return string
  */
 protected function getCorrectUid(Share\IShare $share)
 {
     if ($this->userManager->userExists($share->getShareOwner())) {
         return $share->getShareOwner();
     }
     return $share->getSharedBy();
 }
예제 #15
0
 protected function checkTags($offset)
 {
     $query = $this->connection->getQueryBuilder();
     $query->select('uid')->from('vcategory')->groupBy('uid')->orderBy('uid')->setMaxResults(50)->setFirstResult($offset);
     $result = $query->execute();
     $users = [];
     $hadResults = false;
     while ($row = $result->fetch()) {
         $hadResults = true;
         if (!$this->userManager->userExists($row['uid'])) {
             $users[] = $row['uid'];
         }
     }
     $result->closeCursor();
     if (!$hadResults) {
         // No more tags, stop looping
         return false;
     }
     if (!empty($users)) {
         $query = $this->connection->getQueryBuilder();
         $query->delete('vcategory')->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY)));
         $this->deletedTags += $query->execute();
     }
     return true;
 }
예제 #16
0
 protected function sendEmail($user, $proceed)
 {
     if ($this->isDataEncrypted && !$proceed) {
         throw new EncryptedDataException();
     }
     if (!$this->userManager->userExists($user)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure ' . 'your username is correct.'));
     }
     $token = hash('sha256', \OC_Util::generateRandomBytes(30));
     // Hash the token again to prevent timing attacks
     $this->config->setUserValue($user, 'owncloud', 'lostpassword', hash('sha256', $token));
     $email = $this->config->getUserValue($user, 'settings', 'email');
     if (empty($email)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.'));
     }
     $link = $this->getLink('core.lost.resetform', $user, $token);
     $tmpl = new \OC_Template('core/lostpassword', 'email');
     $tmpl->assign('link', $link, false);
     $msg = $tmpl->fetchPage();
     try {
         // FIXME: should be added to the container and injected in here
         \OC_Mail::send($email, $user, $this->l10n->t('%s password reset', array($this->defaults->getName())), $msg, $this->from, $this->defaults->getName());
     } catch (\Exception $e) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
     }
 }
예제 #17
0
 /**
  * @param string $user
  * @throws \Exception
  */
 protected function sendEmail($user)
 {
     if (!$this->userManager->userExists($user)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
     }
     $email = $this->config->getUserValue($user, 'settings', 'email');
     if (empty($email)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.'));
     }
     $token = $this->secureRandom->getMediumStrengthGenerator()->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
     $this->config->setUserValue($user, 'owncloud', 'lostpassword', $token);
     $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token));
     $tmpl = new \OC_Template('core/lostpassword', 'email');
     $tmpl->assign('link', $link, false);
     $msg = $tmpl->fetchPage();
     try {
         $message = $this->mailer->createMessage();
         $message->setTo([$email => $user]);
         $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
         $message->setPlainBody($msg);
         $message->setFrom([$this->from => $this->defaults->getName()]);
         $this->mailer->send($message);
     } catch (\Exception $e) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
     }
 }
예제 #18
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
         return 404;
     }
     if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
         $output->writeln('<error>Can\'t change applicables on personal mounts</error>');
         return 1;
     }
     $addUsers = $input->getOption('add-user');
     $removeUsers = $input->getOption('remove-user');
     $addGroups = $input->getOption('add-group');
     $removeGroups = $input->getOption('remove-group');
     $applicableUsers = $mount->getApplicableUsers();
     $applicableGroups = $mount->getApplicableGroups();
     if (count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0 || $input->getOption('remove-all')) {
         foreach ($addUsers as $addUser) {
             if (!$this->userManager->userExists($addUser)) {
                 $output->writeln('<error>User "' . $addUser . '" not found</error>');
                 return 404;
             }
         }
         foreach ($addGroups as $addGroup) {
             if (!$this->groupManager->groupExists($addGroup)) {
                 $output->writeln('<error>Group "' . $addGroup . '" not found</error>');
                 return 404;
             }
         }
         if ($input->getOption('remove-all')) {
             $applicableUsers = [];
             $applicableGroups = [];
         } else {
             $applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
             $applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
             $applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
             $applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
         }
         $mount->setApplicableUsers($applicableUsers);
         $mount->setApplicableGroups($applicableGroups);
         $this->globalService->updateStorage($mount);
     }
     $this->writeArrayInOutputFormat($input, $output, ['users' => $applicableUsers, 'groups' => $applicableGroups]);
 }
예제 #19
0
 /**
  * Check for generic requirements before creating a share
  *
  * @param \OCP\Share\IShare $share
  * @throws \InvalidArgumentException
  * @throws GenericShareException
  */
 protected function generalCreateChecks(\OCP\Share\IShare $share)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         // We expect a valid user as sharedWith for user shares
         if (!$this->userManager->userExists($share->getSharedWith())) {
             throw new \InvalidArgumentException('SharedWith is not a valid user');
         }
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             // We expect a valid group as sharedWith for group shares
             if (!$this->groupManager->groupExists($share->getSharedWith())) {
                 throw new \InvalidArgumentException('SharedWith is not a valid group');
             }
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 if ($share->getSharedWith() !== null) {
                     throw new \InvalidArgumentException('SharedWith should be empty');
                 }
             } else {
                 // We can't handle other types yet
                 throw new \InvalidArgumentException('unkown share type');
             }
         }
     }
     // Verify the initiator of the share is set
     if ($share->getSharedBy() === null) {
         throw new \InvalidArgumentException('SharedBy should be set');
     }
     // Cannot share with yourself
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $share->getSharedBy()) {
         throw new \InvalidArgumentException('Can\'t share with yourself');
     }
     // The path should be set
     if ($share->getNode() === null) {
         throw new \InvalidArgumentException('Path should be set');
     }
     // And it should be a file or a folder
     if (!$share->getNode() instanceof \OCP\Files\File && !$share->getNode() instanceof \OCP\Files\Folder) {
         throw new \InvalidArgumentException('Path should be either a file or a folder');
     }
     // Check if we actually have share permissions
     if (!$share->getNode()->isShareable()) {
         $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Permissions should be set
     if ($share->getPermissions() === null) {
         throw new \InvalidArgumentException('A share requires permissions');
     }
     // Check that we do not share with more permissions than we have
     if ($share->getPermissions() & ~$share->getNode()->getPermissions()) {
         $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Check that read permissions are always set
     if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
         throw new \InvalidArgumentException('Shares need at least read permissions');
     }
 }
예제 #20
0
 /**
  * @param string $userId
  * @return \OCP\Files\Folder
  * @throws SetUpException
  */
 public function setUpUserHome($userId = null)
 {
     if (is_null($userId)) {
         $user = $this->userSession->getUser();
     } else {
         $user = $this->userManager->get($userId);
     }
     if (is_null($user) || !$this->userManager->userExists($user->getUID())) {
         throw new SetUpException('could not set up user home for ' . json_encode($user));
     }
     if ($user !== $this->userSession->getUser()) {
         \OC_Util::tearDownFS();
         $this->userSession->setUser($user);
     }
     \OC_Util::setupFS($user->getUID());
     return $this->getOrCreateSubFolder($this->rootFolder, '/' . $user->getUID());
 }
예제 #21
0
 /**
  * move user encryption folder to new root folder
  *
  * @param string $user
  * @param string $oldRoot
  * @param string $newRoot
  * @throws \Exception
  */
 protected function moveUserEncryptionFolder($user, $oldRoot, $newRoot)
 {
     if ($this->userManager->userExists($user)) {
         $source = $oldRoot . '/' . $user . '/files_encryption';
         $target = $newRoot . '/' . $user . '/files_encryption';
         if ($this->rootView->is_dir($source) && $this->targetExists($target) === false) {
             $this->prepareParentFolder($newRoot . '/' . $user);
             $this->rootView->rename($source, $target);
         }
     }
 }
예제 #22
0
 /**
  * get owner from give path, path relative to data/ expected
  *
  * @param string $path relative to data/
  * @return string
  * @throws \BadMethodCallException
  */
 public function getOwner($path)
 {
     $owner = '';
     $parts = explode('/', $path, 3);
     if (count($parts) > 1) {
         $owner = $parts[1];
         if ($this->userManager->userExists($owner) === false) {
             throw new \BadMethodCallException('Unknown user: '******'method expects path to a user folder relative to the data folder');
         }
     }
     return $owner;
 }
예제 #23
0
 /**
  * check if it is a file located in data/user/files only files in the
  * 'files' directory should be moved to the trash
  *
  * @param $path
  * @return bool
  */
 protected function shouldMoveToTrash($path)
 {
     $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path);
     $parts = explode('/', $normalized);
     if (count($parts) < 4) {
         return false;
     }
     if ($this->userManager->userExists($parts[1]) && $parts[2] == 'files') {
         return true;
     }
     return false;
 }
예제 #24
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();
     });
     // remove no longer existing
     $allCards = $this->backend->getCards($systemAddressBook['id']);
     foreach ($allCards as $card) {
         $vCard = Reader::read($card['carddata']);
         $uid = $vCard->UID->getValue();
         // load backend and see if user exists
         if (!$this->userManager->userExists($uid)) {
             $this->backend->deleteCard($systemAddressBook['id'], $card['uri']);
         }
     }
     $progress->finish();
     $output->writeln('');
 }
예제 #25
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $user = $input->getArgument('user');
     if (!is_null($user)) {
         if (!$this->userManager->userExists($user)) {
             throw new \InvalidArgumentException("User <{$user}> in unknown.");
         }
         $output->writeln("Start birthday calendar sync for {$user}");
         $this->birthdayService->syncUser($user);
         return;
     }
     $output->writeln("Start birthday calendar sync for all users ...");
     $p = new ProgressBar($output);
     $p->start();
     $this->userManager->callForAllUsers(function ($user) use($p) {
         $p->advance();
         /** @var IUser $user */
         $this->birthdayService->syncUser($user->getUID());
     });
     $p->finish();
     $output->writeln('');
 }
예제 #26
0
 /**
  * Act on behalf on trash item owner
  * @param string $user
  * @return boolean
  */
 private function setupFS($user)
 {
     if (!$this->userManager->userExists($user)) {
         return false;
     }
     //Check if this user has a trashbin directory
     $view = new \OC\Files\View('/' . $user);
     if (!$view->is_dir('/files_trashbin/files')) {
         return false;
     }
     \OC_Util::tearDownFS();
     \OC_Util::setupFS($user);
     return true;
 }
예제 #27
0
파일: users.php 프로젝트: jincreator/core
 /**
  * Get the groups a user is a subadmin of
  *
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function getUserSubAdminGroups($parameters)
 {
     $user = $parameters['userid'];
     // Check if the user exists
     if (!$this->userManager->userExists($user)) {
         return new OC_OCS_Result(null, 101, 'User does not exist');
     }
     // Get the subadmin groups
     if (!($groups = OC_SubAdmin::getSubAdminsGroups($user))) {
         return new OC_OCS_Result(null, 102, 'Unknown error occurred');
     } else {
         return new OC_OCS_Result($groups);
     }
 }
예제 #28
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->service->setup();
     if ($input->hasArgument('user')) {
         $user = $input->getArgument('user');
         if (!$this->userManager->userExists($user)) {
             throw new \InvalidArgumentException("User <{$user}> in unknown.");
         }
         $output->writeln("Start migration for {$user}");
         $this->service->migrateForUser($user);
         return;
     }
     $output->writeln("Start migration of all known users ...");
     $p = new ProgressBar($output);
     $p->start();
     $this->userManager->callForAllUsers(function ($user) use($p) {
         $p->advance();
         /** @var IUser $user */
         $this->service->migrateForUser($user->getUID());
     });
     $p->finish();
     $output->writeln('');
 }
예제 #29
0
 public function testGetUserOnNonExistingUser()
 {
     $user = $this->generateUsers();
     $this->groupManager->get('admin')->addUser($user);
     $this->userSession->setUser($user);
     $params = array();
     $params['userid'] = $this->getUniqueID();
     while ($this->userManager->userExists($params['userid'])) {
         $params['userid'] = $this->getUniqueID();
     }
     $result = $this->api->getUser($params);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertFalse($result->succeeded());
     $this->assertEquals(\OCP\API::RESPOND_NOT_FOUND, $result->getStatusCode());
 }
예제 #30
0
 public function syncInstance(\Closure $progressCallback)
 {
     $systemAddressBook = $this->getLocalSystemAddressBook();
     $this->userManager->callForAllUsers(function ($user) use($systemAddressBook, $progressCallback) {
         $this->updateUser($user);
         $progressCallback();
     });
     // remove no longer existing
     $allCards = $this->backend->getCards($systemAddressBook['id']);
     foreach ($allCards as $card) {
         $vCard = Reader::read($card['carddata']);
         $uid = $vCard->UID->getValue();
         // load backend and see if user exists
         if (!$this->userManager->userExists($uid)) {
             $this->deleteUser($card['uri']);
         }
     }
 }