#!/usr/contrib/bin/perl # # Read an HTML Form posting and mail the contents to the indicated address # # Input is CL bytes from stdin, where CL is obtained from the # CONTENT_LENGTH environment variable. # # stdin format is of the form: # # keyword1=value1&keyword2=value2& # # spaces are converted to "+"'s and arbitrary characters can be encoded # as "%xx", where "xx" is the hex code for the character. # $clen = $ENV{"CONTENT_LENGTH"}; $rhost = $ENV{"REMOTE_HOST"}; # These are replaced by special fields in the form, if present $name = ""; # Who sent the form $email = "someone"; # Email of who sent the form $recip = "webmaster"; # Who to send the form to $subject = "Proto www.intel.com feedback"; # What the form's about $debug = "off"; # Print blank fields if on $form_table = "/var/httpd/proto/form.tbl"; $count = read(STDIN, $form_args, $clen); if ($count != $clen) { die "Unable to read $clen bytes from httpd.\n"; } # For debugging... open (feedback, ">/var/tmp/feedback.form"); print feedback $form_args; close(feedback); # # Convert special characters in the HTML to "real" form # # "+" -> space $form_args =~ s/\+/ /g; # Preserve &'s so they don't get converted by % processing and then split $form_args =~ s/%26/--:026--/g; # Hex encoded characters into literal data $form_args =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/sprintf("%c", hex($1))/eg; # Args separated by '&' @fargs = split(/&/, $form_args); # Process each argument foreach $arg (@fargs) { ($keyword, $value) = split(/=/, $arg); # Had to defer this until after the split... $value =~ s/--:026--/&/g; # Get rid of leading and trailing spaces $value =~ s/^ *//g; $value =~ s/ *$//g; if ($keyword eq "form-table") { $recip = &lookup($value); } elsif ($keyword eq "form-addr") { $recip = $value; } elsif ($keyword eq "name") { $name = $value; } elsif ($keyword eq "email") { $email = $value; } elsif ($keyword eq "subject") { $subject = $value; } elsif ($keyword eq "debug") { if ($value eq "") { $debug = "on"; } else { $debug = $value; } } else { # Indent multi-line comments if ($value =~ /\n/) { $value =~ s/^/\n/g; # Make sure data starts on newline $value =~ s/\n/\n /g; # Add whitespace to indent comments } $args{$keyword} = $value; } } open(MAIL, "| /usr/sbin/sendmail -odb '$recip'"); if ($name ne "") { print MAIL "From: $name <$email>\n"; } else { print MAIL "From: $email\n"; } print MAIL "To: $recip\n"; print MAIL "Subject: $subject\n"; print MAIL "\n"; foreach $arg_value (keys(%args)) { if ($args{$arg_value} ne "" || $debug eq "on") { print MAIL "$arg_value: ", $args{$arg_value}, "\n"; } } close(MAIL); print "Content-type: text/plain\n\n"; print "Thanks for the input!\n\n"; exit(0); sub lookup { local ($keyword) = @_; # Check to see if they're in the database # If so, return associated email address open(form_table, "<$form_table") || &abort("Can't open '$form_table': $!"); while () { chop; ($form_id, $email) = split(/:/); if ($form_id eq $keyword) { close(form_table); return($email); } } close(form_table); return($recip); }