pass all cgi parameters to an exe

D

D

i want to pass all cgi parameters to an exe (cgi app) and run the executable
and capture all of its output.

use CGI;
my $all_params;
my $thing = `C:/Inetpub/scripts/webapp.exe $all_params`;
print $thing;

this gives me a web page that declares and error, wich is what i would
expect, but this is good because when i pass it the right parameters i will
get back htm and i can parse it easily. the problem is i want to
impersonate what IIS would have passed if i did something like
http://site/scripts/webapp.exe and i thing the CGI module would do this for
me easily but dont know how.
 
T

Tad McClellan

D said:
i want to pass all cgi parameters to an exe (cgi app) and run the executable
and capture all of its output.


I think you are saying that you want to run a program (webapp.exe)
that was designed to run in the CGI environment from the command
line instead?

Why must you do that?

Why not access the designed-for-CGI program in the environment
it expects?

i want to
impersonate what IIS would have passed if i did something like
http://site/scripts/webapp.exe


If you want to _impersonate_ what the web server does, then you'll
need to setup the input to webapp.exe whereever it expects it.

That is, you'll need to setup an env var or stdin depending on
whether it is a GET or POST request.


A much better solution would be to have the *real web server*
do it's thing. You can invoke webapp.exe via a web server if
you make the request using one of the LWP modules.


See the Perl FAQ:

How do I fetch an HTML file?

How do I automate an HTML form submission?
 
D

D

Tad McClellan said:
I think you are saying that you want to run a program (webapp.exe)
that was designed to run in the CGI environment from the command
line instead?

Why must you do that?

Why not access the designed-for-CGI program in the environment
it expects?




If you want to _impersonate_ what the web server does, then you'll
need to setup the input to webapp.exe whereever it expects it.

That is, you'll need to setup an env var or stdin depending on
whether it is a GET or POST request.


A much better solution would be to have the *real web server*
do it's thing. You can invoke webapp.exe via a web server if
you make the request using one of the LWP modules.


See the Perl FAQ:

How do I fetch an HTML file?

How do I automate an HTML form submission?

the thing is this executable is proprietary and i cannot get the source
code, and it does some things that need to be logged. essentially if i can
intercept the output of this exe, i can then parse the output and log what
happened, lets pretend that it gives a page that cancels someones bank
account. so the exe communicates with a mainframe and cancels a persons
account then spits out an html page that says it confirmed the cancel and so
on, i need to log that. the button that submits POSTS all the forms to this
exe can be changed so that it calls my perlscript instead (there is a
rudimentary html file the exe uses as a template). when you mentioned stdin,
that sounded like the answer. but i wouldnt have a clue how to do that, i
figure it must be simple, you take everything that was passed to the
perlscript from the webserver, and then pass it to the exe, get the result
and log it, then pass that same result with no modifications back out to the
browser. i think
 
D

D

D said:
i want to pass all cgi parameters to an exe (cgi app) and run the executable
and capture all of its output.

use CGI;
my $all_params;
my $thing = `C:/Inetpub/scripts/webapp.exe $all_params`;
print $thing;

this gives me a web page that declares and error, wich is what i would
expect, but this is good because when i pass it the right parameters i will
get back htm and i can parse it easily. the problem is i want to
impersonate what IIS would have passed if i did something like
http://site/scripts/webapp.exe and i thing the CGI module would do this for
me easily but dont know how.

heres one solution maybe not the best one

my $q = new CGI;
my $url_params;
my @the_params = $q->param;
foreach my $param_name (@the_params)
{
my $param_value = $q->param($param_name);
$url_params = $url_params . $param_name . "=" . $param_value . "&";
}
my $ua = new LWP::UserAgent;
print "Content-type: text/html\r\n\r\n";
my $reg_url = "http://server/scripts/webapp.exe?$url_params";

use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("$0/0.1 " . $ua->agent);
my $req = HTTP::Request->new( GET => $reg_url );
$req->header('Accept' => 'text/html');
my $res = $ua->request($req);
if ($res->is_success)
{
$thing = $res->content;
if ($thing =~ /KEY TEXT/)
{log_cancellation();} ##i can change or log the output of the exe
print $thing;
}
else
{print "Error: " . $res->status_line . "\n";}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top