#!/usr/local/bin/perl
require "./jcode.pl";
require "./cgi-lib.pl";
&ReadParse;
while(($k,$v) = each %in)
{
&jcode'convert(*v,"sjis");
$in{$k} = $v;
}
# 設定はここから↓
# ログファイル名
$logfile = './ohen.csv';
# ファイルロック形式
# → 0=no 1=symlink関数 2=mkdir関数
$lockkey = 1;
# ロックファイル名
$lockfile = './lock/form.lock';
# 最大記事数(これを超える記事は古い順に削除されます)
$max = 100000;
$mode= $in{"mode"};
$er= $in{"er"};
$kazu = $in{"kazu"};
$count = 1;
$step1 = $in{"step1"};
$back = $in{"back"};
$ma = $in{"ma"};
$sendmail = '/usr/sbin/sendmail';
$mailto = "cups\@nsg.gr.jp";
$ckmail = "cups\@nsg.gr.jp";
$eq1 = $in{"eq1"};
$eq2 = $in{"eq2"};
$eq3 = $in{"eq3"};
$eq4 = $in{"eq4"};
$eq5 = $in{"eq5"};
$eq6 = $in{"eq6"};
$eq7 = $in{"eq7"};
#リンクで来たかチェック
if ($mode eq "") {
$mode= 1;
}
while($count <= $kazu){
$eq[$count] = $in{"eq$count"};
if ($eq[$count] eq "▼選択してください") { &error("選択されていない項目があります。お手数ですが、前のページに戻って選択をお願いします。"); }
$eq[$count] =~ s/,/、/g;
$eq[$count] =~ s/\r//g;
$eq[$count] =~ s/\n//g;
if ($eq[$count] eq "") {$eq[$count] = "未記入";}
$count++;
}
if ($mode == 1) { &step1; }
if ($mode == 2) {
if ($eq1 eq "") { &error("ニックネームが入力されていません。
"); }
if ($eq2 eq "") { &error("応援メッセージが入力されていません。
"); }
®ist;
}
# ステップ1はここから↓
sub step1{
print "Content-type: text/html\n\n";
print <<"EOM";
JAPAN サッカーカレッジ


戻る
Copyright(C)CUPS.All Rights Reserved.
EOM
}
#---------------------------------------------------------------------------
sub error {
print "Content-type: text/html\n\n";
print <<"EOM";
JAPAN サッカーカレッジ


$_[0]
戻る
Copyright(C)CUPS.All Rights Reserved.
EOM
exit;
}
#----------------#
# 書きこみ処理 #
#----------------#
sub regist {
if ($back eq ""){
$step1 = join(",",@eq);
}
local($no,$date_now,$name,$mail,$url,$coment,$ryokin,$goukei);
# ロック処理
&lock if ($lockkey);
open(IN,"$logfile") || &error("Open Error : $logfile");
@lines = ;
close(IN);
$flag=0;
# 重複投稿チェック
($no,$date_now,$name,$mail,$url,$coment,$ryokin,$goukei)
= split(/,/, $lines[0]);
# 記事Noを採番
$no++;
# 更新
while ($max <= @lines) { pop(@lines); }
# 日時の取得
$ENV{'TZ'} = "JST-9";
$time = time;
($sec,$min,$hour,$mday,$mon,$year,$wday,$dmy) = localtime($time);
# 日時のフォーマット
@week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$date = sprintf("%04d/%02d/%02d(%s) %02d:%02d",
$year+1900,$mon+1,$mday,$week[$wday],$hour,$min);
unshift(@lines,"$no$step1,$date,\n");
open(OUT,">$logfile") || &error("Write Error : $logfile");
print OUT @lines;
close(OUT);
# ロック解除
&unlock if ($lockkey);
&sendmail;
print "Content-type: text/html\n\n";
print <<"EOM";
JAPAN サッカーカレッジ


応援メッセージを受け付けました。ありがとうございました。これからも応援よろしくお願いします!!
戻る
Copyright(C)CUPS.All Rights Reserved.
EOM
exit;
}
#---------------------------------------------------------------------------
sub sendmail {
if (!(open(OUT,"| $sendmail -t"))) { &error('予期せぬエラーです'); }
print OUT "X-Mailer: bauhaus-niigata.co.jp\n";
print OUT "X-HTTP_REFERER: $ref\n";
print OUT "Errors-To: $mailto\n";
print OUT "To: $mailto\n";
print OUT "From: $ckmail\n";
print OUT "subject: CUPS HFL ENTRY\n";
print OUT "Content-Transfer-Encoding: 7bit\n";
print OUT "北信越フットボールリーグ情報サイトから応援メッセージの投稿がありました。\n";
print OUT "------------\n\n";
print OUT "■ニックネーム\n";
print OUT "$eq1\n\n";
print OUT "■応援メッセージ\n";
print OUT "$eq2\n\n";
print OUT "------------\n\n";
print OUT "以上。\n";
close(OUT);
EOM
}
#--------------#
# ロック処理 #
#--------------#
sub lock {
# 1分以上古いロックは削除する
if (-e $lockfile) {
local($mtime) = (stat($lockfile))[9];
if ($mtime < time - 60) { &unlock; }
}
local($retry) = 5;
# symlink関数式ロック
if ($lockkey == 1) {
while (!symlink(".", $lockfile)) {
if (--$retry <= 0) { &error('Lock is busy'); }
sleep(1);
}
# mkdir関数式ロック
} elsif ($lockkey == 2) {
while (!mkdir($lockfile, 0755)) {
if (--$retry <= 0) { &error('Lock is busy'); }
sleep(1);
}
}
$lockflag=1;
}
#--------------#
# ロック解除 #
#--------------#
sub unlock {
if ($lockkey == 1) { unlink($lockfile); }
elsif ($lockkey == 2) { rmdir($lockfile); }
$lockflag=0;
}