#! c:/perl/bin/perl
#! /usr/local/bin/perl
#
#require "jcode.pl";
require "cgi-lib.pl";
$dldir = "../download";
$dllistfile = "$dldir/download.lst";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@wday_array = ('日','月','火','水','木','金','土');
$date_now = sprintf("%01d月%01d日(%s)%02d時%02d分",$mon +1,$mday,$wday_array[$wday],$hour,$min);
$rmon=$mon+1;
&ReadParse;
while (($key,$value)=each %in){
if ($key ne 'upfile'){
# &jcode::convert(*value,'sjis');
$value =~ s/</g; $value =~ s/>/>/g;
$br = "";
if ($value =~ /\r\n/) { $value =~ s/\r\n/$br/g; }
if ($value =~ /\n/) { $value =~ s/\n/$br/g; }
if ($value =~ /\r/) { $value =~ s/\r/$br/g; }
if ($value =~ /,/) { $value =~ s/,/,/g; }
$in{"$key"}=$value;
}
}
if ($in{mode} eq 'register'){
if ($in{'sub'} eq "" || $in{'upfile'} eq "") {
&error("タイトル、またはファイル名を正しく入れてください。");
}
if ($in{'fname'} eq ""){
foreach (@in) {
if ($_ =~ /(.*)filename=\"(.*)\"/i) {
$fname=$2;
$fname =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
}
}
} else {
$fname=$in{'fname'};
}
if ($fname !~ /^[0-9a-zA-Z\._]+$/) {
&error("$fname:アップ後のファイル名は半角英数で。");
}
$fname =~ tr/\"\x0D\x0A//d;
$outfile = "$dldir/$fname";
if (-e "$outfile") {
&error("同じファイル名がサーバー上に存在します。
アップ後のファイル名を変更してやり直してください。");
}
open(OUT,"> $outfile") || die;
binmode(OUT);
print OUT $in{upfile};
close(OUT);
chmod (0666,$outfile);
($d_dev,$d_ino,$d_mode,$d_nlink,$d_uid,$d_gid,$d_rdev,$d_size,$d_atime,$d_mtime,$d_ctime,$d_blksize,$d_blocks)=stat("$outfile");
if ($d_size/1000000 > 1){
$size = sprintf("%.1fMB",$d_size/1000000);
} elsif ($d_size/1000 > 1){
$size = sprintf("%.1fkB",$d_size/1000);
} else {
$size = sprintf("%dB",$d_size);
}
open(DLFILE,"< $dllistfile");
while(){
($count,@dummy)=split(/,/);
}
close(DLFILE);
$count++;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($d_mtime);
$update = sprintf("%s年%s月%s日%02s時%02s分",$year+1900,$mon+1,$mday,$hour,$min);
$remote_host=$ENV{'REMOTE_HOST'};
$remote_addr=$ENV{'REMOTE_ADDR'};
open(DAT,">> $dllistfile");
print DAT "$count,$fname,$in{sub},$size,$update,$remote_host,$remote_addr\n";
close(DAT);
chmod(0666,"$dllistfile");
print "Location: showdllst.pl\n\n";
} else {
if ($in{'deletefile'} == 0) {
&error("削除するタイトルを選んでください。");
}
$delnumber = $in{deletefile};
@newlist=();
open(DLFILE,"< $dllistfile");
while(){
($count,$file,@dummy)=split(/,/);
if ($count == $delnumber){
unlink("$dldir/$file");
} else {
push(@newlist,$_);
}
}
close(DLFILE);
open(DAT,"> $dllistfile");
print DAT @newlist;
close(DAT);
print "Location: showdllst.pl\n\n";
}
sub error {
print "Content-Type: text/html\n\n";
print "";
print "";
print "";
print "";
print "
$_[0]\n";
print "";
print "";
exit;
}