#!/usr/bin/perl -w use Digest::HMAC_SHA1 qw(hmac_sha1); use HTTP::Request; use LWP::UserAgent; use MIME::Base64 qw(encode_base64); use strict; use URI::Escape; use warnings; my $AccessKey = '123'; my $SecretKey = 'ABC'; my $SoapURL = 'http://s3.amazonaws.com/soap'; my $OffSet = 6; my $TimeStamp = ASTimeStamp($OffSet); my $key = "AmazonS3" . "CreateBucket" . $TimeStamp; my $Signature = hmac_sha1($key, $SecretKey); $Signature = encode_base64($Signature, ''); $Signature = uri_escape($Signature); my $env = '' . "\n" . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ' ' . 'turbov21' . '' . "\n" . ' ' . $AccessKey . '' . "\n" . ' ' . $TimeStamp . '' . "\n" . ' ' . $Signature . '' . "\n" . ' ' . "\n" . ' ' . "\n" . ''; print $env . "\n\n"; # Builds the HTTP request my $ua = LWP::UserAgent->new(); my $request = HTTP::Request->new(POST => $SoapURL); $request->content_type('text/plain;'); $request->content($env); # Fires off the HTTP Request my $result = $ua->request($request); if ($result->is_success) { print $result->content . "\n"; } else { print "Error: " .$result->status_line . "\n"; } ##### # Formats the time for Amazon sub ASTimeStamp { my ($offset) = @_; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); # Fixes the year $year = $year + 1900; # Fixes month to start from 1, not from 0 $mon++; # Days in the months my @months = ( ['January', 31], ['February', ($year % 4) > 0 ? 28 : 29], ['March', 31], ['April', 30], ['May', 31], ['June', 30], ['July', 31], ['August', 31], ['September', 30], ['October', 31], ['November', 30], ['December', 31] ); # Adjusts time and date to GMT time $hour = $hour + $offset; # If GMT is ahead of you if ($hour > 24) { # Sets the time for the new day $hour = $hour - 24; # Sets the new date $mday++; # Adjusts the month if ($mday > $months[$mon - 1]->[1]) { $mday = 1; $mon++; if ($mon > 12) { $mon = 1; $year++; } } } # If you're ahead of the GMT elsif ($hour < 0) { # Sets the time for the previous day $hour = 24 + $hour; # Sets the new date $mday--; # Adjusts the month # Adjusts the month if ($mday == 0) { $mday = $months[$mon - 2]->[1]; $mon--; if ($mon == 0) { $mon = 12; $year--; } } } # Adds a leading 0 to the minute if ($hour < 10) { $hour = "0" . $hour; } # Adds a leading 0 to the minute if ($min < 10) { $min = "0" . $min; } # Adds a leading 0 to the seconds if ($sec < 10) { $sec = "0" . $sec; } # Adds a leading 0 to the month if ($mon < 10) { $mon = "0" . $mon; } # Adds a leading 0 to the date if ($mday < 10) { $mday = "0" . $mday; } # 2005-01-31T23:59:59.183Z return($year . '-' . $mon . '-' . $mday . 'T' . $hour . ':' . $min . ':' . $sec . ".000Z"); }