Ejemplo n.º 1
0
 /**
  * @param Manager $args
  * @return \Generator
  */
 private function doExecute(Manager $args)
 {
     $server = \Kelunik\AcmeClient\resolveServer($args->get("server"));
     $server = \Kelunik\AcmeClient\serverToKeyname($server);
     $path = \Kelunik\AcmeClient\normalizePath($args->get("storage")) . "/certs/" . $server;
     $certificateStore = new CertificateStore($path);
     try {
         $pem = (yield $certificateStore->get($args->get("name")));
     } catch (CertificateStoreException $e) {
         $this->climate->br()->error("    Certificate not found.")->br();
         (yield new CoroutineResult(1));
         return;
     }
     $cert = new Certificate($pem);
     $this->climate->br();
     $this->climate->whisper("    Certificate is valid until " . date("d.m.Y", $cert->getValidTo()))->br();
     if ($args->defined("names")) {
         $names = array_map("trim", explode(",", $args->get("names")));
         $missingNames = array_diff($names, $cert->getNames());
         if ($missingNames) {
             $this->climate->comment("    The following names are not covered: " . implode(", ", $missingNames))->br();
             (yield new CoroutineResult(1));
             return;
         }
     }
     if ($cert->getValidTo() > time() + $args->get("ttl") * 24 * 60 * 60) {
         (yield new CoroutineResult(0));
         return;
     }
     $this->climate->comment("    Certificate is going to expire within the specified " . $args->get("ttl") . " days.")->br();
     (yield new CoroutineResult(1));
 }
Ejemplo n.º 2
0
 public function execute(Manager $args)
 {
     $version = $this->getVersion();
     $buildTime = $this->readFileOr("info/build.time", time());
     $buildDate = date('M jS Y H:i:s T', (int) trim($buildTime));
     $package = json_decode($this->readFileOr("composer.json", new RuntimeException("No composer.json found.")));
     $this->climate->out("┌ <green>kelunik/acme-client</green> @ <yellow>{$version}</yellow> (built: {$buildDate})");
     $this->climate->out(($args->defined("deps") ? "│" : "└") . " " . $this->getDescription($package));
     if ($args->defined("deps")) {
         $lockFile = json_decode($this->readFileOr("composer.lock", new RuntimeException("No composer.lock found.")));
         $packages = $lockFile->packages;
         for ($i = 0; $i < count($packages); $i++) {
             $link = $i === count($packages) - 1 ? "└──" : "├──";
             $this->climate->out("{$link} <green>{$packages[$i]->name}</green> @ <yellow>{$packages[$i]->version}</yellow>");
             $link = $i === count($packages) - 1 ? "   " : "│  ";
             $this->climate->out("{$link} " . $this->getDescription($packages[$i]));
         }
     }
 }
Ejemplo n.º 3
0
 protected function bootstrapApp(array $argv)
 {
     $args = new Manager();
     $args->add('shoelace', ['prefix' => 's', 'longPrefix' => 'shoelace']);
     $args->parse($argv);
     if ($args->defined('shoelace')) {
         $bootstrap = $args->get('shoelace');
         $files = explode(',', $bootstrap);
         foreach ($files as $file) {
             require_once $file;
         }
     }
     if (!defined('COBBLER_OUTPUT')) {
         define('COBBLER_OUTPUT', __DIR__ . '/../../output');
     }
     if (!defined('COBBLER_CONFIG')) {
         define('COBBLER_CONFIG', __DIR__ . '/../../config');
     }
     if (!defined('TWBS_PATH')) {
         define('TWBS_PATH', __DIR__ . '/../../../../twbs/bootstrap');
     }
 }
Ejemplo n.º 4
0
 /**
  * @param Manager $args
  * @return \Generator
  */
 private function doExecute(Manager $args)
 {
     $configPath = $args->get("config");
     try {
         $config = Yaml::parse((yield \Amp\File\get($configPath)));
     } catch (FilesystemException $e) {
         $this->climate->error("Config file ({$configPath}) not found.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     } catch (ParseException $e) {
         $this->climate->error("Config file ({$configPath}) had an invalid format and couldn't be parsed.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     }
     if ($args->defined("server")) {
         $config["server"] = $args->get("server");
     } else {
         if (!isset($config["server"]) && $args->exists("server")) {
             $config["server"] = $args->get("server");
         }
     }
     if ($args->defined("storage")) {
         $config["storage"] = $args->get("storage");
     } else {
         if (!isset($config["storage"]) && $args->exists("storage")) {
             $config["storage"] = $args->get("storage");
         }
     }
     if (!isset($config["server"])) {
         $this->climate->error("Config file ({$configPath}) didn't have a 'server' set nor was it passed as command line argument.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     }
     if (!isset($config["storage"])) {
         $this->climate->error("Config file ({$configPath}) didn't have a 'storage' set nor was it passed as command line argument.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     }
     if (!isset($config["email"])) {
         $this->climate->error("Config file ({$configPath}) didn't have a 'email' set.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     }
     if (!isset($config["certificates"]) || !is_array($config["certificates"])) {
         $this->climate->error("Config file ({$configPath}) didn't have a 'certificates' section that's an array.");
         (yield new CoroutineResult(self::EXIT_CONFIG_ERROR));
         return;
     }
     $command = implode(" ", array_map("escapeshellarg", [PHP_BINARY, $GLOBALS["argv"][0], "setup", "--server", $config["server"], "--storage", $config["storage"], "--email", $config["email"]]));
     $process = new Process($command);
     $result = (yield $process->exec(Process::BUFFER_ALL));
     if ($result->exit !== 0) {
         $this->climate->error("Registration failed ({$result->exit})");
         $this->climate->error($command);
         $this->climate->br()->out($result->stdout);
         $this->climate->br()->error($result->stderr);
         (yield new CoroutineResult(self::EXIT_SETUP_ERROR));
         return;
     }
     $certificateChunks = array_chunk($config["certificates"], 10, true);
     $errors = [];
     $values = [];
     foreach ($certificateChunks as $certificateChunk) {
         $promises = [];
         foreach ($certificateChunk as $certificate) {
             $promises[] = \Amp\resolve($this->checkAndIssue($certificate, $config["server"], $config["storage"]));
         }
         list($chunkErrors, $chunkValues) = (yield \Amp\any($promises));
         $errors += $chunkErrors;
         $values += $chunkValues;
     }
     $status = ["no_change" => count(array_filter($values, function ($value) {
         return $value === self::STATUS_NO_CHANGE;
     })), "renewed" => count(array_filter($values, function ($value) {
         return $value === self::STATUS_RENEWED;
     })), "failure" => count($errors)];
     if ($status["renewed"] > 0) {
         foreach ($values as $i => $value) {
             if ($value === self::STATUS_RENEWED) {
                 $certificate = $config["certificates"][$i];
                 $this->climate->info("Certificate for " . implode(", ", array_keys($this->toDomainPathMap($certificate["paths"]))) . " successfully renewed.");
             }
         }
     }
     if ($status["failure"] > 0) {
         foreach ($errors as $i => $error) {
             $certificate = $config["certificates"][$i];
             $this->climate->error("Issuance for the following domains failed: " . implode(", ", array_keys($this->toDomainPathMap($certificate["paths"]))));
             $this->climate->error("Reason: {$error}");
         }
         $exitCode = $status["renewed"] > 0 ? self::EXIT_ISSUANCE_PARTIAL : self::EXIT_ISSUANCE_ERROR;
         (yield new CoroutineResult($exitCode));
         return;
     }
     if ($status["renewed"] > 0) {
         (yield new CoroutineResult(self::EXIT_ISSUANCE_OK));
         return;
     }
 }