Van | : | Roel Syperda | Datum | : | 06-01-2005 |
Aan | : | Allen | MsgID | : | 1871.1 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
Van | : | Michel Uphoff (Sysop) | Datum | : | 06-01-2005 |
Aan | : | Roel Syperda | MsgID | : | 1871.2 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
Van | : | Ronald Beuker | Datum | : | 07-01-2005 |
Aan | : | Roel Syperda | MsgID | : | 1871.3 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
Van | : | Roel Syperda | Datum | : | 07-01-2005 |
Aan | : | Ronald Beuker | MsgID | : | 1871.4 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
Van | : | Ronald Beuker | Datum | : | 07-01-2005 |
Aan | : | Roel Syperda | MsgID | : | 1871.5 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
Van | : | Roel Syperda | Datum | : | 08-01-2005 |
Aan | : | Ronald Beuker | MsgID | : | 1871.6 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |
#!/usr/local/bin/perl -wT
use strict;
use CGI;
### VARIABLES (you can change these to the appropriate settings)
my $dbfile = "/opt/guide/www.fotovak-engel.nl/cgi-bin/cwmailform_db";
my $page_title = "Bestelformulier";
my $mailprogram = "/usr/sbin/sendmail -t";
### INIT (do not change unless you know what you're doing)
$ENV{'PATH'} = "/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $q = new CGI;
my %in = $q->Vars;
my %recipients = ();
my %required_fields = ();
### PROGRAM
# Read in the file with recipient-identifiers and recipients
read_db();
# Check the recipient
if((defined($in{'form_recipient'})) && ($in{'form_recipient'} ne "")) {
my $recipient_address = check_recipient($in{'form_recipient'});
if((defined($recipient_address)) && ($recipient_address ne "0")) {
$in{'form_recipient'} = $recipient_address;
} else {
own_die("Recipient not allowed...");
}
} else {
own_die("No recipient...");
}
# Check if all required fields are filled out
if((defined($in{'required_fields'})) && ($in{'required_fields'} ne "")) {
unless(check_required_fields($in{'required_fields'})) {
if((defined($in{'form_wrong_url'})) && ($in{'form_wrong_url'} ne "")) {
print "Location: $in{'form_wrong_url'}\n";
}
own_die("Please fill out all required fields...");
}
}
# Set miscellaneous settings
check_misc();
# Let's email the data
mail_data();
# Redirect to the ok-page, or show a message
if((defined($in{'form_ok_url'})) && ($in{'form_ok_url'} ne "")) {
print "Location: $in{'form_ok_url'}\n";
}
header();
print "Your mail has been sent...\n";
footer();
### SUB-ROUTINES
sub header {
print "Content-type: text/html\n\n";
print "<HTML>\n";
print " <HEAD>\n";
print " <TITLE>$page_title</TITLE>\n";
print " </HEAD>\n";
print " <BODY>\n";
}
sub footer {
print " </BODY>\n";
print "</HTML>\n";
}
sub mail_data {
open(MAIL,"|$mailprogram") || own_die("Please try again later. Mailer-error.");
print MAIL "From: $in{'form_email'}\n";
print MAIL "To: $in{'form_recipient'}\n";
print MAIL "Subject: $in{'form_subject'}\n\n";
print MAIL "The following data was submitted:\n\n";
if((defined($in{'form_body'})) && ($in{'form_body'} ne "")) {
print MAIL "="x45 ."\n";
print MAIL "$in{'form_body'}\n";
print MAIL "="x45 ."\n";
print MAIL "\n";
}
foreach my $in_field (sort(keys(%in))) {
next unless($in_field =~ /^form_/);
next if($in_field =~ /^form_(email|recipient|subject|body|ok_url|wrong_url)$/);
print MAIL "$in_field\t= $in{$in_field}\n";
}
close(MAIL);
}
sub check_recipient {
my($defined_recipient_identifier) = @_;
if((defined($recipients{$defined_recipient_identifier})) && ($recipients{$defined_recipient_identifier} ne "")) {
return($recipients{$defined_recipient_identifier});
} else {
return(0);
}
}
sub check_required_fields {
my $missing_field_count = 0;
my($defined_required_fields) = @_;
my @splitted_required_fields = split(/,/,$defined_required_fields);
foreach my $splitted_required_field (@splitted_required_fields) {
$splitted_required_field =~ s/^\ +//g; # remove leading whitespaces
$splitted_required_field =~ s/\ +$//g; # remove trailing whitespaces
next if($splitted_required_field =~ /^$/);
$required_fields{"form_".$splitted_required_field} = 1;
}
foreach my $required_field (keys(%required_fields)) {
unless((defined($in{$required_field})) && ($in{$required_field} ne "")) {
$missing_field_count++;
}
}
if($missing_field_count > 0) {
return(0);
} else {
return(1);
}
}
sub check_misc {
unless((defined($in{'form_email'})) && ($in{'form_email'} ne "")) {
$in{'form_email'} = "anonymous\@unknown.anon.com";
}
unless((defined($in{'form_subject'})) && ($in{'form_subject'} ne "")) {
$in{'form_subject'} = "WWW-form";
}
}
sub read_db {
if(!open(DB,"$dbfile")) {
own_die("Failed to open configfile...");
} else {
chomp(my @db_lines = <DB>);
close(DB);
foreach my $db_line (@db_lines) {
$db_line =~ s/(\ |\t|(\015\012)|(\015)|(\012))+//g; # Filter out some stuff
my($db_recipient_identifier,$db_recipient) = split(/:/,$db_line);
next unless((defined($db_recipient_identifier)) && ($db_recipient_identifier ne ""));
next unless((defined($db_recipient)) && ($db_recipient ne ""));
$recipients{$db_recipient_identifier} = $db_recipient;
}
}
}
sub own_die {
my($die_msg) = @_;
unless(defined($die_msg)) {
$die_msg = "Error";
}
header();
print "$die_msg\n<BR>\n";
footer();
exit(0);
}
Groeten, Roel.Van | : | Ronald Beuker | Datum | : | 08-01-2005 |
Aan | : | Roel Syperda | MsgID | : | 1871.7 |
Onderwerp | : | Bestand meesturen met formulier dmv C... | Forum | : | ws-nlcomputer |