#! c:/perl/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 = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); $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; $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("Title or File name is missing."); } 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:File name has to be normal characters."); } $fname =~ tr/\"\x0D\x0A//d; $outfile = "$dldir/$fname"; if (-e "$outfile") { &error("The same file name exists on the server.
Please change the file name after uploaded and retry."); } 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",$mon+1,$mday,$year+1900,$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("Select a title to delete"); } $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; }