CGI Perl script to access ERIN database

#!/usr/local/bin/perl

# ERIN database gateway script
# Tony Boston	- June 1994

# Define constants and environment variables

$ENV{'ORACLE_HOME'} = '';
$ENV{'ORACLE_SID'} = '';
$ENV{'TWO_TASK'} = '';
$cgidir = '';
$sqrdir = '';
$logdir = '';

# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";

# Check if GET or POST
if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $query = $ENV{'QUERY_STRING'};
    @pairs = split(/&/, $query);
    foreach $pair (@pairs)
    {
        ($name, $value) = split(/=/, $pair);

        # Un-Webify plus signs and %-encoding
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

        $value =~ s/~!/ ~!/g;

        # Uncomment for debugging purposes
        # print "Setting $name to $value";
        if ($name eq "report") {
              $report = $value;
        }
        else {
           $value =~ tr/'/~/;
           $param = join('', $param," '",$value,"'");
        }
    }
  } 
elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    # Get the input
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    # Split the name-value pairs
    @pairs = split(/&/, $buffer);
 
    foreach $pair (@pairs)
    {
        ($name, $value) = split(/=/, $pair);
 
        # Un-Webify plus signs and %-encoding
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 
        $value =~ s/~!/ ~!/g;
 
        # Uncomment for debugging purposes
        # print "Setting $name to $value";
        if ($name eq "report") {
              $report = $value;
        }
        else {
           $value =~ tr/'/~/;
           $param = join('', $param," '",$value,"'");
        }
    }
  }

# Die if no report name passed
if ($report !~ /R/ ) {
   print "TITLE Error!/TITLE\n";
   print "Error - No report name passed!\n";
   die "$ENV{'REMOTE_HOST'}@$ENV{'REQUEST_METHOD'}@ERIS.pl@Error - No report name passed!\n";
}

# Set up SQR report command and log db access
$command = "$ENV{'ORACLE_HOME'}/bin/sqrt $sqrdir/$report.sqt -d $param | " .
"sed -f $sqrdir/sed_sqr_out; $cgidir/LOG2.sh $ENV{'REMOTE_HOST'} $report " .
"$ENV{'REQUEST_METHOD'} $param";
# Uncomment for debugging purposes
# print $command;
open (COMM, "$command|") || die "Open DB access command did not work: $!\n";
while () {
   print;
}
close (COMM);