Esempio n. 1
0
File: Get.php Progetto: nubs/pwman
 /**
  * Gets the password(s) for the specified application(s).
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input The command input.
  * @param \Symfony\Component\Console\Output\OutputInterface $output The command output.
  * @return int The return status
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $passwordFile = new PasswordFile($input->getArgument('password-file'), new GnuPG());
     $passwordFile->addDecryptKey($input->getOption('decrypt-key') ?: '', $input->getOption('decrypt-passphrase') ?: '');
     $passwords = $passwordFile->getPasswords();
     if ($passwords === null) {
         return $this->_error($output, 'Failed to load passwords from file!');
     }
     $passwordManager = new PasswordManager($passwords);
     $application = $input->getArgument('application') ?: '';
     $matchingPasswords = $passwordManager->matchingApplication($application);
     $output->writeln($this->_formatPasswords($matchingPasswords, $input->getOption('output-format')));
 }
Esempio n. 2
0
File: Set.php Progetto: nubs/pwman
 /**
  * Sets the password for the specified application.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input The command input.
  * @param \Symfony\Component\Console\Output\OutputInterface $output The command output.
  * @return int The return status
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $passwordFile = new PasswordFile($input->getArgument('password-file'), new GnuPG());
     $passwordFile->addDecryptKey($input->getOption('decrypt-key') ?: '', $input->getOption('decrypt-passphrase') ?: '');
     $passwords = $passwordFile->getPasswords();
     if ($passwords === null) {
         return $this->_error($output, 'Failed to load passwords from file!');
     }
     $application = $input->getOption('application') ?: '';
     $passwordManager = new PasswordManager($passwords);
     $existingPasswords = $passwordManager->matchingApplication($application);
     $passwordsToEdit = empty($existingPasswords) ? $this->_newPasswordTemplate($input) : $existingPasswords;
     try {
         $passwordManager->replacePasswords($existingPasswords, $this->_alterPasswords($passwordsToEdit));
     } catch (Exception $e) {
         return $this->_error($output, $e->getMessage());
     }
     $passwordFile->addEncryptKey($input->getOption('encrypt-key') ?: '');
     $passwordFile->setPasswords($passwordManager->getPasswords());
 }