/** * Tests OpenSSL::getExecutable */ public function testCertFile() { Cli::registerBase('configuration', '/foo'); $expected = 'openssl smime -encrypt -aes256 -binary -in \'/foo/bar.txt\' ' . '-out \'/foo/bar.txt.enc\' -outform DER \'/foo/my.pem\' 2> /dev/null ' . '&& rm \'/foo/bar.txt\' 2> /dev/null'; $target = $this->getTargetMock('/foo/bar.txt'); $path = $this->getBinDir(); $this->openSSL->setup(array('pathToOpenSSL' => $path, 'certFile' => '/foo/my.pem', 'algorithm' => 'aes256')); $executable = $this->openSSL->getExecutable($target); $this->assertEquals('(' . $path . '/' . $expected . ')', $executable->getCommandLine()); }
/** * Tests Mcrypt::getExecutable */ public function testKeyFile() { Cli::registerBase('configuration', '/foo'); $expected = 'mcrypt -u -f \'/foo/my.key\' -a \'blowfish\' \'/foo/bar.txt\' 2> /dev/null'; $target = $this->getTargetMock('/foo/bar.txt'); $path = $this->getBinDir(); $this->mcrypt->setup(array('pathToMcrypt' => $path, 'keyFile' => '/foo/my.key', 'algorithm' => 'blowfish')); $executable = $this->mcrypt->getExecutable($target); $this->assertEquals($path . '/' . $expected, $executable->getCommandLine()); }
/** * Writes a buffer with Ansible like asterisk decoration. * * @param string $buffer */ protected function writeWithAsterisk($buffer) { $this->write(Util\Cli::formatWithAsterisk($buffer)); }
/** * Converts a path to an absolute one if necessary. * * @param string $path * @param boolean $useIncludePath * @return string */ protected function toAbsolutePath($path, $useIncludePath = false) { return Cli::toAbsolutePath($path, dirname($this->filename), $useIncludePath); }
/** * Run phpbu * * @param \phpbu\App\Configuration $configuration * @param \phpbu\App\Factory * @return \phpbu\App\Result */ public function run(Configuration $configuration) { // TODO: don't rely on static/global settings this is ugly Util\Cli::registerBase('configuration', $configuration->getWorkingDirectory()); $stop = false; $this->result = new Result(); $this->configuration = $configuration; $this->setupEnvironment($configuration); $this->setupLoggers($configuration); $this->result->phpbuStart($configuration); // create backups /** @var \phpbu\App\Configuration\Backup $backup */ foreach ($configuration->getBackups() as $backup) { if ($stop) { break; } // setup target and collector, reset failure state $target = $this->createTarget($backup->getTarget()); $collector = new Collector($target); $this->failure = false; try { /* ___ ___ _______ ____ _____ * / _ )/ _ |/ ___/ //_/ / / / _ \ * / _ / __ / /__/ ,< / /_/ / ___/ * /____/_/ |_\___/_/|_|\____/_/ */ $this->executeSource($backup, $target); /* _______ _____________ ______ * / ___/ // / __/ ___/ //_/ __/ * / /__/ _ / _// /__/ ,< _\ \ * \___/_//_/___/\___/_/|_/___/ */ $this->executeChecks($backup, $target, $collector); /* __________ _____ ______ * / ___/ _ \ \/ / _ \/_ __/ * / /__/ , _/\ / ___/ / / * \___/_/|_| /_/_/ /_/ */ $this->executeCrypt($backup, $target); /* ______ ___ ___________ * / __/\ \/ / |/ / ___/ __/ * _\ \ \ / / /___\ \ * /___/ /_/_/|_/\___/___/ */ $this->executeSyncs($backup, $target); /* _______ _______ _ ____ _____ * / ___/ / / __/ _ | / |/ / / / / _ \ * / /__/ /__/ _// __ |/ / /_/ / ___/ * \___/____/___/_/ |_/_/|_/\____/_/ */ $this->executeCleanup($backup, $target, $collector); } catch (\Exception $e) { $this->result->debug('exception: ' . $e->getMessage()); $this->result->addError($e); $this->result->backupFailed($backup); if ($backup->stopOnFailure()) { $stop = true; } } } $this->result->phpbuEnd(); return $this->result; }
/** * Return an absolute path relative to the used file. * * @param string $path * @param string $default * @return string */ protected function toAbsolutePath($path, $default = null) { return !empty($path) ? Util\Cli::toAbsolutePath($path, Util\Cli::getBase('configuration')) : $default; }
/** * Constructor. * * @param string $path */ public function __construct($path = null) { $this->binary = Cli::detectCmdLocation($this->cmd, $path, Cli::getCommandLocations($this->cmd)); }