#!/usr/bin/perl # # File: form.cgi # Package: Perl -> Form submit # Author: Kristian Fiskerstrand # Website: http://www.kfwebs.net # Description of package: # Simple Perl form processor # Installation # Remember to chmod the cgi file 755 and the evenutal output file 777 # Configuration section # Script, no need to edit anything below this line $method = 'file'; # either mail or file # For file storing $outputfile = "output.txt"; # For email sending $mailprog = '/usr/sbin/sendmail'; $recipients = 'user@host'; $from = 'user@host'; print "Content-type:text/plain\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $string = ""; foreach $key (keys(%FORM)) { $string .= "$key: $FORM{$key}\n"; } $string .= "IP:".$ENV{'REMOTE_ADDR'}."\n"; $string .= "Form: ".$ENV{'HTTP_REFERER'}."\n"; # Store to file if($method eq 'file') { open(FP, ">>$outputfile"); print FP "#################\n"; print FP $string; print FP "#################\n"; close(FP); } # Send email if($method eq 'mail') { open(MAIL, "|$mailprog -t") or dien("Can't access sendmail binary"); print MAIL "To: $recipients\n"; print MAIL "From: $from\n"; print MAIL "Reply-to: $from\n"; print MAIL "Subject: Form Data\n\n"; print MAIL $string; close(MAIL); } print "Form submitted"; sub dien { my($errmsg) = @_; print $errmsg; exit; }