setAuth($accessKey, $secretKey); } } /** * Set AWS access key and secret key * * @param string $accessKey Access key * @param string $secretKey Secret key * @return void */ public function setAuth($accessKey, $secretKey) { $this->__accessKey = $accessKey; $this->__secretKey = $secretKey; } /** * Return XML document for POST * * @param string $fqdn FQDN to set/update * @param string $ip IP to set for the FQDN * @param string $ttl TTL for the record * @return string XML document */ public function getRequestBody($fqdn, $ip, $ttl){ $xmlreq .= ""; $xmlreq .= ""; $xmlreq .= ""; $xmlreq .= "UPSERT"; $xmlreq .= ""; $xmlreq .= sprintf("%s", $fqdn); $xmlreq .= "A"; $xmlreq .= sprintf("%d", $ttl); $xmlreq .= sprintf("%s", $ip); $xmlreq .= ""; $xmlreq .= ""; $xmlreq .= ""; return $xmlreq; } /** * Return API URL * * @param string $zoneid Amazone Zone ID * @return string URL */ public function getApiUrl($zoneid){ return sprintf("https://route53.amazonaws.com/2013-04-01/hostedzone/%s/rrset", $zoneid); } /** * Return HTTP post headers * * @param int $bodylen length of the POST bost body * @return Array headers */ public function getHttpPostHeaders($bodylen){ $reqdate = gmdate('D, d M Y H:i:s e'); $httphead[] = array(); $httphead[] = sprintf("Date: %s", $reqdate); $httphead[] = "Content-Type: text/plain"; $httphead[] = sprintf("Content-Length: %d", $bodylen); /* to avoid having user to know their AWS Region, for now use V3 */ $httphead[] = sprintf( "X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HMACSHA256,SignedHeaders=date,Signature=%s", $this->__accessKey, base64_encode(hash_hmac("sha256", $reqdate, $this->__secretKey, true)) ); return $httphead; } }