$blocksize) $key=pack('H*', $hashfunc($key)); $key=str_pad($key,$blocksize,chr(0x00)); $ipad=str_repeat(chr(0x36),$blocksize); $opad=str_repeat(chr(0x5c),$blocksize); $hmac = pack( 'H*',$hashfunc( ($key^$opad).pack( 'H*',$hashfunc( ($key^$ipad).$data ) ) ) ); return base64_encode($hmac); } /* * Define POST URL and also payload */ $caller_ref = date("ymdhis"); // use current date as call reference define('XML_PAYLOAD', ' www.scalapedia.com 80 443 match-viewer '.$caller_ref.' www.scalapedia.com true index.php '); define('XML_POST_URL', 'https://cloudfront.amazonaws.com/2010-11-01/distribution/'); /* * Encode and set header */ $data = date("D, j M Y G:i:s T"); //format = Thu, 30 Dec 2010 16:05:21 EST $pub_key = 'AKIAJU5JustAnExampleString'; // access key $sec_key = 'Lt4ARFxGaJustAnExampleString'; // secret key $auth = hmacsha1($sec_key, $data); $header_array = array("Authorization: AWS ".$pub_key.":".$auth,"Date: ".$data, "Content-Type: text/xml","Content-length: ".strlen(XML_PAYLOAD)); /* * Set Curl variables */ $tuCurl = curl_init(); // initialize curl handle curl_setopt($tuCurl, CURLOPT_URL,XML_POST_URL); // set url curl_setopt($tuCurl, CURLOPT_POST, 1); // set POST curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($tuCurl, CURLOPT_TIMEOUT, 6); // times out after 6 seconds curl_setopt($tuCurl, CURLOPT_POSTFIELDS, XML_PAYLOAD); // add POST fields curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $header_array); // add headers /* * Execute the request and also time the transaction */ $start = array_sum(explode(' ', microtime())); $result = curl_exec($tuCurl); $stop = array_sum(explode(' ', microtime())); $totalTime = $stop - $start; /* * Check results */ if ( curl_errno($tuCurl) ) { $result = 'cURL ERROR -> '.curl_errno($tuCurl).': '. curl_error($tuCurl); } else { $returnCode = (int)curl_getinfo($tuCurl, CURLINFO_HTTP_CODE); switch($returnCode){ case 201: $result = 'CloudFront Distribution Created'; break; default: $result = 'HTTP ERROR -> '.$returnCode; break; } } /** * Close, ouput, and exit */ curl_close($tuCurl); echo 'Total time for request: '.$totalTime.'\n'; echo $result.'\n'; exit(0); ?>