David
This was part of a script I developed for a credit card gateway using Active
Perl 5.8.0. It basically imported a file, encrypted and sent it and then
parsed the response out to another file. I installed openssl and installed
the netssleay 1.32 pm in Active Perl. I also used a similar script with
Unix. Perhaps this may help you.
Norm Bumbieris
TicketPro Systems
#!/usr/bin/perl
if($ARGV[0]) {
$datafile = "/netssleay/credreq/" . $ARGV[0];
$outputFile = "/netssleay/credans/" . $ARGV[0];
}
else
{
print "Usage: $0 <data filename>\n\n";
exit 2;
}
if($ARGV[1]) {
print "Usage: $0 <data filename>\n\n";
print "No handling for additional parameters\n";
exit 3;
}
$timestamp = localtime(time);
$errfile = "/netssleay/logs/errlog.txt";
unless(open(LOGFILE,">>$errfile")){
print "$timestamp: Unable to open $errfile for writing, please check
directory permissions! $!\n";
die "Unable to open output file: $datafile, cannot continue\n";
}
unless(open(INFILE,"$datafile")){
print LOGFILE "$timestamp: Unable to open $datafile for reading, please
check directory permissions! Error reported: $!\n";
die "Unable to open output file: $datafile, cannot continue\n";
}
@cdata=<INFILE>;
close(INFILE);
#unlink($datafile);
# Source Key that is provided by usaepay
use Net::SSLeay qw(post_https make_form);
foreach $cdata (@cdata)
{
chomp($cdata);
($name,$value) = split(/=/,$cdata);
$value =~ s/\+/ /g;
#$value =~ s/%(..)/pack("c",hex($1))/ge;
$form{$name} .= "\0" if (defined($form{$name}));
$form{$name} .= "$value";
}
##### END FORM PARSE. VALUES ARE IN %form
# form values can now be accessed by calling $form{'formVariableName'}
###Following lines format the fields to gateway specs.
$form{'UMcard'} =~ s/[^0-9]//g;
$form{'UMexpirM'} =~ s/[^0-9]//g;
$form{'UMexpirY'} =~ s/[^0-9]//g;
$form{'UMexpir'} = "$form{'UMexpirM'}$form{'UMexpirY'}";
$form{'UMamount'} =~ s/[^0-9\.]//g;
#for my $var (sort keys %form){
# print "$var=$form{$var}\n";
#}
#All required fields are checked and formatted
#Now we need to save them in a hash array and submit them through
#Net::SSLeay to the gateway
#Uncomment the following line to enable tracing (for debugging)
#values are: 0=no debugging, 1=ciphers, 2=trace, 3=dump data
$Net::SSLeay::trace = 2;
#gather all the cgi form variables to be sent to the gateway.
%formData = make_form (
'UMkey' => $form{'UMkey'},
#'UMkey' => $sourceKey,
'UMauthCode' => $form{'UMauthCode'},
'UMrefNum' => $form{'UMrefNum'},
'UMcard' => $form{'UMcard'},
'UMexpir' => $form{'UMexpir'},
'UMrouting' => $form{'UMrouting'},
'UMaccount' => $form{'UMaccount'},
'UMamount' => $form{'UMamount'},
'UMtax' => $form{'UMtax'},
'UMcustid' => $form{'UMcustid'},
'UMinvoice' => $form{'UMinvoice'},
'UMponum' => $form{'UMponum'},
'UMticket' => $form{'UMticket'},
'UMdescription' => $form{'UMdescription'},
'UMcvv2' => $form{'UMcvv2'},
'UMcustemail' => $form{'UMcustemail'},
'UMcustreceipt' => $form{'UMcustreceipt'},
'UMname' => $form{'UMname'},
'UMstreet' => $form{'UMstreet'},
'UMzip' => $form{'UMzip'},
'UMssn' => $form{'UMssn'},
'UMdlnum' => $form{'UMdlnum'},
'UMdlstate' => $form{'UMdlstate'},
'UMip' => $form{'UMip'},
'UMcommand' => $form{'UMcommand'},
'UMredir' => $form{'UMredir'},
'UMredirApproved' => $form{'UMredirApproved'},
'UMredirDeclined' => $form{'UMredirDeclined'},
'UMechofields' => $form{'UMechofields'},
'UMechounsafe' => $form{'UMechounsafe'},
'UMtestmode' => $form{'UMtestmode'},
'UMrecurring' => $form{'UMrecurring'},
'UMbillamount' => $form{'UMbillamount'},
'UMschedule' => $form{'UMschedule'},
'UMnumleft' => $form{'UMnumleft'},
'UMstart' => $form{'UMstart'},
'UMexpire' => $form{'UMexpire'},
'UMbillfname' => $form{'UMbillfname'},
'UMbilllname' => $form{'UMbilllname'},
'UMbillcompany' => $form{'UMbillcompany'},
'UMbillstreet' => $form{'UMbillstreet'},
'UMbillstreet2' => $form{'UMbillstreet2'},
'UMbillcity' => $form{'UMbillcity'},
'UMbillstate' => $form{'UMbillstate'},
'UMbillzip' => $form{'UMbillzip'},
'UMbillcountry' => $form{'UMbillcountry'},
'UMbillphone' => $form{'UMbillphone'},
'UMemail' => $form{'UMemail'},
'UMfax' => $form{'UMfax'},
'UMwebsite' => $form{'UMwebsite'},
'UMshipfname' => $form{'UMshipfname'},
'UMshiplname' => $form{'UMshiplname'},
'UMshipcompany' => $form{'UMshipcompany'},
'UMshipstreet' => $form{'UMshipstreet'},
'UMshipstreet2' => $form{'UMshipstreet2'},
'UMshipcity' => $form{'UMshipcity'},
'UMshipstate' => $form{'UMshipstate'},
'UMshipzip' => $form{'UMshipzip'},
'UMshipcountry' => $form{'UMshipcountry'},
'UMshipphone' => $form{'UMshipphone'},
'UMcardauth' => $form{'UMcardauth'},
'UMpares' => $form{'UMpares'},
'UMxid' => $form{'UMxid'},
'UMcavv' => $form{'UMcavv'},
'UMeci' => $form{'UMeci'},
'UMtranterm' => $form{'UMtranterm'},
'UMcardpresent' => $form{'UMcardpresent'},
'UMmagstripe' => $form{'UMmagstripe'},
);
#send data via SSLeay and gather encrypted reply.
#for my $res (sort keys %formData){
# print "$res=$formData{$res}\n";
#}
# my $host = 'www.usaepay.com';
# my $host = 'sandbox.usaepay.com';
#my $host = '64.0.146.7';
my $host = '64.0.146.100';
my $script = '/gate.php';
my $port = '443';
$Net::SSLeay::ssl_version = 3;
my ($replyData, $reply_type, %reply_headers)
= post_https($host, $port, $script, '', %formData);
unless(open(OUTFILE,">$outputFile")){
print LOGFILE "$timestamp: Unable to open $outputFile for writing, please
check directory permissions! Error reported: $!\n";
die "Unable to open output file: $outputFile, cannot continue\n";
}
####Parse the reponse from the gateway.
@replyPairs = split(/&/,$replyData);
foreach $replyPair (@replyPairs)
{
($name,$value) = split(/=/,$replyPair);
$value =~ s/\+/ /g;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$reply{$name} .= "\0" if (defined($reply{$name}));
$reply{$name} .= "$value";
}
foreach $rpl (keys %reply)
{
print OUTFILE "$rpl = $reply{$rpl}\n";
}
close (OUTFILE);
_____
From: David M. Funk [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 19, 2008 9:28 AM
To: [email protected]
Subject: RE: HTTPS put file in perl
Yea that's what I tried earlier and couldn't get to work..
Thanks for your reply though.
David M. Funk
President/CEO
Tivoli Certified Enterprise Consultant
Specializing in Network and Systems Management Solutions
Trinity Solutions
604 Cassandra Dr.
Cranberry Twp., PA 16066
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jim Lynch
Sent: Thursday, June 19, 2008 8:39 AM
To: [email protected]
Subject: Re: HTTPS put file in perl
I don't have any examples, but check out
http://search.cpan.org/dist/libwww-perl/lib/HTTP/Request/Common.pm
Using LWP and a PUT operation seems to be pretty straightforward if this
document is to be believed.
Jim.
On Wed, Jun 18, 2008 at 3:40 PM, David M. Funk <[EMAIL PROTECTED]> wrote:
Anybody have some code snippets that uses https to put a file on a
webserver? I can't seem to get anything to work. I do have an example in
java that works. But I'm no java coder. I would like to convert to perl.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++
java.net.URL sendUrl =new java.net.URL(
"http://10.2.0.232:28100/file?cmd=ft
<http://10.2.0.232:28100/file?cmd=ft&name=testfile.mset&filter=mset>
&name=testfile.mset&filter=mset" );
java.net.HttpURLConnection conn =( java.net.HttpURLConnection
)sendUrl.openConnection();
//sendFile.setChunkedStreamingMode( -1 );
conn.setUseCaches( false );
conn.setRequestMethod( "PUT" );
conn.setDoOutput( true );
conn.connect();
java.io.OutputStreamWriter txtWriter = new java.io.OutputStreamWriter(
conn.getOutputStream() );
java.io.BufferedReader br = new java.io.BufferedReader(new
java.io.FileReader(new java.io.File("c:\\mark\\testFile2.txt")));
String temp=new String();
while((temp=br.readLine())!=null){
txtWriter.write( temp );
txtWriter.write( "\n" );
}
br.close();
txtWriter.close();
//int resp = conn.getResponseCode();
out.write( "response Code:"+conn.getResponseMessage() );
conn.disconnect();=
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++
TIA,
David M. Funk
President/CEO
Tivoli Certified Enterprise Consultant
Specializing in Network and Systems Management Solutions
Trinity Solutions
604 Cassandra Dr.
Cranberry Twp., PA 16066
Phone: 724-316-0721
Fax: 724-772-7889
email: <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
www: <http://www.trinityITsolutions.com>
http://www.trinityITsolutions.com