#!/usr/local/bin/perl # ###################################################################### ### ### ### CGIフォームメール送信 T-FormMail Ver.1.03 ### [1/3] メイン (tfmail.cgi) ### (c) 1996-2002 Takahiro Nishida ### http://www.mytools.net/ ### ### ###################################################################### require './tfmlib.pl'; $DEBUG = 0; print "Content-type: text/html\n\n"; &main; sub main{ &tfmlib'lock; &init_variables; &open_datafile; &check_input; &form_to_mail; &post_mail; &update_log; &update_files; &show_html; &tfmlib'unlock; } ########## 変数の初期化 sub init_variables{ $basedir = $tfmlib'basedir; $datafile = "$basedir/tfmdata.txt"; $logfile = "$basedir/tfmlog.txt"; ### 付帯情報 $time_now = &tfmlib'get_time(0, 1); # 現在時刻 $remote_host = $ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'}; # ホスト $server_name = $ENV{'SERVER_NAME'}; # サーバ $script_name = $ENV{'SCRIPT_NAME'}; # スクリプト名 } ########## データファイルのオープン sub open_datafile{ &tfmlib'openfile($datafile, *datas); &tfmlib'openfile($logfile, *logs); } ########## 入力内容のチェック sub check_input{ &tfmlib'parseform; $code = $tfmlib'F{'_code'}; $id = $tfmlib'F{'_id'}; $email = &tfmlib'decode($tfmlib'F{'_email'}); ### 各種チェック (!$id) || ($id =~ /^\d+$/) || &tfmlib'error(3, "_id"); ($code =~ /^\w+$/) || &tfmlib'error(9); ### codeに対応する設定ファイルを取得 foreach (@datas){ (/^$code\t/) && (($code, $sendto, $frags, $mname, $backurl, $subject, $finmsg, $color) = split("\t")); } ($fsend, $femail, $fshow, $fhost) = split("", $frags); ($bgcolor, $fontcolor, $empfontcolor, $linkcolor, $bgimage) = split(",", $color); ($sendto) || &tfmlib'error(10); ### メール入力なしの場合 unless($email){ # 必須ならエラー if($femail){ &local_error("メールアドレスは必須です"); } # 必須でないなら仮アドレス else{ $email = $sendto; } } ($email =~ /^[\w\-\+\.]+\@[\w\-\+\.]+$/) || &local_error("メールアドレスが入力されていないか、形式が間違っています。"); } ########## 入力をチェックし整形する sub form_to_mail{ local($errbuf, $key, $name, $must, $match, $htmlval, $mailval, $formval); local($mark_m, $mark_i); $mark_m = "★"; $mark_i = "×"; ### 正規表現ライブラリの読込 &tfmlib'matchingpattern; ### 入力チェック部 @mns = split(/\s+/, $mname); # 条件を抜き出す foreach (@mns){ ($key, $name, $must, $match) = split("###"); $htmlval = &tfmlib'decode($tfmlib'F{$key}); $formval = &tfmlib'TagToValue($htmlval); $mailval = &tfmlib'unescape($formval); ### 必須チェック if($must && !$mailval){ $errbuf .= "
/\n\n/g; ### 送信 if($DEBUG){ open(MAIL, ">$basedir/mail.txt") || &tfmlib'error(1, "mail.txt"); } else{ open(MAIL, "| $tfmlib'sendmailpath $sendto") || &tfmlib'error(6); } print MAIL $mailbuf; close(MAIL); } ########## ログの更新 sub update_log{ ### idがあったら投稿済 if($id){ $newline = "$code\t$id\t$time_now\t$remote_host\t$email\t\n"; } ### idが無かったらプレビュー else{ $timeid = &tfmlib'get_time('', 2); $id = sprintf("$timeid%03d", $$ % 1000); $prevflag = 1; $newline = "$code\t$id\t$time_now\t$remote_host\tprev\t\n"; } unshift(@logs, $newline); (@logs > $tfmlib'log_max) && ($#logs = $tfmlib'log_max - 1); } ########## ファイル更新 sub update_files{ &tfmlib'updatefile($datafile, *datas); &tfmlib'updatefile($logfile, *logs); } ########## 表示 sub show_html{ local($htitle, $hcom, $hcont, $hcopy); ### prevflagがあったら確認 if($prevflag){ $htitle = "メール送信確認"; ($fsend) && ($hcom = "以下の内容を $sendto 宛てに送ります。"); $hcom .= "内容を確認して「送信」ボタンを押して下さい。"; $hcont = "
あなたの送信IDは $id です。
※ 送信内容の変更、取消がある場合はこの番号をお書き添えの上、ページ管理者までご連絡下さい。";
if($fshow){
$hcont = "▼ メールの全文です。送信証明として保存しておくことをお勧めします。";
$hcont .= "
";
$hcont .= "" . $hmailbuf . ""; $hcont .= " |
$lmsg
$com
ブラウザのBackで戻ってください。