예제 #1
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);
         }
     }
 }
예제 #2
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');
 }
예제 #3
0
 /**
  * @NoAdminRequired
  *
  * @param int $offset
  * @param int $limit
  * @param string $gid GID to filter for
  * @param string $pattern Pattern to search for in the username
  * @param string $backend Backend to filter for (class-name)
  * @return DataResponse
  *
  * TODO: Tidy up and write unit tests - code is mainly static method calls
  */
 public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '')
 {
     // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
     if ($gid === '_everyone') {
         $gid = '';
     }
     // Remove backends
     if (!empty($backend)) {
         $activeBackends = $this->userManager->getBackends();
         $this->userManager->clearBackends();
         foreach ($activeBackends as $singleActiveBackend) {
             if ($backend === get_class($singleActiveBackend)) {
                 $this->userManager->registerBackend($singleActiveBackend);
                 break;
             }
         }
     }
     $users = [];
     if ($this->isAdmin) {
         if ($gid !== '') {
             $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
         } else {
             $batch = $this->userManager->search($pattern, $limit, $offset);
         }
         foreach ($batch as $user) {
             $users[] = $this->formatUserForIndex($user);
         }
     } else {
         $subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
         // New class returns IGroup[] so convert back
         $gids = [];
         foreach ($subAdminOfGroups as $group) {
             $gids[] = $group->getGID();
         }
         $subAdminOfGroups = $gids;
         // Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
         if ($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
             $gid = '';
         }
         // Batch all groups the user is subadmin of when a group is specified
         $batch = [];
         if ($gid === '') {
             foreach ($subAdminOfGroups as $group) {
                 $groupUsers = $this->groupManager->displayNamesInGroup($group, $pattern, $limit, $offset);
                 foreach ($groupUsers as $uid => $displayName) {
                     $batch[$uid] = $displayName;
                 }
             }
         } else {
             $batch = $this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset);
         }
         $batch = $this->getUsersForUID($batch);
         foreach ($batch as $user) {
             // Only add the groups, this user is a subadmin of
             $userGroups = array_values(array_intersect($this->groupManager->getUserGroupIds($user), $subAdminOfGroups));
             $users[] = $this->formatUserForIndex($user, $userGroups);
         }
     }
     return new DataResponse($users);
 }
예제 #4
0
파일: encryptall.php 프로젝트: ErikPel/core
 /**
  * create key-pair for every user
  */
 protected function createKeyPairs()
 {
     $this->output->writeln("\n");
     $progress = new ProgressBar($this->output);
     $progress->setFormat(" %message% \n [%bar%]");
     $progress->start();
     foreach ($this->userManager->getBackends() as $backend) {
         $limit = 500;
         $offset = 0;
         do {
             $users = $backend->getUsers('', $limit, $offset);
             foreach ($users as $user) {
                 if ($this->keyManager->userHasKeys($user) === false) {
                     $progress->setMessage('Create key-pair for ' . $user);
                     $progress->advance();
                     $this->setupUserFS($user);
                     $password = $this->generateOneTimePassword($user);
                     $this->userSetup->setupUser($user, $password);
                 } else {
                     // users which already have a key-pair will be stored with a
                     // empty password and filtered out later
                     $this->userPasswords[$user] = '';
                 }
             }
             $offset += $limit;
         } while (count($users) >= $limit);
     }
     $progress->setMessage('Key-pair created for all users');
     $progress->finish();
 }
예제 #5
0
 /**
  * @NoAdminRequired
  *
  * @param int $offset
  * @param int $limit
  * @param string $gid GID to filter for
  * @param string $pattern Pattern to search for in the username
  * @param string $backend Backend to filter for (class-name)
  * @return DataResponse
  *
  * TODO: Tidy up and write unit tests - code is mainly static method calls
  */
 public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '')
 {
     // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
     if ($gid === '_everyone') {
         $gid = '';
     }
     // Remove backends
     if (!empty($backend)) {
         $activeBackends = $this->userManager->getBackends();
         $this->userManager->clearBackends();
         foreach ($activeBackends as $singleActiveBackend) {
             if ($backend === get_class($singleActiveBackend)) {
                 $this->userManager->registerBackend($singleActiveBackend);
                 break;
             }
         }
     }
     //$users = ($gid !== '') ? Data::readGroupUsers($gid) : Data::readAllUsers();
     $users = \OCP\User::getDisplayNames();
     ksort($users, SORT_NATURAL | SORT_FLAG_CASE);
     //file_put_contents('123.txt',print_r($users,true));
     $users = array_diff($users, array(User::getUser()));
     $users = array_slice($users, 0);
     return new DataResponse(array('data' => $users, 'status' => 'success'));
 }
예제 #6
0
 /**
  * encrypt all user files with the master key
  *
  * @param ProgressBar $progress
  */
 protected function encryptAllUserFilesWithMasterKey(ProgressBar $progress)
 {
     $userNo = 1;
     foreach ($this->userManager->getBackends() as $backend) {
         $limit = 500;
         $offset = 0;
         do {
             $users = $backend->getUsers('', $limit, $offset);
             foreach ($users as $user) {
                 $userCount = "{$user} ({$userNo})";
                 $this->encryptUsersFiles($user, $progress, $userCount);
                 $userNo++;
             }
             $offset += $limit;
         } while (count($users) >= $limit);
     }
 }
예제 #7
0
파일: decryptall.php 프로젝트: kenwi/core
 /**
  * iterate over all user and encrypt their files
  * @param string $user which users files should be decrypted, default = all users
  */
 protected function decryptAllUsersFiles($user = '')
 {
     $this->output->writeln("\n");
     $userList = [];
     if (empty($user)) {
         $fetchUsersProgress = new ProgressBar($this->output);
         $fetchUsersProgress->setFormat(" %message% \n [%bar%]");
         $fetchUsersProgress->start();
         $fetchUsersProgress->setMessage("Fetch list of users...");
         $fetchUsersProgress->advance();
         foreach ($this->userManager->getBackends() as $backend) {
             $limit = 500;
             $offset = 0;
             do {
                 $users = $backend->getUsers('', $limit, $offset);
                 foreach ($users as $user) {
                     $userList[] = $user;
                 }
                 $offset += $limit;
                 $fetchUsersProgress->advance();
             } while (count($users) >= $limit);
             $fetchUsersProgress->setMessage("Fetch list of users... finished");
             $fetchUsersProgress->finish();
         }
     } else {
         $userList[] = $user;
     }
     $this->output->writeln("\n\n");
     $progress = new ProgressBar($this->output);
     $progress->setFormat(" %message% \n [%bar%]");
     $progress->start();
     $progress->setMessage("starting to decrypt files...");
     $progress->advance();
     $numberOfUsers = count($userList);
     $userNo = 1;
     foreach ($userList as $uid) {
         $userCount = "{$uid} ({$userNo} of {$numberOfUsers})";
         $this->decryptUsersFiles($uid, $progress, $userCount);
         $userNo++;
     }
     $progress->setMessage("starting to decrypt files... finished");
     $progress->finish();
     $this->output->writeln("\n\n");
 }
예제 #8
0
 /**
  * iterate over each user and move the keys to the new storage
  *
  * @param string $oldRoot
  * @param string $newRoot
  * @param OutputInterface $output
  */
 protected function moveUserKeys($oldRoot, $newRoot, OutputInterface $output)
 {
     $progress = new ProgressBar($output);
     $progress->start();
     foreach ($this->userManager->getBackends() as $backend) {
         $limit = 500;
         $offset = 0;
         do {
             $users = $backend->getUsers('', $limit, $offset);
             foreach ($users as $user) {
                 $progress->advance();
                 $this->setupUserFS($user);
                 $this->moveUserEncryptionFolder($user, $oldRoot, $newRoot);
             }
             $offset += $limit;
         } while (count($users) >= $limit);
     }
     $progress->finish();
 }