예제 #1
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = OTPGen::LoadConfig();
     $keyArgument = $input->getArgument('name');
     if (!key_exists($keyArgument, $config) && !is_numeric($keyArgument)) {
         $output->writeln('The entry ' . $keyArgument . ' does not exist in your library.');
         return 0;
     }
     if (is_numeric($keyArgument)) {
         if (intval($keyArgument) > count($config) - 1) {
             $output->writeln('There is no entry in your library with the id: ' . $keyArgument . '.');
             return 0;
         }
         $count = 0;
         foreach ($config as $key => $WhyBother) {
             if ($count == intval($keyArgument)) {
                 $keyArgument = $key;
                 continue;
             }
             $count++;
         }
     }
     unset($config[$key]);
     $otpFile = fopen(OTPGEN_WORKING_DIR . '.otp', 'w') or die('Wasn\'t able to open library are you sure I have enough permissions?');
     fwrite($otpFile, OTPGen::toYAML($config));
     fclose($otpFile);
     $output->writeln('Removed ' . $keyArgument . ' from your library.');
     return 0;
 }
예제 #2
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     //Ask te user for a name which will be used as key
     $question = new Question('Enter a name: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new \RuntimeException('Please enter a name.');
         }
         if (strrpos($answer, " ") === true) {
             throw new \RuntimeException('No spaces allowed in your name.');
         }
         return $answer;
     });
     $name = $helper->ask($input, $output, $question);
     $question = new Question('Enter your token: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new \RuntimeException('Please enter your token.');
         }
     });
     $token = $helper->ask($input, $output, $question);
     $question = new Question('Enter the digest algorithm (default sha1): ', 'sha1');
     $digest = $helper->ask($input, $output, $question);
     $question = new Question('Enter the lenght of the generated token (default 6): ', 6);
     $size = $helper->ask($input, $output, $question);
     $question = new Question('Enter the interval of the token (default 30): ', 30);
     $interval = $helper->ask($input, $output, $question);
     $data = array($name => array('token' => $token, 'digest' => $digest, 'size' => $size, 'interval' => $interval));
     if (file_exists(OTPGEN_WORKING_DIR . '.otp')) {
         $config = OTPGen::loadConfig();
         $data = array_merge($config, $data);
     }
     $otpFile = fopen(OTPGEN_WORKING_DIR . '.otp', 'w') or die('Wasn\'t able to open or create library are you sure I have enough permissions?');
     fwrite($otpFile, OTPGen::toYAML($data));
     fclose($otpFile);
     $output->writeln('Added ' . $name . ' to your library.');
     return 0;
 }