/** * Apply certificates to DirectAdmin * * @return bool * @throws \Exception */ public function applyCertificates() { $sock = new HTTPSocket(); $sock->connect('127.0.0.1', 2222); $sock->set_login('admin'); $sock->set_method('POST'); $sock->query('/CMD_API_SSL', ['domain' => $this->getHostname(), 'action' => 'save', 'type' => 'paste', 'certificate' => $this->domainKeys->getPrivate() . PHP_EOL . $this->getCertificate(), 'submit' => 'Save']); $result = $sock->fetch_parsed_body(); if ($result['error'] != 0) { throw new \Exception('Error while executing first API request: ' . $result['details']); } $sock = new HTTPSocket(); $sock->connect('127.0.0.1', 2222); $sock->set_login('admin'); $sock->set_method('POST'); $sock->query('/CMD_API_SSL', ['domain' => $this->getHostname(), 'action' => 'save', 'type' => 'cacert', 'active' => 'yes', 'cacert' => implode("\n", $this->getCertificateAuthorityCertificates()), 'submit' => 'Save']); $result = $sock->fetch_parsed_body(); if ($result['error'] != 0) { throw new \Exception('Error while executing second API request: ' . $result['details']); } return true; }