#!/usr/bin/perl
use vars qw(%set %in);
use strict;
$set{'log_file'} = './log.cgi'; #ログファイル名
$set{'max_log'} = 30; #保持件数
$set{'max_size'} = 1*1024; #最大投稿容量(KB)
$set{'min_flag'} = 0; #最小容量制限を使用する=1
$set{'min_size'} = 100; #最小投稿容量(KB)
$set{'max_all_flag'} = 0; #総容量制限を使用する=1
$set{'max_all_size'} = 20*1024; #総制限容量(KB)
$set{'file_pre'} = 'up'; #ファイル接頭辞
$set{'pagelog'} = 10; #1ページに表示するファイル数
$set{'base_html'} = 'upload.html'; #1ページ目のファイル名
$set{'interval'} = 0; #同一IP投稿間隔秒数
$set{'deny_host'} = ''; #投稿禁止IP/HOST ,で区切る ex.(bbtec.net,219.119.66,ac.jp)
$set{'admin_name'} = 'admin'; #管理者ログインID
$set{'admin_pass'} = '1234'; #管理者パスワード
# 以下5項目を再設定する際にはPATH,ディレクトリは / で終わること
# $set{'html_dir'},$set{'base_cgi'}を ./ 以外に設定する場合,
# またはDLkeyを使用し なおかつHTMLキャッシュ($set{'dummy_html'} = 2 or 3)を使用する場合は
# $set{'base_cgi'} , $set{'http_html_path'} , $set{'http_src_path'} をフルパス(http://〜〜 or /〜〜)で記述する
$set{'html_dir'} = './'; # 内部HTML保存ディレクトリ
$set{'src_dir'} = './src/'; # 内部ファイル保存ディレクトリ
$set{'base_cgi'} = './upload.cgi'; # このスクリプト名 http://〜の指定可能
$set{'http_html_path'} = './'; # html参照 httpPATH http://〜の指定可能
$set{'http_src_path'} = './src/'; # file参照 httpPATH http://〜の指定可能
$set{'dlkey'} = 0; # DLKeyを使用する=1,DLkey必須=2
$set{'up_ext'} = 'txt,lzh,zip,rar,gca,mpg,mp3,avi,swf,bmp,jpg,gif,png'; #アップロードできる基本拡張子 半角英数小文字 ,で区切る
$set{'up_all'} = 0; #登録以外のものもUPさせられるようにする=1
$set{'ext_org'} = 0; #$set{'up_all'}が1の時オリジナルの拡張子にする=1
$set{'deny_ext'} = 'php,php3,phtml,rb,sh,bat,dll'; #投稿禁止の拡張子 半角英数小文字 ,で区切る
$set{'change_ext'} = 'cgi->txt,pl->txt,log->txt,jpeg->jpg,mpeg->mpg'; #拡張子変換 前->後 半角英数小文字 ,で区切る
$set{'home_url'} = ''; #[HOME]のリンク先 相対パス又は http://から始まる絶対パス
$set{'html_all'} = 1; #[ALL]を出す=1
$set{'dummy_html'} = 0; #ファイル個別HTMLを作成する 通常ファイルのみ=1,DLKey設定ファイルのみ=2,すべて=3
$set{'find_crypt'} = 1; #暗号化ZIPを検出する=1
$set{'binary_compare'} = 0; #既存ファイルとバイナリ比較する=1
$set{'post_flag'} = 0; #PostKeyを使用する=1
$set{'post_key'} = 'postkey'; #PostKey ,で区切ると複数指定 ex.(postkey1,postkey2)
$set{'disp_error'} = 1; #ユーザーにエラーを表示する=1
$set{'error_level'} = 1; #エラーログを記録する=1
$set{'error_log'} = './error.cgi'; #エラーログファイル名
$set{'error_size'} = 1024; # エラーログ最大容量(KB) 制限なし=0
$set{'zero_clear'} = 1; #ファイルが見つからない場合ログから削除する=1
$set{'disp_comment'} = 1; #コメントを表示する=1
$set{'disp_date'} = 1; #日付を表示する=1
$set{'disp_size'} = 1; #サイズを表示する=1
$set{'disp_mime'} = 1; #MIMETYPEを表示する=1
$set{'disp_orgname'} = 1; #オリジナルファイル名を表示する=1
$set{'per_upfile'} = 0666; #アップロードファイルのパーミッション suexec=0604,other=0666
$set{'per_dir'} = 0777; #ソースアップディレクトリのパーミッション suexec=0701,other=0777
$set{'per_logfile'} = 0666; #ログファイルのパーミッション suexec=0600,other=0666
$set{'link_target'} = ''; #target属性
#------
$set{'ver'} = '2005/10/10e';
$set{'char_delname'} = 'D';
$in{'time'} = time(); $in{'date'} = conv_date($in{'time'});
$in{'addr'} = $ENV{'REMOTE_ADDR'};
$in{'host'} = gethostbyaddr(pack('C4',split(/\./, $in{'addr'})), 2) || $ENV{'REMOTE_HOST'} || '(none)';
if($in{'addr'} eq $in{'host'}){ $in{'host'} = '(none)'; }
$set{'html_head'} =<<"EOM";
Uploader
EOM
$set{'html_css'} =<<"EOM";
EOM
unless(-e $set{'log_file'}){ &init; }
unless(-e $set{'base_html'}){ &makehtml; }
{ #デコード
my $readbuffsize = 1024*8;
if ($ENV{'REQUEST_METHOD'} eq "POST" && $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/i){
if ($ENV{'CONTENT_LENGTH'} > ($set{'max_size'} * 1024 + 1024)){ if($ENV{'SERVER_SOFTWARE'} =~ /IIS/){ while(read(STDIN,my $buff,$readbuffsize)){} } &error(106,$ENV{'CONTENT_LENGTH'});}
}else{
if ($ENV{'CONTENT_LENGTH'} > 1024*100){ error(98); }
}
my %ck; foreach(split(/;/,$ENV{'HTTP_COOKIE'})){ my($key,$val) = split(/=/); $key =~ s/\s//g; $ck{$key} = $val;}
my @ck = split(/<>/,$ck{'SN_USER'});
if(length($ck[0]) < 5){
my @salt = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/'); srand;
my $salt = $salt[int(rand(@salt))] . $salt[int(rand(@salt))];
$in{'user'} = crypt($in{'addr'}.$in{'time'}, $salt);
}else{ $in{'user'} = $ck[0]; }
if($ENV{'REQUEST_METHOD'} eq "POST" && $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/i){
my %FORM; my $subbuff; my $filename; my $valuename;
my $upflag; my $valueflag; my $bound; my $mime;
my $readlength = 0;
my $random = int(rand(900000)) + 100000;
my $endflag = 0;
binmode(STDIN);
while(){ $readlength += length($_); if(/(--.*)\r\n$/){ $bound = $1; last; }}
if(-e "$set{'src_dir'}$random.temporary"){ $random++; }
if(-e "$set{'src_dir'}$random.temporary"){ $random++; }
if(-e "$set{'src_dir'}$random.temporary"){ &error(204); }
open(OUT,">$set{'src_dir'}$random.temporary");
binmode(OUT);
my $formbuff;
while(my $buff = ){
$readlength += length($buff);
if($upflag == 1){ if($buff =~ /Content-Type:\s(.*)\r\n$/i){ $mime = $1; } $upflag++; next;}
if($upflag == 2){
while(1){
my $readblen; my $filebuff;
if($ENV{'CONTENT_LENGTH'} - $readlength < $readbuffsize){ $readblen = $ENV{'CONTENT_LENGTH'} - $readlength; }
else{ $readblen = $readbuffsize; }
if(!read(STDIN,$filebuff,$readblen)){ last };
$readlength += length($filebuff);
if($ENV{'CONTENT_LENGTH'} - $readlength < $readbuffsize){
my $readblen = $ENV{'CONTENT_LENGTH'} - $readlength;
read(STDIN,my $subbuff,$readblen);
$readlength += length($subbuff);
$filebuff .= $subbuff;
$endflag = 1;
}
my $offset = index($filebuff,$bound);
if($offset >= 0){
$buff = substr($filebuff,0,$offset-2); my $subbuff = substr($filebuff,$offset);
print OUT $buff; $upflag = 0; $formbuff .= $subbuff; last;
}else{ print OUT $filebuff; }
}
if($endflag){ last; }
next;
}
if($buff =~ /^Content-Disposition:\sform-data;\sname=\"upfile\";\sfilename=\"(.*)\"\r\n$/i){
$filename = $1; $upflag = 1; next;
}
$formbuff .= $buff;
}
close(OUT);
chmod($set{'per_upfile'},"$set{'src_dir'}$random.temporary");
{ my $value;
foreach my $buff(split(/\r\n/,$formbuff)){
$buff .= "\r\n";
if($buff =~ /^$bound\-\-/){ $FORM{$value} =~ s/\r\n$//; $valueflag = 0; last;}
if($buff =~ /^$bound/){ $FORM{$value} =~ s/\r\n$//; $valueflag = 0; next;}
if($valueflag == 1){ $valueflag++; next; }
if($valueflag == 2){ $FORM{$value} .= $buff; }
if($buff =~ /^Content-Disposition: form-data; name=\"(.+)\"\r\n$/){ $value = $1; $valueflag++; }
}
}
if($upflag || $valueflag){ unlink("$set{'src_dir'}$random.temporary"); &error(108);}
$in{'postname'} = $FORM{'postname'};
$in{'org_pass'} = $in{'pass'} = $FORM{'pass'};
$in{'dlkey'} = $FORM{'dlkey'};
$in{'comment'} = $FORM{'comment'};
$in{'jcode'} = $FORM{'jcode'};
$in{'postkey'} = $FORM{'postkey'};
$in{'upfile'} = $filename;
$in{'type'} = $mime;
$in{'tmpfile'} = "$set{'src_dir'}$random.temporary";
$in{'orgname'} = $in{'upfile'};
if(-s "$in{'tmpfile'}" == 0){ unlink("$in{'tmpfile'}"); &error(99) }
if($set{'min_flag'} && ((-s "$in{'tmpfile'}") < $set{'min_size'} * 1024)){ &error(107,(-s "$in{'tmpfile'}"));}
if((-s "$in{'tmpfile'}") > $set{'max_size'} * 1024){ &error(106,(-s "$in{'tmpfile'}"));}
if($set{'post_flag'} && !check_postkey($in{'postkey'})){ &error(109); }
if($set{'dlkey'} == 2 && !$in{'dlkey'}){ unlink("$in{'tmpfile'}"); &error(61); }
}else{
my ($buffer,%FORM,@admin_delno);
if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});}
else { $buffer = $ENV{'QUERY_STRING'}; }
my @pairs = split(/&/,$buffer);
foreach my $pair (@pairs) {
my ($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if($name eq 'admin_delno'){
push(@admin_delno,$value);
}else{
$FORM{$name} = $value;
}
}
$in{'delpass'} = $FORM{'delpass'};
$in{'delno'} = $FORM{'delno'};
$in{'file'} = $FORM{'file'};
$in{'dlkey'} = $FORM{'dlkey'};
$in{'mode'} = $FORM{'mode'};
$in{'checkmode'} = $FORM{'checkmode'};
$in{'admin_delno'} = join(',',@admin_delno);
if($in{'delno'} eq $set{'admin_name'} && $in{'delpass'} eq $set{'admin_pass'}){ &admin_mode(); }
if(!$in{'delno'} && $in{'delpass'} eq $set{'admin_pass'}){ &makehtml; &quit; }
}
my @denyhost = split(/,/,$set{'deny_host'});
foreach my $value (@denyhost){
if ($in{'addr'} =~ /$value/ || $in{'host'} =~ /$value/){ &error(101);}
}
my @form = ($in{'postname'},$in{'comment'},$in{'orgname'},$in{'type'},$in{'dlkey'});
foreach my $value (@form) {
if (length($value) > 128) { $value = substr($value,0,128).'...'; }
# $value =~ s/&/&/g;
$value =~ s/"/"/g;
$value =~ s/</g;
$value =~ s/>/>/g;
$value =~ s/\r//g;
$value =~ s/\n//g;
$value =~ s/\t//g;
$value =~ s/\0//g;
}
($in{'postname'},$in{'comment'},$in{'orgname'},$in{'type'},$in{'dlkey'}) = @form;
}
if($in{'mode'} eq 'delete'){ &delete(); &quit(); }
if($in{'mode'} eq 'dl'){ &dlfile;} #DL
if(!$in{'upfile'}){ &error(99); }
{#メイン処理
open(IN,$set{'log_file'})||&error(303);
my @log = ;
close(IN);
my ($no,$lastip,$lasttime) = split(/<>/,$log[0]);
if($set{'interval'} && $in{'time'} <= ($lasttime + $set{'interval'}) && $in{'addr'} eq $lastip){ &error(203);}
$in{'ext'} = extfind($in{'orgname'}); if(!$in{'ext'}){ &error(202); }
my $orgname;
if(split(/\//,$in{'orgname'}) > split(/\\/,$in{'orgname'})){ my @name = split(/\//,$in{'orgname'}); $orgname = $name[$#name]; }
else{ my @name = split(/\\/,$in{'orgname'}); $orgname = $name[$#name];}
my @salt = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/');
srand;
my $salt = $salt[int(rand(@salt))] . $salt[int(rand(@salt))];
$in{'pass'} = crypt($in{'pass'}, $salt);
if($set{'binary_compare'}){
my @files = globfile("$set{'src_dir'}",".*");
my @dir = globdir("$set{'src_dir'}",".*");
foreach my $dir (@dir){ push(@files,globfile($dir."/",".*")); }
foreach my $value (@files){
next if($value =~ /\.temporary$/);
if(binarycmp($in{'tmpfile'},$value)){ unlink($in{'tmpfile'}); &error(205,$value);}
}
}
if($set{'find_crypt'}){
open(FILE,$in{'tmpfile'}); binmode(FILE); seek(FILE,0,0); read(FILE,my $buff,4); my $crypt_flag = 0;
if($buff =~ /^\x50\x4b\x03\x04$/){ seek(FILE,6,0); read(FILE,my $buff,1); $crypt_flag = 1 if(($buff & "\x01") eq "\x01"); }
close(FILE);
$in{'comment'} = '*'.$in{'comment'} if($crypt_flag);
}
open(IN,$set{'log_file'})||&error(303);
@log = ;
close(IN);
($no,$lastip,$lasttime) = split(/<>/,$log[0]);
shift(@log);
$no++;
my $tmpno = sprintf("%04d",$no);
my $dlsalt;
my $filedir;
my $allsize = (-s $in{'tmpfile'});
if($set{'dlkey'} && $in{'dlkey'}){
my @salt = ('a'..'z', 'A'..'Z', '0'..'9'); srand;
for (my $c = 1; $c <= 20; ++$c) { $dlsalt .= $salt[int(rand(@salt))]; }
$filedir = "$set{'src_dir'}$set{'file_pre'}${tmpno}.$in{'ext'}_$dlsalt/";
mkdir($filedir,$set{'per_dir'});
rename("$in{'tmpfile'}","$filedir$set{'file_pre'}$tmpno.$in{'ext'}");
open(OUT,">${filedir}index.html");
close(OUT);
chmod($set{'per_upfile'},"${filedir}index.html");
$in{'comment'} = '[DLKey] '.$in{'comment'};
}else{
undef $in{'dlkey'};
rename("$in{'tmpfile'}","$set{'src_dir'}$set{'file_pre'}$tmpno.$in{'ext'}");
}
if (length($orgname) > 128) { $orgname = substr($orgname,0,128).'...'; }
my @note;
if($set{'post_flag'} && $set{'post_key'}){
push(@note,'PostKey:'.$in{'postkey'});
}
if($ENV{'SERVER_SOFTWARE'} =~ /Apache|IIS/){
my $disptime;
my $time = time() - $in{'time'};
my @str = ('Upload:','秒');
my $disptime = $time.$str[1];
push(@note,$str[0].$disptime);
}
if($in{'dlkey'}){
my @salt = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/'); srand;
my $salt = $salt[int(rand(@salt))] . $salt[int(rand(@salt))];
my $crypt_dlkey = crypt($in{'dlkey'}, $salt);
push(@note,"DLKey");
}
my $note = join(',',@note);
my $usersalt = substr($in{'user'},0,2);
my $userid = crypt($in{'user'},$usersalt);
$in{'time'} = time();
# $in{'date'} = conv_date(time());
my @new;
$new[0] = "$no<>$in{'addr'}<>$in{'time'}<>1\n";
my $addlog = "$no<>$in{'postname'}<>$in{'ext'}<>$in{'date'}<>$in{'comment'}<>$in{'type'}<>$orgname<>$in{'addr'}<>$in{'host'}<>$in{'pass'},$userid<>$set{'file_pre'}<>$note<>1\n";
$new[1] = $addlog;
# open(OUT,">>./alllog.cgi"); print OUT $addlog; close(OUT);
my $i = 2;
foreach my $value (@log){
my ($no,$postname,$ext,$date,$comment,$mime,$orgname,$addr,$host,$pass,$filepre,$note,$dummy) = split(/<>/,$value);
if(!$dummy){ $filepre = $set{'file_pre'};}
$no = sprintf("%04d",$no);
my $filename;
my $filedir;
if($note =~ /DLpath:(.+)\s/){
my $dlpath = $1;
$filename = "$set{'src_dir'}$filepre$no.${ext}_$dlpath/$filepre$no.$ext";
$filedir = "$set{'src_dir'}$filepre$no.${ext}_$dlpath/";
}else{
$filename = "$set{'src_dir'}$filepre$no.$ext";
}
$allsize += (-s $filename);
if($i <= $set{'max_log'} && !($set{'max_all_flag'} && $set{'max_all_size'}*1024 < $allsize)){
if((-e $filename)||!$set{'zero_clear'}){ push(@new,$value); $i++; }
}else{
if(unlink($filename)){
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } } rmdir($filedir);
}elsif(unlink($filename)){
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } } rmdir($filedir);
}elsif(-e $filename){
push(@new,$value);
}else{
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } } rmdir($filedir);
}
}
}
logwrite(@new);
if($in{'dlkey'} && ( $set{'dummy_html'} == 2 || $set{'dummy_html'} == 3)){
&makedummyhtml("$set{'file_pre'}$tmpno.$in{'ext'}",$in{'comment'},"$set{'file_pre'}$tmpno.$in{'ext'}",$dlsalt,$in{'date'},$in{'type'},$orgname,$no);
}elsif(!$in{'dlkey'} && ($set{'dummy_html'} == 1 || $set{'dummy_html'} == 3)){
&makedummyhtml("$set{'file_pre'}$tmpno.$in{'ext'}");
}
&makehtml(); &quit();
}
sub makehtml{
my ($buff,$init,$postval,$dlkey);
my $page = 0; my $i = 1;
open(IN,$set{'log_file'})||&error(303);
my $log = my @log = ;
close(IN);
if($log == 1){ $log++; $init++;}
my $lastpage = int(($log - 2)/$set{'pagelog'}) + 1;
$postval = ' obj.postkey.value = unescape(p[2]);' if($set{'post_flag'});
my $header =<<"EOM";
$set{'html_head'}
$set{'html_css'}
Now.. Testing..
EOM
my $maxsize = 'Max '.dispsize($set{'max_size'}*1024);
my ($minsize,$total);
if($set{'min_flag'}){ $minsize = 'Min '.dispsize($set{'min_size'}*1024).' - '; }
if($set{'max_all_flag'}){ $total .= ' Total '.dispsize($set{'max_all_size'}*1024);}
$header .= qq|';
my $allsize = 0;
my @files = globfile("$set{'src_dir'}",".*");
my @dir = globdir("$set{'src_dir'}",".*");
foreach my $dir (@dir){ push(@files,globfile($dir."/",".*")); }
foreach my $value (@files){ $allsize += (-s "$value"); }
$allsize = dispsize($allsize);
my $footer = "
Used ${allsize}\n
";
if($set{'up_all'} && !$set{'ext_org'}){ $footer .= $set{'up_ext'}.' +'; }
elsif(!$set{'up_all'}){ $footer .= $set{'up_ext'}; }
$footer .= "\n\n\n";
my $info_title = "\n | NAME | FILE | ";
if($set{'disp_comment'}){ $info_title .= "COMMENT | "; } if($set{'disp_size'}){ $info_title .= "SIZE | "; } if($set{'disp_date'}){ $info_title .= "DATE | "; }
if($set{'disp_mime'}){ $info_title .= "MIME | "; } if($set{'disp_orgname'}){ $info_title .= "ORIG | "; }
$info_title .= "
\n";
my $home_url_link;
if($set{'home_url'}){ $home_url_link = qq|[HOME] |;}
if($set{'html_all'}){
my $buff; my $no = 1; my $time = time; my $subheader;
foreach my $value (@log){
my ($no,$postname,$ext,$date,$comment,$mime,$orgname,$addr,$host,$pass,$dummy) = split(/<>/,$value);
if(!$dummy){ next; }
$buff .= makeitem($value);
}
$subheader .= "[ALL] ";
while($no <= $lastpage){
if($no == $page) { $subheader .= "\[$no\] ";}
else{ if($no == 1){ $subheader .= "\[$no\] "}
else{$subheader .= "\[$no\] ";} }
$no++;
}
$subheader .= $info_title;
open(OUT,">$set{'html_dir'}all.html")||&error(306,"$set{'html_dir'}all.html");
print OUT $header."
".$home_url_link.$subheader."
".$buff.$footer;
close(OUT);
chmod($set{'per_upfile'},"$set{'html_dir'}all.html");
}else{ unlink("$set{'html_dir'}all.html"); }
while($log > $i){
$buff .= makeitem($log[$i]) unless($init);
if(($i % $set{'pagelog'}) == 0||$i == $log -1){
$page++; my $subheader; my $no = 1; my $time = time;
if($set{'html_all'}){ $subheader .= "[ALL] "; }
while($no <= $lastpage){
if($no == $page) { $subheader .= "\[$no\] ";}
else{ if($no == 1){ $subheader .= "\[$no\] "}
else{$subheader .= "\[$no\] ";}
}
$no++;
}
$subheader .= $info_title;
my $loghtml;
if($page == 1){ $loghtml = "$set{'html_dir'}$set{'base_html'}"; }
else{ $loghtml = "$set{'html_dir'}$page.html"; }
open(OUT,">$loghtml") || &error(306,"$loghtml");
print OUT $header."
".$home_url_link.$subheader."
".$buff.$footer;
close(OUT);
chmod($set{'per_upfile'},$loghtml);
undef $buff;
}
$i++;
}
while($page < 1000){
$page ++;
if(-e "$set{'html_dir'}$page.html"){ unlink("$set{'html_dir'}$page.html"); }else{ last; }
}
}
sub delete{
my $mode = $_[0];
my @delno = split(/,/,$_[1]);
my $delno; my $flag = 0; my $tmpaddr;
my $delnote;
if($in{'delno'} =~ /(\d+)/){ $delno = $1; }
if($mode ne 'admin' && !$in{'delno'}){ return; }
elsif($mode ne 'admin' && !$delno){ &error(401,$in{'delno'}); }
open(IN,$set{'log_file'})|| &error(303);
my @log = ;
close(IN);
if($in{'addr'} =~ /(\d+).(\d+).(\d+).(\d+)/){ $tmpaddr = "$1.$2.$3."; }
my $findflag = 0;
foreach my $value (@log){
my ($no,$postname,$ext,$date,$comment,$mime,$orgname,$addr,$host,$pass,$filepre,$note,$dummy) = split(/<>/,$value);
$delnote = $note;
my $delflag = 0;
if(!$addr){ next; }
if($mode eq 'admin'){
foreach my $delno (@delno){ if($no == $delno){ $delflag = 1; last; } }
}elsif($no == $delno){
$findflag = 1;
unless ($addr =~ /^$tmpaddr/){
my ($pass,$id) = split(/,/,$pass);
my $delpass = $in{'delpass'} || $in{'addr'}.time();
my $salt = substr($pass, 0, 2); $delpass = crypt($delpass,$salt);
my $usersalt = substr($in{'user'},0,2); my $userid = crypt($in{'user'},$usersalt);
if ($in{'delpass'} ne $set{'admin_pass'} && $delpass ne $pass && $userid ne $id){
if($mode ne 'admin'){ if(!$dummy){ $filepre = $set{'file_pre'};} $no = sprintf("%04d",$no); &error(404,"$filepre$no.$ext");}
}
}
$delflag = 1;
}
if($delflag){
# open(OUT,">>./del.cgi"); print OUT $value; close(OUT);
$flag = 1;
if(!$dummy){ $filepre = $set{'file_pre'};}
$no = sprintf("%04d",$no);
my $filename;
my ($dlpath,$filedir);
if($delnote =~ /DLpath:(.+)\s/){
$dlpath = $1;
$filename = "$set{'src_dir'}$filepre$no.${ext}_$dlpath/$filepre$no.$ext";
$filedir = "$set{'src_dir'}$filepre$no.${ext}_$dlpath/";
}else{
$filename = "$set{'src_dir'}$filepre$no.$ext";
}
if(unlink($filename)){
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } rmdir($filedir);} undef $value;
}elsif(unlink($filename)){
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } rmdir($filedir);} undef $value;
}elsif(!(-e $filename)){
unlink("$set{'src_dir'}$filepre$no.$ext.html"); if($filedir){ foreach(globfile($filedir,".*")){ unlink; } rmdir($filedir);} undef $value;
}else{
if($mode ne 'admin'){ &error(403,"$filepre$no.$ext");}
}
}
}
if($mode ne 'admin' && !$findflag){ &error(402,$delno); }
if($flag){
logwrite(@log);
&makehtml();
}
}
sub quit{
my ($cookiename,$buff);
my $flag = 0;
my @tmpfiles = globfile("$set{'src_dir'}","\.temporary");
foreach my $value (@tmpfiles){ if((stat($value))[10] < time - 60*60){ unlink("$value"); $flag++; } }
&makehtml() if($flag);
$buff =<<"EOM";
$set{'html_head'}
EOM
if($in{'jcode'} || $in{'mode'} eq 'delete'){
$buff .=<<"EOM";
\n|;
}
$buff .=<<"EOM";