#==================================================
# ファイル操作(DATファイル更新)
#==================================================
{
#IDを生成する
use Digest::MD5;
my $md5 = Digest::MD5->new;
use Digest::MD5 qw(md5_hex);
my $idnum = md5_hex($ENV{'REMOTE_ADDR'});
$idnum = substr($idnum,-4);
# my $idnum = $ENV{'REMOTE_ADDR'};
# $idnum =~ s/\./0/g;
# $idnum = crypt($idnum,$idnum);
# $idnum = substr($idnum,-3);
$md5->add($idnum);
$md5->add($FORM{"bbs"});
$md5->add(substr($DATE,6,2));
my $md5datefile = "$PATH/md5.cgi";
if(-e $md5datefile){
open(MD5FILE,"<$md5datefile");
my $md5line = <MD5FILE>;
close(MD5FILE);
my ($md5date,$md5number) = split /<>/,$md5line;
if($md5date eq $MD5DATE){
$md5->add($md5number);
}else{
open(MD5FILE,">$md5datefile");
my $data = "";
sysopen(RANDOM, "/dev/random", O_READ) || die "cannot open /dev/random $!\n";
sysread(RANDOM, $data, 16);
close(RANDOM);
print MD5FILE "$MD5DATE<>$data";
close(MD5FILE);
$md5->add($data);
}
}else{
open(MD5FILE,">$md5datefile");
my $data = "";
sysopen(RANDOM, "/dev/random", O_READ) || die "cannot open /dev/random $!\n";
sysread(RANDOM, $data, 16);
close(RANDOM);
print MD5FILE "$MD5DATE<>$data";
close(MD5FILE);
$md5->add($data);
}
chmod(0777,"$md5datefile");
my $idcrypt = $md5->b64digest;
$idcrypt = substr($idcrypt,0,8);
my $outdat;
if($SETTING{'BBS_NO_ID'} eq "checked") {
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}elsif($FLAG == 9){
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE ID:???<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}elsif($SETTING{'BBS_FORCE_ID'} eq "checked"){
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE ID:$idcrypt<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}elsif($FORM{'mail'} ne ""){
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE ID:???<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}elsif($FLAG == 9){
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE ID:???<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}else{
$outdat = "$FORM{'FROM'}<>$FORM{'mail'}<>$DATE ID:$idcrypt<> $FORM{'MESSAGE'} <>$FORM{'subject'}\n";
}
open(OUT, ">>$DATAFILE");
flock(OUT,2);
print OUT $outdat;
flock(OUT,8);
close(OUT);
#パーミッション調整
umask(0);
chmod(0666, $DATAFILE);
}