Exemplo n.º 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;
 }
Exemplo n.º 2
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. Add it by using the add command.');
         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++;
         }
     }
     $totp = new TOTP();
     $totp->setDigits($config[$keyArgument]['size'])->setDigest($config[$keyArgument]['digest'])->setInterval($config[$keyArgument]['interval'])->setSecret($config[$keyArgument]['token']);
     $output->writeln('Your token is: <options=bold>' . $totp->now() . '</>');
     return 0;
 }
Exemplo n.º 3
0
 /**
  * Runs the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = OTPGen::LoadConfig();
     $count = 0;
     foreach ($config as $key => $whyBother) {
         $output->writeln('(' . $count . ') ' . $key);
         $count++;
     }
     return 0;
 }