/**
  * Solve a HTTP-01 challenge
  *
  * @return bool
  */
 public function solve()
 {
     $payload = $this->domain->account->acme->generateHttp01Payload($this->token);
     $wwwCheck = explode('.', $this->challengeDomain, 2);
     if ($wwwCheck[0] === 'www') {
         // WWW, so use the path to without www
         $domainPath = $this->challengeDomain[1];
     } else {
         // without WWW, so use the normal domain
         $domainPath = $this->challengeDomain;
     }
     $subdomainCheck = explode('.', $domainPath, 2);
     if ($subdomainCheck[1] === $this->domain->getDomain()) {
         // The second key is the same as the domain, so we're on a subdomain
         $challengePath = $this->domain->getPath() . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . $subdomainCheck[0] . DIRECTORY_SEPARATOR . '.well-known';
     } else {
         // Were not on a subdomain, use main domain
         $challengePath = $this->domain->getPath() . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . '.well-known';
     }
     if (!file_exists($challengePath)) {
         mkdir($challengePath);
         if (defined('CRON')) {
             chown($challengePath, $this->domain->account->getUsername());
             chgrp($challengePath, $this->domain->account->getUsername());
         }
     }
     $challengePath .= DIRECTORY_SEPARATOR . 'acme-challenge';
     if (!file_exists($challengePath)) {
         mkdir($challengePath);
         if (defined('CRON')) {
             chown($challengePath, $this->domain->account->getUsername());
             chgrp($challengePath, $this->domain->account->getUsername());
         }
     }
     file_put_contents($challengePath . DIRECTORY_SEPARATOR . $this->token, $payload);
     if (defined('CRON')) {
         chown($challengePath . DIRECTORY_SEPARATOR . $this->token, $this->domain->account->getUsername());
         chgrp($challengePath . DIRECTORY_SEPARATOR . $this->token, $this->domain->account->getUsername());
     }
     \amp\wait($this->domain->account->acme->selfVerify($this->challengeDomain, $this->token, $payload));
     \amp\wait($this->domain->account->acme->answerChallenge($this->uri, $payload));
     \amp\wait($this->domain->account->acme->pollForChallenge($this->location));
     unlink($challengePath . DIRECTORY_SEPARATOR . $this->token);
     $isChallengePathEmpty = !(new \FilesystemIterator($challengePath))->valid();
     if ($isChallengePathEmpty) {
         rmdir($challengePath);
         $challengePath = dirname($challengePath);
         $isChallengePathEmpty = !(new \FilesystemIterator($challengePath))->valid();
         if ($isChallengePathEmpty) {
             rmdir($challengePath);
         }
     }
     return true;
 }
 /**
  * Receive challanges from ACME
  *
  * @return string Challenges
  */
 public function receiveChallenges()
 {
     $domains = array_merge((array) $this->domain->getDomain(), $this->subdomains);
     foreach ($domains as $domain) {
         list($this->location[$domain], $response) = \amp\wait($this->domain->account->acme->requestChallenges($domain));
         $this->combinations[$domain] = $response->combinations;
         $this->status[$domain] = $response->status;
         $this->expires[$domain] = $response->expires;
         foreach ($response->challenges as $challenge) {
             $challengeClassName = '\\DirectAdmin\\LetsEncrypt\\Lib\\Challenges\\';
             $challengeClassName .= ucfirst(strtolower(preg_replace("/[^A-Za-z0-9 ]/", '', $challenge->type))) . 'Challenge';
             if (class_exists($challengeClassName)) {
                 $this->challenges[$domain][] = new $challengeClassName($challenge, $this->location[$domain], $this->domain, $domain);
             } else {
                 $this->challenges[$domain][] = new BaseChallenge($challenge, $this->location[$domain], $this->domain, $domain);
             }
         }
     }
     return $this->challenges;
 }
示例#3
0
 /**
  * Register user at ACME
  *
  * @throws \Kelunik\Acme\AcmeException
  */
 public function register()
 {
     try {
         \amp\wait($this->acme->register($this->email));
     } catch (\Exception $e) {
         throw new \Exception('Error registering ' . $this->email . ': ' . $e->getMessage(), 0, $e);
     }
     $this->config('status', 'registered at Let\'s Encrypt');
     $this->config('email', $this->email);
 }
示例#4
0
 /**
  * Request certificate at ACME
  *
  * @param KeyPair|null $domainKeys
  * @param array|null $subdomains List of subdomains to request
  * @return array
  * @throws \Exception
  * @throws \Kelunik\Acme\AcmeException
  */
 public function requestCertificate($domainKeys = null, $subdomains = null)
 {
     if ($domainKeys == null) {
         if ($this->domainKeys == null) {
             $this->createKeys();
         } else {
             $domainKeys = $this->domainKeys;
         }
     }
     $domains = (array) $this->getDomain();
     if ($subdomains == null) {
         $domains = array_merge($domains, $this->getSubdomains());
     } else {
         $domains = array_merge($domains, $subdomains);
     }
     try {
         $location = \amp\wait($this->account->acme->requestCertificate($domainKeys, $domains));
         $this->certificates = \amp\wait($this->account->acme->pollForCertificate($location));
     } catch (\Exception $e) {
         throw new \Exception("Error requesting certificate: " . $e->getMessage(), 0, $e);
     }
     return $this->certificates;
 }