Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form script failing second child mod_perl

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
I have a script I moved to mod_perl. (Apache Registry)
Works fine under first child, but fails when new child opened with:
Code:
Fri Feb 13 07:14:24 2009] [error] Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. at /usr/local/libdata/perl5/site_perl/i386-openbsd/Term/ReadKey.pm line 362.\nCompilation failed in require at /usr/local/libdata/perl5/site_perl/Term/ReadLine/Perl.pm line 63.\n

script:

Code:
#!/usr/bin/perl
#use warnings;
use strict;
#use diagnostics;
use File::Copy;
#Start Attempt to untaint --Chris
                delete $ENV{PATH}; # Make %ENV safer
        #End Attempt to untaint --Chris
# Email Method, sendmail or SMTP etc  --Chris
our $website="ledgersmb.info";
our $email_method = "sendmail";
# path to Unix sendmail (if applicable)
our $SENDMAIL="/usr/sbin/sendmail";
our $basedir="/var/[URL unfurl="true"]www/htdocs/users/data/$website";[/URL]
our $archivedir="/var/[URL unfurl="true"]www/htdocs/users/olddata/$website";[/URL]
if(!-e "$archivedir") {
        die "Cannot find archive directory $!";
}
our $landing_page="";
our %FORM_DATA=undef;
our %simple_form=undef;
our $request_method="";
our $query_string="";
our @key_value_pairs=();
our $key_value="";
our $key="";
our $value="";

sub parse_form_data
{
    local (*FORM_DATA) = @_;
    local  ( $request_method, $query_string, @key_value_pairs, $key_value, $key, $value);
    $request_method = $ENV{'REQUEST_METHOD'};
    if ($request_method eq "GET") {
        $query_string = $ENV{'QUERY_STRING'};
    } elsif ($request_method eq "POST") {
        read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
    };
    @key_value_pairs = split(/&/, $query_string);
    foreach $key_value (@key_value_pairs) {
        ($key, $value) = split (/=/, $key_value);
        if (defined($value)) {$value =~ tr/+/ /;
            $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;};
        if (defined($FORM_DATA{$key})) {
            $FORM_DATA{$key} = join (" ", $FORM_DATA{$key}, $value);
        } else {
            $FORM_DATA{$key} = $value;
        }
    }
}; # end of sub

&parse_form_data(*simple_form);
my $t = time;

chdir ($basedir) ;

while (($key , $value) = each (%simple_form)) {
if (($key=~m/N_url/) && !($value=~m/^N_url$/)) {die ("http assholes")};
}

open (OUTFILE, ">bwcform_$t") or die ("Cannot open file");

foreach my $key (sort keys(%simple_form)) {

  print OUTFILE "<VARIABLE NAME=$key START>\n";
  print OUTFILE "$simple_form{$key}\n";
  print OUTFILE "<VARIABLE NAME=$key END>\n";
  if ($key eq "redirect") { $landing_page = $simple_form{$key};}

  }

print OUTFILE "\nEnv stuff:\n\n";
   foreach my $key (sort keys(%ENV)) {
print OUTFILE "<VARIABLE NAME=$key START>\n";
  print OUTFILE "$ENV{$key}\n";
  print OUTFILE "<VARIABLE NAME=$key END>\n";
   }
close (OUTFILE);
if ($landing_page ne "") {
  print "Location: [URL unfurl="true"]http://$ENV{'HTTP_HOST'}/$landing_page\n\n";[/URL]
} else {
  print "Location: [URL unfurl="true"]http://$ENV{'HTTP_HOST'}/\n\n";[/URL]
}
&process_email();

sub process_email {
opendir (DIRHANDLE, "$basedir") || die ("This sucks! $!");
my @filenames = readdir(DIRHANDLE);
foreach my $file (@filenames) {
        next if $file =~ /^\.\.?$/;     # skip . and ..
        parse_file($file,$basedir)



        }
closedir(DIRHANDLE);
print "Done, Fool!";
}

 sub parse_file {

        my $file=shift;
        my $basedir=shift;
         print "$basedir/$file\n";
         open (FORMFILE, "$basedir/$file") || die "OOPS Bad $!";
         my $formstuff="";
         while (<FORMFILE>) {
                 if ($_=~ m/<VARIABLE NAME=.*START>/) {
                         $_=~s/<VARIABLE NAME=/\[/;
                         $_=~s/START>/\]:/;
                         chomp;
                         $formstuff.=$_;
                         } elsif ($_=~ m/<VARIABLE NAME=.*END>/) {
                                 $formstuff.="\n";
                         } elsif ($_=~ m/Env stuff:\n/) {
                                $formstuff.="\nEnv stuff:\n\n";
                                }
                         else {
                                 chomp;
                                 $formstuff.=$_;
                         }

}

close (FORMFILE);
sendemail ($formstuff);
move("$basedir/$file", "$archivedir/$file".".sent")
    or die "move failed: $!";
#rename("$basedir/$file", "$archivedir/$file".".sent") || die "Cannot rename $file: $!";
}
sub sendemail {

        # send email notification that form submission has occurred with contents
        my $to='webmaster@ledgersmb.info';
        my $bcc="";
        my $from='FORM_MAILER@ledgersmb.info';
        my $subject="Form submission from ledgersmb.info";
        my $body=shift;
        &sendmail($to,$bcc,$from,$subject,$body);
}

######################################################
## Send Email via Unix sendmail (to,from,subject,body) $SENDMAIL must
## be a global variable assigned with the path to sendmail

sub sendmail {

        my($to, $bcc, $from, $subject, $body) = @_;

    open(MAIL, "|$SENDMAIL -t -i");

    print MAIL "To: $to\n";
    print MAIL "From: $from\n";
    print MAIL "Subject: $subject\n\n";

    print MAIL "$body\n";

    close(MAIL);
    return(0);
}

I've tried fiddling with use File::Copy qw(move);
and some combos of my or our but I haven't had any luck
 
Found the problem

Was also using Apache::DB

Guessing from what I searched, that debugging often causes this problem.

Seems like something that ought to get fixed.
Script works fine now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top