use LWP::UserAgent;
$ua = new LWP::UserAgent;
$req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc";
$req->content_type("application/x-www-form-urlencoded");
$req->content($query);
$res = $ua->request($req);
Anyone any ideas?
#!/usr/bin/perl
# REPLACE THIS WITH YOUR NOCHEX EMAIL ADDRESS.
$admin_email = "sa...@geodetech.com";
# THIS SHOULD BE EITHER smtp OR sendmail DEPENDING
# ON THE MAIL METHOD YOU WANT TO USE.
$mail_method = "smtp";
# IF YOU ARE USING SENDMAIL TO SEND EMAIL
# SET THE PATH TO SENDMAIL ON YOUR SERVER.
# IN ALL PROBABILITY THE DEFAULT WILL WORK
$sendmail_path = "/usr/sbin/sendmail -t";
# IF YOU ARE USING SMTP TO SEND EMAIL
# SPECIFY THE SMTP SERVER TO USE.
# IN ALL PROBABILITY THE DEFAULT WILL WORK
$smtp_server = "localhost";
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $query);
$count = 0;
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$variable{$name} = $value;
$count++;
}
$transaction_id = $variable{'transaction_id'};
$transaction_date = $variable{'transaction_date'};
$from_email = $variable{'from_email'};
$to_email = $variable{'to_email'};
$order_id = $variable{'order_id'};
$amount = $variable{'amount'};
$security_key = $variable{'security_key'};
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$req = new HTTP::Request "POST","https://www.nochex.com/nochex.dll/apc/apc";
$req->content_type("application/x-www-form-urlencoded");
$req->content($query);
$res = $ua->request($req);
if ($res->is_error) {
$subject = "Perl APC Script Error - Could not connect to Nochex servers";
$message = "Your Perl APC script was called but returned an error because
it \ncould not connect with the NOCHEX servers.\n.";
} elsif ($res->content eq "AUTHORISED") {
$subject = "APC Result - AUTHORISED";
$message = "NOCHEX RESPONSE:
AUTHORISED\n-----------------------------------------------\nOrder submitted
with ID:
".$order_id."\n-----------------------------------------------\ntransaction
id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom
email:\t".$from_email."\nto
email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity
key:\t".$security_key."\n";
} elsif ($res->content eq "DECLINED") {
$subject = "APC Result - DECLINED";
$message = "NOCHEX RESPONSE:
DECLINED\n-----------------------------------------------\nOrder submitted
with ID:
".$order_id."\n-----------------------------------------------\ntransaction
id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom
email:\t".$from_email."\nto
email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity
key:\t".$security_key."\n";
} else {
$subject = "Invalid APC Result Returned";
$message = "The NOCHEX APC server returned an unrecognised or invalid
response. In \nall probability due to en error in your code but could be the
APC \nserver screwing
up.\n-----------------------------------------------\nOrder submitted with
ID:
".$order_id."\n-----------------------------------------------\ntransaction
id:\t".$transaction_id."\ntransaction date:\t".$transaction_date."\nfrom
email:\t".$from_email."\nto
email:\t".$to_email."\norder_id:\t".$order_id."\namount:\t".$amount."\nsecurity
key:\t".$security_key."\n";
}
print "Content-Type: text/plain\n\n";
if ($mail_method eq "smtp") {
use Net::SMTP;
$smtp = Net::SMTP->new($smtp_server);
$smtp->mail($ENV{USER});
$smtp->to($admin_email);
$smtp->data();
$smtp->datasend("From: APC Script <apc_s...@your.website>\n");
$smtp->datasend("To: ".$admin_email."\n");
$smtp->datasend("Subject: ".$admin_email."\n");
$smtp->datasend("Content-Type: text/plain\n");
$smtp->datasend("\n");
$smtp->datasend($message);
$smtp->dataend();
$smtp->quit;
} elsif ($mail_method eq "sendmail") {
open(SENDMAIL, "|$sendmail_path") or die "Cannot open sendmail: $!";
print SENDMAIL "From: APC Script <apc_s...@your.website>\n";
print SENDMAIL "To: ".$admin_email."\n";
print SENDMAIL "Subject: ".$subject."\n";
print SENDMAIL "Content-Type: text/plain\n\n";
print SENDMAIL $message;
close(SENDMAIL);
}
Why did you post this here? Seems to me *someone* forgot what groups
are for what! ;)
sherm--
> ...
I notice that you didn't get status to confirm that
res->is_error is returning a 401 authorization error...
> if ($res->is_error) {
> $subject = "Perl APC Script Error - ... ";
> $message = "Your Perl APC script was called .
$status = $res->status_line; # confirm actual error
} elsif {
...
Also: use LWP::Debug qw/+/; # add debug trace as needed
--
Charles DeRykus
> ...
} elsif {
...
--
Charles DeRykus
I've added '$status = $res->status;' line where suggested, and have also
added the lines '$response_as_string = $res->as_string;' and '$error_as_html
= $res->error_as_HTML;'. When I print these, I get the following output:-
----------------------------------------------------------------------
response_as_string = HTTP/1.1 411 Length Required
Connection: close
Date: Thu, 07 Jan 2010 09:32:22 GMT
Content-Length: 24
Content-Type: text/html
Client-Date: Thu, 07 Jan 2010 09:32:19 GMT
Client-Peer: [REMOVED FOR SECURITY]
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=Equifax/OU=Equifax Secure Certificate
Authority
Client-SSL-Cert-Subject: /C=GB/ST=West Yorkshire/L=Leeds/O=Nochex
Ltd/OU=GB/CN=www.nochex.com
Client-SSL-Cipher: RC4-MD5
Client-SSL-Warning: Peer certificate not verified
<h1>Length Required</h1>error_as_html = <HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
411 Length Required
</BODY>
</HTML>
status = 411 Length
Required-----------------------------------------------So it appears that a
length is required. It may be a stupid question, but a length of what, and
how should I provide it within the following code?use LWP::UserAgent;$ua =
new LWP::UserAgent;$req = new HTTP::Request('POST',
'https://www.nochex.com/nochex.dll/apc/apc');$req->content_type("application/x-www-form-urlencoded");$req->content($query);$res
= $ua->request($req);
> > ...
>
>
> I've added '$status = $res->status;' line where suggested, and have also
> added the lines '$response_as_string = $res->as_string;' and '$error_as_html
> = $res->error_as_HTML;'. When I print these, I get the following output:-
> ----------------------------------------------------------------------
> response_as_string = HTTP/1.1 411 Length Required
> ...
> status = 411 Length
> Required-----------------------------------------------So it appears that a
> length is required. It may be a stupid question, but a length of what, and
> how should I provide it within the following code?use LWP::UserAgent;$ua =
> new LWP::UserAgent;$req = new HTTP::Request('POST',
> 'https://www.nochex.com/nochex.dll/apc/apc');$req->content_type("application/x-www-form-urlencoded");$req->content($query);$res
> = $ua->request($req);
A POST will require a valid content-length header IIRC.
> $req->content($query);
> $res = $ua->request($req);
Where is your request $query above defined?
You can check the actual request to ensure that the
request has valid headers and the $query content is
getting set and passed to the server correctly.
print $req->as_string;
As mentioned earlier, 'use LWP::Debug qw/+/' will provide
voluminous details about the transaction too.
--
Charles DeRykus
> > ...
>
>
> I've added '$status = $res->status;' line where suggested, and have also
> added the lines '$response_as_string = $res->as_string;' and
> '$error_as_html
> = $res->error_as_HTML;'. When I print these, I get the following output:-
> ----------------------------------------------------------------------
> response_as_string = HTTP/1.1 411 Length Required
> ...
> status = 411 Length
> Required-----------------------------------------------So it appears that
> a
> length is required. It may be a stupid question, but a length of what, and
> how should I provide it within the following code?use LWP::UserAgent;$ua =
> new LWP::UserAgent;$req = new HTTP::Request('POST',
> 'https://www.nochex.com/nochex.dll/apc/apc');$req->content_type("application/x-www-form-urlencoded");$req->content($query);$res
> = $ua->request($req);
A POST will require a valid content-length header IIRC.
> $req->content($query);
> $res = $ua->request($req);
Where is your request $query above defined?
$query is defined in the following line near the top of the script:-
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
You can check the actual request to ensure that the
request has valid headers and the $query content is
getting set and passed to the server correctly.
print $req->as_string;
adding the following lines:-
$request_as_string = $req->as_string;
print "request_as_string = $request_as_string\n";
produced the following output:-
'request_as_string = POST https://www.nochex.com/nochex.dll/apc/apc
User-Agent: libwww-perl/5.79
Content-Type: application/x-www-form-urlencoded'Notably, there is no mention
of any $query content, so I guess there isn't any! However, is that because
none is being provided in the call-back, or am I just not finding it
somehow?As mentioned earlier, 'use LWP::Debug qw/+/' will providevoluminous
details about the transaction too.Unfortunately, the CPAN write up on
LWP::Debug doesn't give me enough information to figure out how to apply
it.--Charles DeRykus
sherm--
I explained why at the top of the post! This is the number one newsgroup for
miscellaneous perl discussions and queries and, as far as I'm concerned, I'm
bang on topic. Also, it appears Charles DeRykus agrees with me, and he's
being VERY helpful.
Graham
There's a major problem then because you're sending no content
in the POST. The code you posted shows:
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
So the intent is to pick up the correct form pairs from the
user via STDIN to supply the POST content. Adding this check
would be a good idea:
my $len = read( STDIN, $query, $ENV{'CONTENT_LENGTH'})
or die "error: ", defined $len ? "no content" : $!;
As mentioned earlier, 'use LWP::Debug qw/+/' will providevoluminous
> details about the transaction too.Unfortunately, the CPAN write up on
> LWP::Debug doesn't give me enough information to figure out how to apply
> it.
It's applied automatically if added as is.
(This thread is probably better continued in the
libwww-perl mailing list. Check Google for details.)
--
Charles DeRykus
We don't like socialists in our newsgroup. We'll be seeing not again
commie.
PERMO
> We don't like socialists in our newsgroup. We'll be seeing not again
> commie.
>
> PERMO
If you're going to post nonsense, you could at least snip the text. We
all know you're know Shendley, so your efforts are in vain (it'll just
win more support for the person you're attempting to harass).
--
Not really a wanna-be, but I don't know everything.
What efforts?? I've already proven my point & and he knows what it is.
Now it's just entertainment for me. I am above nearly every single
person I come in contact with in every conceivable way. Nearly
everybody on this planet is the nexus of my next laugh. Give me break.
PERMO
> On Jan 7, 6:37 pm, Wanna-Be Sys Admin <sysad...@example.com> wrote:
>> Permostat wrote:
>> > We don't like socialists in our newsgroup. We'll be seeing not
>> > again commie.
>>
>> > PERMO
>>
>> If you're going to post nonsense, you could at least snip the text.
>> We all know you're know Shendley, so your efforts are in vain (it'll
>> just win more support for the person you're attempting to harass).
>> --
>> Not really a wanna-be, but I don't know everything.
It's improper to quote signatures.
> What efforts??
This, that, what you've done. It takes some effort to bother pretending
to be someone else.
> I've already proven my point & and he knows what it is.
You've made no point, you've only posted as someone else and shown you
don't know how to quote messages on usenet. How does that make him
look bad?
> Now it's just entertainment for me.
That's kind of sad.
> I am above nearly every single
> person I come in contact with in every conceivable way.
I suppose you are welcome to believe that so long as you make a claim,
that it makes it true in your own mind, but that sort of logic doesn't
work too well in real life, when it's more than just self esteem.
> Nearly
> everybody on this planet is the nexus of my next laugh.
Are you the guy that wrote the time travel watch spam?
> Give me break.
I'll be happy to break whatever.
When you know the internet well enough to do anything in under two
minutes, it is no effort. Which is where you cross dressers are wrong
about trolls spending way too much on here.
> > I've already proven my point & and he knows what it is.
>
> You've made no point, you've only posted as someone else and shown you
> don't know how to quote messages on usenet. How does that make him
> look bad?
>
I'm not trying to make anyone look bad and I'll quote on Usenet
however I want to quote. Nobody has told me anything about my quoting
in 15 years. So I'm going to assume you are assuming I'm some hack who
has never walked into an alt. group before. You've lost the plot and
let yourself believe you are as smart as you think you are.
> > Now it's just entertainment for me.
>
> That's kind of sad.
It is sad to be so letdown by people in general that you let them
become little wind up things.
> > I am above nearly every single
> > person I come in contact with in every conceivable way.
>
> I suppose you are welcome to believe that so long as you make a claim,
> that it makes it true in your own mind, but that sort of logic doesn't
> work too well in real life, when it's more than just self esteem.
It is only confidence and self esteem. I have found a loving and
sweetly devoted girlfriend. I have super loyal friends who defend me.
And I have parents who fund my education and make sure to the final
degree that I am well taken care of. I don't fuck with bullshitters,
drama queens, or junkie/alcoholics. Why all of this?? Because I
understand how important a person like myself is and I accept NO less
than best in my life. It works.
> > Nearly
> > everybody on this planet is the nexus of my next laugh.
>
> Are you the guy that wrote the time travel watch spam?
I use the correct words for the proper intent. I didn't mean to
confuse you.
> > Give me break.
>
> I'll be happy to break whatever.
Stick a cattle prod set to max up your cunt.
> Not really a wanna-be, but I don't know everything.
PROTO
> On Jan 7, 11:33 pm, Wanna-Be Sys Admin <sysad...@example.com> wrote:
>> Permostat wrote:
>> > On Jan 7, 6:37 pm, Wanna-Be Sys Admin <sysad...@example.com> wrote:
>> >> Permostat wrote:
>> >> > We don't like socialists in our newsgroup. We'll be seeing not
>> >> > again commie.
>>
>> >> > PERMO
>>
>> >> If you're going to post nonsense, you could at least snip the
>> >> text. We all know you're know Shendley, so your efforts are in
>> >> vain (it'll just win more support for the person you're attempting
>> >> to harass). --
>> >> Not really a wanna-be, but I don't know everything.
>>
>> It's improper to quote signatures.
>>
>> > What efforts??
>>
>> This, that, what you've done. It takes some effort to bother
>> pretending to be someone else.
>
> When you know the internet well enough to do anything in under two
> minutes, it is no effort.
What does "knowing the Internet" have to do with how fast you type or
not? The point is, it takes time and effort, which shows you're the
one with the problem.
> Which is where you cross dressers are wrong
> about trolls spending way too much on here.
Well, at least you admit you're a troll. Anyway, shouldn't "cross
dressers" be hyphenated? You would seem to know, so I'm asking you.
>> > I've already proven my point & and he knows what it is.
>>
>> You've made no point, you've only posted as someone else and shown
>> you don't know how to quote messages on usenet. How does that make
>> him look bad?
>>
>
> I'm not trying to make anyone look bad and I'll quote on Usenet
> however I want to quote.
Not trying to make anyone look bad, by posting as their name pretending
to be them? Sure. And, as for quoting style... you want to look like
an idiot? Seems to me, if you spent so much time online (that much, I
can believe) that you'd know how to quote properly.
> Nobody has told me anything about my quoting
> in 15 years.
That's because you're either new to usenet, or you frequent groups that
aren't remotely educated.
> So I'm going to assume you are assuming I'm some hack who
> has never walked into an alt. group before.
I really don't care what you past in alt.test This is not an alt.*
group.
> You've lost the plot and
> let yourself believe you are as smart as you think you are.
Do you _own_ a mirror?
>> > Now it's just entertainment for me.
>>
>> That's kind of sad.
>
> It is sad to be so letdown by people in general that you let them
> become little wind up things.
You're not making any sense. I think it's sad that you think bugging
someone online is entertaining. I think it's sad you feel the need to
spend the time to post as them, pretending to be them, including
creating multiple profiles on popular social networking sites. I think
it's sad, that instead of dropping it, you chose to engage people here
that only makes you look like a fool.
>> > I am above nearly every single
>> > person I come in contact with in every conceivable way.
>>
>> I suppose you are welcome to believe that so long as you make a
>> claim, that it makes it true in your own mind, but that sort of logic
>> doesn't work too well in real life, when it's more than just self
>> esteem.
>
> It is only confidence and self esteem.
But, it is not "fact" and that's the problem. Furthermore, any day I'm
certain I'd out-wit you.
> I have found a loving and
> sweetly devoted girlfriend.
So? Honestly, I can't help but doubt anyone that will spout off such
irrelevant variables into their argument. The fact you feel the need,
says it's probably one of several traits of failure you have.
> I have super loyal friends who defend me.
Do your "super loyal friends" care not why they defend your defenseless
actions? You're telling me that your "friends" are so good, that you
can harass people for no reason and they'll stand by and defend you?
This is a good thing?
> And I have parents who fund my education
Because, without their "funding" you couldn't make it on your own like
an intelligent person could?
> and make sure to the final
> degree that I am well taken care of.
We care?
> I don't fuck with bullshitters,
So you don't talk to yourself?
> drama queens, or junkie/alcoholics.
You know, as trolly as you're being, what's your point? If you stay
away from those people, good, but *good luck* doing so online.
> Why all of this??
Yes, why? What's your point?
> Because I
> understand how important a person like myself is and I accept NO less
> than best in my life. It works.
Irrelevant. No one cares how special your mother tells you that you
are, people care that you're coming here posting as a long time member,
posting as their name and trying to create problems. Regardless of how
important you think you are, it shows you lack intellect and reason.
>> > Nearly
>> > everybody on this planet is the nexus of my next laugh.
>>
>> Are you the guy that wrote the time travel watch spam?
>
> I use the correct words for the proper intent. I didn't mean to
> confuse you.
The fact I don't buy into your bullshit, is hardly an indication you've
somehow confused me. Of course, we can only respond to what you say or
do. You act the act you act.
>> > Give me break.
>>
>> I'll be happy to break whatever.
>
> Stick a cattle prod set to max up your cunt.
Well, if I physically had a "cunt" on my person, I might be too busy to
give you the time I've given you. Are you lonely? This is the worst
sweet talk anyone's ever tried with me.
>> Not really a wanna-be, but I don't know everything.
>
> PROTO
Again, try and learn to not quot signatures, you genius.
--
Charles DeRykus
Checking the enironmental variables, $ENV{'REQUEST_METHOD'} = GET and there
is no query string, so that explains why $query is empty! Looks like the
problem wasn't with the script (although it wasn't perfect), but with
Nochex - what a lot of numpties! Still, I should have checked all these
issues before bothering folk, so apologies. I'll leave it here.
---
Graham
+-------------------+ .:\:\:/:/:.
| PLEASE DO NOT | :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:
| | '=(\ 9 9 /)='
| Thank you, | ( (_) )
| Management | /`-vvv-'\
+-------------------+ / \
| | @@@ / /|,,,,,|\ \
| | @@@ /_// /^\ \\_\
@x@@x@ | | |/ WW( ( ) )WW
\||||/ | | \| __\,,\ /,,/__
\||/ | | | (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==================================================================
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
It's okay man. Sometimes people have bad days.
SHERMINATOR
Listen to this guy. You smart ones make it too easy.
PERMO
What's with this guy?? Do you think he walks around Switzerland saying
plonk at people all day??
SHERMAN
hp