Ejemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::bootstrapProcessWire($output);
     $name = $input->getArgument('name');
     $email = $input->getOption('email');
     $pass = $input->getOption('password');
     $roles = explode(",", $input->getOption('roles'));
     $helper = $this->getHelper('question');
     if (!$email) {
         $question = new Question('Please enter a email address : ', 'email');
         $email = $helper->ask($input, $output, $question);
     }
     if (!$pass) {
         $question = new Question('Please enter a password : '******'password');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $pass = $helper->ask($input, $output, $question);
     }
     if (!\ProcessWire\wire("pages")->get("name={$name}") instanceof \ProcessWire\NullPage) {
         $output->writeln("<error>User '{$name}' already exists!</error>");
         exit(1);
     }
     $user = $this->createUser($email, $name, $this->userContainer, $pass);
     $user->save();
     if ($input->getOption('roles')) {
         $this->attachRolesToUser($name, $roles, $output);
     }
     if ($pass) {
         $output->writeln("<info>User '{$name}' created successfully!</info>");
     } else {
         $output->writeln("<info>User '{$name}' created successfully! Please do not forget to set a password.</info>");
     }
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var WardenSetupService $wardenSetupService */
     $wardenSetupService = $this->getContainer()->get('warden_setup');
     /** @var UserProviderService $userProviderService */
     $userProviderService = $this->getContainer()->get('user_provider');
     if ($userProviderService->isSetup() && !$input->getOption('regenerate')) {
         $output->writeln('Warden username and password is already setup - check the README file if you need to regenerate.');
         return;
     }
     $helper = $this->getHelper('question');
     $usernameQuestion = new Question('Please enter the admin username [admin]: ', 'admin');
     $username = $helper->ask($input, $output, $usernameQuestion);
     $passwordQuestion = new Question('Please enter the admin password (minimum of 8 characters): ', '');
     $passwordQuestion->setValidator(function ($value) {
         if (trim($value) == '') {
             throw new \Exception('The password can not be empty');
         }
         if (strlen($value) < 8) {
             throw new \Exception('Password provided is too short - must be minimum of 8 characters');
         }
         return $value;
     });
     $passwordQuestion->setMaxAttempts(3);
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $password = $helper->ask($input, $output, $passwordQuestion);
     $output->writeln(' - Setting up the password file ...');
     $userProviderService->generateLoginFile($username, $password);
     $output->writeln(' - Setting up the CSS file ...');
     $wardenSetupService->generateCSSFile();
     $output->writeln('Warden installation complete.');
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $usernameQuestion = new Question('E-mail: ');
     $usernameQuestion->setValidator(function ($value) {
         if (trim($value) === '') {
             throw new \Exception('E-mail can not be empty');
         }
         if (!Validators::isEmail($value)) {
             throw new \Exception('E-mail is not valid');
         }
         return $value;
     });
     $passwordQuestion = new Question('Password: '******'') {
             throw new \Exception('The password can not be empty');
         }
         return $value;
     });
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $username = $questionHelper->ask($input, $output, $usernameQuestion);
     $password = $questionHelper->ask($input, $output, $passwordQuestion);
     $name = $questionHelper->ask($input, $output, new Question('Name: '));
     $user = $this->userFacade->add($username, $password, $name);
     $output->writeln('User ' . $user->getEmail() . ' was successfully created!');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Mysql();
     $server->setHostname($input->getArgument("host"));
     $server->setUser("provisioning");
     $server->setPassword($this->createPassword());
     $server->setDatabase("provisioning");
     $server->setMode($input->getArgument("mode"));
     $server->setType($input->getArgument("type"));
     $server->setActive(false);
     // convert errors to PDOExceptions
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
     $dsn = sprintf("mysql:host=%s;port=%s;charset=utf8", $server->getHostname(), 3306);
     $pdo = new \PDO($dsn, $input->getArgument("user"), $password, $options);
     $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     $pdo->exec("SET NAMES utf8;");
     $pdo->exec("CREATE USER '{$server->getUser()}'@'%' IDENTIFIED BY '{$server->getPassword()}';");
     $pdo->exec("GRANT CREATE, DROP, GRANT OPTION, LOCK TABLES, REFERENCES, EVENT, ALTER, DELETE, INDEX, INSERT, SELECT, UPDATE, CREATE TEMPORARY TABLES, TRIGGER, CREATE VIEW, SHOW VIEW, ALTER ROUTINE, CREATE ROUTINE, EXECUTE, CREATE USER, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, USAGE ON *.* TO '{$server->getUser()}' WITH GRANT OPTION;");
     $pdo->exec("CREATE DATABASE {$server->getDatabase()} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;");
     // Write to DB
     $entityManager = $this->getProvisioningServer("mysql")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getMySqlServersTable([$server], $output);
     $table->render();
 }
 /**
  * Execute the command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = $input->getOption('db');
     if (empty($db)) {
         throw new \InvalidArgumentException('You must define the database name with --db');
     }
     $password = $input->getOption('password');
     if (is_null($password)) {
         $helper = $this->getHelper('question');
         $question = new Question('Password: '******'host'), $input->getOption('user'), $password);
     } catch (\Exception $e) {
         throw new \RuntimeException("Can't connect to the database. Check your credentials");
     }
     $writer = new \Inet\Neuralyzer\Configuration\Writer();
     $ignoreFields = $input->getOption('ignore-field');
     $writer->protectCols($input->getOption('protect'));
     // Override the protection if fields are defined
     if (!empty($ignoreFields)) {
         $writer->protectCols(true);
         $writer->setProtectedCols($ignoreFields);
     }
     $writer->setIgnoredTables($input->getOption('ignore-table'));
     $data = $writer->generateConfFromDB($pdo, new \Inet\Neuralyzer\Guesser());
     $writer->save($data, $input->getOption('file'));
     $output->writeln('<comment>Configuration written to ' . $input->getOption('file') . '</comment>');
 }
Ejemplo n.º 6
0
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $password = getenv('VAULT_PASSWORD');
     $tries = 0;
     while (!$password) {
         $question = new Question('Vault password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $this->vault = new Vault($password, $output);
     // Defaults
     $this->vault->setStoragePath(getcwd() . '/vault');
     $this->vault->setWorkPath(getcwd() . '/secure');
     $this->vault->verify();
     // Load droid.yml
     $filename = $this->getVaultFilename();
     if ($filename && file_exists($filename)) {
         $loader = new JsonLoader();
         $loader->load($vault, $filename);
     } else {
     }
     return parent::doRun($input, $output);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Redshift();
     $server->setHostname($input->getArgument("hostname"));
     $server->setConnectionId($input->getArgument("connectionId"));
     $server->setUser("provisioning");
     $server->setPassword($this->createPassword());
     $server->setDatabase("provisioning");
     $server->setMode("active");
     $server->setActive(false);
     // convert errors to PDOExceptions
     $options = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_EMULATE_PREPARES => false];
     $dsn = "pgsql:host={$server->getHostname()};port=5439;dbname={$input->getArgument("database")}";
     $pdo = new \PDO($dsn, $input->getArgument("user"), $password, $options);
     $pdo->exec("CREATE USER {$server->getUser()} CREATEUSER PASSWORD '{$server->getPassword()}';");
     $pdo->exec("CREATE DATABASE {$server->getDatabase()};");
     $pdo->exec("REVOKE ALL PRIVILEGES ON SCHEMA public FROM PUBLIC;");
     // Write to DB
     $entityManager = $this->getProvisioningServer("redshift")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getRedshiftServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument("login");
     $helper = $this->getHelper('question');
     $question = new Question("Unix password for « {$login} » : ");
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $input->getArgument("password") ? $input->getArgument("password") : $helper->ask($input, $output, $question);
     $blih = new Blih($login, $password);
     $blihRepositoriesResponse = $blih->repository()->all();
     if ($blihRepositoriesResponse->code == 200) {
         $user = $this->getUserOrCreateIt($login);
         $repositoryNames = array_keys(get_object_vars($blihRepositoriesResponse->body->repositories));
         foreach ($repositoryNames as $repositoryName) {
             $output->writeln("> Repository « {$login}/{$repositoryName} »");
             $repository = $this->getRepoOrCreateIt($user, $repositoryName);
             $aclResponse = $blih->repository($repositoryName)->acl()->get();
             if ($aclResponse->code == 200) {
                 $acls = get_object_vars($aclResponse->body);
                 foreach ($acls as $aclLogin => $acl) {
                     $output->writeln("  ACL for « {$aclLogin} »: {$acl}");
                     $aclUser = $this->getUserOrCreateIt($aclLogin);
                     $repositoryACL = $this->getACLOrCreateIt($aclUser, $repository);
                     $repositoryACL->setR(strpos($acl, "r") !== false);
                     $repositoryACL->setW(strpos($acl, "w") !== false);
                     $repositoryACL->setA(strpos($acl, "a") !== false);
                     $this->getContainer()->get("doctrine")->getManager()->persist($repositoryACL);
                 }
             }
             $output->writeln("");
             $this->getContainer()->get("doctrine")->getManager()->persist($repository);
             $this->getContainer()->get("doctrine")->getManager()->flush();
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("password")) {
         $password = $input->getOption("password");
     } else {
         $question = new Question('Password: '******'question');
         $password = $helper->ask($input, $output, $question);
     }
     $server = new Server\Database\Redshift();
     $server->setHostname($input->getArgument("host"));
     $server->setConnectionId($input->getArgument("connectionId"));
     $server->setUser($input->getArgument("user"));
     $server->setPassword($password);
     $server->setDatabase($input->getArgument("database"));
     $server->setMode("active");
     $server->setActive(false);
     // Write to DB
     $entityManager = $this->getProvisioningServer("redshift")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getRedshiftServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 10
0
 /**
  * Ask the user the given secret question.
  *
  * @param  string  $question
  * @return string
  */
 public function secret($question)
 {
     $question = '<comment>' . $question . '</comment> ';
     $question = new Question($question);
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     return $this->getHelperSet()->get('question')->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 11
0
 private function askForPassword()
 {
     $helper = $this->getHelper('question');
     $question = new Question('What is the new user\'s password: ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     return $helper->ask($this->input, $this->output, $question);
 }
Ejemplo n.º 12
0
 /**
  * @param $message
  * @return string
  */
 public function askHiddenResponse($message)
 {
     $this->clearLine();
     $this->output->writeln("\n");
     $question = new Question('<question>' . $message . '</question> ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $var = $this->dialog->ask($this->input, $this->output, $question);
     return $var;
 }
Ejemplo n.º 13
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $safeName = $input->getArgument('safe');
     if (empty($safeName)) {
         $safeNames = $SafeController->getSafeNames();
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('<question>Please select the safe for this secret:</question> ', $safeNames);
         $safeName = $helper->ask($input, $output, $question);
     }
     if (empty($safeName)) {
         throw new \Exception("Invalid safe name");
     }
     $output->writeln('');
     $output->writeln(sprintf("<info>Using safe '%s'... </info>", $safeName));
     $keyName = $input->getArgument('key');
     if (empty($keyName)) {
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please enter the key name for this secret :</question> ');
         $keyName = $helper->ask($input, $output, $question);
     }
     if (empty($keyName)) {
         throw new \Exception("Invalid key name");
     }
     $value = $input->getArgument('value');
     if (empty($value)) {
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please enter the value for this secret (output hidden):</question> ');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $value = $helper->ask($input, $output, $question);
     }
     if (empty($value) && !file_exists($value)) {
         throw new \Exception("Invalid value");
     }
     if (file_exists($value)) {
         $value = file_get_contents($value);
     }
     $output->writeln('');
     $output->write(sprintf("Creating secret '%s'... ", $keyName));
     $SecretController = new SecretController();
     try {
         $safe = $SafeController->view($safeName);
         $SecretController->create($safe, $keyName, $value);
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $output->writeln('<info>DONE</info>');
     $output->writeln('');
 }
Ejemplo n.º 14
0
 protected function requestSlackCredentials(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $output->writeln('<info>Please sign in to Slack to continue. Your username and password are not stored.</info>');
     $emailQuestion = new Question('Email: ');
     $email = $helper->ask($input, $output, $emailQuestion);
     $passwordQuestion = new Question('Password: ');
     $passwordQuestion->setHidden(true);
     $passwordQuestion->setHiddenFallback(false);
     $password = $helper->ask($input, $output, $passwordQuestion);
     return array($email, $password);
 }
Ejemplo n.º 15
0
 /**
  * Ask a question
  * 
  * @param string $question  Question to ask
  * @param mixed  $default   Default value
  * @param bool   $hidden    Hide response
  * @param bool   $required  User input is required
  * @return mixed
  */
 public function ask($question, $default = null, $hidden = false, $required = true)
 {
     $helper = $this->getHelper('question');
     $q = new Question($question, $default);
     if ($hidden) {
         $q->setHidden(true);
         $q->setHiddenFallback(false);
     }
     if ($required) {
         $q->setValidator([$this, 'assertNotEmpty']);
         $q->setMaxAttempts(2);
     }
     return $helper->ask($this->input, $this->output, $q);
 }
Ejemplo n.º 16
0
 private function getPasswordQuestion($questionText)
 {
     $question = new Question($questionText);
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $question->setValidator(function ($answer) {
         $answer = trim($answer);
         if (5 > strlen($answer)) {
             throw new \InvalidArgumentException('The password should be at least 6 charaters.');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     return $question;
 }
Ejemplo n.º 17
0
 protected function enterData(QuestionHelper $helper, InputInterface $input, OutputInterface $output, $label, $errorMessage, $hidden = false)
 {
     $question = new Question($this->decorateInfo($label));
     if ($hidden) {
         $question->setHidden(true);
         $question->setHiddenFallback(false);
     }
     $question->setValidator(function ($value) use(&$errorMessage) {
         if (trim($value) == '') {
             throw new \Exception($errorMessage);
         }
         return $value;
     });
     return $helper->ask($input, $output, $question);
 }
Ejemplo n.º 18
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $username = $input->getArgument('username');
     $passwordQuestion = new Question('What is the new password for ' . $username . '? (characters are not printed)' . PHP_EOL);
     $passwordQuestion->setHidden(true);
     $passwordQuestion->setHiddenFallback(false);
     $password = $helper->ask($input, $output, $passwordQuestion);
     $confirmationQuestion = new Question('Confirmation:' . PHP_EOL);
     $confirmationQuestion->setHidden(true);
     $confirmationQuestion->setHiddenFallback(false);
     $confirmation = $helper->ask($input, $output, $confirmationQuestion);
     if ($this->validatePassword($output, $password, $confirmation)) {
         $this->resetPassword($output, $username, $password);
     }
 }
Ejemplo n.º 19
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $algo = $input->getOption('algorithm');
     if (!in_array($algo, hash_algos())) {
         $output->writeln('Invalid algorithm: ' . $algo);
         return 1;
     }
     $iterations = $input->getOption('iterations');
     if (!is_int($iterations) || $iterations < self::MIN_ITERATIONS) {
         $output->writeln('Number of iterations invalid or too small (at least ' . self::MIN_ITERATIONS . '): ' . $iterations);
         return 1;
     }
     $length = $input->getOption('key-length');
     if (!is_int($iterations) || $iterations < 0) {
         $output->writeln('Invalid key length: ' . $iterations);
         return 1;
     }
     if ($input->getArgument('password')) {
         $password = $input->getArgument('password');
     } elseif (!$input->getOption('no-interaction')) {
         $helper = $this->getHelper('question');
         $question = new Question('Password: '******'') {
                 throw new \Exception('The password cannot be blank');
             }
             return $value;
         });
         $password = $helper->ask($input, $output, $question);
         $question = new Question('Re-type password: '******'<error>Passwords do not match</error>');
             return 1;
         }
     } else {
         $output->writeln('Password required');
         return 1;
     }
     $salt = $this->random_bytes(32);
     $hash = $this->hash_pbkdf2($algo, $password, $salt, $iterations, $length, true);
     $output->writeln(self::encode_hash($hash, $salt, $algo, $iterations, $length));
 }
Ejemplo n.º 20
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $path = $input->getOption('path');
     $user_name = $input->getArgument('username');
     $password = $input->getOption('password');
     $admin = $input->getOption('admin');
     $active = $input->getOption('active');
     if ($input->getOption('ask-password')) {
         $helper = $this->getHelper('question');
         $question = new Question("Please enter the new password for user {$user_name}: ", null);
         defined('PHPUNIT_SUGARCLI_TESTSUITE') || $question->setHidden(true);
         defined('PHPUNIT_SUGARCLI_TESTSUITE') || $question->setHiddenFallback(true);
         $password = $helper->ask($input, $output, $question);
     }
     $additionnal_fields = array();
     foreach ($this->fields_mapping as $option => $field_name) {
         $value = $input->getOption($option);
         if (!is_null($value)) {
             $additionnal_fields[$field_name] = $value;
         }
     }
     try {
         $um = new UsersManager($this->getService('sugarcrm.entrypoint'));
         if ($this->isCreate($input)) {
             $um->createUser($user_name, $additionnal_fields);
             // Users are active by default.
             if (is_null($active)) {
                 $active = true;
             }
         } else {
             $um->updateUser($user_name, $additionnal_fields);
         }
         if (!is_null($admin)) {
             $um->setAdmin($user_name, $this->getBoolean($admin));
         }
         if (!is_null($active)) {
             $um->setActive($user_name, $this->getBoolean($active));
         }
         if (!is_null($password)) {
             $um->setPassword($user_name, $password);
         }
     } catch (BeanNotFoundException $e) {
         $logger->error("User '{$user_name}' doesn't exists on the SugarCRM located at '{$path}'.");
         return ExitCode::EXIT_USER_NOT_FOUND;
     }
 }
Ejemplo n.º 21
0
 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pullRequestId = $input->getArgument(self::PULL_REQUEST_ARGUMENT);
     list($owner, $repository) = explode("/", $input->getArgument(self::REPOSITORY_ARGUMENT));
     $githubToken = $input->getOption(self::GITHUB_TOKEN_OPTION);
     $githubUser = $input->getOption(self::GITHUB_USER_OPTION);
     $githubPass = false;
     $codeStandard = $input->getOption(self::CODE_STANDARD_OPTION);
     if (!empty($githubUser)) {
         $helper = $this->getHelper('question');
         $question = new Question('Password:'******'') {
                 throw new \Exception('The password can not be empty');
             }
             return $value;
         });
         $githubPass = $helper->ask($input, $output, $question);
     }
     $executor = new Executor($output, $owner, $repository, $codeStandard, $githubToken, $githubUser, $githubPass);
     $output->writeln('<fg=white;bg=cyan;options=bold>                               </fg=white;bg=cyan;options=bold>');
     $output->writeln('<fg=white;bg=cyan;options=bold>  PHP DIFF CS (CODE STANDARD)  </fg=white;bg=cyan;options=bold>');
     $output->writeln('<fg=white;bg=cyan;options=bold>                               </fg=white;bg=cyan;options=bold>');
     $output->writeln('');
     $output->writeln('<fg=cyan>Project: <options=bold>' . $input->getArgument(self::REPOSITORY_ARGUMENT) . '</options=bold></fg=cyan>');
     $output->writeln('<fg=cyan>Pull Request: <options=bold>#' . $pullRequestId . '</options=bold></fg=cyan>');
     $output->writeln('<fg=cyan>Code Standard: <options=bold>' . $codeStandard . '</options=bold></fg=cyan>');
     $output->writeln('');
     try {
         $results = $executor->execute($pullRequestId);
     } catch (\Exception $e) {
         $output->writeln('<error>ERROR:</error> ' . $e->getMessage());
         die;
     }
     if (count($results)) {
         foreach ($results as $result) {
             $output->writeln($result);
         }
     }
     $output->writeln(PHP_EOL);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("secret")) {
         $secret = $input->getOption("secret");
     } else {
         $question = new Question('AWS Secret: ');
         $question->setHidden(true);
         $question->setHiddenFallback(false);
         $helper = $this->getHelper('question');
         $secret = $helper->ask($input, $output, $question);
     }
     $server = new Server\Docker();
     $server->setRegion($input->getArgument("region"))->setKey($input->getArgument("key"))->setSecret($secret)->setCluster($input->getArgument("cluster"))->setActive(false);
     // Write to DB
     $entityManager = $this->getProvisioningServer("docker")->getEntityManager();
     $entityManager->persist($server);
     $entityManager->flush();
     $table = $this->getDockerServersTable([$server], $output);
     $table->render();
 }
Ejemplo n.º 23
0
 public function getConfig($name, $description, $default = null, $validator = null, $secure = false)
 {
     if (array_key_exists($name, $this->answers)) {
         $value = $this->answers[$name];
         return $value;
     }
     // Get question
     $question = new Question('Please enter ' . $description . ': ', $default);
     $question->setHidden($secure);
     $question->setHiddenFallback(false);
     $question->setValidator($validator);
     $question->setMaxAttempts(5);
     if ($this->isFirst()) {
         $this->output->write("\n");
     }
     $value = $this->questionHelper->ask($this->input, $this->output, $question);
     $this->answers[$name] = $value;
     $this->configWriter->setConfig($name, $value);
     return $value;
 }
Ejemplo n.º 24
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Please enter password:'******'name');
     $email = $input->getArgument('email');
     $plainPassword = $helper->ask($input, $output, $question);
     $user = new User();
     $encoder = $this->getContainer()->get('security.password_encoder');
     $encoded = $encoder->encodePassword($user, $plainPassword);
     $user->setAccountname($name);
     $user->setPassword($encoded);
     $user->setEmail($email);
     $user->setIsSuperAdmin(true);
     $em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $em->persist($user);
     $em->flush();
     $output->writeln("Super admin <info>{$name}</info> created.");
 }
 protected function getConfig(InputInterface $input, OutputInterface $output)
 {
     if ($this->config === null) {
         $config = null;
         if (is_file(getcwd() . '/config.php')) {
             $config = (include getcwd() . '/config.php');
             if (!is_array($config) || !array_key_exists('db', $config)) {
                 unset($config);
             }
         }
         if (!$config) {
             if (!$input->getOption('dsn')) {
                 throw new Exception('Unable to find config.php. Please send --dsn parameter');
             } elseif (!$input->getOption('username')) {
                 throw new Exception('Unable to find config.php. Please send --username parameter');
             }
             $helper = $this->getHelper('question');
             $question = new Question('What is the database password?' . PHP_EOL);
             $question->setHidden(true);
             $question->setHiddenFallback(false);
             $password = $helper->ask($input, $output, $question);
             $config = ['db' => ['dsn' => $input->getOption('dsn'), 'username' => $input->getOption('username'), 'password' => $password], 'table' => $input->getOption('table'), 'dir' => $input->getOption('dir')];
         }
         if (!array_key_exists('table', $config) || empty($config['table'])) {
             $config['table'] = 'migrations';
         }
         if (!array_key_exists('dir', $config) || empty($config['dir'])) {
             $config['dir'] = 'migrations';
         }
         $this->tableName = $config['table'];
         $this->dir = $config['dir'];
         $this->config = $config;
     }
     $this->checkDir();
     return $this->config;
 }
Ejemplo n.º 26
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $helper = $this->getHelper('question');
     $class = $this->getContainer()->getParameter('user_class');
     $user = new $class();
     $question = new Question('Adresse email de l\'utilisateur ? ');
     $user->setEmail($helper->ask($input, $output, $question));
     $question = new Question('Mot de passe ? ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $plainPassword = $helper->ask($input, $output, $question);
     $user->setPassword($this->getContainer()->get('security.password_encoder')->encodePassword($user, $plainPassword));
     $question = new Question('Role initial ? ');
     $user->addRole($helper->ask($input, $output, $question));
     $listErrors = $this->getContainer()->get('validator')->validate($user);
     if (count($listErrors) > 0) {
         return $output->writeln("Erreur (cet utilisateur existe déjà ?)");
     } else {
         $em = $this->getContainer()->get('doctrine')->getManager();
         $em->persist($user);
         $em->flush();
     }
     $output->writeln("Utilisateur enregistré !");
 }
Ejemplo n.º 27
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = new File($input->hasOption('path') ? $input->getOption('path') : './app/pdo.cfg');
     /** @var QuestionHelper $helper */
     $helper = $this->getHelper('question');
     $question = new ChoiceQuestion('Please select your database driver', array('pgsql', 'mysql'));
     $driver = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the name of your database : ');
     $database = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the host of the database [localhost] : ', 'localhost');
     $host = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the login of the database : ', '');
     $username = $helper->ask($input, $output, $question);
     $question = new Question('Please enter the password of the database (value hidden) : ', '');
     $question->setHidden(true);
     $question->setHiddenFallback(true);
     $pass = $helper->ask($input, $output, $question);
     $file->clear();
     $file->write($driver . PHP_EOL);
     $file->write($database . PHP_EOL);
     $file->write($host . PHP_EOL);
     $file->write($username . PHP_EOL);
     $file->write($pass . PHP_EOL);
 }
Ejemplo n.º 28
0
 /**
  * prepare encryption module to decrypt all files
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param $user
  * @return bool
  */
 public function prepare(InputInterface $input, OutputInterface $output, $user)
 {
     $question = new Question('Please enter the recovery key password: '******'You can only decrypt the users files if you know');
         $output->writeln('the users password or if he activated the recovery key.');
         $output->writeln('');
         $questionUseLoginPassword = new ConfirmationQuestion('Do you want to use the users login password to decrypt all files? (y/n) ', false);
         $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword);
         if ($useLoginPassword) {
             $question = new Question('Please enter the user\'s login password: '******'No recovery key available for user ' . $user);
                 return false;
             } else {
                 $user = $recoveryKeyId;
             }
         }
     } else {
         $output->writeln('You can only decrypt the files of all users if the');
         $output->writeln('recovery key is enabled by the admin and activated by the users.');
         $output->writeln('');
         $user = $recoveryKeyId;
     }
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $password = $this->questionHelper->ask($input, $output, $question);
     $privateKey = $this->getPrivateKey($user, $password);
     if ($privateKey !== false) {
         $this->updateSession($user, $privateKey);
         return true;
     } else {
         $output->writeln('Could not decrypt private key, maybe you entered the wrong password?');
     }
     return false;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $force = $input->getOption('force');
     /**
      * @var QuestionHelper $helper
      */
     $helper = $this->getHelper('question');
     $question = new Question('Please enter your manage token: ');
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $manageToken = $helper->ask($input, $output, $question);
     $manageClient = new \Keboola\ManageApi\Client(["token" => $manageToken]);
     $this->client = new \GuzzleHttp\Client(['base_uri' => 'https://connection.keboola.com/manage/', 'headers' => ['X-KBC-ManageApiToken' => $manageToken, 'Accept-Encoding' => 'gzip', 'User-Agent' => $this->getUserAgent()]]);
     $this->dbOrchestrationManager = $this->getContainer()->get('orchestrator.doctrine.orchestration_manager');
     foreach ($manageClient->listMaintainers() as $maintainer) {
         $maintainerPrinted = false;
         $output->write('M');
         foreach ($this->loadOrganizations($maintainer) as $organization) {
             $organizationPrinted = false;
             $output->write('O');
             foreach ($manageClient->listOrganizationProjects($organization['id']) as $project) {
                 if ($project['isDisabled']) {
                     $output->write('P');
                     continue;
                 }
                 if (!$this->loadProjectOrchestrations($project['id']) && !$this->loadProjectDeletedOrchestrations($project['id'])) {
                     $output->write('P');
                     continue;
                 }
                 // delete orchestrator bucket if exists
                 if (!$maintainerPrinted) {
                     $maintainerPrinted = true;
                     $output->writeln("\t" . $maintainer['name']);
                 }
                 if (!$organizationPrinted) {
                     $organizationPrinted = true;
                     $output->writeln("\t\t" . $organization['name']);
                 }
                 $output->writeln("\t\t\t" . $project['name'] . " (" . $project['id'] . ")");
                 $projectToken = $manageClient->createProjectStorageToken($project['id'], ["description" => "Orchestrator old table deletion", "canManageBuckets" => true, "canReadAllFileUploads" => true, "expiresIn" => 1800]);
                 $client = new Client(["token" => $projectToken["token"]]);
                 foreach ($client->listBuckets() as $bucket) {
                     $bucketId = 'sys.c-orchestrator';
                     if ($bucket['id'] != $bucketId) {
                         continue;
                     }
                     // bucket delete
                     if ($force) {
                         try {
                             $client->dropBucket($bucketId, array('force' => true));
                             $output->writeln("\t\t\t\tOrchestrator bucket deleted");
                         } catch (Exception $e) {
                             $output->writeln("\t\t\t\t" . $e->getMessage());
                             continue;
                         }
                         $manageClient->addNotification(array('type' => 'common', 'projectId' => $project['id'], 'title' => sprintf(' Orchestrator bucket %s was removed from your project -- %s', 'sys.c-orchestrator', $project['name']), 'message' => 'As we announced on our [blog](http://status.keboola.com/orchestrator-table-deletion-announcement), ' . 'we have deleted the unused orchestrator bucket from your KBC storage. ' . 'This message is just for your information and has no effect on your existing orchestrations.'));
                         $output->writeln("\t\t\t\tNotification created");
                     } else {
                         $output->writeln("\t\t\t\tOrchestrator bucket will be deleted");
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 30
0
 /**
  * Asks the use for database credentials.
  */
 private function askCredentials($input, $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question($this->messages->translator->trans('db.username'));
     $this->username = $helper->ask($input, $output, $question);
     $question = new Question($this->messages->translator->trans('db.password'));
     $question->setHidden(true);
     $question->setHiddenFallback(false);
     $this->password = $helper->ask($input, $output, $question);
 }