예제 #1
0
파일: Get.php 프로젝트: 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')));
 }
예제 #2
0
파일: Set.php 프로젝트: 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());
 }