#! /usr/local/bin/perl ############################################## #BooFormMailPro,v1.23 / this program is free.# # (C) BooBooClub 2000-2012 # ############################################## #set data $cgi = './bfmp.cgi'; $sendmail = '/path/to/sendmail'; $to = 'your@mail.address'; $cc = ''; $bcc = ''; $subject = 'From BooFormMailPro'; $from = 'from@address'; $type = 'r'; $sendbutton = '送 信'; $review = 'review.html'; $thanks = 'thanks.html'; $nerror = 'error.html'; $tbop = 'border="1" cellspacing="0" cellpadding="3" bordercolor="#888888"'; $tdlo = 'align="left"'; $tdro = 'align="left"'; $fontn = 'size="3"'; $fontv = 'size="3"'; $head = '【'; $sepa = '】'; $rtn = 'off'; $raddr = 'on'; $chbr = 'on'; $chkblack = 'off'; $blacklist = './blacklist.txt'; #read lib require './jcode.pl'; require './bmail.pl'; #read blacklist if($chkblack eq 'on'){ open (BL,"$blacklist"); @blacklist = ; close (BL); } #read data if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } if (length($buffer) < 1 || length($buffer) > 1048576){ &submiterror; } @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $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; $value =~ s/(\r\n|[\r\n])\.(\r\n|[\r\n])/$1 \.$2/g; $name =~ s/\Q(!--Sym_lt--)\E//g; $name =~ s/\Q(!--Sym_quot--)\E/"/g; $value =~ s/\Q(!--Sym_lt--)\E//g; $value =~ s/\Q(!--Sym_quot--)\E/"/g; &jcode'convert(*name,'sjis'); &jcode'convert(*value,'sjis'); if($value ne ''){ $FORM{$name} .= "\0".$value; } if($valsort !~ /_\Q$name\E_/){ push(@valsort,$name); $valsort .= '_'."$name".'_'; } if($chkblack eq 'on'){ foreach $black(@blacklist){ $black =~ s/(\r\n|[\r\n])//g; &jcode'convert(*black,'sjis'); if($black ne '' && ($name =~ /\Q$black\E/ || $value =~ /\Q$black\E/)){ &submiterror; } } } } foreach $key(keys %FORM){ $FORM{$key} =~ s/^\0//; } #read ENV $remoteaddr = $ENV{'REMOTE_ADDR'}; if($remoteaddr eq ''){ $remoteaddr = 'Unknown'; } #return code; $space = ''; if($rtn eq 'on'){ $rtncode = "\n"; $rtncode .= "$space"; } else{ $rtncode = ''; } #branch if($FORM{'*review'} ne ''){ $review = $FORM{'*review'}; } if($FORM{'*thanks'} ne ''){ $thanks = $FORM{'*thanks'}; } if($FORM{'*nerror'} ne ''){ $nerror = $FORM{'*nerror'}; } if($review !~ /\.html$/ || $thanks !~ /\.html$/ || $nerror !~ /\.html$/){ &seterror; } if($FORM{'*set'} ne ''){ @set = split(/,/,$FORM{'*set'}); } if($FORM{'*check'} ne ''){ @check = split(/,/,$FORM{'*check'}); foreach $check(@check){ if($FORM{$check} eq '' || $FORM{$check} =~ /^\0+$/){ $nodata .= "\0".$check; } } $nodata =~ s/^\0//; $nodata =~ s/\0/
/g; if($nodata ne ''){ &noinputerror; } } if ($from eq '*'){ $fb = '*'; $from = $FORM{'E-mail'}; } if ($subject eq '*'){ $sb = '*'; $subject = $FORM{'Subject'}; } if ($type eq 's' || $FORM{'r'} ne ''){ &mail; &s; } elsif ($type eq "r"){ &r; } else{ &seterror; } sub mail{ $to =~ s/\r\n|[\r\n]//g; $cc =~ s/\r\n|[\r\n]//g; $bcc =~ s/\r\n|[\r\n]//g; $from =~ s/\r\n|[\r\n]//g; $subject =~ s/\r\n|[\r\n]//g; if($from eq ''){ $from = $to; } if($from eq '' || length($from) > 245 || $from =~ /\@.*[\,\@]/ || $from !~ /[^@]+@[\w\-]+\..+/ || $subject eq '' ){ &submiterror; } &jcode'convert(*subject,'jis'); $subject = &bmail::mime(header,$subject); open(SEND,"|$sendmail -t"); print SEND 'From: '."$from"."\n"; print SEND 'Subject: '."$subject"."\n"; print SEND 'MIME-Version: 1.0'."\n"; print SEND 'X-Mailer: BooFormMailPro-CGI'."\n"; print SEND 'X-Mailer-Produced-by: BooBooClub'."\n"; if($raddr eq 'on'){ print SEND 'X-RemoteAddress: '."$remoteaddr"."\n"; } print SEND 'To: '."$to"."\n"; if($cc ne ''){ print SEND 'Cc: '."$cc"."\n"; } if($bcc ne ''){ print SEND 'Bcc: '."$bcc"."\n"; } print SEND 'Content-Type: text/plain; charset=iso-2022-jp'."\n\n"; &body; if($rtn eq 'on'){ $body =~ s/
/\n$space/g; } else{ $body =~ s/
/,/g; } &jcode'convert(*body,'jis'); print SEND "$body"."\n"; close SEND; } sub s{ $view = ''."\n" .$view .'
'."\n"; open (HTML,"$thanks"); @msg = ; close (HTML); $msg = join('',@msg); $msg =~ s//$view/g; print "Content-type:text/html\n\n"; print $msg; exit 0; } sub r{ &body; $view = ''."\n" .''."\n" .''."\n" .$view .$hide .''."\n" .''."\n" .'
'."\n"; open (HTML,"$review"); @msg = ; close (HTML); $msg = join('',@msg); $msg =~ s//$view/g; print "Content-type:text/html\n\n"; print $msg; exit 0; } sub body{ if($FORM{'*set'}){ $hide .= ''."\n"; foreach $set(@set){ $name = $set; $value = $FORM{$set}; if($value =~ /\0/){ @value = split(/\0/,$value); foreach $value(@value){ &setbody; } } else{ &setbody; } } } else{ foreach $set (@valsort){ $name = $set; $value = $FORM{$set}; if($value =~ /\0/){ $value =~ s/\0/
/g; &setbody; } else{ &setbody; } } } } sub setbody{ $hname = $vname = $name; $hvalue = $vvalue = $value; $hname =~ s//(!--Sym_gt--)/g; $hname =~ s/"/(!--Sym_quot--)/g; $hvalue =~ s//(!--Sym_gt--)/g; $hvalue =~ s/"/(!--Sym_quot--)/g; $vname =~ s//>/g; $vvalue =~ s//>/g; $vvalue =~ s/<br>/
/g; $hide .= ''."\n"; if($set ne 'Subject' && $set ne 'r' && $set !~ /^\*/){ $body .= $head.$name.$sepa.$rtncode.$value.$rtncode."\n"; if($chbr eq 'on'){ $vvalue =~ s/\n/
\n/g; } $view .= ''."$vname".''."$vvalue".''."\n"; } } sub noinputerror{ $errmsg = '
'."\n" .''."$nodata".'
'."\n" .'
'."\n"; open (HTML,"$nerror"); @msg = ; close (HTML); $msg = join('',@msg); $msg =~ s//$errmsg/g; print "Content-type:text/html\n\n"; print $msg; exit 0; } sub submiterror{ print "Content-type:text/html\n\n"; print ''."\n"; print ''."\n"; print 'Submit Error'."\n"; print ''."\n"; print '

Submit Error

送信エラーです。

'."\n"; print 'BACK
'."\n"; print ''."\n"; exit 0; } sub seterror{ print "Content-type:text/html\n\n"; print ''."\n"; print ''."\n"; print 'Setting Error'."\n"; print ''."\n"; print '

Setting Error

CGI設定エラーです。

'."\n"; print 'BACK
'."\n"; print ''."\n"; exit 0; }