/** * Constructor. * * @param string|bool $key * * @throws PathNotFoundException * @throws WrongPermissionException */ public function __construct($key) { $this->crypto = new Crypto(new Core()); if ($key === true) { $keyFile = GlobalConfig::getConfigDir() . 'encryption_key'; if (!file_exists($keyFile) || !is_file($keyFile) || !is_readable($keyFile)) { throw new PathNotFoundException($keyFile); } if (fileperms($keyFile) != 0600) { chmod($keyFile, 0600); } $this->key = file_get_contents($keyFile); return; } if (file_exists($key) && is_file($key) && is_readable($key)) { if (fileperms($key) != 0600) { throw new WrongPermissionException($key, fileperms($key), '0600'); } $this->key = file_get_contents($key); return; } if (is_string($key)) { $this->key = $key; return; } throw new InvalidArgumentException('Invalid encrypt value.'); }
/** * Execute Command. * * @param InputInterface $consoleInput * @param OutputInterface $consoleOutput * * @return int|null|void */ public function execute(InputInterface $consoleInput, OutputInterface $consoleOutput) { GlobalConfig::preFlight($consoleOutput); $command = $this->executable() . ' ' . GlobalConfig::getConfigFile(); $process = new Process($command, realpath(__DIR__ . '/../'), array_merge($_SERVER, $_ENV), null, null); $process->run(function ($type, $line) use($consoleOutput) { $consoleOutput->write($line); }); }
/** * Execute Command. * * @param InputInterface $consoleInput * @param OutputInterface $consoleOutput * * @throws PathNotFoundException * @throws \Exception * @throws \kriskbx\wyn\Exceptions\PropertyNotSetException * * @return int|null|void */ public function execute(InputInterface $consoleInput, OutputInterface $consoleOutput) { parent::execute($consoleInput, $consoleOutput); GlobalConfig::preFlight($consoleOutput); $this->sleep = $consoleInput->getOption('interval'); $this->workerCommand = $this->buildWorkerCommand(); $process = $this->makeProcess(); $consoleOutput->writeln('<info>Daemon started...</info>'); while (true) { $consoleOutput->writeln('<info>Running backup:cron...</info>'); $process->run(function ($type, $line) { $this->output->writeln($line); }); sleep($this->sleep); } }
/** * Configure Command. */ public function configure() { $this->setName('decrypt')->setDescription('Decrypt the data from an encrypted output')->addArgument('output', InputArgument::REQUIRED, 'Name of the configured output.')->addArgument('target', InputArgument::REQUIRED, 'Path to save the decrypted data to.')->addArgument('config', InputArgument::OPTIONAL, 'Path to the config file.', GlobalConfig::getConfigFile()); }
/** * SyncSettings constructor. * * @param array $excludeInput * @param array $excludeOutput * @param bool $skipInputErrors * @param bool $skipOutputErrors * @param bool $delete * @param bool $versioning * @param bool $encrypt * @param string|array $to * @param string $cron * @param int $timeout * @param string $timezone * @param null $cronConfig * @param bool $checkFileSize */ public function __construct($excludeInput = [], $excludeOutput = [], $skipInputErrors = true, $skipOutputErrors = true, $delete = true, $versioning = false, $encrypt = false, $to = null, $cron = null, $timeout = 600, $timezone = 'Europe/Berlin', $cronConfig = null, $checkFileSize = true) { $this->excludeInput = $excludeInput; $this->excludeOutput = $excludeOutput; $this->ignoreInput = $skipInputErrors; $this->ignoreOutput = $skipOutputErrors; $this->delete = $delete; $this->versioning = $versioning; $this->encrypt = $encrypt; $this->to = $to; $this->cron = $cron; $this->timeout = $timeout; $this->timezone = $timezone; $this->checkFileSize = $checkFileSize; $this->cronConfig = $cronConfig ? $cronConfig : GlobalConfig::getConfigDir(); }
/** * Configure Command. */ public function configure() { $this->setName('backup:all')->setDescription('Backups all inputs with configured outputs from the given config file')->addArgument('config', InputArgument::OPTIONAL, 'Path to the config file.', GlobalConfig::getConfigFile()); $this->setDefaultOptions(); }
/** * Configure Command. */ public function configure() { $this->setName('backup:single')->setDescription('Backups a single input to a single output from the given config file')->addArgument('input', InputArgument::REQUIRED, 'Name of the configured input.')->addArgument('output', InputArgument::OPTIONAL, 'Name of the configured output. Required if no output is configured.')->addArgument('config', InputArgument::OPTIONAL, 'Path to the config file.', GlobalConfig::getConfigFile()); $this->setDefaultOptions(); }
/** * Get path to local git repository. * * @return string */ public function getLocalRepoPath() { $gitDir = @file_exists($this->gitDir) && @is_dir($this->gitDir) ? $this->gitDir : GlobalConfig::getGitDir() . DIRECTORY_SEPARATOR . $this->input; return $gitDir . DIRECTORY_SEPARATOR; }