Example #1
0
 /**
  * Create default encryption middleware.
  *
  * @param SyncSettingsContract $settings
  * @param Application          $app
  * @param BackupCommand|null   $command
  *
  * @throws PathNotFoundException
  */
 protected function createEncryptionMiddleware(SyncSettingsContract $settings, Application &$app, BackupCommand $command = null)
 {
     if ($settings->encrypt() === false) {
         return;
     }
     $command = $this->getCommand($command);
     try {
         $encryptionMiddleware = new EncryptionMiddleware($settings->encrypt());
         $app->middleware($encryptionMiddleware);
     } catch (PathNotFoundException $e) {
         // If we have access to the actual command object we can ask the user
         // if a new random encryption key should be generated and do this task
         // for him or her.
         if (!$command) {
             throw $e;
         }
         $helper = $command->getHelper('question');
         $question = new ConfirmationQuestion("<comment>The encryption-key '" . $e->getPath() . "' doesn't exist. Create a new random one?</comment> <info>[y|n]</info>\n", false);
         if (!$helper->ask($input = $command->getInput(), $output = $command->getOutput(), $question)) {
             throw $e;
         }
         touch($e->getPath());
         chmod($e->getPath(), 0600);
         file_put_contents($e->getPath(), (new Rand())->bytes(32));
         $output->writeln('');
         $this->createEncryptionMiddleware($settings, $app, $command);
     }
 }
Example #2
0
 /**
  * @param InputInterface  $consoleInput
  * @param OutputInterface $consoleOutput
  * @param $config
  * @param $inputName
  * @param $console
  *
  * @return int|void
  *
  * @throws \Exception
  */
 public function backup($inputName, InputInterface $consoleInput, OutputInterface $consoleOutput, ConfigContract $config, SyncOutputContract $console)
 {
     // Loop through outputs
     foreach ($this->getOutputNames($consoleInput, $config, $inputName) as $outputName) {
         // Display started message
         $this->started($consoleOutput, $inputName, $outputName);
         // Create Sync Settings
         $settings = $this->createSettings($inputName, $outputName, $consoleInput, $config);
         $this->setTimezone($settings);
         // Create IO Handler
         $inputHandler = $this->createInput($inputName, $config);
         $outputHandler = $this->createOutput($outputName, $config, null, $consoleInput->getOption('no-interaction'));
         // Create Sync Application
         $app = new Application();
         $app->create($inputHandler, $outputHandler, $settings, $console);
         // Add Middleware
         $this->createVersioningMiddleware($inputName, $settings, $app);
         $this->createEncryptionMiddleware($settings, $app);
         // Run Sync
         $app->run();
         // Free some RAM
         unset($settings, $inputHandler, $outputHandler, $app);
     }
 }
Example #3
0
 /**
  * The output is a remote one.
  * So we need to sync to a local directory first,
  * commit the changes and sync to changes to the
  * actual output.
  *
  * @param SyncContract         $sync
  * @param SyncOutputContract   $output
  * @param SyncSettingsContract $settings
  */
 protected function remote(SyncContract &$sync, SyncOutputContract $output, SyncSettingsContract $settings)
 {
     // Display starting msg
     $output->out(SyncOutput::VERSIONING_SYNC_TO_LOCAL);
     // Set git to remote
     $this->git->remote();
     $this->git->init();
     // Sync to local git repo
     $localSettings = new SyncSettings($settings->excludeInput(), ['.git/**/*', '**/.gitignore', '**/.gitkeep'], $settings->ignoreInput(), true, true);
     $localSync = Application::createSync($sync->getInput(), $this->git->getOutputHandler(), $localSettings, $sync->getOutputHelper());
     $localSync->init();
     $localSync->sync();
     // Free some RAM
     unset($localSync);
     $output->out(SyncOutput::MISC_LINE_BREAK);
     // Commit
     $this->commit($output);
     $output->out(SyncOutput::VERSIONING_SYNC_TO_OUTPUT);
     // Modify existing sync object to take the local git repository as input
     $sync->setInput($this->git->getInputHandler());
     $sync->setSettings(new SyncSettings([], $settings->excludeOutput(), true, $settings->ignoreOutput(), true));
 }