/** * Performs the update * * @param RequestInterface $request * * @return ResponseInterface * @throws \RuntimeException */ public function update(RequestInterface $request) { /** * Zone inquire */ $domInquire = $this->loadXml($this->getRequestGet()); $splittedHost = $this->split($request->getHost()); $name = $splittedHost['hostname'] . '.' . $splittedHost['tld']; $domInquire->getElementsByTagName('user')->item(0)->nodeValue = $this->user; $domInquire->getElementsByTagName('password')->item(0)->nodeValue = $this->password; $domInquire->getElementsByTagName('context')->item(0)->nodeValue = $this->context; $domInquire->getElementsByTagName('name')->item(0)->nodeValue = $name; $response = $this->requestCurl($domInquire->saveXML()); $domResponse = $this->loadXml($response); /** * Check if we can get zone records */ $xpath = new \DOMXPath($domResponse); $nodeList = $xpath->query('/response/result/status/type'); if (0 === $nodeList->length) { throw new \RuntimeException('Query path in response not found. Maybe the api changed?'); } if ('success' !== $nodeList->item(0)->nodeValue) { throw new \RuntimeException('Cannot get zone records. ' . $xpath->query('/response/result/status/text')->item(0)->nodeValue); } /** * Zone-Update */ $domUpdate = $this->loadXml($this->getRequestPut()); $domUpdateZone = $domResponse->getElementsByTagName('zone')->item(0); $domUpdateZone->removeChild($domUpdateZone->getElementsByTagName('created')->item(0)); $domUpdateZone->removeChild($domUpdateZone->getElementsByTagName('changed')->item(0)); $domUpdateZone->removeChild($domUpdateZone->getElementsByTagName('domainsafe')->item(0)); $domUpdateZone->removeChild($domUpdateZone->getElementsByTagName('owner')->item(0)); $domUpdateZone->removeChild($domUpdateZone->getElementsByTagName('updated_by')->item(0)); $domUpdate->getElementsByTagName('task')->item(0)->appendChild($domUpdate->importNode($domUpdateZone, true)); $domUpdate->getElementsByTagName('user')->item(0)->nodeValue = $this->user; $domUpdate->getElementsByTagName('password')->item(0)->nodeValue = $this->password; $domUpdate->getElementsByTagName('context')->item(0)->nodeValue = $this->context; /** * Populate Zone-Update-XML */ $subdomain = $splittedHost['subdomain']; if ($request->getIPv4()) { $xpath = new \DOMXPath($domUpdate); $query = "//task/zone/rr[name='" . $subdomain . "' and type='A']/value"; $entries = $xpath->query($query); if ($entries->length !== 1) { throw new \RuntimeException('Domain has no A-record for ' . $subdomain); } $entries->item(0)->nodeValue = $request->getIPv4(); } if ($request->getIpv6()) { $xpath = new \DOMXPath($domUpdate); $query = "//task/zone/rr[name='" . $subdomain . "' and type='AAAA']/value"; $entries = $xpath->query($query); if ($entries->length !== 1) { throw new \RuntimeException('Domain has no AAAA-record for ' . $subdomain); } $entries->item(0)->nodeValue = $request->getIpv6(); } /** * Update-Request */ $response = $this->requestCurl($domUpdate->saveXML()); $domResponse = $this->loadXml($response); $xpath = new \DOMXPath($domResponse); $nodeList = $xpath->query('/response/result/status/type'); if (0 === $nodeList->length) { throw new \RuntimeException('Query path in response not found. Maybe the api changed?'); } if ('success' === $nodeList->item(0)->nodeValue) { $response = new Response(true, $domResponse->saveXML()); return $response; } else { throw new \RuntimeException('Cannot set new zone records. ' . $xpath->query('/response/result/status/text')->item(0)->nodeValue); } }