Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2010
    Thanked 1 Time in 1 Post

    script works with -w switch but not without

    this script works on localhost with the -w switch but not without. it also works when use strict and use warning are active.


    without switch (aborted script):
    (2)No such file or directory: exec of ... failed

    with the switch i get:
    Use of uninitialized value $email_flag in string ne ...

    which looks initialised to me.

    on the life web server neither one works. perl is new to me, but i know some BASH and PHP.

    i run debian lenny, apache2, perl 5.10.

    #!/usr/bin/perl -w
    #works with the next two lines enabled
    #use strict;
    #use warnings;
    ##clear output
    $| = 1;
    # Define these bits 
    my $mailprog = '/usr/sbin/sendmail'; # where the mail program lives
    # $webpage  = '/'; # default web page to return to .. hidden in form element webpage
    my $to = "not\@for.you";   # where the mail is sent
    my ($command,$email,@pairs,$buffer,$pair,$email_flag) ;
    ##!! print "Content-Type: text/html\n\n";
    # get the data from the form
     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    # Split the name-value pairs
            @pairs = split(/&/, $buffer);
           foreach $pair (@pairs) {
            # Split the pair up into individual variables.                       #
            my($name, $value) = split(/=/, $pair);
            # Decode the form encoding on the name and value variables.          #
            $name =~ tr/+/ /;
            $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
            $value =~ tr/+/ /;
            $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
            # If they try to include server side includes, erase them, so they
            # aren't a security risk if the html gets returned.  Another 
            # security hole plugged up.
            $value =~ s/<!--(.|\n)*-->//g;
         ##  print "Name of form element is $name with value of $value \n";
            if ($name eq 'email') {
                $email = $value;
            if ($name eq 'command') {
                $command = $value;
    # end of extracting variables from form 
    # Do a little email checking
        if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
            $email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/ ) {
            $email_flag = "ERROR";
    #         $why_error = "Email";
    my $urlcommand = $command;
    ## Do a little command checking
    if ($command eq 'Subscribe') {
    $command = "SUBSCRIBE rpc-news";
    if ($command eq 'Unsubscribe') {
    $command = "UNSUBSCRIBE rpc-news";
    if ($command eq 'Suspend') {
    $command = "SET rpc-news NOMAIL";
    if ($command eq 'Resume') {
    $command = "SET rpc-news MAIL";
    my $getInfo = '';
    ## Start page output
    print "Content-Type: text/html\n";
     # only mail if email address is ok
      if ($email_flag ne "ERROR") {
        # Open The Mail Program
        open(MAIL,"|$mailprog -t");
         print MAIL "To: $to\n";
         print MAIL "From: $email\n";
         print MAIL "Subject: [rpc-news] $command \n";
         print MAIL "Reply-to: $email \n";
     #    print "X-RemoteIPaddress: $ENV{'REMOTE_ADDR'} \n";
         print MAIL "$command \n";
         print MAIL "EXIT \n";
        close (MAIL);
    	# email is valid
    	$getInfo = "?result=good";
    if ($email_flag eq "ERROR") {
    	$getInfo = "?result=bad";
    ## redirect to cms page 
    my $rootURL= $ENV{'SERVER_NAME'};
    my $url = "http://${rootURL}/thank_you.html${getInfo}&action=${urlcommand}";
    print "Location: $url\n\n";
    Last edited by rotezecke; 06-11-2011 at 09:35 AM. Reason: found the fix

  2. #2
    New Coder
    Join Date
    Sep 2010
    Thanked 1 Time in 1 Post

    windows line endings on unix servers. who would have thought ...


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts