Forward variables to cgi script

C

Chad

I have a Visual Basic program that loads a url and plugs in some values
for a few variables in a perl cgi script. This script is on a SCO
server and runs some 4GL programs. Instead of having the Visual Basic
program run the cgi script from a url on the SCO box I want it to run a
cgi script on my Linux server and then have that cgi script forward to
the cgi script on the SCO box. I got this working with the following
cgi script on the Linux box.

#!/usr/bin/perl

$user = "<username>";
$pass = "<password>";
$data = "<database_path>";

print "Location:
http://sco_server/cgi-bin/reportsrv.cgi?USERNAME=$user&PASSWORD=$p
ass&DATABASE=$data\n\n"

The cgi script reportsrv.cgi on SCO takes the three variables USERNAME,
PASSWORD, and DATABASE. If I have the Visual Basic program connect
directly to the SCO box it passes those variables to the cgi script,
but how can I get a cgi script on Linux to pass those same variables to
the cgi script on SCO? As you can see I've hard coded them into the
script above, which is not what I want. I've tried useing
USERNAME=USERNAME etc.. in the url, but that didn't pass the variables.
 
M

Mumia W.

Chad said:
I have a Visual Basic program that loads a url and plugs in some values
for a few variables in a perl cgi script. This script is on a SCO
server and runs some 4GL programs. Instead of having the Visual Basic
program run the cgi script from a url on the SCO box I want it to run a
cgi script on my Linux server and then have that cgi script forward to
the cgi script on the SCO box. I got this working with the following
cgi script on the Linux box.

#!/usr/bin/perl

$user = "<username>";
$pass = "<password>";
$data = "<database_path>";

print "Location:
http://sco_server/cgi-bin/reportsrv.cgi?USERNAME=$user&PASSWORD=$p
ass&DATABASE=$data\n\n"

The cgi script reportsrv.cgi on SCO takes the three variables USERNAME,
PASSWORD, and DATABASE. If I have the Visual Basic program connect
directly to the SCO box it passes those variables to the cgi script,
but how can I get a cgi script on Linux to pass those same variables to
the cgi script on SCO? As you can see I've hard coded them into the
script above, which is not what I want. I've tried useing
USERNAME=USERNAME etc.. in the url, but that didn't pass the variables.

Use the CGI module to parse the form and escape the form data before
sending it to the browser:

use strict;
use warnings;
use CGI qw/:standard/;
use URI::Escape;

our ($user, $pass, $data);

$user = escapeHTML(param('user'));
$pass = escapeHTML(param('pass'));
$data = escapeHTML(param('data'));

print "Location: $location?" .
"USERNAME=$user&PASSWORD=$pass&DATABASE=$data\n\n"

__END__

Param() comes from the CGI module, and escapeHTML comes from
URI::Escape. Read the docs on how to use these.
 
M

Mumia W.

Mumia said:
Chad said:
[...]
Param() comes from the CGI module, and escapeHTML comes from
URI::Escape. [...]

No it doesn't. My brain is finally activated. Use uri_escape() to escape
URL's :)

use strict;
use warnings;
use CGI qw/:standard/;
use URI::Escape;

our ($user, $pass, $data);

$user = uri_escape(param('user'));
$pass = uri_escape(param('pass'));
$data = uri_escape(param('data'));

my $locstr = qq{
Location: $location?
USERNAME=$user&
PASSWORD=$pass&
DATABASE=$data
};

$locstr =~ s/(?<!tion:)\s+//g;
print $locstr, "\n\n";


__END__
 
M

Mumia W.

Chad said:
I have a Visual Basic program that loads a url and plugs in some values
for a few variables in a perl cgi script.
[...] how can I get a cgi script on Linux to pass those same variables to
the cgi script on SCO? [...]


I posted another solution in the thread.

You can also generate a 307 redirection header to tell the browser to
post the form to another location like so:

use strict;
use warnings;
use CGI qw/:standard/;

# You set the $location.

print header(
-status => '307 Temporary Redirect',
-location => $location,
);

__END__

BRAIN = ON
:)
 
C

Chad

Mumia said:
Chad said:
I have a Visual Basic program that loads a url and plugs in some values
for a few variables in a perl cgi script.
[...] how can I get a cgi script on Linux to pass those same variables to
the cgi script on SCO? [...]


I posted another solution in the thread.

You can also generate a 307 redirection header to tell the browser to
post the form to another location like so:

use strict;
use warnings;
use CGI qw/:standard/;

# You set the $location.

print header(
-status => '307 Temporary Redirect',
-location => $location,
);

__END__

Thanks, both solutions worked. I guess I'll use the 307 redirection
since it's less code. Thanks for your help.
 
M

Mumia W.

Chad said:
Mumia said:
[...]
print header(
-status => '307 Temporary Redirect',
-location => $location,
);

__END__

Thanks, both solutions worked. I guess I'll use the 307 redirection
since it's less code. Thanks for your help.

You're welcome.
 

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,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top