Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     if ($output instanceof ConsoleOutput) {
         $stderr = $output->getErrorOutput();
     } else {
         $stderr = $output;
     }
     $sshDir = $configHelper->getConfiguration()->getSshDirectory();
     $keyFile = new \SplFileInfo($input->getArgument('key') ?: $sshDir . '/id_rsa-' . sha1(mt_rand() . time()));
     // Check if file already exists
     try {
         $keyFile->getType();
         // Throws if file does not exist.
         throw new FileExistsException($keyFile);
     } catch (\RuntimeException $ex) {
         // noop
     }
     OutsideConfiguredRootDirectoryException::assert($keyFile, 'ssh-dir', $configHelper->getConfiguration()->getSshDirectory());
     $sshKeygen = ProcessBuilder::create(['ssh-keygen', '-q', '-f', $keyFile, '-C', $input->getOption('comment'), '-N', ''])->setTimeout(null)->getProcess();
     $processHelper->mustRun($output, $sshKeygen);
     $stderr->writeln(sprintf('Generated key <info>%s</info>', $keyFile->getPathname()), OutputInterface::VERBOSITY_VERBOSE);
     if ($input->getOption('print-public-key')) {
         $output->write(file_get_contents($keyFile->getPathname() . '.pub'), false, OutputInterface::OUTPUT_RAW | OutputInterface::VERBOSITY_QUIET);
     }
     if ($input->getOption('target-repository')) {
         $this->getApplication()->find('repository:add')->run(new ArrayInput(['repository' => $input->getOption('target-repository'), 'key' => $keyFile->getPathname(), '--alias' => preg_replace('/^id_rsa-/', '', $keyFile->getFilename())]), $output);
     }
 }
 /**
  * @return string
  */
 public function getPath()
 {
     $path = $this->globalConfiguration->getApplicationsDirectory() . '/' . $this->getName();
     OutsideConfiguredRootDirectoryException::assert($path, 'applications-dir', $this->globalConfiguration->getApplicationsDirectory());
     return $path;
 }
Пример #3
0
 public function getLink()
 {
     $link = new \SplFileInfo($this->globalConfiguration->getVhostsDirectory() . '/' . $this->getName());
     OutsideConfiguredRootDirectoryException::assert($link->getPathname(), 'vhosts-dir', $this->globalConfiguration->getVhostsDirectory());
     return $link;
 }